Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop RTR droids from dropping group and accepting orders #2390

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 57 additions & 7 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,20 @@ static void orderPlayFireSupportAudio(BASE_OBJECT *psObj)
}
}

/** Returns true if the Droid has been ordered to retreat
* and is assigned to a group.
*/
inline bool isRetreatingInGroup(const DROID *psDroid)
{
if (psDroid->group == UBYTE_MAX)
{
return false;
}
else
{
return psDroid->order.type == DORDER_RTR || psDroid->order.type == DORDER_RTB || psDroid->order.type == DORDER_RTR_SPECIFIED;
}
}

/** This function actually tells the droid to perform the psOrder.
* This function is called everytime to send a direct order to a droid.
Expand Down Expand Up @@ -1344,6 +1358,10 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
break;
case DORDER_MOVE:
case DORDER_SCOUT:
if (isRetreatingInGroup(psDroid))
{
break;
}
// can't move vtols to blocking tiles
if (isVtolDroid(psDroid)
&& fpathBlockingTile(map_coord(psOrder->pos), getPropulsionStats(psDroid)->propulsionType))
Expand All @@ -1362,11 +1380,19 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
actionDroid(psDroid, DACTION_MOVE, psOrder->pos.x, psOrder->pos.y);
break;
case DORDER_PATROL:
if (isRetreatingInGroup(psDroid))
{
break;
}
psDroid->order = *psOrder;
psDroid->order.pos2 = psDroid->pos.xy();
actionDroid(psDroid, DACTION_MOVE, psOrder->pos.x, psOrder->pos.y);
break;
case DORDER_RECOVER:
if (isRetreatingInGroup(psDroid))
{
break;
}
psDroid->order = *psOrder;
actionDroid(psDroid, DACTION_MOVE, psOrder->psObj->pos.x, psOrder->psObj->pos.y);
break;
Expand All @@ -1388,8 +1414,9 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
case DORDER_ATTACK:
case DORDER_ATTACKTARGET:
if (psDroid->numWeaps == 0
|| psDroid->asWeaps[0].nStat == 0
|| isTransporter(psDroid))
|| psDroid->asWeaps[0].nStat == 0
|| isTransporter(psDroid)
|| isRetreatingInGroup(psDroid))
{
break;
}
Expand Down Expand Up @@ -1424,6 +1451,10 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
break;
case DORDER_BUILD:
case DORDER_LINEBUILD:
if (isRetreatingInGroup(psDroid))
{
break;
}
// build a new structure or line of structures
ASSERT_OR_RETURN(, isConstructionDroid(psDroid), "%s cannot construct things!", objInfo(psDroid));
ASSERT_OR_RETURN(, psOrder->psStats != nullptr, "invalid structure stats pointer");
Expand All @@ -1433,6 +1464,10 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
objTrace(psDroid->id, "Starting new construction effort of %s", psOrder->psStats ? getStatsName(psOrder->psStats) : "NULL");
break;
case DORDER_BUILDMODULE:
if (isRetreatingInGroup(psDroid))
{
break;
}
//build a module onto the structure
if (!isConstructionDroid(psDroid) || psOrder->index < nextModuleToBuild((STRUCTURE *)psOrder->psObj, -1))
{
Expand All @@ -1445,6 +1480,10 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
objTrace(psDroid->id, "Starting new upgrade of %s", psOrder->psStats ? getStatsName(psOrder->psStats) : "NULL");
break;
case DORDER_HELPBUILD:
if (isRetreatingInGroup(psDroid))
{
break;
}
// help to build a structure that is starting to be built
ASSERT_OR_RETURN(, isConstructionDroid(psDroid), "Not a constructor droid");
ASSERT_OR_RETURN(, psOrder->psObj != nullptr, "Help to build a NULL pointer?");
Expand All @@ -1456,6 +1495,10 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
objTrace(psDroid->id, "Helping construction of %s", psOrder->psStats ? getStatsName(psDroid->order.psStats) : "NULL");
break;
case DORDER_DEMOLISH:
if (isRetreatingInGroup(psDroid))
{
break;
}
if (!(psDroid->droidType == DROID_CONSTRUCT || psDroid->droidType == DROID_CYBORG_CONSTRUCT))
{
break;
Expand All @@ -1482,6 +1525,10 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
actionDroid(psDroid, DACTION_DROIDREPAIR, psOrder->psObj);
break;
case DORDER_OBSERVE:
if (isRetreatingInGroup(psDroid))
{
break;
}
// keep an object within sensor view
psDroid->order = *psOrder;
actionDroid(psDroid, DACTION_OBSERVE, psOrder->psObj);
Expand Down Expand Up @@ -1696,6 +1743,10 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
}
break;
case DORDER_GUARD:
if (isRetreatingInGroup(psDroid))
{
break;
}
psDroid->order = *psOrder;
if (psOrder->psObj != nullptr)
{
Expand Down Expand Up @@ -1728,6 +1779,10 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
assignVTOLPad(psDroid, (STRUCTURE *)psOrder->psObj);
break;
case DORDER_CIRCLE:
if (isRetreatingInGroup(psDroid))
{
break;
}
if (!isVtolDroid(psDroid))
{
break;
Expand Down Expand Up @@ -3109,11 +3164,6 @@ void secondaryCheckDamageLevel(DROID *psDroid)
{
if (secondaryCheckDamageLevelDeselect(psDroid, secondaryGetState(psDroid, DSO_REPAIR_LEVEL)))
{
if (!isVtolDroid(psDroid))
{
psDroid->group = UBYTE_MAX;
}

/* set return to repair if not on hold */
if (psDroid->order.type != DORDER_RTR &&
psDroid->order.type != DORDER_RTB &&
Expand Down