Skip to content

Commit

Permalink
Nexus/Semperfi: Add/fix check that repair templates exist before buil…
Browse files Browse the repository at this point in the history
…ding it.

Also name the power storage variable something more intelligible.
  • Loading branch information
perim committed May 16, 2016
1 parent a379496 commit 712e3ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
7 changes: 5 additions & 2 deletions data/mp/multiplay/skirmish/nexus.slo
Expand Up @@ -1718,9 +1718,12 @@ event repairDroids(repairDroidsTr)
{
initEnumStruct(FALSE,factory,me,me);
structure= enumStruct(); // find factory.
if ((structure != NULLOBJECT) and (getDroidCount(me) < MAX_DROIDS) and (skCanBuildTemplate(me, structure, repairUnit)))
if (structure != NULLOBJECT)
{
buildDroid(repairUnit, structure, me, 1); // build repairunit.
if ((getDroidCount(me) < MAX_DROIDS) and (skCanBuildTemplate(me, structure, repairUnit)))
{
buildDroid(repairUnit, structure, me, 1); // build repairunit.
}
}
}
}
Expand Down
29 changes: 7 additions & 22 deletions data/mp/multiplay/skirmish/semperfi.slo
Expand Up @@ -155,7 +155,6 @@ private int count,count2,result;

private bool powerSave,_DEBUG,bRunning;
// Hopefully this will be at least as large as MAX_PLAYERS... Why can't I just use MAX_PLAYERS as the array size?!
// P.S. And why can't I put a comment on the same line as a #define??!! Gah, who cares if the lua2 branch works, lets switch to it, anyway.
#define MAX_PLAYERS_HACK 17
private int allianceTime[MAX_PLAYERS_HACK];
private int sender,x,y,beaconX[MAX_PLAYERS_HACK],beaconY[MAX_PLAYERS_HACK],tBeacon[MAX_PLAYERS_HACK],
Expand Down Expand Up @@ -2045,18 +2044,19 @@ function STRUCTURE findIdleStructure(STRUCTURESTAT _structType, bool _bIdleOnly)
// build repair droids.
event repairDroids(repairDroidsTr)
{

// if we're running low on repair droids, build some..
if(numRepairUnits <3)
{
initEnumStruct(FALSE,factory,me,me);
structure= enumStruct(); // find factory.
if( (structure != NULLOBJECT) and (getDroidCount(me) < MAX_DROIDS) )
if (structure != NULLOBJECT)
{
buildDroid(repairUnit, structure, me, 1); // build repairunit.
if ((getDroidCount(me) < MAX_DROIDS) and (skCanBuildTemplate(me, structure, repairUnit)))
{
buildDroid(repairUnit, structure, me, 1); // build repairunit.
}
}
}

}


Expand Down Expand Up @@ -2149,7 +2149,6 @@ function void factoryBuildDroid(STRUCTURE _factory)
// put cyborg factories to work
event cyborgFactoryEvent(cyborgFactoryEventTr)
{

if(not ((defendGroup.members < maxCyborgs) or (maxCyborgs == UNLIMITED)))
{
exit; //we need no cyborgs
Expand Down Expand Up @@ -2241,7 +2240,6 @@ event chooseScoutArea(chooseScoutAreaTr)

event expandScoutArea(expandScoutAreaTr)
{

//expand the scouting area slightly
scoutTLX = scoutTLX - ((mapWidth*128)/ tileExpand);
scoutTLY = scoutTLY - ((mapHeight*128)/ tileExpand);
Expand Down Expand Up @@ -3728,16 +3726,8 @@ function bool attemptToHelp(int _playerToHelp, int _x, int _y)
if(haveHelpers() or _DEBUG)
{
dbg("got attackers", me);
//if(allyBaseAtLoc(_playerToHelp, _x, _y)) //is he just trying to misuse us?
//{
helpPlayer(_playerToHelp, _x, _y);
return TRUE;
//}
//else
//{
// dbg("ally needs no help", me);
// messagePlayer(ALL_ALLIES, M_ANNOYED, MAX_PROBABILITY / 2);
//}
helpPlayer(_playerToHelp, _x, _y);
return TRUE;
}
else
{
Expand Down Expand Up @@ -3898,11 +3888,6 @@ function bool canStopHelpingAlly()
return TRUE;
}

/* Nothing to defend anymore */
//if(!allyBaseAtLoc(lastHelpPlayer, helpX, helpY)){
// return TRUE;
//}

return FALSE;
}

Expand Down
16 changes: 8 additions & 8 deletions src/power.cpp
Expand Up @@ -71,8 +71,8 @@ struct PlayerPower
// All fields are 32.32 fixed point.
int64_t currentPower; ///< The current amount of power available to the player.
std::vector<PowerRequest> powerQueue; ///< Requested power.
int powerModifier; ///< Percentage modifier on power from each derrick.
int64_t max;
int powerModifier; ///< Percentage modifier on power from each derrick.
int64_t maxStorage; ///< Maximum storage of power, in total.
};

static PlayerPower asPower[MAX_PLAYERS];
Expand All @@ -84,8 +84,8 @@ void setPowerModifier(int player, int modifier)

void setPowerMaxStorage(int player, int max)
{
asPower[player].max = max * FP_ONE;
asPower[player].currentPower = std::min<int64_t>(asPower[player].max, asPower[player].currentPower);
asPower[player].maxStorage = max * FP_ONE;
asPower[player].currentPower = std::min<int64_t>(asPower[player].maxStorage, asPower[player].currentPower);
}

/*allocate the space for the playerPower*/
Expand All @@ -104,7 +104,7 @@ void clearPlayerPower()
asPower[player].currentPower = 0;
asPower[player].powerModifier = 100;
asPower[player].powerQueue.clear();
asPower[player].max = MAX_POWER * FP_ONE;
asPower[player].maxStorage = MAX_POWER * FP_ONE;
}
}

Expand Down Expand Up @@ -226,7 +226,7 @@ void addPower(int player, int32_t quantity)
ASSERT_OR_RETURN(, player < MAX_PLAYERS, "Bad player (%d)", player);
syncDebug("addPower%d %" PRId64"+=%d", player, asPower[player].currentPower, quantity);
asPower[player].currentPower += quantity * FP_ONE;
CLIP(asPower[player].currentPower, 0, asPower[player].max);
CLIP(asPower[player].currentPower, 0, asPower[player].maxStorage);
}

/*resets the power calc flag for all players*/
Expand Down Expand Up @@ -324,9 +324,9 @@ static void updateCurrentPower(STRUCTURE *psStruct, UDWORD player, int ticks)

asPower[player].currentPower += (extractedPower * multiplier) / 100 * ticks;
ASSERT(asPower[player].currentPower >= 0, "negative power");
if (asPower[player].currentPower > asPower[player].max)
if (asPower[player].currentPower > asPower[player].maxStorage)
{
asPower[player].currentPower = asPower[player].max;
asPower[player].currentPower = asPower[player].maxStorage;
}
}

Expand Down

0 comments on commit 712e3ad

Please sign in to comment.