Skip to content

Commit fc50831

Browse files
committed
[GEN][ZH] Remove unnecessary NULL pointer tests in AIPathfind, AIPlayer, AIStates
1 parent 0a97cd0 commit fc50831

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
@@ -5607,10 +5607,10 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
56075607
const Object *obj, Int attackDistance)
56085608
{
56095609
Bool canPathThroughUnits = false;
5610-
if (obj && obj->getAIUpdateInterface()) {
5610+
if (obj->getAIUpdateInterface()) {
56115611
canPathThroughUnits = obj->getAIUpdateInterface()->canPathThroughUnits();
56125612
}
5613-
Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
5613+
Bool isCrusher = obj->getCrusherLevel() > 0;
56145614
if (attackDistance==NO_ATTACK && !m_isTunneling && !locomotorSet.isDownhillOnly() && goalCell) {
56155615
ExamineCellsStruct info;
56165616
info.thePathfinder = this;
@@ -8772,7 +8772,7 @@ Bool Pathfinder::isViewBlockedByObstacle(const Object* obj, const Object* objOth
87728772
ViewBlockedStruct info;
87738773
info.obj = obj;
87748774
info.objOther = objOther;
8775-
if (objOther && objOther->isSignificantlyAboveTerrain()) {
8775+
if (objOther->isSignificantlyAboveTerrain()) {
87768776
return false; // We don't check los to flying objects. jba.
87778777
}
87788778
#if 1
@@ -9587,14 +9587,14 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
95879587
Int startTimeMS = ::GetTickCount();
95889588
#endif
95899589
Bool isHuman = true;
9590-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
9590+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
95919591
isHuman = false; // computer gets to cheat.
95929592
}
95939593
Bool otherCenter;
95949594
Int otherRadius;
95959595
getRadiusAndCenter(otherObj, otherRadius, otherCenter);
95969596

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

95999599
m_zoneManager.setAllPassable();
96009600

@@ -9672,12 +9672,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
96729672
bounds.hi.y = cellCenter.y+boxHalfWidth;
96739673
PathNode *node;
96749674
Bool overlap = false;
9675-
if (obj) {
9676-
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
9677-
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
9678-
//overlap = true;
9679-
}
9675+
9676+
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
9677+
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
9678+
//overlap = true;
96809679
}
9680+
96819681
for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
96829682
Coord2D start, end;
96839683
start.x = node->getPosition()->x;
@@ -9689,12 +9689,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
96899689
break;
96909690
}
96919691
}
9692-
if (otherObj) {
9693-
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
9694-
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
9695-
//overlap = true;
9696-
}
9692+
9693+
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
9694+
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
9695+
//overlap = true;
96979696
}
9697+
96989698
if (!overlap && pathToAvoid2) {
96999699
for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
97009700
Coord2D start, end;
@@ -9766,7 +9766,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
97669766
Int radius;
97679767
getRadiusAndCenter(obj, radius, centerInCell);
97689768
Bool isHuman = true;
9769-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
9769+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
97709770
isHuman = false; // computer gets to cheat.
97719771
}
97729772

@@ -9978,7 +9978,7 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
99789978
// Int startTimeMS = ::GetTickCount();
99799979
#endif
99809980

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

