Permalink
Browse files

Keep track of more power stats.

Track total amount of power extracted and total
amount of wasted power due to limit reached. For
now not used for anything, but can be shown later
in score menu.
  • Loading branch information...
perim committed Nov 19, 2017
1 parent fa6e0cb commit 3dbd5a3c832e7165c7d73920657e0ede504fee82
Showing with 32 additions and 4 deletions.
  1. +1 −2 src/action.cpp
  2. +1 −1 src/hci.cpp
  3. +21 −1 src/power.cpp
  4. +6 −0 src/power.h
  5. +3 −0 src/qtscriptdebug.cpp
View
@@ -1625,8 +1625,7 @@ void actionUpdateDroid(DROID *psDroid)
//don't move VTOL's
// also don't move closer to sensor towers
if (!isVtolDroid(psDroid) &&
(order->psObj->type != OBJ_STRUCTURE))
if (!isVtolDroid(psDroid) && order->psObj->type != OBJ_STRUCTURE)
{
Vector2i diff = (psDroid->pos - order->psObj->pos).xy;
int rangeSq = asWeaponStats[psDroid->asWeaps[0].nStat].upgrade[psDroid->player].maxRange / 2; // move close to sensor
View
@@ -468,7 +468,7 @@ static void intDisplayReticuleButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yO
// Set the x,y members of a button widget initialiser given a reticule button index.
//
void setReticuleBut(int ButId)
static void setReticuleBut(int ButId)
{
/* Default button data */
W_BUTINIT sButInit;
View
@@ -66,6 +66,8 @@ struct PlayerPower
std::vector<PowerRequest> powerQueue; ///< Requested power.
int powerModifier; ///< Percentage modifier on power from each derrick.
int64_t maxStorage; ///< Maximum storage of power, in total.
int64_t extractedPower; ///< Total amount of extracted power in this game.
int64_t wastedPower; ///< Total amount of wasted power in this game.
};
static PlayerPower asPower[MAX_PLAYERS];
@@ -95,6 +97,8 @@ void clearPlayerPower()
for (unsigned player = 0; player < MAX_PLAYERS; player++)
{
asPower[player].currentPower = 0;
asPower[player].extractedPower = 0;
asPower[player].wastedPower = 0;
asPower[player].powerModifier = 100;
asPower[player].powerQueue.clear();
asPower[player].maxStorage = MAX_POWER * FP_ONE;
@@ -219,7 +223,11 @@ 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].maxStorage);
if (asPower[player].currentPower > asPower[player].maxStorage)
{
asPower[player].wastedPower += asPower[player].currentPower - asPower[player].maxStorage;
asPower[player].currentPower = asPower[player].maxStorage;
}
}
/*resets the power calc flag for all players*/
@@ -316,9 +324,11 @@ static void updateCurrentPower(STRUCTURE *psStruct, UDWORD player, int ticks)
syncDebug("updateCurrentPower%d = %" PRId64",%u", player, extractedPower, multiplier);
asPower[player].currentPower += (extractedPower * multiplier) / 100 * ticks;
asPower[player].extractedPower += (extractedPower * multiplier) / 100 * ticks;
ASSERT(asPower[player].currentPower >= 0, "negative power");
if (asPower[player].currentPower > asPower[player].maxStorage)
{
asPower[player].wastedPower += asPower[player].currentPower - asPower[player].maxStorage;
asPower[player].currentPower = asPower[player].maxStorage;
}
}
@@ -355,6 +365,16 @@ int64_t getPrecisePower(unsigned player)
return asPower[player].currentPower;
}
int64_t getExtractedPower(unsigned player)
{
return asPower[player].extractedPower / FP_ONE;
}
int64_t getWastedPower(unsigned player)
{
return asPower[player].wastedPower / FP_ONE;
}
int32_t getPowerMinusQueued(unsigned player)
{
ASSERT_OR_RETURN(0, player < MAX_PLAYERS, "Invalid player (%u)", player);
View
@@ -70,6 +70,12 @@ int64_t getPrecisePower(unsigned player);
int32_t getPowerMinusQueued(unsigned player);
int getQueuedPower(int player);
/// Get amount of power extracted during the whole game
int64_t getExtractedPower(unsigned player);
/// Get amount of power wasted during the whole game
int64_t getWastedPower(unsigned player);
/** Resets the power levels for all players when power is turned back on. */
void powerCalc(bool on);
View
@@ -233,6 +233,9 @@ static void fillPlayerModel(QStandardItemModel &m, int i)
KEYVAL("NetPlay.players.difficulty", QString::number(NetPlay.players[i].difficulty));
KEYVAL("NetPlay.players.autoGame", QString::number(NetPlay.players[i].autoGame));
KEYVAL("NetPlay.players.IPtextAddress", NetPlay.players[i].IPtextAddress);
KEYVAL("Current power", QString::number(getPower(i)));
KEYVAL("Extracted power", QString::number(getExtractedPower(i)));
KEYVAL("Wasted power", QString::number(getWastedPower(i)));
#undef B2Q
#undef KEYVAL

0 comments on commit 3dbd5a3

Please sign in to comment.