Skip to content

Commit 2c2dd8a

Browse files
committed
[GEN][ZH] Remove unnecessary NULL pointer tests in AIPathfind, AIPlayer, AIStates
1 parent ef5fea1 commit 2c2dd8a

File tree

6 files changed

+44
-44
lines changed

6 files changed

+44
-44
lines changed

Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,10 +5612,10 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
56125612
const Object *obj, Int attackDistance)
56135613
{
56145614
Bool canPathThroughUnits = false;
5615-
if (obj && obj->getAIUpdateInterface()) {
5615+
if (obj->getAIUpdateInterface()) {
56165616
canPathThroughUnits = obj->getAIUpdateInterface()->canPathThroughUnits();
56175617
}
5618-
Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
5618+
Bool isCrusher = obj->getCrusherLevel() > 0;
56195619
if (attackDistance==NO_ATTACK && !m_isTunneling && !locomotorSet.isDownhillOnly() && goalCell) {
56205620
ExamineCellsStruct info;
56215621
info.thePathfinder = this;
@@ -8777,7 +8777,7 @@ Bool Pathfinder::isViewBlockedByObstacle(const Object* obj, const Object* objOth
87778777
ViewBlockedStruct info;
87788778
info.obj = obj;
87798779
info.objOther = objOther;
8780-
if (objOther && objOther->isSignificantlyAboveTerrain()) {
8780+
if (objOther->isSignificantlyAboveTerrain()) {
87818781
return false; // We don't check los to flying objects. jba.
87828782
}
87838783
#if 1
@@ -9592,14 +9592,14 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
95929592
Int startTimeMS = ::GetTickCount();
95939593
#endif
95949594
Bool isHuman = true;
9595-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
9595+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
95969596
isHuman = false; // computer gets to cheat.
95979597
}
95989598
Bool otherCenter;
95999599
Int otherRadius;
96009600
getRadiusAndCenter(otherObj, otherRadius, otherCenter);
96019601

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

96049604
m_zoneManager.setAllPassable();
96059605

@@ -9677,12 +9677,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
96779677
bounds.hi.y = cellCenter.y+boxHalfWidth;
96789678
PathNode *node;
96799679
Bool overlap = false;
9680-
if (obj) {
9681-
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
9682-
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
9683-
//overlap = true;
9684-
}
9680+
9681+
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
9682+
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
9683+
//overlap = true;
96859684
}
9685+
96869686
for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
96879687
Coord2D start, end;
96889688
start.x = node->getPosition()->x;
@@ -9694,12 +9694,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
96949694
break;
96959695
}
96969696
}
9697-
if (otherObj) {
9698-
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
9699-
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
9700-
//overlap = true;
9701-
}
9697+
9698+
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
9699+
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
9700+
//overlap = true;
97029701
}
9702+
97039703
if (!overlap && pathToAvoid2) {
97049704
for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
97059705
Coord2D start, end;
@@ -9771,7 +9771,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
97719771
Int radius;
97729772
getRadiusAndCenter(obj, radius, centerInCell);
97739773
Bool isHuman = true;
9774-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
9774+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
97759775
isHuman = false; // computer gets to cheat.
97769776
}
97779777

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

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

