Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): dota style stat picker, lead graph and armies chart

Olcay Seygan674f9c7b7cdc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0bb1bbadb..e4e748b56 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -478,7 +478,10 @@ found and fixed — EA's own, not port damage.**
- A general who has taken Artillery Barrage to level 3 shows one Artillery Barrage on the promotions strip, not three copies of the same picture in a row.
- The strips close up again: across a row the trays slide an eighth of a tray under each other, so a row reads as one run of metal. The cameos never overlap each other, because every tray goes down before any picture does.
- Watching, the strips can be switched off. A small "Strips" drop-down in the top left corner opens into three boxes - the production queue, the generals' promotions and the superweapon timers - and each box switches its strip the moment it is clicked and is remembered for the next match you watch. The message list moves down to start under it. Playing, there is no drop-down and every strip is up, whatever you chose in the stands.
-- Watching, every player's net worth is on screen under the strips drop-down, the way Dota shows it: richest first, the general's portrait, the number, and a bar measured against the richest player, green for one side and red for the other in a two-sided match and each player's own colour in a free for all. Net worth is the cash in hand plus what everything the player has standing would cost to build again, counted twice a second. Click its title to fold it away.
+- Watching, every player's net worth is on screen under the strips drop-down, the way Dota shows it: richest first, the general's portrait, the number, and a bar measured against the richest player, green for one side and red for the other in a two-sided match and each player's own colour in a free for all. Net worth is the cash in hand plus what everything the player has standing would cost to build again, counted twice a second. Click the minus to fold it away.
+- The number that list ranks by is yours to pick, as in Dota's game stats. Click its title and it opens into net worth, cash, income per minute, army value, kills and losses, the general's rank and power; the list re-sorts the moment you choose.
+- Under it, a graph of the net worth lead since the first minute: green above the line while the first team is ahead, red below while the second is, with how far ahead the leader is right now. It appears in any match with two sides.
+- An armies chart, closed until you open it: every player's six most expensive kinds of unit, with how many of each he has on the field.
- Both are an ordinary web page with a stylesheet, in the game's Window folder. Change the colours, the sizes or the order there and the next match you watch draws it that way, and the page opens in a browser too.
- A minimised command bar stays minimised. Changing seats, or clicking another player's unit while watching, put the whole bar back up over the battlefield you had just cleared. A new match still opens with the bar up.
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 0a413781c..912ce0778 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1059,6 +1059,41 @@ GUI:HudNetWorth
"Net worth"
END
+// the other numbers the spectator's drop-down can rank every player by
+GUI:HudStatCash
+"Cash"
+END
+
+GUI:HudStatIncome
+"Income per minute"
+END
+
+GUI:HudStatArmy
+"Army value"
+END
+
+GUI:HudStatKills
+"Kills / losses"
+END
+
+GUI:HudStatRank
+"General's rank"
+END
+
+GUI:HudStatPower
+"Power"
+END
+
+// the graph of how far the first team's net worth is ahead of the second's
+GUI:HudNetWorthLead
+"Net worth lead"
+END
+
+// each player's most expensive units, with how many he has
+GUI:HudArmies
+"Armies"
+END
+
// the scoreboard on Tab
GUI:ScoreboardAllies
"YOUR SIDE"
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index c781ad992..5fce93c06 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15589,6 +15589,38 @@ GUI:HudNetWorth
"Net değer"
END
+GUI:HudStatCash
+"Nakit"
+END
+
+GUI:HudStatIncome
+"Dakikalık gelir"
+END
+
+GUI:HudStatArmy
+"Ordu değeri"
+END
+
+GUI:HudStatKills
+"Öldürme / kayıp"
+END
+
+GUI:HudStatRank
+"General rütbesi"
+END
+
+GUI:HudStatPower
+"Elektrik"
+END
+
+GUI:HudNetWorthLead
+"Net değer farkı"
+END
+
+GUI:HudArmies
+"Ordular"
+END
+
GUI:ScoreboardAllies
"TAKIMIN"
END
diff --git a/GeneralsMD/Code/Data/Window/Html/Spectator.html b/GeneralsMD/Code/Data/Window/Html/Spectator.html
index f082c2cb9..c5d6262bc 100644
--- a/GeneralsMD/Code/Data/Window/Html/Spectator.html
+++ b/GeneralsMD/Code/Data/Window/Html/Spectator.html
@@ -1,7 +1,9 @@
<!DOCTYPE html>
<!--
- What a spectator sees over the battlefield: the drop-down that switches the strips, and every
- player's net worth. Laid out by litehtml and drawn by the game (GameClient/HtmlOverlay.h).
+ What a spectator sees over the battlefield, down the left edge the way Dota's spectator has it:
+ the drop-down that switches the strips, every player ranked by a number picked from a second
+ drop-down, the net worth lead over the match, and what each army is made of. Laid out by
+ litehtml and drawn by the game (GameClient/HtmlOverlay.h).
A CSS pixel is a pixel of an 800x600 screen and font-size is the game font's point size there;
the page is scaled with the rest of the interface. A background on html or body is for a
@@ -9,15 +11,26 @@
than linear ones.
The game fills in, before layout (GameClient/HtmlTemplate.h):
- {{option:Key}} "on" while that Options.ini on/off option is on
- {{flip:name}} "flipped" while a data-click of flip:name has been clicked an odd number of times
- {{text:Label}} a string table label, in the player's language
- data-each="players", one copy per player still in the match, richest first, with
- {{name}} {{networth}} {{share}} (percent of the richest) {{color}} {{team}} {{teams}}
+ {{option:Key}} "on" while that Options.ini on/off option is on
+ {{flip:name}} "flipped" while a data-click of flip:name has been clicked an odd number of times
+ {{pick:group}} the choice last made with data-click="pick:group:choice"
+ {{pick:group:choice}} "on" while that is the choice; pick:stat:networth is on until another is made
+ {{text:Label}} a string table label, in the player's language
+ {{stat}} the label of the picked stat
+ {{teams}} how many teams are left
+ {{lead}} {{leader}} how much net worth the leading team is ahead by, and "team0" or "team1"
+ {{graph}} "shown" once two teams have a lead worth drawing
+ data-each="players", one copy per player still in the match, ranked by the picked stat, with
+ {{name}} {{value}} {{share}} (percent of the highest) {{networth}} {{color}} {{team}} {{teams}}
{{portrait}} (a mapped image name, for <img src>)
+ data-each="lead", the first team's net worth less the second's since the start, up to 48
+ columns, with {{up}} or {{down}} as a percent of the biggest lead either way
+ data-each="army", per player a {{kind}} "head" entry with his {{image}} and {{color}}, then up to
+ six "unit" entries, the most money first, with the unit's {{image}} and {{count}}
- A data-click of option:Key flips that option and saves it; one of flip:name flips the name for
- the rest of the match. #hud-top's bottom edge is where the message list starts.
+ The stats: networth, cash, income, army, kills, rank, power. A data-click of option:Key flips
+ that option and saves it; flip:name flips the name for the rest of the match; pick:group:choice
+ picks and folds up flip:group. #hud-top's bottom edge is where the message list starts.
Edit the copy under Run/Window/Html and the next match reads it.
-->
@@ -31,6 +44,18 @@
#hud-top { position: absolute; left: 6px; top: 6px; width: 150px; }
+ .panel { background-color: rgba(8, 12, 16, 0.78); border-top: 1px solid #45525c; margin-bottom: 4px; padding-bottom: 2px; }
+ .head { padding: 2px 4px; color: #aab6bf; }
+ .head:hover { color: #ffffff; }
+ .fold { display: inline-block; width: 8px; margin-right: 2px; }
+ .fold::before { content: "-"; }
+ .flipped > .head .fold::before { content: "+"; }
+ .flipped > .body { display: none; }
+ .opens > .head .fold::before { content: "+"; }
+ .opens.flipped > .head .fold::before { content: "-"; }
+ .opens > .body { display: none; }
+ .opens.flipped > .body { display: block; }
+
.menu { background-color: rgba(0, 0, 0, 0.6); margin-bottom: 4px; }
.row { padding: 2px 3px; }
.row:hover { background-color: rgba(255, 255, 255, 0.12); }
@@ -42,20 +67,42 @@
.menu .sign::before { content: "+"; }
.menu.flipped .sign::before { content: "-"; }
- .networth { background-color: rgba(8, 12, 16, 0.78); border-top: 1px solid #45525c; padding-bottom: 2px; }
- .title { padding: 2px 4px; color: #aab6bf; }
- .title:hover { color: #ffffff; }
- .networth .sign::before { content: "- "; }
- .networth.flipped .sign::before { content: "+ "; }
- .networth.flipped .list { display: none; }
+ .picker { color: #e8c865; }
+ .picker:hover { color: #ffffff; }
+ .picker::after { content: " v"; }
+ .choices { display: none; background-color: rgba(0, 0, 0, 0.85); border: 1px solid #45525c; margin: 0 2px 2px 2px; }
+ .body.flipped .choices { display: block; }
+ .choice { padding: 2px 6px; color: #aab6bf; }
+ .choice:hover { background-color: rgba(255, 255, 255, 0.12); color: #ffffff; }
+ .choice.on { color: #e8c865; }
.player { height: 14px; margin: 1px 2px; }
.portrait { float: left; width: 22px; height: 14px; border-left: 2px solid #888888; }
- .track { position: relative; height: 14px; margin-left: 27px; }
+ .track { position: relative; height: 14px; margin-left: 27px; background-color: rgba(255, 255, 255, 0.05); }
.bar { position: absolute; left: 0; top: 0; height: 14px; }
.teams2.team0 .bar { background: linear-gradient(to right, #2f6b21, #72cf4b); }
.teams2.team1 .bar { background: linear-gradient(to right, #7a1d17, #e2553f); }
- .worth { position: relative; padding-left: 3px; line-height: 14px; font-weight: bold; color: #ffffff; }
+ .name { position: absolute; left: 3px; top: 0; line-height: 14px; color: #ffffff; }
+ .value { position: absolute; right: 3px; top: 0; line-height: 14px; font-weight: bold; color: #ffffff; }
+
+ .graph { display: none; }
+ .graph.shown { display: block; }
+ .lead { float: right; font-weight: bold; }
+ .team0 .lead { color: #72cf4b; }
+ .team1 .lead { color: #e2553f; }
+ .chart { height: 36px; margin: 1px 3px 0 3px; background-color: rgba(255, 255, 255, 0.05); }
+ .col { float: left; width: 3px; height: 36px; }
+ .half { position: relative; height: 18px; }
+ .over { border-bottom: 1px solid #45525c; height: 17px; }
+ .up { position: absolute; left: 0; right: 0; bottom: 0; background-color: #72cf4b; }
+ .down { position: absolute; left: 0; right: 0; top: 0; background-color: #e2553f; }
+
+ .army { overflow: hidden; padding: 0 2px; }
+ .cell { float: left; position: relative; width: 18px; height: 15px; margin: 1px 1px 0 0; }
+ .cell img { width: 18px; height: 15px; }
+ .cell.head { clear: left; width: 20px; padding: 0; border-left: 2px solid #888888; }
+ .cell.head img { width: 20px; }
+ .count { position: absolute; right: 1px; bottom: 0; font-size: 8px; font-weight: bold; color: #ffffff; }
</style>
</head>
<body>
@@ -70,19 +117,54 @@
</div>
</div>
- <div class="networth {{flip:networth}}">
- <div class="title" data-click="flip:networth"><span class="sign"></span>{{text:GUI:HudNetWorth}}</div>
- <div class="list">
+ <div class="panel {{flip:statsfold}}">
+ <div class="head">
+ <span class="fold" data-click="flip:statsfold"></span><span class="picker" data-click="flip:stat">{{stat}}</span>
+ </div>
+ <div class="body {{flip:stat}}">
+ <div class="choices">
+ <div class="choice {{pick:stat:networth}}" data-click="pick:stat:networth">{{text:GUI:HudNetWorth}}</div>
+ <div class="choice {{pick:stat:cash}}" data-click="pick:stat:cash">{{text:GUI:HudStatCash}}</div>
+ <div class="choice {{pick:stat:income}}" data-click="pick:stat:income">{{text:GUI:HudStatIncome}}</div>
+ <div class="choice {{pick:stat:army}}" data-click="pick:stat:army">{{text:GUI:HudStatArmy}}</div>
+ <div class="choice {{pick:stat:kills}}" data-click="pick:stat:kills">{{text:GUI:HudStatKills}}</div>
+ <div class="choice {{pick:stat:rank}}" data-click="pick:stat:rank">{{text:GUI:HudStatRank}}</div>
+ <div class="choice {{pick:stat:power}}" data-click="pick:stat:power">{{text:GUI:HudStatPower}}</div>
+ </div>
<div class="player teams{{teams}} team{{team}}" data-each="players">
<img class="portrait" src="{{portrait}}" style="border-color: {{color}}">
<div class="track">
<div class="bar" style="width: {{share}}%; background-color: {{color}}"></div>
- <span class="worth">{{networth}}</span>
+ <span class="name">{{name}}</span>
+ <span class="value">{{value}}</span>
</div>
</div>
</div>
</div>
+ <div class="panel graph {{graph}} {{flip:graphfold}}">
+ <div class="head {{leader}}">
+ <span class="fold" data-click="flip:graphfold"></span>{{text:GUI:HudNetWorthLead}}
+ <span class="lead">{{lead}}</span>
+ </div>
+ <div class="body chart">
+ <div class="col" data-each="lead">
+ <div class="half over"><div class="up" style="height: {{up}}%"></div></div>
+ <div class="half"><div class="down" style="height: {{down}}%"></div></div>
+ </div>
+ </div>
+ </div>
+
+ <div class="panel opens {{flip:armyfold}}">
+ <div class="head" data-click="flip:armyfold"><span class="fold"></span>{{text:GUI:HudArmies}}</div>
+ <div class="body army">
+ <div class="cell {{kind}}" data-each="army" style="border-color: {{color}}">
+ <img src="{{image}}">
+ <span class="count">{{count}}</span>
+ </div>
+ </div>
+ </div>
+
</div>
</body>
</html>
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index a4bf654e3..431b495a1 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -1198,17 +1198,23 @@ protected:
//
// The spectator's page over the battlefield, Window/Html/Spectator.html: the drop-down that
- // switches the strips on and off, and every player's net worth. Only while watching.
+ // switches the strips on and off, every player ranked by a chosen number, the net worth lead
+ // over time and what each army is made of. Only while watching.
//
void drawSpectatorPage( void );
Bool handleSpectatorPageClick( const ICoord2D *mouse, Bool act ); ///< TRUE when the click landed on it
+ void sampleSpectatorLead( Int lead, Bool twoTeams ); ///< the lead graph's next point, if one is due
HtmlOverlay * m_spectatorOverlay;
Bool m_spectatorPageLoaded; ///< read once a match, so an edited page shows in the next one
Bool m_spectatorPageShown; ///< drawn this frame, so clicks are its to take
std::string m_spectatorPage; ///< the page as written, before its {{values}} are filled
std::set< std::string > m_spectatorFlipped; ///< names a data-click="flip:name" has flipped
+ std::map< std::string, std::string > m_spectatorPicked; ///< group to choice, from data-click="pick:group:choice"
HtmlLists m_spectatorLists;
+ HtmlValues m_spectatorTotals; ///< the page's values that are not per player, gathered with the lists
UnsignedInt m_spectatorListsFrame; ///< the logic frame the lists were last gathered on
+ std::vector< Int > m_spectatorLead; ///< the first team's net worth less the second's, one per sample
+ UnsignedInt m_spectatorLeadFrame; ///< the logic frame the last of those was taken on
Int m_hudTogglesBottom; ///< the bottom of the page's #hud-top, so the message list starts under it
Bool m_placementRangeRingUp; ///< the structure on the cursor is armed, so its reach is drawn
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index f3fedbe55..ac07559e4 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1193,6 +1193,7 @@ InGameUI::InGameUI()
m_spectatorPageLoaded = FALSE;
m_spectatorPageShown = FALSE;
m_spectatorListsFrame = 0;
+ m_spectatorLeadFrame = 0;
m_hudTogglesBottom = 0;
m_scoreboardOpen = FALSE;
m_scoreboardStringsUsed = 0;
@@ -1741,17 +1742,28 @@ static Real elevatedReach( Real reach, Real range, const Coord3D &center, Real a
// matches without a build. What a data-click names is also the {{name}} that reads it back:
// data-click="option:Key" flips that on/off option and {{option:Key}} is "on" while it is on;
// data-click="flip:name" flips a switch that lasts the match and {{flip:name}} is "flipped" while
-// it is flipped. {{text:Label}} is a string table label in the player's language.
+// it is flipped. data-click="pick:group:choice" makes choice the group's one pick, so {{pick:group}}
+// is "choice" and {{pick:group:choice}} is "on", and folds up the flip of the same name: a drop-down
+// that flip:group opened closes on the choice made in it. {{text:Label}} is a string table label
+// in the player's language.
//-------------------------------------------------------------------------------------------------
static const char *const SPECTATOR_PAGE = "Window\\Html\\Spectator.html";
static const std::string OPTION_ACTION = "option:";
static const std::string FLIP_ACTION = "flip:";
+static const std::string PICK_ACTION = "pick:";
static const std::string TEXT_LOOKUP = "text:";
+static const std::string STAT_GROUP = "stat";
enum
{
HUD_TOGGLES_INSET = 6, ///< between the page's #hud-top and the messages under it, 800x600
NET_WORTH_REFRESH_FRAMES = LOGICFRAMES_PER_SECOND / 2, ///< how often every player's worth is counted again
+ FRAMES_PER_MINUTE = LOGICFRAMES_PER_SECOND * 60,
+ LEAD_SAMPLE_FRAMES = LOGICFRAMES_PER_SECOND * 10, ///< one point of the lead graph every ten seconds
+ LEAD_GRAPH_COLUMNS = 48, ///< the most columns the graph draws; a longer match is averaged into them
+ ARMY_CHART_UNITS = 6, ///< kinds of unit shown per player, the most money first
+ PLAYER_NAME_CHARS = 11, ///< a name longer than this is cut, there is no clipping to hide it
+ TWO_TEAMS = 2,
PERCENT = 100
};
@@ -1794,76 +1806,152 @@ static std::string cssColor( Color color )
return text;
}
-struct NetWorthGather
+/** Everything the page can rank one player by, counted in one walk over what he owns. */
+struct SpectatorStats
+{
+ Player *player;
+ Int team;
+ Int networth; ///< cash plus the build cost of everything standing
+ Int cash;
+ Int income; ///< money earned per minute of match, averaged over the whole of it
+ Int army; ///< the build cost of everything standing that is not a structure
+ Int kills; ///< units and buildings destroyed
+ Int losses;
+ Int rank;
+ Int power; ///< produced less consumed, negative when his base is browned out
+ std::map< const ThingTemplate *, Int > units; ///< how many of each unit with a cameo he has standing
+};
+
+/** One entry of the stat drop-down: what pick:stat:key names, the label it goes by, and the number
+ * the list is ranked by when it is picked. */
+struct SpectatorStat
{
- const Player *player;
- Int worth;
+ const char *key;
+ const char *label;
+ Int SpectatorStats::*value;
};
-static void addObjectWorth( Object *obj, void *userData )
+static const SpectatorStat SPECTATOR_STATS[] =
{
- NetWorthGather *gather = (NetWorthGather *)userData;
- if( !obj->isEffectivelyDead() )
- gather->worth += obj->getTemplate()->calcCostToBuild( gather->player );
+ { "networth", "GUI:HudNetWorth", &SpectatorStats::networth },
+ { "cash", "GUI:HudStatCash", &SpectatorStats::cash },
+ { "income", "GUI:HudStatIncome", &SpectatorStats::income },
+ { "army", "GUI:HudStatArmy", &SpectatorStats::army },
+ { "kills", "GUI:HudStatKills", &SpectatorStats::kills },
+ { "rank", "GUI:HudStatRank", &SpectatorStats::rank },
+ { "power", "GUI:HudStatPower", &SpectatorStats::power }
+};
+
+/** The stat pick:stat:key names, the first until one is picked. */
+static const SpectatorStat &spectatorStat( const std::map< std::string, std::string > &picked )
+{
+ std::map< std::string, std::string >::const_iterator pick = picked.find( STAT_GROUP );
+ for( Int stat = 0; pick != picked.end() && stat < (Int)ARRAY_SIZE( SPECTATOR_STATS ); stat++ )
+ if( pick->second == SPECTATOR_STATS[ stat ].key )
+ return SPECTATOR_STATS[ stat ];
+ return SPECTATOR_STATS[ 0 ];
+}
+
+static void addObjectStats( Object *obj, void *userData )
+{
+ SpectatorStats *stats = (SpectatorStats *)userData;
+ if( obj->isEffectivelyDead() )
+ return;
+
+ const ThingTemplate *thing = obj->getTemplate();
+ const Int cost = thing->calcCostToBuild( stats->player );
+ stats->networth += cost;
+ if( obj->isKindOf( KINDOF_STRUCTURE ) )
+ return;
+
+ stats->army += cost;
+ if( cost > 0 && thing->getButtonImage() != NULL )
+ stats->units[ thing ]++;
}
//-------------------------------------------------------------------------------------------------
-/** The page's "players" list: everyone still in the match, richest first, each with what his cash
- * and everything he has standing would cost to buy again. Allies both ways share a team number,
- * counted in the order the teams first appear in the player list, and every entry carries how
- * many teams there are, so a page can colour two sides the way Dota does and leave a free for all
- * in the players' own colours. */
+/** Everyone still in the match with his numbers, ranked by `stat`. Allies both ways share a team
+ * number, counted in the order the teams first appear in the player list; `teams` is how many. */
//-------------------------------------------------------------------------------------------------
-static void gatherNetWorth( std::vector< HtmlValues > &rows )
+static std::vector< SpectatorStats > gatherSpectatorStats( const SpectatorStat &stat, Int &teams )
{
- struct Worth
- {
- Player *player;
- Int worth;
- Int team;
- };
- std::vector< Worth > worths;
+ std::vector< SpectatorStats > players;
const Player *local = ThePlayerList->getLocalPlayer();
- Int teams = 0;
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ teams = 0;
for( Int index = 0; index < ThePlayerList->getPlayerCount(); index++ )
{
Player *player = ThePlayerList->getNthPlayer( index );
if( player == NULL || player == local || !player->isPlayerActive() || !player->isPlayableSide() )
continue;
- NetWorthGather gather;
- gather.player = player;
- gather.worth = player->getMoney()->countMoney();
- player->iterateObjects( addObjectWorth, &gather );
-
- Worth worth = { player, gather.worth, -1 };
- for( size_t earlier = 0; earlier < worths.size() && worth.team < 0; earlier++ )
- {
- const Player *other = worths[ earlier ].player;
+ ScoreKeeper *score = player->getScoreKeeper();
+ SpectatorStats stats;
+ stats.player = player;
+ stats.team = -1;
+ stats.cash = player->getMoney()->countMoney();
+ stats.networth = stats.cash;
+ stats.income = frame > 0 ? (Int)( (Int64)score->getTotalMoneyEarned() * FRAMES_PER_MINUTE / frame ) : 0;
+ stats.army = 0;
+ stats.kills = score->getTotalUnitsDestroyed() + score->getTotalBuildingsDestroyed();
+ stats.losses = score->getTotalUnitsLost() + score->getTotalBuildingsLost();
+ stats.rank = player->getRankLevel();
+ stats.power = player->getEnergy()->getProduction() - player->getEnergy()->getConsumption();
+ player->iterateObjects( addObjectStats, &stats );
+
+ for( size_t earlier = 0; earlier < players.size() && stats.team < 0; earlier++ )
+ {
+ const Player *other = players[ earlier ].player;
if( player->getRelationship( other->getDefaultTeam() ) == ALLIES && other->getRelationship( player->getDefaultTeam() ) == ALLIES )
- worth.team = worths[ earlier ].team;
+ stats.team = players[ earlier ].team;
}
- if( worth.team < 0 )
- worth.team = teams++;
- worths.push_back( worth );
+ if( stats.team < 0 )
+ stats.team = teams++;
+ players.push_back( stats );
}
- std::stable_sort( worths.begin(), worths.end(), []( const Worth &a, const Worth &b ) { return a.worth > b.worth; } );
- const Int richest = worths.empty() ? 0 : worths.front().worth;
+ const Int SpectatorStats::*value = stat.value;
+ std::stable_sort( players.begin(), players.end(),
+ [ value ]( const SpectatorStats &a, const SpectatorStats &b ) { return a.*value > b.*value; } );
+ return players;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The page's "players" list: one entry per player in the order `players` is ranked, the picked
+ * number written out and as a percentage of the highest. Every entry carries how many teams
+ * there are, so a page can colour two sides the way Dota does and leave a free for all in the
+ * players' own colours. */
+//-------------------------------------------------------------------------------------------------
+static void fillSpectatorPlayers( const std::vector< SpectatorStats > &players, const SpectatorStat &stat, Int teams,
+ std::vector< HtmlValues > &rows )
+{
+ Int highest = 0;
+ for( size_t index = 0; index < players.size(); index++ )
+ highest = max( highest, players[ index ].*stat.value );
rows.clear();
- for( size_t index = 0; index < worths.size(); index++ )
+ for( size_t index = 0; index < players.size(); index++ )
{
- const Worth &worth = worths[ index ];
- const PlayerTemplate *side = worth.player->getPlayerTemplate();
+ const SpectatorStats &stats = players[ index ];
+ const PlayerTemplate *side = stats.player->getPlayerTemplate();
const Image *portrait = side ? side->getEnabledImage() : NULL;
+ const Int value = stats.*stat.value;
+
+ std::wstring name( stats.player->getPlayerDisplayName().str() );
+ if( name.size() > PLAYER_NAME_CHARS )
+ name.resize( PLAYER_NAME_CHARS );
+
+ std::string text = std::to_string( value );
+ if( stat.value == &SpectatorStats::kills )
+ text += " / " + std::to_string( stats.losses );
HtmlValues row;
- row[ "name" ] = WideCharStringToMultiByte( worth.player->getPlayerDisplayName().str() );
- row[ "networth" ] = std::to_string( worth.worth );
- row[ "share" ] = std::to_string( richest > 0 ? worth.worth * PERCENT / richest : 0 );
- row[ "color" ] = cssColor( clientPlayerColor( worth.player ) );
- row[ "team" ] = std::to_string( worth.team );
+ row[ "name" ] = WideCharStringToMultiByte( name.c_str() );
+ row[ "value" ] = text;
+ row[ "networth" ] = std::to_string( stats.networth );
+ row[ "share" ] = std::to_string( highest > 0 && value > 0 ? value * PERCENT / highest : 0 );
+ row[ "color" ] = cssColor( clientPlayerColor( stats.player ) );
+ row[ "team" ] = std::to_string( stats.team );
row[ "teams" ] = std::to_string( teams );
row[ "portrait" ] = portrait ? portrait->getName().str() : "";
rows.push_back( row );
@@ -1871,8 +1959,100 @@ static void gatherNetWorth( std::vector< HtmlValues > &rows )
}
//-------------------------------------------------------------------------------------------------
-/** The spectator's page: the drop-down that switches the strips on and off, and every player's net
- * worth.
+/** The page's "army" list, Dota's item chart for an army: per player an entry of kind "head" with
+ * his portrait and colour, then his most expensive kinds of unit, each of kind "unit" with its
+ * cameo and how many are standing. Flat, so a page floats the entries and clears at each head. */
+//-------------------------------------------------------------------------------------------------
+static void fillSpectatorArmies( const std::vector< SpectatorStats > &players, std::vector< HtmlValues > &cells )
+{
+ typedef std::pair< const ThingTemplate *, Int > UnitCount;
+
+ cells.clear();
+ for( size_t index = 0; index < players.size(); index++ )
+ {
+ const SpectatorStats &stats = players[ index ];
+ const PlayerTemplate *side = stats.player->getPlayerTemplate();
+ const Image *portrait = side ? side->getEnabledImage() : NULL;
+
+ HtmlValues head;
+ head[ "kind" ] = "head";
+ head[ "image" ] = portrait ? portrait->getName().str() : "";
+ head[ "color" ] = cssColor( clientPlayerColor( stats.player ) );
+ cells.push_back( head );
+
+ const Player *owner = stats.player;
+ std::vector< UnitCount > units( stats.units.begin(), stats.units.end() );
+ std::stable_sort( units.begin(), units.end(), [ owner ]( const UnitCount &a, const UnitCount &b )
+ { return a.second * a.first->calcCostToBuild( owner ) > b.second * b.first->calcCostToBuild( owner ); } );
+ if( units.size() > ARMY_CHART_UNITS )
+ units.resize( ARMY_CHART_UNITS );
+
+ for( size_t unit = 0; unit < units.size(); unit++ )
+ {
+ HtmlValues cell;
+ cell[ "kind" ] = "unit";
+ cell[ "image" ] = units[ unit ].first->getButtonImage()->getName().str();
+ cell[ "count" ] = std::to_string( units[ unit ].second );
+ cells.push_back( cell );
+ }
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The page's "lead" list: the first team's net worth less the second's since the match began, as
+ * at most LEAD_GRAPH_COLUMNS columns, each with {{up}} or {{down}} the percentage of the biggest
+ * lead either way. A longer match averages neighbouring samples into one column. */
+//-------------------------------------------------------------------------------------------------
+static void fillSpectatorLead( const std::vector< Int > &samples, std::vector< HtmlValues > &columns )
+{
+ const Int count = (Int)samples.size();
+ const Int columnCount = min( count, (Int)LEAD_GRAPH_COLUMNS );
+ std::vector< Int > averages( columnCount );
+ Int biggest = 0;
+ for( Int column = 0; column < columnCount; column++ )
+ {
+ const Int first = column * count / columnCount;
+ const Int last = ( column + 1 ) * count / columnCount;
+ Int64 sum = 0;
+ for( Int sample = first; sample < last; sample++ )
+ sum += samples[ sample ];
+ averages[ column ] = (Int)( sum / ( last - first ) );
+ biggest = max( biggest, abs( averages[ column ] ) );
+ }
+
+ columns.clear();
+ for( Int column = 0; column < columnCount; column++ )
+ {
+ const Int share = biggest > 0 ? abs( averages[ column ] ) * PERCENT / biggest : 0;
+ HtmlValues entry;
+ entry[ "up" ] = std::to_string( averages[ column ] > 0 ? share : 0 );
+ entry[ "down" ] = std::to_string( averages[ column ] < 0 ? share : 0 );
+ columns.push_back( entry );
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The lead graph samples every LEAD_SAMPLE_FRAMES while two teams are left. A logic frame that
+ * went backwards is a new match or a load, and starts the graph again. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::sampleSpectatorLead( Int lead, Bool twoTeams )
+{
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ if( frame < m_spectatorLeadFrame )
+ m_spectatorLead.clear();
+ if( !twoTeams )
+ return;
+ if( !m_spectatorLead.empty() && frame < m_spectatorLeadFrame + LEAD_SAMPLE_FRAMES )
+ return;
+
+ m_spectatorLead.push_back( lead );
+ m_spectatorLeadFrame = frame;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The spectator's page: the drop-down that switches the strips on and off, every player ranked by
+ * the number picked in the stat drop-down, the net worth lead over the match and each army's most
+ * expensive units - the panels Dota's spectator keeps down the left of the screen.
*
* Watching a match three strips fight over the same picture - the production rows, the
* promotions, the superweapon countdowns - and which of them a spectator wants depends on what he
@@ -1913,11 +2093,34 @@ void InGameUI::drawSpectatorPage( void )
const UnsignedInt frame = TheGameLogic->getFrame();
if( m_spectatorLists.empty() || frame < m_spectatorListsFrame || frame >= m_spectatorListsFrame + NET_WORTH_REFRESH_FRAMES )
{
- gatherNetWorth( m_spectatorLists[ "players" ] );
+ const SpectatorStat &stat = spectatorStat( m_spectatorPicked );
+ Int teams = 0;
+ const std::vector< SpectatorStats > players = gatherSpectatorStats( stat, teams );
+ fillSpectatorPlayers( players, stat, teams, m_spectatorLists[ "players" ] );
+ fillSpectatorArmies( players, m_spectatorLists[ "army" ] );
+
+ Int lead = 0;
+ for( size_t index = 0; index < players.size(); index++ )
+ lead += players[ index ].team == 0 ? players[ index ].networth : -players[ index ].networth;
+ sampleSpectatorLead( lead, teams == TWO_TEAMS );
+ fillSpectatorLead( m_spectatorLead, m_spectatorLists[ "lead" ] );
+
+ m_spectatorTotals.clear();
+ m_spectatorTotals[ "stat" ] = WideCharStringToMultiByte( TheGameText->fetch( stat.label ).str() );
+ m_spectatorTotals[ PICK_ACTION + STAT_GROUP + ":" + stat.key ] = "on";
+ m_spectatorTotals[ "teams" ] = std::to_string( teams );
+ m_spectatorTotals[ "lead" ] = std::to_string( abs( lead ) );
+ m_spectatorTotals[ "leader" ] = lead == 0 ? "" : ( lead > 0 ? "team0" : "team1" );
+ m_spectatorTotals[ "graph" ] = teams == TWO_TEAMS && m_spectatorLead.size() >= TWO_TEAMS ? "shown" : "";
m_spectatorListsFrame = frame;
}
- HtmlValues values;
+ HtmlValues values = m_spectatorTotals;
+ for( std::map< std::string, std::string >::const_iterator pick = m_spectatorPicked.begin(); pick != m_spectatorPicked.end(); ++pick )
+ {
+ values[ PICK_ACTION + pick->first ] = pick->second;
+ values[ PICK_ACTION + pick->first + ":" + pick->second ] = "on";
+ }
for( Int row = 0; row < TheOptionCatalogCount; row++ )
if( TheOptionCatalog[ row ].kind == OPTION_BOOL && TheOptionCatalog[ row ].get() )
values[ OPTION_ACTION + TheOptionCatalog[ row ].iniKey ] = "on";
@@ -1949,6 +2152,21 @@ Bool InGameUI::handleSpectatorPageClick( const ICoord2D *mouse, Bool act )
if( m_spectatorFlipped.erase( name ) == 0 )
m_spectatorFlipped.insert( name );
}
+ else if( action.compare( 0, PICK_ACTION.size(), PICK_ACTION ) == 0 )
+ {
+ const std::string pick = action.substr( PICK_ACTION.size() );
+ const size_t colon = pick.find( ':' );
+ if( colon == std::string::npos )
+ {
+ DEBUG_LOG(( "Spectator page: data-click=\"%s\" is not pick:group:choice\n", action.c_str() ));
+ return TRUE;
+ }
+
+ const std::string group = pick.substr( 0, colon );
+ m_spectatorPicked[ group ] = pick.substr( colon + 1 );
+ m_spectatorFlipped.erase( group );
+ m_spectatorLists.clear();
+ }
else if( action.compare( 0, OPTION_ACTION.size(), OPTION_ACTION ) == 0 )
{
const OptionDef *option = findOptionDef( action.substr( OPTION_ACTION.size() ).c_str() );
@@ -3394,7 +3612,11 @@ void InGameUI::reset( void )
m_scoreboardOpen = FALSE;
m_spectatorPageLoaded = FALSE;
m_spectatorFlipped.clear();
+ m_spectatorPicked.clear();
m_spectatorLists.clear();
+ m_spectatorTotals.clear();
+ m_spectatorLead.clear();
+ m_spectatorLeadFrame = 0;
m_inputEnabled = true;
// reset the command bar
TheControlBar->reset();