Skip to content

[GEN][ZH] Remove unnecessary NULL pointer tests in AIPathfind, AIPlayer, AIStates #1095

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 19 additions & 19 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5612,10 +5612,10 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
const Object *obj, Int attackDistance)
{
Bool canPathThroughUnits = false;
if (obj && obj->getAIUpdateInterface()) {
if (obj->getAIUpdateInterface()) {
canPathThroughUnits = obj->getAIUpdateInterface()->canPathThroughUnits();
}
Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
Bool isCrusher = obj->getCrusherLevel() > 0;
if (attackDistance==NO_ATTACK && !m_isTunneling && !locomotorSet.isDownhillOnly() && goalCell) {
ExamineCellsStruct info;
info.thePathfinder = this;
Expand Down Expand Up @@ -8777,7 +8777,7 @@ Bool Pathfinder::isViewBlockedByObstacle(const Object* obj, const Object* objOth
ViewBlockedStruct info;
info.obj = obj;
info.objOther = objOther;
if (objOther && objOther->isSignificantlyAboveTerrain()) {
if (objOther->isSignificantlyAboveTerrain()) {
return false; // We don't check los to flying objects. jba.
}
#if 1
Expand Down Expand Up @@ -9592,14 +9592,14 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
Int startTimeMS = ::GetTickCount();
#endif
Bool isHuman = true;
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
isHuman = false; // computer gets to cheat.
}
Bool otherCenter;
Int otherRadius;
getRadiusAndCenter(otherObj, otherRadius, otherCenter);

Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
Bool isCrusher = obj->getCrusherLevel() > 0;

m_zoneManager.setAllPassable();

Expand Down Expand Up @@ -9677,12 +9677,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
bounds.hi.y = cellCenter.y+boxHalfWidth;
PathNode *node;
Bool overlap = false;
if (obj) {
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
//overlap = true;
}

if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
//overlap = true;
}

for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
Coord2D start, end;
start.x = node->getPosition()->x;
Expand All @@ -9694,12 +9694,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
break;
}
}
if (otherObj) {
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
//overlap = true;
}

if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
//overlap = true;
}

if (!overlap && pathToAvoid2) {
for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
Coord2D start, end;
Expand Down Expand Up @@ -9771,7 +9771,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
Int radius;
getRadiusAndCenter(obj, radius, centerInCell);
Bool isHuman = true;
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
isHuman = false; // computer gets to cheat.
}

Expand Down Expand Up @@ -9983,7 +9983,7 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
// Int startTimeMS = ::GetTickCount();
#endif

Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
Bool isCrusher = obj->getCrusherLevel() > 0;
Int radius;
Bool centerInCell;
getRadiusAndCenter(obj, radius, centerInCell);
Expand Down Expand Up @@ -10034,7 +10034,7 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
const Int ATTACK_CELL_LIMIT = 2500; // this is a rather expensive operation, so limit the search.

