Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game object stats refactor, pt. 2 #3617

Merged
merged 10 commits into from
Feb 5, 2024
28 changes: 14 additions & 14 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static bool actionInsideMinRange(DROID *psDroid, BASE_OBJECT *psObj, WEAPON_STAT

if (!psStats)
{
psStats = getWeaponStats(psDroid, 0);
psStats = psDroid->getWeaponStats(0);
}

/* if I am a multi-turret droid */
Expand Down Expand Up @@ -605,7 +605,7 @@ static bool actionRemoveDroidsFromBuildPos(unsigned player, Vector2i pos, uint16
{
Vector2i dest = world_coord(b.map + Vector2i(x, y)) + Vector2i(TILE_UNITS, TILE_UNITS) / 2;
unsigned dist = iHypot(droid->pos.xy() - dest);
if (dist < bestDist && !fpathBlockingTile(map_coord(dest.x), map_coord(dest.y), getPropulsionStats(droid)->propulsionType))
if (dist < bestDist && !fpathBlockingTile(map_coord(dest.x), map_coord(dest.y), droid->getPropulsionStats()->propulsionType))
{
bestDest = dest;
bestDist = dist;
Expand Down Expand Up @@ -634,7 +634,7 @@ void actionSanity(DROID *psDroid)
// clear the target if it has died
for (int i = 0; i < MAX_WEAPONS; i++)
{
bDirect = proj_Direct(getWeaponStats(psDroid, i));
bDirect = proj_Direct(psDroid->getWeaponStats(i));
if (psDroid->psActionTarget[i] && (avoidOverkill ? aiObjectIsProbablyDoomed(psDroid->psActionTarget[i], bDirect) : psDroid->psActionTarget[i]->died))
{
syncDebugObject(psDroid->psActionTarget[i], '-');
Expand Down Expand Up @@ -681,7 +681,7 @@ void actionUpdateDroid(DROID *psDroid)

CHECK_DROID(psDroid);

PROPULSION_STATS *psPropStats = getPropulsionStats(psDroid);
PROPULSION_STATS *psPropStats = psDroid->getPropulsionStats();
ASSERT_OR_RETURN(, psPropStats != nullptr, "Invalid propulsion stats pointer");

bool secHoldActive = secondaryGetState(psDroid, DSO_HALTTYPE) == DSS_HALT_HOLD;
Expand Down Expand Up @@ -738,7 +738,7 @@ void actionUpdateDroid(DROID *psDroid)
{
BASE_OBJECT *psTemp = nullptr;

WEAPON_STATS *const psWeapStats = getWeaponStats(psDroid, i);
WEAPON_STATS *const psWeapStats = psDroid->getWeaponStats(i);
if (psDroid->asWeaps[i].nStat > 0
&& psWeapStats->rotate
&& IS_TIME_TO_CHECK_FOR_NEW_TARGET(psDroid)
Expand Down Expand Up @@ -838,7 +838,7 @@ void actionUpdateDroid(DROID *psDroid)
BASE_OBJECT *psTemp = nullptr;

//I moved psWeapStats flag update there
WEAPON_STATS *const psWeapStats = getWeaponStats(psDroid, i);
WEAPON_STATS *const psWeapStats = psDroid->getWeaponStats(i);
if (!psDroid->isVtol()
&& psDroid->asWeaps[i].nStat > 0
&& psWeapStats->rotate
Expand Down Expand Up @@ -876,7 +876,7 @@ void actionUpdateDroid(DROID *psDroid)
bHasTarget = false;
for (unsigned i = 0; i < psDroid->numWeaps; ++i)
{
bDirect = proj_Direct(getWeaponStats(psDroid, i));
bDirect = proj_Direct(psDroid->getWeaponStats(i));
blockingWall = nullptr;
// Does this weapon have a target?
if (psDroid->psActionTarget[i] != nullptr)
Expand Down Expand Up @@ -1071,7 +1071,7 @@ void actionUpdateDroid(DROID *psDroid)
&& actionVisibleTarget(psDroid, psActionTarget, i)
&& actionInRange(psDroid, psActionTarget, i))
{
WEAPON_STATS *const psWeapStats = getWeaponStats(psDroid, i);
WEAPON_STATS *const psWeapStats = psDroid->getWeaponStats(i);
WEAPON_EFFECT weapEffect = psWeapStats->weaponEffect;
blockingWall = visGetBlockingWall(psDroid, psActionTarget);

Expand Down Expand Up @@ -1226,7 +1226,7 @@ void actionUpdateDroid(DROID *psDroid)
&& validTarget(psDroid, psDroid->psActionTarget[0], i))
{
//I moved psWeapStats flag update there
psWeapStats = getWeaponStats(psDroid, i);
psWeapStats = psDroid->getWeaponStats(i);
if (actionVisibleTarget(psDroid, psDroid->psActionTarget[0], i))
{
if (actionInRange(psDroid, psDroid->psActionTarget[0], i))
Expand Down Expand Up @@ -1325,7 +1325,7 @@ void actionUpdateDroid(DROID *psDroid)
&& actionVisibleTarget(psDroid, psDroid->psActionTarget[0], i))
{
bool chaseBloke = false;
WEAPON_STATS *const psWeapStats = getWeaponStats(psDroid, i);
WEAPON_STATS *const psWeapStats = psDroid->getWeaponStats(i);
const bool actionIsInRange = actionInRange(psDroid, psDroid->psActionTarget[0], i);
if (psWeapStats->rotate)
{
Expand Down Expand Up @@ -1403,7 +1403,7 @@ void actionUpdateDroid(DROID *psDroid)
/* Stopped moving but haven't reached the target - possibly move again */

//'hack' to make the droid to check the primary turrent instead of all
WEAPON_STATS *const psWeapStats = getWeaponStats(psDroid, 0);
WEAPON_STATS *const psWeapStats = psDroid->getWeaponStats(0);

if (order->type == DORDER_ATTACKTARGET && secHoldActive)
{
Expand Down Expand Up @@ -1969,7 +1969,7 @@ void actionUpdateDroid(DROID *psDroid)
{
Vector2i diff = (psDroid->pos - order->psObj->pos).xy();
//Consider .shortRange here
int rangeSq = getWeaponStats(psDroid, 0)->upgrade[psDroid->player].maxRange / 2; // move close to sensor
int rangeSq = psDroid->getWeaponStats(0)->upgrade[psDroid->player].maxRange / 2; // move close to sensor
rangeSq = rangeSq * rangeSq;
if (dot(diff, diff) < rangeSq)
{
Expand Down Expand Up @@ -2063,7 +2063,7 @@ void actionUpdateDroid(DROID *psDroid)
{
BASE_OBJECT *psTemp = nullptr;

WEAPON_STATS *const psWeapStats = getWeaponStats(psDroid, i);
WEAPON_STATS *const psWeapStats = psDroid->getWeaponStats(i);
if (psDroid->asWeaps[i].nStat > 0 && psWeapStats->rotate
&& secondaryGetState(psDroid, DSO_ATTACK_LEVEL) == DSS_ALEV_ALWAYS
&& IS_TIME_TO_CHECK_FOR_NEW_TARGET(psDroid)
Expand Down Expand Up @@ -2231,7 +2231,7 @@ static void actionDroidBase(DROID *psDroid, DROID_ACTION_DATA *psAction)
{
ASSERT_OR_RETURN(, psAction->psObj == nullptr || !psAction->psObj->died, "Droid dead");

WEAPON_STATS *psWeapStats = getWeaponStats(psDroid, 0);
WEAPON_STATS *psWeapStats = psDroid->getWeaponStats(0);
Vector2i pos(0, 0);

CHECK_DROID(psDroid);
Expand Down
24 changes: 12 additions & 12 deletions src/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static int aiDroidRange(DROID *psDroid, int weapon_slot)
}
else
{
WEAPON_STATS *psWStats = getWeaponStats(psDroid, weapon_slot);
WEAPON_STATS *psWStats = psDroid->getWeaponStats(weapon_slot);
longRange = proj_GetLongRange(*psWStats, psDroid->player);
}

Expand All @@ -110,7 +110,7 @@ static bool aiStructHasRange(STRUCTURE *psStruct, BASE_OBJECT *psTarget, int wea
return false;
}

WEAPON_STATS *psWStats = &asWeaponStats[psStruct->asWeaps[weapon_slot].nStat];
WEAPON_STATS *psWStats = psStruct->getWeaponStats(weapon_slot);

int longRange = proj_GetLongRange(*psWStats, psStruct->player);
return objPosDiffSq(psStruct, psTarget) < longRange * longRange && lineOfFire(psStruct, psTarget, weapon_slot, true);
Expand Down Expand Up @@ -197,7 +197,7 @@ static BASE_OBJECT *aiSearchSensorTargets(BASE_OBJECT *psObj, int weapon_slot, W
{
continue;
}
const auto sensorType = getSensorStats(psDroid)->type;
const auto sensorType = psDroid->getSensorStats()->type;
// Artillery should not fire at objects observed by VTOL CB/Strike sensors.
if (sensorType == VTOL_CB_SENSOR ||
sensorType == VTOL_INTERCEPT_SENSOR ||
Expand Down Expand Up @@ -293,7 +293,7 @@ static SDWORD targetAttackWeight(BASE_OBJECT *psTarget, BASE_OBJECT *psAttacker,
{
psAttackerDroid = (DROID *)psAttacker;

attackerWeapon = getWeaponStats(psAttackerDroid, weapon_slot);
attackerWeapon = psAttackerDroid->getWeaponStats(weapon_slot);

//check if this droid is assigned to a commander
bCmdAttached = hasCommander(psAttackerDroid);
Expand Down Expand Up @@ -335,7 +335,7 @@ static SDWORD targetAttackWeight(BASE_OBJECT *psTarget, BASE_OBJECT *psAttacker,
}
else if (psAttacker->type == OBJ_STRUCTURE)
{
attackerWeapon = (WEAPON_STATS *)(&asWeaponStats[((STRUCTURE *)psAttacker)->asWeaps[weapon_slot].nStat]);
attackerWeapon = ((STRUCTURE*)psAttacker)->getWeaponStats(weapon_slot);
}
else /* feature */
{
Expand Down Expand Up @@ -420,8 +420,8 @@ static SDWORD targetAttackWeight(BASE_OBJECT *psTarget, BASE_OBJECT *psAttacker,
}

/* Now calculate the overall weight */
attackWeight = asWeaponModifier[weaponEffect][getPropulsionStats(targetDroid)->propulsionType] // Our weapon's effect against target
+ asWeaponModifierBody[weaponEffect][getBodyStats(targetDroid)->size]
attackWeight = asWeaponModifier[weaponEffect][targetDroid->getPropulsionStats()->propulsionType] // Our weapon's effect against target
+ asWeaponModifierBody[weaponEffect][targetDroid->getBodyStats()->size]
+ WEIGHT_DIST_TILE_DROID * objSensorRange(psAttacker) / TILE_UNITS
- WEIGHT_DIST_TILE_DROID * dist / TILE_UNITS // farther droids are less attractive
+ WEIGHT_HEALTH_DROID * damageRatio / 100 // we prefer damaged droids
Expand Down Expand Up @@ -583,7 +583,7 @@ int aiBestNearestTarget(DROID *psDroid, BASE_OBJECT **ppsObj, int weapon_slot, i
++numDroidNearestTargetChecksThisFrame;

// Check if we have a CB target to begin with
WEAPON_STATS* psWStats = getWeaponStats(psDroid, weapon_slot);
WEAPON_STATS* psWStats = psDroid->getWeaponStats(weapon_slot);
if (!proj_Direct(psWStats))
{
bestTarget = aiSearchSensorTargets((BASE_OBJECT *)psDroid, weapon_slot, psWStats, &tmpOrigin);
Expand Down Expand Up @@ -887,7 +887,7 @@ bool aiChooseTarget(BASE_OBJECT *psObj, BASE_OBJECT **ppsTarget, int weapon_slot

ASSERT_OR_RETURN(false, psObj->asWeaps[weapon_slot].nStat > 0, "Invalid weapon turret");

WEAPON_STATS *psWStats = &asWeaponStats[psObj->asWeaps[weapon_slot].nStat];
WEAPON_STATS *psWStats = ((const STRUCTURE*)psObj)->getWeaponStats(weapon_slot);
int longRange = proj_GetLongRange(*psWStats, psObj->player);

// see if there is a target from the command droids
Expand Down Expand Up @@ -1267,7 +1267,7 @@ bool validTarget(BASE_OBJECT const *psObject, BASE_OBJECT const *psTarget, int w
switch (psTarget->type)
{
case OBJ_DROID:
if (asPropulsionTypes[getPropulsionStats((const DROID*)psTarget)->propulsionType].travel == AIR)
if (asPropulsionTypes[((const DROID*)psTarget)->getPropulsionStats()->propulsionType].travel == AIR)
{
if (((const DROID *)psTarget)->sMove.Status != MOVEINACTIVE)
{
Expand Down Expand Up @@ -1302,7 +1302,7 @@ bool validTarget(BASE_OBJECT const *psObject, BASE_OBJECT const *psTarget, int w
// Can't attack without a weapon
if (((const DROID *)psObject)->numWeaps != 0 && ((const DROID *)psObject)->asWeaps[weapon_slot].nStat != 0)
{
surfaceToAir = getWeaponStats((const DROID*)psObject, weapon_slot)->surfaceToAir;
surfaceToAir = ((const DROID*)psObject)->getWeaponStats(weapon_slot)->surfaceToAir;
if (((surfaceToAir & SHOOT_IN_AIR) && bTargetInAir) || ((surfaceToAir & SHOOT_ON_GROUND) && !bTargetInAir))
{
return true;
Expand All @@ -1317,7 +1317,7 @@ bool validTarget(BASE_OBJECT const *psObject, BASE_OBJECT const *psTarget, int w
// Can't attack without a weapon
if (((const STRUCTURE *)psObject)->numWeaps != 0 && ((const STRUCTURE *)psObject)->asWeaps[weapon_slot].nStat != 0)
{
surfaceToAir = asWeaponStats[((const STRUCTURE *)psObject)->asWeaps[weapon_slot].nStat].surfaceToAir;
surfaceToAir = ((const STRUCTURE*)psObject)->getWeaponStats(weapon_slot)->surfaceToAir;
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/basedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@ enum OBJECT_FLAG
OBJECT_FLAG_COUNT
};

struct WEAPON_STATS;

struct BASE_OBJECT : public SIMPLE_OBJECT
{
BASE_OBJECT(OBJECT_TYPE type, uint32_t id, unsigned player);
~BASE_OBJECT();

WEAPON_STATS* getWeaponStats(int weaponSlot) const;

SCREEN_DISP_DATA sDisplay; ///< screen coordinate details
UBYTE group = 0; ///< Which group selection is the droid currently in?
UBYTE selected; ///< Whether the object is selected (might want this elsewhere)
Expand Down
6 changes: 6 additions & 0 deletions src/baseobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ BASE_OBJECT::~BASE_OBJECT()
visRemoveVisibility(this);
}


WEAPON_STATS* BASE_OBJECT::getWeaponStats(int weaponSlot) const
{
return &asWeaponStats[asWeaps[weaponSlot].nStat];
}

// Query visibility for display purposes (i.e. for `selectedPlayer`)
// *DO NOT USE TO QUERY VISIBILITY FOR CALCULATIONS INVOLVING GAME / SIMULATION STATE*
UBYTE BASE_OBJECT::visibleForLocalDisplay() const
Expand Down
2 changes: 1 addition & 1 deletion src/bucket3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static SDWORD bucketCalculateZ(RENDER_TYPE objectType, void *pObject, const glm:
position.z = -(psSimpObj->pos.y);
position.y = psSimpObj->pos.z;

psBStats = getBodyStats(psDroid);
psBStats = psDroid->getBodyStats();
droidSize = psBStats->pIMD->radius;
z = pie_RotateProjectWithPerspective(&position, perspectiveViewMatrix, &pixel) - (droidSize * 2);

Expand Down
2 changes: 1 addition & 1 deletion src/cmddroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ SDWORD cmdDroidGetIndex(const DROID *psCommander)
/** This function returns the maximum group size of the command droid.*/
unsigned int cmdDroidMaxGroup(const DROID *psCommander)
{
const BRAIN_STATS *psStats = getBrainStats(psCommander);
const BRAIN_STATS *psStats = psCommander->getBrainStats();
return getDroidLevel(psCommander) * psStats->upgrade[psCommander->player].maxDroidsMult + psStats->upgrade[psCommander->player].maxDroids;
}

Expand Down
2 changes: 1 addition & 1 deletion src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ int objArmour(const BASE_OBJECT *psObj, WEAPON_CLASS weaponClass)
int armour = 0;
if (psObj->type == OBJ_DROID)
{
armour = bodyArmour(*getBodyStats((const DROID*)psObj), psObj->player, weaponClass);
armour = bodyArmour(*((const DROID*)psObj)->getBodyStats(), psObj->player, weaponClass);
}
else if (psObj->type == OBJ_STRUCTURE && weaponClass == WC_KINETIC && ((const STRUCTURE *)psObj)->status != SS_BEING_BUILT)
{
Expand Down
4 changes: 2 additions & 2 deletions src/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static bool displayCompObj(DROID *psDroid, bool bButton, const glm::mat4& modelM
}

/* get propulsion stats */
psPropStats = getPropulsionStats(psDroid);
psPropStats = psDroid->getPropulsionStats();
ASSERT_OR_RETURN(didDrawSomething, psPropStats != nullptr, "invalid propulsion stats pointer");

//set pieflag for button object or ingame object
Expand Down Expand Up @@ -531,7 +531,7 @@ static bool displayCompObj(DROID *psDroid, bool bButton, const glm::mat4& modelM
}

/* Render animation effects based on movement or lack thereof, if any */
const auto* bodyStats = getBodyStats(psDroid);
const auto* bodyStats = psDroid->getBodyStats();
psMoveAnim = bodyStats->ppMoveIMDList[psDroid->asBits[COMP_PROPULSION]];
psStillAnim = bodyStats->ppStillIMDList[psDroid->asBits[COMP_PROPULSION]];
if (!bButton && psMoveAnim && psDroid->sMove.Status != MOVEINACTIVE)
Expand Down
26 changes: 13 additions & 13 deletions src/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,32 @@ void drawMuzzleFlash(WEAPON sWeap, iIMDShape *weaponImd, iIMDShape *flashImd, PI
#define PART_IMD(STATS,DROID,COMPONENT,PLAYER) (STATS[DROID->asBits[COMPONENT]].pIMD)

/* Get the chassis imd */
#define BODY_IMD(DROID,PLAYER) (getBodyStats(DROID)->pIMD)
#define BODY_IMD(DROID,PLAYER) (DROID->getBodyStats()->pIMD)
/* Get the brain imd - NOTE: Unused!*/
#define BRAIN_IMD(DROID,PLAYER) (getBrainStats(DROID)->pIMD)
#define BRAIN_IMD(DROID,PLAYER) (DROID->getBrainStats()->pIMD)
/* Get the weapon imd */
#define WEAPON_IMD(DROID,WEAPON_NUM) (getWeaponStats(DROID, WEAPON_NUM)->pIMD)
#define WEAPON_IMD(DROID,WEAPON_NUM) (DROID->getWeaponStats(WEAPON_NUM)->pIMD)
/* Get the propulsion imd THIS IS A LITTLE MORE COMPLICATED NOW!*/
//#define PROPULSION_IMD(DROID,PLAYER) (asPropulsionStats[DROID->asBits[COMP_PROPULSION]].pIMD[PLAYER])
/* Get the sensor imd */
#define SENSOR_IMD(DROID,PLAYER) (getSensorStats(DROID)->pIMD)
#define SENSOR_IMD(DROID,PLAYER) (DROID->getSensorStats()->pIMD)
/* Get an ECM imd!?! */
#define ECM_IMD(DROID,PLAYER) (getECMStats(DROID)->pIMD)
#define ECM_IMD(DROID,PLAYER) (DROID->getECMStats()->pIMD)
/* Get an Repair imd!?! */
#define REPAIR_IMD(DROID,PLAYER) (getRepairStats(DROID)->pIMD)
#define REPAIR_IMD(DROID,PLAYER) (DROID->getRepairStats()->pIMD)
/* Get a construct imd */
#define CONSTRUCT_IMD(DROID,PLAYER) (getConstructStats(DROID)->pIMD)
#define CONSTRUCT_IMD(DROID,PLAYER) (DROID->getConstructStats()->pIMD)
/* Get a weapon mount imd*/
#define WEAPON_MOUNT_IMD(DROID,WEAPON_NUM) (getWeaponStats(DROID, WEAPON_NUM)->pMountGraphic)
#define WEAPON_MOUNT_IMD(DROID,WEAPON_NUM) (DROID->getWeaponStats(WEAPON_NUM)->pMountGraphic)
/* Get a sensor mount imd*/
#define SENSOR_MOUNT_IMD(DROID,PLAYER) (getSensorStats(DROID)->pMountGraphic)
#define SENSOR_MOUNT_IMD(DROID,PLAYER) (DROID->getSensorStats()->pMountGraphic)
/* Get a construct mount imd*/
#define CONSTRUCT_MOUNT_IMD(DROID,PLAYER) (getConstructStats(DROID)->pMountGraphic)
#define CONSTRUCT_MOUNT_IMD(DROID,PLAYER) (DROID->getConstructStats()->pMountGraphic)
/* Get a ecm mount imd*/
#define ECM_MOUNT_IMD(DROID,PLAYER) (getECMStats(DROID)->pMountGraphic)
#define ECM_MOUNT_IMD(DROID,PLAYER) (DROID->getECMStats()->pMountGraphic)
/* Get a repair mount imd*/
#define REPAIR_MOUNT_IMD(DROID,PLAYER) (getRepairStats(DROID)->pMountGraphic)
#define REPAIR_MOUNT_IMD(DROID,PLAYER) (DROID->getRepairStats()->pMountGraphic)
/* Get a muzzle flash pie*/
#define MUZZLE_FLASH_PIE(DROID,WEAPON_NUM) (getWeaponStats(DROID, WEAPON_NUM)->pMuzzleGraphic)
#define MUZZLE_FLASH_PIE(DROID,WEAPON_NUM) (DROID->getWeaponStats(WEAPON_NUM)->pMuzzleGraphic)

#endif // __INCLUDED_SRC_COMPONENT_H__
Loading
Loading