Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up actionVTOLLandingPos() interface.

Program logic should be unchanged.
  • Loading branch information...
commit ce3e76cd62293c107ce8c82ec564d39dad6779ee 1 parent 0b7605c
@Cyp Cyp authored
View
33 src/action.cpp
@@ -2120,16 +2120,15 @@ void actionUpdateDroid(DROID *psDroid)
if (DROID_STOPPED(psDroid) ||
(psDroid->action == DACTION_WAITFORREARM))
{
- UDWORD droidX = psDroid->psActionTarget[0]->pos.x;
- UDWORD droidY = psDroid->psActionTarget[0]->pos.y;
- if (!actionVTOLLandingPos(psDroid, &droidX, &droidY))
+ Vector2i pos = removeZ(psDroid->psActionTarget[0]->pos);
+ if (!actionVTOLLandingPos(psDroid, &pos))
{
// totally bunged up - give up
objTrace(psDroid->id, "Couldn't find a clear tile near rearm pad - returning to base");
orderDroid(psDroid, DORDER_RTB, ModeImmediate);
break;
}
- moveDroidToDirect(psDroid, droidX,droidY);
+ moveDroidToDirect(psDroid, pos.x, pos.y);
}
break;
default:
@@ -2174,7 +2173,7 @@ static void actionDroidBase(DROID *psDroid, DROID_ACTION_DATA *psAction)
{
SDWORD pbx,pby;
WEAPON_STATS *psWeapStats = getWeaponStats(psDroid, 0);
- UDWORD droidX,droidY;
+ Vector2i pos;
BASE_OBJECT *psTarget;
//added MinRangeResult;
UBYTE i;
@@ -2304,29 +2303,27 @@ static void actionDroidBase(DROID *psDroid, DROID_ACTION_DATA *psAction)
psDroid->actionPos = psAction->psObj->pos;
psDroid->actionStarted = gameTime;
setDroidActionTarget(psDroid, psAction->psObj, 0);
- droidX = psDroid->psActionTarget[0]->pos.x;
- droidY = psDroid->psActionTarget[0]->pos.y;
- if (!actionVTOLLandingPos(psDroid, &droidX, &droidY))
+ pos = removeZ(psDroid->psActionTarget[0]->pos);
+ if (!actionVTOLLandingPos(psDroid, &pos))
{
// totally bunged up - give up
orderDroid(psDroid, DORDER_RTB, ModeImmediate);
break;
}
- moveDroidToDirect(psDroid, droidX, droidY);
+ moveDroidToDirect(psDroid, pos.x, pos.y);
break;
case DACTION_CLEARREARMPAD:
debug( LOG_NEVER, "Unit %d clearing rearm pad", psDroid->id);
psDroid->action = DACTION_CLEARREARMPAD;
setDroidActionTarget(psDroid, psAction->psObj, 0);
- droidX = psDroid->psActionTarget[0]->pos.x;
- droidY = psDroid->psActionTarget[0]->pos.y;
- if (!actionVTOLLandingPos(psDroid, &droidX, &droidY))
+ pos = removeZ(psDroid->psActionTarget[0]->pos);
+ if (!actionVTOLLandingPos(psDroid, &pos))
{
// totally bunged up - give up
orderDroid(psDroid, DORDER_RTB, ModeImmediate);
break;
}
- moveDroidToDirect(psDroid, droidX, droidY);
+ moveDroidToDirect(psDroid, pos.x, pos.y);
break;
case DACTION_MOVE:
case DACTION_TRANSPORTIN:
@@ -2710,7 +2707,7 @@ static bool vtolLandingTileSearchFunction(int x, int y, void* matchState)
}
// choose a landing position for a VTOL when it goes to rearm
-bool actionVTOLLandingPos(const DROID* psDroid, UDWORD* px, UDWORD* py)
+bool actionVTOLLandingPos(DROID const *psDroid, Vector2i *p)
{
int startX, startY;
DROID* psCurr;
@@ -2720,8 +2717,8 @@ bool actionVTOLLandingPos(const DROID* psDroid, UDWORD* px, UDWORD* py)
CHECK_DROID(psDroid);
/* Initial box dimensions and set iteration count to zero */
- startX = map_coord(*px);
- startY = map_coord(*py);
+ startX = map_coord(p->x);
+ startY = map_coord(p->y);
// set blocking flags for all the other droids
for(psCurr=apsDroidLists[psDroid->player]; psCurr; psCurr = psCurr->psNext)
@@ -2751,8 +2748,8 @@ bool actionVTOLLandingPos(const DROID* psDroid, UDWORD* px, UDWORD* py)
{
debug( LOG_NEVER, "Unit %d landing pos (%d,%d)",
psDroid->id, xyCoords.x, xyCoords.y);
- *px = world_coord(xyCoords.x) + TILE_UNITS / 2;
- *py = world_coord(xyCoords.y) + TILE_UNITS / 2;
+ p->x = world_coord(xyCoords.x) + TILE_UNITS / 2;
+ p->y = world_coord(xyCoords.y) + TILE_UNITS / 2;
}
// clear blocking flags for all the other droids
View
2  src/action.h
@@ -96,7 +96,7 @@ bool actionReachedBuildPos(DROID const *psDroid, int x, int y, uint16_t directio
void moveToRearm(DROID *psDroid);
/** Choose a landing position for a VTOL when it goes to rearm. */
-bool actionVTOLLandingPos(const DROID* psDroid, UDWORD* px, UDWORD* py);
+bool actionVTOLLandingPos(DROID const *psDroid, Vector2i *p);
/** How many frames to skip before looking for a better target. */
#define TARGET_UPD_SKIP_FRAMES 1000
View
9 src/move.cpp
@@ -328,7 +328,6 @@ static void moveShuffleDroid(DROID *psDroid, Vector2i s)
bool frontClear = true, leftClear = true, rightClear = true;
SDWORD lvx,lvy, rvx,rvy, svx,svy;
SDWORD shuffleMove;
- SDWORD tarX,tarY;
CHECK_DROID(psDroid);
@@ -414,11 +413,10 @@ static void moveShuffleDroid(DROID *psDroid, Vector2i s)
}
// check the location for vtols
- tarX = (SDWORD)psDroid->pos.x + mx;
- tarY = (SDWORD)psDroid->pos.y + my;
+ Vector2i tar = removeZ(psDroid->pos) + Vector2i(mx, my);
if (isVtolDroid(psDroid))
{
- actionVTOLLandingPos(psDroid, (UDWORD *)&tarX,(UDWORD *)&tarY);
+ actionVTOLLandingPos(psDroid, &tar);
}
@@ -429,8 +427,7 @@ static void moveShuffleDroid(DROID *psDroid, Vector2i s)
}
psDroid->sMove.Status = MOVESHUFFLE;
psDroid->sMove.src = removeZ(psDroid->pos);
- psDroid->sMove.target.x = tarX;
- psDroid->sMove.target.y = tarY;
+ psDroid->sMove.target = tar;
psDroid->sMove.numPoints = 0;
psDroid->sMove.pathIndex = 0;
View
15 src/order.cpp
@@ -1625,16 +1625,15 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
{
if (psStruct->pStructureType->type == REF_HQ)
{
- UDWORD droidX = psStruct->pos.x;
- UDWORD droidY = psStruct->pos.y;
+ Vector2i pos = removeZ(psStruct->pos);
psDroid->order = *psOrder;
// Find a place to land for vtols. And Transporters in a multiPlay game.
if (isVtolDroid(psDroid) || (game.type == SKIRMISH && (psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER)))
{
- actionVTOLLandingPos(psDroid, &droidX,&droidY);
+ actionVTOLLandingPos(psDroid, &pos);
}
- actionDroid(psDroid, DACTION_MOVE, droidX,droidY);
+ actionDroid(psDroid, DACTION_MOVE, pos.x, pos.y);
break;
}
}
@@ -1718,13 +1717,11 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
* repaired, need to find a suitable location to drop down. */
if (game.type == SKIRMISH && (psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER))
{
- UDWORD droidX, droidY;
- droidX = psDroid->order.pos.x;
- droidY = psDroid->order.pos.y;
+ Vector2i pos = psDroid->order.pos;
objTrace(psDroid->id, "Repair transport");
- actionVTOLLandingPos(psDroid, &droidX,&droidY);
- actionDroid(psDroid, DACTION_MOVE, droidX,droidY);
+ actionVTOLLandingPos(psDroid, &pos);
+ actionDroid(psDroid, DACTION_MOVE, pos.x, pos.y);
}
else
{
View
7 src/structure.cpp
@@ -2440,11 +2440,10 @@ static bool structPlaceDroid(STRUCTURE *psStructure, DROID_TEMPLATE *psTempl,
if (isVtolDroid(psNewDroid))
{
- UDWORD droidX = psFlag->coords.x;
- UDWORD droidY = psFlag->coords.y;
+ Vector2i pos = removeZ(psFlag->coords);
//find a suitable location near the delivery point
- actionVTOLLandingPos(psNewDroid, &droidX, &droidY);
- orderDroidLoc(psNewDroid, DORDER_MOVE, droidX, droidY, ModeQueue);
+ actionVTOLLandingPos(psNewDroid, &pos);
+ orderDroidLoc(psNewDroid, DORDER_MOVE, pos.x, pos.y, ModeQueue);
}
else
{
Please sign in to comment.
Something went wrong with that request. Please try again.