Bool isHuman = true;
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
isHuman = false; // computer gets to cheat.
}
m_zoneManager.clearPassableFlags();
Expand Down Expand Up @@ -10260,7 +10260,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
Real repulsorDistSqr = repulsorRadius*repulsorRadius;
Int cellCount = 0;
Bool isHuman = true;
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
isHuman = false; // computer gets to cheat.
}

Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ void AIPlayer::checkQueuedTeams( void )
for ( DLINK_ITERATOR<TeamInQueue> iter = iterate_TeamBuildQueue(); !iter.done(); iter.advance())
{
TeamInQueue *team = iter.cur();
if (team && team->isAllBuilt())
if (team->isAllBuilt())
{
// Move to ready queue
removeFrom_TeamBuildQueue(team);
Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5071,7 +5071,7 @@ StateReturnType AIAttackFireWeaponState::update()
rather than addressing the situation, we just punt and wait for it to clear
up on its own.
*/
if (m_att && !m_att->isWeaponSlotOkToFire(wslot))
if (!m_att->isWeaponSlotOkToFire(wslot))
{
return STATE_FAILURE;
}
Expand All @@ -5091,7 +5091,7 @@ StateReturnType AIAttackFireWeaponState::update()
(victim->isDestroyed() || victim->isEffectivelyDead() || (victim->isKindOf(KINDOF_MINE) && victim->testStatus(OBJECT_STATUS_MASKED)))
)
{
const Coord3D* originalVictimPos = m_att ? m_att->getOriginalVictimPos() : NULL;
const Coord3D* originalVictimPos = m_att->getOriginalVictimPos();
if (originalVictimPos)
{
// note that it is important to use getLastCommandSource here; this allows
Expand Down
38 changes: 19 additions & 19 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6130,10 +6130,10 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
const Object *obj, Int attackDistance)
{
Bool canPathThroughUnits = false;
if (obj && obj->getAIUpdateInterface()) {
if (obj->getAIUpdateInterface()) {
canPathThroughUnits = obj->getAIUpdateInterface()->canPathThroughUnits();
}
Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
Bool isCrusher = obj->getCrusherLevel() > 0;
if (attackDistance==NO_ATTACK && !m_isTunneling && !locomotorSet.isDownhillOnly() && goalCell) {
ExamineCellsStruct info;
info.thePathfinder = this;
Expand Down Expand Up @@ -9404,7 +9404,7 @@ Bool Pathfinder::isViewBlockedByObstacle(const Object* obj, const Object* objOth
ViewBlockedStruct info;
info.obj = obj;
info.objOther = objOther;
if (objOther && objOther->isSignificantlyAboveTerrain()) {
if (objOther->isSignificantlyAboveTerrain()) {
return false; // We don't check los to flying objects. jba.
}
#if 1
Expand Down Expand Up @@ -10241,14 +10241,14 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
Int startTimeMS = ::GetTickCount();
#endif
Bool isHuman = true;
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
isHuman = false; // computer gets to cheat.
}
Bool otherCenter;
Int otherRadius;
getRadiusAndCenter(otherObj, otherRadius, otherCenter);

Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
Bool isCrusher = obj->getCrusherLevel() > 0;

m_zoneManager.setAllPassable();

Expand Down Expand Up @@ -10326,12 +10326,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
bounds.hi.y = cellCenter.y+boxHalfWidth;
PathNode *node;
Bool overlap = false;
if (obj) {
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
//overlap = true;
}

if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
//overlap = true;
}

for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
Coord2D start, end;
start.x = node->getPosition()->x;
Expand All @@ -10343,12 +10343,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
break;
}
}
if (otherObj) {
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
//overlap = true;
}

if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
//overlap = true;
}

if (!overlap && pathToAvoid2) {
for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
Coord2D start, end;
Expand Down Expand Up @@ -10420,7 +10420,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
Int radius;
getRadiusAndCenter(obj, radius, centerInCell);
Bool isHuman = true;
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
isHuman = false; // computer gets to cheat.
}

Expand Down Expand Up @@ -10632,7 +10632,7 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
// Int startTimeMS = ::GetTickCount();
#endif

Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
Bool isCrusher = obj->getCrusherLevel() > 0;
Int radius;
Bool centerInCell;
getRadiusAndCenter(obj, radius, centerInCell);
Expand Down Expand Up @@ -10683,7 +10683,7 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
const Int ATTACK_CELL_LIMIT = 2500; // this is a rather expensive operation, so limit the search.

Bool isHuman = true;
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
isHuman = false; // computer gets to cheat.
}
m_zoneManager.clearPassableFlags();
Expand Down Expand Up @@ -10967,7 +10967,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
Real repulsorDistSqr = repulsorRadius*repulsorRadius;
Int cellCount = 0;
Bool isHuman = true;
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
isHuman = false; // computer gets to cheat.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,7 @@ void AIPlayer::checkQueuedTeams( void )
for ( DLINK_ITERATOR<TeamInQueue> iter = iterate_TeamBuildQueue(); !iter.done(); iter.advance())
{
TeamInQueue *team = iter.cur();
if (team && team->isAllBuilt())
if (team->isAllBuilt())
{
// Move to ready queue
removeFrom_TeamBuildQueue(team);
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5226,7 +5226,7 @@ StateReturnType AIAttackFireWeaponState::update()
rather than addressing the situation, we just punt and wait for it to clear
up on its own.
*/
if (m_att && !m_att->isWeaponSlotOkToFire(wslot))
if (!m_att->isWeaponSlotOkToFire(wslot))
{
return STATE_FAILURE;
}
Expand Down Expand Up @@ -5264,7 +5264,7 @@ StateReturnType AIAttackFireWeaponState::update()
(victim->isDestroyed() || victim->isEffectivelyDead() || (victim->isKindOf(KINDOF_MINE) && victim->testStatus(OBJECT_STATUS_MASKED)))
)
{
const Coord3D* originalVictimPos = m_att ? m_att->getOriginalVictimPos() : NULL;
const Coord3D* originalVictimPos = m_att->getOriginalVictimPos();
if (originalVictimPos)
{
// note that it is important to use getLastCommandSource here; this allows
Expand Down
Loading