Permalink
Browse files

More trace points for rearm. Some code cleanup.

Also add a bit more info to debug menu. Things
used to track down the rearm bug previously.
  • Loading branch information...
perim committed Dec 31, 2017
1 parent 0b4012f commit f7f177176b289b65752d95f8c048506020669894
Showing with 69 additions and 36 deletions.
  1. +26 −19 src/action.cpp
  2. +5 −4 src/droid.cpp
  3. +5 −0 src/objects.cpp
  4. +2 −0 src/order.cpp
  5. +9 −1 src/qtscriptdebug.cpp
  6. +22 −12 src/structure.cpp
View
@@ -1132,8 +1132,7 @@ void actionUpdateDroid(DROID *psDroid)
}
case DACTION_MOVETOATTACK:
// send vtols back to rearm
if (isVtolDroid(psDroid) &&
vtolEmpty(psDroid))
if (isVtolDroid(psDroid) && vtolEmpty(psDroid))
{
moveToRearm(psDroid);
break;
@@ -1551,9 +1550,9 @@ void actionUpdateDroid(DROID *psDroid)
break;
case DACTION_MOVETOREARMPOINT:
/* moving to rearm pad */
if (DROID_STOPPED(psDroid))
{
objTrace(psDroid->id, "Finished moving onto the rearm pad");
psDroid->action = DACTION_WAITDURINGREARM;
}
break;
@@ -1755,15 +1754,17 @@ void actionUpdateDroid(DROID *psDroid)
break;
}
case DACTION_WAITFORREARM:
// wait here for the rearm pad to ask the vtol to move
// wait here for the rearm pad to instruct the vtol to move
if (psDroid->psActionTarget[0] == nullptr)
{
// rearm pad destroyed - move to another
objTrace(psDroid->id, "rearm pad gone - switch to new one");
moveToRearm(psDroid);
break;
}
if (DROID_STOPPED(psDroid) && vtolHappy(psDroid))
{
objTrace(psDroid->id, "do not need to rearm after all");
// don't actually need to rearm so just sit next to the rearm pad
psDroid->action = DACTION_NONE;
}
@@ -1772,6 +1773,7 @@ void actionUpdateDroid(DROID *psDroid)
if (DROID_STOPPED(psDroid))
{
psDroid->action = DACTION_NONE;
objTrace(psDroid->id, "clearing rearm pad");
if (!vtolHappy(psDroid)) // Droid has cleared the rearm pad without getting rearmed. One way this can happen if a rearming pad was built under the VTOL while it was waiting for a pad.
{
moveToRearm(psDroid); // Rearm somewhere else instead.
@@ -1785,6 +1787,7 @@ void actionUpdateDroid(DROID *psDroid)
if (psDroid->psActionTarget[0] == nullptr)
{
// base destroyed - find another
objTrace(psDroid->id, "rearm gone - find another");
moveToRearm(psDroid);
break;
}
@@ -1805,8 +1808,7 @@ void actionUpdateDroid(DROID *psDroid)
psDroid->action = DACTION_WAITFORREARM;
}
if (DROID_STOPPED(psDroid) ||
(psDroid->action == DACTION_WAITFORREARM))
if (DROID_STOPPED(psDroid) || psDroid->action == DACTION_WAITFORREARM)
{
Vector2i pos = psDroid->psActionTarget[0]->pos.xy;
if (!actionVTOLLandingPos(psDroid, &pos))
@@ -1816,6 +1818,7 @@ void actionUpdateDroid(DROID *psDroid)
orderDroid(psDroid, DORDER_RTB, ModeImmediate);
break;
}
objTrace(psDroid->id, "moving to rearm pad at %d,%d (%d,%d)", (int)pos.x, (int)pos.y, (int)(pos.x/TILE_UNITS), (int)(pos.y/TILE_UNITS));
moveDroidToDirect(psDroid, pos.x, pos.y);
}
break;
@@ -1868,6 +1871,7 @@ static void actionDroidBase(DROID *psDroid, DROID_ACTION_DATA *psAction)
psDroid->actionStarted = gameTime;
syncDebugDroid(psDroid, '-');
syncDebug("%d does %s", psDroid->id, getDroidActionName(psAction->action));
objTrace(psDroid->id, "base set action to %s (was %s)", getDroidActionName(psAction->action), getDroidActionName(psDroid->action));
DROID_ORDER_DATA *order = &psDroid->order;
@@ -1983,9 +1987,11 @@ static void actionDroidBase(DROID *psDroid, DROID_ACTION_DATA *psAction)
if (!actionVTOLLandingPos(psDroid, &pos))
{
// totally bunged up - give up
objTrace(psDroid->id, "move to rearm action failed!");
orderDroid(psDroid, DORDER_RTB, ModeImmediate);
break;
}
objTrace(psDroid->id, "move to rearm");
moveDroidToDirect(psDroid, pos.x, pos.y);
break;
case DACTION_CLEARREARMPAD:
@@ -1996,9 +2002,11 @@ static void actionDroidBase(DROID *psDroid, DROID_ACTION_DATA *psAction)
if (!actionVTOLLandingPos(psDroid, &pos))
{
// totally bunged up - give up
objTrace(psDroid->id, "clear rearm pad action failed!");
orderDroid(psDroid, DORDER_RTB, ModeImmediate);
break;
}
objTrace(psDroid->id, "move to clear rearm pad");
moveDroidToDirect(psDroid, pos.x, pos.y);
break;
case DACTION_MOVE:
@@ -2092,7 +2100,7 @@ static void actionDroidBase(DROID *psDroid, DROID_ACTION_DATA *psAction)
psDroid->action = DACTION_WAITDURINGREPAIR;
break;
case DACTION_MOVETOREARMPOINT:
debug(LOG_NEVER, "Unit %d moving to rearm point", psDroid->id);
objTrace(psDroid->id, "set to move to rearm pad");
psDroid->action = psAction->action;
psDroid->actionPos.x = psAction->x;
psDroid->actionPos.y = psAction->y;
@@ -2192,7 +2200,6 @@ void actionDroid(DROID *psDroid, DROID_ACTION action,
/*send the vtol droid back to the nearest rearming pad - if one otherwise
return to base*/
// IF YOU CHANGE THE ORDER/ACTION RESULTS TELL ALEXL!!!! && recvvtolrearm
void moveToRearm(DROID *psDroid)
{
CHECK_DROID(psDroid);
@@ -2234,6 +2241,7 @@ void moveToRearm(DROID *psDroid)
else
{
//return to base un-armed
objTrace(psDroid->id, "Did not find an available rearm pad - RTB instead");
orderDroid(psDroid, DORDER_RTB, ModeImmediate);
}
}
@@ -2242,18 +2250,16 @@ void moveToRearm(DROID *psDroid)
// whether a tile is suitable for a vtol to land on
static bool vtolLandingTile(SDWORD x, SDWORD y)
{
if (x < 0 || x >= (SDWORD)mapWidth ||
y < 0 || y >= (SDWORD)mapHeight)
if (x < 0 || x >= (SDWORD)mapWidth || y < 0 || y >= (SDWORD)mapHeight)
{
return false;
}
MAPTILE *psTile = mapTile(x, y);
if ((psTile->tileInfoBits & BITS_FPATHBLOCK) ||
(TileIsOccupied(psTile)) ||
(terrainType(psTile) == TER_CLIFFFACE) ||
(terrainType(psTile) == TER_WATER))
const MAPTILE *psTile = mapTile(x, y);
if (psTile->tileInfoBits & BITS_FPATHBLOCK ||
TileIsOccupied(psTile) ||
terrainType(psTile) == TER_CLIFFFACE ||
terrainType(psTile) == TER_WATER)
{
return false;
}
@@ -2347,7 +2353,8 @@ static bool vtolLandingTileSearchFunction(int x, int y, void *matchState)
return false;
}
// choose a landing position for a VTOL when it goes to rearm
// Choose a landing position for a VTOL when it goes to rearm that is close to rearm
// pad but not on it, since it may be busy by the time we get there.
bool actionVTOLLandingPos(DROID const *psDroid, Vector2i *p)
{
CHECK_DROID(psDroid);
@@ -2357,7 +2364,7 @@ bool actionVTOLLandingPos(DROID const *psDroid, Vector2i *p)
int startY = map_coord(p->y);
// set blocking flags for all the other droids
for (DROID *psCurr = apsDroidLists[psDroid->player]; psCurr; psCurr = psCurr->psNext)
for (const DROID *psCurr = apsDroidLists[psDroid->player]; psCurr; psCurr = psCurr->psNext)
{
Vector2i t;
if (DROID_STOPPED(psCurr))
@@ -2383,7 +2390,7 @@ bool actionVTOLLandingPos(DROID const *psDroid, Vector2i *p)
vtolLandingTileSearchFunction, &xyCoords);
if (foundTile)
{
debug(LOG_NEVER, "Unit %d landing pos (%d,%d)", psDroid->id, xyCoords.x, xyCoords.y);
objTrace(psDroid->id, "Unit %d landing pos (%d,%d)", psDroid->id, xyCoords.x, xyCoords.y);
p->x = world_coord(xyCoords.x) + TILE_UNITS / 2;
p->y = world_coord(xyCoords.y) + TILE_UNITS / 2;
}
View
@@ -2661,8 +2661,7 @@ bool vtolReadyToRearm(DROID *psDroid, STRUCTURE *psStruct)
{
CHECK_DROID(psDroid);
if (!isVtolDroid(psDroid)
|| psDroid->action != DACTION_WAITFORREARM)
if (!isVtolDroid(psDroid) || psDroid->action != DACTION_WAITFORREARM)
{
return false;
}
@@ -2674,20 +2673,22 @@ bool vtolReadyToRearm(DROID *psDroid, STRUCTURE *psStruct)
&& !vtolOnRearmPad((STRUCTURE *)psRearmPad, psDroid))
{
// target rearm pad is clear - let it go there
objTrace(psDroid->id, "rearm pad at %d,%d won't snatch us - we already have another available at %d,%d", psStruct->pos.x / TILE_UNITS, psStruct->pos.y / TILE_UNITS, psRearmPad->pos.x / TILE_UNITS, psRearmPad->pos.y / TILE_UNITS);
return false;
}
if (vtolHappy(psDroid) &&
vtolOnRearmPad(psStruct, psDroid))
if (vtolHappy(psDroid) && vtolOnRearmPad(psStruct, psDroid))
{
// there is a vtol on the pad and this vtol is already rearmed
// don't bother shifting the other vtol off
objTrace(psDroid->id, "rearm pad at %d,%d won't snatch us - we're rearmed and pad is busy", psStruct->pos.x / TILE_UNITS, psStruct->pos.y / TILE_UNITS);
return false;
}
if (psDroid->psActionTarget[0] != nullptr && psDroid->psActionTarget[0] != psStruct)
{
// vtol is rearming at a different base
objTrace(psDroid->id, "rearm pad at %d,%d won't snatch us - we already are snatched by %d,%d", psStruct->pos.x / TILE_UNITS, psStruct->pos.y / TILE_UNITS, psDroid->psActionTarget[0]->pos.x / TILE_UNITS, psDroid->psActionTarget[0]->pos.y / TILE_UNITS);
return false;
}
View
@@ -72,6 +72,11 @@ const char *objInfo(const BASE_OBJECT *psObj)
{
static char info[PATH_MAX];
if (!psObj)
{
return "null";
}
switch (psObj->type)
{
case OBJ_DROID:
View
@@ -1304,6 +1304,7 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
syncDebugDroid(psDroid, '-');
syncDebug("%d ordered %s", psDroid->id, getDroidOrderName(psOrder->type));
objTrace(psDroid->id, "base set order to %s (was %s)", getDroidOrderName(psOrder->type), getDroidOrderName(psDroid->order.type));
if (psOrder->type != DORDER_TRANSPORTIN // transporters special
&& psOrder->psObj == nullptr // location-type order
@@ -1691,6 +1692,7 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
// no repair facility or HQ go to the landing zone
if (!bMultiPlayer && selectedPlayer == 0)
{
objTrace(psDroid->id, "could not RTR, doing RTL instead");
orderDroid(psDroid, DORDER_RTB, ModeImmediate);
}
}
View
@@ -48,6 +48,7 @@
#include "lib/framework/wzconfig.h"
#include "lib/netplay/netplay.h"
#include "action.h"
#include "difficulty.h"
#include "multiplay.h"
#include "objects.h"
@@ -581,6 +582,7 @@ static QString arrayToString(const T *array, int length)
}
// Using ^ to denote stats that are in templates, and as such do not change.
// Using : to denote stats that come from structure specializations.
QStandardItemList componentToString(const QString &name, const COMPONENT_STATS *psStats, int player)
{
QStandardItem *key = new QStandardItem(name);
@@ -705,7 +707,7 @@ void ScriptDebugger::selected(const BASE_OBJECT *psObj)
setPair(row, selectedModel, "Frustrated time", QString::number(psDroid->lastFrustratedTime));
setPair(row, selectedModel, "Resistance", QString::number(psDroid->resistance));
setPair(row, selectedModel, "Secondary order", QString::number(psDroid->secondaryOrder));
setPair(row, selectedModel, "Action", QString::number(psDroid->action));
setPair(row, selectedModel, "Action", QString(getDroidActionName(psDroid->action)));
setPair(row, selectedModel, "Action position", QString::fromStdString(glm::to_string(psDroid->actionPos)));
setPair(row, selectedModel, "Action started", QString::number(psDroid->actionStarted));
setPair(row, selectedModel, "Action points", QString::number(psDroid->actionPoints));
@@ -748,6 +750,12 @@ void ScriptDebugger::selected(const BASE_OBJECT *psObj)
setPair(row, selectedModel, "^Height", QString::number(psStruct->pStructureType->height));
setPair(row, selectedModel, componentToString("ECM", psStruct->pStructureType->pECM, psObj->player));
setPair(row, selectedModel, componentToString("Sensor", psStruct->pStructureType->pSensor, psObj->player));
if (psStruct->pStructureType->type == REF_REARM_PAD)
{
setPair(row, selectedModel, ":timeStarted", QString::number(psStruct->pFunctionality->rearmPad.timeStarted));
setPair(row, selectedModel, ":timeLastUpdated", QString::number(psStruct->pFunctionality->rearmPad.timeLastUpdated));
setPair(row, selectedModel, ":Rearm target", QString(objInfo(psStruct->pFunctionality->rearmPad.psObj)));
}
}
else if (psObj->type == OBJ_FEATURE)
{
View
@@ -2941,30 +2941,32 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
/* select next droid if none being rearmed*/
if (psChosenObj == nullptr)
{
for (psDroid = apsDroidLists[psStructure->player]; psDroid;
psDroid = psDroid->psNext)
objTrace(psStructure->id, "Rearm pad idle - look for victim");
for (psDroid = apsDroidLists[psStructure->player]; psDroid; psDroid = psDroid->psNext)
{
// move next droid waiting on ground to rearm pad
if (vtolReadyToRearm(psDroid, psStructure) &&
(psChosenObj == nullptr || (((DROID *)psChosenObj)->actionStarted > psDroid->actionStarted)))
{
objTrace(psDroid->id, "rearm pad candidate");
objTrace(psStructure->id, "we found %s to rearm", objInfo(psDroid));
psChosenObj = psDroid;
}
}
if (!psChosenObj) // None available? Try allies.
// None available? Try allies.
for (int i = 0; i < MAX_PLAYERS && !psChosenObj; i++)
{
for (i = 0; i < MAX_PLAYERS; i++)
if (aiCheckAlliances(i, psStructure->player) && i != psStructure->player)
{
if (aiCheckAlliances(i, psStructure->player) && i != psStructure->player)
for (psDroid = apsDroidLists[i]; psDroid; psDroid = psDroid->psNext)
{
for (psDroid = apsDroidLists[i]; psDroid; psDroid = psDroid->psNext)
// move next droid waiting on ground to rearm pad
if (vtolReadyToRearm(psDroid, psStructure))
{
// move next droid waiting on ground to rearm pad
if (vtolReadyToRearm(psDroid, psStructure))
{
psChosenObj = psDroid;
break;
}
psChosenObj = psDroid;
objTrace(psDroid->id, "allied rearm pad candidate");
objTrace(psStructure->id, "we found allied %s to rearm", objInfo(psDroid));
break;
}
}
}
@@ -2982,6 +2984,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
psDroid->sMove.Status == MOVEHOVER) &&
psDroid->action == DACTION_WAITFORREARM)
{
objTrace(psDroid->id, "supposed to go to rearm but not on our way -- fixing"); // this should never happen...
actionDroid(psDroid, DACTION_MOVETOREARMPOINT, psStructure);
}
}
@@ -3302,6 +3305,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
if (psDroid->died || (psDroid->action != DACTION_MOVETOREARMPOINT && psDroid->action != DACTION_WAITDURINGREARM))
{
psReArmPad->psObj = nullptr;
objTrace(psDroid->id, "VTOL has wrong action or is dead");
return;
}
if (psDroid->action == DACTION_WAITDURINGREARM && psDroid->sMove.Status == MOVEINACTIVE)
@@ -3324,6 +3328,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
psDroid->asWeaps[i].ammo = asWeaponStats[psDroid->asWeaps[i].nStat].upgrade[psDroid->player].numRounds;
psDroid->asWeaps[i].lastFired = 0;
}
objTrace(psDroid->id, "fully loaded");
}
else
{
@@ -3366,6 +3371,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
psReArmPad->psObj = nullptr;
auxStructureNonblocking(psStructure);
triggerEventDroidIdle(psDroid);
objTrace(psDroid->id, "VTOL happy and ready for action!");
}
}
}
@@ -6679,6 +6685,10 @@ STRUCTURE *findNearestReArmPad(DROID *psDroid, STRUCTURE *psTarget, bool bClear)
{
psNearest = psTotallyClear;
}
if (!psNearest)
{
objTrace(psDroid->id, "Failed to find a landing spot (%s)!", bClear ? "req clear" : "any");
}
return psNearest;
}

0 comments on commit f7f1771

Please sign in to comment.