@@ -4415,7 +4415,10 @@ Bool Pathfinder::checkForMovement(const Object *obj, TCheckMovementInfo &info)
44154415 ObjectID allies[maxAlly];
44164416 Int numAlly = 0 ;
44174417
4418- if (!obj) return true ; // not object can move there.
4418+ if (!obj) {
4419+ return true ; // not object can move there.
4420+ }
4421+
44194422 ObjectID ignoreId = INVALID_ID;
44204423 if (obj->getAIUpdateInterface ()) {
44214424 ignoreId = obj->getAIUpdateInterface ()->getIgnoredObstacleID ();
@@ -4428,81 +4431,86 @@ Bool Pathfinder::checkForMovement(const Object *obj, TCheckMovementInfo &info)
44284431 for (i=info.cell .x -info.radius ; i<info.cell .x +numCellsAbove; i++) {
44294432 for (j=info.cell .y -info.radius ; j<info.cell .y +numCellsAbove; j++) {
44304433 PathfindCell *cell = getCell (info.layer ,i, j);
4431- if (cell) {
4432- enum PathfindCell::CellFlags flags = cell->getFlags ();
4433- ObjectID posUnit = cell->getPosUnit ();
4434- if ((flags == PathfindCell::UNIT_GOAL) || (flags == PathfindCell::UNIT_GOAL_OTHER_MOVING)) {
4435- info.allyGoal = true ;
4436- }
4437- if (flags == PathfindCell::NO_UNITS) {
4438- continue ; // Nobody is here, so it's ok.
4439- } else if (posUnit==obj->getID ()) {
4440- continue ; // we got it.
4441- } else if (posUnit==ignoreId) {
4442- continue ; // we are ignoring this one.
4443- } else {
4444- Bool check = false ;
4445- Object *unit = NULL ;
4446- if (flags==PathfindCell::UNIT_PRESENT_MOVING || flags==PathfindCell::UNIT_GOAL_OTHER_MOVING) {
4447- unit = TheGameLogic->findObjectByID (posUnit);
4448- // order matters: we want to know if I consider it to be an ally, not vice versa
4449- if (unit && obj->getRelationship (unit) == ALLIES) {
4450- info.allyMoving = true ;
4451- }
4452- if (info.considerTransient ) {
4453- check = true ;
4454- }
4455- }
4456- if (flags == PathfindCell::UNIT_PRESENT_FIXED) {
4457- check = true ;
4458- unit = TheGameLogic->findObjectByID (posUnit);
4459- }
4460- if (check && unit!=NULL ) {
4461- if (obj->getAIUpdateInterface () && obj->getAIUpdateInterface ()->getIgnoredObstacleID ()==unit->getID ()) {
4462- // Don't check if it's the ignored obstacle.
4463- check = false ;
4464- }
4465- }
4466- if (check && unit) {
4434+ if (!cell) {
4435+ return false ; // off the map, so can't move here.
4436+ }
4437+
4438+ PathfindCell::CellFlags flags = cell->getFlags ();
4439+ if ((flags == PathfindCell::UNIT_GOAL) || (flags == PathfindCell::UNIT_GOAL_OTHER_MOVING)) {
4440+ info.allyGoal = true ;
4441+ } else if (flags == PathfindCell::NO_UNITS) {
4442+ continue ; // Nobody is here, so it's ok.
4443+ }
4444+
4445+ ObjectID posUnit = cell->getPosUnit ();
4446+ if (posUnit == obj->getID ()) {
4447+ continue ; // we got it.
4448+ }
4449+
4450+ if (posUnit == ignoreId) {
4451+ continue ; // we are ignoring this one.
4452+ }
4453+
4454+ Bool check = false ;
4455+ Object *unit = NULL ;
4456+ if (flags == PathfindCell::UNIT_PRESENT_MOVING || flags == PathfindCell::UNIT_GOAL_OTHER_MOVING) {
4457+ unit = TheGameLogic->findObjectByID (posUnit);
4458+ // order matters: we want to know if I consider it to be an ally, not vice versa
4459+ if (unit && obj->getRelationship (unit) == ALLIES) {
4460+ info.allyMoving = true ;
4461+ }
4462+ if (info.considerTransient ) {
4463+ check = true ;
4464+ }
4465+ }
4466+ if (flags == PathfindCell::UNIT_PRESENT_FIXED) {
4467+ check = true ;
4468+ unit = TheGameLogic->findObjectByID (posUnit);
4469+ }
4470+ if (check && unit!=NULL ) {
4471+ if (obj->getAIUpdateInterface () && obj->getAIUpdateInterface ()->getIgnoredObstacleID ()==unit->getID ()) {
4472+ // Don't check if it's the ignored obstacle.
4473+ check = false ;
4474+ }
4475+ }
4476+ if (!check || !unit) {
4477+ continue ;
4478+ }
4479+
44674480#ifdef INFANTRY_MOVES_THROUGH_INFANTRY
4468- if (obj->isKindOf (KINDOF_INFANTRY) && unit->isKindOf (KINDOF_INFANTRY)) {
4469- // Infantry can run through infantry.
4470- continue ; //
4471- }
4481+ if (obj->isKindOf (KINDOF_INFANTRY) && unit->isKindOf (KINDOF_INFANTRY)) {
4482+ // Infantry can run through infantry.
4483+ continue ; //
4484+ }
44724485#endif
4473- // See if it is an ally.
4474- // order matters: we want to know if I consider it to be an ally, not vice versa
4475- if (obj->getRelationship (unit) == ALLIES) {
4476- if (!unit->getAIUpdateInterface ()) {
4477- return false ; // can't path through not-idle units.
4478- }
4479- if (!unit->getAIUpdateInterface ()->isIdle ()) {
4480- return false ; // can't path through not-idle units.
4481- }
4482- Bool found = false ;
4483- Int k;
4484- for (k=0 ; k<numAlly; k++) {
4485- if (allies[k] == unit->getID ()) {
4486- found = true ;
4487- }
4488- }
4489- if (!found) {
4490- info.allyFixedCount ++;
4491- if (numAlly < maxAlly) {
4492- allies[numAlly] = unit->getID ();
4493- numAlly++;
4494- }
4495- }
4496- } else {
4497- Bool canCrush = obj->canCrushOrSquish ( unit, TEST_CRUSH_OR_SQUISH );
4498- if (!canCrush) {
4499- info.enemyFixed = true ;
4500- }
4501- }
4486+ // See if it is an ally.
4487+ // order matters: we want to know if I consider it to be an ally, not vice versa
4488+ if (obj->getRelationship (unit) == ALLIES) {
4489+ if (!unit->getAIUpdateInterface ()) {
4490+ return false ; // can't path through not-idle units.
4491+ }
4492+ if (!unit->getAIUpdateInterface ()->isIdle ()) {
4493+ return false ; // can't path through not-idle units.
4494+ }
4495+ Bool found = false ;
4496+ Int k;
4497+ for (k=0 ; k<numAlly; k++) {
4498+ if (allies[k] == unit->getID ()) {
4499+ found = true ;
4500+ }
4501+ }
4502+ if (!found) {
4503+ info.allyFixedCount ++;
4504+ if (numAlly < maxAlly) {
4505+ allies[numAlly] = unit->getID ();
4506+ numAlly++;
45024507 }
45034508 }
45044509 } else {
4505- return false ; // off the map, so can't place here.
4510+ Bool canCrush = obj->canCrushOrSquish ( unit, TEST_CRUSH_OR_SQUISH );
4511+ if (!canCrush) {
4512+ info.enemyFixed = true ;
4513+ }
45064514 }
45074515 }
45084516 }
0 commit comments