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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): a lobby unit limit, 840 shared out between the players
Olcay Seygan4113308151f3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ad1cc1b56..79c4387ec 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -473,6 +473,7 @@ found and fixed — EA's own, not port damage.**- Every lobby now has two tabs over the bottom panel, Info and Lobby Settings, and the one you are looking at is the one greyed out. The host's settings live on the settings page; the map details in skirmish and the chat log in a network game come back the moment you tab away from it.- Skirmish keeps starting cash and the game speed slider there. LAN and online keep starting cash next to peace time and the superweapon rule. Before this they were scattered around whatever space each of the three lobby screens happened to have left over.- The game speed slider stops at 60. Its last notch used to read "--" and started the match at a thousand game frames a second, which no machine can play and every machine tried to. A speed saved on that notch comes back as 60.+- A Unit Limit box on the settings page caps the match at 840 units, shared out evenly: two players get 420 each, four get 210, eight get 105. Units standing and units waiting in a queue both count against your share, buildings do not, and the build buttons grey out when you reach it. Your own count and your share sit in the top right corner next to the frame rate, so you can see the wall coming. The host ticks it; everybody else sees it ticked.- Superweapons are a dropdown instead of a tick box. Allow Superweapons is the game as it plays without a rule. Limit Superweapons leaves each player one Particle Cannon, one Nuclear Missile or one Scud Storm at a time. No Superweapons bars them.- The USA Superweapon General is the exception to both, because the rule that reads as a handicap to everyone else reads as a deletion to him: three superweapons of his own are what he pays for weaker tanks, weaker infantry and a worse air force with. Under Limit he keeps four of each of his. Under No he keeps one. Play him against a lobby that has banned superweapons and you are playing the army you paid for, not an empty base.- The tick box was one number for everybody, which is why it could only ever say yes or no. A ticked box in a settings file from an older build reads back as No Superweapons.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex b8f33a7d5..d06448b07 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -674,3 +674,11 @@ ENDTOOLTIP:Superweapons"How many of each superweapon a player may have standing. Allow: as many as he can pay for. Limit: one each, and four for the USA Superweapon General. No: none at all, except the Superweapon General, who keeps one. He is the exception because his three superweapons are what he pays for a weaker army with."END++GUI:UnitLimit+"Unit Limit"+END++TOOLTIP:UnitLimit+"840 units shared out evenly between the players: two players get 420 each, eight get 105. Units standing and units waiting in a queue both count, buildings do not. Your own count and your share are in the top right corner during the match."+ENDdiff --git a/GeneralsMD/Code/Data/Window/Menus/GameSpyGameOptionsMenu.wnd b/GeneralsMD/Code/Data/Window/Menus/GameSpyGameOptionsMenu.wndindex ab134825c..f08e53c94 100644--- a/GeneralsMD/Code/Data/Window/Menus/GameSpyGameOptionsMenu.wnd+++ b/GeneralsMD/Code/Data/Window/Menus/GameSpyGameOptionsMenu.wnd@@ -11213,6 +11213,53 @@ WINDOWIMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;END+ CHILD+ WINDOW+ WINDOWTYPE = CHECKBOX;+ SCREENRECT = UPPERLEFT: 500 420, BOTTOMRIGHT: 660 444, CREATIONRESOLUTION: 800 600;+ NAME = "GameSpyGameOptionsMenu.wnd:CheckBoxUnitLimit";+ STATUS = ENABLED+IMAGE;+ STYLE = CHECKBOX+MOUSETRACK;+ SYSTEMCALLBACK = "[None]";+ INPUTCALLBACK = "[None]";+ TOOLTIPCALLBACK = "[None]";+ DRAWCALLBACK = "[None]";+ FONT = NAME: "Arial", SIZE: 10, BOLD: 0;+ HEADERTEMPLATE = "TextEntry";+ TOOLTIPTEXT = "TOOLTIP:UnitLimit";+ TOOLTIPDELAY = -1;+ TEXT = "GUI:UnitLimit";+ TEXTCOLOR = ENABLED: 254 254 254 255, ENABLEDBORDER: 0 0 0 255,+ DISABLED: 140 138 138 255, DISABLEDBORDER: 64 64 64 255,+ HILITE: 128 128 255 255, HILITEBORDER: 0 0 128 255;+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ ENDENDALLCHILDRENENDCHILDdiff --git a/GeneralsMD/Code/Data/Window/Menus/LanGameOptionsMenu.wnd b/GeneralsMD/Code/Data/Window/Menus/LanGameOptionsMenu.wndindex da2650b90..aee7659c0 100644--- a/GeneralsMD/Code/Data/Window/Menus/LanGameOptionsMenu.wnd+++ b/GeneralsMD/Code/Data/Window/Menus/LanGameOptionsMenu.wnd@@ -10312,6 +10312,53 @@ WINDOWIMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;END+ CHILD+ WINDOW+ WINDOWTYPE = CHECKBOX;+ SCREENRECT = UPPERLEFT: 501 376, BOTTOMRIGHT: 661 400, CREATIONRESOLUTION: 800 600;+ NAME = "LanGameOptionsMenu.wnd:CheckBoxUnitLimit";+ STATUS = ENABLED+IMAGE;+ STYLE = CHECKBOX+MOUSETRACK;+ SYSTEMCALLBACK = "[None]";+ INPUTCALLBACK = "[None]";+ TOOLTIPCALLBACK = "[None]";+ DRAWCALLBACK = "[None]";+ FONT = NAME: "Arial", SIZE: 10, BOLD: 0;+ HEADERTEMPLATE = "TextEntry";+ TOOLTIPTEXT = "TOOLTIP:UnitLimit";+ TOOLTIPDELAY = -1;+ TEXT = "GUI:UnitLimit";+ TEXTCOLOR = ENABLED: 254 254 254 255, ENABLEDBORDER: 0 0 0 255,+ DISABLED: 140 138 138 255, DISABLEDBORDER: 64 64 64 255,+ HILITE: 128 128 255 255, HILITEBORDER: 0 0 128 255;+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ ENDENDALLCHILDRENENDCHILDdiff --git a/GeneralsMD/Code/Data/Window/Menus/SkirmishGameOptionsMenu.wnd b/GeneralsMD/Code/Data/Window/Menus/SkirmishGameOptionsMenu.wndindex a55ae4722..a47fea982 100644--- a/GeneralsMD/Code/Data/Window/Menus/SkirmishGameOptionsMenu.wnd+++ b/GeneralsMD/Code/Data/Window/Menus/SkirmishGameOptionsMenu.wnd@@ -9557,7 +9557,7 @@ WINDOWCHILDWINDOWWINDOWTYPE = STATICTEXT;- SCREENRECT = UPPERLEFT: 312 452, BOTTOMRIGHT: 456 476, CREATIONRESOLUTION: 800 600;+ SCREENRECT = UPPERLEFT: 312 444, BOTTOMRIGHT: 456 468, CREATIONRESOLUTION: 800 600;NAME = "SkirmishGameOptionsMenu.wnd:LabelGameSpeed";STATUS = ENABLED+NOINPUT+NOFOCUS;STYLE = STATICTEXT+MOUSETRACK;@@ -9604,7 +9604,7 @@ WINDOWCHILDWINDOWWINDOWTYPE = HORZSLIDER;- SCREENRECT = UPPERLEFT: 468 454, BOTTOMRIGHT: 606 474, CREATIONRESOLUTION: 800 600;+ SCREENRECT = UPPERLEFT: 468 446, BOTTOMRIGHT: 606 466, CREATIONRESOLUTION: 800 600;NAME = "SkirmishGameOptionsMenu.wnd:SliderGameSpeed";STATUS = ENABLED+IMAGE+TABSTOP;STYLE = HORZSLIDER+MOUSETRACK;@@ -9679,7 +9679,7 @@ WINDOWCHILDWINDOWWINDOWTYPE = STATICTEXT;- SCREENRECT = UPPERLEFT: 614 452, BOTTOMRIGHT: 648 476, CREATIONRESOLUTION: 800 600;+ SCREENRECT = UPPERLEFT: 614 444, BOTTOMRIGHT: 648 468, CREATIONRESOLUTION: 800 600;NAME = "SkirmishGameOptionsMenu.wnd:StaticTextGameSpeed";STATUS = ENABLED;STYLE = STATICTEXT+MOUSETRACK;@@ -9725,7 +9725,7 @@ WINDOWCHILDWINDOWWINDOWTYPE = STATICTEXT;- SCREENRECT = UPPERLEFT: 312 420, BOTTOMRIGHT: 456 444, CREATIONRESOLUTION: 800 600;+ SCREENRECT = UPPERLEFT: 312 416, BOTTOMRIGHT: 456 440, CREATIONRESOLUTION: 800 600;NAME = "SkirmishGameOptionsMenu.wnd:LabelSuperweapons";STATUS = ENABLED+IMAGE;STYLE = STATICTEXT+MOUSETRACK;@@ -9773,7 +9773,7 @@ WINDOWCHILDWINDOWWINDOWTYPE = COMBOBOX;- SCREENRECT = UPPERLEFT: 468 420, BOTTOMRIGHT: 648 444, CREATIONRESOLUTION: 800 600;+ SCREENRECT = UPPERLEFT: 468 416, BOTTOMRIGHT: 648 440, CREATIONRESOLUTION: 800 600;NAME = "SkirmishGameOptionsMenu.wnd:ComboBoxSuperweapons";STATUS = ENABLED+IMAGE;STYLE = MOUSETRACK+COMBOBOX;@@ -10010,6 +10010,53 @@ WINDOWIMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;END+ CHILD+ WINDOW+ WINDOWTYPE = CHECKBOX;+ SCREENRECT = UPPERLEFT: 312 472, BOTTOMRIGHT: 492 496, CREATIONRESOLUTION: 800 600;+ NAME = "SkirmishGameOptionsMenu.wnd:CheckBoxUnitLimit";+ STATUS = ENABLED+IMAGE;+ STYLE = CHECKBOX+MOUSETRACK;+ SYSTEMCALLBACK = "[None]";+ INPUTCALLBACK = "[None]";+ TOOLTIPCALLBACK = "[None]";+ DRAWCALLBACK = "[None]";+ FONT = NAME: "Arial", SIZE: 10, BOLD: 0;+ HEADERTEMPLATE = "TextEntry";+ TOOLTIPTEXT = "TOOLTIP:UnitLimit";+ TOOLTIPDELAY = -1;+ TEXT = "GUI:UnitLimit";+ TEXTCOLOR = ENABLED: 254 254 254 255, ENABLEDBORDER: 0 0 0 255,+ DISABLED: 140 138 138 255, DISABLEDBORDER: 64 64 64 255,+ HILITE: 128 128 255 255, HILITEBORDER: 0 0 128 255;+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ ENDENDALLCHILDRENENDCHILDdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 7ef8d2b0c..b9bece34b 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -386,6 +386,7 @@ public:Int m_autoSkirmishAIStateOdd; ///< -aidiff2 <name>: rung for the odd-numbered slots (0 = same as -aidiff)Int m_autoSkirmishTeams; ///< -teams <n>: split the auto-skirmish slots into n allied teams (0 or 1 = free-for-all)Int m_peaceTime; ///< -peacetime <n>: the lobby's peace time, in minutes, for an -autoskirmish run+ Bool m_unitLimit; ///< -unitlimit: the lobby's unit limit for an -autoskirmish runInt m_maxGameFrames; ///< -maxframes <n>: quit after n logic frames however the match is going (0 = no limit)Int m_screenShotFrame; ///< -screenshot <n>: save one picture when the run reaches logic frame n (0 = never)Int m_videoStartFrame; ///< -video <from> <to> [name]: the first logic frame recordeddiff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex 07229a65f..d3972b58f 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -121,6 +121,11 @@ static const char *ScienceAvailabilityNames[] =enum { SUPERWEAPON_CAP_BANNED = -1, SUPERWEAPON_CAP_UNLIMITED = 0 };Int SuperweaponBuildCap( Int restriction, const AsciiString &playerTemplateName );+// The lobby's unit limit is this many units for the whole match, shared out evenly between the+// players who are not watching. UnitLimitPerPlayer is one player's share.+enum { UNIT_LIMIT_TOTAL = 840 };+Int UnitLimitPerPlayer( Int nonObserverPlayers );+static const Int NUM_HOTKEY_SQUADS = 10;enum { NO_HOTKEY_SQUAD = -1 };@@ -303,6 +308,7 @@ public:// Check MaxSimultaneousOfTypeBool canBuildMoreOfType( const ThingTemplate *whatToBuild ) const;+ Int countUnitsTowardCap( void ) const; ///< units standing and queued, what the lobby's unit limit is checked against/// Difficulty level for this player.GameDifficulty getPlayerDifficulty(void) const;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.hindex 6fc013c97..5925e9d6b 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h@@ -258,6 +258,10 @@ public:/// TRUE while the truce forbids these two hurting each other; the one question both gates askBool peaceTimeForbids( const Object *attacker, const Object *victim ) const;+ /** Each player's share of the lobby's unit limit, the same number for everybody. 0 when the+ limit is off, which is every campaign mission and every game it was not ticked for. */+ UnsignedInt getUnitCap( void ) const { return m_unitCap; }+#ifdef DUMP_PERF_STATSvoid getAIMetricsStatistics( UnsignedInt *numAI, UnsignedInt *numMoving, UnsignedInt *numAttacking, UnsignedInt *numWaitingForPath, UnsignedInt *overallFailedPathfinds );void resetOverallFailedPathfinds() { m_overallFailedPathfinds = 0; }@@ -374,6 +378,7 @@ private:Int m_rankLevelLimit;UnsignedShort m_superweaponRestriction;UnsignedInt m_peaceTimeEndFrame; ///< logic frame the lobby's peace time runs out on, 0 = no peace time+ UnsignedInt m_unitCap; ///< units each player may have standing and queued, 0 = no limitLoadScreen *getLoadScreen( Bool loadSaveGame );LoadScreen *m_loadScreen;diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.hindex 185793210..f2b40a1cb 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h@@ -80,6 +80,11 @@ void PopulateSuperweaponComboBox(GameWindow *comboBox, GameInfo *myGame, Bool hovoid UpdateSuperweaponComboBox(GameWindow *comboBox, GameInfo *myGame, Bool hostMayEdit);Int SuperweaponRestrictionFromComboBox(GameWindow *comboBox);+// The unit limit check box, which the host ticks and which travels in the options string as UL.+// UpdateUnitLimitCheckBox puts the box on what the game says and greys it out for anyone who may not+// touch it, and it only sets the box when the box is wrong.+void UpdateUnitLimitCheckBox(GameWindow *checkBox, GameInfo *myGame, Bool hostMayEdit);+// The lobby's own tab strip: one page of host settings, and the window that page covers - the chat// log in the two network lobbies, the map info list in the skirmish one. All three screens share// these because only one lobby is ever up, and because a tab strip written three times drifts.diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.hindex 0f54b5557..062e02f63 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h@@ -245,6 +245,11 @@ public:inline Int getPeaceTime( void ) const;void setPeaceTime( Int minutes );+ // The lobby's unit limit: UNIT_LIMIT_TOTAL units shared out evenly between the players. Off is+ // the retail game. UnitLimitPerPlayer in Player.h turns the player count into each one's share.+ inline Bool getUnitLimit( void ) const;+ void setUnitLimit( Bool unitLimit );+Bool hasAIPlayers( void ) const; ///< is any slot held by a computer player?protected:@@ -269,6 +274,7 @@ protected:UnsignedShort m_superweaponRestriction;Bool m_oldFactionsOnly; // Only USA, China, GLA -- not USA Air Force General, GLA Toxic General, et alInt m_peaceTime; // minutes of enforced peace at the start of the match, 0 = off+ Bool m_unitLimit; // the lobby's unit limit is on};extern GameInfo *TheGameInfo;@@ -297,6 +303,7 @@ void GameInfo::setOldFactionsOnly( Bool oldFactionsOnly ) { m_oldFactionsread it here, so none of them has to remember. The host's pick is kept, not cleared - take thebot back out and it is still there. */Int GameInfo::getPeaceTime( void ) const { return hasAIPlayers() ? 0 : m_peaceTime; }+Bool GameInfo::getUnitLimit( void ) const { return m_unitLimit; }AsciiString GameInfoToAsciiString( const GameInfo *game );Bool ParseAsciiStringToGameInfo( GameInfo *game, AsciiString options );diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex c59cc693b..34a1a4db2 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -1931,6 +1931,18 @@ Int parsePeaceTime(char *args[], int num)return 1;}+/* -unitlimit: turn the lobby's unit limit on for an -autoskirmish run. The check box lives in the+ lobby settings page and an unattended run has no lobby, so a measurement of what the cap does to+ a match, or a replay check of it, needs this. Cleared for a network game, like -peacetime. */+Int parseUnitLimit(char *args[], int num)+{+ if (TheWritableGlobalData)+ {+ TheWritableGlobalData->m_unitLimit = TRUE;+ }+ return 1;+}+/* -slowframe <ms> lowers the bar a logic frame has to clear before it logs its own breakdown.The default of 20ms is a stutter hunt: it catches the frames a player would notice. Chasing a@@ -2295,6 +2307,7 @@ static CommandLineParam params[] ={ "-slowframe", parseSlowFrame },{ "-teams", parseTeams },{ "-peacetime", parsePeaceTime },+ { "-unitlimit", parseUnitLimit },{ "-aislice", parseAISlice },{ "-noflowpath", parseNoFlowPath },{ "-nolanes", parseNoLanePath },diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex f07c0213d..7e20d1135 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -691,6 +691,7 @@ GlobalData::GlobalData()m_autoSkirmishAIStateOdd = 0; // 0 = not set: every slot plays at -aidiffm_autoSkirmishTeams = 0; // 0 = not set: every slot fights every other slotm_peaceTime = 0; // no truce unless -peacetime asks for one+ m_unitLimit = FALSE; // no unit limit unless -unitlimit asks for onem_autoSkirmishObserver = FALSE;m_headless = FALSE;m_maxGameFrames = 0; // run until the match endsdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex 720c198d5..fea0545dd 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -2992,8 +2992,59 @@ Int SuperweaponBuildCap( Int restriction, const AsciiString &playerTemplateName//=============================================================================// Make sure that building another of this unit/structure/object won't exceed MaxSimultaneousOfType()+Int UnitLimitPerPlayer( Int nonObserverPlayers )+{+ return nonObserverPlayers > 1 ? UNIT_LIMIT_TOTAL / nonObserverPlayers : UNIT_LIMIT_TOTAL;+}++//=============================================================================+/* What the unit limit counts: infantry, vehicles and aircraft. A structure is not a unit, and+ neither is a drone or a projectile - those arrive with their owner or out of a weapon, nobody+ queued them, and they should not eat the share a player spends. */+static Bool isUnitTowardCap( const ThingTemplate *thing )+{+ if ( thing->isKindOf( KINDOF_STRUCTURE ) || thing->isKindOf( KINDOF_DRONE ) || thing->isKindOf( KINDOF_PROJECTILE ) )+ return FALSE;++ return thing->isKindOf( KINDOF_INFANTRY ) || thing->isKindOf( KINDOF_VEHICLE ) || thing->isKindOf( KINDOF_AIRCRAFT );+}++// one object: itself if it is a unit, and whatever units it has queued, however many each entry makes+static void countUnitTowardCap( Object *obj, void *userData )+{+ Int *count = (Int *)userData;+ if ( !obj->isEffectivelyDead() && isUnitTowardCap( obj->getTemplate() ) )+ ++(*count);++ ProductionUpdateInterface *production = ProductionUpdate::getProductionUpdateInterfaceFromObject( obj );+ if ( production == NULL )+ return;++ for ( const ProductionEntry *entry = production->firstProduction(); entry; entry = production->nextProduction( entry ) )+ {+ const ThingTemplate *unit = entry->getProductionObject();+ if ( entry->getProductionType() == PRODUCTION_UNIT && unit && isUnitTowardCap( unit ) )+ *count += entry->getProductionQuantityRemaining();+ }+}++Int Player::countUnitsTowardCap( void ) const+{+ Int count = 0;+ iterateObjects( countUnitTowardCap, &count );+ return count;+}++//=============================================================================Bool Player::canBuildMoreOfType( const ThingTemplate *whatToBuild ) const{+ // the lobby's unit limit: a queue entry is refused once what stands and what is queued fills the+ // share. Everything that decides whether a unit may be built comes through here - the command+ // bar, the production queue and the computer players' build lists+ const UnsignedInt unitCap = TheGameLogic ? TheGameLogic->getUnitCap() : 0;+ if ( unitCap > 0 && isUnitTowardCap( whatToBuild ) && (UnsignedInt)countUnitsTowardCap() >= unitCap )+ return false;+// make sure we're not maxed out for this type of unit.UnsignedInt maxSimultaneousOfType = whatToBuild->getMaxSimultaneousOfType();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cppindex 6e00b7b18..2be400b5e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp@@ -41,6 +41,7 @@#include "GameClient/KeyDefs.h"#include "GameClient/GameWindowManager.h"#include "GameClient/GadgetListBox.h"+#include "GameClient/GadgetCheckBox.h"#include "GameClient/GadgetComboBox.h"#include "GameClient/GadgetTextEntry.h"#include "GameClient/GadgetStaticText.h"@@ -120,6 +121,7 @@ static NameKeyType buttonSelectMapID = NAMEKEY_INVALID;static NameKeyType comboBoxSuperweaponsID = NAMEKEY_INVALID;static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID;static NameKeyType comboBoxPeaceTimeID = NAMEKEY_INVALID;+static NameKeyType checkBoxUnitLimitID = NAMEKEY_INVALID;static NameKeyType windowMapID = NAMEKEY_INVALID;// Window Pointers ------------------------------------------------------------------------static GameWindow *parentLanGameOptions = NULL;@@ -132,6 +134,7 @@ static GameWindow *textEntryMapDisplay = NULL;static GameWindow *comboBoxSuperweapons = NULL;static GameWindow *comboBoxStartingCash = NULL;static GameWindow *comboBoxPeaceTime = NULL;+static GameWindow *checkBoxUnitLimit = NULL;static GameWindow *windowMap = NULL;static GameWindow *comboBoxPlayer[MAX_SLOTS] = {NULL,NULL,NULL,NULL,@@ -660,6 +663,24 @@ static void handlePeaceTimeSelection()}}+static void handleUnitLimitSelection()+{+ LANGameInfo *myGame = TheLAN->GetMyGame();++ // setting the box from the host's options clicks it too; only a real change is worth a new options string+ if (myGame == NULL || checkBoxUnitLimit == NULL || myGame->getUnitLimit() == GadgetCheckBoxIsChecked( checkBoxUnitLimit ))+ return;++ myGame->setUnitLimit( GadgetCheckBoxIsChecked( checkBoxUnitLimit ) );+ myGame->resetAccepted();++ if (myGame->amIHost() && !s_isIniting)+ {+ TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);+ lanUpdateSlotList(); // Update the accepted button UI+ }+}+static void handleSuperweaponSelection(){LANGameInfo *myGame = TheLAN->GetMyGame();@@ -708,6 +729,7 @@ void InitLanGameGadgets( void )comboBoxSuperweaponsID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ComboBoxSuperweapons" ) );comboBoxStartingCashID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ComboBoxStartingCash" ) );comboBoxPeaceTimeID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ComboBoxPeaceTime" ) );+ checkBoxUnitLimitID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:CheckBoxUnitLimit" ) );windowMapID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:MapWindow" ) );// Initialize the pointers to our gadgets@@ -741,6 +763,11 @@ void InitLanGameGadgets( void )DEBUG_ASSERTCRASH(comboBoxPeaceTime, ("Could not find the comboBoxPeaceTime"));if (comboBoxPeaceTime)PopulatePeaceTimeComboBox(comboBoxPeaceTime, TheLAN->GetMyGame(), TheLAN->AmIHost());+ // the fork's own control too, and missing is survivable the same way+ checkBoxUnitLimit = TheWindowManager->winGetWindowFromId( parentLanGameOptions, checkBoxUnitLimitID );+ DEBUG_ASSERTCRASH(checkBoxUnitLimit, ("Could not find the checkBoxUnitLimit"));+ if (checkBoxUnitLimit)+ UpdateUnitLimitCheckBox(checkBoxUnitLimit, TheLAN->GetMyGame(), TheLAN->AmIHost());windowMap = TheWindowManager->winGetWindowFromId( parentLanGameOptions,windowMapID );DEBUG_ASSERTCRASH(windowMap, ("Could not find the LanGameOptionsMenu.wnd:MapWindow" ));@@ -843,6 +870,7 @@ void DeinitLanGameGadgets( void )comboBoxSuperweapons = NULL;comboBoxStartingCash = NULL;comboBoxPeaceTime = NULL;+ checkBoxUnitLimit = NULL;windowMap = NULL;for (Int i = 0; i < MAX_SLOTS; i++){@@ -898,6 +926,7 @@ void LanGameOptionsMenuInit( WindowLayout *layout, void *userData )game->setMap( pref.getPreferredMap() );game->setStartingCash( pref.getStartingCash() );game->setSuperweaponRestriction( pref.getSuperweaponRestriction() );+ game->setUnitLimit( pref.getInt( "UnitLimit", 0 ) != 0 );AsciiString lowerMap = pref.getPreferredMap();lowerMap.toLower();std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);@@ -1017,6 +1046,8 @@ void updateGameOptions( void )if (comboBoxPeaceTime)UpdatePeaceTimeComboBox( comboBoxPeaceTime, theGame, TheLAN->AmIHost() );+ if (checkBoxUnitLimit)+ UpdateUnitLimitCheckBox( checkBoxUnitLimit, theGame, TheLAN->AmIHost() );}}@@ -1247,6 +1278,12 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt mGameWindow *control = (GameWindow *)mData1;Int controlID = control->winGetWindowId();+ if ( controlID == checkBoxUnitLimitID )+ {+ handleUnitLimitSelection();+ break;+ }+if ( LobbyTabClicked( (NameKeyType)controlID ) )break;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cppindex 0d7af364f..4ca45c5ee 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp@@ -120,6 +120,7 @@ static NameKeyType sliderGameSpeedID = NAMEKEY_INVALID;static NameKeyType staticTextGameSpeedID = NAMEKEY_INVALID;static NameKeyType comboBoxSuperweaponsID = NAMEKEY_INVALID;static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID;+static NameKeyType checkBoxUnitLimitID = NAMEKEY_INVALID;// Window Pointers ------------------------------------------------------------------------static GameWindow *staticTextGameSpeed = NULL;@@ -133,6 +134,7 @@ static GameWindow *windowMap = NULL;static GameWindow *textEntryPlayerName = NULL;static GameWindow *comboBoxSuperweapons = NULL;static GameWindow *comboBoxStartingCash = NULL;+static GameWindow *checkBoxUnitLimit = NULL;static GameWindow *comboBoxPlayer[MAX_SLOTS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };@@ -363,6 +365,7 @@ Bool SkirmishPreferences::write(void)setStartingCash( TheSkirmishGameInfo->getStartingCash() );setSuperweaponRestriction( TheSkirmishGameInfo->getSuperweaponRestriction() );+ setInt( "UnitLimit", TheSkirmishGameInfo->getUnitLimit() ? 1 : 0 );setSlotList();@@ -1081,6 +1084,7 @@ void InitSkirmishGameGadgets( void )staticTextGameSpeedID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:StaticTextGameSpeed" ) );comboBoxSuperweaponsID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:ComboBoxSuperweapons" ) );comboBoxStartingCashID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:ComboBoxStartingCash" ) );+ checkBoxUnitLimitID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:CheckBoxUnitLimit" ) );// Initialize the pointers to our gadgetsparentSkirmishGameOptions = TheWindowManager->winGetWindowFromId( NULL, parentSkirmishGameOptionsID );@@ -1104,6 +1108,11 @@ void InitSkirmishGameGadgets( void )comboBoxStartingCash = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, comboBoxStartingCashID );DEBUG_ASSERTCRASH(comboBoxStartingCash, ("Could not find the comboBoxStartingCash"));PopulateStartingCashComboBox(comboBoxStartingCash, TheSkirmishGameInfo );+ // the fork's own control; a stale Run/Window has a layout without it, and that is survivable+ checkBoxUnitLimit = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, checkBoxUnitLimitID );+ DEBUG_ASSERTCRASH(checkBoxUnitLimit, ("Could not find the checkBoxUnitLimit"));+ if ( checkBoxUnitLimit )+ UpdateUnitLimitCheckBox( checkBoxUnitLimit, TheSkirmishGameInfo, TRUE );textEntryPlayerNameID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:TextEntryPlayerName" ) );textEntryPlayerName = TheWindowManager->winGetWindowFromId( NULL, textEntryPlayerNameID );@@ -1276,6 +1285,8 @@ void updateSkirmishGameOptions( void )if ( comboBoxSuperweapons )UpdateSuperweaponComboBox( comboBoxSuperweapons, TheSkirmishGameInfo, TRUE );+ if ( checkBoxUnitLimit )+ UpdateUnitLimitCheckBox( checkBoxUnitLimit, TheSkirmishGameInfo, TRUE );Int itemCount = GadgetComboBoxGetLength(comboBoxStartingCash);for ( Int index = 0; index < itemCount; index++ ){@@ -1359,6 +1370,7 @@ void SkirmishGameOptionsMenuInit( WindowLayout *layout, void *userData )TheSkirmishGameInfo->setStartingCash( prefs.getStartingCash() );TheSkirmishGameInfo->setSuperweaponRestriction( prefs.getSuperweaponRestriction() );+ TheSkirmishGameInfo->setUnitLimit( prefs.getInt( "UnitLimit", 0 ) != 0 );TheSkirmishGameInfo->setMap(prefs.getPreferredMap());const MapMetaData *md = TheMapCache->findMap(TheSkirmishGameInfo->getMap());@@ -1641,6 +1653,11 @@ WindowMsgHandledType SkirmishGameOptionsMenuSystem( GameWindow *window, Unsigned/// static NameKeyType buttonResetFPSID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:ButtonResetFPS" ) );if(buttonPushed)break;+ if ( controlID == checkBoxUnitLimitID )+ {+ TheSkirmishGameInfo->setUnitLimit( GadgetCheckBoxIsChecked( control ) );+ break;+ }if ( LobbyTabClicked( (NameKeyType)controlID ) )break;if ( controlID == buttonExitID )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cppindex 3ccc58674..340cbc459 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp@@ -204,6 +204,7 @@ static NameKeyType comboBoxSuperweaponsID = NAMEKEY_INVALID;static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID;static NameKeyType comboBoxPeaceTimeID = NAMEKEY_INVALID;static NameKeyType checkBoxLimitArmiesID = NAMEKEY_INVALID;+static NameKeyType checkBoxUnitLimitID = NAMEKEY_INVALID;// Window Pointers ------------------------------------------------------------------------static GameWindow *parentWOLGameSetup = NULL;@@ -219,6 +220,7 @@ static GameWindow *comboBoxSuperweapons = NULL;static GameWindow *comboBoxStartingCash = NULL;static GameWindow *comboBoxPeaceTime = NULL;static GameWindow *checkBoxLimitArmies = NULL;+static GameWindow *checkBoxUnitLimit = NULL;static GameWindow *comboBoxPlayer[MAX_SLOTS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };@@ -336,6 +338,7 @@ static void savePlayerInfo( void )pref.setSuperweaponRestriction( TheGameSpyGame->getSuperweaponRestriction() );pref.setStartingCash( TheGameSpyGame->getStartingCash() );pref.setInt( "PeaceTime", TheGameSpyGame->getPeaceTime() );+ pref.setInt( "UnitLimit", TheGameSpyGame->getUnitLimit() ? 1 : 0 );}pref.write();}@@ -806,6 +809,24 @@ static Bool superweaponIsTheHostsToPick( void )return TheGameSpyGame && TheGameSpyGame->amIHost() && !TheGameSpyGame->getUseStats();}+static void handleUnitLimitSelection()+{+ GameInfo *myGame = TheGameSpyInfo->getCurrentStagingRoom();++ // setting the box from the host's options clicks it too; only a real change is worth a new options string+ if (myGame == NULL || checkBoxUnitLimit == NULL || myGame->getUnitLimit() == GadgetCheckBoxIsChecked( checkBoxUnitLimit ))+ return;++ myGame->setUnitLimit( GadgetCheckBoxIsChecked( checkBoxUnitLimit ) );+ myGame->resetAccepted();++ if (myGame->amIHost())+ {+ TheGameSpyInfo->setGameOptions();+ WOLDisplaySlotList();// Update the accepted button UI+ }+}+static void handlePeaceTimeSelection(){GameInfo *myGame = TheGameSpyInfo->getCurrentStagingRoom();@@ -1075,6 +1096,8 @@ void WOLDisplayGameOptions( void )// this out of the same recursion the two above are guarding againstif ( comboBoxPeaceTime )UpdatePeaceTimeComboBox( comboBoxPeaceTime, theGame, peaceTimeIsTheHostsToPick() );+ if ( checkBoxUnitLimit )+ UpdateUnitLimitCheckBox( checkBoxUnitLimit, theGame, superweaponIsTheHostsToPick() );}@@ -1162,6 +1185,7 @@ void InitWOLGameGadgets( void )comboBoxStartingCashID = TheNameKeyGenerator->nameToKey(AsciiString("GameSpyGameOptionsMenu.wnd:ComboBoxStartingCash"));comboBoxPeaceTimeID = TheNameKeyGenerator->nameToKey(AsciiString("GameSpyGameOptionsMenu.wnd:ComboBoxPeaceTime"));checkBoxLimitArmiesID = TheNameKeyGenerator->nameToKey(AsciiString("GameSpyGameOptionsMenu.wnd:CheckBoxLimitArmies"));+ checkBoxUnitLimitID = TheNameKeyGenerator->nameToKey(AsciiString("GameSpyGameOptionsMenu.wnd:CheckBoxUnitLimit"));windowMapSelectMapID = TheNameKeyGenerator->nameToKey(AsciiString("WOLMapSelectMenu.wnd:WinMapPreview"));NameKeyType staticTextTitleID = NAMEKEY("GameSpyGameOptionsMenu.wnd:StaticTextGameName");@@ -1191,6 +1215,11 @@ void InitWOLGameGadgets( void )DEBUG_ASSERTCRASH(comboBoxPeaceTime, ("Could not find the GameSpyGameOptionsMenu.wnd:ComboBoxPeaceTime" ));if ( comboBoxPeaceTime )PopulatePeaceTimeComboBox( comboBoxPeaceTime, TheGameSpyGame, peaceTimeIsTheHostsToPick() );+ // the fork's own control, on the same terms as the superweapon rule: the host's, and never in a stats game+ checkBoxUnitLimit = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, checkBoxUnitLimitID );+ DEBUG_ASSERTCRASH(checkBoxUnitLimit, ("Could not find the GameSpyGameOptionsMenu.wnd:CheckBoxUnitLimit" ));+ if ( checkBoxUnitLimit )+ UpdateUnitLimitCheckBox( checkBoxUnitLimit, TheGameSpyGame, superweaponIsTheHostsToPick() );checkBoxLimitArmies = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, checkBoxLimitArmiesID );DEBUG_ASSERTCRASH(windowMap, ("Could not find the GameSpyGameOptionsMenu.wnd:CheckBoxLimitArmies" ));@@ -1345,6 +1374,7 @@ void DeinitWOLGameGadgets( void )comboBoxSuperweapons = NULL;comboBoxStartingCash = NULL;comboBoxPeaceTime = NULL;+ checkBoxUnitLimit = NULL;// GameWindow *staticTextTitle = NULL;for (Int i = 0; i < MAX_SLOTS; i++)@@ -1441,6 +1471,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData )game->setStartingCash( isUsingStats? TheMultiplayerSettings->getDefaultStartingMoney() : customPref.getStartingCash() );game->setSuperweaponRestriction( isUsingStats? 0 : customPref.getSuperweaponRestriction() );game->setPeaceTime( isUsingStats? 0 : customPref.getInt( "PeaceTime", 0 ) );+ game->setUnitLimit( !isUsingStats && customPref.getInt( "UnitLimit", 0 ) != 0 );if (isUsingStats)game->setOldFactionsOnly( 0 );@@ -2745,6 +2776,12 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msgInt controlID = control->winGetWindowId();static NameKeyType buttonCommunicatorID = NAMEKEY("GameSpyGameOptionsMenu.wnd:ButtonCommunicator");+ if ( controlID == checkBoxUnitLimitID )+ {+ handleUnitLimitSelection();+ break;+ }+if ( LobbyTabClicked( (NameKeyType)controlID ) )break;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 0c3cd853e..4d5856a45 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -7271,6 +7271,17 @@ void InGameUI::drawHudOverlay( void )REAL_TO_INT( m_hudLogicHz + 0.5f ), REAL_TO_INT( m_hudFps + 0.5f ),TheDisplay->getRendererName() );+ // the lobby's unit limit, as this player's own share and not the match total: what stands and+ // what is queued, against the number the production queue refuses at+ const UnsignedInt unitCap = TheGameLogic->getUnitCap();+ const Player *localPlayer = ThePlayerList ? ThePlayerList->getLocalPlayer() : NULL;+ if( unitCap > 0 && localPlayer && !localPlayer->isPlayerObserver() )+ {+ UnicodeString units;+ units.format( L" %d/%d units", localPlayer->countUnitsTowardCap(), unitCap );+ text.concat( units );+ }+if( m_hudDisplayString == NULL ){// bold at a small point size, because this plate is read at a glance rather than readdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex 444f9017b..68ca6dfd3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -236,6 +236,7 @@ GameLogic::GameLogic( void )m_gameMode = GAME_NONE;m_rankLevelLimit = 1000;m_peaceTimeEndFrame = 0;+ m_unitCap = 0;m_gamePaused = FALSE;m_inputEnabledMemory = TRUE;m_mouseVisibleMemory = TRUE;@@ -1175,6 +1176,7 @@ void GameLogic::startNewGame( Bool loadingSaveGame )TheWritableGlobalData->m_groupDrill = 0; // -groupdrillTheWritableGlobalData->m_scenarioFile.clear(); // -scenarioTheWritableGlobalData->m_peaceTime = 0; // -peacetime, and the host's options string is read below+ TheWritableGlobalData->m_unitLimit = FALSE; // -unitlimit, the same}m_showBehindBuildingMarkers = TRUE;@@ -1227,14 +1229,23 @@ void GameLogic::startNewGame( Bool loadingSaveGame ){m_superweaponRestriction = TheGameInfo->getSuperweaponRestriction();m_peaceTimeEndFrame = TheGameInfo->getPeaceTime() * 60 * LOGICFRAMES_PER_SECOND;+ m_unitCap = TheGameInfo->getUnitLimit()+ ? (UnsignedInt)UnitLimitPerPlayer( TheGameInfo->getNumNonObserverPlayers() ) : 0;}else{// ??? Apparently this is legit? Oh well, use defaultsm_superweaponRestriction = 0;m_peaceTimeEndFrame = 0;+ m_unitCap = 0;}+ /* -unitlimit is the lobby's check box for an -autoskirmish run, which has no lobby to tick it+ in. A network game reads the host's options string instead, and the switch is cleared for+ one above. */+ if ( TheGlobalData->m_unitLimit && TheGameInfo )+ m_unitCap = (UnsignedInt)UnitLimitPerPlayer( TheGameInfo->getNumNonObserverPlayers() );+/* -peacetime is the one way past the no-computer-players rule in GameInfo::getPeaceTime(), andit is deliberate: an unattended run is nothing but bots, so without this there would be noway to watch what the truce does to a match or to prove a change to it still replays. No@@ -5532,13 +5543,14 @@ void GameLogic::prepareLogicForObjectLoad( void )* 11: objects are written back to front, so that loading - which prepends each one - rebuilds* the list in the order it was saved in. Version 10 and earlier are reversed on load.* 12: xfer m_peaceTimeEndFrame+ * 13: xfer m_unitCap*/// ------------------------------------------------------------------------------------------------void GameLogic::xfer( Xfer *xfer ){// version- const XferVersion currentVersion = 12;+ const XferVersion currentVersion = 13;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -5894,6 +5906,15 @@ void GameLogic::xfer( Xfer *xfer ){m_peaceTimeEndFrame = 0;}++ if ( version >= 13 )+ {+ xfer->xferUnsignedInt( &m_unitCap );+ }+ else if ( xfer->getXferMode() == XFER_LOAD )+ {+ m_unitCap = 0;+ }} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cppindex 2a4d9ae09..fce5f16e4 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp@@ -34,6 +34,7 @@#include "Common/NameKeyGenerator.h"#include "Common/MultiplayerSettings.h"+#include "GameClient/GadgetCheckBox.h"#include "GameClient/GadgetListBox.h"#include "GameClient/GadgetComboBox.h"#include "GameClient/GadgetTextEntry.h"@@ -533,6 +534,15 @@ Int SuperweaponRestrictionFromComboBox(GameWindow *comboBox)return (Int)GadgetComboBoxGetItemData(comboBox, selIndex);}+void UpdateUnitLimitCheckBox(GameWindow *checkBox, GameInfo *myGame, Bool hostMayEdit)+{+ checkBox->winEnable( hostMayEdit );++ const Bool unitLimit = myGame->getUnitLimit();+ if ( GadgetCheckBoxIsChecked( checkBox ) != unitLimit )+ GadgetCheckBoxSetChecked( checkBox, unitLimit );+}+// -----------------------------------------------------------------------------// The lobby tab strip.static GameWindow *theLobbySettingsPage = NULL;diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cppindex fccadaa83..c201b30de 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp@@ -394,6 +394,7 @@ void GameInfo::reset( void )m_superweaponRestriction = 0;m_startingCash = TheGlobalData->m_defaultStartingCash;m_peaceTime = 0;+ m_unitLimit = FALSE;//@@ -805,6 +806,11 @@ void GameInfo::setPeaceTime( Int minutes )m_peaceTime = minutes;}+void GameInfo::setUnitLimit( Bool unitLimit )+{+ m_unitLimit = unitLimit;+}+Bool GameInfo::isColorTaken(Int colorIdx, Int slotToIgnore ) const{for (Int i=0; i<MAX_SLOTS; ++i)@@ -1024,9 +1030,10 @@ AsciiString GameInfoToAsciiString( const GameInfo *game )}AsciiString optionsString;- optionsString.format("US=%d;M=%2.2x%s;MC=%X;MS=%d;SD=%d;C=%d;SR=%u;SC=%u;O=%c;PT=%d;", game->getUseStats(), game->getMapContentsMask(), newMapName.str(),+ optionsString.format("US=%d;M=%2.2x%s;MC=%X;MS=%d;SD=%d;C=%d;SR=%u;SC=%u;O=%c;PT=%d;UL=%d;", game->getUseStats(), game->getMapContentsMask(), newMapName.str(),game->getMapCRC(), game->getMapSize(), game->getSeed(), game->getCRCInterval(), game->getSuperweaponRestriction(),- game->getStartingCash().countMoney(), game->oldFactionsOnly() ? 'Y' : 'N', game->getPeaceTime() );+ game->getStartingCash().countMoney(), game->oldFactionsOnly() ? 'Y' : 'N', game->getPeaceTime(),+ game->getUnitLimit() ? 1 : 0 );//add player info for each slotoptionsString.concat(slotListID);@@ -1113,6 +1120,7 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)Money startingCash = TheGlobalData->m_defaultStartingCash;UnsignedShort restriction = 0; // Always the defaultInt peaceTime = 0; // absent from the string = off, so an older host is still joinable+ Bool unitLimit = FALSE; // the sameBool sawMap, sawMapCRC, sawMapSize, sawSeed, sawSlotlist, sawUseStats, sawSuperweaponRestriction, sawStartingCash, sawOldFactions;sawMap = sawMapCRC = sawMapSize = sawSeed = sawSlotlist = sawUseStats = sawSuperweaponRestriction = sawStartingCash = sawOldFactions = FALSE;@@ -1218,6 +1226,10 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)else if (key.compare("PT") == 0 ){peaceTime = atoi(val.str());+ }+ else if (key.compare("UL") == 0 )+ {+ unitLimit = atoi(val.str()) != 0;}else if (key.getLength() == 1 && *key.str() == slotListID){@@ -1565,6 +1577,7 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)game->setStartingCash( startingCash );game->setOldFactionsOnly( oldFactionsOnly );game->setPeaceTime( peaceTime );+ game->setUnitLimit( unitLimit );return true;}@@ -1591,7 +1604,7 @@ void SkirmishGameInfo::crc( Xfer *xfer )// ------------------------------------------------------------------------------------------------void SkirmishGameInfo::xfer( Xfer *xfer ){- const XferVersion currentVersion = 5; // 5 adds m_peaceTime+ const XferVersion currentVersion = 6; // 5 adds m_peaceTime, 6 m_unitLimitXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -1698,6 +1711,15 @@ void SkirmishGameInfo::xfer( Xfer *xfer )m_peaceTime = 0;}+ if ( version >= 6 )+ {+ xfer->xferBool( &m_unitLimit );+ }+ else if ( xfer->getXferMode() == XFER_LOAD )+ {+ m_unitLimit = FALSE;+ }+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cppindex c54c9b88e..ad91b61a5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp@@ -340,6 +340,7 @@ void LANAPI::OnGameStart( void ){pref["Map"] = AsciiStringToQuotedPrintable(m_currentGame->getMap());pref.setSuperweaponRestriction( m_currentGame->getSuperweaponRestriction() );+ pref.setInt( "UnitLimit", m_currentGame->getUnitLimit() ? 1 : 0 );pref.setStartingCash( m_currentGame->getStartingCash() );}pref.write();diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex f48af8461..006d18d99 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -991,6 +991,18 @@ TEST(force_fire_is_the_attack_key_and_nothing_else)CHECK( !CommandXlat_isForceAttackTargeting( false, true ) );}+/* Player.cpp: the lobby's unit limit is 840 units shared out by the players who are not watching. */+TEST(unit_limit_shares_840_between_the_players)+{+ CHECK_EQ( UnitLimitPerPlayer( 2 ), 420 );+ CHECK_EQ( UnitLimitPerPlayer( 3 ), 280 );+ CHECK_EQ( UnitLimitPerPlayer( 8 ), 105 );++ /* a lobby with nobody left in it is not a division by zero */+ CHECK_EQ( UnitLimitPerPlayer( 0 ), 840 );+ CHECK_EQ( UnitLimitPerPlayer( 1 ), 840 );+}+/* CommandXlat.cpp: a right drag spreads the selection along the line drawn, but only when there isa selection to spread and no GUI command already waiting for the click. */extern Bool Command_formationDragArmed( Bool setting, Bool haveMovableSelection,diff --git a/GeneralsMD/Code/Tools/lobbysettings_layout.py b/GeneralsMD/Code/Tools/lobbysettings_layout.pyindex d9f8c8783..5c634168b 100644--- a/GeneralsMD/Code/Tools/lobbysettings_layout.py+++ b/GeneralsMD/Code/Tools/lobbysettings_layout.py@@ -118,6 +118,11 @@ PAGE = "PageLobbySettings"# in the LAN layout than in the other two.SUPERWEAPON_CHECKBOX = ("CheckboxLimitSuperweapons", "CheckBoxLimitSuperweapons")+# The unit limit check box was put on all three pages by hand after the pages were generated, so+# build() does not make it; the selfcheck still wants it on every page, because the menu code names it+# and a missing control is as silent as the rest.+UNIT_LIMIT_CHECKBOX = "CheckBoxUnitLimit"+# Cloned from a control that is already on the screen, so they inherit its images and font. A# layout gets the ones its own page has a row for: the skirmish lobby has no peace time, because a# skirmish is played against computer players and those do not honour a truce.@@ -138,6 +143,8 @@ STRINGS = ["GUI:SuperweaponsLimit","GUI:SuperweaponsNone","TOOLTIP:Superweapons",+ "GUI:UnitLimit",+ "TOOLTIP:UnitLimit",]@@ -276,6 +283,12 @@ def selfcheck():elif page is not None and control not in list(page.walk()):problems.append("%s.wnd: %s is not on the settings page" % (menu, name))+ unit_limit = layout.find(UNIT_LIMIT_CHECKBOX)+ if unit_limit is None:+ problems.append("%s.wnd has no %s" % (menu, UNIT_LIMIT_CHECKBOX))+ elif page is not None and unit_limit not in list(page.walk()):+ problems.append("%s.wnd: %s is not on the settings page" % (menu, UNIT_LIMIT_CHECKBOX))+for name in SUPERWEAPON_CHECKBOX:if layout.find(name) is not None:problems.append("%s.wnd still carries %s; the combo box replaced it"