Skip to content

Commit

Permalink
Add new repair droid suborder
Browse files Browse the repository at this point in the history
  • Loading branch information
DARwins1 authored and KJeff01 committed Aug 5, 2023
1 parent 6bc54e6 commit c789e0c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 22 deletions.
2 changes: 2 additions & 0 deletions data/base/images/intfac.img
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@
0,0,image_transeta_down.png
0,0,image_ord_firedes_up.png
0,0,image_ord_firedes_down.png
0,0,image_ord_accrep_up.png
0,0,image_ord_accrep_down.png
0,0,image_lfttab.png
0,0,image_lfttabd.png
0,0,image_lfttabh.png
Expand Down
Binary file added data/base/images/intfac/image_ord_accrep_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/base/images/intfac/image_ord_accrep_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/intfac.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ enum INTFAC_TYPE
IMAGE_TRANSETA_DOWN,
IMAGE_ORD_FIREDES_UP,
IMAGE_ORD_FIREDES_DOWN,
IMAGE_ORD_ACCREP_UP,
IMAGE_ORD_ACCREP_DOWN,
IMAGE_LFTTAB,
IMAGE_LFTTABD,
IMAGE_LFTTABH,
Expand Down
19 changes: 18 additions & 1 deletion src/intorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#define MAX_DISPLAYABLE_ORDERS 11 // Max number of displayable orders.
#define MAX_ORDER_BUTS 5 // Max number of buttons for a given order.
#define NUM_ORDERS 12 // Number of orders in OrderButtons list.
#define NUM_ORDERS 13 // Number of orders in OrderButtons list.

#define IDORDER_ATTACK_RANGE 8010
#define IDORDER_REPAIR_LEVEL 8020
Expand All @@ -56,6 +56,7 @@
#define IDORDER_FIRE_DESIGNATOR 8100
#define IDORDER_ASSIGN_VTOL_PRODUCTION 8110
#define IDORDER_CIRCLE 8120
#define IDORDER_ACCREP 8130

enum ORDBUTTONTYPE
{
Expand Down Expand Up @@ -156,6 +157,7 @@ enum
STR_DORD_FIREDES,
STR_DORD_VTOL_FACTORY,
STR_DORD_CIRCLE,
STR_DORD_ACCREP,
};

// return translated text
Expand Down Expand Up @@ -186,6 +188,7 @@ static const char *getDORDDescription(int id)
case STR_DORD_FIREDES : return _("Assign Fire Support");
case STR_DORD_VTOL_FACTORY : return _("Assign VTOL Factory Production");
case STR_DORD_CIRCLE : return _("Circle");
case STR_DORD_ACCREP : return _("Accept Retreating Units");

default : return ""; // make compiler shut up
}
Expand Down Expand Up @@ -250,6 +253,20 @@ static ORDERBUTTONS OrderButtons[NUM_ORDERS] =
{STR_DORD_FIREDES, 0, 0},
{DSS_FIREDES_SET, 0, 0}
},
{
ORDBUTCLASS_NORMAL,
DSO_ACCEPT_RETREP,
DSS_ACCREP_MASK,
ORD_BTYPE_BOOLEAN,
ORD_JUSTIFY_COMBINE,
IDORDER_ACCREP,
1, 0,
{IMAGE_ORD_ACCREP_UP, 0, 0},
{IMAGE_ORD_ACCREP_UP, 0, 0},
{IMAGE_DES_HILIGHT, 0, 0},
{STR_DORD_ACCREP, 0, 0},
{DSS_ACCREP_SET, 0, 0}
},
{
ORDBUTCLASS_NORMAL,
DSO_PATROL,
Expand Down
55 changes: 34 additions & 21 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3088,6 +3088,13 @@ bool secondarySupported(DROID *psDroid, SECONDARY_ORDER sec)
}
break;

case DSO_ACCEPT_RETREP:
if (psDroid->droidType != DROID_REPAIR && psDroid->droidType != DROID_CYBORG_REPAIR)
{
supported = false;
}
break;

case DSO_REPAIR_LEVEL:
case DSO_PATROL:
case DSO_HALTTYPE:
Expand Down Expand Up @@ -3148,6 +3155,9 @@ SECONDARY_STATE secondaryGetState(DROID *psDroid, SECONDARY_ORDER sec, QUEUE_MOD
case DSO_CIRCLE:
return (SECONDARY_STATE)(state & DSS_CIRCLE_MASK);
break;
case DSO_ACCEPT_RETREP:
return (SECONDARY_STATE)(state & DSS_ACCREP_MASK);
break;
case DSO_HALTTYPE:
if (psDroid->order.type == DORDER_HOLD)
{
Expand Down Expand Up @@ -3333,30 +3343,26 @@ static inline RtrBestResult decideWhereToRepairAndBalance(DROID *psDroid)
}
}
}
// if we are repair droid ourselves, don't consider other repairs droids
// because that causes havoc on front line: RT repairing themselves,
// blocking everyone else. And everyone else moving toward RT, also toward front line.s
// Ideally, we should just avoid retreating toward "danger", but dangerMap is only for multiplayer
if (psDroid->droidType != DROID_REPAIR && psDroid->droidType != DROID_CYBORG_REPAIR)

