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
fix(gameengine): charge the unit limit for payloads and paired builds
Olcay Seyganb7bb30573261
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 063ab5c9a..c0709cb9b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -474,7 +474,7 @@ found and fixed — EA's own, not port damage.**- The skirmish and LAN rooms are laid out again, on one grid. Each column heading sits over its own column instead of up to 18 pixels to the right of it. The seats and the settings page underneath them start and stop at the same two edges, and Play Game stands under the map and your win record on the right-hand pair. The open tab used to be lettered in a grey that measured about 2 to 1 against the panel and read as a button that was switched off. Play Game waits at the bottom right and the button that leaves the room sits at the bottom left, as far from it as the screen allows. With all eight seats taken, "USA Super Weapon General" still fits in its box. The online room keeps its old layout.- 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.+- 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. A transport that rolls out full is charged for its riders while it is still in the queue, so a Troop Crawler costs nine and cannot slip eight Red Guards past the limit, and a pair of Red Guards costs two. A shift or control batch near the wall queues as many as still fit and stops there, and a button whose next order would not fit greys out. 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/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex 1fb9f51c8..e5e7abb6c 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -125,6 +125,8 @@ Int SuperweaponBuildCap( Int restriction, const AsciiString &playerTemplateName// players who are not watching. UnitLimitPerPlayer is one player's share.enum { UNIT_LIMIT_TOTAL = 840 };Int UnitLimitPerPlayer( Int nonObserverPlayers );+// Whether a build that adds unitsItAdds (a transport and its payload) goes past the share. 0 is no cap.+Bool UnitCapRefuses( Int unitsTowardCap, Int unitsItAdds, UnsignedInt unitCap );// Pro Rules, PRO-RULES.md: what every skirmish and network match refuses whoever plays it.// GameLogic::isProRules() says whether a match is under them; these say what they cover, by name@@ -322,7 +324,8 @@ public:Bool canAffordBuild( const ThingTemplate *whatToBuild ) const;// Check MaxSimultaneousOfType- Bool canBuildMoreOfType( const ThingTemplate *whatToBuild ) const;+ // unitsPerOrder is what one queue entry delivers at the factory asking (QuantityModifier), 1 without one+ Bool canBuildMoreOfType( const ThingTemplate *whatToBuild, Int unitsPerOrder = 1 ) const;Int countUnitsTowardCap( void ) const; ///< units standing and queued, what the lobby's unit limit is checked against/// Difficulty level for this player.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.hindex 34a0b5176..bd05b4cc7 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h@@ -159,6 +159,7 @@ public:virtual void cancelUpgrade( const UpgradeTemplate *upgrade ) = 0;virtual Bool isUpgradeInQueue( const UpgradeTemplate *upgrade ) const = 0;virtual UnsignedInt countUnitTypeInQueue( const ThingTemplate *unitType ) const = 0;+ virtual Int getQuantityPerOrder( const ThingTemplate *unitType ) const = 0;virtual Bool queueCreateUnit( const ThingTemplate *unitType, ProductionID productionID ) = 0;virtual void cancelUnitCreate( ProductionID productionID ) = 0;@@ -216,6 +217,7 @@ public:virtual void cancelUpgrade( const UpgradeTemplate *upgrade ); ///< cancel upgrade "research"virtual Bool isUpgradeInQueue( const UpgradeTemplate *upgrade ) const; ///< is the upgrade in our production queue alreadyvirtual UnsignedInt countUnitTypeInQueue( const ThingTemplate *unitType ) const; ///< count number of units with matching unit type in the production queue+ virtual Int getQuantityPerOrder( const ThingTemplate *unitType ) const; ///< units one paid order hands back, from QuantityModifiervirtual Bool queueCreateUnit( const ThingTemplate *unitType, ProductionID productionID ); ///< queue unit to be producedvirtual void cancelUnitCreate( ProductionID productionID ); ///< cancel construction of unit with matching production IDdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex 857347d2d..b816989dc 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -97,6 +97,7 @@#include "GameLogic/Module/SupplyTruckAIUpdate.h"#include "GameLogic/Module/BattlePlanUpdate.h"#include "GameLogic/Module/ProductionUpdate.h"+#include "GameLogic/Module/TransportContain.h"#include "GameLogic/VictoryConditions.h"#include "GameNetwork/GameInfo.h"@@ -3051,6 +3052,46 @@ static Bool isUnitTowardCap( const ThingTemplate *thing )return thing->isKindOf( KINDOF_INFANTRY ) || thing->isKindOf( KINDOF_VEHICLE ) || thing->isKindOf( KINDOF_AIRCRAFT );}+/* The contain modules that fill a new transport from its InitialPayload line. MobNexusContain+ parses the line too but never creates anything from it. */+static const char *const theInitialPayloadContainModules[] =+{+ "TransportContain",+ "HelixContain",+ "OverlordContain",+ "InternetHackContain",+ "RiderChangeContain"+};++/* A queued Troop Crawler is nine units, not one: its eight Red Guards are born inside it the+ frame it rolls out and count from then on, so the queue has to charge for them already or a+ player one short of the cap overshoots it by eight. */+static Int unitsTowardCapPerBuild( const ThingTemplate *unit )+{+ Int units = 1;+ const ModuleInfo &modules = unit->getBehaviorModuleInfo();+ for ( Int m = 0; m < modules.getCount(); ++m )+ {+ const AsciiString moduleName = modules.getNthName( m );+ for ( Int c = 0; c < ARRAY_SIZE( theInitialPayloadContainModules ); ++c )+ {+ if ( moduleName.compare( theInitialPayloadContainModules[ c ] ) != 0 )+ continue;++ const TransportContainModuleData *contain = (const TransportContainModuleData *)modules.getNthData( m );+ if ( contain->m_initialPayload.count > 0+ && isUnitTowardCap( TheThingFactory->findTemplate( contain->m_initialPayload.name ) ) )+ units += contain->m_initialPayload.count;+ }+ }+ return units;+}++Bool UnitCapRefuses( Int unitsTowardCap, Int unitsItAdds, UnsignedInt unitCap )+{+ return unitCap > 0 && (UnsignedInt)( unitsTowardCap + unitsItAdds ) > unitCap;+}+// one object: itself if it is a unit, and whatever units it has queued, however many each entry makesstatic void countUnitTowardCap( Object *obj, void *userData ){@@ -3066,7 +3107,7 @@ static void countUnitTowardCap( Object *obj, void *userData ){const ThingTemplate *unit = entry->getProductionObject();if ( entry->getProductionType() == PRODUCTION_UNIT && unit && isUnitTowardCap( unit ) )- *count += entry->getProductionQuantityRemaining();+ *count += entry->getProductionQuantityRemaining() * unitsTowardCapPerBuild( unit );}}@@ -3078,13 +3119,16 @@ Int Player::countUnitsTowardCap( void ) const}//=============================================================================-Bool Player::canBuildMoreOfType( const ThingTemplate *whatToBuild ) const+Bool Player::canBuildMoreOfType( const ThingTemplate *whatToBuild, Int unitsPerOrder ) 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+ // the lobby's unit limit: a queue entry is refused when everything it delivers - a pair of Red+ // Guards, a transport and its payload - would take what stands and what is queued past 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. A shift batch is one queue message per+ // entry, so the logic takes entries until the next one no longer fits and drops the restconst UnsignedInt unitCap = TheGameLogic ? TheGameLogic->getUnitCap() : 0;- if ( unitCap > 0 && isUnitTowardCap( whatToBuild ) && (UnsignedInt)countUnitsTowardCap() >= unitCap )+ if ( unitCap > 0 && isUnitTowardCap( whatToBuild )+ && UnitCapRefuses( countUnitsTowardCap(), unitsPerOrder * unitsTowardCapPerBuild( whatToBuild ), unitCap ) )return false;// Pro Rules refuse a banned unit outright, through the same doordiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cppindex 2d3a9c17f..f223773b8 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp@@ -1379,7 +1379,7 @@ CanMakeType BuildAssistant::canMakeUnit( Object *builder, const ThingTemplate *w// make sure we're not maxed out for this type of unit.// Warning: isPossibleToMakeUnit() now implicitly calls// canBuildMoreOfType(), so do this check first- if ( player && !player->canBuildMoreOfType( whatToBuild ) )+ if ( player && !player->canBuildMoreOfType( whatToBuild, pu ? pu->getQuantityPerOrder( whatToBuild ) : 1 ) )return CANMAKE_MAXED_OUT_FOR_PLAYER;if (!isPossibleToMakeUnit(builder, whatToBuild))diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cppindex ba4d625c0..b129e6d51 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp@@ -390,14 +390,30 @@ void ProductionUpdate::cancelUpgrade( const UpgradeTemplate *upgrade )} // end cancelUpgrade+//-------------------------------------------------------------------------------------------------+/** Check to see if there is a quantity modifier entry. What this means is if we are building a particular unit+ * and it has a modifier, we build that number of objects instead of just one. A good example is the Chinese+ * barracks building redguards -- they are built 2 at a time, but the user or script only pays for one and+ * builds two for that price! */+//-------------------------------------------------------------------------------------------------+Int ProductionUpdate::getQuantityPerOrder( const ThingTemplate *unitType ) const+{+ const ProductionUpdateModuleData *data = getProductionUpdateModuleData();+ for( std::vector<QuantityModifier>::const_iterator it = data->m_quantityModifiers.begin(); it != data->m_quantityModifiers.end(); ++it )+ {+ const ThingTemplate* productionTemplate = TheThingFactory->findTemplate( it->m_templateName );+ if( productionTemplate && productionTemplate->isEquivalentTo( unitType ) )+ return it->m_quantity;+ }+ return 1;+}+//-------------------------------------------------------------------------------------------------/** Queue the prodcution of a unit. Returns TRUE if unit was added to queue, FALSE if it* was not *///-------------------------------------------------------------------------------------------------Bool ProductionUpdate::queueCreateUnit( const ThingTemplate *unitType, ProductionID productionID ){- const ProductionUpdateModuleData *data = getProductionUpdateModuleData();-// if we can't create the unit do nothingif( TheBuildAssistant->canMakeUnit( getObject(), unitType ) != CANMAKE_OK )return FALSE;@@ -442,22 +458,9 @@ Bool ProductionUpdate::queueCreateUnit( const ThingTemplate *unitType, Productio// allocate a new production entryProductionEntry *production = newInstance(ProductionEntry);- // Check to see if there is a quantity modifier entry. What this means is if we are building a particular unit- // and it has a modifier, we build that number of objects instead of just one. A good example is the Chinese- // barracks building redguards -- they are built 4 at a time, but the user or script only pays for one and- // builds four for that price!- production->m_productionQuantityTotal = 1;+ production->m_productionQuantityTotal = getQuantityPerOrder( unitType );production->m_productionQuantityProduced = 0;- for( std::vector<QuantityModifier>::const_iterator it = data->m_quantityModifiers.begin(); it != data->m_quantityModifiers.end(); ++it )- {- const ThingTemplate* productionTemplate = TheThingFactory->findTemplate( it->m_templateName );- if( productionTemplate && productionTemplate->isEquivalentTo( unitType ) )- {- production->m_productionQuantityTotal = it->m_quantity;- break;- }- }-+// assing production entry dataproduction->m_type = PRODUCTION_UNIT;production->m_objectToProduce = unitType;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 11bbe0c4d..399fe8c8a 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -1003,6 +1003,22 @@ TEST(unit_limit_shares_840_between_the_players)CHECK_EQ( UnitLimitPerPlayer( 1 ), 840 );}+/* Player.cpp: a build is refused when it and its payload would go past the share, not when the+ share is already full. */+TEST(unit_limit_charges_a_transport_for_its_payload)+{+ /* one short of 105: a tank fits, a pair of Red Guards and a Troop Crawler with its eight do not */+ CHECK( !UnitCapRefuses( 104, 1, 105 ) );+ CHECK( UnitCapRefuses( 104, 2, 105 ) );+ CHECK( !UnitCapRefuses( 103, 2, 105 ) );+ CHECK( UnitCapRefuses( 104, 9, 105 ) );+ CHECK( !UnitCapRefuses( 96, 9, 105 ) );+ CHECK( UnitCapRefuses( 105, 1, 105 ) );++ /* no limit in the lobby refuses nothing */+ CHECK( !UnitCapRefuses( 5000, 9, 0 ) );+}+/* 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,