Skip to content

Commit

Permalink
Calculate weapon pitch from turret base
Browse files Browse the repository at this point in the history
  • Loading branch information
DARwins1 committed Nov 27, 2023
1 parent 806f503 commit c3ce490
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,20 @@ bool actionTargetTurret(BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, WEAPON *

//set the pitch limits based on the weapon stats of the attacker
pitchLowerLimit = pitchUpperLimit = 0;
Vector3i attackerMuzzlePos = psAttacker->pos; // Using for calculating the pitch, but not the direction, in case using the exact direction causes bugs somewhere.
Vector3i attackerTurretPos = psAttacker->pos; // Using for calculating the pitch, but not the direction, in case using the exact direction causes bugs somewhere.
if (psAttacker->type == OBJ_STRUCTURE)
{
STRUCTURE *psStructure = (STRUCTURE *)psAttacker;
int weapon_slot = psWeapon - psStructure->asWeaps; // Should probably be passed weapon_slot instead of psWeapon.
calcStructureMuzzleLocation(psStructure, &attackerMuzzlePos, weapon_slot);
calcStructureMuzzleBaseLocation(psStructure, &attackerTurretPos, weapon_slot);
pitchLowerLimit = DEG(psWeapStats->minElevation);
pitchUpperLimit = DEG(psWeapStats->maxElevation);
}
else if (psAttacker->type == OBJ_DROID)
{
DROID *psDroid = (DROID *)psAttacker;
int weapon_slot = psWeapon - psDroid->asWeaps; // Should probably be passed weapon_slot instead of psWeapon.
calcDroidMuzzleLocation(psDroid, &attackerMuzzlePos, weapon_slot);
calcDroidMuzzleBaseLocation(psDroid, &attackerTurretPos, weapon_slot);

if (psDroid->droidType == DROID_WEAPON || isTransporter(psDroid)
|| psDroid->droidType == DROID_COMMAND || psDroid->droidType == DROID_CYBORG
Expand Down Expand Up @@ -395,7 +395,7 @@ bool actionTargetTurret(BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, WEAPON *
if (!bRepair && (unsigned)objPosDiffSq(psAttacker, psTarget) > minRange * minRange && proj_Direct(psWeapStats))
{
/* get target distance */
Vector3i delta = psTarget->pos - attackerMuzzlePos;
Vector3i delta = psTarget->pos - attackerTurretPos;
int32_t dxy = iHypot(delta.x, delta.y);

uint16_t targetPitch = iAtan2(delta.z, dxy);
Expand Down

0 comments on commit c3ce490

Please sign in to comment.