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): director record score bar and plates for any team layout

Olcay Seygan167254e7928a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 45979cd09..091d5e3d0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -749,7 +749,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- Watching, the bars over the buildings are everyone's too - what each factory is turning out, and how long the superweapons have left. An observer used to see none of it.
- Watching, the camera can drive itself. Two drop-downs in the camera panel on the right, above the board, say who has it and which player you follow, and you can follow nobody. The Director goes to the fight with the most on the line over the last five seconds, where a dead Overlord counts for more than six riflemen being shot at and anything happening to a superweapon counts three times over. It stays with that fight twelve seconds, leaves after six only for one four times the size, and after half a minute on the same fight a third bigger is enough. So a 4v4 is watched like a broadcast rather than hunted for, and it does not hop between spots every few seconds. Any general's power used on the map outranks every fight. A nuke is shown in its silo as it leaves, then the camera waits at the target for it to come down and stays through the blast. The particle cannon's beam is followed along its whole sweep, and a Scud Storm or a carpet bomb is watched until the last explosion has died down. Then it goes back to the fighting. The camera glides between places and slows into each one, and only cuts when the next one is across most of the map. When nobody is shooting it no longer parks on empty ground: it goes round what is worth seeing, an army on the march, a superweapon, a base going up, the rest of a base, the dearest first and fourteen seconds each, and does not come back to one of the last three while there is anything else to show. With a player picked it keeps to his fights and his own armies and buildings. Player camera shows his screen: a human player's camera comes over the network five times a second, smoothed in between, and a computer player, who has no camera, gets the Director narrowed to his own fights. Scroll with the keys or a drag, turn the view or click the radar and the camera is yours again, still following the same player. The edge of the screen does not scroll while it drives: the panel on the right stands on that edge, and reaching for it used to hand the camera back to you, so the Director stopped following the fighting the first time you went to change a setting. In a replay with the recorded camera switched on in the options, the player you follow still drives the camera the way his button in the old list did.
- Watching, the Director climbs over a wide battle until the whole of it is on the screen, and comes back down to your own height when it moves on or you take the camera. The mouse wheel still zooms while it drives, and it keeps what you chose. It stops short of the map's border too, where a fight on the edge used to come with a black corner of nothing beside it. A nuke or a Scud Storm is shown leaving its silo even when the Director has only just arrived at another fight; before, the launch was over by the time it was allowed to move. Rewinding a replay leaves your camera settings as they were, where a rewind used to hand you back a free camera with nobody followed. And following one player while a superweapon wiped out everything he had at the spot could close the game. It no longer does.
-- Watching can be filmed. Start the game with `-directorrecord` and the Director has the camera from the first second, with nothing over the picture but the radar, and the whole match goes into one video; the game closes itself when the match is decided or the replay runs out. Beside `-replay` it turns an old match into footage, and beside four computer players it films a match nobody played. It plays the match twice. The first time there is no picture and the game runs as fast as the machine goes, 8,000 frames of a four-player match in 17 seconds, writing down where each fight starts and when each superweapon fires; the second time it films, and the camera is already at a fight four seconds before the first shot instead of arriving halfway through it. When two fights are about to start far apart the screen splits three seconds before the second begins, and only when the first run saw the Director's own fight go on for the whole time the split will be up, so the second picture never sweeps in and straight back out. A skirmish the first run saw come to nothing is not cut to, and neither is a special power that hurts nobody: an Air Force general's spy satellite every minute used to pull the camera to empty ground, where a carpet bomb or an artillery strike still gets it from the launch. Each half keeps its own fight. The main camera used to leave for the second half's fight as it began, and the two halves glided past each other over empty ground and swapped places; now it takes that fight over only once its own is finished, and the second half closes as it does. The two runs compare the whole state of the game every 30 seconds, and if they ever disagree the rest is filmed the old way, finding fights as they happen. A skirmish without `-seed` is handed one, the same for both runs. The film opens on every player at once: the screen cut into one picture per player along lines at 45 degrees that meet round the radar, two players on a diagonal and four on an X, each picture on that player's base. Seven seconds in they sweep away to the Director's single view, which stays on the first player's base until something happens instead of gliding across empty ground to another one. When two real fights far apart are both worth watching, the radar slides out of its corner, then the second fight sweeps in from the corner along a 45 degree diagonal, carrying the radar in a frame of the same line to the middle, one fight on each side with its own camera gliding to it. Going back is the same film run backwards: the second fight sweeps out with the radar, and the radar slides back into its corner. The lines are the Reforged gold on a dark edge, so they read on snow and at night, and they run straight into the radar's frame. While the screen is cut, each picture frames its own fight: the camera puts it in the biggest round space its slice has clear of the lines and the radar, and rises until the whole fight fits there with room to spare, never lower than the Director flies and never more than three times as high. A fight that spreads is let out smoothly; one that shrinks does not make the picture pump in and out. The opening frames each player's base the same way. A split holds at least six seconds after its second picture is all the way in and ends once the second fight has burnt down to a quarter of the first, and the picture then stays whole four seconds even for a fight the first run saw coming, so it does not flicker between one and two. The two fights have to be further apart than either half's picture is wide once it has risen to fit its fight, so no piece of ground shows in both: at a fixed 660 the two halves of a 1v1 showed the same bridge from neighbouring angles. A crowd beside the Director's fight that the first run saw as part of it does not split the screen either; that was the Director's own fight spreading, and the second half swept in for two seconds before the camera followed it there. Only the video shows the other pictures; the window keeps the Director's own fight under the lines. Two bases going up are not a fight, and the split ends the moment the camera's own fight and the second one turn out to be the same. The pictures go straight into ffmpeg as they are drawn, so an hour of 1080p does not need tens of gigabytes of disk first; put ffmpeg beside the game or on your PATH, because without it nothing is recorded and the game says so and closes. The film carries a score bar across the top in the Reforged colours: every player's name in his own colour, his general, his cash and what his army cost (a computer player goes by his general with his difficulty beside it, where every one of them used to read "Hard AI"), the match clock in the middle, and under it one bar the two sides' armies pull on, each player's share in his colour and a gold mark at the middle, so whoever is past it is ahead. Each picture of the opening names its player on a plate hanging just over his command centre, and the plate stays on the building as the camera rises and the pictures sweep away. Each half of a split names the players in its fight, in a plate inside its own slice clear of the lines and the radar, and while the halves sweep in it rides above its fight, where it used to slide down over it. It is sized from the screen's height and reads the same at 720p and 1080p, and the pictures under it are framed below it, so no base or fight sits behind the bar. Any recorded clip also plays its animations at their real speed now. The animation clock used to move by however long each picture took to save, and a slow disk made every explosion in the footage run fast.
+- Watching can be filmed. Start the game with `-directorrecord` and the Director has the camera from the first second, with nothing over the picture but the radar, and the whole match goes into one video; the game closes itself when the match is decided or the replay runs out. Beside `-replay` it turns an old match into footage, and beside four computer players it films a match nobody played. It plays the match twice. The first time there is no picture and the game runs as fast as the machine goes, 8,000 frames of a four-player match in 17 seconds, writing down where each fight starts and when each superweapon fires; the second time it films, and the camera is already at a fight four seconds before the first shot instead of arriving halfway through it. When two fights are about to start far apart the screen splits three seconds before the second begins, and only when the first run saw the Director's own fight go on for the whole time the split will be up, so the second picture never sweeps in and straight back out. A skirmish the first run saw come to nothing is not cut to, and neither is a special power that hurts nobody: an Air Force general's spy satellite every minute used to pull the camera to empty ground, where a carpet bomb or an artillery strike still gets it from the launch. Each half keeps its own fight. The main camera used to leave for the second half's fight as it began, and the two halves glided past each other over empty ground and swapped places; now it takes that fight over only once its own is finished, and the second half closes as it does. The two runs compare the whole state of the game every 30 seconds, and if they ever disagree the rest is filmed the old way, finding fights as they happen. A skirmish without `-seed` is handed one, the same for both runs. The film opens on every player at once: the screen cut into one picture per player along lines at 45 degrees that meet round the radar, two players on a diagonal and four on an X, each picture on that player's base. Seven seconds in they sweep away to the Director's single view, which stays on the first player's base until something happens instead of gliding across empty ground to another one. When two real fights far apart are both worth watching, the radar slides out of its corner, then the second fight sweeps in from the corner along a 45 degree diagonal, carrying the radar in a frame of the same line to the middle, one fight on each side with its own camera gliding to it. Going back is the same film run backwards: the second fight sweeps out with the radar, and the radar slides back into its corner. The lines are the Reforged gold on a dark edge, so they read on snow and at night, and they run straight into the radar's frame. While the screen is cut, each picture frames its own fight: the camera puts it in the biggest round space its slice has clear of the lines and the radar, and rises until the whole fight fits there with room to spare, never lower than the Director flies and never more than three times as high. A fight that spreads is let out smoothly; one that shrinks does not make the picture pump in and out. The opening frames each player's base the same way. A split holds at least six seconds after its second picture is all the way in and ends once the second fight has burnt down to a quarter of the first, and the picture then stays whole four seconds even for a fight the first run saw coming, so it does not flicker between one and two. The two fights have to be further apart than either half's picture is wide once it has risen to fit its fight, so no piece of ground shows in both: at a fixed 660 the two halves of a 1v1 showed the same bridge from neighbouring angles. A crowd beside the Director's fight that the first run saw as part of it does not split the screen either; that was the Director's own fight spreading, and the second half swept in for two seconds before the camera followed it there. Only the video shows the other pictures; the window keeps the Director's own fight under the lines. Two bases going up are not a fight, and the split ends the moment the camera's own fight and the second one turn out to be the same. The pictures go straight into ffmpeg as they are drawn, so an hour of 1080p does not need tens of gigabytes of disk first; put ffmpeg beside the game or on your PATH, because without it nothing is recorded and the game says so and closes. The film carries a score bar across the top in the Reforged colours: every player's name in his own colour, his general, his cash and what his army cost (a computer player goes by his general with his difficulty beside it, where every one of them used to read "Hard AI"), the match clock in the middle, and under it one bar the two sides' armies pull on, each player's share in his colour and a gold mark at the middle, so whoever is past it is ahead. Teammates sit together on it with their team's army total under them, a free for all deals its players to both sides, and with three sides or more the bar is every side's share end to end. Eight players fit at 720p: a side of more than three rows sets them smaller and drops the general column. A dark colour like purple is lightened where it is text, so it reads on the bar's ground, and the gold player's colour gets a dark edge so it does not melt into the gold lines. A skirmish can be staged in any shape now, 4v1 or three players alone beside a pair: `-team 4 0` puts slot 4 on team 0. The opening seats teammates next to each other and names their team on their plates, and a split names a team as "Team A" where a player alone keeps his own name. Each picture of the opening names its player on a plate hanging just over his command centre, and the plate stays on the building as the camera rises and the pictures sweep away. Each half of a split names the players in its fight, in a plate inside its own slice clear of the lines and the radar, and while the halves sweep in it rides above its fight, where it used to slide down over it. It is sized from the screen's height and reads the same at 720p and 1080p, and the pictures under it are framed below it, so no base or fight sits behind the bar. Any recorded clip also plays its animations at their real speed now. The animation clock used to move by however long each picture took to save, and a slow disk made every explosion in the footage run fast.
- Watching, tick Fog of war under the camera and you see what the player you follow sees and nothing more: black where he has never been, grey where he has been, none of the enemy he cannot see, and an enemy base as he last saw it. Stealth goes by his eyes too: a Jarmen Kell he has not found is gone from the screen and the radar, and his own stealthed units show the way they show him. It stays on whoever drives the camera, until you switch it off or follow nobody. Switch to another player and his fog comes in whole, shadows included: a building he has never seen casts nothing on his grey ground. An observer used to have no fog at all: the whole map, all match, with no way to see the game the way one of its players was seeing it.
- An ally, and anyone watching, now sees a stealthed unit's muzzle flash, its promotion and the cash it earns - if they can see the unit at all. Those three asked 'is it mine' instead of 'can I see it', so allies and observers got nothing.
- Watching, the match opens on the middle of the map. An observer has no start position, so the game looked for the camera waypoint of "player zero", did not find it, and fell back to the corner of the map: every match watched from the stands began pointed at empty ground in the south west.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 300914b44..545c32e38 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -77,6 +77,9 @@ enum HealthBarModeType
/** The HudScale option's steps, 100/115/130/150% of the bottom HUD's own size (ControlBarHudScale). */
enum { HUD_SCALE_COUNT = 4 };
+/// -team left a slot alone: its team comes from -teams, or none
+enum { AUTO_SKIRMISH_TEAM_UNSET = -2 };
+
/** The interface: the HUD, mouse and keys of Zero Hour 1.04, or this fork's own. Picked for each
* run by -interface (the launcher passes it), Classic without it; Options.ini has no say. Client
* only, and never read by GameLogic: two players on different styles are still in the same game. */
@@ -501,6 +504,7 @@ public:
AsciiString m_cinemaScript; ///< -cinema <name>: interface off, camera flown by Run/Cinema/<name>.txt (empty = off)
Bool m_autoSkirmishTakeover; ///< -takeover: give every -autoskirmish slot a driverless human seat, so nothing thinks unless a scenario says so
AsciiString m_autoSkirmishSide[ MAX_PLAYER_COUNT ]; ///< -side <slot> <faction>: name that slot's faction instead of drawing it from the seed
+ Int m_autoSkirmishTeam[ MAX_PLAYER_COUNT ]; ///< -team <slot> <n>: that slot's team, -1 for none; AUTO_SKIRMISH_TEAM_UNSET leaves it to -teams
AsciiString m_netGameHosts; ///< -netgame <ip>[,<ip>...]: the slot list of a LAN game started from the command line (empty = off)
Bool m_netGameStarted; ///< that -netgame passed its checks and StartAutomatedGame ran, so every seat has this command line
Int m_netGameLocalSlot; ///< -netslot <n>: which of those addresses this copy of the game is
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
index fdc8fc05a..cf40068d9 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -51,6 +51,7 @@
#include "Common/AsciiString.h"
#include "Common/GameCommon.h"
+#include "GameClient/Color.h"
#include "GameClient/View.h"
#include <vector>
@@ -235,6 +236,21 @@ void ObserverCamera_paneCircles( const Real *rays, Int count, Int width, Int hei
/// holds all of it, so it stays inside the pane and clear of its lines; the circle's middle row when
/// it is too wide for that
Real ObserverCamera_paneLabelTop( const Coord2D &centre, Real radius, Real width, Real height );
+/// the score bar's column, 0 left and 1 right, for each block of players, given each block's size:
+/// two blocks face each other; more go one by one to the column with fewer rows, a block of two or
+/// more counting the row of its total as well
+std::vector< Int > ObserverCamera_blockColumns( const std::vector< Int > &sizes );
+/// values cut into width pixels in proportion, the rounding handed to the largest remainders so the
+/// pieces fill width exactly; all zero when the values add up to nothing
+std::vector< Int > ObserverCamera_barShares( const std::vector< Int > &values, Int width );
+/// the order to take things in so the ones of one team sit together, the teams in the order they
+/// first appear and each team's members in their own order
+std::vector< Int > ObserverCamera_teamOrder( const std::vector< Int > &teams );
+/// a player's colour lifted towards white until it reads on the broadcast's ground at 4.5 to 1;
+/// a colour that already does comes back unchanged
+Color ObserverCamera_readableColor( Color color );
+/// whether a player's colour is close enough to the brand gold of the lines to need an edge
+Bool ObserverCamera_nearBrandGold( Color color );
/// how far from around the farthest of the things within reach of it lie, on the ground, and never less
/// than least
Real ObserverCamera_extentAround( const std::vector< DirectorHeat > &things, const Coord2D &around, Real reach, Real least );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index f1f726d38..dadf1390e 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -2062,6 +2062,23 @@ Int parseSide(char *args[], int num)
return 1;
}
+/* -team <slot> <n> puts one -autoskirmish slot on team n, -1 for none, over whatever -teams gave
+ it. -teams only splits evenly into blocks; this stages any layout, 4v1, 2v1 or three players
+ alone beside a pair (-team 3 0 -team 4 0 with the rest -1). */
+Int parseTeam(char *args[], int num)
+{
+ if (TheWritableGlobalData && num > 2 && args[1] && args[2])
+ {
+ const Int slot = atoi(args[1]);
+ if (slot >= 0 && slot < MAX_SLOTS)
+ TheWritableGlobalData->m_autoSkirmishTeam[slot] = max(atoi(args[2]), -1);
+ else
+ DEBUG_LOG(("-team: slot %d is outside 0..%d\n", slot, MAX_SLOTS - 1));
+ return 3;
+ }
+ return 1;
+}
+
/* -takeover empties every -autoskirmish seat instead of filling it with an AI.
SLOT_TAKEOVER is an occupied seat with nothing behind it: startNewGame writes playerIsHuman for
@@ -2633,6 +2650,7 @@ static CommandLineParam params[] =
{ "-cinema", parseCinema },
{ "-freecam", parseFreeCamera },
{ "-side", parseSide },
+ { "-team", parseTeam },
{ "-takeover", parseTakeover },
{ "-replay", parseReplay },
{ "-loadsave", parseLoadSave },
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index eebf513f7..dd90a5202 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -709,6 +709,8 @@ static void startAutoSkirmish( Int numPlayersWanted )
if (teamNumber >= teams)
teamNumber = teams - 1; // an uneven split puts the remainder on the last team
}
+ if (TheGlobalData->m_autoSkirmishTeam[ i ] != AUTO_SKIRMISH_TEAM_UNSET)
+ teamNumber = TheGlobalData->m_autoSkirmishTeam[ i ];
slot.setTeamNumber( teamNumber );
TheSkirmishGameInfo->setSlot( i, slot );
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 39ac97b83..e480b81cb 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -756,7 +756,10 @@ GlobalData::GlobalData()
m_cinemaScript.clear(); // the interface is on and the camera belongs to the player
m_autoSkirmishTakeover = FALSE; // the AI plays the opponents unless -takeover empties their seats
for( Int slot = 0; slot < MAX_PLAYER_COUNT; slot++ )
+ {
m_autoSkirmishSide[ slot ].clear(); // every faction still comes out of the seed unless -side names one
+ m_autoSkirmishTeam[ slot ] = AUTO_SKIRMISH_TEAM_UNSET; // and every team out of -teams unless -team names one
+ }
m_netGameHosts.clear(); // no network game from the command line
m_netGameStarted = FALSE;
m_netGameLocalSlot = 0;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index b3989d2b3..90c492194 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -10539,6 +10539,9 @@ static const char *const BROADCAST_NUMBERS = "Consolas";
/// the broadcast's sizes are a 720 row picture's, grown with the picture's height
static const Real BROADCAST_ROWS = 720.0f;
static const Int BROADCAST_NAME_POINTS = 11;
+static const Int BROADCAST_COMPACT_POINTS = 8;
+/// a column with more rows than this, totals counted, sets its rows compact
+static const Int BROADCAST_FULL_ROWS = 3;
static const Int BROADCAST_SIDE_POINTS = 9;
static const Int BROADCAST_HEAD_POINTS = 7;
static const Int BROADCAST_CLOCK_POINTS = 16;
@@ -10593,6 +10596,41 @@ static UnicodeString broadcastSide( Player *player )
return player->getPlayerType() == PLAYER_COMPUTER ? player->getPlayerDisplayName() : player->getPlayerTemplate()->getDisplayName();
}
+/** How many of players are on team. */
+static Int broadcastTeamSize( const std::vector< SpectatorStats > &players, Int team )
+{
+ Int size = 0;
+ for( size_t index = 0; index < players.size(); index++ )
+ size += players[ index ].team == team ? 1 : 0;
+ return size;
+}
+
+/** A team of two or more by its letter, Team A the first such team in team order; a player alone has
+ * no team name. */
+static UnicodeString broadcastTeamName( const std::vector< SpectatorStats > &players, Int team )
+{
+ Int letter = 'A';
+ for( Int earlier = 0; earlier < team; earlier++ )
+ letter += broadcastTeamSize( players, earlier ) >= 2 ? 1 : 0;
+ AsciiString name;
+ name.format( "Team %c", letter );
+ UnicodeString text;
+ text.translate( name );
+ return text;
+}
+
+/** A player's colour as a filled rectangle; one near the lines' gold gets an edge of the ground round
+ * it, so it does not run into them. */
+static void drawBroadcastSwatch( Int left, Int top, Int width, Int height, Color color )
+{
+ if( width <= 0 )
+ return;
+ TheDisplay->drawFillRect( left, top, width, height, color );
+ if( !ObserverCamera_nearBrandGold( color ) || width < 3 )
+ return;
+ TheDisplay->drawOpenRect( left, top, width, height, 1.0f, BROADCAST_GROUND );
+}
+
/// a label on the picture: pieces of text side by side, each its colour, on the ground with the gold
/// rule along its bottom
struct BroadcastPlate
@@ -10689,29 +10727,45 @@ void InGameUI::drawDirectorBroadcast( void )
const Int rule = broadcastPixels( BROADCAST_RULE );
const Int tug = broadcastPixels( BROADCAST_TUG );
- const Int teams = players.back().team + 1;
- size_t leftCount = ( players.size() + 1 ) / 2;
- if( teams == 2 )
+ // a block is one side: a team, or a player on his own. Two face each other; more are dealt to the
+ // two columns whole, so teammates stay together, and a team of two or more has a row of its total
+ std::vector< Int > blockFirst, blockSizes, blockArmies;
+ for( size_t index = 0; index < players.size(); index++ )
{
- leftCount = 0;
- while( players[ leftCount ].team == 0 )
- leftCount++;
+ if( index == 0 || players[ index ].team != players[ index - 1 ].team )
+ {
+ blockFirst.push_back( (Int)index );
+ blockSizes.push_back( 0 );
+ blockArmies.push_back( 0 );
+ }
+ blockSizes.back()++;
+ blockArmies.back() += players[ index ].army;
}
+ const Int blocks = (Int)blockSizes.size();
+ const std::vector< Int > columns = ObserverCamera_blockColumns( blockSizes );
+ // a column of more than three rows goes compact, smaller and without the side column: four rows
+ // a side and a total at full size took a third of a 720 row picture
+ Int columnRows[ 2 ] = { 0, 0 };
+ for( Int block = 0; block < blocks; block++ )
+ columnRows[ columns[ block ] ] += blockSizes[ block ] + ( blockSizes[ block ] >= 2 ? 1 : 0 );
+ const Bool compact = max( columnRows[ 0 ], columnRows[ 1 ] ) > BROADCAST_FULL_ROWS;
+ const std::string size = compact ? "compact" : "";
+ const Int rowPoints = broadcastPoints( compact ? BROADCAST_COMPACT_POINTS : BROADCAST_NAME_POINTS );
std::vector< BroadcastRow > rows;
Int nameWidth = 0, sideWidth = 0, cashWidth = 0, armyWidth = 0, rowHeight = 0;
- Int armies[ 2 ] = { 0, 0 };
for( size_t index = 0; index < players.size(); index++ )
{
const SpectatorStats &stats = players[ index ];
- const std::string seat = std::to_string( stats.player->getPlayerIndex() );
+ const std::string seat = size + std::to_string( stats.player->getPlayerIndex() );
BroadcastRow row;
row.stats = &stats;
row.color = clientPlayerColor( stats.player );
- row.name = broadcastText( "name" + seat, broadcastName( stats.player ), BROADCAST_WORDS, broadcastPoints( BROADCAST_NAME_POINTS ), TRUE );
- row.side = broadcastText( "side" + seat, broadcastSide( stats.player ), BROADCAST_WORDS, broadcastPoints( BROADCAST_SIDE_POINTS ), FALSE );
- row.cash = broadcastText( "cash" + seat, broadcastNumber( "$", stats.cash ), BROADCAST_NUMBERS, broadcastPoints( BROADCAST_NAME_POINTS ), TRUE );
- row.army = broadcastText( "army" + seat, broadcastNumber( "", stats.army ), BROADCAST_NUMBERS, broadcastPoints( BROADCAST_NAME_POINTS ), TRUE );
+ row.name = broadcastText( "name" + seat, broadcastName( stats.player ), BROADCAST_WORDS, rowPoints, TRUE );
+ row.side = broadcastText( "side" + seat, compact ? UnicodeString::TheEmptyString : broadcastSide( stats.player ), BROADCAST_WORDS,
+ broadcastPoints( BROADCAST_SIDE_POINTS ), FALSE );
+ row.cash = broadcastText( "cash" + seat, broadcastNumber( "$", stats.cash ), BROADCAST_NUMBERS, rowPoints, TRUE );
+ row.army = broadcastText( "army" + seat, broadcastNumber( "", stats.army ), BROADCAST_NUMBERS, rowPoints, TRUE );
Int width = 0, height = 0;
row.name->getSize( &width, &height );
nameWidth = max( nameWidth, width );
@@ -10723,10 +10777,29 @@ void InGameUI::drawDirectorBroadcast( void )
rowHeight = max( rowHeight, height );
row.army->getSize( &width, &height );
armyWidth = max( armyWidth, width );
- armies[ index < leftCount ? 0 : 1 ] += stats.army;
rows.push_back( row );
}
+ // each team's name and its army's total; the total is measured into the army column
+ std::vector< DisplayString * > teamNames( blocks, NULL ), teamTotals( blocks, NULL );
+ Int totalHeight = 0;
+ for( Int block = 0; block < blocks; block++ )
+ {
+ if( blockSizes[ block ] < 2 )
+ continue;
+ const std::string key = size + std::to_string( block );
+ const Int totalPoints = broadcastPoints( compact ? BROADCAST_COMPACT_POINTS : BROADCAST_SIDE_POINTS );
+ teamNames[ block ] = broadcastText( "teamname" + key, broadcastTeamName( players, players[ blockFirst[ block ] ].team ), BROADCAST_WORDS,
+ totalPoints, TRUE );
+ teamTotals[ block ] = broadcastText( "teamtotal" + key, broadcastNumber( "", blockArmies[ block ] ), BROADCAST_NUMBERS, totalPoints, TRUE );
+ Int width = 0, height = 0;
+ teamNames[ block ]->getSize( &width, &height );
+ totalHeight = max( totalHeight, height );
+ teamTotals[ block ]->getSize( &width, &height );
+ armyWidth = max( armyWidth, width );
+ totalHeight = max( totalHeight, height );
+ }
+
DisplayString *cashHead = broadcastText( "cashhead", TheGameText->fetch( "GUI:HudStatCash" ), BROADCAST_NUMBERS,
broadcastPoints( BROADCAST_HEAD_POINTS ), FALSE );
DisplayString *armyHead = broadcastText( "armyhead", TheGameText->fetch( "GUI:HudStatArmy" ), BROADCAST_NUMBERS,
@@ -10736,10 +10809,8 @@ void InGameUI::drawDirectorBroadcast( void )
DisplayString *clock = broadcastText( "clock", clockText, BROADCAST_NUMBERS, broadcastPoints( BROADCAST_CLOCK_POINTS ), TRUE );
// the number columns are as wide as six digits whatever they hold, so the bar does not change its
// width every time a player's cash crosses a thousand
- DisplayString *cashWidest = broadcastText( "cashwidest", broadcastNumber( "$", BROADCAST_WIDEST ), BROADCAST_NUMBERS,
- broadcastPoints( BROADCAST_NAME_POINTS ), TRUE );
- DisplayString *armyWidest = broadcastText( "armywidest", broadcastNumber( "", BROADCAST_WIDEST ), BROADCAST_NUMBERS,
- broadcastPoints( BROADCAST_NAME_POINTS ), TRUE );
+ DisplayString *cashWidest = broadcastText( "cashwidest" + size, broadcastNumber( "$", BROADCAST_WIDEST ), BROADCAST_NUMBERS, rowPoints, TRUE );
+ DisplayString *armyWidest = broadcastText( "armywidest" + size, broadcastNumber( "", BROADCAST_WIDEST ), BROADCAST_NUMBERS, rowPoints, TRUE );
Int cashHeadWidth = 0, armyHeadWidth = 0, headHeight = 0, clockWidth = 0, clockHeight = 0, widestHeight = 0;
Int cashWidestWidth = 0, armyWidestWidth = 0;
cashHead->getSize( &cashHeadWidth, &headHeight );
@@ -10752,9 +10823,17 @@ void InGameUI::drawDirectorBroadcast( void )
// the bar's measures, its left edge at left and its top on the screen's
const Int half = swatch + gap / 2 + nameWidth + gap + sideWidth + gap + cashColumn + gap + armyColumn;
- const Int rowCount = (Int)max( leftCount, rows.size() - leftCount );
+ const Int blockGap = gap / 2;
+ Int columnHeights[ 2 ] = { 0, 0 };
+ for( Int block = 0; block < blocks; block++ )
+ {
+ Int &columnHeight = columnHeights[ columns[ block ] ];
+ if( columnHeight > 0 )
+ columnHeight += blockGap;
+ columnHeight += blockSizes[ block ] * ( rowHeight + rowGap ) + ( teamNames[ block ] != NULL ? totalHeight + rowGap : 0 );
+ }
const Int tableTop = pad + headHeight;
- const Int tableBottom = tableTop + rowCount * ( rowHeight + rowGap );
+ const Int tableBottom = tableTop + max( columnHeights[ 0 ], columnHeights[ 1 ] );
const Int clockBox = clockWidth + 2 * gap;
const Int width = 2 * ( pad + half + pad ) + clockBox;
const Int left = ( TheDisplay->getWidth() - width ) / 2;
@@ -10779,48 +10858,85 @@ void InGameUI::drawDirectorBroadcast( void )
armyHead->draw( rightArmyEnd - armyHeadWidth, pad, BROADCAST_MUTED, BROADCAST_GROUND );
cashHead->draw( rightCashEnd - cashHeadWidth, pad, BROADCAST_MUTED, BROADCAST_GROUND );
- for( size_t index = 0; index < rows.size(); index++ )
- {
- const BroadcastRow &row = rows[ index ];
- const Bool onLeft = index < leftCount;
- const Int top = tableTop + (Int)( onLeft ? index : index - leftCount ) * ( rowHeight + rowGap );
- Int nameW = 0, nameH = 0, sideW = 0, sideH = 0, cashW = 0, cashH = 0, armyW = 0, armyH = 0;
- row.name->getSize( &nameW, &nameH );
- row.side->getSize( &sideW, &sideH );
- row.cash->getSize( &cashW, &cashH );
- row.army->getSize( &armyW, &armyH );
- const Int swatchLeft = onLeft ? left + pad : rightStart + half - swatch;
- const Int nameLeft = onLeft ? swatchLeft + swatch + gap / 2 : swatchLeft - gap / 2 - nameW;
- const Int sideLeft = onLeft ? nameLeft + nameWidth + gap : swatchLeft - gap / 2 - nameWidth - gap - sideW;
- const Int cashEnd = onLeft ? leftCashEnd : rightCashEnd;
+ // each column's blocks top down in team order, a hairline between two blocks
+ Int columnTops[ 2 ] = { tableTop, tableTop };
+ for( Int block = 0; block < blocks; block++ )
+ {
+ const Bool onLeft = columns[ block ] == 0;
+ Int &top = columnTops[ columns[ block ] ];
+ const Int columnLeft = onLeft ? left + pad : rightStart;
+ if( top > tableTop )
+ {
+ TheDisplay->drawFillRect( columnLeft, top + ( blockGap - rowGap ) / 2, half, 1, BROADCAST_LINE );
+ top += blockGap;
+ }
+ for( Int index = blockFirst[ block ]; index < blockFirst[ block ] + blockSizes[ block ]; index++ )
+ {
+ const BroadcastRow &row = rows[ index ];
+ Int nameW = 0, nameH = 0, sideW = 0, sideH = 0, cashW = 0, cashH = 0, armyW = 0, armyH = 0;
+ row.name->getSize( &nameW, &nameH );
+ row.side->getSize( &sideW, &sideH );
+ row.cash->getSize( &cashW, &cashH );
+ row.army->getSize( &armyW, &armyH );
+ const Int swatchLeft = onLeft ? left + pad : rightStart + half - swatch;
+ const Int nameLeft = onLeft ? swatchLeft + swatch + gap / 2 : swatchLeft - gap / 2 - nameW;
+ const Int sideLeft = onLeft ? nameLeft + nameWidth + gap : swatchLeft - gap / 2 - nameWidth - gap - sideW;
+ const Int cashEnd = onLeft ? leftCashEnd : rightCashEnd;
+ const Int armyEnd = onLeft ? leftArmyEnd : rightArmyEnd;
+ drawBroadcastSwatch( swatchLeft, top, swatch, rowHeight, row.color );
+ row.name->draw( nameLeft, top + ( rowHeight - nameH ) / 2, ObserverCamera_readableColor( row.color ), BROADCAST_GROUND );
+ row.side->draw( sideLeft, top + ( rowHeight - sideH ) / 2, BROADCAST_MUTED, BROADCAST_GROUND );
+ row.cash->draw( cashEnd - cashW, top + ( rowHeight - cashH ) / 2, BROADCAST_INK, BROADCAST_GROUND );
+ row.army->draw( armyEnd - armyW, top + ( rowHeight - armyH ) / 2, BROADCAST_INK, BROADCAST_GROUND );
+ top += rowHeight + rowGap;
+ }
+ if( teamNames[ block ] == NULL )
+ continue;
+ // the team's name where its players' names are, its armies' total under theirs
+ Int teamW = 0, teamH = 0, totalW = 0, totalH = 0;
+ teamNames[ block ]->getSize( &teamW, &teamH );
+ teamTotals[ block ]->getSize( &totalW, &totalH );
+ const Int nameStart = onLeft ? left + pad + swatch + gap / 2 : rightStart + half - swatch - gap / 2 - teamW;
const Int armyEnd = onLeft ? leftArmyEnd : rightArmyEnd;
- TheDisplay->drawFillRect( swatchLeft, top, swatch, rowHeight, row.color );
- row.name->draw( nameLeft, top + ( rowHeight - nameH ) / 2, row.color, BROADCAST_GROUND );
- row.side->draw( sideLeft, top + ( rowHeight - sideH ) / 2, BROADCAST_MUTED, BROADCAST_GROUND );
- row.cash->draw( cashEnd - cashW, top + ( rowHeight - cashH ) / 2, BROADCAST_INK, BROADCAST_GROUND );
- row.army->draw( armyEnd - armyW, top + ( rowHeight - armyH ) / 2, BROADCAST_INK, BROADCAST_GROUND );
+ teamNames[ block ]->draw( nameStart, top + ( totalHeight - teamH ) / 2, BROADCAST_MUTED, BROADCAST_GROUND );
+ teamTotals[ block ]->draw( armyEnd - totalW, top + ( totalHeight - totalH ) / 2, BROADCAST_MUTED, BROADCAST_GROUND );
+ top += totalHeight + rowGap;
}
- // the tug of war: each side's armies from its own end, split among its players
+ // the army bar: every side's share from the left, the left column's first, then the right
+ // column's from the right edge in, so with two sides each pulls from its own end. Two sides meet
+ // at a gold mark in the middle; more are parted by the ground's colour
+ std::vector< Int > barPlayers, barArmies, barBlocks;
+ for( Int column = 0; column < 2; column++ )
+ {
+ for( Int taken = 0; taken < blocks; taken++ )
+ {
+ const Int block = column == 0 ? taken : blocks - 1 - taken;
+ if( columns[ block ] != column )
+ continue;
+ for( Int member = 0; member < blockSizes[ block ]; member++ )
+ {
+ const Int index = column == 0 ? blockFirst[ block ] + member : blockFirst[ block ] + blockSizes[ block ] - 1 - member;
+ barPlayers.push_back( index );
+ barArmies.push_back( players[ index ].army );
+ barBlocks.push_back( block );
+ }
+ }
+ }
const Int tugLeft = left + pad;
const Int tugWidth = width - 2 * pad;
- const Int total = armies[ 0 ] + armies[ 1 ];
TheDisplay->drawFillRect( tugLeft, tugTop, tugWidth, tug, BROADCAST_LINE );
- Int fromLeft = tugLeft;
- Int fromRight = tugLeft + tugWidth;
- for( size_t index = 0; index < rows.size() && total > 0; index++ )
+ const std::vector< Int > shares = ObserverCamera_barShares( barArmies, tugWidth );
+ Int barAt = tugLeft;
+ for( size_t piece = 0; piece < shares.size(); piece++ )
{
- const Int share = (Int)( (Int64)rows[ index ].stats->army * tugWidth / total );
- if( index < leftCount )
- {
- TheDisplay->drawFillRect( fromLeft, tugTop, share, tug, rows[ index ].color );
- fromLeft += share;
- continue;
- }
- fromRight -= share;
- TheDisplay->drawFillRect( fromRight, tugTop, share, tug, rows[ index ].color );
+ drawBroadcastSwatch( barAt, tugTop, shares[ piece ], tug, rows[ barPlayers[ piece ] ].color );
+ if( blocks > 2 && piece > 0 && barBlocks[ piece ] != barBlocks[ piece - 1 ] )
+ TheDisplay->drawFillRect( barAt, tugTop - rule, rule, tug + 2 * rule, BROADCAST_GROUND );
+ barAt += shares[ piece ];
}
- TheDisplay->drawFillRect( tugLeft + ( tugWidth - rule ) / 2, tugTop - rule, rule, tug + 2 * rule, BROADCAST_GOLD );
+ if( blocks == 2 )
+ TheDisplay->drawFillRect( tugLeft + ( tugWidth - rule ) / 2, tugTop - rule, rule, tug + 2 * rule, BROADCAST_GOLD );
IRegion2D bar;
bar.lo.x = left;
@@ -10837,18 +10953,28 @@ void InGameUI::drawDirectorBroadcast( void )
for( Int pane = 0; pane < panes && panes >= 2; pane++ )
{
const PlayerMaskType sides = TheObserverCamera.getPaneSides( pane );
+ // a team of two or more by its name once, a player alone by his own
BroadcastPlate plate;
- for( size_t index = 0; index < rows.size(); index++ )
+ for( Int block = 0; block < blocks; block++ )
{
- if( ( rows[ index ].stats->player->getPlayerMask() & sides ) == 0 )
- continue;
- if( !plate.pieces.empty() )
+ for( Int index = blockFirst[ block ]; index < blockFirst[ block ] + blockSizes[ block ]; index++ )
{
- plate.pieces.push_back( versus );
- plate.colors.push_back( BROADCAST_MUTED );
+ if( ( rows[ index ].stats->player->getPlayerMask() & sides ) == 0 )
+ continue;
+ if( !plate.pieces.empty() )
+ {
+ plate.pieces.push_back( versus );
+ plate.colors.push_back( BROADCAST_MUTED );
+ }
+ const Bool team = teamNames[ block ] != NULL;
+ Player *player = rows[ index ].stats->player;
+ plate.pieces.push_back( team ? broadcastText( "plateteam" + std::to_string( block ), broadcastTeamName( players, players[ index ].team ),
+ BROADCAST_WORDS, broadcastPoints( BROADCAST_NAME_POINTS ), TRUE ) : broadcastText( "name" + std::to_string( player->getPlayerIndex() ),
+ broadcastName( player ), BROADCAST_WORDS, broadcastPoints( BROADCAST_NAME_POINTS ), TRUE ) );
+ plate.colors.push_back( team ? BROADCAST_INK : ObserverCamera_readableColor( rows[ index ].color ) );
+ if( team )
+ break;
}
- plate.pieces.push_back( rows[ index ].name );
- plate.colors.push_back( rows[ index ].color );
}
if( plate.pieces.empty() )
continue;
@@ -10892,13 +11018,23 @@ void InGameUI::drawDirectorIntroPlate( void )
const std::string seat = std::to_string( player->getPlayerIndex() );
BroadcastPlate plate;
plate.pieces.push_back( broadcastText( "name" + seat, broadcastName( player ), BROADCAST_WORDS, broadcastPoints( BROADCAST_NAME_POINTS ), TRUE ) );
- plate.colors.push_back( clientPlayerColor( player ) );
+ plate.colors.push_back( ObserverCamera_readableColor( clientPlayerColor( player ) ) );
// an AI is called by its side already
if( player->getPlayerType() != PLAYER_COMPUTER )
{
plate.pieces.push_back( broadcastText( "side" + seat, broadcastSide( player ), BROADCAST_WORDS, broadcastPoints( BROADCAST_SIDE_POINTS ), FALSE ) );
plate.colors.push_back( BROADCAST_MUTED );
}
+ // and the team he is on, the score bar's name for it
+ const std::vector< SpectatorStats > players = gatherSpectatorStats( SPECTATOR_STATS[ 0 ], NULL );
+ for( size_t index = 0; index < players.size(); index++ )
+ {
+ if( players[ index ].player != player || broadcastTeamSize( players, players[ index ].team ) < 2 )
+ continue;
+ plate.pieces.push_back( broadcastText( "introteam" + seat, broadcastTeamName( players, players[ index ].team ), BROADCAST_WORDS,
+ broadcastPoints( BROADCAST_SIDE_POINTS ), TRUE ) );
+ plate.colors.push_back( BROADCAST_GOLD );
+ }
Int plateWidth = 0, plateHeight = 0;
broadcastPlateSize( plate, &plateWidth, &plateHeight );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index 8fd6e94af..22dcc274c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -40,6 +40,7 @@
#include "GameLogic/PartitionManager.h"
#include "GameLogic/TerrainLogic.h"
+#include <algorithm>
#include <math.h>
ObserverCamera TheObserverCamera;
@@ -597,6 +598,130 @@ Real ObserverCamera_paneLabelTop( const Coord2D &centre, Real radius, Real width
return centre.y - max( above, height * 0.5f );
}
+//-------------------------------------------------------------------------------------------------
+std::vector< Int > ObserverCamera_blockColumns( const std::vector< Int > &sizes )
+{
+ std::vector< Int > columns( sizes.size(), 0 );
+ if( sizes.size() == 2 )
+ {
+ columns[ 1 ] = 1;
+ return columns;
+ }
+ // the biggest first, each to the shorter column, which evens the two out best
+ std::vector< Int > biggestFirst;
+ for( size_t block = 0; block < sizes.size(); block++ )
+ biggestFirst.push_back( (Int)block );
+ std::stable_sort( biggestFirst.begin(), biggestFirst.end(), [ &sizes ]( Int a, Int b ) { return sizes[ a ] > sizes[ b ]; } );
+ Int rows[ 2 ] = { 0, 0 };
+ for( size_t taken = 0; taken < biggestFirst.size(); taken++ )
+ {
+ const Int block = biggestFirst[ taken ];
+ const Int column = rows[ 1 ] < rows[ 0 ] ? 1 : 0;
+ rows[ column ] += sizes[ block ] + ( sizes[ block ] >= 2 ? 1 : 0 );
+ columns[ block ] = column;
+ }
+ return columns;
+}
+
+//-------------------------------------------------------------------------------------------------
+std::vector< Int > ObserverCamera_barShares( const std::vector< Int > &values, Int width )
+{
+ std::vector< Int > pixels( values.size(), 0 );
+ Int64 total = 0;
+ for( size_t index = 0; index < values.size(); index++ )
+ total += values[ index ];
+ if( total <= 0 )
+ return pixels;
+ std::vector< Int64 > remainders( values.size(), 0 );
+ Int given = 0;
+ for( size_t index = 0; index < values.size(); index++ )
+ {
+ const Int64 scaled = (Int64)values[ index ] * width;
+ pixels[ index ] = (Int)( scaled / total );
+ remainders[ index ] = scaled % total;
+ given += pixels[ index ];
+ }
+ for( ; given < width; given++ )
+ {
+ size_t largest = 0;
+ for( size_t index = 1; index < values.size(); index++ )
+ if( remainders[ index ] > remainders[ largest ] )
+ largest = index;
+ pixels[ largest ]++;
+ remainders[ largest ] = -1;
+ }
+ return pixels;
+}
+
+//-------------------------------------------------------------------------------------------------
+std::vector< Int > ObserverCamera_teamOrder( const std::vector< Int > &teams )
+{
+ std::vector< Int > order;
+ std::vector< Bool > taken( teams.size(), FALSE );
+ for( size_t first = 0; first < teams.size(); first++ )
+ {
+ if( taken[ first ] )
+ continue;
+ for( size_t index = first; index < teams.size(); index++ )
+ {
+ if( teams[ index ] != teams[ first ] )
+ continue;
+ order.push_back( (Int)index );
+ taken[ index ] = TRUE;
+ }
+ }
+ return order;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The relative luminance of a colour, the way the contrast ratio is defined. */
+//-------------------------------------------------------------------------------------------------
+static Real luminance( Real red, Real green, Real blue )
+{
+ const Real channels[ 3 ] = { red, green, blue };
+ Real linear[ 3 ];
+ for( Int channel = 0; channel < 3; channel++ )
+ {
+ const Real value = channels[ channel ] / 255.0f;
+ linear[ channel ] = value <= 0.03928f ? value / 12.92f : powf( ( value + 0.055f ) / 1.055f, 2.4f );
+ }
+ return 0.2126f * linear[ 0 ] + 0.7152f * linear[ 1 ] + 0.0722f * linear[ 2 ];
+}
+
+/// the broadcast's ground, zerohour.gg's --bg, and the contrast its text needs on it
+static const UnsignedByte BROADCAST_GROUND_RGB[ 3 ] = { 0x0c, 0x12, 0x20 };
+static const Real READABLE_CONTRAST = 4.5f;
+static const Real READABLE_STEP = 0.05f;
+/// zerohour.gg's --gold, the pane lines' colour, and how far from it a player's colour has to be to
+/// stand apart from them, summed over the three channels
+static const Int BRAND_GOLD_RGB[ 3 ] = { 0xf2, 0xc2, 0x30 };
+static const Int BRAND_GOLD_NEAR = 100;
+
+//-------------------------------------------------------------------------------------------------
+Color ObserverCamera_readableColor( Color color )
+{
+ UnsignedByte red, green, blue, alpha;
+ GameGetColorComponents( color, &red, &green, &blue, &alpha );
+ const Real ground = luminance( BROADCAST_GROUND_RGB[ 0 ], BROADCAST_GROUND_RGB[ 1 ], BROADCAST_GROUND_RGB[ 2 ] );
+ for( Real white = 0.0f; white <= 1.0f; white += READABLE_STEP )
+ {
+ const Real r = red + ( 255.0f - red ) * white;
+ const Real g = green + ( 255.0f - green ) * white;
+ const Real b = blue + ( 255.0f - blue ) * white;
+ if( ( luminance( r, g, b ) + 0.05f ) / ( ground + 0.05f ) >= READABLE_CONTRAST )
+ return GameMakeColor( (UnsignedByte)REAL_TO_INT( r ), (UnsignedByte)REAL_TO_INT( g ), (UnsignedByte)REAL_TO_INT( b ), alpha );
+ }
+ return GameMakeColor( 255, 255, 255, alpha );
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool ObserverCamera_nearBrandGold( Color color )
+{
+ UnsignedByte red, green, blue, alpha;
+ GameGetColorComponents( color, &red, &green, &blue, &alpha );
+ return abs( red - BRAND_GOLD_RGB[ 0 ] ) + abs( green - BRAND_GOLD_RGB[ 1 ] ) + abs( blue - BRAND_GOLD_RGB[ 2 ] ) <= BRAND_GOLD_NEAR;
+}
+
//-------------------------------------------------------------------------------------------------
Real ObserverCamera_extentAround( const std::vector< DirectorHeat > &things, const Coord2D &around, Real reach, Real least )
{
@@ -1630,6 +1755,27 @@ void ObserverCamera::advancePanes( UnsignedInt frame )
if( player->isPlayableSide() && !player->isPlayerObserver() && player->isPlayerActive() )
m_panePlayers[ players++ ] = player;
}
+ // teammates side by side round the meeting point: a player's team is the first one
+ // before him allied with him both ways
+ std::vector< Int > teams;
+ for( Int pane = 0; pane < players; pane++ )
+ {
+ Int team = pane;
+ for( Int earlier = 0; earlier < pane && team == pane; earlier++ )
+ {
+ const Player *one = m_panePlayers[ pane ];
+ const Player *other = m_panePlayers[ earlier ];
+ if( one->getRelationship( other->getDefaultTeam() ) == ALLIES && other->getRelationship( one->getDefaultTeam() ) == ALLIES )
+ team = teams[ earlier ];
+ }
+ teams.push_back( team );
+ }
+ const std::vector< Int > order = ObserverCamera_teamOrder( teams );
+ const Player *found[ OBSERVER_MOST_PANES ];
+ for( Int pane = 0; pane < players; pane++ )
+ found[ pane ] = m_panePlayers[ order[ pane ] ];
+ for( Int pane = 0; pane < players; pane++ )
+ m_panePlayers[ pane ] = found[ pane ];
m_paneCount = ObserverCamera_paneLayout( players, m_paneRays );
if( m_paneCount >= 2 )
{
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index 8c81ecfa6..15497114d 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -859,3 +859,82 @@ TEST(pane_animations_ease_over_logic_frames)
last = now;
}
}
+
+TEST(the_score_bar_keeps_each_team_together_and_balances_its_two_columns)
+{
+ // two sides face each other whatever their sizes: 4v1
+ std::vector< Int > sizes;
+ sizes.push_back( 4 );
+ sizes.push_back( 1 );
+ std::vector< Int > columns = ObserverCamera_blockColumns( sizes );
+ CHECK_EQ( columns[ 0 ], 0 );
+ CHECK_EQ( columns[ 1 ], 1 );
+ // eight alone alternate, four a column
+ sizes.assign( 8, 1 );
+ columns = ObserverCamera_blockColumns( sizes );
+ Int left = 0;
+ for( size_t block = 0; block < columns.size(); block++ )
+ left += columns[ block ] == 0 ? 1 : 0;
+ CHECK_EQ( left, 4 );
+ // four alone and a pair: the pair's two rows and its total land where there is room
+ sizes.assign( 4, 1 );
+ sizes.push_back( 2 );
+ columns = ObserverCamera_blockColumns( sizes );
+ Int rows[ 2 ] = { 0, 0 };
+ for( size_t block = 0; block < columns.size(); block++ )
+ rows[ columns[ block ] ] += sizes[ block ] + ( sizes[ block ] >= 2 ? 1 : 0 );
+ CHECK_EQ( rows[ 0 ], 4 );
+ CHECK_EQ( rows[ 1 ], 3 );
+
+ // teammates are taken together in the order their teams first appear
+ std::vector< Int > teams;
+ teams.push_back( 0 );
+ teams.push_back( 1 );
+ teams.push_back( 0 );
+ teams.push_back( 2 );
+ teams.push_back( 1 );
+ const std::vector< Int > order = ObserverCamera_teamOrder( teams );
+ const Int expected[] = { 0, 2, 1, 4, 3 };
+ CHECK_EQ( (Int)order.size(), 5 );
+ for( Int index = 0; index < 5; index++ )
+ CHECK_EQ( order[ index ], expected[ index ] );
+}
+
+TEST(the_army_bar_cuts_its_whole_width_among_the_sides)
+{
+ std::vector< Int > armies;
+ armies.push_back( 1 );
+ armies.push_back( 1 );
+ armies.push_back( 1 );
+ const std::vector< Int > pixels = ObserverCamera_barShares( armies, 100 );
+ CHECK_EQ( pixels[ 0 ] + pixels[ 1 ] + pixels[ 2 ], 100 );
+ CHECK( pixels[ 0 ] >= 33 && pixels[ 0 ] <= 34 );
+ armies[ 0 ] = 3000;
+ armies[ 1 ] = 1000;
+ armies[ 2 ] = 0;
+ const std::vector< Int > uneven = ObserverCamera_barShares( armies, 100 );
+ CHECK_EQ( uneven[ 0 ], 75 );
+ CHECK_EQ( uneven[ 1 ], 25 );
+ CHECK_EQ( uneven[ 2 ], 0 );
+ armies.assign( 3, 0 );
+ const std::vector< Int > none = ObserverCamera_barShares( armies, 100 );
+ CHECK_EQ( none[ 0 ] + none[ 1 ] + none[ 2 ], 0 );
+}
+
+TEST(a_dark_player_colour_is_lifted_to_read_and_a_gold_one_is_told_from_the_lines)
+{
+ // purple, #9600c8, is lifted; white stays white
+ const Color purple = GameMakeColor( 0x96, 0x00, 0xc8, 255 );
+ const Color lifted = ObserverCamera_readableColor( purple );
+ CHECK_NE( lifted, purple );
+ UnsignedByte red, green, blue, alpha;
+ GameGetColorComponents( lifted, &red, &green, &blue, &alpha );
+ CHECK( red > 0x96 && green > 0x00 && blue > 0xc8 );
+ const Color white = GameMakeColor( 255, 255, 255, 255 );
+ CHECK_NE( lifted, white );
+ CHECK_EQ( ObserverCamera_readableColor( white ), white );
+ // gold, #dde20d, is near the lines' gold; blue and red are not
+ CHECK( ObserverCamera_nearBrandGold( GameMakeColor( 0xdd, 0xe2, 0x0d, 255 ) ) );
+ CHECK( !ObserverCamera_nearBrandGold( GameMakeColor( 0x00, 0x00, 0xff, 255 ) ) );
+ CHECK( !ObserverCamera_nearBrandGold( GameMakeColor( 0xff, 0x00, 0x00, 255 ) ) );
+}