Move saving of droids to ini file format. Add basic sanity layer for orders/actions.

master
Per Inge Mathisen 2011-04-18 22:20:29 +02:00
parent c110ea8e31
commit 49069f7ddb
5 changed files with 437 additions and 1307 deletions

View File

@ -824,6 +824,45 @@ static void actionHomeBasePos(SDWORD player, SDWORD *px, SDWORD *py)
*py = getLandingY(player);
}
void actionSanity(DROID *psDroid)
{
// Don't waste ammo unless given a direct attack order.
bool avoidOverkill = psDroid->order != DORDER_ATTACK && psDroid->order != DORDER_ATTACK &&
(psDroid->action == DACTION_ATTACK || psDroid->action == DACTION_MOVEFIRE || psDroid->action == DACTION_MOVETOATTACK ||
psDroid->action == DACTION_ROTATETOATTACK || psDroid->action == DACTION_VTOLATTACK);
// clear the target if it has died
for (int i = 0; i < DROID_MAXWEAPS; i++)
{
if (psDroid->psActionTarget[i] && (avoidOverkill? aiObjectIsProbablyDoomed(psDroid->psActionTarget[i]) : psDroid->psActionTarget[i]->died))
{
setDroidActionTarget(psDroid, NULL, i);
if (i == 0)
{
if (psDroid->action != DACTION_MOVEFIRE &&
psDroid->action != DACTION_TRANSPORTIN &&
psDroid->action != DACTION_TRANSPORTOUT)
{
psDroid->action = DACTION_NONE;
// if VTOL - return to rearm pad if not patrolling
if (isVtolDroid(psDroid))
{
if ((psDroid->order == DORDER_PATROL || psDroid->order == DORDER_CIRCLE) && !vtolEmpty(psDroid))
{
// Back to the patrol.
actionDroid(psDroid, DACTION_MOVE, psDroid->orderX, psDroid->orderY);
}
else
{
moveToRearm(psDroid);
}
}
}
}
}
}
}
// Update the action state for a droid
void actionUpdateDroid(DROID *psDroid)
{
@ -843,41 +882,7 @@ void actionUpdateDroid(DROID *psDroid)
psPropStats = asPropulsionStats + psDroid->asBits[COMP_PROPULSION].nStat;
ASSERT_OR_RETURN(, psPropStats != NULL, "Invalid propulsion stats pointer");
// Don't waste ammo unless given a direct attack order.
bool avoidOverkill = psDroid->order != DORDER_ATTACK && psDroid->order != DORDER_ATTACK &&
(psDroid->action == DACTION_ATTACK || psDroid->action == DACTION_MOVEFIRE || psDroid->action == DACTION_MOVETOATTACK ||
psDroid->action == DACTION_ROTATETOATTACK || psDroid->action == DACTION_VTOLATTACK);
// clear the target if it has died
for (i = 0; i < DROID_MAXWEAPS; i++)
{
if (psDroid->psActionTarget[i] && (avoidOverkill? aiObjectIsProbablyDoomed(psDroid->psActionTarget[i]) : psDroid->psActionTarget[i]->died))
{
setDroidActionTarget(psDroid, NULL, i);
if (i == 0)
{
if (psDroid->action != DACTION_MOVEFIRE &&
psDroid->action != DACTION_TRANSPORTIN &&
psDroid->action != DACTION_TRANSPORTOUT)
{
psDroid->action = DACTION_NONE;
// if VTOL - return to rearm pad if not patrolling
if (isVtolDroid(psDroid))
{
if ((psDroid->order == DORDER_PATROL || psDroid->order == DORDER_CIRCLE) && !vtolEmpty(psDroid))
{
// Back to the patrol.
actionDroid(psDroid, DACTION_MOVE, psDroid->orderX,psDroid->orderY);
}
else
{
moveToRearm(psDroid);
}
}
}
}
}
}
actionSanity(psDroid);
//if the droid has been attacked by an EMP weapon, it is temporarily disabled
if (psDroid->lastHitWeapon == WSC_EMP)

View File

@ -58,6 +58,9 @@ const char* getDroidActionName(DROID_ACTION action);
*/
void actionUpdateDroid(DROID *psDroid);
/** Do sanity update only. Called from actionUpdateDroid() normally. */
void actionSanity(DROID *psDroid);
/** Give a droid an action. */
void actionDroid(DROID *psDroid, DROID_ACTION action);

File diff suppressed because it is too large Load Diff

View File

@ -91,9 +91,6 @@ RUN_DATA asRunData[MAX_PLAYERS];
// deal with a droid receiving a primary order
static bool secondaryGotPrimaryOrder(DROID *psDroid, DROID_ORDER order);
// check all the orders in the list for died objects
static void orderCheckList(DROID *psDroid);
// Clear all the orders from the list, up to listSize (without clearing pending (not yet synchronised) orders, that is).
static void orderClearDroidList(DROID *psDroid);

View File

@ -35,7 +35,10 @@ extern void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder);
//call this *AFTER* every mission so it gets reset
extern void initRunData(void);
/* Update a droids order state */
/// Check all the orders in the list for died objects
void orderCheckList(DROID *psDroid);
/** Update a droids order state */
extern void orderUpdateDroid(DROID *psDroid);
/* Give a droid an order */