// one of these lists is empty when on mission
DROID* psdroidList = apsDroidLists[psDroid->player] != nullptr ? apsDroidLists[psDroid->player] : mission.apsDroidLists[psDroid->player];
for (DROID* psCurr = psdroidList; psCurr != nullptr; psCurr = psCurr->psNext)
{
// one of these lists is empty when on mission
DROID *psdroidList = apsDroidLists[psDroid->player] != nullptr ? apsDroidLists[psDroid->player] : mission.apsDroidLists[psDroid->player];
for (DROID *psCurr = psdroidList; psCurr != nullptr; psCurr = psCurr->psNext)
// Accept any repair droids that accept retreating units
if ((psCurr->droidType == DROID_REPAIR || psCurr->droidType == DROID_CYBORG_REPAIR)
&& secondaryGetState(psCurr, DSO_ACCEPT_RETREP))
{
if (psCurr->droidType == DROID_REPAIR || psCurr->droidType == DROID_CYBORG_REPAIR)
thisDistToRepair = droidSqDist(psDroid, psCurr);
if (thisDistToRepair <= 0)
{
thisDistToRepair = droidSqDist(psDroid, psCurr);
if (thisDistToRepair <= 0)
{
continue; // unreachable
}
vDroidPos.push_back(psCurr->pos);
vDroid.push_back(psCurr);
if (bestDistToRepairDroid > thisDistToRepair)
{
bestDistToRepairDroid = thisDistToRepair;
bestDroidPos = psCurr->pos;
}
continue; // unreachable
}
vDroidPos.push_back(psCurr->pos);
vDroid.push_back(psCurr);
if (bestDistToRepairDroid > thisDistToRepair)
{
bestDistToRepairDroid = thisDistToRepair;
bestDroidPos = psCurr->pos;
}
}
}
Expand Down Expand Up @@ -3531,6 +3537,10 @@ bool secondarySetState(DROID *psDroid, SECONDARY_ORDER sec, SECONDARY_STATE Stat
secondarySet |= DSS_HALT_GUARD;
}
break;
case DSO_ACCEPT_RETREP:
secondaryMask = DSS_ACCREP_MASK;
secondarySet = State;
break;
case DSO_UNUSED:
case DSO_FIRE_DESIGNATOR:
// Do nothing.
Expand Down Expand Up @@ -3733,6 +3743,9 @@ bool secondarySetState(DROID *psDroid, SECONDARY_ORDER sec, SECONDARY_STATE Stat
CurrState &= ~DSS_CIRCLE_MASK;
}
break;
case DSO_ACCEPT_RETREP:
CurrState = (CurrState & ~DSS_ACCREP_MASK) | State;
break;
case DSO_PATROL:
if (State & DSS_PATROL_SET)
{
Expand Down
3 changes: 3 additions & 0 deletions src/orderdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ enum SECONDARY_ORDER
DSO_FIRE_DESIGNATOR, /**< Assigns a droid to be a target designator. */
DSO_ASSIGN_VTOL_PRODUCTION, /**< Assigns a vtol factory to a command droid - the state is given by the factory number. */
DSO_CIRCLE, /**< circling target position and engage. */
DSO_ACCEPT_RETREP /**< Whether droids should retreat to this repair droid. */
};

/** All associated secondary states of the secondary orders. */
Expand All @@ -122,6 +123,7 @@ enum SECONDARY_STATE
DSS_HALT_PURSUE = 0x0000c0, /**< state referred to secondary order DSO_HALTTYPE. If halted, droid pursues the target by its free will. */
DSS_RECYCLE_SET = 0x000100, /**< state referred to secondary order DSO_RECYCLE. If set, the droid can be recycled. */
DSS_ASSPROD_START = 0x000200, /**< @todo this state is not called on the code. Consider removing it. */
DSS_ACCREP_SET = 0x000400, /**< state referred to secondary order DSO_ACCEPT_RETREP. If set, units will retreat to this repair droid. */
DSS_ASSPROD_MID = 0x002000, /**< @todo this state is not called on the code. Consider removing it. */
DSS_ASSPROD_END = 0x040000, /**< @todo this state is not called on the code. Consider removing it. */
DSS_RTL_REPAIR = 0x080000, /**< state set to send order DORDER_RTR to droid. */
Expand Down Expand Up @@ -149,6 +151,7 @@ enum SECONDARY_STATE
#define DSS_PATROL_MASK 0x400000
#define DSS_FIREDES_MASK 0x800000
#define DSS_CIRCLE_MASK 0x400100
#define DSS_ACCREP_MASK 0x000400

struct STRUCTURE_STATS;

Expand Down

0 comments on commit c789e0c

Please sign in to comment.