1003110031
Bool isHuman = true;
10032-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10032+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1003310033
isHuman = false; // computer gets to cheat.
1003410034
}
1003510035
m_zoneManager.clearPassableFlags();
@@ -10255,7 +10255,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1025510255
Real repulsorDistSqr = repulsorRadius*repulsorRadius;
1025610256
Int cellCount = 0;
1025710257
Bool isHuman = true;
10258-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10258+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1025910259
isHuman = false; // computer gets to cheat.
1026010260
}
1026110261

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,7 @@ void AIPlayer::checkQueuedTeams( void )
25432543
for ( DLINK_ITERATOR<TeamInQueue> iter = iterate_TeamBuildQueue(); !iter.done(); iter.advance())
25442544
{
25452545
TeamInQueue *team = iter.cur();
2546-
if (team && team->isAllBuilt())
2546+
if (team->isAllBuilt())
25472547
{
25482548
// Move to ready queue
25492549
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
@@ -5076,7 +5076,7 @@ StateReturnType AIAttackFireWeaponState::update()
50765076
rather than addressing the situation, we just punt and wait for it to clear
50775077
up on its own.
50785078
*/
5079-
if (m_att && !m_att->isWeaponSlotOkToFire(wslot))
5079+
if (!m_att->isWeaponSlotOkToFire(wslot))
50805080
{
50815081
return STATE_FAILURE;
50825082
}
@@ -5096,7 +5096,7 @@ StateReturnType AIAttackFireWeaponState::update()
50965096
(victim->isDestroyed() || victim->isEffectivelyDead() || (victim->isKindOf(KINDOF_MINE) && victim->testStatus(OBJECT_STATUS_MASKED)))
50975097
)
50985098
{
5099-
const Coord3D* originalVictimPos = m_att ? m_att->getOriginalVictimPos() : NULL;
5099+
const Coord3D* originalVictimPos = m_att->getOriginalVictimPos();
51005100
if (originalVictimPos)
51015101
{
51025102
// 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
@@ -6125,10 +6125,10 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
61256125
const Object *obj, Int attackDistance)
61266126
{
61276127
Bool canPathThroughUnits = false;
6128-
if (obj && obj->getAIUpdateInterface()) {
6128+
if (obj->getAIUpdateInterface()) {
61296129
canPathThroughUnits = obj->getAIUpdateInterface()->canPathThroughUnits();
61306130
}
6131-
Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
6131+
Bool isCrusher = obj->getCrusherLevel() > 0;
61326132
if (attackDistance==NO_ATTACK && !m_isTunneling && !locomotorSet.isDownhillOnly() && goalCell) {
61336133
ExamineCellsStruct info;
61346134
info.thePathfinder = this;
@@ -9399,7 +9399,7 @@ Bool Pathfinder::isViewBlockedByObstacle(const Object* obj, const Object* objOth
93999399
ViewBlockedStruct info;
94009400
info.obj = obj;
94019401
info.objOther = objOther;
9402-
if (objOther && objOther->isSignificantlyAboveTerrain()) {
9402+
if (objOther->isSignificantlyAboveTerrain()) {
94039403
return false; // We don't check los to flying objects. jba.
94049404
}
94059405
#if 1
@@ -10236,14 +10236,14 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1023610236
Int startTimeMS = ::GetTickCount();
1023710237
#endif
1023810238
Bool isHuman = true;
10239-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10239+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1024010240
isHuman = false; // computer gets to cheat.
1024110241
}
1024210242
Bool otherCenter;
1024310243
Int otherRadius;
1024410244
getRadiusAndCenter(otherObj, otherRadius, otherCenter);
1024510245

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

1024810248
m_zoneManager.setAllPassable();
1024910249

@@ -10321,12 +10321,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1032110321
bounds.hi.y = cellCenter.y+boxHalfWidth;
1032210322
PathNode *node;
1032310323
Bool overlap = false;
10324-
if (obj) {
10325-
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
10326-
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
10327-
//overlap = true;
10328-
}
10324+
10325+
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
10326+
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
10327+
//overlap = true;
1032910328
}
10329+
1033010330
for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
1033110331
Coord2D start, end;
1033210332
start.x = node->getPosition()->x;
@@ -10338,12 +10338,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1033810338
break;
1033910339
}
1034010340
}
10341-
if (otherObj) {
10342-
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
10343-
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
10344-
//overlap = true;
10345-
}
10341+
10342+
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
10343+
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
10344+
//overlap = true;
1034610345
}
10346+
1034710347
if (!overlap && pathToAvoid2) {
1034810348
for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
1034910349
Coord2D start, end;
@@ -10415,7 +10415,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1041510415
Int radius;
1041610416
getRadiusAndCenter(obj, radius, centerInCell);
1041710417
Bool isHuman = true;
10418-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10418+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1041910419
isHuman = false; // computer gets to cheat.
1042010420
}
1042110421

@@ -10627,7 +10627,7 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1062710627
// Int startTimeMS = ::GetTickCount();
1062810628
#endif
1062910629

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

1068010680
Bool isHuman = true;
10681-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10681+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1068210682
isHuman = false; // computer gets to cheat.
1068310683
}
1068410684
m_zoneManager.clearPassableFlags();
@@ -10962,7 +10962,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1096210962
Real repulsorDistSqr = repulsorRadius*repulsorRadius;
1096310963
Int cellCount = 0;
1096410964
Bool isHuman = true;
10965-
if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
10965+
if (obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) {
1096610966
isHuman = false; // computer gets to cheat.
1096710967
}
1096810968

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ void AIPlayer::checkQueuedTeams( void )
28722872
for ( DLINK_ITERATOR<TeamInQueue> iter = iterate_TeamBuildQueue(); !iter.done(); iter.advance())
28732873
{
28742874
TeamInQueue *team = iter.cur();
2875-
if (team && team->isAllBuilt())
2875+
if (team->isAllBuilt())
28762876
{
28772877
// Move to ready queue
28782878
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
@@ -5231,7 +5231,7 @@ StateReturnType AIAttackFireWeaponState::update()
52315231
rather than addressing the situation, we just punt and wait for it to clear
52325232
up on its own.
52335233
*/
5234-
if (m_att && !m_att->isWeaponSlotOkToFire(wslot))
5234+
if (!m_att->isWeaponSlotOkToFire(wslot))
52355235
{
52365236
return STATE_FAILURE;
52375237
}
@@ -5269,7 +5269,7 @@ StateReturnType AIAttackFireWeaponState::update()
52695269
(victim->isDestroyed() || victim->isEffectivelyDead() || (victim->isKindOf(KINDOF_MINE) && victim->testStatus(OBJECT_STATUS_MASKED)))
52705270
)
52715271
{
5272-
const Coord3D* originalVictimPos = m_att ? m_att->getOriginalVictimPos() : NULL;
5272+
const Coord3D* originalVictimPos = m_att->getOriginalVictimPos();
52735273
if (originalVictimPos)
52745274
{
52755275
// note that it is important to use getLastCommandSource here; this allows

0 commit comments

Comments
 (0)