1003610036
Bool isHuman = true;
10037-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10037+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1003810038
isHuman = false; // computer gets to cheat.
1003910039
}
1004010040
m_zoneManager.clearPassableFlags();
@@ -10260,7 +10260,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1026010260
Real repulsorDistSqr = repulsorRadius*repulsorRadius;
1026110261
Int cellCount = 0;
1026210262
Bool isHuman = true;
10263-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10263+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1026410264
isHuman = false; // computer gets to cheat.
1026510265
}
1026610266

Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ void AIPlayer::checkQueuedTeams( void )
25442544
for ( DLINK_ITERATOR<TeamInQueue> iter = iterate_TeamBuildQueue(); !iter.done(); iter.advance())
25452545
{
25462546
TeamInQueue *team = iter.cur();
2547-
if (team && team->isAllBuilt())
2547+
if (team->isAllBuilt())
25482548
{
25492549
// Move to ready queue
25502550
removeFrom_TeamBuildQueue(team);

Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5071,7 +5071,7 @@ StateReturnType AIAttackFireWeaponState::update()
50715071
rather than addressing the situation, we just punt and wait for it to clear
50725072
up on its own.
50735073
*/
5074-
if (m_att && !m_att->isWeaponSlotOkToFire(wslot))
5074+
if (!m_att->isWeaponSlotOkToFire(wslot))
50755075
{
50765076
return STATE_FAILURE;
50775077
}
@@ -5091,7 +5091,7 @@ StateReturnType AIAttackFireWeaponState::update()
50915091
(victim->isDestroyed() || victim->isEffectivelyDead() || (victim->isKindOf(KINDOF_MINE) && victim->testStatus(OBJECT_STATUS_MASKED)))
50925092
)
50935093
{
5094-
const Coord3D* originalVictimPos = m_att ? m_att->getOriginalVictimPos() : NULL;
5094+
const Coord3D* originalVictimPos = m_att->getOriginalVictimPos();
50955095
if (originalVictimPos)
50965096
{
50975097
// note that it is important to use getLastCommandSource here; this allows

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6130,10 +6130,10 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
61306130
const Object *obj, Int attackDistance)
61316131
{
61326132
Bool canPathThroughUnits = false;
6133-
if (obj && obj->getAIUpdateInterface()) {
6133+
if (obj->getAIUpdateInterface()) {
61346134
canPathThroughUnits = obj->getAIUpdateInterface()->canPathThroughUnits();
61356135
}
6136-
Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
6136+
Bool isCrusher = obj->getCrusherLevel() > 0;
61376137
if (attackDistance==NO_ATTACK && !m_isTunneling && !locomotorSet.isDownhillOnly() && goalCell) {
61386138
ExamineCellsStruct info;
61396139
info.thePathfinder = this;
@@ -9404,7 +9404,7 @@ Bool Pathfinder::isViewBlockedByObstacle(const Object* obj, const Object* objOth
94049404
ViewBlockedStruct info;
94059405
info.obj = obj;
94069406
info.objOther = objOther;
9407-
if (objOther && objOther->isSignificantlyAboveTerrain()) {
9407+
if (objOther->isSignificantlyAboveTerrain()) {
94089408
return false; // We don't check los to flying objects. jba.
94099409
}
94109410
#if 1
@@ -10241,14 +10241,14 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1024110241
Int startTimeMS = ::GetTickCount();
1024210242
#endif
1024310243
Bool isHuman = true;
10244-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10244+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1024510245
isHuman = false; // computer gets to cheat.
1024610246
}
1024710247
Bool otherCenter;
1024810248
Int otherRadius;
1024910249
getRadiusAndCenter(otherObj, otherRadius, otherCenter);
1025010250

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

1025310253
m_zoneManager.setAllPassable();
1025410254

@@ -10326,12 +10326,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1032610326
bounds.hi.y = cellCenter.y+boxHalfWidth;
1032710327
PathNode *node;
1032810328
Bool overlap = false;
10329-
if (obj) {
10330-
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
10331-
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
10332-
//overlap = true;
10333-
}
10329+
10330+
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
10331+
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
10332+
//overlap = true;
1033410333
}
10334+
1033510335
for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
1033610336
Coord2D start, end;
1033710337
start.x = node->getPosition()->x;
@@ -10343,12 +10343,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1034310343
break;
1034410344
}
1034510345
}
10346-
if (otherObj) {
10347-
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
10348-
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
10349-
//overlap = true;
10350-
}
10346+
10347+
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
10348+
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
10349+
//overlap = true;
1035110350
}
10351+
1035210352
if (!overlap && pathToAvoid2) {
1035310353
for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
1035410354
Coord2D start, end;
@@ -10420,7 +10420,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1042010420
Int radius;
1042110421
getRadiusAndCenter(obj, radius, centerInCell);
1042210422
Bool isHuman = true;
10423-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10423+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1042410424
isHuman = false; // computer gets to cheat.
1042510425
}
1042610426

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

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

1068510685
Bool isHuman = true;
10686-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10686+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1068710687
isHuman = false; // computer gets to cheat.
1068810688
}
1068910689
m_zoneManager.clearPassableFlags();
@@ -10967,7 +10967,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1096710967
Real repulsorDistSqr = repulsorRadius*repulsorRadius;
1096810968
Int cellCount = 0;
1096910969
Bool isHuman = true;
10970-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10970+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1097110971
isHuman = false; // computer gets to cheat.
1097210972
}
1097310973

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2873,7 +2873,7 @@ void AIPlayer::checkQueuedTeams( void )
28732873
for ( DLINK_ITERATOR<TeamInQueue> iter = iterate_TeamBuildQueue(); !iter.done(); iter.advance())
28742874
{
28752875
TeamInQueue *team = iter.cur();
2876-
if (team && team->isAllBuilt())
2876+
if (team->isAllBuilt())
28772877
{
28782878
// Move to ready queue
28792879
removeFrom_TeamBuildQueue(team);

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5226,7 +5226,7 @@ StateReturnType AIAttackFireWeaponState::update()
52265226
rather than addressing the situation, we just punt and wait for it to clear
52275227
up on its own.
52285228
*/
5229-
if (m_att && !m_att->isWeaponSlotOkToFire(wslot))
5229+
if (!m_att->isWeaponSlotOkToFire(wslot))
52305230
{
52315231
return STATE_FAILURE;
52325232
}
@@ -5264,7 +5264,7 @@ StateReturnType AIAttackFireWeaponState::update()
52645264
(victim->isDestroyed() || victim->isEffectivelyDead() || (victim->isKindOf(KINDOF_MINE) && victim->testStatus(OBJECT_STATUS_MASKED)))
52655265
)
52665266
{
5267-
const Coord3D* originalVictimPos = m_att ? m_att->getOriginalVictimPos() : NULL;
5267+
const Coord3D* originalVictimPos = m_att->getOriginalVictimPos();
52685268
if (originalVictimPos)
52695269
{
52705270
// note that it is important to use getLastCommandSource here; this allows

0 commit comments

Comments
 (0)