Restructure function visGetBlockingWall:

* return a pointer instead of a BOOL (will be a NULL pointer on failure)
 * don't `goto` the end of the function when we've found a blocking wall, just return the pointer instead


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4569 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-04-12 13:26:08 +00:00
parent cfbb1aa1ac
commit 7fa6ce0c65
4 changed files with 21 additions and 24 deletions

View File

@ -246,7 +246,8 @@ SDWORD aiBestNearestTarget(DROID *psDroid, BASE_OBJECT **ppsObj, int weapon_slot
{
ASSERT(!bestTarget->died, "aiBestNearestTarget: AI gave us a target that is already dead.");
/* See if target is blocked by a wall; only affects direct weapons */
if(proj_Direct( asWeaponStats + psDroid->asWeaps[weapon_slot].nStat) && visGetBlockingWall((BASE_OBJECT *)psDroid, bestTarget, &targetStructure) )
if (proj_Direct(asWeaponStats + psDroid->asWeaps[weapon_slot].nStat)
&& (targetStructure = visGetBlockingWall((BASE_OBJECT *)psDroid, bestTarget)))
{
//are we any good against walls?
if(asStructStrengthModifier[weaponEffect][targetStructure->pStructureType->strength] >= 100) //can attack atleast with default strength

View File

@ -741,11 +741,11 @@ void orderUpdateDroid(DROID *psDroid)
// that the unit will fire on other things while moving
actionDroidLoc(psDroid, DACTION_MOVE, psDroid->psTarget->pos.x, psDroid->psTarget->pos.y);
}
else if (!vtolDroid(psDroid) &&
(psDroid->psTarget == psDroid->psActionTarget[0]) &&
actionInRange(psDroid, psDroid->psTarget, 0) &&
visGetBlockingWall((BASE_OBJECT *)psDroid, psDroid->psTarget, &psWall) &&
(psWall->player != psDroid->player))
else if (!vtolDroid(psDroid)
&& psDroid->psTarget == psDroid->psActionTarget[0]
&& actionInRange(psDroid, psDroid->psTarget, 0)
&& (psWall = visGetBlockingWall((BASE_OBJECT *)psDroid, psDroid->psTarget))
&& psWall->player != psDroid->player)
{
// there is a wall in the way - attack that
actionDroidObj(psDroid, DACTION_ATTACK, (BASE_OBJECT *)psWall);

View File

@ -422,40 +422,36 @@ BOOL visibleObjWallBlock(BASE_OBJECT *psViewer, BASE_OBJECT *psTarget)
}
// Find the wall that is blocking LOS to a target (if any)
BOOL visGetBlockingWall(BASE_OBJECT *psViewer, BASE_OBJECT *psTarget, STRUCTURE **ppsWall)
STRUCTURE* visGetBlockingWall(BASE_OBJECT* psViewer, BASE_OBJECT* psTarget)
{
SDWORD tileX, tileY, player;
STRUCTURE *psCurr, *psWall;
blockingWall = true;
numWalls = 0;
visibleObject(psViewer, psTarget);
blockingWall = false;
// see if there was a wall in the way
psWall = NULL;
if (numWalls == 1)
{
tileX = map_coord(wallX);
tileY = map_coord(wallY);
for(player=0; player<MAX_PLAYERS; player += 1)
const int tileX = map_coord(wallX);
const int tileY = map_coord(wallY);
unsigned int player;
for (player = 0; player < MAX_PLAYERS; ++player)
{
for(psCurr = apsStructLists[player]; psCurr; psCurr = psCurr->psNext)
STRUCTURE* psWall;
for (psWall = apsStructLists[player]; psWall; psWall = psWall->psNext)
{
if (map_coord(psCurr->pos.x) == tileX
&& map_coord(psCurr->pos.y) == tileY)
if (map_coord(psWall->pos.x) == tileX
&& map_coord(psWall->pos.y) == tileY)
{
psWall = psCurr;
goto found;
return psWall;
}
}
}
}
found:
*ppsWall = psWall;
return psWall != NULL;;
return NULL;
}
/* Find out what can see this object */

View File

@ -48,7 +48,7 @@ extern BOOL visibleObjectBlock(BASE_OBJECT *psViewer, BASE_OBJECT *psTarget,
extern BOOL visibleObjWallBlock(BASE_OBJECT *psViewer, BASE_OBJECT *psTarget);
// Find the wall that is blocking LOS to a target (if any)
extern BOOL visGetBlockingWall(BASE_OBJECT *psViewer, BASE_OBJECT *psTarget, STRUCTURE **ppsWall);
extern STRUCTURE* visGetBlockingWall(BASE_OBJECT* psViewer, BASE_OBJECT* psTarget);
extern void processVisibility(BASE_OBJECT *psCurr);