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): handicap column sets each seat's unit health
Olcay Seygan928a278788b3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8fa664359..6d5ebb421 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,12 @@ found and fixed, EA's own, not port damage.**---+## A handicap for every seat++- The skirmish, LAN and online rooms have a Handicap box at the end of every seat's row, from 100% down to 10%. At 50% every unit that player fields has half its health: his Crusader reads 240 where the same tank reads 480 across the map. His buildings stay at full health.+- You pick for your own seat and the host picks for the computer seats, the way colour and team already work. The pick is in the replay and the saved game, and a room that leaves the column at 100% plays and replays as it did.+- Promotions and armour research still come on top, at the seat's share: an Elite Paladin with Composite Armor reads 364 at 50% against 728 at 100%. A vehicle stolen from a handicapped player moves to its new owner's column and keeps its share of health, so a Humvee at 80 of 120 becomes 160 of 240 with no damage dealt and no repair given.+## Computer players earn double- A computer player in a skirmish or a network match now earns double, on every difficulty. A truckload worth 75 banks 150, and the 1000 for capturing an oil derrick is 2000. It counts everything the computer makes by playing: supply docks, oil derricks and other tech buildings, black markets, drop zones, hackers, bounties, crates, salvage and stolen cash. On one generated map, two Easy computers earned 25,800 and 28,200 in six minutes and forty seconds and now earn 51,600 and 56,400. Two Hard ones on the same seed went from 22,800 and 24,825 to 74,800 and 81,090, because Hard spends the extra money on more income: one of them built four supply centers and two drop zones where it used to build two and one.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 267df68e6..eabd1b96e 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -312,6 +312,7 @@ Data/Scenarios/glowmicrowave.txtData/Scenarios/gpu1m_battle.txtData/Scenarios/guardradius.txtData/Scenarios/gunfx.txt+Data/Scenarios/handicap.txtData/Scenarios/headlights.txtData/Scenarios/helislide.txtData/Scenarios/helitypes.txtdiff --git a/GeneralsMD/Code/Data/Scenarios/handicap.txt b/GeneralsMD/Code/Data/Scenarios/handicap.txtnew file mode 100644index 000000000..bfc6b3984--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/handicap.txt@@ -0,0 +1,103 @@+# The lobby's handicap, read off the tallies with and without it. Run the same line twice, the second+# time without -handicap, and seat 0's units read half their max health while its power plant and+# seat 1's own stock stay the same.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionAmerica -seed 7 -maxframes 6000+# -handicap 0 50 -scenario handicap -logPrefix handicap_+#+# Each seat's stock stands at its own start, out of reach of the other. Crusader: bare, then 100 more+# from Composite Armor. Paladin: made elite first, then the same armor, whose addition carries both+# multipliers. The Crusader spawned after the research is a new unit under a finished upgrade.+#+# The Humvee and the Tomahawk are the captures, staged on open ground in the east: a few Rebels wear+# each vehicle down until a Hijacker of theirs takes it. A tally every half second shows the share of+# health carried across the capture while the max moves to the new owner's factor.+#+# The Battle Bus takes Overlord fire until its second life, an absolute max health in the data.++30 spawn 0 AmericaPowerPlant 1 start0:-200:-250+30 spawn 1 AmericaPowerPlant 1 start1:-200:-250+30 spawn 0 AmericaStrategyCenter 1 start0:250:-250+30 spawn 1 AmericaStrategyCenter 1 start1:250:-250+30 spawn 0 AmericaTankCrusader 1 start0:0:300+30 spawn 1 AmericaTankCrusader 1 start1:0:-300+30 spawn 0 AmericaTankPaladin 1 start0:80:300+30 spawn 1 AmericaTankPaladin 1 start1:80:-300+30 spawn 0 AmericaInfantryRanger 1 start0:160:300+30 spawn 1 AmericaInfantryRanger 1 start1:160:-300+40 tally 0 AmericaPowerPlant+40 tally 1 AmericaPowerPlant+40 tally 0 AmericaTankCrusader+40 tally 1 AmericaTankCrusader+40 tally 0 AmericaTankPaladin+40 tally 1 AmericaTankPaladin+40 tally 0 AmericaInfantryRanger+40 tally 1 AmericaInfantryRanger+50 rank 0 AmericaTankPaladin elite+50 rank 1 AmericaTankPaladin elite+60 tally 0 AmericaTankPaladin+60 tally 1 AmericaTankPaladin+70 shiftupgrade 0 AmericaStrategyCenter Upgrade_AmericaCompositeArmor+70 shiftupgrade 1 AmericaStrategyCenter Upgrade_AmericaCompositeArmor+2500 tally 0 AmericaTankCrusader+2500 tally 1 AmericaTankCrusader+2500 tally 0 AmericaTankPaladin+2500 tally 1 AmericaTankPaladin+2510 spawn 0 AmericaTankCrusader 1 start0:0:360+2510 spawn 1 AmericaTankCrusader 1 start1:0:-360+2520 tally 0 AmericaTankCrusader+2520 tally 1 AmericaTankCrusader++# seat 0's Humvee goes to seat 1+100 spawn 0 AmericaVehicleHumvee 1 2450 3650+100 spawn 1 GLAInfantryRebel 3 2570 3650 20+160 spawn 1 GLAInfantryHijacker 1 2480 3650+165 enter 1 GLAInfantryHijacker 0 AmericaVehicleHumvee+150 tally 0 AmericaVehicleHumvee+165 tally 0 AmericaVehicleHumvee+180 tally 0 AmericaVehicleHumvee+180 tally 1 AmericaVehicleHumvee+195 tally 0 AmericaVehicleHumvee+195 tally 1 AmericaVehicleHumvee+210 tally 0 AmericaVehicleHumvee+210 tally 1 AmericaVehicleHumvee+240 tally 1 AmericaVehicleHumvee+300 tally 1 AmericaVehicleHumvee++# seat 1's Tomahawk goes to seat 0+100 spawn 1 AmericaVehicleTomahawk 1 3000 3650+100 spawn 0 GLAInfantryRebel 3 3120 3650 20+160 spawn 0 GLAInfantryHijacker 1 3030 3650+165 enter 0 GLAInfantryHijacker 1 AmericaVehicleTomahawk+150 tally 1 AmericaVehicleTomahawk+165 tally 1 AmericaVehicleTomahawk+180 tally 1 AmericaVehicleTomahawk+180 tally 0 AmericaVehicleTomahawk+195 tally 1 AmericaVehicleTomahawk+195 tally 0 AmericaVehicleTomahawk+210 tally 1 AmericaVehicleTomahawk+210 tally 0 AmericaVehicleTomahawk+240 tally 0 AmericaVehicleTomahawk+300 tally 0 AmericaVehicleTomahawk++# seat 0's Battle Bus, into its second life+100 spawn 0 GLAVehicleBattleBus 1 1135 3696+100 spawn 1 ChinaTankOverlord 1 1290 3696+110 tally 0 GLAVehicleBattleBus*+120 tally 0 GLAVehicleBattleBus*+130 tally 0 GLAVehicleBattleBus*+140 tally 0 GLAVehicleBattleBus*+150 tally 0 GLAVehicleBattleBus*+160 tally 0 GLAVehicleBattleBus*+170 tally 0 GLAVehicleBattleBus*+180 tally 0 GLAVehicleBattleBus*+190 tally 0 GLAVehicleBattleBus*+200 tally 0 GLAVehicleBattleBus*+210 tally 0 GLAVehicleBattleBus*+220 tally 0 GLAVehicleBattleBus*+240 tally 0 GLAVehicleBattleBus*+260 tally 0 GLAVehicleBattleBus*+280 tally 0 GLAVehicleBattleBus*+300 tally 0 GLAVehicleBattleBus*diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 13b519500..cf8b3a201 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -687,6 +687,7 @@ public:Int m_autoSkirmishTakeoverSlot; ///< -takeover <slot>: only that seat is driverless and the AI plays the rest; -1 for every seatAsciiString m_autoSkirmishSide[ MAX_PLAYER_COUNT ]; ///< -side <slot> <faction>: name that slot's faction instead of drawing it from the seedInt m_autoSkirmishTeam[ MAX_PLAYER_COUNT ]; ///< -team <slot> <n>: that slot's team, -1 for none; AUTO_SKIRMISH_TEAM_UNSET leaves it to -teams+ Int m_autoSkirmishHandicap[ MAX_PLAYER_COUNT ]; ///< -handicap <slot> <percent>: that seat's lobby handicap, 100 for none; read only into the game slotAsciiString m_autoSkirmishSeatName[ MAX_PLAYER_COUNT ]; ///< -seatname <slot> <name>: what that seat is called instead of its difficultyInt m_autoSkirmishPersona[ MAX_PLAYER_COUNT ]; ///< -aipersona <slot> <name>: that AI seat's AIPersonality, -1 leaves it to the two belowInt m_autoSkirmishPersonaOdd; ///< -aipersona2 <name>: the odd seats' personality, -1 for the same as every seat'sdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/Handicap.h b/GeneralsMD/Code/GameEngine/Include/Common/Handicap.hindex b31e22b33..0220335cb 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Handicap.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Handicap.h@@ -76,6 +76,7 @@ public:{BUILDCOST,BUILDTIME,+ MAXHEALTH, // the lobby's handicap; set for GENERIC only, so a structure stays wholeHANDICAP_TYPE_COUNT};@@ -100,6 +101,9 @@ public:*/Real getHandicap(HandicapType t, const ThingTemplate *tmpl) const;+ /// the multiplier for anything that is not a building+ Real getGenericHandicap(HandicapType t) const { return m_handicaps[t][GENERIC]; }+protected:private:diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.hindex 59d2d50c1..14a543bd4 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h@@ -325,6 +325,8 @@ public:void setTemporaryTeam( Team* team ); ///< sets the unit's team BUT NOT its original teamPlayer* getControllingPlayer() const;+ Real getHandicapHealthFactor() const; ///< what the owner's lobby handicap makes of this object's max health+ void friend_ownerChangedHandicap( const Player *oldOwner ); ///< a new owner's factor, its share of health kept: no damage, no healRelationship getRelationship(const Object *that) const;Color getIndicatorColor() const;diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.hindex ee28c2a7f..3c9cdd1b4 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h@@ -128,6 +128,17 @@ void UpdateAIPersonaComboBoxes(GameInfo *myGame, GameWindow *comboPersona[]);Bool HandleAIPersonaSelection(GameInfo *myGame, GameWindow *comboPersona[], NameKeyType comboPersonaID[],NameKeyType controlID);+// The handicap column: one combo box a seat, 100 down to 10 percent with the value as item data.+// Whoever may change a seat's team may change its handicap, so UpdateHandicapComboBoxes, called after+// UpdateSlotList, copies the team box's enabled state. HandleHandicapSelection answers the new+// percent when the click was one of the boxes and is a change, 0 otherwise. The host's pick goes into+// the slot, unless the options string has no room for it; a guest's waits for the host's slot list.+void InitHandicapComboBoxes(GameWindow *parent, const char *layoutFilename,+ GameWindow *comboHandicap[], NameKeyType comboHandicapID[]);+void UpdateHandicapComboBoxes(GameInfo *myGame, GameWindow *comboHandicap[], GameWindow *comboTeam[]);+Int HandleHandicapSelection(GameInfo *myGame, GameWindow *comboHandicap[], NameKeyType comboHandicapID[],+ NameKeyType controlID);+// What a seat row shows beside its combo boxes: a bar and a swatch in the seat's colour, a swatch in// the team's colour (both framed like the check boxes), and in the network rooms a green card for// a player who is ready and a gold edge round the host's. All of it is drawn from the slot on everydiff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.hindex 6f07c21a9..57141bd79 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h@@ -91,6 +91,13 @@ Int PlayerTemplateFromPreference( const AsciiString &text );AsciiString PlayerTemplateSlotField( Int pick );Int PlayerTemplateFromSlotField( const AsciiString &field );+// The lobby's handicap column, in percent of a unit's max health.+enum+{+ HANDICAP_FULL = 100,+ HANDICAP_STEP = 10+};+// The lobby's income sharing: which earnings are split evenly between a player and every ally// still in the match. The values travel in the options string and in saves, so only append.enum IncomeSharing@@ -132,7 +139,10 @@ public:void setPlayerTemplate( Int playerTemplate ){ m_playerTemplate = playerTemplate;if (playerTemplate == PLAYERTEMPLATE_OBSERVER)+ {m_startPos = -1;+ m_handicap = HANDICAP_FULL;+ }}Int getPlayerTemplate( void ) const { return m_playerTemplate; }@@ -142,6 +152,9 @@ public:void setAIPersonality( Int persona ) { m_aiPersonality = persona; } ///< an AIPersonality; RANDOM stays RANDOM until the match startsInt getAIPersonality( void ) const { return m_aiPersonality; }+ void setHandicap( Int handicap ) { m_handicap = handicap; } ///< percent of max health this seat's units have, see IsValidHandicap+ Int getHandicap( void ) const { return m_handicap; }+inline void setName( UnicodeString name ) { m_name = name; }inline UnicodeString getName( void ) const { return m_name; }@@ -192,6 +205,7 @@ protected:Int m_playerTemplate; ///< PlayerTemplateInt m_teamNumber; ///< alliance, -1 for noneInt m_aiPersonality; ///< AIPersonality of an AI seat, AIPERSONA_NORMAL otherwise+ Int m_handicap; ///< percent of max health this seat's units have, HANDICAP_FULL for noneInt m_origColor; ///< color, or -1 for randomInt m_origStartPos; ///< start position, or -1 for randomInt m_origPlayerTemplate; ///< PlayerTemplate@@ -417,6 +431,18 @@ AsciiString GameInfoMapPathFromField( const AsciiString& field );AsciiString AIPersonaSlotField( Int persona );Int AIPersonaFromSlotField( const char *field );+// A seat's handicap is the last field of its slot entry, human or AI, written only when it is not+// HANDICAP_FULL, so every string without a pick stays the one it was. An AI seat writes its persona+// as ",0" when a handicap has to follow it. Absent, or a value the lobby does not offer, is full health.+Bool IsValidHandicap( Int handicap );+AsciiString HandicapSlotField( Int handicap );+Int HandicapFromSlotField( const char *field );++// A guest's "Handicap=<n>" request reaching the host. TRUE when the slot list has to go round again,+// which it does for a pick that does not fit in the options string as well: the guest's box has to+// come back to what the host kept.+Bool ApplyHandicapRequest( GameInfo *game, GameSlot *slot, Int handicap );+//// Three things every lobby - skirmish, LAN and online - has to agree on about a slot state, kept// here so that appending a rung to the enum above is one edit rather than a hunt through the menus.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex aca4ff421..bb588da30 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -2239,6 +2239,25 @@ Int parseTeam(char *args[], int num)return 1;}+/* -handicap <slot> <percent> gives one -autoskirmish or -netgame seat a lobby's handicap: 100, 90 ...+ 10 percent of max health on its units, anything else is refused, since the options string would+ read it back as 100 in the replay. It goes into the slot like a lobby's pick; a real lobby never+ looks at it, and every copy of a -netgame match has to be given the same line, as with -side. */+Int parseHandicap(char *args[], int num)+{+ if (TheWritableGlobalData && num > 2 && args[1] && args[2])+ {+ const Int slot = atoi(args[1]);+ const Int handicap = atoi(args[2]);+ if (slot >= 0 && slot < MAX_SLOTS && IsValidHandicap(handicap))+ TheWritableGlobalData->m_autoSkirmishHandicap[slot] = handicap;+ else+ DEBUG_LOG(("-handicap: slot %d at %d percent is no lobby's pick\n", slot, handicap));+ return 3;+ }+ return 1;+}+/* -seatname <slot> <name> calls one -autoskirmish seat by a name instead of its difficulty, the way aplayer's own name stands on his seat: a cup's bots by their entrants' names, or a long one to seethe director's score bar cut it. ASCII only; it is read before the game text is. */@@ -3038,6 +3057,7 @@ static CommandLineParam params[] ={ "-freecam", parseFreeCamera },{ "-side", parseSide },{ "-team", parseTeam },+ { "-handicap", parseHandicap },{ "-seatname", parseSeatName },{ "-takeover", parseTakeover },{ "-replay", parseReplay },diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex e804ef0f4..d04dd6971 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -779,6 +779,7 @@ static void startAutoSkirmish( Int numPlayersWanted )if (TheGlobalData->m_autoSkirmishTeam[ i ] != AUTO_SKIRMISH_TEAM_UNSET)teamNumber = TheGlobalData->m_autoSkirmishTeam[ i ];slot.setTeamNumber( teamNumber );+ slot.setHandicap( TheGlobalData->m_autoSkirmishHandicap[ i ] );TheSkirmishGameInfo->setSlot( i, slot );}TheSkirmishGameInfo->setLocalIP( TheSkirmishGameInfo->getSlot(0)->getIP() );diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex efc3afd3c..f40dfc48e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -1121,6 +1121,7 @@ GlobalData::GlobalData(){m_autoSkirmishSide[ slot ].clear(); // every faction still comes out of the seed unless -side names onem_autoSkirmishTeam[ slot ] = AUTO_SKIRMISH_TEAM_UNSET; // and every team out of -teams unless -team names one+ m_autoSkirmishHandicap[ slot ] = 100; // and every seat at full health unless -handicap names itm_autoSkirmishSeatName[ slot ].clear(); // and every computer seat is called by its difficulty unless -seatname names itm_autoSkirmishPersona[ slot ] = -1; // and plays the personality -aipersonaall or -aipersona2 gives it}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Handicap.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Handicap.cppindex da5091a8f..9c79b86bf 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Handicap.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Handicap.cpp@@ -73,6 +73,7 @@ void Handicap::readFromDict(const Dict* d){"BUILDCOST","BUILDTIME",+ "MAXHEALTH",// "FIREPOWER",// "ARMOR",// "GROUNDSPEED",diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex 58d4bd66f..a69c8722e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -4905,6 +4905,11 @@ void Player::crc( Xfer *xfer )// The bank, so an income or a refund that drifted is caught before it buys something.xfer->xferSnapshot( &m_money );+ // The lobby's handicap, only on a seat that has one, so every other replay keeps the CRC it has.+ Real healthHandicap = m_handicap.getGenericHandicap( Handicap::MAXHEALTH );+ if( healthHandicap != 1.0f )+ xfer->xferReal( &healthHandicap );+} // end crc// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cppindex 786f55ecd..f8f310ce7 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp@@ -916,6 +916,7 @@ void TeamPrototype::setControllingPlayer(Player *newController)if (oldController)oldController->removeTemplateCountMember(objIt.cur());newController->addTemplateCountMember(objIt.cur());+ objIt.cur()->friend_ownerChangedHandicap(oldController);}}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/EstablishConnectionsWindow.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/EstablishConnectionsWindow.cppindex 22d95d95e..4c879d92f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/EstablishConnectionsWindow.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/EstablishConnectionsWindow.cpp@@ -75,6 +75,7 @@ static const char *gadgetsToHide[] ="MapWindow","StaticTextGameName","StaticTextTeam",+ "StaticTextHandicap","StaticTextFaction","StaticTextColor","StaticTextPlayers",@@ -87,6 +88,7 @@ static const char *gadgetsToHide[] =static const char *perPlayerGadgetsToHide[] ={"ComboBoxTeam",+ "ComboBoxHandicap","ComboBoxColor","ComboBoxPlayerTemplate","ComboBoxAIPersona",diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cppindex 99df2c951..23df3d1ee 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp@@ -170,6 +170,13 @@ static NameKeyType comboBoxAIPersonaID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INNAMEKEY_INVALID,NAMEKEY_INVALID,NAMEKEY_INVALID,NAMEKEY_INVALID };+static GameWindow *comboBoxHandicap[MAX_SLOTS] = {NULL,NULL,NULL,NULL,+ NULL,NULL,NULL,NULL };+static NameKeyType comboBoxHandicapID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID };+//static GameWindow *buttonStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,// NULL,NULL,NULL,NULL };//@@ -461,6 +468,8 @@ void LANDisableButtons()comboBoxColor[i]->winEnable(false);comboBoxPlayerTemplate[i]->winEnable(false);comboBoxTeam[i]->winEnable(false);+ if (comboBoxHandicap[i])+ comboBoxHandicap[i]->winEnable(false);buttonAccept[i]->winEnable(false);buttonMapStartPosition[i]->winEnable(false);}@@ -682,6 +691,28 @@ static void handleTeamSelection(int index)}}+// HandleHandicapSelection has set the host's slot; the same round as a team pick from here+static void handleHandicapSelection(Int handicap)+{+ LANGameInfo *myGame = TheLAN->GetMyGame();+ myGame->resetAccepted();++ if (myGame->amIHost())+ {+ if (!s_isIniting)+ {+ TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);+ lanUpdateSlotList();+ }+ }+ else if (AreSlotListUpdatesEnabled())+ {+ AsciiString options;+ options.format("Handicap=%d", handicap);+ TheLAN->RequestGameOptions(options, true);+ }+}+static void handleStartingCashSelection(){LANGameInfo *myGame = TheLAN->GetMyGame();@@ -869,6 +900,7 @@ void lanUpdateSlotList( void )UpdateSlotList( TheLAN->GetMyGame(), comboBoxPlayer, comboBoxColor,comboBoxPlayerTemplate, comboBoxTeam, buttonAccept, buttonStart, buttonMapStartPosition);UpdateAIPersonaComboBoxes( TheLAN->GetMyGame(), comboBoxAIPersona );+ UpdateHandicapComboBoxes( TheLAN->GetMyGame(), comboBoxHandicap, comboBoxTeam );UpdateLobbySeatVisuals( TheLAN->GetMyGame() );updateMapStartSpots(TheLAN->GetMyGame(), buttonMapStartPosition);@@ -1040,6 +1072,7 @@ void InitLanGameGadgets( void )GadgetButtonSetEnabledColor(buttonAccept[0], acceptTrueColor );InitAIPersonaComboBoxes( parentLanGameOptions, "LanGameOptionsMenu.wnd", comboBoxAIPersona, comboBoxAIPersonaID );+ InitHandicapComboBoxes( parentLanGameOptions, "LanGameOptionsMenu.wnd", comboBoxHandicap, comboBoxHandicapID );InitLobbySeatVisuals( parentLanGameOptions, "LanGameOptionsMenu.wnd" );// the settings page and the chat log share one rectangle; this opens on the chat log@@ -1074,6 +1107,7 @@ void DeinitLanGameGadgets( void )comboBoxColor[i] = NULL;comboBoxPlayerTemplate[i] = NULL;comboBoxTeam[i] = NULL;+ comboBoxHandicap[i] = NULL;buttonAccept[i] = NULL;// buttonStartPosition[i] = NULL;buttonMapStartPosition[i] = NULL;@@ -1452,6 +1486,10 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt mlanUpdateSlotList();}}+ else if ( Int handicap = HandleHandicapSelection( myGame, comboBoxHandicap, comboBoxHandicapID, (NameKeyType)controlID ) )+ {+ handleHandicapSelection( handicap );+ }else{for (Int i = 0; i < MAX_SLOTS; i++)diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanMapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanMapSelectMenu.cppindex f762ec0fd..792c456d0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanMapSelectMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanMapSelectMenu.cpp@@ -81,6 +81,7 @@ static const char *gadgetsToHide[] =//"StaticTextTitle","StaticTextPlayers","StaticTextTeam",+ "StaticTextHandicap","StaticTextFaction","StaticTextColor","TextEntryMapDisplay",@@ -98,6 +99,7 @@ static const char *perPlayerGadgetsToHide[] ="ButtonAccept","ComboBoxPlayer","ComboBoxTeam",+ "ComboBoxHandicap","ComboBoxColor","ComboBoxPlayerTemplate","ComboBoxAIPersona",diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cppindex 189dd372e..d8405497e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp@@ -202,6 +202,13 @@ static NameKeyType comboBoxAIPersonaID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INNAMEKEY_INVALID,NAMEKEY_INVALID,NAMEKEY_INVALID,NAMEKEY_INVALID };+static GameWindow *comboBoxHandicap[MAX_SLOTS] = {NULL,NULL,NULL,NULL,+ NULL,NULL,NULL,NULL };+static NameKeyType comboBoxHandicapID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID };+//static GameWindow *buttonStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,// NULL,NULL,NULL,NULL };//@@ -1375,6 +1382,7 @@ void InitSkirmishGameGadgets( void )}InitAIPersonaComboBoxes( parentSkirmishGameOptions, "SkirmishGameOptionsMenu.wnd", comboBoxAIPersona, comboBoxAIPersonaID );+ InitHandicapComboBoxes( parentSkirmishGameOptions, "SkirmishGameOptionsMenu.wnd", comboBoxHandicap, comboBoxHandicapID );InitLobbySeatVisuals( parentSkirmishGameOptions, "SkirmishGameOptionsMenu.wnd" );populateSkirmishBattleHonors();@@ -1401,6 +1409,7 @@ void skirmishUpdateSlotList( void )comboBoxColor, comboBoxPlayerTemplate,comboBoxTeam, NULL, buttonStart, buttonMapStartPosition );UpdateAIPersonaComboBoxes( TheSkirmishGameInfo, comboBoxAIPersona );+ UpdateHandicapComboBoxes( TheSkirmishGameInfo, comboBoxHandicap, comboBoxTeam );UpdateLobbySeatVisuals( TheSkirmishGameInfo );updateMapStartSpots(TheSkirmishGameInfo, buttonMapStartPosition, FALSE);doUpdateSlotList = TRUE;@@ -1429,6 +1438,7 @@ static const char *gadgetsToHide[] ="StaticTextPlayers","StaticTextColor","StaticTextTeam",+ "StaticTextHandicap","StaticTextFaction",NULL // keep this last};@@ -1436,6 +1446,7 @@ static const char *perPlayerGadgetsToHide[] ={"ComboBoxPlayer","ComboBoxTeam",+ "ComboBoxHandicap","ComboBoxColor","ComboBoxPlayerTemplate","ComboBoxAIPersona",@@ -1841,6 +1852,10 @@ WindowMsgHandledType SkirmishGameOptionsMenuSystem( GameWindow *window, Unsigned{// the slot has it; Skirmish.ini keeps it with the rest of the slot list}+ else if ( HandleHandicapSelection( TheSkirmishGameInfo, comboBoxHandicap, comboBoxHandicapID, (NameKeyType)controlID ) )+ {+ // the same+ }else{for (Int i = 0; i < MAX_SLOTS; i++)diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cppindex 1d21ab416..0c4ed9bdd 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishMapSelectMenu.cpp@@ -137,6 +137,7 @@ static const char *gadgetsToHide[] ="MapWindow","StaticTextPlayers","StaticTextTeam",+ "StaticTextHandicap","StaticTextFaction","StaticTextColor","TextEntryPlayerName",@@ -155,6 +156,7 @@ static const char *perPlayerGadgetsToHide[] ="ComboBoxPlayer","ComboBoxAIPersona","ComboBoxTeam",+ "ComboBoxHandicap","ComboBoxColor","ComboBoxPlayerTemplate",NULL // keep this lastdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cppindex 4077e7157..700488319 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp@@ -260,6 +260,13 @@ static NameKeyType comboBoxAIPersonaID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INNAMEKEY_INVALID,NAMEKEY_INVALID,NAMEKEY_INVALID,NAMEKEY_INVALID };+static GameWindow *comboBoxHandicap[MAX_SLOTS] = {NULL,NULL,NULL,NULL,+ NULL,NULL,NULL,NULL };+static NameKeyType comboBoxHandicapID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID,+ NAMEKEY_INVALID,NAMEKEY_INVALID };+//static GameWindow *buttonStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,// NULL,NULL,NULL,NULL };//@@ -796,6 +803,35 @@ static void handleTeamSelection(int index)}}+// HandleHandicapSelection has set the host's slot; the same round as a team pick from here+static void handleHandicapSelection(Int handicap)+{+ GameInfo *myGame = TheGameSpyInfo->getCurrentStagingRoom();++ if (TheGameSpyInfo->amIHost())+ {+ // send around a new slotlist+ myGame->resetAccepted();+ TheGameSpyInfo->setGameOptions();+ WOLDisplaySlotList();+ }+ else+ {+ // request the handicap from the host+ AsciiString options;+ options.format("Handicap=%d", handicap);+ AsciiString hostName;+ hostName.translate(myGame->getSlot(0)->getName());+ PeerRequest req;+ req.peerRequestType = PeerRequest::PEERREQUEST_UTMPLAYER;+ req.UTM.isStagingRoom = TRUE;+ req.id = "REQ/";+ req.nick = hostName.str();+ req.options = options.str();+ TheGameSpyPeerMessageQueue->addRequest(req);+ }+}+static void handleStartingCashSelection(){GameInfo *myGame = TheGameSpyInfo->getCurrentStagingRoom();@@ -1272,6 +1308,7 @@ void WOLDisplaySlotList( void )UpdateSlotList( game, comboBoxPlayer, comboBoxColor,comboBoxPlayerTemplate, comboBoxTeam, buttonAccept, buttonStart, buttonMapStartPosition );UpdateAIPersonaComboBoxes( game, comboBoxAIPersona );+ UpdateHandicapComboBoxes( game, comboBoxHandicap, comboBoxTeam );UpdateLobbySeatVisuals( game );WOLDisplayGameOptions();@@ -1536,6 +1573,7 @@ void InitWOLGameGadgets( void )//GadgetButtonSetEnabledColor(buttonAccept[0], GameSpyColor[GSCOLOR_ACCEPT_TRUE]);InitAIPersonaComboBoxes( parentWOLGameSetup, "GameSpyGameOptionsMenu.wnd", comboBoxAIPersona, comboBoxAIPersonaID );+ InitHandicapComboBoxes( parentWOLGameSetup, "GameSpyGameOptionsMenu.wnd", comboBoxHandicap, comboBoxHandicapID );InitLobbySeatVisuals( parentWOLGameSetup, "GameSpyGameOptionsMenu.wnd" );// the settings page and the chat log share one rectangle; this opens on the chat log@@ -1574,6 +1612,7 @@ void DeinitWOLGameGadgets( void )comboBoxColor[i] = NULL;comboBoxPlayerTemplate[i] = NULL;comboBoxTeam[i] = NULL;+ comboBoxHandicap[i] = NULL;buttonAccept[i] = NULL;// buttonStartPosition[i] = NULL;buttonMapStartPosition[i] = NULL;@@ -2649,6 +2688,14 @@ void WOLGameSetupMenuUpdate( WindowLayout * layout, void *userData)DEBUG_LOG(("Rejecting invalid team %d\n", val));}}+ else if (key == "Handicap")+ {+ if (ApplyHandicapRequest(game, slot, val))+ {+ change = true;+ shouldUnaccept = true;+ }+ }else if (key == "IP"){if (uVal != slot->getIP())@@ -2919,6 +2966,10 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msgTheGameSpyInfo->setGameOptions();WOLDisplaySlotList();}+ else if ( Int handicap = HandleHandicapSelection( TheGameSpyInfo->getCurrentStagingRoom(), comboBoxHandicap, comboBoxHandicapID, (NameKeyType)controlID ) )+ {+ handleHandicapSelection( handicap );+ }else{GameSpyStagingRoom *myGame = TheGameSpyInfo->getCurrentStagingRoom();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cppindex ffeac255d..fa0748dbf 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp@@ -96,6 +96,7 @@ static const char *gadgetsToHide[] =//"StaticTextGameName","StaticTextPlayers","StaticTextTeam",+ "StaticTextHandicap","StaticTextFaction","StaticTextColor","TextEntryMapDisplay",@@ -115,6 +116,7 @@ static const char *perPlayerGadgetsToHide[] ="StaticTextPlayer","ComboBoxPlayer","ComboBoxTeam",+ "ComboBoxHandicap","ComboBoxColor","ComboBoxPlayerTemplate","ComboBoxAIPersona",diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/UndeadBody.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/UndeadBody.cppindex d042d4c8a..813ed21a3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/UndeadBody.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/UndeadBody.cpp@@ -139,7 +139,7 @@ void UndeadBody::startSecondLife(DamageInfo *damageInfo)m_isSecondLife = TRUE;// Modify ActiveBody's max health and initial health- setMaxHealth(data->m_secondLifeMaxHealth, FULLY_HEAL);+ setMaxHealth(data->m_secondLifeMaxHealth * getObject()->getHandicapHealthFactor(), FULLY_HEAL);// Set Armor set flag to use second life armorsetArmorSetFlag(ARMORSET_SECOND_LIFE);diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex b8d3dca47..e34b7fdb1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -186,8 +186,26 @@ AsciiString DescribeObject(const Object *obj)#endif // DEBUG_LOGGING//-------------------------------------------------------------------------------------------------+// The lobby's handicap on the body, its share of health kept. An InactiveBody has no health to scale.//--------------------------------------------------------------------------------------------------Object::Object( const ThingTemplate *tt, const ObjectStatusMaskType &objectStatusMask, Team *team ) :+static void scaleMaxHealth( Object *obj, Real factor )+{+ BodyModuleInterface *body = obj->getBodyModule();+ if( factor != 1.0f && body && body->getMaxHealth() > 0.0f )+ body->setMaxHealth( body->getMaxHealth() * factor, PRESERVE_RATIO );+}++// what walks, drives or flies: a seat's missiles, mines and parachutes are not its units+static Real handicapHealthFactor( const Object *obj, const Player *owner )+{+ if( owner == NULL || ( !obj->isKindOf( KINDOF_INFANTRY ) && !obj->isKindOf( KINDOF_VEHICLE ) ) )+ return 1.0f;+ return owner->getHandicap()->getHandicap( Handicap::MAXHEALTH, obj->getTemplate() );+}++//-------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+Object::Object( const ThingTemplate *tt, const ObjectStatusMaskType &objectStatusMask, Team *team ) :Thing(tt),m_indicatorColor(0),m_ai(NULL),@@ -513,6 +531,10 @@ Object::Object( const ThingTemplate *tt, const ObjectStatusMaskType &objectStatuconst Player* controller = getControllingPlayer();m_experienceTracker->setVeterancyLevel( controller->getProductionVeterancyLevel( getTemplate()->getName() ) );+ // Before the create modules and initObject can run an upgrade, whose addition already comes out at+ // this factor. A save's loaded object gets its saved health over this afterwards.+ scaleMaxHealth( this, getHandicapHealthFactor() );+/// allow for inter-Module resolutionfor (BehaviorModule** b = m_behaviors; *b; ++b){@@ -954,6 +976,7 @@ void Object::setOrRestoreTeam( Team* team, Bool restoring )return;Team* oldTeam = m_team;+ const Player *oldOwner = getControllingPlayer();// Before Switch //////////////////////////if (m_team)@@ -1005,6 +1028,11 @@ void Object::setOrRestoreTeam( Team* team, Bool restoring )draw->changedTeam();}+ // A captured unit serves at its new owner's handicap. Before onCapture, whose upgrade check adds at+ // the new factor. A save has the health already.+ if( !restoring )+ friend_ownerChangedHandicap( oldOwner );+// This can't just go in ::defect, because some things just do setTeam. The act of// setting a new team needs to tell the modules and do other important stuff.// And it needs to happen after the switch.@@ -1728,6 +1756,24 @@ Player * Object::getControllingPlayer() constreturn NULL;}+//=============================================================================+// Object::getHandicapHealthFactor+//=============================================================================+Real Object::getHandicapHealthFactor() const+{+ return handicapHealthFactor( this, getControllingPlayer() );+}++//=============================================================================+// Object::friend_ownerChangedHandicap+//=============================================================================+void Object::friend_ownerChangedHandicap( const Player *oldOwner )+{+ // A new object takes its factor at the end of its constructor; one going away has no use for one.+ if( m_modulesReady && !isDestroyed() )+ scaleMaxHealth( this, getHandicapHealthFactor() / handicapHealthFactor( this, oldOwner ) );+}+//=============================================================================void Object::setProducer(const Object* obj){@@ -3961,7 +4007,7 @@ void Object::updateObjValuesFromMapProperties(Dict* properties)if (exists && valInt >= 0) {BodyModuleInterface* body = getBodyModule();if (body) {- body->setMaxHealth(valInt);+ body->setMaxHealth(valInt * getHandicapHealthFactor());}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/MaxHealthUpgrade.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/MaxHealthUpgrade.cppindex b3fb0803b..fd46b8354 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/MaxHealthUpgrade.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/MaxHealthUpgrade.cpp@@ -90,7 +90,9 @@ void MaxHealthUpgrade::upgradeImplementation( )// Veterancy multiplies max health when it arrives, so an addition made after a promotion has// to carry the promotion's bonus too. Without it an Elite Paladin that researched Composite// Armor ended on 750 where one armored first and promoted later ended on 780.- Real add = data->m_addMaxHealth * TheGlobalData->getRankHealthBonus( obj->getTemplate(), obj->getVeterancyLevel(), obj->getRankGrade() );+ // The lobby's handicap is a multiplier that is already in the max health too.+ Real add = data->m_addMaxHealth * TheGlobalData->getRankHealthBonus( obj->getTemplate(), obj->getVeterancyLevel(), obj->getRankGrade() )+ * obj->getHandicapHealthFactor();body->setMaxHealth( body->getMaxHealth() + add, data->m_maxHealthChangeType );}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex f2bce8c32..d7f6da1b0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -1558,6 +1558,9 @@ void GameLogic::startNewGame( Bool loadingSaveGame )d.setInt(TheKey_playerColor, TheMultiplayerSettings->getColor(slot->getColor())->getColor());d.setInt(TheKey_playerNightColor, TheMultiplayerSettings->getColor(slot->getColor())->getNightColor());d.setInt(TheKey_multiplayerStartIndex, slot->getStartPos());+ // Player's Handicap reads it; absent at full health, so such a seat's dict is the one it always was+ if (slot->getHandicap() != HANDICAP_FULL)+ d.setReal(TheNameKeyGenerator->nameToKey("HANDICAP_MAXHEALTH_GENERIC"), slot->getHandicap() / (Real)HANDICAP_FULL);// d.setBool(TheKey_multiplayerIsLocal, slot->isLocalPlayer());// d.setBool(TheKey_multiplayerIsLocal, slot->getIP() == game->getLocalIP());//diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cppindex a7964835b..43d562fb3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp@@ -1014,6 +1014,98 @@ Bool HandleAIPersonaSelection(GameInfo *myGame, GameWindow *comboPersona[], Name// -----------------------------------------------------------------------------+// the box's lines run 100, 90 ... 10+static Int handicapComboPos(Int handicap)+{+ return (HANDICAP_FULL - handicap) / HANDICAP_STEP;+}++void InitHandicapComboBoxes(GameWindow *parent, const char *layoutFilename,+ GameWindow *comboHandicap[], NameKeyType comboHandicapID[])+{+ const Int lines = HANDICAP_FULL / HANDICAP_STEP;+ for (Int i = 0; i < MAX_SLOTS; ++i)+ {+ AsciiString name;+ name.format("%s:ComboBoxHandicap%d", layoutFilename, i);+ comboHandicapID[i] = NAMEKEY(name);+ comboHandicap[i] = TheWindowManager->winGetWindowFromId(parent, comboHandicapID[i]);+ if (!comboHandicap[i])+ continue; // a layout from before the column++ GameWindow *listBox = GadgetComboBoxGetListBox(comboHandicap[i]);+ ListboxData *listData = (ListboxData *)listBox->winGetUserData();+ if (listData->listLength < lines)+ GadgetListBoxSetListLength(listBox, lines);+ GadgetComboBoxSetMaxDisplay(comboHandicap[i], min(lines, 8)); // as the personality box, for the lower seats++ GadgetComboBoxReset(comboHandicap[i]);+ const Color color = comboHandicap[i]->winGetEnabledTextColor();+ for (Int handicap = HANDICAP_FULL; handicap >= HANDICAP_STEP; handicap -= HANDICAP_STEP)+ {+ UnicodeString label;+ label.format(u"%d%%", handicap);+ Int index = GadgetComboBoxAddEntry(comboHandicap[i], label, color);+ GadgetComboBoxSetItemData(comboHandicap[i], index, (void *)(intptr_t)handicap);+ }+ GadgetComboBoxSetSelectedPos(comboHandicap[i], handicapComboPos(HANDICAP_FULL), TRUE);+ comboHandicap[i]->winEnable(FALSE); // until UpdateHandicapComboBoxes knows whose seat it is+ }+}++void UpdateHandicapComboBoxes(GameInfo *myGame, GameWindow *comboHandicap[], GameWindow *comboTeam[])+{+ if (!AreSlotListUpdatesEnabled())+ return;+ for (Int i = 0; i < MAX_SLOTS; ++i)+ {+ if (!comboHandicap[i])+ continue;+ comboHandicap[i]->winEnable(comboTeam[i] && BitTest(comboTeam[i]->winGetStatus(), WIN_STATUS_ENABLED));+ const Int wanted = handicapComboPos(myGame->getConstSlot(i)->getHandicap());+ Int pos = -1;+ GadgetComboBoxGetSelectedPos(comboHandicap[i], &pos);+ if (pos != wanted)+ GadgetComboBoxSetSelectedPos(comboHandicap[i], wanted, TRUE);+ }+}++Int HandleHandicapSelection(GameInfo *myGame, GameWindow *comboHandicap[], NameKeyType comboHandicapID[],+ NameKeyType controlID)+{+ // setting a box's selection sends this too, and filling the boxes at init is no pick+ if (!AreSlotListUpdatesEnabled())+ return 0;+ for (Int i = 0; i < MAX_SLOTS; ++i)+ {+ if (!comboHandicap[i] || controlID != comboHandicapID[i])+ continue;+ Int pos = -1;+ GadgetComboBoxGetSelectedPos(comboHandicap[i], &pos);+ GameSlot *slot = myGame->getSlot(i);+ const Int was = slot->getHandicap();+ const Int handicap = (Int)(intptr_t)GadgetComboBoxGetItemData(comboHandicap[i], pos);+ if (handicap == was)+ return 0;+ // A guest's slot takes it from the host's list. Written here, a start already on its way would+ // have this seat play a handicap nobody else ever saw.+ if (!myGame->amIHost())+ return handicap;+ slot->setHandicap(handicap);+ // an options string past the LAN budget comes back empty and is never sent+ if (GameInfoToAsciiString(myGame).isEmpty())+ {+ slot->setHandicap(was);+ GadgetComboBoxSetSelectedPos(comboHandicap[i], handicapComboPos(was), TRUE);+ return 0;+ }+ return handicap;+ }+ return 0;+}++// -----------------------------------------------------------------------------+static GameWindow *theSeatCard[MAX_SLOTS];static GameWindow *theSeatBar[MAX_SLOTS];static GameWindow *theSeatSwatch[MAX_SLOTS];diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cppindex 442faa842..80004b2bc 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp@@ -226,6 +226,7 @@ void GameSlot::reset()m_playerTemplate = -1;m_teamNumber = -1;m_aiPersonality = AIPERSONA_NORMAL;+ m_handicap = HANDICAP_FULL;m_NATBehavior = FirewallHelperClass::FIREWALL_TYPE_SIMPLE;m_lastFrameInGame = 0;m_disconnected = FALSE;@@ -454,6 +455,7 @@ void GameSlot::setState( SlotState state, UnicodeString name, UnsignedInt IP )m_playerTemplate = -1;m_teamNumber = -1;m_aiPersonality = AIPERSONA_NORMAL;+ m_handicap = HANDICAP_FULL;if (state == SLOT_OPEN && TheGameSpyGame && TheGameSpyGame->getConstSlot(0) == this){@@ -1442,23 +1444,27 @@ static AsciiString buildGameInfoAsciiString( const GameInfo *game, const AsciiStif (slot && slot->isHuman()){AsciiString tmp; //all this data goes after name- tmp.format( ",%X,%d,%c%c,%d,%s,%d,%d,%d:",+ tmp.format( ",%X,%d,%c%c,%d,%s,%d,%d,%d%s:",slot->getIP(), slot->getPort(),(slot->isAccepted()?'T':'F'),(slot->hasMap()?'T':'F'),slot->getColor(), PlayerTemplateSlotField(slot->getPlayerTemplate()).str(),slot->getStartPos(), slot->getTeamNumber(),- slot->getNATBehavior() );+ slot->getNATBehavior(),+ HandicapSlotField(slot->getHandicap()).str() );str.format( "H%s%s", playerNames[i].str(), tmp.str() );}else if (slot && slot->isAI()){// an older parser stops at the team and never sees the personality after it- str.format("C%c,%d,%s,%d,%d%s:", SlotStateToOptionsChar(slot->getState()),+ const Int handicap = slot->getHandicap();+ const Bool personaHolds = handicap != HANDICAP_FULL && slot->getAIPersonality() == AIPERSONA_NORMAL;+ str.format("C%c,%d,%s,%d,%d%s%s:", SlotStateToOptionsChar(slot->getState()),slot->getColor(), PlayerTemplateSlotField(slot->getPlayerTemplate()).str(),slot->getStartPos(), slot->getTeamNumber(),- AIPersonaSlotField(slot->getAIPersonality()).str());+ personaHolds ? ",0" : AIPersonaSlotField(slot->getAIPersonality()).str(),+ HandicapSlotField(handicap).str());}else if (slot && slot->getState() == SLOT_OPEN){@@ -1496,6 +1502,42 @@ Int AIPersonaFromSlotField( const char *field )return (persona > AIPERSONA_NORMAL && persona < AIPERSONA_COUNT) ? persona : AIPERSONA_NORMAL;}+Bool IsValidHandicap( Int handicap )+{+ return handicap >= HANDICAP_STEP && handicap <= HANDICAP_FULL && handicap % HANDICAP_STEP == 0;+}++AsciiString HandicapSlotField( Int handicap )+{+ AsciiString field;+ if (handicap != HANDICAP_FULL)+ field.format(",%d", handicap);+ return field;+}++Int HandicapFromSlotField( const char *field )+{+ if (field == NULL)+ return HANDICAP_FULL;+ const Int handicap = atoi(field);+ return IsValidHandicap(handicap) ? handicap : HANDICAP_FULL;+}++Bool ApplyHandicapRequest( GameInfo *game, GameSlot *slot, Int handicap )+{+ if (!IsValidHandicap(handicap) || handicap == slot->getHandicap() || slot->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)+ {+ DEBUG_LOG(("Rejecting invalid handicap %d\n", handicap));+ return FALSE;+ }+ const Int was = slot->getHandicap();+ slot->setHandicap(handicap);+ // a pick that pushes the options string past the packet would empty it for everyone+ if (GameInfoToAsciiString(game).isEmpty())+ slot->setHandicap(was);+ return TRUE;+}+static Int grabHexInt(const char *s){char tmp[5] = "0xff";@@ -1821,6 +1863,9 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)}newSlot[i].setNATBehavior(NATType);DEBUG_LOG(("ParseAsciiStringToGameInfo - NAT behavior is %X\n", NATType));++ //Read the optional handicap+ newSlot[i].setHandicap(HandicapFromSlotField(strtok_r(NULL,",",&slotPos)));}// case 'H':break;case 'C':@@ -1934,6 +1979,9 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)//Read the optional personalitynewSlot[i].setAIPersonality(AIPersonaFromSlotField(strtok_r(NULL,",",&slotPos)));+ //Read the optional handicap+ newSlot[i].setHandicap(HandicapFromSlotField(strtok_r(NULL,",",&slotPos)));+}//case 'C':break;case 'O':@@ -2025,7 +2073,7 @@ void SkirmishGameInfo::crc( Xfer *xfer )// ------------------------------------------------------------------------------------------------void SkirmishGameInfo::xfer( Xfer *xfer ){- const XferVersion currentVersion = 11; // 5 adds m_peaceTime, 6 m_unitLimit, 7 m_proRules, 8 m_incomeSharing, 9 m_techRespawn, 10 m_supplyPileLimit, 11 each slot's AI personality+ const XferVersion currentVersion = 12; // 5 adds m_peaceTime, 6 m_unitLimit, 7 m_proRules, 8 m_incomeSharing, 9 m_techRespawn, 10 m_supplyPileLimit, 11 each slot's AI personality, 12 each slot's handicapXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -2086,6 +2134,12 @@ void SkirmishGameInfo::xfer( Xfer *xfer )elsepersona = AIPERSONA_NORMAL;+ Int handicap = m_slot[slot]->getHandicap();+ if (version >= 12)+ xfer->xferInt(&handicap);+ else+ handicap = HANDICAP_FULL;+if( xfer->getXferMode() == XFER_LOAD ) {m_slot[slot]->setState((SlotState)state, name);if (isAccepted) m_slot[slot]->setAccept();@@ -2100,6 +2154,7 @@ void SkirmishGameInfo::xfer( Xfer *xfer )m_slot[slot]->setStartPos(startPos);m_slot[slot]->setPlayerTemplate(playerTemplate);m_slot[slot]->setAIPersonality(persona);+ m_slot[slot]->setHandicap(handicap);}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cppindex 261b05cc3..7b08e3cff 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp@@ -266,6 +266,7 @@ Bool LANAPI::StartAutomatedGame( AsciiString mapName, Int seed, const UnsignedInslot.setState( (SlotState)TheGlobalData->m_autoSkirmishAIState );slot.setAIPersonality( TheGlobalData->autoSkirmishPersona( i ) );}+ slot.setHandicap( TheGlobalData->m_autoSkirmishHandicap[ i ] ); // after setState, which clears it// -side names a seat's army here too, the same words on every machine; a name nobody knows is a// random draw, which then shows in the run's own logconst Int named = TheGlobalData->m_autoSkirmishSide[ i ].isEmpty() ? -1 : ThePlayerTemplateStore->getTemplateNumByName( TheGlobalData->m_autoSkirmishSide[ i ] );@@ -608,6 +609,14 @@ void LANAPI::OnGameOptions( UnsignedInt playerIP, Int playerSlot, AsciiString opDEBUG_LOG(("Rejecting invalid team %d\n", val));}}+ else if (key == "Handicap")+ {+ if (ApplyHandicapRequest(m_currentGame, slot, val))+ {+ change = true;+ shouldUnaccept = true;+ }+ }else if (key == "NAT"){if ((val >= FirewallHelperClass::FIREWALL_TYPE_SIMPLE) &&diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 4e72c9331..6b01823da 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -21034,6 +21034,177 @@ TEST(file_write_queue_writes_what_the_file_calls_wrote)queue.start( q );const char head[] = "GENREP\0\0\0\0";fwrite( head, 1, 10, d );+#include "Common/MultiplayerSettings.h"+#include "GameNetwork/LANAPICallbacks.h"++/* A seat's handicap is the last field of its slot entry, and only when the seat has one: a string+ with none, a replay's header and Skirmish.ini stay byte for byte what they were, and an older one+ reads as full health. An AI seat at Normal has to write its persona as 0 for the handicap to land+ in the right field. The host's copy of a guest's request refuses what the lobby does not offer and+ what the 400 bytes of a LAN packet have no room for. */+TEST(handicap_rides_the_slot_entry_and_full_health_leaves_the_string_unchanged)+{+ CHECK( bootOnce() );++ CHECK_STR( HandicapSlotField( HANDICAP_FULL ).str(), "" );+ CHECK_STR( HandicapSlotField( 50 ).str(), ",50" );+ for( Int h = HANDICAP_STEP; h <= HANDICAP_FULL; h += HANDICAP_STEP )+ {+ CHECK( IsValidHandicap( h ) );+ AsciiString field = HandicapSlotField( h );+ CHECK_EQ( HandicapFromSlotField( field.isEmpty() ? NULL : field.str() + 1 ), h );+ }+ static const char *const refused[] = { "", "0", "5", "55", "110", "-10", "x" };+ for( Int r = 0; r < (Int)ARRAY_SIZE( refused ); ++r )+ CHECK_EQ( HandicapFromSlotField( refused[r] ), (Int)HANDICAP_FULL );+ CHECK_EQ( HandicapFromSlotField( NULL ), (Int)HANDICAP_FULL );++ UnicodeString playerName;+ playerName.translate( AsciiString( "Player" ) );++ GameSlot seat;+ CHECK_EQ( seat.getHandicap(), (Int)HANDICAP_FULL );+ seat.setState( SLOT_MED_AI );+ seat.setHandicap( 40 );+ seat.setState( SLOT_BRUTAL_AI ); // another rung keeps it, as it keeps the faction+ CHECK_EQ( seat.getHandicap(), 40 );+ GameSlot copy = seat; // GameInfo::setSlot copies the parsed slot in whole+ CHECK_EQ( copy.getHandicap(), 40 );+ seat.setState( SLOT_PLAYER, playerName );+ CHECK_EQ( seat.getHandicap(), (Int)HANDICAP_FULL );+ seat.setHandicap( 40 );+ seat.setPlayerTemplate( PLAYERTEMPLATE_OBSERVER ); // an observer has no units to weaken+ CHECK_EQ( seat.getHandicap(), (Int)HANDICAP_FULL );++ // what building and parsing a whole string asks of the engine, and no more+ GlobalData *savedData = TheWritableGlobalData;+ TheWritableGlobalData = NEW GlobalData;+ GameState *savedState = TheGameState;+ TheGameState = NEW GameState;+ MultiplayerSettings *savedSettings = TheMultiplayerSettings;+ TheMultiplayerSettings = NEW MultiplayerSettings;+ PlayerTemplateStore *savedStore = ThePlayerTemplateStore;+ ThePlayerTemplateStore = NEW PlayerTemplateStore;+ ThePlayerTemplateStore->init();+ LANAPI *savedLAN = TheLAN;++ const AsciiString mapPath( "Save\\test\\test.map" );+ SkirmishGameInfo host;+ host.init();+ AsciiString mapInSaves = TheGameState->getSaveDirectory();+ mapInSaves.concat( "test.map" );+ host.setMap( mapInSaves );+ host.setSeed( 7 );+ GameSlot *slot = host.getSlot( 0 );+ slot->setState( SLOT_PLAYER, playerName, 0xC0A80164u );+ slot->setPort( 8088 );+ slot->setPlayerTemplate( PLAYERTEMPLATE_RANDOM );+ slot->setAccept();+ slot->setMapAvailability( TRUE );+ host.getSlot( 1 )->setState( SLOT_BRUTAL_AI );+ host.getSlot( 1 )->setPlayerTemplate( PLAYERTEMPLATE_RANDOM );+ host.getSlot( 2 )->setState( SLOT_EASY_AI );+ host.getSlot( 2 )->setPlayerTemplate( PLAYERTEMPLATE_RANDOM );+ host.getSlot( 2 )->setAIPersonality( AIPERSONA_TURTLE );+ // parsing an open or closed seat asks TheGameText, which the harness does not stand up+ for( Int i = 3; i < MAX_SLOTS; ++i )+ {+ host.getSlot( i )->setState( SLOT_MED_AI );+ host.getSlot( i )->setPlayerTemplate( PLAYERTEMPLATE_RANDOM );+ }++ // nobody picked: the old string, not one byte more+ const AsciiString untouched = GameInfoOptionsString( &host, mapPath, 0 );+ AsciiString humanEntry;+ humanEntry.format( "HPlayer,C0A80164,8088,TT,-1,-1,-1,-1,%d:", (Int)slot->getNATBehavior() );+ AsciiString aiEntries;+ aiEntries.format( "CH,-1,-1,-1,-1:CE,-1,-1,-1,-1,%d:", (Int)AIPERSONA_TURTLE );+ CHECK( strstr( untouched.str(), humanEntry.str() ) != NULL );+ CHECK( strstr( untouched.str(), aiEntries.str() ) != NULL );++ // a pick on each kind of seat comes back as itself, and the persona beside it stays put+ host.getSlot( 0 )->setHandicap( 50 );+ host.getSlot( 1 )->setHandicap( 30 );+ host.getSlot( 2 )->setHandicap( 70 );+ const AsciiString picked = GameInfoOptionsString( &host, mapPath, 0 );+ humanEntry.format( "HPlayer,C0A80164,8088,TT,-1,-1,-1,-1,%d,50:", (Int)slot->getNATBehavior() );+ aiEntries.format( "CH,-1,-1,-1,-1,0,30:CE,-1,-1,-1,-1,%d,70:", (Int)AIPERSONA_TURTLE );+ CHECK( strstr( picked.str(), humanEntry.str() ) != NULL );+ CHECK( strstr( picked.str(), aiEntries.str() ) != NULL );++ SkirmishGameInfo guest;+ guest.init();+ CHECK( ParseAsciiStringToGameInfo( &guest, picked ) );+ CHECK_EQ( guest.getSlot( 0 )->getHandicap(), 50 );+ CHECK_EQ( guest.getSlot( 1 )->getHandicap(), 30 );+ CHECK_EQ( guest.getSlot( 1 )->getAIPersonality(), (Int)AIPERSONA_NORMAL );+ CHECK_EQ( guest.getSlot( 2 )->getHandicap(), 70 );+ CHECK_EQ( guest.getSlot( 2 )->getAIPersonality(), (Int)AIPERSONA_TURTLE );+ CHECK_EQ( guest.getSlot( 3 )->getHandicap(), (Int)HANDICAP_FULL );++ // a string from before the column, and one whose value no build wrote+ CHECK( ParseAsciiStringToGameInfo( &guest, untouched ) );+ for( Int i = 0; i < MAX_SLOTS; ++i )+ CHECK_EQ( guest.getSlot( i )->getHandicap(), (Int)HANDICAP_FULL );+ CHECK_EQ( guest.getSlot( 2 )->getAIPersonality(), (Int)AIPERSONA_TURTLE );+ AsciiString odd;+ odd.format( "US=0;M=00save/test;MC=0;MS=0;SD=7;C=100;SR=0;SC=0;O=N;S=HPlayer,C0A80164,8088,TT,-1,-1,-1,-1,%d,77:CH,-1,-1,-1,-1,0,120:CM,-1,-1,-1,-1:CM,-1,-1,-1,-1:CM,-1,-1,-1,-1:CM,-1,-1,-1,-1:CM,-1,-1,-1,-1:CM,-1,-1,-1,-1:;",+ (Int)slot->getNATBehavior() );+ CHECK( ParseAsciiStringToGameInfo( &guest, odd ) );+ CHECK_EQ( guest.getSlot( 0 )->getHandicap(), (Int)HANDICAP_FULL );+ CHECK_EQ( guest.getSlot( 1 )->getHandicap(), (Int)HANDICAP_FULL );++ // the host's answer to a guest's request+ GameSlot *asker = host.getSlot( 0 );+ CHECK( ApplyHandicapRequest( &host, asker, 60 ) );+ CHECK_EQ( asker->getHandicap(), 60 );+ CHECK( !ApplyHandicapRequest( &host, asker, 60 ) ); // nothing changed, nothing to send round+ CHECK( !ApplyHandicapRequest( &host, asker, 55 ) );+ CHECK( !ApplyHandicapRequest( &host, asker, 0 ) );+ CHECK( !ApplyHandicapRequest( &host, asker, 110 ) );+ CHECK_EQ( asker->getHandicap(), 60 );++ // a room so full of fixed fields that its last few picks have no room: those do not stand, the+ // string never empties, and the list still goes round so the guest's box comes back+ host.setPeaceTime( 30 );+ host.setIncomeSharing( INCOME_SHARING_ALL );+ host.setTechRespawn( 300 );+ host.setSupplyPileLimit( 60000 );+ host.setUnitLimit( TRUE );+ host.setTurbo( TRUE );+ host.setMapCRC( 0xFFFFFFFFu );+ host.setMapSize( 9999999 );+ host.setSeed( 2147483647 );+ for( Int i = 0; i < MAX_SLOTS; ++i )+ {+ host.getSlot( i )->setState( SLOT_PLAYER, playerName, 0xC0A80164u + i );+ host.getSlot( i )->setPort( 8088 );+ }+ TheLAN = reinterpret_cast<LANAPI *>( &host ); // asked only whether it is there, for the budget+ CHECK( !GameInfoToAsciiString( &host ).isEmpty() );+ Int stood = 0;+ for( Int i = 0; i < MAX_SLOTS; ++i )+ {+ CHECK( ApplyHandicapRequest( &host, host.getSlot( i ), 50 ) );+ CHECK( !GameInfoToAsciiString( &host ).isEmpty() );+ if( host.getSlot( i )->getHandicap() == 50 )+ ++stood;+ }+ printf( " a full room took %d of %d picks\n", stood, MAX_SLOTS );+ CHECK( stood > 0 );+ CHECK( stood < MAX_SLOTS );+ TheLAN = savedLAN;++ delete ThePlayerTemplateStore;+ ThePlayerTemplateStore = savedStore;+ delete TheMultiplayerSettings;+ TheMultiplayerSettings = savedSettings;+ delete TheGameState;+ TheGameState = savedState;+ delete TheWritableGlobalData;+ TheWritableGlobalData = savedData;+}+queue.write( head, 10 );const UnsignedInt patch = 0x11223344;long end = ftell( d ); // a patch before the first flush, as logGameStart's