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(gameengine): director power flags and defeated cards with banners

Olcay Seygan50e741242ed0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7852305a8..09ee105be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -750,6 +750,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- 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. In its corner the radar sits flush against the bottom and left of the picture with a thin gold edge on its top and right only, where it used to stand in a heavy frame a few pixels in from the corner. Under each line and round the radar lies a soft band of the Reforged blue. The pictures slide into place first, and only then does the gold draw out from where the lines meet, over most of a second, with the band fading in behind it and the radar's frame tracing its gold round the map once the radar has arrived; going out, the gold pulls back in before the pictures leave. The opening plays it the same way from the first player's full view. While the screen stays cut a bright white-gold light runs out along every line every five seconds, the opening included. At first all of this ran inside the half second the pictures take to slide, and on film the lines were already whole by the third 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 single view rises and settles over a second and a half when it reaches a fight, where it used to glide in for seconds and then step back up in a third of one, and the hand-over between the cut screen and the single view is one camera: the opening's last picture used to jump sideways about fifty paces the moment it became the Director's. When the Director moves onto the second half's fight, that half is the one that stays: it widens to fill the screen and carries straight on as the single view, where the other half used to fill the screen and the camera then cut across the map. 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. Inside a split no picture ever jumps. A split ends the usual way after eighteen seconds, or the moment either half's fight is over or moves on to somewhere else, and only then does the camera go where the next fight is; in an eight-player film one split stayed up for three minutes while the main half was thrown across the map to six new fights, once by 2,900 paces as it was still sweeping in. 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, the match clock in a tab over it and every side in one row, "Team A vs Team B vs" a player alone: a card a player, his colour along its top, his name in that colour, his general (a computer player goes by his general with his difficulty under it, where every one of them used to read "Hard AI"), then on one line his cash and what his army cost, the army's figure labelled so the two never get mixed up; the bar is a fifth shorter than its first cut, 99 rows of a 720p picture for a 1v1 where it took 126. A team's cards sit together under its name and its army's total. Under the whole row is one bar the armies pull on, each player's share in his colour and a gold mark at the middle when two sides play, so whoever is past it is ahead. From five players on the cards stand in two rows, a team never broken across them, and each card keeps to one line, the name and the army's value, so the type stays at its full size: eight players in one row had shrunk it to letters six pixels tall that nobody could read in motion. Eight alone take 103 rows of a 720p picture, a 4v4 with its two team names 139. 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 two pixels wide even at 720p 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. The name sits over his general and team in smaller type, and the plate stays wholly inside its picture: in an eight-player opening the lines used to cut it down to "ank General Team A", and in a 4v1 the top one hid under the score bar. 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.
+- The film shows who fired what. When a player uses a general's power, a small flag drops out from under his card in the score bar carrying the power's icon, hangs there four seconds and pulls back up; a superweapon's flag is edged in gold. A power gets its flag only once it hits somebody, the same rule the camera follows, so an Air Force general's spy satellite never hangs one, and a player who fires two in quick succession has them wait their turn under his card. A player knocked out no longer blinks out of the bar. His card flashes red with a line drawn through his name, and a second later it closes while the cards beside it slide into the room it leaves, where the whole row used to jump on the frame he lost. At the same moment a banner opens across the lower part of the picture with his name and general under a red Defeated. The match no longer cuts off on the frame the last card falls, either: the film runs three and a half seconds past the decision, so the last defeat plays out and the winner's banner comes up in gold beneath it.
- 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/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 68f3c80bd..23f5b9728 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -18,6 +18,8 @@ Data/Cinema/aurorafog.txt
Data/Cinema/blastcheck.txt
Data/Cinema/demo.txt
Data/Cinema/explreel.txt
+Data/Cinema/filterblur.txt
+Data/Cinema/filterbw.txt
Data/Cinema/headlights.txt
Data/Cinema/hero_loop.txt
Data/Cinema/hero_loop_01.txt
@@ -39,6 +41,9 @@ Data/Cinema/lsv_spam2.txt
Data/Cinema/missileapex_film.txt
Data/Cinema/mobwatch.txt
Data/Cinema/nohud.txt
+Data/Cinema/nukedome.txt
+Data/Cinema/nukefade.txt
+Data/Cinema/nukewarp.txt
Data/Cinema/rf_ai.txt
Data/Cinema/rf_ai_wave.txt
Data/Cinema/rf_beach.txt
@@ -71,6 +76,10 @@ Data/Cinema/s240_snow.txt
Data/Cinema/s240_tank.txt
Data/Cinema/s240_town.txt
Data/Cinema/scudlaunch_film.txt
+Data/Cinema/swpair_nuke.txt
+Data/Cinema/swpair_scud.txt
+Data/Cinema/thumb_chaos_a.txt
+Data/Cinema/thumb_chaos_b.txt
Data/Cinema/tr_arrival.txt
Data/Cinema/tr_chaos.txt
Data/Cinema/tr_clash.txt
@@ -105,9 +114,11 @@ Data/Scenarios/airbelow.txt
Data/Scenarios/airbelowfar.txt
Data/Scenarios/alphaaurora.txt
Data/Scenarios/aurorafog.txt
+Data/Scenarios/avengerlasers.txt
Data/Scenarios/blastcheck.txt
Data/Scenarios/bridgecross.txt
Data/Scenarios/bridgelong.txt
+Data/Scenarios/broadcastend.txt
Data/Scenarios/chokeprobe.txt
Data/Scenarios/comanchepods.txt
Data/Scenarios/comturret.txt
@@ -118,6 +129,9 @@ Data/Scenarios/dragonflame.txt
Data/Scenarios/driveby.txt
Data/Scenarios/empfriendly.txt
Data/Scenarios/explreel.txt
+Data/Scenarios/glowbase.txt
+Data/Scenarios/glowfight.txt
+Data/Scenarios/glowmicrowave.txt
Data/Scenarios/guardradius.txt
Data/Scenarios/headlights.txt
Data/Scenarios/helislide.txt
@@ -162,6 +176,7 @@ Data/Scenarios/mobopen.txt
Data/Scenarios/mobstress.txt
Data/Scenarios/mobwin.txt
Data/Scenarios/netstance.txt
+Data/Scenarios/nukefade.txt
Data/Scenarios/obeyorders.txt
Data/Scenarios/overlordbridge.txt
Data/Scenarios/overlordlong.txt
@@ -201,6 +216,7 @@ Data/Scenarios/stashbeside.txt
Data/Scenarios/statues.txt
Data/Scenarios/sweep.txt
Data/Scenarios/swhole.txt
+Data/Scenarios/swpair.txt
Data/Scenarios/techrespawn.txt
Data/Scenarios/towncross.txt
Data/Scenarios/toxinslope.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/broadcastend.txt b/GeneralsMD/Code/Data/Scenarios/broadcastend.txt
new file mode 100644
index 000000000..48d8f6d9d
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/broadcastend.txt
@@ -0,0 +1,29 @@
+# -directorrecord's broadcast moments in about a minute of film: power flags under two players'
+# cards, one queued behind another, a defeat that slides the score bar, and the defeat that decides
+# the match with the winner's banner after it. Three easy AIs on Twilight Flame, every seat an enemy
+# of every other. Not -takeover: that puts the local player in a seat, and the director never runs.
+#
+# generals.exe -win -xres 1280 -yres 720 -quickstart -noshellmap -multiInstance
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 3 -aidiff easy
+# -side 0 FactionAmerica -side 1 FactionChina -side 2 FactionGLA -seed 7
+# -scenario broadcastend -directorrecord broadcastend -maxframes 4000 -logPrefix bcast_
+#
+# America's Crusaders take the GLA base, America's A-10s and particle cannon and China's carpet bomb
+# land on it, and America's Paladins then take the Chinese base.
+
+# --- America's particle cannon, powered, at home ------------------------------------------
+10 spawn 0 AmericaParticleCannonUplink 1 start0:0:-200
+10 spawn 0 AmericaPowerPlant 3 start0:-260:40 90
+
+# --- the GLA base goes first ----------------------------------------------------------------
+60 spawn 0 AmericaTankCrusader 20 start2:-350:0 36
+90 attack 0 AmericaTankCrusader 2 *
+
+# a general's power for each of two players, and America's particle cannon queued behind its A-10s
+300 power 0 AmericaCommandCenter start2:0:0 SuperweaponA10ThunderboltMissileStrike
+340 power 1 ChinaCommandCenter start2:80:40 Early_SuperweaponChinaCarpetBomb
+360 power 0 AmericaParticleCannonUplink start2:0:0
+
+# --- then the Chinese base, which decides it ----------------------------------------------
+1000 spawn 0 AmericaTankPaladin 16 start1:-350:0 40
+1030 attack 0 AmericaTankPaladin 1 *
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index bf38cf5ae..0476cf339 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -73,6 +73,8 @@ class Image;
class GameFont;
class GameSlot;
class Player;
+struct SpectatorStats;
+struct BroadcastLayout;
enum LegalBuildCode : Int;
enum KindOfType : Int;
enum ShadowType : Int;
@@ -1766,6 +1768,9 @@ protected:
/// thing written, so a text is laid out again only when it changes
DisplayString *broadcastText( const std::string &key, const UnicodeString &text, const char *font, Int points, Bool bold );
std::map< std::string, DisplayString * > m_broadcastTexts;
+ /// the score bar laid out for players, under the clock's tab, team letters taken from named
+ void layOutBroadcast( const std::vector< SpectatorStats > &players, const std::vector< SpectatorStats > &named,
+ const std::string &tag, Int clockBox, Int clockBoxHeight, BroadcastLayout &layout );
DisplayString * m_peaceTimeLabelDisplayString; ///< the word written over that clock
DisplayString * m_peaceCountdownDisplayString; ///< the big digit of its last ten seconds
Int m_lastMoneyDisplayed; ///< so the money gadget is only written when the amount changes
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
index a751caf51..222bf1847 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -71,6 +71,8 @@ struct DirectorHeat
};
class Player;
+class SpecialPowerTemplate;
+class ThingTemplate;
/// a special power used lately: who used it, where it was fired from, where it lands, and until which
/// logic frame it is worth watching. A superweapon is shown leaving its silo before its target
@@ -85,8 +87,43 @@ struct DirectorEvent
Real weight;
Bool superweapon;
Bool landed; ///< it hurt somebody where it was aimed: a superweapon from the start, any other once a hit is seen there
+ const SpecialPowerTemplate *power; ///< the power used; NULL for a warhead no power sent
+ const ThingTemplate *sourceThing; ///< what it was fired from
};
+/// -directorrecord's broadcast shows some things one at a time from a queue: a special power's flag
+/// under its player's card in the score bar, and a defeated player's banner. start is the logic frame
+/// it began to come in, 0 while it waits behind another; leaving the frame it began to go, 0 while it
+/// holds. A defeat's banner has no power
+struct DirectorShowing
+{
+ Int player;
+ const SpecialPowerTemplate *power;
+ const ThingTemplate *sourceThing;
+ Bool superweapon;
+ UnsignedInt start;
+ UnsignedInt leaving;
+};
+
+/// one logic frame of such a queue: the first in it comes in over moveFrames, holds holdAlone frames
+/// alone, half that with one waiting behind it and a third with more, goes over moveFrames, and the
+/// next starts the frame it is gone. With keepLast the last one holds for good. TRUE when one started
+/// this frame
+Bool ObserverCamera_advanceShowing( std::vector< DirectorShowing > &queue, UnsignedInt frame, UnsignedInt moveFrames, UnsignedInt holdAlone,
+ Bool keepLast );
+/// how far in a queued thing that comes and goes over moveFrames is on frame, 0 to 1, eased in and out
+Real ObserverCamera_showingShown( const DirectorShowing &showing, UnsignedInt frame, UnsignedInt moveFrames );
+/// a defeated player's card on frame: how bright its red flash is, how far the line through it has
+/// drawn and how far it has collapsed, each 0 to 1. defeated is the frame he lost on, collapseFrom the
+/// frame his card starts to go
+void ObserverCamera_cardExit( UnsignedInt frame, UnsignedInt defeated, UnsignedInt collapseFrom, Real *flash, Real *struck, Real *collapse );
+/// the frame the card of a player who lost on defeated starts to collapse: once it has been seen struck,
+/// and not before the card that went before it, from lastCollapse, has gone, so the others slide for
+/// one card at a time
+UnsignedInt ObserverCamera_collapseFrom( UnsignedInt defeated, UnsignedInt lastCollapse );
+/// progress along from to to, eased in and out, 0 before from and 1 after to
+Real ObserverCamera_easeBetween( Real progress, Real from, Real to );
+
/// -directorrecord's scouting pass plays the match headless first and writes down what is worth
/// filming, so the filming pass can be there before it starts. A fight runs from the scan it was
/// first hot on, start, to the last, starting at place and last seen at target; peak is its hottest
@@ -328,8 +365,10 @@ public:
/// on is following
Int getShroudPlayerIndex( void ) const;
- /// a special power was used: logic tells the director, and never asks it anything back
- void noteSpecialPower( const Player *owner, const Coord3D *from, const Coord3D *at, Bool superweapon );
+ /// a special power was used: logic tells the director, and never asks it anything back. power is
+ /// the power and sourceThing what fired it, both NULL for a warhead no power sent
+ void noteSpecialPower( const Player *owner, const Coord3D *from, const Coord3D *at, Bool superweapon,
+ const SpecialPowerTemplate *power, const ThingTemplate *sourceThing );
/// a superweapon is hitting the ground here this frame, a beam or a warhead. Keeps the event it
/// belongs to going a few seconds more, and with follow the event's target moves with it
void noteSuperweaponHit( const Player *owner, const Coord3D *at, Bool follow );
@@ -381,6 +420,19 @@ public:
void beginPanePass( Int pane );
void endPanePass( void );
+ /// -directorrecord's broadcast: the flag of a special power hanging under a player's card now, NULL
+ /// for none, and how far it has dropped, 0 to 1
+ const DirectorShowing *getPowerFlag( Int playerIndex, Real *drop ) const;
+ /// the defeated player's banner up now, NULL for none, and how far in it is
+ const DirectorShowing *getDefeatBanner( Real *shown ) const;
+ /// every player seen playing in this match, the ones who have lost included
+ PlayerMaskType getPlayedMask( void ) const { return m_playedMask; }
+ /// the logic frame a player lost on, 0 while he has not, and the frame his card starts to collapse
+ UnsignedInt getDefeatFrame( Int playerIndex ) const { return m_defeatFrame[ playerIndex ]; }
+ UnsignedInt getCollapseFrame( Int playerIndex ) const { return m_collapseFrame[ playerIndex ]; }
+ /// how far in the winner's banner is, 0 until a while after the match is decided
+ Real getWinnerShown( void ) const;
+
/// -directorrecord's scouting pass, once a pass of a headless run: count the fights on every scan
/// and a checkpoint of the logic's CRC now and then
void scout( void );
@@ -422,6 +474,8 @@ private:
void dropOldEvents( UnsignedInt frame );
void loadTimeline( void );
void checkTimeline( UnsignedInt frame );
+ void noteFlag( const DirectorEvent &event );
+ void updateBroadcastMoments( UnsignedInt frame );
/// a sight, a fight going on, a special power, or a fight the timeline says is about to begin
enum PlaceKind { PLACE_SIGHT, PLACE_FIGHT, PLACE_EVENT, PLACE_UPCOMING };
@@ -481,6 +535,14 @@ private:
std::vector< DirectorEvent > m_events; ///< the special powers still worth watching, oldest first
UnsignedInt m_nextEventId;
+ std::vector< DirectorShowing > m_flags[ MAX_PLAYER_COUNT ]; ///< each player's special powers waiting to hang under his card, the first up now
+ std::vector< DirectorShowing > m_defeatBanners; ///< the defeated players' banners, the first up now
+ PlayerMaskType m_playedMask; ///< every player seen playing in this match
+ UnsignedInt m_defeatFrame[ MAX_PLAYER_COUNT ]; ///< the frame each player lost on, 0 while he has not
+ UnsignedInt m_collapseFrame[ MAX_PLAYER_COUNT ]; ///< the frame his card starts to collapse
+ UnsignedInt m_lastCollapse; ///< the last card's, which the next one waits out
+ UnsignedInt m_winnerFrame; ///< the frame the winner's banner starts to come in, 0 before the match is decided
+
std::vector< DirectorHeat > m_fights; ///< the last scan's hits one player dealt another he is at war with; the split counts only these
std::vector< PlayerMaskType > m_fightSides; ///< and the two players each of them was between
std::vector< IRegion2D > m_broadcast; ///< the rectangles the broadcast drew over pane 0 this frame
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index dd90a5202..3dd61ccbf 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -2427,6 +2427,25 @@ static void updateHeadlessRun( void )
if (why == NULL)
return;
+ /* -directorrecord films on past the decision, so the last player's defeat and the winner's banner
+ are in the movie: it used to stop on the frame the last card fell. Not past the game's own end,
+ though: the multiplayer scripts' end timer clears the match FRAMES_TO_SHOW_WIN_LOSE_MESSAGE (120)
+ frames after it is decided and drops to the shell, which would leave without these lines. The
+ decision's own CRC is logged on its frame, the one the scouting pass closed on. */
+ static UnsignedInt filmDecidedOn = 0;
+ const UnsignedInt FILM_PAST_DECISION_FRAMES = 105;
+ if (TheGlobalData->m_directorRecord && strcmp( why, "decided" ) == 0)
+ {
+ if (filmDecidedOn == 0)
+ {
+ filmDecidedOn = frame;
+ DEBUG_LOG(("-directorrecord: decided on frame %d, CRC 0x%08X, filming %u frames more\n", frame,
+ TheGameLogic->getCRC( CRC_RECALC ), FILM_PAST_DECISION_FRAMES));
+ }
+ if (frame < filmDecidedOn + FILM_PAST_DECISION_FRAMES)
+ return;
+ }
+
const UnsignedInt wallMs = Clock_Milliseconds() - runStartTime;
const Real logicFps = wallMs ? (Real)(frame - runStartFrame) * 1000.0f / (Real)wallMs : 0.0f;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index b18a3b751..b6cbe9d19 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -2113,10 +2113,11 @@ static void addObjectStats( Object *obj, void *userData )
}
//-------------------------------------------------------------------------------------------------
-/** Everyone still in the match but leftOut 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. */
+/** Everyone still in the match but leftOut with his numbers, ranked by `stat`, and the players in kept
+ * who have lost. Allies both ways share a team number, counted in the order the teams first appear
+ * in the player list. */
//-------------------------------------------------------------------------------------------------
-static std::vector< SpectatorStats > gatherSpectatorStats( const SpectatorStat &stat, const Player *leftOut )
+static std::vector< SpectatorStats > gatherSpectatorStats( const SpectatorStat &stat, const Player *leftOut, PlayerMaskType kept = 0 )
{
std::vector< SpectatorStats > players;
const UnsignedInt frame = TheGameLogic->getFrame();
@@ -2124,7 +2125,9 @@ static std::vector< SpectatorStats > gatherSpectatorStats( const SpectatorStat &
for( Int index = 0; index < ThePlayerList->getPlayerCount(); index++ )
{
Player *player = ThePlayerList->getNthPlayer( index );
- if( player == NULL || player == leftOut || !player->isPlayerActive() || !player->isPlayableSide() )
+ if( player == NULL || player == leftOut || !player->isPlayableSide() )
+ continue;
+ if( !player->isPlayerActive() && ( player->getPlayerMask() & kept ) == 0 )
continue;
ScoreKeeper *score = player->getScoreKeeper();
@@ -10641,16 +10644,38 @@ struct BroadcastPlate
std::vector< Color > colors;
};
-static void broadcastPlateSize( const BroadcastPlate &plate, Int *width, Int *height )
+/** The plate's text alone, its pieces half a gap apart: their width and the tallest's height. */
+static void broadcastPiecesSize( const BroadcastPlate &plate, Int *width, Int *height )
{
- Int textWidth = 0, textHeight = 0;
+ *width = *height = 0;
for( size_t piece = 0; piece < plate.pieces.size(); piece++ )
{
Int pieceWidth = 0, pieceHeight = 0;
plate.pieces[ piece ]->getSize( &pieceWidth, &pieceHeight );
- textWidth += pieceWidth + ( piece > 0 ? broadcastPixels( BROADCAST_GAP ) / 2 : 0 );
- textHeight = max( textHeight, pieceHeight );
+ *width += pieceWidth + ( piece > 0 ? broadcastPixels( BROADCAST_GAP ) / 2 : 0 );
+ *height = max( *height, pieceHeight );
}
+}
+
+/** The plate's text from left, each piece centred down a line height rows high from top, faded to
+ * shown, its shadow in ground. */
+static void drawBroadcastPieces( const BroadcastPlate &plate, Int left, Int top, Int height, Real shown, Color ground )
+{
+ Int x = left;
+ for( size_t piece = 0; piece < plate.pieces.size(); piece++ )
+ {
+ Int pieceWidth = 0, pieceHeight = 0;
+ plate.pieces[ piece ]->getSize( &pieceWidth, &pieceHeight );
+ plate.pieces[ piece ]->draw( x, top + ( height - pieceHeight ) / 2, broadcastFade( plate.colors[ piece ], shown ),
+ broadcastFade( ground, shown ) );
+ x += pieceWidth + broadcastPixels( BROADCAST_GAP ) / 2;
+ }
+}
+
+static void broadcastPlateSize( const BroadcastPlate &plate, Int *width, Int *height )
+{
+ Int textWidth = 0, textHeight = 0;
+ broadcastPiecesSize( plate, &textWidth, &textHeight );
*width = textWidth + 2 * broadcastPixels( BROADCAST_PAD );
*height = textHeight + broadcastPixels( BROADCAST_PAD ) + broadcastPixels( BROADCAST_RULE );
}
@@ -10659,22 +10684,72 @@ static void broadcastPlateSize( const BroadcastPlate &plate, Int *width, Int *he
static void drawBroadcastPlate( const BroadcastPlate &plate, Int left, Int top, Real shown )
{
const Int pad = broadcastPixels( BROADCAST_PAD );
- const Int gap = broadcastPixels( BROADCAST_GAP );
const Int rule = broadcastPixels( BROADCAST_RULE );
Int width = 0, height = 0;
broadcastPlateSize( plate, &width, &height );
- const Int textHeight = height - pad - rule;
TheDisplay->drawFillRect( left, top, width, height, broadcastFade( BROADCAST_GROUND, shown ) );
TheDisplay->drawFillRect( left, top + height - rule, width, rule, broadcastFade( BROADCAST_GOLD, shown ) );
- Int x = left + pad;
- for( size_t piece = 0; piece < plate.pieces.size(); piece++ )
+ drawBroadcastPieces( plate, left + pad, top + pad / 2, height - pad - rule, shown, BROADCAST_GROUND );
+}
+
+/// the broadcast's red, for a defeat and nothing else: a struck card and the defeat banner's tab
+static const Color BROADCAST_DEFEAT = GameMakeColor( 0xb8, 0x26, 0x1f, 255 );
+/// the defeat and winner banners: the name's points, the tab's word's, and where the defeat banner's
+/// foot sits, a share of the picture's height down; the winner's hangs under it
+static const Int BROADCAST_BANNER_POINTS = 16;
+static const Int BROADCAST_BANNER_WORD_POINTS = 12;
+static const Real BROADCAST_BANNER_FOOT = 0.7f;
+
+/** A banner's height with title over under, its rule included. */
+static Int broadcastBannerHeight( const BroadcastPlate &title, const BroadcastPlate &under )
+{
+ Int width = 0, titleHeight = 0, underHeight = 0;
+ broadcastPiecesSize( title, &width, &titleHeight );
+ broadcastPiecesSize( under, &width, &underHeight );
+ return titleHeight + underHeight + broadcastPixels( BROADCAST_PAD ) + broadcastPixels( BROADCAST_RULE );
+}
+
+/** A banner across the lower picture for a defeat or the winner, centred, its foot on the row foot: a
+ * tab of colour holding word, beside it title over the smaller under, on the ground with a rule of the
+ * tab's colour along its foot. It opens as the rule grows out from its middle, the panel rises off the
+ * rule and the words come last; shown runs it from 0 to 1, and going back down closes it the same way.
+ * The rectangle it takes on the picture. */
+static IRegion2D drawBroadcastBanner( DisplayString *word, Color tab, Color wordColor, const BroadcastPlate &title,
+ const BroadcastPlate &under, Int foot, Real shown )
+{
+ const Int pad = broadcastPixels( BROADCAST_PAD );
+ const Int rule = broadcastPixels( BROADCAST_RULE );
+ Int wordWidth = 0, wordHeight = 0, titleWidth = 0, titleHeight = 0, underWidth = 0, underHeight = 0;
+ word->getSize( &wordWidth, &wordHeight );
+ broadcastPiecesSize( title, &titleWidth, &titleHeight );
+ broadcastPiecesSize( under, &underWidth, &underHeight );
+ const Int tabWidth = wordWidth + 2 * pad;
+ const Int width = tabWidth + pad + max( titleWidth, underWidth ) + pad;
+ const Int height = broadcastBannerHeight( title, under ) - rule;
+ const Int left = ( (Int)TheDisplay->getWidth() - width ) / 2;
+ const Int top = foot - rule - height;
+
+ const Int ruleWidth = REAL_TO_INT( width * ObserverCamera_easeBetween( shown, 0.0f, 0.45f ) );
+ TheDisplay->drawFillRect( left + ( width - ruleWidth ) / 2, foot - rule, ruleWidth, rule, tab );
+ const Int panelHeight = REAL_TO_INT( height * ObserverCamera_easeBetween( shown, 0.3f, 0.85f ) );
+ if( panelHeight > 0 )
{
- Int pieceWidth = 0, pieceHeight = 0;
- plate.pieces[ piece ]->getSize( &pieceWidth, &pieceHeight );
- plate.pieces[ piece ]->draw( x, top + pad / 2 + ( textHeight - pieceHeight ) / 2, broadcastFade( plate.colors[ piece ], shown ),
- broadcastFade( BROADCAST_GROUND, shown ) );
- x += pieceWidth + gap / 2;
+ TheDisplay->drawFillRect( left, foot - rule - panelHeight, width, panelHeight, BROADCAST_GROUND );
+ TheDisplay->drawFillRect( left, foot - rule - panelHeight, tabWidth, panelHeight, tab );
+ }
+ const Real words = ObserverCamera_easeBetween( shown, 0.8f, 1.0f );
+ if( words > 0.0f )
+ {
+ word->draw( left + pad, top + ( height - wordHeight ) / 2, broadcastFade( wordColor, words ), broadcastFade( tab, words ) );
+ drawBroadcastPieces( title, left + tabWidth + pad, top + pad / 2, titleHeight, words, BROADCAST_GROUND );
+ drawBroadcastPieces( under, left + tabWidth + pad, top + pad / 2 + titleHeight, underHeight, words, BROADCAST_GROUND );
}
+ IRegion2D drawn;
+ drawn.lo.x = left;
+ drawn.lo.y = top;
+ drawn.hi.x = left + width;
+ drawn.hi.y = foot;
+ return drawn;
}
//-------------------------------------------------------------------------------------------------
@@ -10709,66 +10784,81 @@ static const Int BROADCAST_CARD_DETAIL_POINTS[ BROADCAST_CARD_STEPS ] = { 9, 8,
static const Real BROADCAST_CARD_PAD[ BROADCAST_CARD_STEPS ] = { 6.0f, 5.0f, 4.0f, 3.0f };
/// the house colour along a card's top
static const Real BROADCAST_CARD_STRIP = 3.0f;
+/// the line through a defeated player's name, in 720 line pixels, with a pixel of the ground each side
+static const Real BROADCAST_STRIKE = 2.0f;
+/// a power's flag under a card: its icon this many 720 rows high, with this much of the panel round it
+static const Real BROADCAST_FLAG_ICON = 30.0f;
+static const Real BROADCAST_FLAG_INSET = 3.0f;
+
+/// the score bar laid out for one set of players: their cards' strings, every block's and card's place on
+/// the screen and the bar's measures. While a defeated player's card closes the bar is drawn between
+/// two, with that card and without it
+struct BroadcastLayout
+{
+ std::vector< SpectatorStats > players;
+ std::vector< BroadcastRow > rows;
+ std::vector< Int > blockFirst, blockSizes, blockArmies, lineOf;
+ std::vector< DisplayString * > teamNames, teamTotals;
+ std::vector< Int > blockLefts, blockWidths, blockHeaderTops, blockCardsTops;
+ std::vector< Int > cardLefts, cardTops, cardLines;
+ DisplayString *armyHead = NULL;
+ DisplayString *versusText = NULL;
+ Bool compact = FALSE;
+ Int step = 0, lines = 0, cardWidth = 0, fullCardWidth = 0, cardHeight = 0, cardPad = 0, halfPad = 0, versusWidth = 0;
+ Int nameHeight = 0, sideHeight = 0, numberHeight = 0, labelHeight = 0, textHeight = 0, strip = 0;
+ Int left = 0, barWidth = 0, height = 0, rowLeft = 0, rowWidth = 0, tugTop = 0;
+};
+
+/// a card's rectangle on the screen
+struct BroadcastPlace
+{
+ Int left, top, width, height;
+};
//-------------------------------------------------------------------------------------------------
-/** The score bar hangs from the top edge in the middle: the match clock in a tab of its own, and under
- * it every side in one row (two rows of one-line cards from five players), "Team A vs Team B vs a player alone", a card a player with his name in
- * his colour, his general or difficulty, his cash and the cost of everything he has standing that is
- * not a building. A team's cards sit together under its name and its armies' total. Under the row
- * the armies pull on one bar, each player his colour in the cards' order, gold at the middle when
- * two sides play so the side ahead is the one past it. While
- * a split is up each pane carries a plate in the top of its circle, inside its wedge and clear of
- * the lines and the radar, naming the fight's players.
- * Everything is read off the players and their objects; nothing here writes the logic. */
+/** The score bar laid out for players into l: every side in one row (two rows of one-line cards from
+ * five players), its cards sized to the largest step that fits the screen, under the clock's tab of
+ * clockBox by clockBoxHeight. Team letters come from named, everyone who played; tag keeps this
+ * layout's team totals apart from another's drawn in the same frame. */
//-------------------------------------------------------------------------------------------------
-void InGameUI::drawDirectorBroadcast( void )
+void InGameUI::layOutBroadcast( const std::vector< SpectatorStats > &players, const std::vector< SpectatorStats > &named,
+ const std::string &tag, Int clockBox, Int clockBoxHeight, BroadcastLayout &l )
{
- TheObserverCamera.clearBroadcast();
- std::vector< SpectatorStats > players = gatherSpectatorStats( SPECTATOR_STATS[ 0 ], NULL );
- // the match is over: nobody is left to score
- if( players.empty() )
- return;
- std::stable_sort( players.begin(), players.end(), []( const SpectatorStats &a, const SpectatorStats &b )
- { return a.team != b.team ? a.team < b.team : a.player->getPlayerIndex() < b.player->getPlayerIndex(); } );
-
const Int pad = broadcastPixels( BROADCAST_PAD );
- const Int rule = broadcastPixels( BROADCAST_RULE );
const Int tug = broadcastPixels( BROADCAST_TUG );
-
+ l.players = players;
// a block is one side: a team, or a player on his own, its players' cards side by side and a "vs"
// between two blocks
- std::vector< Int > blockFirst, blockSizes, blockArmies;
- for( size_t index = 0; index < players.size(); index++ )
+ for( size_t index = 0; index < l.players.size(); index++ )
{
- if( index == 0 || players[ index ].team != players[ index - 1 ].team )
+ if( index == 0 || l.players[ index ].team != l.players[ index - 1 ].team )
{
- blockFirst.push_back( (Int)index );
- blockSizes.push_back( 0 );
- blockArmies.push_back( 0 );
+ l.blockFirst.push_back( (Int)index );
+ l.blockSizes.push_back( 0 );
+ l.blockArmies.push_back( 0 );
}
- blockSizes.back()++;
- blockArmies.back() += players[ index ].army;
+ l.blockSizes.back()++;
+ l.blockArmies.back() += l.players[ index ].army;
}
- const Int blocks = (Int)blockSizes.size();
+ const Int blocks = (Int)l.blockSizes.size();
// five players or more stand in two rows, whole blocks to a row, and their cards keep one line each:
// the name at the left, the army's value at the right, no general and no cash. One row of eight
// two-line cards fell to 7 point text at 720, and one line with the cash had to be cut to fit
- const std::vector< Int > lineOf = ObserverCamera_cardRows( blockSizes );
- const Int lines = lineOf.back() + 1;
- const Bool compact = lines > 1;
- std::vector< std::vector< Int > > lineSizes( lines );
+ l.lineOf = ObserverCamera_cardRows( l.blockSizes );
+ l.lines = l.lineOf.back() + 1;
+ l.compact = l.lines > 1;
+ std::vector< std::vector< Int > > lineSizes( l.lines );
for( Int block = 0; block < blocks; block++ )
- lineSizes[ lineOf[ block ] ].push_back( blockSizes[ block ] );
+ lineSizes[ l.lineOf[ block ] ].push_back( l.blockSizes[ block ] );
// every card's text at a size, and the card width it needs: the widest of the name, the general or
// difficulty, the money line (cash, then the army's label and value) at six digits each, and a team
// header spread over its block's cards. Each size keeps strings of its own, since a string keeps
// the font it was made with
- std::vector< BroadcastRow > rows( players.size() );
- std::vector< DisplayString * > teamNames( blocks, NULL ), teamTotals( blocks, NULL );
- DisplayString *armyHead = NULL;
- DisplayString *versusText = NULL;
+ l.rows.assign( l.players.size(), BroadcastRow() );
+ l.teamNames.assign( blocks, NULL );
+ l.teamTotals.assign( blocks, NULL );
Int widestWidth = 0;
auto buildCards = [ & ]( Int step ) -> Int
{
@@ -10776,19 +10866,19 @@ void InGameUI::drawDirectorBroadcast( void )
const Int cardPad = broadcastPixels( BROADCAST_CARD_PAD[ step ] );
const Int namePoints = broadcastPoints( BROADCAST_CARD_NAME_POINTS[ step ] );
const Int detailPoints = broadcastPoints( BROADCAST_CARD_DETAIL_POINTS[ step ] );
- armyHead = broadcastText( size + "armyhead", TheGameText->fetch( "GUI:HudStatArmy" ), BROADCAST_WORDS,
+ l.armyHead = broadcastText( size + "armyhead", TheGameText->fetch( "GUI:HudStatArmy" ), BROADCAST_WORDS,
broadcastPoints( BROADCAST_HEAD_POINTS ), FALSE );
- versusText = broadcastText( size + "versus", UnicodeString( u"vs" ), BROADCAST_WORDS, detailPoints, FALSE );
+ l.versusText = broadcastText( size + "versus", UnicodeString( u"vs" ), BROADCAST_WORDS, detailPoints, FALSE );
DisplayString *widest = broadcastText( size + "widest", broadcastNumber( "$", BROADCAST_WIDEST ), BROADCAST_NUMBERS, detailPoints, TRUE );
Int width = 0, height = 0, labelWidth = 0;
- armyHead->getSize( &labelWidth, &height );
+ l.armyHead->getSize( &labelWidth, &height );
widest->getSize( &widestWidth, &height );
- Int content = compact ? 0 : widestWidth + cardPad + labelWidth + cardPad / 2 + widestWidth;
- for( size_t index = 0; index < players.size(); index++ )
+ Int content = l.compact ? 0 : widestWidth + cardPad + labelWidth + cardPad / 2 + widestWidth;
+ for( size_t index = 0; index < l.players.size(); index++ )
{
- const SpectatorStats &stats = players[ index ];
+ const SpectatorStats &stats = l.players[ index ];
const std::string seat = size + std::to_string( stats.player->getPlayerIndex() );
- BroadcastRow &row = rows[ index ];
+ BroadcastRow &row = l.rows[ index ];
row.stats = &stats;
row.color = clientPlayerColor( stats.player );
row.name = broadcastText( "name" + seat, broadcastName( stats.player ), BROADCAST_WORDS, namePoints, TRUE );
@@ -10796,25 +10886,27 @@ void InGameUI::drawDirectorBroadcast( void )
row.cash = broadcastText( "cash" + seat, broadcastNumber( "$", stats.cash ), BROADCAST_NUMBERS, detailPoints, TRUE );
row.army = broadcastText( "army" + seat, broadcastNumber( "$", stats.army ), BROADCAST_NUMBERS, detailPoints, TRUE );
row.name->getSize( &width, &height );
- content = max( content, compact ? width + cardPad + widestWidth : width );
- if( compact )
+ content = max( content, l.compact ? width + cardPad + widestWidth : width );
+ if( l.compact )
continue;
row.side->getSize( &width, &height );
content = max( content, width );
}
for( Int block = 0; block < blocks; block++ )
{
- if( blockSizes[ block ] < 2 )
+ if( l.blockSizes[ block ] < 2 )
continue;
- const std::string key = size + std::to_string( block );
- teamNames[ block ] = broadcastText( "teamname" + key, broadcastTeamName( players, players[ blockFirst[ block ] ].team ), BROADCAST_WORDS,
- detailPoints, TRUE );
- teamTotals[ block ] = broadcastText( "teamtotal" + key, broadcastNumber( "$", blockArmies[ block ] ), BROADCAST_NUMBERS, detailPoints, TRUE );
+ // keyed by the team and the layout, not the block's place: while a card closes both layouts are
+ // up, and a team's total is not the same in the two
+ const Int team = l.players[ l.blockFirst[ block ] ].team;
+ const std::string key = size + tag + std::to_string( team );
+ l.teamNames[ block ] = broadcastText( "teamname" + key, broadcastTeamName( named, team ), BROADCAST_WORDS, detailPoints, TRUE );
+ l.teamTotals[ block ] = broadcastText( "teamtotal" + key, broadcastNumber( "$", l.blockArmies[ block ] ), BROADCAST_NUMBERS, detailPoints, TRUE );
// the total measured as six digits, as the cards' numbers are, so the width holds still
Int nameWidth = 0;
- teamNames[ block ]->getSize( &nameWidth, &height );
+ l.teamNames[ block ]->getSize( &nameWidth, &height );
const Int header = nameWidth + cardPad + widestWidth;
- const Int cards = blockSizes[ block ];
+ const Int cards = l.blockSizes[ block ];
content = max( content, ( header - ( cards - 1 ) * cardPad + cards - 1 ) / cards - 2 * cardPad );
}
return content + 2 * cardPad;
@@ -10828,158 +10920,388 @@ void InGameUI::drawDirectorBroadcast( void )
cardWidths[ step ] = buildCards( step );
cardGaps[ step ] = broadcastPixels( BROADCAST_CARD_PAD[ step ] );
Int versusWidth = 0, versusHeight = 0;
- versusText->getSize( &versusWidth, &versusHeight );
+ l.versusText->getSize( &versusWidth, &versusHeight );
versusWidths[ step ] = versusWidth + 4 * cardGaps[ step ];
}
const Int room = (Int)TheDisplay->getWidth() - 4 * pad;
- Int step = 0;
- for( Int line = 0; line < lines; line++ )
- step = max( step, ObserverCamera_cardStep( lineSizes[ line ], cardWidths, cardGaps, versusWidths, BROADCAST_CARD_STEPS, room ) );
- buildCards( step );
- const Int cardPad = cardGaps[ step ];
- const Int versusWidth = versusWidths[ step ];
+ l.step = 0;
+ for( Int line = 0; line < l.lines; line++ )
+ l.step = max( l.step, ObserverCamera_cardStep( lineSizes[ line ], cardWidths, cardGaps, versusWidths, BROADCAST_CARD_STEPS, room ) );
+ buildCards( l.step );
+ l.cardPad = cardGaps[ l.step ];
+ l.versusWidth = versusWidths[ l.step ];
std::vector< Int > lineCards, lineBlocks;
- Int cardWidth = cardWidths[ step ];
- std::vector< Int > lineWidths( lines, 0 );
- for( Int line = 0; line < lines; line++ )
- lineWidths[ line ] = ObserverCamera_cardRow( lineSizes[ line ], cardWidth, cardPad, versusWidth, &lineCards, &lineBlocks );
- Int rowWidth = *std::max_element( lineWidths.begin(), lineWidths.end() );
- if( rowWidth > room )
- {
- for( Int line = 0; line < lines; line++ )
- cardWidth = min( cardWidth, ObserverCamera_cardWidthIn( lineSizes[ line ], cardPad, versusWidth, room ) );
- for( Int line = 0; line < lines; line++ )
- lineWidths[ line ] = ObserverCamera_cardRow( lineSizes[ line ], cardWidth, cardPad, versusWidth, &lineCards, &lineBlocks );
- rowWidth = *std::max_element( lineWidths.begin(), lineWidths.end() );
+ l.cardWidth = cardWidths[ l.step ];
+ l.fullCardWidth = l.cardWidth;
+ std::vector< Int > lineWidths( l.lines, 0 );
+ for( Int line = 0; line < l.lines; line++ )
+ lineWidths[ line ] = ObserverCamera_cardRow( lineSizes[ line ], l.cardWidth, l.cardPad, l.versusWidth, &lineCards, &lineBlocks );
+ l.rowWidth = *std::max_element( lineWidths.begin(), lineWidths.end() );
+ if( l.rowWidth > room )
+ {
+ for( Int line = 0; line < l.lines; line++ )
+ l.cardWidth = min( l.cardWidth, ObserverCamera_cardWidthIn( lineSizes[ line ], l.cardPad, l.versusWidth, room ) );
+ for( Int line = 0; line < l.lines; line++ )
+ lineWidths[ line ] = ObserverCamera_cardRow( lineSizes[ line ], l.cardWidth, l.cardPad, l.versusWidth, &lineCards, &lineBlocks );
+ l.rowWidth = *std::max_element( lineWidths.begin(), lineWidths.end() );
}
// every block's and every card's left across the bar, a shorter line in the middle under the longer
- std::vector< Int > cardLefts( players.size(), 0 ), blockLefts( blocks, 0 );
- for( Int line = 0; line < lines; line++ )
+ std::vector< Int > cardLefts( l.players.size(), 0 ), blockLefts( blocks, 0 );
+ for( Int line = 0; line < l.lines; line++ )
{
- ObserverCamera_cardRow( lineSizes[ line ], cardWidth, cardPad, versusWidth, &lineCards, &lineBlocks );
- const Int shift = ( rowWidth - lineWidths[ line ] ) / 2;
+ ObserverCamera_cardRow( lineSizes[ line ], l.cardWidth, l.cardPad, l.versusWidth, &lineCards, &lineBlocks );
+ const Int shift = ( l.rowWidth - lineWidths[ line ] ) / 2;
Int blockInLine = 0, cardInLine = 0;
for( Int block = 0; block < blocks; block++ )
{
- if( lineOf[ block ] != line )
+ if( l.lineOf[ block ] != line )
continue;
blockLefts[ block ] = shift + lineBlocks[ blockInLine++ ];
- for( Int index = blockFirst[ block ]; index < blockFirst[ block ] + blockSizes[ block ]; index++ )
+ for( Int index = l.blockFirst[ block ]; index < l.blockFirst[ block ] + l.blockSizes[ block ]; index++ )
cardLefts[ index ] = shift + lineCards[ cardInLine++ ];
}
}
- UnicodeString clockText;
- clockText.translate( AsciiString( spectatorClock( TheGameLogic->getFrame() ).c_str() ) );
- DisplayString *clock = broadcastText( "clock", clockText, BROADCAST_NUMBERS, broadcastPoints( BROADCAST_CLOCK_POINTS ), TRUE );
- Int clockWidth = 0, clockHeight = 0;
- clock->getSize( &clockWidth, &clockHeight );
-
// the bar's measures: the clock in a tab at the top in the middle, under it a line of team headers
// when there are teams, the cards, a header line and a card line again for a second row, and the
// armies' bar under all of it
- Int nameHeight = 0, sideHeight = 0, numberHeight = 0, labelHeight = 0, headerHeight = 0, width = 0;
- rows[ 0 ].name->getSize( &width, &nameHeight );
- rows[ 0 ].side->getSize( &width, &sideHeight );
- rows[ 0 ].cash->getSize( &width, &numberHeight );
- armyHead->getSize( &width, &labelHeight );
- numberHeight = max( numberHeight, labelHeight );
+ Int headerHeight = 0, width = 0;
+ l.rows[ 0 ].name->getSize( &width, &l.nameHeight );
+ l.rows[ 0 ].side->getSize( &width, &l.sideHeight );
+ l.rows[ 0 ].cash->getSize( &width, &l.numberHeight );
+ l.armyHead->getSize( &width, &l.labelHeight );
+ l.numberHeight = max( l.numberHeight, l.labelHeight );
for( Int block = 0; block < blocks; block++ )
- if( teamNames[ block ] != NULL )
- teamNames[ block ]->getSize( &width, &headerHeight );
+ if( l.teamNames[ block ] != NULL )
+ l.teamNames[ block ]->getSize( &width, &headerHeight );
// half a card pad round the card's text and under the team names, and a pad's half under the
// armies' bar: with a pad each and the money on two lines the bar took 125 rows of 720
- const Int halfPad = max( cardPad / 2, 1 );
+ l.halfPad = max( l.cardPad / 2, 1 );
if( headerHeight > 0 )
- headerHeight += halfPad;
- const Int clockBox = clockWidth + 2 * broadcastPixels( BROADCAST_GAP );
- const Int clockBoxHeight = clockHeight + rule;
- const Int barWidth = max( rowWidth, clockBox ) + 2 * pad;
- const Int left = ( (Int)TheDisplay->getWidth() - barWidth ) / 2;
- const Int rowLeft = left + ( barWidth - rowWidth ) / 2;
- const Int headerTop = clockBoxHeight + halfPad;
- const Int strip = broadcastPixels( BROADCAST_CARD_STRIP );
- const Int textHeight = compact ? max( nameHeight, numberHeight ) : nameHeight + sideHeight + numberHeight;
- const Int cardHeight = strip + halfPad + textHeight + halfPad;
+ headerHeight += l.halfPad;
+ l.barWidth = max( l.rowWidth, clockBox ) + 2 * pad;
+ l.left = ( (Int)TheDisplay->getWidth() - l.barWidth ) / 2;
+ l.rowLeft = l.left + ( l.barWidth - l.rowWidth ) / 2;
+ const Int headerTop = clockBoxHeight + l.halfPad;
+ l.strip = broadcastPixels( BROADCAST_CARD_STRIP );
+ l.textHeight = l.compact ? max( l.nameHeight, l.numberHeight ) : l.nameHeight + l.sideHeight + l.numberHeight;
+ l.cardHeight = l.strip + l.halfPad + l.textHeight + l.halfPad;
// a row's team headers take a line over it only when the row has a team
- std::vector< Int > lineHeaders( lines, 0 ), lineTops( lines, 0 );
+ std::vector< Int > lineHeaders( l.lines, 0 ), lineTops( l.lines, 0 );
+ for( Int block = 0; block < blocks; block++ )
+ if( l.teamNames[ block ] != NULL )
+ lineHeaders[ l.lineOf[ block ] ] = headerHeight;
+ l.tugTop = headerTop;
+ for( Int line = 0; line < l.lines; line++ )
+ {
+ lineTops[ line ] = l.tugTop;
+ l.tugTop += lineHeaders[ line ] + l.cardHeight + l.halfPad;
+ }
+ l.height = l.tugTop + tug + pad / 2;
+
+ // and every block and card where it stands on the screen
+ l.blockLefts.assign( blocks, 0 );
+ l.blockWidths.assign( blocks, 0 );
+ l.blockHeaderTops.assign( blocks, 0 );
+ l.blockCardsTops.assign( blocks, 0 );
+ l.cardLefts.assign( l.players.size(), 0 );
+ l.cardTops.assign( l.players.size(), 0 );
+ l.cardLines.assign( l.players.size(), 0 );
for( Int block = 0; block < blocks; block++ )
- if( teamNames[ block ] != NULL )
- lineHeaders[ lineOf[ block ] ] = headerHeight;
- Int tugTop = headerTop;
- for( Int line = 0; line < lines; line++ )
{
- lineTops[ line ] = tugTop;
- tugTop += lineHeaders[ line ] + cardHeight + halfPad;
+ l.blockLefts[ block ] = l.rowLeft + blockLefts[ block ];
+ l.blockWidths[ block ] = l.blockSizes[ block ] * l.cardWidth + ( l.blockSizes[ block ] - 1 ) * l.cardPad;
+ l.blockHeaderTops[ block ] = lineTops[ l.lineOf[ block ] ];
+ l.blockCardsTops[ block ] = l.blockHeaderTops[ block ] + lineHeaders[ l.lineOf[ block ] ];
+ for( Int index = l.blockFirst[ block ]; index < l.blockFirst[ block ] + l.blockSizes[ block ]; index++ )
+ {
+ l.cardLefts[ index ] = l.rowLeft + cardLefts[ index ];
+ l.cardTops[ index ] = l.blockCardsTops[ block ];
+ l.cardLines[ index ] = l.lineOf[ block ];
+ }
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The score bar hangs from the top edge in the middle: the match clock in a tab of its own, and under
+ * it every side in one row (two rows of one-line cards from five players), "Team A vs Team B vs a player alone", a card a player with his name in
+ * his colour, his general or difficulty, his cash and the cost of everything he has standing that is
+ * not a building. A team's cards sit together under its name and its armies' total. Under the row
+ * the armies pull on one bar, each player his colour in the cards' order, gold at the middle when
+ * two sides play so the side ahead is the one past it. A special power a player used drops its icon
+ * in a flag from under his card. A player who loses has his card flash red and struck through, then
+ * it closes while the others slide to where they stand without it, and his banner comes up across
+ * the lower picture; once the match is decided the winner's comes up under the last. While
+ * a split is up each pane carries a plate in the top of its circle, inside its wedge and clear of
+ * the lines and the radar, naming the fight's players.
+ * Everything is read off the players and their objects; nothing here writes the logic. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::drawDirectorBroadcast( void )
+{
+ TheObserverCamera.clearBroadcast();
+ // everyone who played, the ones who lost included, so a team keeps its letter after a player of it is
+ // gone; the bar holds the ones still in, and a defeated player's card until it has closed
+ std::vector< SpectatorStats > named = gatherSpectatorStats( SPECTATOR_STATS[ 0 ], NULL, TheObserverCamera.getPlayedMask() );
+ std::stable_sort( named.begin(), named.end(), []( const SpectatorStats &a, const SpectatorStats &b )
+ { return a.team != b.team ? a.team < b.team : a.player->getPlayerIndex() < b.player->getPlayerIndex(); } );
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ std::vector< SpectatorStats > shown, settled;
+ std::vector< Real > flashes, strikes;
+ Real slide = 0.0f;
+ for( size_t index = 0; index < named.size(); index++ )
+ {
+ const Int seat = named[ index ].player->getPlayerIndex();
+ Real flash = 0.0f, struck = 0.0f, collapse = 0.0f;
+ if( TheObserverCamera.getDefeatFrame( seat ) != 0 )
+ ObserverCamera_cardExit( frame, TheObserverCamera.getDefeatFrame( seat ), TheObserverCamera.getCollapseFrame( seat ),
+ &flash, &struck, &collapse );
+ if( collapse >= 1.0f )
+ continue;
+ shown.push_back( named[ index ] );
+ flashes.push_back( flash );
+ strikes.push_back( struck );
+ if( collapse > 0.0f )
+ slide = collapse;
+ else
+ settled.push_back( named[ index ] );
}
- const Int height = tugTop + tug + pad / 2;
+ // the match is over: nobody is left to score
+ if( shown.empty() )
+ return;
+ // cards close one at a time, so the bar is between two layouts at most: with that card and without it
+ const Bool sliding = slide > 0.0f && !settled.empty();
+
+ const Int pad = broadcastPixels( BROADCAST_PAD );
+ const Int rule = broadcastPixels( BROADCAST_RULE );
+ const Int tug = broadcastPixels( BROADCAST_TUG );
+ UnicodeString clockText;
+ clockText.translate( AsciiString( spectatorClock( frame ).c_str() ) );
+ DisplayString *clock = broadcastText( "clock", clockText, BROADCAST_NUMBERS, broadcastPoints( BROADCAST_CLOCK_POINTS ), TRUE );
+ Int clockWidth = 0, clockHeight = 0;
+ clock->getSize( &clockWidth, &clockHeight );
+ const Int clockBox = clockWidth + 2 * broadcastPixels( BROADCAST_GAP );
+ const Int clockBoxHeight = clockHeight + rule;
+
+ BroadcastLayout from, to;
+ layOutBroadcast( shown, named, "", clockBox, clockBoxHeight, from );
+ if( sliding )
+ layOutBroadcast( settled, named, "to", clockBox, clockBoxHeight, to );
+ // a card is drawn with the first layout's strings and measures over the first half of a slide and the
+ // second's after: the same strings unless the size or the rows change
+ const BroadcastLayout &face = sliding && slide >= 0.5f ? to : from;
+ auto mix = [ & ]( Int first, Int second ) { return sliding ? first + REAL_TO_INT( ( second - first ) * slide ) : first; };
+ auto seatIn = []( const BroadcastLayout &l, const Player *player ) -> Int
+ {
+ for( size_t index = 0; index < l.players.size(); index++ )
+ if( l.players[ index ].player == player )
+ return (Int)index;
+ return -1;
+ };
+ auto teamIn = []( const BroadcastLayout &l, Int team ) -> Int
+ {
+ for( size_t block = 0; block < l.blockFirst.size(); block++ )
+ if( l.players[ l.blockFirst[ block ] ].team == team )
+ return (Int)block;
+ return -1;
+ };
+ // a card in both layouts moves from its first place to its second; the closing one narrows on its own
+ // middle and the others slide over it
+ auto cardPlace = [ & ]( Int index ) -> BroadcastPlace
+ {
+ BroadcastPlace place = { from.cardLefts[ index ], from.cardTops[ index ], from.cardWidth, from.cardHeight };
+ if( !sliding )
+ return place;
+ const Int other = seatIn( to, from.players[ index ].player );
+ if( other < 0 )
+ {
+ const Int open = REAL_TO_INT( from.cardWidth * ( 1.0f - slide ) );
+ place.left += ( from.cardWidth - open ) / 2;
+ place.width = open;
+ return place;
+ }
+ place.left = mix( from.cardLefts[ index ], to.cardLefts[ other ] );
+ place.top = mix( from.cardTops[ index ], to.cardTops[ other ] );
+ place.width = mix( from.cardWidth, to.cardWidth );
+ place.height = mix( from.cardHeight, to.cardHeight );
+ return place;
+ };
+ const Int left = mix( from.left, to.left );
+ const Int barWidth = mix( from.barWidth, to.barWidth );
+ const Int height = mix( from.height, to.height );
+ const Int rowLeft = mix( from.rowLeft, to.rowLeft );
+ const Int rowWidth = mix( from.rowWidth, to.rowWidth );
+ const Int tugTop = mix( from.tugTop, to.tugTop );
const Int clockLeft = left + ( barWidth - clockBox ) / 2;
+ // a special power's flag, its button's icon on the panel, drops from the bar's foot under its
+ // player's card; a superweapon's is edged in gold. Drawn before the bar, which covers it until it is
+ // clear. In two rows the top row's flags hang a quarter card left and the bottom's a quarter right,
+ // so a card and the one under it do not hang theirs on top of each other
+ std::vector< IRegion2D > flagsDrawn;
+ for( size_t index = 0; index < from.players.size(); index++ )
+ {
+ Real drop = 0.0f;
+ const DirectorShowing *flag = TheObserverCamera.getPowerFlag( from.players[ index ].player->getPlayerIndex(), &drop );
+ if( flag == NULL || drop <= 0.0f )
+ continue;
+ const Image *icon = superweaponCameo( flag->power );
+ if( icon == NULL && flag->sourceThing != NULL )
+ icon = flag->sourceThing->getButtonImage();
+ if( icon == NULL || icon->getImageHeight() <= 0 )
+ continue;
+ const BroadcastPlace place = cardPlace( (Int)index );
+ const Int faceIndex = &face == &from ? (Int)index : seatIn( to, from.players[ index ].player );
+ const Int quarter = face.lines > 1 ? ( face.cardLines[ faceIndex ] == 0 ? -place.width / 4 : place.width / 4 ) : 0;
+ const Int iconHeight = broadcastPixels( BROADCAST_FLAG_ICON );
+ const Int iconWidth = iconHeight * icon->getImageWidth() / icon->getImageHeight();
+ const Int inset = broadcastPixels( BROADCAST_FLAG_INSET );
+ const Int edge = flag->superweapon ? max( broadcastPixels( BROADCAST_GOLD_EDGE ), 2 ) : 0;
+ const Int accent = from.strip;
+ const Int flagWidth = iconWidth + 2 * inset + 2 * edge;
+ const Int flagHeight = iconHeight + 2 * inset + accent;
+ const Int flagLeft = place.left + place.width / 2 + quarter - flagWidth / 2;
+ const Int flagTop = height - flagHeight + REAL_TO_INT( flagHeight * drop );
+ if( edge > 0 )
+ TheDisplay->drawFillRect( flagLeft, flagTop, flagWidth, flagHeight, BROADCAST_GOLD );
+ TheDisplay->drawFillRect( flagLeft + edge, flagTop, flagWidth - 2 * edge, flagHeight - accent, BROADCAST_PANEL );
+ TheDisplay->drawImage( icon, flagLeft + edge + inset, flagTop + inset, flagLeft + edge + inset + iconWidth, flagTop + inset + iconHeight );
+ if( edge == 0 )
+ drawBroadcastSwatch( flagLeft, flagTop + flagHeight - accent, flagWidth, accent, from.rows[ index ].color );
+ IRegion2D drawn;
+ drawn.lo.x = flagLeft - max( broadcastPixels( BROADCAST_GOLD_EDGE ), 2 );
+ drawn.lo.y = height;
+ drawn.hi.x = flagLeft + flagWidth + max( broadcastPixels( BROADCAST_GOLD_EDGE ), 2 );
+ drawn.hi.y = flagTop + flagHeight + max( broadcastPixels( BROADCAST_GOLD_EDGE ), 2 );
+ flagsDrawn.push_back( drawn );
+ }
+
TheDisplay->drawFillRect( left, 0, barWidth, height, BROADCAST_GROUND );
TheDisplay->drawFillRect( clockLeft, 0, clockBox, clockBoxHeight, BROADCAST_PANEL );
TheDisplay->drawFillRect( clockLeft, clockBoxHeight - rule, clockBox, rule, BROADCAST_GOLD );
clock->draw( clockLeft + ( clockBox - clockWidth ) / 2, 0, BROADCAST_INK, BROADCAST_GROUND );
- // block by block: a "vs" before every block but the first, a team's name and its armies' total over
- // its cards, and a card a player, the house colour along its top, the name, the general or the
- // difficulty, then one money line: the cash at the left, the army's label and value at the right
- Int versusTextWidth = 0, versusTextHeight = 0;
- versusText->getSize( &versusTextWidth, &versusTextHeight );
- Int armyLabelWidth = 0;
- armyHead->getSize( &armyLabelWidth, &labelHeight );
- for( Int block = 0; block < blocks; block++ )
+ // block by block: a "vs" before every block but the first of its row, and a team's name and its
+ // armies' total over its cards. A block in both layouts moves with its cards; one in the first alone,
+ // the closing player's own, or a team header gone with him, fades out where it stood
+ auto drawMoving = [ & ]( DisplayString *text, Color color, Bool first, Int firstX, Int firstY, Bool second, Int secondX, Int secondY )
+ {
+ if( first && second )
+ text->draw( mix( firstX, secondX ), mix( firstY, secondY ), color, BROADCAST_GROUND );
+ else if( first )
+ text->draw( firstX, firstY, broadcastFade( color, 1.0f - slide ), broadcastFade( BROADCAST_GROUND, 1.0f - slide ) );
+ else if( second )
+ text->draw( secondX, secondY, broadcastFade( color, slide ), broadcastFade( BROADCAST_GROUND, slide ) );
+ };
+ auto versusAt = []( const BroadcastLayout &l, Int block, Int *x, Int *y ) -> Bool
{
- const Int blockLeft = rowLeft + blockLefts[ block ];
- const Int blockWidth = blockSizes[ block ] * cardWidth + ( blockSizes[ block ] - 1 ) * cardPad;
- const Int blockHeaderTop = lineTops[ lineOf[ block ] ];
- const Int blockCardsTop = blockHeaderTop + lineHeaders[ lineOf[ block ] ];
- if( block > 0 && lineOf[ block ] == lineOf[ block - 1 ] )
- versusText->draw( blockLeft - ( versusWidth + versusTextWidth ) / 2, blockCardsTop + ( cardHeight - versusTextHeight ) / 2,
- BROADCAST_MUTED, BROADCAST_GROUND );
- if( teamNames[ block ] != NULL )
- {
- Int totalWidth = 0, totalHeight = 0;
- teamTotals[ block ]->getSize( &totalWidth, &totalHeight );
- teamNames[ block ]->draw( blockLeft, blockHeaderTop, BROADCAST_GOLD, BROADCAST_GROUND );
- teamTotals[ block ]->draw( blockLeft + blockWidth - totalWidth, blockHeaderTop, BROADCAST_INK, BROADCAST_GROUND );
- }
- for( Int index = blockFirst[ block ]; index < blockFirst[ block ] + blockSizes[ block ]; index++ )
+ if( block <= 0 || l.lineOf[ block ] != l.lineOf[ block - 1 ] )
+ return FALSE;
+ Int width = 0, tall = 0;
+ l.versusText->getSize( &width, &tall );
+ *x = l.blockLefts[ block ] - ( l.versusWidth + width ) / 2;
+ *y = l.blockCardsTops[ block ] + ( l.cardHeight - tall ) / 2;
+ return TRUE;
+ };
+ for( size_t block = 0; block < from.blockFirst.size(); block++ )
+ {
+ const Int other = sliding ? teamIn( to, from.players[ from.blockFirst[ block ] ].team ) : -1;
+ Int firstX = 0, firstY = 0, secondX = 0, secondY = 0;
+ const Bool versusFirst = versusAt( from, (Int)block, &firstX, &firstY );
+ const Bool versusSecond = other >= 0 && versusAt( to, other, &secondX, &secondY );
+ drawMoving( versusFirst && versusSecond ? face.versusText : versusFirst ? from.versusText : to.versusText, BROADCAST_MUTED,
+ versusFirst, firstX, firstY, versusSecond, secondX, secondY );
+
+ const Bool headerFirst = from.teamNames[ block ] != NULL;
+ const Bool headerSecond = other >= 0 && to.teamNames[ other ] != NULL;
+ if( !headerFirst && !headerSecond )
+ continue;
+ const BroadcastLayout &look = headerFirst && headerSecond ? face : headerFirst ? from : to;
+ const Int lookBlock = &look == &from ? (Int)block : other;
+ Int totalWidth = 0, totalHeight = 0;
+ look.teamTotals[ lookBlock ]->getSize( &totalWidth, &totalHeight );
+ const Int secondLeft = other >= 0 ? to.blockLefts[ other ] : 0;
+ const Int secondRight = other >= 0 ? to.blockLefts[ other ] + to.blockWidths[ other ] : 0;
+ const Int secondTop = other >= 0 ? to.blockHeaderTops[ other ] : 0;
+ drawMoving( look.teamNames[ lookBlock ], BROADCAST_GOLD, headerFirst, from.blockLefts[ block ], from.blockHeaderTops[ block ],
+ headerSecond, secondLeft, secondTop );
+ drawMoving( look.teamTotals[ lookBlock ], BROADCAST_INK, headerFirst, from.blockLefts[ block ] + from.blockWidths[ block ] - totalWidth,
+ from.blockHeaderTops[ block ], headerSecond, secondRight - totalWidth, secondTop );
+ }
+
+ // a card a player, the house colour along its top, the name, the general or the difficulty, then one
+ // money line: the cash at the left, the army's label and value at the right. A defeated player's card
+ // flashes red, takes a red veil and has a line drawn through his name; closing, its words go first
+ auto drawCard = [ & ]( const BroadcastLayout &l, Int index, const BroadcastPlace &place, Real faded, Real words, Real flash, Real struck )
+ {
+ const BroadcastRow &row = l.rows[ index ];
+ const Int textLeft = place.left + l.cardPad;
+ const Int numberEnd = place.left + place.width - l.cardPad;
+ TheDisplay->drawFillRect( place.left, place.top, place.width, place.height, broadcastFade( BROADCAST_PANEL, faded ) );
+ if( struck > 0.0f )
+ TheDisplay->drawFillRect( place.left, place.top, place.width, place.height, broadcastFade( BROADCAST_DEFEAT, 0.2f * struck * faded ) );
+ drawBroadcastSwatch( place.left, place.top, place.width, l.strip, broadcastFade( row.color, faded ) );
+ if( words > 0.0f )
{
- const BroadcastRow &row = rows[ index ];
- const Int cardLeft = rowLeft + cardLefts[ index ];
- const Int textLeft = cardLeft + cardPad;
- const Int numberEnd = cardLeft + cardWidth - cardPad;
- TheDisplay->drawFillRect( cardLeft, blockCardsTop, cardWidth, cardHeight, BROADCAST_PANEL );
- drawBroadcastSwatch( cardLeft, blockCardsTop, cardWidth, strip, row.color );
- Int top = blockCardsTop + strip + halfPad;
+ const Color ground = broadcastFade( BROADCAST_GROUND, words );
+ Int top = place.top + l.strip + l.halfPad;
Int numberWidth = 0, numberTall = 0;
row.name->getSize( &numberWidth, &numberTall );
- row.name->draw( textLeft, compact ? top + textHeight - numberTall : top, ObserverCamera_readableColor( row.color ), BROADCAST_GROUND );
- if( !compact )
+ const Int nameTop = l.compact ? top + l.textHeight - numberTall : top;
+ const Int nameTall = numberTall;
+ row.name->draw( textLeft, nameTop, broadcastFade( ObserverCamera_readableColor( row.color ), words * ( 1.0f - 0.4f * struck ) ), ground );
+ if( !l.compact )
{
- top += nameHeight;
- row.side->draw( textLeft, top, BROADCAST_MUTED, BROADCAST_GROUND );
- top += sideHeight;
+ top += l.nameHeight;
+ row.side->draw( textLeft, top, broadcastFade( BROADCAST_MUTED, words ), ground );
+ top += l.sideHeight;
}
- const Int moneyBottom = compact ? top + textHeight : top + numberHeight;
+ const Int moneyBottom = l.compact ? top + l.textHeight : top + l.numberHeight;
row.army->getSize( &numberWidth, &numberTall );
- row.army->draw( numberEnd - numberWidth, moneyBottom - numberTall, BROADCAST_INK, BROADCAST_GROUND );
- if( compact )
+ row.army->draw( numberEnd - numberWidth, moneyBottom - numberTall, broadcastFade( BROADCAST_INK, words ), ground );
+ if( !l.compact )
+ {
+ Int armyLabelWidth = 0, armyLabelTall = 0;
+ l.armyHead->getSize( &armyLabelWidth, &armyLabelTall );
+ l.armyHead->draw( numberEnd - numberWidth - l.halfPad - armyLabelWidth, moneyBottom - l.labelHeight, broadcastFade( BROADCAST_MUTED, words ), ground );
+ row.cash->getSize( &numberWidth, &numberTall );
+ row.cash->draw( textLeft, moneyBottom - numberTall, broadcastFade( BROADCAST_INK, words ), ground );
+ }
+ // the line runs left to right across the card through the name, edged in the ground so it reads
+ // over a red player's name as well
+ if( struck > 0.0f )
+ {
+ const Int thick = max( broadcastPixels( BROADCAST_STRIKE ), 2 );
+ const Int lineTop = nameTop + ( nameTall - thick ) / 2;
+ const Int length = REAL_TO_INT( ( place.width - 2 * l.cardPad ) * struck );
+ TheDisplay->drawFillRect( textLeft, lineTop - 1, length, thick + 2, ground );
+ TheDisplay->drawFillRect( textLeft, lineTop, length, thick, broadcastFade( BROADCAST_DEFEAT, words ) );
+ }
+ }
+ if( flash > 0.0f )
+ TheDisplay->drawFillRect( place.left, place.top, place.width, place.height, broadcastFade( BROADCAST_DEFEAT, 0.85f * flash * faded ) );
+ };
+ // the closing card first, so the others slide over it
+ for( Int pass = 0; pass < 2; pass++ )
+ for( size_t index = 0; index < from.players.size(); index++ )
+ {
+ const Int other = sliding ? seatIn( to, from.players[ index ].player ) : (Int)index;
+ const Bool closing = sliding && other < 0;
+ if( closing != ( pass == 0 ) )
continue;
- armyHead->draw( numberEnd - numberWidth - halfPad - armyLabelWidth, moneyBottom - labelHeight, BROADCAST_MUTED, BROADCAST_GROUND );
- row.cash->getSize( &numberWidth, &numberTall );
- row.cash->draw( textLeft, moneyBottom - numberTall, BROADCAST_INK, BROADCAST_GROUND );
+ const BroadcastLayout &look = closing ? from : face;
+ drawCard( look, &look == &from ? (Int)index : other, cardPlace( (Int)index ), closing ? 1.0f - slide : 1.0f,
+ closing ? max( 1.0f - slide * 4.0f, 0.0f ) : 1.0f, flashes[ index ], strikes[ index ] );
}
- }
// the armies' bar under the whole row, every player's share in the cards' order, so with two sides
// each pulls from its own end and they meet at a gold mark in the middle; more sides are parted by
// the ground's colour
+ const Int faceBlocks = (Int)face.blockFirst.size();
std::vector< Int > barArmies, barBlocks;
- for( Int block = 0; block < blocks; block++ )
- for( Int index = blockFirst[ block ]; index < blockFirst[ block ] + blockSizes[ block ]; index++ )
+ for( Int block = 0; block < faceBlocks; block++ )
+ for( Int index = face.blockFirst[ block ]; index < face.blockFirst[ block ] + face.blockSizes[ block ]; index++ )
{
- barArmies.push_back( players[ index ].army );
+ barArmies.push_back( face.players[ index ].army );
barBlocks.push_back( block );
}
TheDisplay->drawFillRect( rowLeft, tugTop, rowWidth, tug, BROADCAST_LINE );
@@ -10987,12 +11309,12 @@ void InGameUI::drawDirectorBroadcast( void )
Int barAt = rowLeft;
for( size_t piece = 0; piece < shares.size(); piece++ )
{
- drawBroadcastSwatch( barAt, tugTop, shares[ piece ], tug, rows[ piece ].color );
- if( blocks > 2 && piece > 0 && barBlocks[ piece ] != barBlocks[ piece - 1 ] )
+ drawBroadcastSwatch( barAt, tugTop, shares[ piece ], tug, face.rows[ piece ].color );
+ if( faceBlocks > 2 && piece > 0 && barBlocks[ piece ] != barBlocks[ piece - 1 ] )
TheDisplay->drawFillRect( barAt, tugTop - rule, rule, tug + 2 * rule, BROADCAST_GROUND );
barAt += shares[ piece ];
}
- if( blocks == 2 )
+ if( faceBlocks == 2 )
TheDisplay->drawFillRect( rowLeft + ( rowWidth - rule ) / 2, tugTop - rule, rule, tug + 2 * rule, BROADCAST_GOLD );
IRegion2D bar;
@@ -11001,17 +11323,20 @@ void InGameUI::drawDirectorBroadcast( void )
bar.hi.x = left + barWidth;
bar.hi.y = height;
TheObserverCamera.addBroadcast( bar );
+ for( size_t flag = 0; flag < flagsDrawn.size(); flag++ )
+ TheObserverCamera.addBroadcast( flagsDrawn[ flag ] );
TheObserverCamera.setBroadcastTop( (Real)( height + pad ) );
static Int loggedHeight = -1;
- if( height != loggedHeight )
+ if( !sliding && height != loggedHeight )
{
loggedHeight = height;
- DEBUG_LOG(( "OBSCAM frame %u score bar %d x %d, %d row(s), size %d (name %d, detail %d points), card %d of %d\n", TheGameLogic->getFrame(),
- barWidth, height, lines, step, BROADCAST_CARD_NAME_POINTS[ step ], BROADCAST_CARD_DETAIL_POINTS[ step ], cardWidth, cardWidths[ step ] ));
+ DEBUG_LOG(( "OBSCAM frame %u score bar %d x %d, %d row(s), size %d (name %d, detail %d points), card %d of %d\n", frame,
+ barWidth, height, from.lines, from.step, BROADCAST_CARD_NAME_POINTS[ from.step ], BROADCAST_CARD_DETAIL_POINTS[ from.step ],
+ from.cardWidth, from.fullCardWidth ));
}
// a split's plate a pane, faded in and out with the panes; the opening's are each pane's own
- const Real shown = TheObserverCamera.getPaneProgress();
+ const Real paneShown = TheObserverCamera.getPaneProgress();
const Int panes = TheObserverCamera.isIntro() ? 0 : TheObserverCamera.getDrawnPaneCount();
DisplayString *versus = broadcastText( "versus", UnicodeString( u"vs" ), BROADCAST_WORDS, broadcastPoints( BROADCAST_SIDE_POINTS ), FALSE );
for( Int pane = 0; pane < panes && panes >= 2; pane++ )
@@ -11019,23 +11344,23 @@ void InGameUI::drawDirectorBroadcast( void )
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( Int block = 0; block < blocks; block++ )
+ for( size_t block = 0; block < from.blockFirst.size(); block++ )
{
- for( Int index = blockFirst[ block ]; index < blockFirst[ block ] + blockSizes[ block ]; index++ )
+ for( Int index = from.blockFirst[ block ]; index < from.blockFirst[ block ] + from.blockSizes[ block ]; index++ )
{
- if( ( rows[ index ].stats->player->getPlayerMask() & sides ) == 0 )
+ Player *player = from.players[ index ].player;
+ if( ( 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 ),
+ const Bool team = from.teamNames[ block ] != NULL;
+ plate.pieces.push_back( team ? broadcastText( "plateteam" + std::to_string( block ), broadcastTeamName( named, from.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 ) );
+ plate.colors.push_back( team ? BROADCAST_INK : ObserverCamera_readableColor( from.rows[ index ].color ) );
if( team )
break;
}
@@ -11050,7 +11375,7 @@ void InGameUI::drawDirectorBroadcast( void )
TheObserverCamera.getPaneCircle( pane, &centre, &radius );
const Int plateTop = REAL_TO_INT( ObserverCamera_paneLabelTop( centre, radius, (Real)plateWidth, (Real)plateHeight ) );
const Int plateLeft = REAL_TO_INT( centre.x ) - plateWidth / 2;
- drawBroadcastPlate( plate, plateLeft, plateTop, shown );
+ drawBroadcastPlate( plate, plateLeft, plateTop, paneShown );
IRegion2D drawn;
drawn.lo.x = plateLeft;
@@ -11059,6 +11384,67 @@ void InGameUI::drawDirectorBroadcast( void )
drawn.hi.y = plateTop + plateHeight;
TheObserverCamera.addBroadcast( drawn );
}
+
+ // a defeated player's banner across the lower picture, the broadcast's red in its tab, and once the
+ // match is decided the winner's under it in gold. A banner names the player in his colour, under it
+ // his general or difficulty and his team
+ auto bannerLines = [ & ]( Player *player, BroadcastPlate *title, BroadcastPlate *under )
+ {
+ const std::string seat = std::to_string( player->getPlayerIndex() );
+ title->pieces.push_back( broadcastText( "bannername" + seat, broadcastName( player ), BROADCAST_WORDS, broadcastPoints( BROADCAST_BANNER_POINTS ), TRUE ) );
+ title->colors.push_back( ObserverCamera_readableColor( clientPlayerColor( player ) ) );
+ under->pieces.push_back( broadcastText( "bannerside" + seat, broadcastSide( player ), BROADCAST_WORDS, broadcastPoints( BROADCAST_SIDE_POINTS ), FALSE ) );
+ under->colors.push_back( BROADCAST_MUTED );
+ for( size_t index = 0; index < named.size(); index++ )
+ {
+ if( named[ index ].player != player || broadcastTeamSize( named, named[ index ].team ) < 2 )
+ continue;
+ under->pieces.push_back( broadcastText( "bannerteam" + seat, broadcastTeamName( named, named[ index ].team ), BROADCAST_WORDS,
+ broadcastPoints( BROADCAST_SIDE_POINTS ), TRUE ) );
+ under->colors.push_back( BROADCAST_GOLD );
+ }
+ };
+ const Int foot = REAL_TO_INT( TheDisplay->getHeight() * BROADCAST_BANNER_FOOT );
+ Real defeatShown = 0.0f;
+ const DirectorShowing *defeat = TheObserverCamera.getDefeatBanner( &defeatShown );
+ if( defeat != NULL && defeatShown > 0.0f )
+ {
+ BroadcastPlate title, under;
+ bannerLines( ThePlayerList->getNthPlayer( defeat->player ), &title, &under );
+ DisplayString *word = broadcastText( "bannerdefeated", UnicodeString( u"Defeated" ), BROADCAST_WORDS,
+ broadcastPoints( BROADCAST_BANNER_WORD_POINTS ), TRUE );
+ TheObserverCamera.addBroadcast( drawBroadcastBanner( word, BROADCAST_DEFEAT, BROADCAST_INK, title, under, foot, defeatShown ) );
+ }
+ // a team that won is named once, its players under it
+ const Real winnerShown = TheObserverCamera.getWinnerShown();
+ std::vector< const SpectatorStats * > winners;
+ for( size_t index = 0; index < named.size(); index++ )
+ if( named[ index ].player->isPlayerActive() )
+ winners.push_back( &named[ index ] );
+ if( winnerShown > 0.0f && !winners.empty() )
+ {
+ BroadcastPlate title, under;
+ const Int team = winners[ 0 ]->team;
+ if( broadcastTeamSize( named, team ) >= 2 )
+ {
+ title.pieces.push_back( broadcastText( "bannerwinteam", broadcastTeamName( named, team ), BROADCAST_WORDS,
+ broadcastPoints( BROADCAST_BANNER_POINTS ), TRUE ) );
+ title.colors.push_back( BROADCAST_INK );
+ for( size_t index = 0; index < winners.size(); index++ )
+ {
+ Player *player = winners[ index ]->player;
+ under.pieces.push_back( broadcastText( "bannerwinner" + std::to_string( player->getPlayerIndex() ), broadcastName( player ),
+ BROADCAST_WORDS, broadcastPoints( BROADCAST_SIDE_POINTS ), TRUE ) );
+ under.colors.push_back( ObserverCamera_readableColor( clientPlayerColor( player ) ) );
+ }
+ }
+ else
+ bannerLines( winners[ 0 ]->player, &title, &under );
+ DisplayString *word = broadcastText( "bannervictory", UnicodeString( u"Victory" ), BROADCAST_WORDS,
+ broadcastPoints( BROADCAST_BANNER_WORD_POINTS ), TRUE );
+ const Int winnerFoot = foot + broadcastPixels( BROADCAST_GAP ) + broadcastBannerHeight( title, under );
+ TheObserverCamera.addBroadcast( drawBroadcastBanner( word, BROADCAST_GOLD, BROADCAST_GROUND, title, under, winnerFoot, winnerShown ) );
+ }
}
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index 235b8277b..089b0db88 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -25,6 +25,9 @@
#include "Common/Player.h"
#include "Common/PlayerList.h"
+#include "Common/PlayerTemplate.h"
+#include "Common/Science.h"
+#include "Common/SpecialPower.h"
#include "Common/ThingTemplate.h"
#include "GameClient/Display.h"
#include "GameClient/Drawable.h"
@@ -39,6 +42,7 @@
#include "GameLogic/Object.h"
#include "GameLogic/PartitionManager.h"
#include "GameLogic/TerrainLogic.h"
+#include "GameLogic/VictoryConditions.h"
#include <algorithm>
#include <math.h>
@@ -200,6 +204,26 @@ static const UnsignedInt DIRECTOR_PREROLL_FRAMES = 4 * LOGICFRAMES_PER_SECOND;
/// both passes take the logic's CRC this often, and a filming pass whose CRC differs from the
/// scouting pass's is not playing the match the timeline describes
static const UnsignedInt SCOUT_CRC_FRAMES = 30 * LOGICFRAMES_PER_SECOND;
+/// the broadcast's power flags drop and go back up over the first many logic frames; the defeat and
+/// winner banners open and close over the second, the rule, the panel and the words one after another
+static const UnsignedInt FLAG_MOVE_FRAMES = 15;
+static const UnsignedInt BANNER_MOVE_FRAMES = 24;
+/// a power's flag hangs under its player's card this long when nothing waits behind it, a defeated
+/// player's banner holds this long
+static const UnsignedInt FLAG_HOLD_FRAMES = 4 * LOGICFRAMES_PER_SECOND;
+static const UnsignedInt DEFEAT_BANNER_HOLD_FRAMES = 3 * LOGICFRAMES_PER_SECOND;
+/// a defeated player's card flashes red over the first of these, a line is drawn through it from the
+/// second over the third, it is seen struck until the fourth after the defeat and then collapses over
+/// the last while the others slide together
+static const UnsignedInt CARD_FLASH_FRAMES = 12;
+static const UnsignedInt CARD_STRIKE_FROM = 6;
+static const UnsignedInt CARD_STRIKE_FRAMES = 12;
+static const UnsignedInt CARD_STRUCK_FRAMES = 36;
+static const UnsignedInt CARD_COLLAPSE_FRAMES = 18;
+/// the winner's banner starts to come in this long after the match is decided, as the last defeated
+/// player's banner over it has opened: the film runs 105 frames past the decision, and at 30 the winner's
+/// was all in for only 51 of them
+static const UnsignedInt WINNER_DELAY_FRAMES = 24;
//-------------------------------------------------------------------------------------------------
static Bool sameFight( const Coord2D &a, const Coord2D &b )
@@ -1170,9 +1194,7 @@ Int ObserverCamera_paneBandWidth( Int height )
}
//-------------------------------------------------------------------------------------------------
-/** progress along from to to, eased in and out, 0 before from and 1 after to. */
-//-------------------------------------------------------------------------------------------------
-static Real easeBetween( Real progress, Real from, Real to )
+Real ObserverCamera_easeBetween( Real progress, Real from, Real to )
{
const Real t = min( max( ( progress - from ) / ( to - from ), 0.0f ), 1.0f );
return t * t * ( 3.0f - 2.0f * t );
@@ -1181,19 +1203,19 @@ static Real easeBetween( Real progress, Real from, Real to )
//-------------------------------------------------------------------------------------------------
Real ObserverCamera_lineDrawn( Real progress )
{
- return easeBetween( progress, 0.0f, PANE_LINE_DRAWN_BY );
+ return ObserverCamera_easeBetween( progress, 0.0f, PANE_LINE_DRAWN_BY );
}
//-------------------------------------------------------------------------------------------------
Real ObserverCamera_bandShown( Real progress )
{
- return easeBetween( progress, PANE_BAND_FROM, 1.0f );
+ return ObserverCamera_easeBetween( progress, PANE_BAND_FROM, 1.0f );
}
//-------------------------------------------------------------------------------------------------
Real ObserverCamera_frameTraced( Real progress )
{
- return easeBetween( progress, 0.0f, PANE_FRAME_TRACED_BY );
+ return ObserverCamera_easeBetween( progress, 0.0f, PANE_FRAME_TRACED_BY );
}
//-------------------------------------------------------------------------------------------------
@@ -1202,7 +1224,55 @@ Real ObserverCamera_shimmerAt( UnsignedInt frame )
const UnsignedInt into = frame % PANE_SHIMMER_PERIOD;
if( into >= PANE_SHIMMER_FRAMES )
return -1.0f;
- return easeBetween( (Real)into, 0.0f, (Real)PANE_SHIMMER_FRAMES );
+ return ObserverCamera_easeBetween( (Real)into, 0.0f, (Real)PANE_SHIMMER_FRAMES );
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool ObserverCamera_advanceShowing( std::vector< DirectorShowing > &queue, UnsignedInt frame, UnsignedInt moveFrames, UnsignedInt holdAlone,
+ Bool keepLast )
+{
+ if( !queue.empty() && queue.front().leaving != 0 && frame >= queue.front().leaving + moveFrames )
+ queue.erase( queue.begin() );
+ if( queue.empty() )
+ return FALSE;
+ DirectorShowing &first = queue.front();
+ if( first.start == 0 )
+ {
+ first.start = frame;
+ return TRUE;
+ }
+ const size_t waiting = queue.size() - 1;
+ const UnsignedInt hold = holdAlone / (UnsignedInt)min( waiting + 1, (size_t)3 );
+ if( first.leaving == 0 && !( keepLast && waiting == 0 ) && frame >= first.start + moveFrames + hold )
+ first.leaving = frame;
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------------------------------
+Real ObserverCamera_showingShown( const DirectorShowing &showing, UnsignedInt frame, UnsignedInt moveFrames )
+{
+ if( showing.start == 0 )
+ return 0.0f;
+ const Real in = ObserverCamera_easeFrames( frame, showing.start, moveFrames );
+ if( showing.leaving == 0 )
+ return in;
+ return in * ( 1.0f - ObserverCamera_easeFrames( frame, showing.leaving, moveFrames ) );
+}
+
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera_cardExit( UnsignedInt frame, UnsignedInt defeated, UnsignedInt collapseFrom, Real *flash, Real *struck, Real *collapse )
+{
+ // up in a third of the flash, down over the rest
+ const UnsignedInt up = CARD_FLASH_FRAMES / 3;
+ *flash = ObserverCamera_easeFrames( frame, defeated, up ) * ( 1.0f - ObserverCamera_easeFrames( frame, defeated + up, CARD_FLASH_FRAMES - up ) );
+ *struck = ObserverCamera_easeFrames( frame, defeated + CARD_STRIKE_FROM, CARD_STRIKE_FRAMES );
+ *collapse = ObserverCamera_easeFrames( frame, collapseFrom, CARD_COLLAPSE_FRAMES );
+}
+
+//-------------------------------------------------------------------------------------------------
+UnsignedInt ObserverCamera_collapseFrom( UnsignedInt defeated, UnsignedInt lastCollapse )
+{
+ return max( defeated + CARD_STRUCK_FRAMES, lastCollapse + CARD_COLLAPSE_FRAMES );
}
//-------------------------------------------------------------------------------------------------
@@ -1255,6 +1325,16 @@ void ObserverCamera::reset( void )
m_seen.clear();
m_events.clear();
m_nextEventId = 1;
+ for( Int index = 0; index < MAX_PLAYER_COUNT; index++ )
+ {
+ m_flags[ index ].clear();
+ m_defeatFrame[ index ] = 0;
+ m_collapseFrame[ index ] = 0;
+ }
+ m_defeatBanners.clear();
+ m_playedMask = 0;
+ m_lastCollapse = 0;
+ m_winnerFrame = 0;
m_fights.clear();
m_fightSides.clear();
m_broadcast.clear();
@@ -1312,7 +1392,8 @@ void ObserverCamera::reset( void )
/** Called from the logic on every machine, players' included, so it only ever adds to a list the
* director reads; nothing the logic does depends on it. */
//-------------------------------------------------------------------------------------------------
-void ObserverCamera::noteSpecialPower( const Player *owner, const Coord3D *from, const Coord3D *at, Bool superweapon )
+void ObserverCamera::noteSpecialPower( const Player *owner, const Coord3D *from, const Coord3D *at, Bool superweapon,
+ const SpecialPowerTemplate *power, const ThingTemplate *sourceThing )
{
const UnsignedInt frame = TheGameLogic->getFrame();
dropOldEvents( frame );
@@ -1332,7 +1413,11 @@ void ObserverCamera::noteSpecialPower( const Player *owner, const Coord3D *from,
// director cut to empty ground for every one an Air Force general fired. The scouting pass knows
// which ones land; without it a power waits for its first hit
event.landed = superweapon || ObserverCamera_powerLands( m_timeline, frame, event.target );
+ event.power = power;
+ event.sourceThing = sourceThing;
m_events.push_back( event );
+ if( event.landed )
+ noteFlag( event );
if( !TheGlobalData->m_directorScoutFile.isEmpty() )
{
@@ -1369,10 +1454,102 @@ void ObserverCamera::noteSuperweaponHit( const Player *owner, const Coord3D *at,
}
// a warhead nobody's special power sent, a script's or a map's, is still worth seeing land
- noteSpecialPower( owner, at, at, TRUE );
+ noteSpecialPower( owner, at, at, TRUE, NULL, NULL );
m_events.back().until = frame + EVENT_AFTERMATH_FRAMES;
}
+//-------------------------------------------------------------------------------------------------
+/** A power that landed hangs its flag under its player's card: a superweapon, or a general's power,
+ * one a promotion bought. A unit's own ability, a sniper's shot or a hacker's, is neither. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::noteFlag( const DirectorEvent &event )
+{
+ if( !TheGlobalData->m_directorRecord || event.power == NULL )
+ return;
+ if( !event.superweapon && event.power->getRequiredScience() == SCIENCE_INVALID )
+ return;
+ const Int index = event.owner->getPlayerIndex();
+ const DirectorShowing flag = { index, event.power, event.sourceThing, event.superweapon, 0, 0 };
+ m_flags[ index ].push_back( flag );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The broadcast's moments, one logic frame on: a player seen playing who no longer is has lost, his
+ * card struck and his banner queued; the match decided brings the winner's banner; and every queue
+ * of flags and banners moves on. Read off the players, never written to them. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::updateBroadcastMoments( UnsignedInt frame )
+{
+ for( Int index = 0; index < ThePlayerList->getPlayerCount() && index < MAX_PLAYER_COUNT; index++ )
+ {
+ Player *player = ThePlayerList->getNthPlayer( index );
+ if( !player->isPlayableSide() || player->isPlayerObserver() )
+ continue;
+ const PlayerMaskType mask = player->getPlayerMask();
+ if( player->isPlayerActive() )
+ {
+ m_playedMask |= mask;
+ continue;
+ }
+ if( ( m_playedMask & mask ) == 0 || m_defeatFrame[ index ] != 0 )
+ continue;
+ m_defeatFrame[ index ] = frame;
+ m_collapseFrame[ index ] = ObserverCamera_collapseFrom( frame, m_lastCollapse );
+ m_lastCollapse = m_collapseFrame[ index ];
+ m_flags[ index ].clear();
+ const DirectorShowing banner = { index, NULL, NULL, FALSE, 0, 0 };
+ m_defeatBanners.push_back( banner );
+ DEBUG_LOG(( "OBSCAM frame %u defeat: player %d '%s' (%s), card struck, collapses at frame %u\n", frame, index,
+ WideCharAsUtf8( player->getPlayerDisplayName().str() ).str(), WideCharAsUtf8( player->getPlayerTemplate()->getDisplayName().str() ).str(),
+ m_collapseFrame[ index ] ));
+ }
+
+ const UnsignedInt decidedOn = TheVictoryConditions->getEndFrame();
+ const Bool decided = decidedOn > LOGICFRAMES_PER_SECOND;
+ if( decided && m_winnerFrame == 0 )
+ {
+ m_winnerFrame = frame + WINNER_DELAY_FRAMES;
+ DEBUG_LOG(( "OBSCAM frame %u match decided on frame %u, winner banner at frame %u\n", frame, decidedOn, m_winnerFrame ));
+ }
+
+ if( ObserverCamera_advanceShowing( m_defeatBanners, frame, BANNER_MOVE_FRAMES, DEFEAT_BANNER_HOLD_FRAMES, decided ) )
+ DEBUG_LOG(( "OBSCAM frame %u defeat banner: player %d, %d waiting\n", frame, m_defeatBanners.front().player,
+ (Int)m_defeatBanners.size() - 1 ));
+ for( Int index = 0; index < MAX_PLAYER_COUNT; index++ )
+ {
+ if( !ObserverCamera_advanceShowing( m_flags[ index ], frame, FLAG_MOVE_FRAMES, FLAG_HOLD_FRAMES, FALSE ) )
+ continue;
+ const DirectorShowing &flag = m_flags[ index ].front();
+ DEBUG_LOG(( "OBSCAM frame %u power flag under player %d's card: %s%s, %d waiting\n", frame, index, flag.power->getName().str(),
+ flag.superweapon ? " (superweapon)" : "", (Int)m_flags[ index ].size() - 1 ));
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+const DirectorShowing *ObserverCamera::getPowerFlag( Int playerIndex, Real *drop ) const
+{
+ const std::vector< DirectorShowing > &flags = m_flags[ playerIndex ];
+ if( flags.empty() || flags.front().start == 0 )
+ return NULL;
+ *drop = ObserverCamera_showingShown( flags.front(), TheGameLogic->getFrame(), FLAG_MOVE_FRAMES );
+ return &flags.front();
+}
+
+//-------------------------------------------------------------------------------------------------
+const DirectorShowing *ObserverCamera::getDefeatBanner( Real *shown ) const
+{
+ if( m_defeatBanners.empty() || m_defeatBanners.front().start == 0 )
+ return NULL;
+ *shown = ObserverCamera_showingShown( m_defeatBanners.front(), TheGameLogic->getFrame(), BANNER_MOVE_FRAMES );
+ return &m_defeatBanners.front();
+}
+
+//-------------------------------------------------------------------------------------------------
+Real ObserverCamera::getWinnerShown( void ) const
+{
+ return m_winnerFrame == 0 ? 0.0f : ObserverCamera_easeFrames( TheGameLogic->getFrame(), m_winnerFrame, BANNER_MOVE_FRAMES );
+}
+
//-------------------------------------------------------------------------------------------------
void ObserverCamera::dropOldEvents( UnsignedInt frame )
{
@@ -2607,7 +2784,11 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
// hits at the target keep it going: the missiles arriving, the bombs, the fires after
if( frame >= event.since + EVENT_LAUNCH_FRAMES && ObserverCamera_heatAround( hits, event.target, &middle ) > 0.0f )
event.until = max( event.until, frame + EVENT_AFTERMATH_FRAMES );
- event.landed = event.landed || ObserverCamera_heatAround( fights, event.target, &middle ) > 0.0f;
+ if( !event.landed && ObserverCamera_heatAround( fights, event.target, &middle ) > 0.0f )
+ {
+ event.landed = TRUE;
+ noteFlag( event );
+ }
if( !event.landed )
continue;
if( best == NULL || event.weight >= best->weight )
@@ -2884,6 +3065,7 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )
if( !m_timelineLoaded )
loadTimeline();
checkTimeline( frame );
+ updateBroadcastMoments( frame );
const Bool introStarting = !m_introDone;
advancePanes( frame );
if( m_intro && introStarting )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
index ec47accd6..4e9b252c8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
@@ -574,7 +574,7 @@ void SpecialPowerModule::aboutToDoSpecialPower( const Coord3D *location )
// the observer's director camera goes to see it; this only tells the client
if( location != NULL )
TheObserverCamera.noteSpecialPower( getObject()->getControllingPlayer(), getObject()->getPosition(), location,
- getObject()->isKindOf( KINDOF_FS_SUPERWEAPON ) );
+ getObject()->isKindOf( KINDOF_FS_SUPERWEAPON ), getSpecialPowerModuleData()->m_specialPowerTemplate, getObject()->getTemplate() );
// Let EVA do her thing
SpecialPowerType type = getSpecialPowerModuleData()->m_specialPowerTemplate->getSpecialPowerType();
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index 2055dd5ba..feffaa59f 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -1038,3 +1038,73 @@ TEST(a_dark_player_colour_is_lifted_to_read_and_a_gold_one_is_told_from_the_line
CHECK( !ObserverCamera_nearBrandGold( GameMakeColor( 0x00, 0x00, 0xff, 255 ) ) );
CHECK( !ObserverCamera_nearBrandGold( GameMakeColor( 0xff, 0x00, 0x00, 255 ) ) );
}
+
+TEST(power_flags_hang_one_at_a_time_and_hold_less_with_another_waiting)
+{
+ const DirectorShowing waiting = { 3, NULL, NULL, FALSE, 0, 0 };
+ std::vector< DirectorShowing > flags( 2, waiting );
+ // the first drops on the frame it is queued; with one behind it, it holds half of 120 after its 15
+ CHECK( ObserverCamera_advanceShowing( flags, 100, 15, 120, FALSE ) );
+ CHECK_EQ( flags[ 0 ].start, 100u );
+ CHECK_EQ( flags[ 1 ].start, 0u );
+ CHECK_NEAR( ObserverCamera_showingShown( flags[ 0 ], 100, 15 ), 0.0f, 0.0001f );
+ for( UnsignedInt frame = 101; frame < 175; frame++ )
+ CHECK( !ObserverCamera_advanceShowing( flags, frame, 15, 120, FALSE ) );
+ CHECK_NEAR( ObserverCamera_showingShown( flags[ 0 ], 174, 15 ), 1.0f, 0.0001f );
+ CHECK( !ObserverCamera_advanceShowing( flags, 175, 15, 120, FALSE ) );
+ CHECK_EQ( flags[ 0 ].leaving, 175u );
+ CHECK( ObserverCamera_showingShown( flags[ 0 ], 182, 15 ) > 0.0f );
+ CHECK( ObserverCamera_showingShown( flags[ 0 ], 182, 15 ) < 1.0f );
+ // gone 15 frames later, and the next drops on that frame and, alone, holds the whole 120
+ for( UnsignedInt frame = 176; frame < 190; frame++ )
+ CHECK( !ObserverCamera_advanceShowing( flags, frame, 15, 120, FALSE ) );
+ CHECK( ObserverCamera_advanceShowing( flags, 190, 15, 120, FALSE ) );
+ CHECK_EQ( (Int)flags.size(), 1 );
+ CHECK_EQ( flags[ 0 ].start, 190u );
+ for( UnsignedInt frame = 191; frame <= 325; frame++ )
+ ObserverCamera_advanceShowing( flags, frame, 15, 120, FALSE );
+ CHECK_EQ( flags[ 0 ].leaving, 325u );
+ for( UnsignedInt frame = 326; frame <= 340; frame++ )
+ ObserverCamera_advanceShowing( flags, frame, 15, 120, FALSE );
+ CHECK( flags.empty() );
+ CHECK( !ObserverCamera_advanceShowing( flags, 341, 15, 120, FALSE ) );
+}
+
+TEST(the_last_defeat_banner_of_a_decided_match_stays_up)
+{
+ const DirectorShowing waiting = { 1, NULL, NULL, FALSE, 0, 0 };
+ std::vector< DirectorShowing > banners( 2, waiting );
+ for( UnsignedInt frame = 100; frame < 1000; frame++ )
+ ObserverCamera_advanceShowing( banners, frame, 24, 90, TRUE );
+ // the first opened over 24, held 45 with the last behind it and closed over 24; the last never leaves
+ CHECK_EQ( (Int)banners.size(), 1 );
+ CHECK_EQ( banners[ 0 ].start, 193u );
+ CHECK_EQ( banners[ 0 ].leaving, 0u );
+ CHECK_NEAR( ObserverCamera_showingShown( banners[ 0 ], 999, 24 ), 1.0f, 0.0001f );
+}
+
+TEST(a_defeated_card_flashes_is_struck_and_closes_one_card_at_a_time)
+{
+ Real flash = 0.0f, struck = 0.0f, collapse = 0.0f;
+ const UnsignedInt first = ObserverCamera_collapseFrom( 100, 0 );
+ CHECK_EQ( first, 136u );
+ ObserverCamera_cardExit( 100, 100, first, &flash, &struck, &collapse );
+ CHECK_NEAR( flash, 0.0f, 0.0001f );
+ ObserverCamera_cardExit( 104, 100, first, &flash, &struck, &collapse );
+ CHECK_NEAR( flash, 1.0f, 0.0001f );
+ CHECK_NEAR( struck, 0.0f, 0.0001f );
+ ObserverCamera_cardExit( 112, 100, first, &flash, &struck, &collapse );
+ CHECK_NEAR( flash, 0.0f, 0.0001f );
+ CHECK( struck > 0.0f && struck < 1.0f );
+ ObserverCamera_cardExit( 136, 100, first, &flash, &struck, &collapse );
+ CHECK_NEAR( struck, 1.0f, 0.0001f );
+ CHECK_NEAR( collapse, 0.0f, 0.0001f );
+ ObserverCamera_cardExit( 145, 100, first, &flash, &struck, &collapse );
+ CHECK_NEAR( collapse, 0.5f, 0.0001f );
+ ObserverCamera_cardExit( 154, 100, first, &flash, &struck, &collapse );
+ CHECK_NEAR( collapse, 1.0f, 0.0001f );
+ // a second player beaten on the same frame closes once the first card has gone, a later one on its own
+ const UnsignedInt second = ObserverCamera_collapseFrom( 100, first );
+ CHECK_EQ( second, 154u );
+ CHECK_EQ( ObserverCamera_collapseFrom( 400, second ), 436u );
+}