Skip to content

[GEN] Backports redundant call reductions from ZH #750

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class JetAIUpdate : public AIUpdateInterface
virtual Bool isTemporarilyPreventingAimSuccess() const;
virtual Bool isDoingGroundMovement() const;
virtual void notifyVictimIsDead();
virtual Bool isOutOfSpecialReloadAmmo() const;

const Coord3D* friend_getProducerLocation() const { return &m_producerLocation; }
Real friend_getOutOfAmmoDamagePerSecond() const { return getJetAIUpdateModuleData()->m_outOfAmmoDamagePerSecond; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,
MemoryPoolObjectHolder hold(iter);
for( them = iter->first(); them; them = iter->next() )
{
Relationship rel = builderObject ? builderObject->getRelationship( them ) : NEUTRAL;

// ignore any kind of class of objects that we will "remove" for building
if( isRemovableForConstruction( them ) == TRUE )
Expand All @@ -695,7 +696,7 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,

// an immobile object may obstruct our building depending on flags.
if( them->isKindOf( KINDOF_IMMOBILE ) ) {
if (onlyCheckEnemies && builderObject && builderObject->getRelationship( them ) != ENEMIES ) {
if (onlyCheckEnemies && builderObject && rel != ENEMIES ) {
continue;
}
TheTerrainVisual->addFactionBib(them, true);
Expand All @@ -706,7 +707,7 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,
// if this is an enemy object of the builder object (and therefore the thing
// that will be constructed) we can't build here
//
if( builderObject && builderObject->getRelationship( them ) == ENEMIES ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good change. I suggest to sync Generals to Zero Hour.

if( builderObject && rel == ENEMIES ) {
TheTerrainVisual->addFactionBib(them, true);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,11 +1028,12 @@ CommandAvailability ControlBar::getCommandAvailability( const CommandButton *com
{
case GUI_COMMAND_DOZER_CONSTRUCT:
{
const ThingTemplate * whatToBuild = command->getThingTemplate();
// if the command is a dozer construct task and the object dozer is building anything
// this command is not available
if(command->getThingTemplate())
if(whatToBuild)
{
BuildableStatus bStatus = command->getThingTemplate()->getBuildable();
BuildableStatus bStatus = whatToBuild->getBuildable();
if (bStatus == BSTATUS_NO || (bStatus == BSTATUS_ONLY_BY_AI && obj->getControllingPlayer()->getPlayerType() != PLAYER_COMPUTER))
return COMMAND_HIDDEN;
}
Expand All @@ -1057,10 +1058,10 @@ CommandAvailability ControlBar::getCommandAvailability( const CommandButton *com
return COMMAND_RESTRICTED;

// return whether or not the player can build this thing
if( player->canBuild( command->getThingTemplate() ) == FALSE )
if( player->canBuild( whatToBuild ) == FALSE )
return COMMAND_RESTRICTED;

if( !player->canAffordBuild( command->getThingTemplate() ) )
if( !player->canAffordBuild( whatToBuild ) )
{
return COMMAND_RESTRICTED;//COMMAND_CANT_AFFORD;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ UpdateSleepTime AutoHealBehavior::update( void )
if( owningPlayer )
{
AutoHealPlayerScanHelper helper;
helper.m_kindOfToTest = getAutoHealBehaviorModuleData()->m_kindOf;
helper.m_kindOfToTest = d->m_kindOf;
helper.m_objectList = &objectsToHeal;
helper.m_theHealer = getObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,12 @@ UpdateSleepTime SlowDeathBehavior::update()
//-------------------------------------------------------------------------------------------------
void SlowDeathBehavior::onDie( const DamageInfo *damageInfo )
{
Object *obj = getObject();

if (!isDieApplicable(damageInfo))
return;

AIUpdateInterface *ai = getObject()->getAIUpdateInterface();
AIUpdateInterface *ai = obj->getAIUpdateInterface();
if (ai)
{
// has another AI already handled us. (hopefully another SlowDeathBehavior)
Expand All @@ -492,10 +494,10 @@ void SlowDeathBehavior::onDie( const DamageInfo *damageInfo )
}

// deselect this unit for all players.
TheGameLogic->deselectObject(getObject(), PLAYERMASK_ALL, TRUE);
TheGameLogic->deselectObject(obj, PLAYERMASK_ALL, TRUE);

Int total = 0;
BehaviorModule** update = getObject()->getBehaviorModules();
BehaviorModule** update = obj->getBehaviorModules();
for (; *update; ++update)
{
SlowDeathBehaviorInterface* sdu = (*update)->getSlowDeathBehaviorInterface();
Expand All @@ -510,7 +512,7 @@ void SlowDeathBehavior::onDie( const DamageInfo *damageInfo )
// this returns a value from 1...total, inclusive
Int roll = GameLogicRandomValue(1, total);

for (/* UpdateModuleInterface** */ update = getObject()->getBehaviorModules(); *update; ++update)
for (/* UpdateModuleInterface** */ update = obj->getBehaviorModules(); *update; ++update)
{
SlowDeathBehaviorInterface* sdu = (*update)->getSlowDeathBehaviorInterface();
if (sdu != NULL && sdu->isDieApplicable(damageInfo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,9 @@ void OpenContain::orderAllPassengersToExit( CommandSourceType commandSource )
//-------------------------------------------------------------------------------------------------
void OpenContain::processDamageToContained()
{
const OpenContainModuleData *data = getOpenContainModuleData();
Real percentDamage = data->m_damagePercentageToUnits;

const ContainedItemsList* items = getContainedItemsList();
if( items )
{
Expand All @@ -1290,7 +1293,7 @@ void OpenContain::processDamageToContained()
++it;

//Calculate the damage to be inflicted on each unit.
Real damage = object->getBodyModule()->getMaxHealth() * getOpenContainModuleData()->m_damagePercentageToUnits;
Real damage = object->getBodyModule()->getMaxHealth() * percentDamage;

DamageInfo damageInfo;
damageInfo.in.m_damageType = DAMAGE_UNRESISTABLE;
Expand All @@ -1299,7 +1302,7 @@ void OpenContain::processDamageToContained()
damageInfo.in.m_amount = damage;
object->attemptDamage( &damageInfo );

if( !object->isEffectivelyDead() && getOpenContainModuleData()->m_damagePercentageToUnits == 1.0f )
if( !object->isEffectivelyDead() && percentDamage == 1.0f )
object->kill(); // in case we are carrying flame proof troops we have been asked to kill
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ CreateObjectDie::~CreateObjectDie( void )
//-------------------------------------------------------------------------------------------------
void CreateObjectDie::onDie( const DamageInfo * damageInfo )
{
const CreateObjectDieModuleData *data = getCreateObjectDieModuleData();
if (!isDieApplicable(damageInfo))
return;

Object *damageDealer = TheGameLogic->findObjectByID( damageInfo->in.m_sourceID );

ObjectCreationList::create(getCreateObjectDieModuleData()->m_ocl, getObject(), damageDealer);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good change. I suggest to sync Generals to Zero Hour.

ObjectCreationList::create( data->m_ocl, getObject(), damageDealer );
} // end onDie

// ------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ DestroyDie::~DestroyDie( void )
//-------------------------------------------------------------------------------------------------
void DestroyDie::onDie( const DamageInfo *damageInfo )
{
Object *obj = getObject();
if (!isDieApplicable(damageInfo))
return;
TheGameLogic->destroyObject(getObject());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good change. I suggest to sync Generals to Zero Hour.

TheGameLogic->destroyObject( obj );
}

// ------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Int FiringTracker::getNumConsecutiveShotsAtVictim( const Object *victim ) const
void FiringTracker::shotFired(const Weapon* weaponFired, ObjectID victimID)
{
UnsignedInt now = TheGameLogic->getFrame();
Object *me = getObject();

if( victimID == m_victimID )
{
Expand Down Expand Up @@ -117,15 +118,15 @@ void FiringTracker::shotFired(const Weapon* weaponFired, ObjectID victimID)
Int shotsNeededOne = weaponFired->getContinuousFireOneShotsNeeded();
Int shotsNeededTwo = weaponFired->getContinuousFireTwoShotsNeeded();

if( getObject()->testWeaponBonusCondition( WEAPONBONUSCONDITION_CONTINUOUS_FIRE_MEAN ) )
if( me->testWeaponBonusCondition( WEAPONBONUSCONDITION_CONTINUOUS_FIRE_MEAN ) )
{
// Can either go up or down from here.
if( m_consecutiveShots < shotsNeededOne )
coolDown();
else if( m_consecutiveShots > shotsNeededTwo )
speedUp();
}
else if( getObject()->testWeaponBonusCondition( WEAPONBONUSCONDITION_CONTINUOUS_FIRE_FAST ) )
else if( me->testWeaponBonusCondition( WEAPONBONUSCONDITION_CONTINUOUS_FIRE_FAST ) )
{
// Only place I can go here from here is all the way down
if( m_consecutiveShots < shotsNeededTwo )
Expand Down Expand Up @@ -161,7 +162,7 @@ void FiringTracker::shotFired(const Weapon* weaponFired, ObjectID victimID)
}


setWakeFrame(getObject(), calcTimeToSleep());
setWakeFrame(me, calcTimeToSleep());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just note: The Zero Hour developer forgot replacing a few getObject() above.

}

//-------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3945,12 +3945,14 @@ void AIUpdateInterface::privateHackInternet( CommandSourceType cmdSource )
/// if we are attacking "fromID", stop that and attack "toID" instead
void AIUpdateInterface::transferAttack(ObjectID fromID, ObjectID toID)
{
Object *newTarget = TheGameLogic->findObjectByID( toID );

if (m_currentVictimID == fromID)
m_currentVictimID = toID;

Object* goalObj = getStateMachine()->getGoalObject();
if (goalObj && goalObj->getID() == fromID)
getStateMachine()->setGoalObject(TheGameLogic->findObjectByID(toID));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good change. I suggest to sync Generals to Zero Hour.

getStateMachine()->setGoalObject( newTarget );
}

//----------------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,17 @@ enum JetAIStateType CPP_11(: Int)
};

//-------------------------------------------------------------------------------------------------
static Bool isOutOfSpecialReloadAmmo(Object* jet)
Bool JetAIUpdate::isOutOfSpecialReloadAmmo() const
{
const Object* jet = getObject();
// if we have at least one special reload weapon,
// AND all such weapons are out of ammo,
// return true.
Int specials = 0;
Int out = 0;
for( Int i = 0; i < WEAPONSLOT_COUNT; i++ )
{
Weapon* weapon = jet->getWeaponInWeaponSlot((WeaponSlotType)i);
const Weapon* weapon = jet->getWeaponInWeaponSlot((WeaponSlotType)i);
if (weapon == NULL || weapon->getReloadType() != RETURN_TO_BASE_TO_RELOAD)
continue;
++specials;
Expand Down Expand Up @@ -300,7 +301,7 @@ class JetOrHeliCirclingDeadAirfieldState : public State
// it might not have an owning airfield, and it might be trying to return
// simply due to being idle, not out of ammo. so check and don't die in that
// case, but just punt back out to idle.
if (!isOutOfSpecialReloadAmmo(jet) && jet->getProducerID() == INVALID_ID)
if (!jetAI->isOutOfSpecialReloadAmmo() && jet->getProducerID() == INVALID_ID)
{
return STATE_FAILURE;
}
Expand Down Expand Up @@ -1656,7 +1657,7 @@ UpdateSleepTime JetAIUpdate::update()
}

// note that we might still have weapons with ammo, but still be forced to return to reload.
if (isOutOfSpecialReloadAmmo(jet) && getFlag(ALLOW_AIR_LOCO))
if (isOutOfSpecialReloadAmmo() && getFlag(ALLOW_AIR_LOCO))
{
m_returnToBaseFrame = 0;

Expand All @@ -1682,7 +1683,7 @@ UpdateSleepTime JetAIUpdate::update()
else if (m_returnToBaseFrame != 0 && now >= m_returnToBaseFrame && getFlag(ALLOW_AIR_LOCO))
{
m_returnToBaseFrame = 0;
DEBUG_ASSERTCRASH(isOutOfSpecialReloadAmmo(jet) == false, ("Hmm, this seems unlikely -- isOutOfSpecialReloadAmmo(jet)==false"));
DEBUG_ASSERTCRASH(isOutOfSpecialReloadAmmo() == false, ("Hmm, this seems unlikely -- isOutOfSpecialReloadAmmo()==false"));
setFlag(USE_SPECIAL_RETURN_LOCO, false);
setLastCommandSource( CMD_FROM_AI );
getStateMachine()->setState(RETURNING_FOR_LANDING);
Expand All @@ -1700,7 +1701,7 @@ UpdateSleepTime JetAIUpdate::update()
}
m_returnToBaseFrame = 0;
if (getFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD) &&
isOutOfSpecialReloadAmmo(jet) && getFlag(ALLOW_AIR_LOCO))
isOutOfSpecialReloadAmmo() && getFlag(ALLOW_AIR_LOCO))
{
setFlag(USE_SPECIAL_RETURN_LOCO, true);
setFlag(HAS_PENDING_COMMAND, true);
Expand Down Expand Up @@ -2101,7 +2102,7 @@ void JetAIUpdate::doLandingCommand(Object *airfield, CommandSourceType cmdSource
}

getObject()->setProducer(airfield);
DEBUG_ASSERTCRASH(isOutOfSpecialReloadAmmo(getObject()) == false, ("Hmm, this seems unlikely -- isOutOfSpecialReloadAmmo(jet)==false"));
DEBUG_ASSERTCRASH(isOutOfSpecialReloadAmmo() == false, ("Hmm, this seems unlikely -- isOutOfSpecialReloadAmmo()==false"));
setFlag(USE_SPECIAL_RETURN_LOCO, false);
setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, false);
setLastCommandSource( cmdSource );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void AutoDepositUpdate::awardInitialCaptureBonus( Player *player )
//-------------------------------------------------------------------------------------------------
UpdateSleepTime AutoDepositUpdate::update( void )
{
const AutoDepositUpdateModuleData *modData = getAutoDepositUpdateModuleData();
/// @todo srj use SLEEPY_UPDATE here
if( TheGameLogic->getFrame() >= m_depositOnFrame)
{
Expand All @@ -125,23 +126,25 @@ UpdateSleepTime AutoDepositUpdate::update( void )
m_awardInitialCaptureBonus = TRUE;
m_initialized = TRUE;
}
m_depositOnFrame = TheGameLogic->getFrame() + getAutoDepositUpdateModuleData()->m_depositFrame;
m_depositOnFrame = TheGameLogic->getFrame() + modData->m_depositFrame;

if(getObject()->isNeutralControlled() || getAutoDepositUpdateModuleData()->m_depositAmount <= 0 )
if(getObject()->isNeutralControlled() || modData->m_depositAmount <= 0 )
return UPDATE_SLEEP_NONE;

// makes sure that buildings under construction do not get a bonus CCB
if( getObject()->getConstructionPercent() != CONSTRUCTION_COMPLETE )
return UPDATE_SLEEP_NONE;

getObject()->getControllingPlayer()->getMoney()->deposit( getAutoDepositUpdateModuleData()->m_depositAmount);
getObject()->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( getAutoDepositUpdateModuleData()->m_depositAmount);

int moneyAmount = modData->m_depositAmount;

getObject()->getControllingPlayer()->getMoney()->deposit( moneyAmount );
getObject()->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( modData->m_depositAmount);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just note: Here the Zero Hour developer forgot refactor.


//Display cash income floating over the blacklotus
if(getAutoDepositUpdateModuleData()->m_depositAmount > 0)
if(moneyAmount > 0)
{
UnicodeString moneyString;
moneyString.format( TheGameText->fetch( "GUI:AddCash" ), getAutoDepositUpdateModuleData()->m_depositAmount );
moneyString.format( TheGameText->fetch( "GUI:AddCash" ), moneyAmount );
Coord3D pos;
pos.set( getObject()->getPosition() );
pos.z += 10.0f; //add a little z to make it show up above the unit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ Coord3D DockUpdate::computeApproachPosition( Int positionIndex, Object *forWhom
// ------------------------------------------------------------------------------------------------
void DockUpdate::loadDockPositions()
{
Drawable *myDrawable = getObject()->getDrawable();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary change. I suggest copy Generals to Zero Hour.

Object *obj = getObject();
Drawable *myDrawable = obj->getDrawable();

if (myDrawable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,17 +669,17 @@ AsciiString GameSpyStagingRoom::generateGameSpyGameResultsPacket( void )
Int gsPlayerID = slot->getProfileID();
Bool disconnected = slot->disconnected();

AsciiString result = "loss", side = "USA";
AsciiString result = "loss";
if (disconnected)
result = "discon";
else if (TheNetwork->sawCRCMismatch())
result = "desync";
else if (TheVictoryConditions->hasAchievedVictory(p))
result = "win";

side = p->getPlayerTemplate()->getSide();
AsciiString side = p->getPlayerTemplate()->getSide();
if (side == "America")
side = "USA";
side = "USA"; //conform to GameSpy

AsciiString playerStr;
playerStr.format("\\player_%d\\%s\\pid_%d\\%d\\team_%d\\%d\\result_%d\\%s\\side_%d\\%s",
Expand Down
Loading