Skip to content

Commit

Permalink
Set factory secondary states onto droids built when offworld.
Browse files Browse the repository at this point in the history
Fixes ticket 3334.
  • Loading branch information
KJeff01 committed Nov 16, 2018
1 parent ff64846 commit ce90222
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/mission.cpp
Expand Up @@ -2517,8 +2517,7 @@ void intProcessMissionResult(UDWORD id)

/*builds a droid back at the home base whilst on a mission - stored in a list made
available to the transporter interface*/
DROID *buildMissionDroid(DROID_TEMPLATE *psTempl, UDWORD x, UDWORD y,
UDWORD player)
DROID *buildMissionDroid(DROID_TEMPLATE *psTempl, UDWORD x, UDWORD y, UDWORD player)
{
DROID *psNewDroid;

Expand Down
46 changes: 29 additions & 17 deletions src/structure.cpp
Expand Up @@ -2205,6 +2205,31 @@ bool placeDroid(STRUCTURE *psStructure, UDWORD *droidX, UDWORD *droidY)
return true;
}

//Set the factory secondary orders to a droid
void setFactorySecondaryState(DROID *psDroid, STRUCTURE *psStructure)
{
CHECK_STRUCTURE(psStructure);
ASSERT_OR_RETURN(, StructIsFactory(psStructure), "structure not a factory");

if (myResponsibility(psStructure->player))
{
uint32_t newState = psStructure->pFunctionality->factory.secondaryOrder;
uint32_t diff = newState ^ psDroid->secondaryOrder;
if ((diff & DSS_REPLEV_MASK) != 0)
{
secondarySetState(psDroid, DSO_REPAIR_LEVEL, (SECONDARY_STATE)(newState & DSS_REPLEV_MASK));
}
if ((diff & DSS_ALEV_MASK) != 0)
{
secondarySetState(psDroid, DSO_ATTACK_LEVEL, (SECONDARY_STATE)(newState & DSS_ALEV_MASK));
}
if ((diff & DSS_CIRCLE_MASK) != 0)
{
secondarySetState(psDroid, DSO_CIRCLE, (SECONDARY_STATE)(newState & DSS_CIRCLE_MASK));
}
}
}

/* Place a newly manufactured droid next to a factory and then send if off
to the assembly point, returns true if droid was placed successfully */
static bool structPlaceDroid(STRUCTURE *psStructure, DROID_TEMPLATE *psTempl, DROID **ppsDroid)
Expand Down Expand Up @@ -2236,23 +2261,7 @@ static bool structPlaceDroid(STRUCTURE *psStructure, DROID_TEMPLATE *psTempl, DR
return false;
}

if (myResponsibility(psStructure->player))
{
uint32_t newState = psStructure->pFunctionality->factory.secondaryOrder;
uint32_t diff = newState ^ psNewDroid->secondaryOrder;
if ((diff & DSS_REPLEV_MASK) != 0)
{
secondarySetState(psNewDroid, DSO_REPAIR_LEVEL, (SECONDARY_STATE)(newState & DSS_REPLEV_MASK));
}
if ((diff & DSS_ALEV_MASK) != 0)
{
secondarySetState(psNewDroid, DSO_ATTACK_LEVEL, (SECONDARY_STATE)(newState & DSS_ALEV_MASK));
}
if ((diff & DSS_CIRCLE_MASK) != 0)
{
secondarySetState(psNewDroid, DSO_CIRCLE, (SECONDARY_STATE)(newState & DSS_CIRCLE_MASK));
}
}
setFactorySecondaryState(psNewDroid, psStructure);

if (psStructure->visible[selectedPlayer])
{
Expand Down Expand Up @@ -3163,6 +3172,9 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
psStructure->player);
if (psDroid)
{
psDroid->secondaryOrder = psFactory->secondaryOrder;
psDroid->secondaryOrderPending = psDroid->secondaryOrder;
setFactorySecondaryState(psDroid, psStructure);
setDroidBase(psDroid, psStructure);
bDroidPlaced = true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/structure.h
Expand Up @@ -166,6 +166,9 @@ STRUCTURE_STATS *structGetDemolishStat();
/*find a location near to the factory to start the droid of*/
bool placeDroid(STRUCTURE *psStructure, UDWORD *droidX, UDWORD *droidY);

//Set the factory secondary orders to a droid
void setFactorySecondaryState(DROID *psDroid, STRUCTURE *psStructure);

/* is this a lassat structure? */
static inline bool isLasSat(STRUCTURE_STATS *pStructureType)
{
Expand Down

0 comments on commit ce90222

Please sign in to comment.