@@ -4698,7 +4698,10 @@ Bool Pathfinder::checkForMovement(const Object *obj, TCheckMovementInfo &info)
46984698 ObjectID allies[maxAlly];
46994699 Int numAlly = 0 ;
47004700
4701- if (!obj) return true ; // not object can move there.
4701+ if (!obj) {
4702+ return true ; // not object can move there.
4703+ }
4704+
47024705 ObjectID ignoreId = INVALID_ID;
47034706 if (obj->getAIUpdateInterface ()) {
47044707 ignoreId = obj->getAIUpdateInterface ()->getIgnoredObstacleID ();
@@ -4711,78 +4714,85 @@ Bool Pathfinder::checkForMovement(const Object *obj, TCheckMovementInfo &info)
47114714 for (i=info.cell .x -info.radius ; i<info.cell .x +numCellsAbove; i++) {
47124715 for (j=info.cell .y -info.radius ; j<info.cell .y +numCellsAbove; j++) {
47134716 PathfindCell *cell = getCell (info.layer ,i, j);
4714- if (cell) {
4715- enum PathfindCell::CellFlags flags = cell->getFlags ();
4716- ObjectID posUnit = cell->getPosUnit ();
4717- if ((flags == PathfindCell::UNIT_GOAL) || (flags == PathfindCell::UNIT_GOAL_OTHER_MOVING)) {
4718- info.allyGoal = true ;
4719- }
4720- if (flags == PathfindCell::NO_UNITS) {
4721- continue ; // Nobody is here, so it's ok.
4722- } else if (posUnit==obj->getID ()) {
4723- continue ; // we got it.
4724- } else if (posUnit==ignoreId) {
4725- continue ; // we are ignoring this one.
4726- } else {
4727- Bool check = false ;
4728- Object *unit = NULL ;
4729- if (flags==PathfindCell::UNIT_PRESENT_MOVING || flags==PathfindCell::UNIT_GOAL_OTHER_MOVING) {
4730- unit = TheGameLogic->findObjectByID (posUnit);
4731- // order matters: we want to know if I consider it to be an ally, not vice versa
4732- if (unit && obj->getRelationship (unit) == ALLIES) {
4733- info.allyMoving = true ;
4734- }
4735- if (info.considerTransient ) {
4736- check = true ;
4737- }
4738- }
4739- if (flags == PathfindCell::UNIT_PRESENT_FIXED) {
4740- check = true ;
4741- unit = TheGameLogic->findObjectByID (posUnit);
4742- }
4743- if (check && unit!=NULL ) {
4744- if (obj->getAIUpdateInterface () && obj->getAIUpdateInterface ()->getIgnoredObstacleID ()==unit->getID ()) {
4745- // Don't check if it's the ignored obstacle.
4746- check = false ;
4747- }
4748- }
4749- if (check && unit) {
4717+ if (!cell) {
4718+ return false ; // off the map, so can't move here.
4719+ }
4720+
4721+ PathfindCell::CellFlags flags = cell->getFlags ();
4722+ ObjectID posUnit = cell->getPosUnit ();
4723+ if ((flags == PathfindCell::UNIT_GOAL) || (flags == PathfindCell::UNIT_GOAL_OTHER_MOVING)) {
4724+ info.allyGoal = true ;
4725+ }
4726+
4727+ if (flags == PathfindCell::NO_UNITS) {
4728+ continue ; // Nobody is here, so it's ok.
4729+ }
4730+
4731+ if (posUnit == obj->getID ()) {
4732+ continue ; // we got it.
4733+ }
4734+
4735+ if (posUnit == ignoreId) {
4736+ continue ; // we are ignoring this one.
4737+ }
4738+
4739+ Bool check = false ;
4740+ Object *unit = NULL ;
4741+ if (flags == PathfindCell::UNIT_PRESENT_MOVING || flags == PathfindCell::UNIT_GOAL_OTHER_MOVING) {
4742+ unit = TheGameLogic->findObjectByID (posUnit);
4743+ // order matters: we want to know if I consider it to be an ally, not vice versa
4744+ if (unit && obj->getRelationship (unit) == ALLIES) {
4745+ info.allyMoving = true ;
4746+ }
4747+ if (info.considerTransient ) {
4748+ check = true ;
4749+ }
4750+ }
4751+ if (flags == PathfindCell::UNIT_PRESENT_FIXED) {
4752+ check = true ;
4753+ unit = TheGameLogic->findObjectByID (posUnit);
4754+ }
4755+ if (check && unit!=NULL ) {
4756+ if (obj->getAIUpdateInterface () && obj->getAIUpdateInterface ()->getIgnoredObstacleID ()==unit->getID ()) {
4757+ // Don't check if it's the ignored obstacle.
4758+ check = false ;
4759+ }
4760+ }
4761+ if (!check || !unit) {
4762+ continue ;
4763+ }
4764+
47504765#ifdef INFANTRY_MOVES_THROUGH_INFANTRY
4751- if (obj->isKindOf (KINDOF_INFANTRY) && unit->isKindOf (KINDOF_INFANTRY)) {
4752- // Infantry can run through infantry.
4753- continue ; //
4754- }
4766+ if (obj->isKindOf (KINDOF_INFANTRY) && unit->isKindOf (KINDOF_INFANTRY)) {
4767+ // Infantry can run through infantry.
4768+ continue ; //
4769+ }
47554770#endif
4756- // See if it is an ally.
4757- // order matters: we want to know if I consider it to be an ally, not vice versa
4758- if (obj->getRelationship (unit) == ALLIES) {
4759- if (!unit->getAIUpdateInterface ()) {
4760- return false ; // can't path through not-idle units.
4761- }
4762- Bool found = false ;
4763- Int k;
4764- for (k=0 ; k<numAlly; k++) {
4765- if (allies[k] == unit->getID ()) {
4766- found = true ;
4767- }
4768- }
4769- if (!found) {
4770- info.allyFixedCount ++;
4771- if (numAlly < maxAlly) {
4772- allies[numAlly] = unit->getID ();
4773- numAlly++;
4774- }
4775- }
4776- } else {
4777- Bool canCrush = obj->canCrushOrSquish ( unit, TEST_CRUSH_OR_SQUISH );
4778- if (!canCrush) {
4779- info.enemyFixed = true ;
4780- }
4781- }
4771+ // See if it is an ally.
4772+ // order matters: we want to know if I consider it to be an ally, not vice versa
4773+ if (obj->getRelationship (unit) == ALLIES) {
4774+ if (!unit->getAIUpdateInterface ()) {
4775+ return false ; // can't path through not-idle units.
4776+ }
4777+ Bool found = false ;
4778+ Int k;
4779+ for (k=0 ; k<numAlly; k++) {
4780+ if (allies[k] == unit->getID ()) {
4781+ found = true ;
4782+ }
4783+ }
4784+ if (!found) {
4785+ info.allyFixedCount ++;
4786+ if (numAlly < maxAlly) {
4787+ allies[numAlly] = unit->getID ();
4788+ numAlly++;
47824789 }
47834790 }
47844791 } else {
4785- return false ; // off the map, so can't place here.
4792+ Bool canCrush = obj->canCrushOrSquish ( unit, TEST_CRUSH_OR_SQUISH );
4793+ if (!canCrush) {
4794+ info.enemyFixed = true ;
4795+ }
47864796 }
47874797 }
47884798 }
0 commit comments