Remove unnecessary steps and duplicate code in droid build code. Also add
future proofing for droid actions in savegames.master
parent
f5c1543581
commit
37aef13bfd
|
@ -1431,10 +1431,10 @@ void actionUpdateDroid(DROID *psDroid)
|
|||
objTrace(psDroid->id, "DACTION_MOVETOBUILD: !validLocation");
|
||||
cancelBuild(psDroid);
|
||||
}
|
||||
else // is ok
|
||||
else if (droidStartBuild(psDroid))
|
||||
{
|
||||
syncDebug("Reached build target: build");
|
||||
psDroid->action = DACTION_BUILD_FOUNDATION;
|
||||
psDroid->action = DACTION_BUILD;
|
||||
psDroid->actionStarted = gameTime;
|
||||
psDroid->actionPoints = 0;
|
||||
}
|
||||
|
@ -1658,59 +1658,6 @@ void actionUpdateDroid(DROID *psDroid)
|
|||
psDroid->psActionTarget[0]->pos.y);
|
||||
}
|
||||
break;
|
||||
case DACTION_BUILD_FOUNDATION:
|
||||
if (!order->psStats)
|
||||
{
|
||||
objTrace(psDroid->id, "DACTION_BUILD_FOUNDATION: lost target stats");
|
||||
psDroid->action = DACTION_NONE;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
MAPTILE* const psTile = mapTile(map_coord(order->pos.x), map_coord(order->pos.y));
|
||||
if ((order->psObj == NULL) && (TileHasStructure(psTile) || TileHasFeature(psTile)))
|
||||
{
|
||||
if (TileHasStructure(psTile))
|
||||
{
|
||||
// structure on the build location - see if it is the same type
|
||||
STRUCTURE* const psStruct = getTileStructure(map_coord(order->pos.x), map_coord(order->pos.y));
|
||||
if (psStruct->pStructureType == order->psStats)
|
||||
{
|
||||
// same type - do a help build
|
||||
setDroidTarget(psDroid, psStruct);
|
||||
}
|
||||
else
|
||||
{
|
||||
objTrace(psDroid->id, "DACTION_BUILD_FOUNDATION: blocked");
|
||||
cancelBuild(psDroid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!validLocation(order->psStats, order->pos, order->direction, psDroid->player, false))
|
||||
{
|
||||
objTrace(psDroid->id, "DACTION_BUILD_FOUNDATION: not valid location");
|
||||
cancelBuild(psDroid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//ready to start building the structure
|
||||
DroidStartBuild dsb;
|
||||
if (psDroid->action != DACTION_NONE && (dsb = droidStartBuild(psDroid)))
|
||||
{
|
||||
if (dsb == DroidStartBuildSuccess) // Not if waiting for oil to finish burning.
|
||||
{
|
||||
objTrace(psDroid->id, "DACTION_BUILD_FOUNDATION: start build");
|
||||
psDroid->action = DACTION_BUILD;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
objTrace(psDroid->id, "DACTION_BUILD_FOUNDATION: giving up");
|
||||
cancelBuild(psDroid);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DACTION_OBSERVE:
|
||||
// align the turret
|
||||
actionTargetTurret(psDroid, psDroid->psActionTarget[0], &psDroid->asWeaps[0]);
|
||||
|
|
|
@ -33,7 +33,7 @@ enum DROID_ACTION
|
|||
DACTION_NONE, ///< 0 not doing anything
|
||||
DACTION_MOVE, ///< 1 moving to a location
|
||||
DACTION_BUILD, ///< 2 building a structure
|
||||
DACTION_BUILD_FOUNDATION, ///< 3 building a foundation for a structure
|
||||
DACTION_UNUSED3, ///< 3 used to be building a foundation for a structure
|
||||
DACTION_DEMOLISH, ///< 4 demolishing a structure
|
||||
DACTION_REPAIR, ///< 5 repairing a structure
|
||||
DACTION_ATTACK, ///< 6 attacking something
|
||||
|
@ -55,7 +55,7 @@ enum DROID_ACTION
|
|||
DACTION_MOVETODEMOLISH, ///< 19 moving to a new demolition location
|
||||
DACTION_MOVETOREPAIR, ///< 20 moving to a new repair location
|
||||
DACTION_BUILDWANDER, ///< 21 moving around while building
|
||||
DACTION_FOUNDATION_WANDER, ///< 22 moving around while building the foundation
|
||||
DACTION_UNUSED4, ///< 22 used to be moving around while building the foundation
|
||||
DACTION_MOVETOATTACK, ///< 23 moving to a target to attack
|
||||
DACTION_ROTATETOATTACK, ///< 24 rotating to a target to attack
|
||||
DACTION_MOVETOOBSERVE, ///< 25 moving to be able to see a target
|
||||
|
|
|
@ -4462,6 +4462,7 @@ static bool writeDroid(WzConfig &ini, DROID *psCurr, bool onMission, int &counte
|
|||
if (psCurr->timeLastHit != UDWORD_MAX) ini.setValue("timeLastHit", psCurr->timeLastHit);
|
||||
ini.setValue("secondaryOrder", psCurr->secondaryOrder);
|
||||
ini.setValue("action", psCurr->action);
|
||||
ini.setValue("actionString", getDroidActionName(psCurr->action)); // future-proofing
|
||||
ini.setVector2i("action/pos", psCurr->actionPos);
|
||||
ini.setValue("actionStarted", psCurr->actionStarted);
|
||||
ini.setValue("actionPoints", psCurr->actionPoints);
|
||||
|
|
|
@ -2183,9 +2183,7 @@ bool orderStateStatsLoc(DROID *psDroid, DROID_ORDER order, BASE_STATS **ppsStats
|
|||
break;
|
||||
case DORDER_BUILD:
|
||||
case DORDER_LINEBUILD:
|
||||
if (psDroid->action == DACTION_MOVETOBUILD ||
|
||||
psDroid->action == DACTION_BUILD_FOUNDATION ||
|
||||
psDroid->action == DACTION_FOUNDATION_WANDER)
|
||||
if (psDroid->action == DACTION_MOVETOBUILD)
|
||||
{
|
||||
*ppsStats = psDroid->order.psStats;
|
||||
*pX = psDroid->order.pos.x;
|
||||
|
|
|
@ -1797,7 +1797,6 @@ CONST_SYMBOL asConstantTable[] =
|
|||
{ "DACTION_NONE", VAL_INT, false, DACTION_NONE, NULL, NULL, 0.0f },
|
||||
{ "DACTION_MOVE", VAL_INT, false, DACTION_MOVE, NULL, NULL, 0.0f },
|
||||
{ "DACTION_BUILD", VAL_INT, false, DACTION_BUILD, NULL, NULL, 0.0f },
|
||||
{ "DACTION_BUILD_FOUNDATION", VAL_INT, false, DACTION_BUILD_FOUNDATION, NULL, NULL, 0.0f },
|
||||
{ "DACTION_DEMOLISH", VAL_INT, false, DACTION_DEMOLISH, NULL, NULL, 0.0f },
|
||||
{ "DACTION_REPAIR", VAL_INT, false, DACTION_REPAIR, NULL, NULL, 0.0f },
|
||||
{ "DACTION_ATTACK", VAL_INT, false, DACTION_ATTACK, NULL, NULL, 0.0f },
|
||||
|
@ -1817,7 +1816,6 @@ CONST_SYMBOL asConstantTable[] =
|
|||
|
||||
{ "DACTION_MOVETOREPAIR", VAL_INT, false, DACTION_MOVETOREPAIR, NULL, NULL, 0.0f },
|
||||
{ "DACTION_BUILDWANDER", VAL_INT, false, DACTION_BUILDWANDER, NULL, NULL, 0.0f },
|
||||
{ "DACTION_FOUNDATION_WANDER", VAL_INT, false, DACTION_FOUNDATION_WANDER, NULL, NULL, 0.0f },
|
||||
{ "DACTION_MOVETOATTACK", VAL_INT, false, DACTION_MOVETOATTACK, NULL, NULL, 0.0f },
|
||||
{ "DACTION_ROTATETOATTACK", VAL_INT, false, DACTION_ROTATETOATTACK, NULL, NULL, 0.0f },
|
||||
{ "DACTION_MOVETOOBSERVE", VAL_INT, false, DACTION_MOVETOOBSERVE, NULL, NULL, 0.0f },
|
||||
|
|
Loading…
Reference in New Issue