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): per-rung superweapon ration and base-first aim
Olcay Seygan027c54b67d19
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f29be0ad3..4a240cdea 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -296,7 +296,9 @@ found and fixed — EA's own, not port damage.**- Measured over a half-hour match: a Particle Cannon that fired at the identical spot three times running now spreads six shots over five parts of the map, and comes back to the first one at the end, when what you rebuilt there is worth twice what it killed.- The spy satellite goes through the same targeting, and it was scanning one cell of one base seventeen times a match. It sweeps now.- The computer drives its Particle Cannon's beam the way you do. It used to draw the same short S across the aim point and burn empty ground on either side of it; now the beam walks from one cluster to the next, leaving each the moment what stood there is dead. Fired into five groups of six Scorpions, the old sweep killed 4. Medium now kills 8 and Hard, which drives at double speed, 11. Easy keeps the old sweep. Replays recorded before this change play out differently.-- Medium and Hard aim their strikes at your economy. A supply center, black market, hacker, drop zone, captured derrick, strategy center or palace counts double its price on Medium and triple on Hard, and never less than 1,000 extra, so a cheap derrick still draws fire. The army used to soak up every nuke because it was the only thing that shot back; losing a supply center is felt for the rest of the match. Easy and the computer in missions and Challenges aim as before.+- Medium and Hard aim their strikes at your economy. A supply center, black market, hacker, drop zone, captured derrick, strategy center or palace counts double its price on Medium and triple on Hard, and never less than 1,000 extra, so a cheap derrick still draws fire. The army used to soak up every nuke because it was the only thing that shot back; losing a supply center is felt for the rest of the match.+- Players on v3.1.0 still watched nukes land on their army. The extra weight on anything that shoots back was the same on every difficulty, so it kept winning. Easy keeps it, Medium counts it at half, and Hard drops it and goes for your base: war factories, barracks, airfields and power plants now count like the economy buildings above, and so does a superweapon, though at the 1,000 floor rather than its price, since a strike seldom brings one down. Hard only turns on your army when it knows none of your buildings. Over twelve four-player Hard matches on Twilight Flame, 14 of 33 superweapon shots fell mostly on buildings before and 23 of 36 after; against Easy opponents, 17 of 30 before and 27 of 29 after. The Particle Cannon's beam is driven by the same weights. Replays recorded before this change play out differently.+- The computer in Generals' Challenge and in missions aims exactly as it did in 2003: price alone, no threat weight, no army hunting and no memory of where it last fired. The earlier note on this said "as before", but the threat weight and the army hunting had reached those opponents too.## Generals powers the computer actually meant to buy@@ -1221,7 +1223,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- No Superweapons can be picked. The dropdown sits low on the settings page, and its last row hung past the bottom edge of the panel: it drew, but a click on it went to nobody and the list stayed on whatever it said before. Any dropdown row past the edge of its panel takes the click now.- 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.- No Superweapons leaves China its upgrades. The Nuclear Missile silo is where China buys Uranium Shells, Nuclear Tanks and Neutron Shells, so banning it took them off every China general. Each player may now put up one silo under No, the Superweapon General too, and its missile never launches. Nothing treats it as a superweapon either: no fire button, no shortcut, no countdown on anybody's screen, no announcer telling the enemy one is up, and the doors stay shut. The banner under the match clock had not heard: eight Tank Generals under No put up eight red "built" banners, one per silo, and a player read that as eight nukes on the way. A silo whose missile never launches goes up with no banner and no line in the match feed now, and the computer no longer picks nuke targets, up to thirty times a second, for a missile it cannot fire. The Particle Cannon and the Scud Storm are still banned. A replay of a No Superweapons match recorded before this, where a silo went up or a missile flew, will not play back the same.-- The computer pays for every superweapon in base defences. Twelve finished defences let it put up one, twenty-four let it put up two, and with fewer than twelve it waits. It was four until the computer learned to build its guns as a steady mix. Its Particle Cannons, silos and Scud Storms all count against one allowance, and a superweapon counts from the moment its foundation goes down, so it cannot start two on the same twelve towers. A defence counts only once it is finished: a scaffold put down and cancelled unlocks nothing. Tunnel Networks and Propaganda Towers count as defences; the tunnel a Sneak Attack drops for free does not. The silo whose missile never launches, under No Superweapons or Pro Rules, is only there for China's upgrades and goes up without a single tower. Lose its towers and the superweapons it has keep standing, but the next one waits. You are not asked for towers at all: for a human player the lobby's limit and Pro Rules are the whole rule, as they were before the towers rule came in, and the buttons never grey out for want of defences. Campaign and Generals Challenge missions are left as they were. A replay from a build that held humans to the towers too plays out differently if a human's superweapon was turned away in it.+- The computer pays for every superweapon in base defences. On Hard twelve finished defences let it put up one, twenty-four let it put up two, and with fewer than twelve it waits. It was four until the computer learned to build its guns as a steady mix. Medium asks for six and Easy for three, because the twelve held them back for good: their bases never stand that many. Over twelve four-player Medium matches on Twilight Flame the median Medium base peaked at nine guns, and 3 of 48 Medium sides built a superweapon in 25 minutes. With six, 36 of 48 did. Easy's own script still keeps its first superweapon back for most of half an hour. Its Particle Cannons, silos and Scud Storms all count against one allowance, and a superweapon counts from the moment its foundation goes down, so it cannot start two on the same twelve towers. A defence counts only once it is finished: a scaffold put down and cancelled unlocks nothing. Tunnel Networks and Propaganda Towers count as defences; the tunnel a Sneak Attack drops for free does not. The silo whose missile never launches, under No Superweapons or Pro Rules, is only there for China's upgrades and goes up without a single tower. Lose its towers and the superweapons it has keep standing, but the next one waits. You are not asked for towers at all: for a human player the lobby's limit and Pro Rules are the whole rule, as they were before the towers rule came in, and the buttons never grey out for want of defences. Campaign and Generals Challenge missions are left as they were. A replay from a build that held humans to the towers too plays out differently if a human's superweapon was turned away in it.- 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.## Pro Rules, in every network gamediff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex abe050d5a..bf3ee80f6 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -154,14 +154,14 @@ 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 );-// A computer player's superweapons are paid for in base defences: every DEFENSES_PER_SUPERWEAPON-// finished defences it stands allow it one superweapon, counted across every type (four until-// the owner raised it to twelve). A human is held-// only by the lobby's rule and Pro Rules. Whether one more is refused,-// given the finished defences and the superweapons he already has, foundations included. It sits-// on top of the lobby's rule and never loosens it.+// A computer player's superweapons are paid for in base defences: every defensesPerSuperweapon+// finished defences it stands allow it one superweapon, counted across every type. The number is+// the rung's (AIDifficultyProfile::m_superweaponDefenses), DEFENSES_PER_SUPERWEAPON on Hard, and+// 0 asks for none. A human is held only by the lobby's rule and Pro Rules. Whether one more is+// refused, given the finished defences and the superweapons he already has, foundations included.+// It sits on top of the lobby's rule and never loosens it.enum { DEFENSES_PER_SUPERWEAPON = 12 };-Bool SuperweaponDefenseCapRefuses( Int finishedDefenses, Int superweapons );+Bool SuperweaponDefenseCapRefuses( Int finishedDefenses, Int superweapons, Int defensesPerSuperweapon );// Only a defence somebody paid for counts. The Sneak Attack tunnel, its Start and every general's// copy are the only FS_BASE_DEFENSE templates with no BuildCost: a power drops them for free.Bool DefenseCountsForSuperweapons( Int buildCost );diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex 62df80bcc..f31c93186 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -266,7 +266,9 @@ struct AIDifficultyProfile// SuperweaponsReal m_beamSteerSeconds; ///< how often a firing Particle Cannon's beam is driven onto the richest ground near it; 0 = the retail S curve- Real m_strikeEconomyWeight; ///< what a supply centre, black market, hacker or strategy centre is worth to a strike on top of its price, in prices; 0 = price alone+ Real m_strikeEconomyWeight; ///< what a factory, power plant, superweapon, supply centre, black market, hacker or strategy centre is worth to a strike on top of its price, in prices; 0 = price alone+ Real m_strikeThreatWeight; ///< what an armed unit or gun is worth to a strike on top of its price, in combat power; 0 = price alone, and his army is a candidate only when none of his buildings is+ Int m_superweaponDefenses; ///< finished base defences each superweapon asks for (Player::canBuildMoreOfType); 0 = none};//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex 3691391c1..c9b6308af 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -475,7 +475,7 @@ protected:* player index and only what that player can see (or, for a building, has ever seen) is* counted; -1 keeps the omniscient answer for a caller that is not a player's own thinking. */static Int getPlayerSuperweaponValue( Coord3D *center, Int playerNdx, Real radius, Bool includeMilitaryUnits = TRUE, Int observerNdx = -1,- Real economyWeight = 0.0f );+ Real economyWeight = 0.0f, Real threatWeight = 0.0f );// End of aiplayer interface.protected:@@ -536,6 +536,7 @@ protected:/// what a superweapon aimed here is worth, with the shots already on their way taken offInt superweaponScore( Coord3D *center, Int playerNdx, Real radius, Bool targetMilitaryUnits );Real strikeEconomyWeight( void ); ///< the rung's m_strikeEconomyWeight for a skirmish AI, 0 for a campaign one+ Real strikeThreatWeight( void ); ///< the rung's m_strikeThreatWeight for a skirmish AI, 0 for a campaign onevoid noteSuperweaponAim( const Coord3D *pos ); ///< remember a spot, so the next shot goes elsewhereprotected:diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex bb7563ed7..ff220e894 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -3383,9 +3383,9 @@ Bool UnitCapRefuses( Int unitsTowardCap, Int unitsItAdds, UnsignedInt unitCap )}//=============================================================================-Bool SuperweaponDefenseCapRefuses( Int finishedDefenses, Int superweapons )+Bool SuperweaponDefenseCapRefuses( Int finishedDefenses, Int superweapons, Int defensesPerSuperweapon ){- return superweapons >= finishedDefenses / DEFENSES_PER_SUPERWEAPON;+ return defensesPerSuperweapon > 0 && superweapons >= finishedDefenses / defensesPerSuperweapon;}Bool DefenseCountsForSuperweapons( Int buildCost )@@ -3564,12 +3564,13 @@ Bool Player::canBuildMoreOfType( const ThingTemplate *whatToBuild, Int unitsPerO{SuperweaponDefenseCount count = { 0, 0 };iterateObjects( countSuperweaponDefenses, &count );- // a Tech computer's first superweapon is its plan, and a GLA Air one's SCUD Storm, and waits for a few- // guns rather than twelve, Easy the most+ // a Tech computer's first superweapon is its plan, and a GLA Air one's SCUD Storm, and waits for+ // at most this many guns, whatever the rung's own ration asksstatic const Int TECH_FIRST_DEFENSES[ AISKILL_COUNT ] = { 8, 6, 4 };- const Bool techFirst = count.superweapons == 0 && m_ai && m_ai->superweaponIsPlan() &&+ const Bool techFirst = count.superweapons == 0 && m_ai->superweaponIsPlan() &&count.defenses >= TECH_FIRST_DEFENSES[ getAISkillLevel() ];- if ( !techFirst && SuperweaponDefenseCapRefuses( count.defenses, count.superweapons ) )+ if ( !techFirst && SuperweaponDefenseCapRefuses( count.defenses, count.superweapons,+ m_ai->getSkillProfile()->m_superweaponDefenses ) )return false;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex 9f29cdc03..e29980825 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1305,12 +1305,25 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* on armed units sent every strike at the army; a strike on the economy is the one a player feels* for the rest of the match. Easy keeps price alone, Medium doubles it, Hard triples it.*- * scoutS maxSc decis cntr mass ttk indiv team infl focus save harv expand guard hoard econ micro gate answer massU bankS floor payoff upgr nonc share maxF fMult push minPow siege beam strikeE */+ * strikeT and swDef came in on 2026-10-20, from v3.1.0 players: the computer seldom built a+ * superweapon and spent the ones it built on their army. strikeT is the threat weight that was a+ * flat 2 on every rung; Easy keeps it, Medium halves it, Hard drops it and looks at his army only when+ * none of his buildings is known. strikeE now also covers factories, power plants and superweapons+ * (the last at the 1,000 floor, since a strike seldom kills one), and Medium's went from 1 to 2, Hard's+ * from 2 to 3. swDef is the guns each superweapon asks for, 12 on every rung before: over twelve+ * four-player matches on Twilight Flame the median side peaked at 4 finished guns on Easy, 9 on Medium+ * and 18 on Hard, so Medium+ * built 3 superweapons in 48 sides over 25 minutes. At 6 it built 36, and 29 of its 38 shots landed+ * mostly on buildings. Hard's went from 14 of 33 shots mostly on buildings to 23 of 36, and against+ * Easy from 17 of 30 to 27 of 29. Easy's 3 is unmeasured in play: its script clock still holds its+ * first superweapon past 25 minutes, so none was built either way.+ *+ * scoutS maxSc decis cntr mass ttk indiv team infl focus save harv expand guard hoard econ micro gate answer massU bankS floor payoff upgr nonc share maxF fMult push minPow siege beam strikeE strikeT swDef */static const AIDifficultyProfile s_defaultSkillLadder[ AISKILL_COUNT ] ={- /* Easy */ { 75.0f, 1, 7.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0, FALSE, FALSE, FALSE, FALSE, FALSE, 120.0f, 6000, 4.0f, 720.0f, 0.05f, 0.05f, 3, 0.0f, 360.0f, 1500.0f, 80.0f, 0.00f, 0.0f },- /* Medium */ { 45.0f, 1, 3.0f, 0.50f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 6000, FALSE, FALSE, FALSE, FALSE, FALSE, 60.0f, 5000, 2.5f, 420.0f, 0.05f, 0.25f, 5, 3.0f, 300.0f, 2000.0f, 120.0f, 1.00f, 1.0f },- /* Hard */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE, TRUE, TRUE, FALSE, 30.0f, 4000, 1.5f, 180.0f, 0.05f, 1.00f, 8, 2.0f, 240.0f, 4500.0f, 160.0f, 0.25f, 2.0f }+ /* Easy */ { 75.0f, 1, 7.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0, FALSE, FALSE, FALSE, FALSE, FALSE, 120.0f, 6000, 4.0f, 720.0f, 0.05f, 0.05f, 3, 0.0f, 360.0f, 1500.0f, 80.0f, 0.00f, 0.0f, 2.0f, 3 },+ /* Medium */ { 45.0f, 1, 3.0f, 0.50f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 6000, FALSE, FALSE, FALSE, FALSE, FALSE, 60.0f, 5000, 2.5f, 420.0f, 0.05f, 0.25f, 5, 3.0f, 300.0f, 2000.0f, 120.0f, 1.00f, 2.0f, 1.0f, 6 },+ /* Hard */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE, TRUE, TRUE, FALSE, 30.0f, 4000, 1.5f, 180.0f, 0.05f, 1.00f, 8, 2.0f, 240.0f, 4500.0f, 160.0f, 0.25f, 3.0f, 0.0f, DEFENSES_PER_SUPERWEAPON }};//-------------------------------------------------------------------------------------------------@@ -2214,6 +2227,8 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*{ "SiegeTrail", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_siegeTrail ) },{ "BeamSteerSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_beamSteerSeconds ) },{ "StrikeEconomyWeight", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_strikeEconomyWeight ) },+ { "StrikeThreatWeight", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_strikeThreatWeight ) },+ { "SuperweaponDefenses", INI::parseInt, NULL, offsetof( AIDifficultyProfile, m_superweaponDefenses ) },{ NULL, NULL, NULL, 0 }};diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 9c1d8ea25..571595ad8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -2055,17 +2055,18 @@ static void summarizeStrike( const Coord3D *at, Int playerNdx, Real radius, Int//----------------------------------------------------------------------------------------------------------/** What a superweapon aimed at this spot is worth to this player right now.*- * The score itself is EA's - the price of everything inside the blast, with the threat weight and- * the rung's economy weight on top (getPlayerSuperweaponValue) - and the fade on top of it+ * The score itself is EA's - the price of everything inside the blast, with the rung's threat and+ * economy weights on top (getPlayerSuperweaponValue) - and the fade on top of it* is what stops the salvo. A negative score belongs to a sneak attack, which reads defended ground* as a cost rather than a prize; fading that would flatter exactly the ground it is avoiding.+ * A Challenge or mission opponent gets neither weight nor fade: it aims as retail did.*///----------------------------------------------------------------------------------------------------------Int AIPlayer::superweaponScore( Coord3D *center, Int playerNdx, Real radius, Bool targetMilitaryUnits ){const Int value = getPlayerSuperweaponValue( center, playerNdx, radius, targetMilitaryUnits, m_player->getPlayerIndex(),- strikeEconomyWeight() );- if( value <= 0 )+ strikeEconomyWeight(), strikeThreatWeight() );+ if( value <= 0 || !isSkirmishAI() )return value;const UnsignedInt now = TheGameLogic->getFrame();@@ -2087,13 +2088,18 @@ Int AIPlayer::superweaponScore( Coord3D *center, Int playerNdx, Real radius, Boo}//-----------------------------------------------------------------------------------------------------------/** A Challenge or mission opponent aims as the map script was written for: price and threat alone. */+/** A Challenge or mission opponent aims as the map script was written for: price alone. *///----------------------------------------------------------------------------------------------------------Real AIPlayer::strikeEconomyWeight( void ){return isSkirmishAI() ? getSkillProfile()->m_strikeEconomyWeight : 0.0f;}+Real AIPlayer::strikeThreatWeight( void )+{+ return isSkirmishAI() ? getSkillProfile()->m_strikeThreatWeight : 0.0f;+}+//----------------------------------------------------------------------------------------------------------/** Remember a spot the next shot should leave alone.*@@ -2227,10 +2233,12 @@ Bool AIPlayer::computeSuperweaponTarget(const SpecialPowerTemplate *power, Coord// the ground his buildings are on: getPlayerStructureBounds measures structures, so the wave// parked on our own doorstep was never a candidate at all - the AI could only ever shoot at// real estate. Offer what we can see of his army as centres too and let the same score choose.+ // A rung that puts no threat weight on his army (Hard) looks there only when the grid found+ // nothing of his worth a shot; a Challenge or mission opponent never, as in retail.// ponytail: a value pass per armed unit, which is only paid on a frame a superweapon is ready.//Player *enemy = ThePlayerList->getNthPlayer( playerNdx );- if( targetMilitaryUnits && enemy != NULL )+ if( targetMilitaryUnits && enemy != NULL && isSkirmishAI() && ( strikeThreatWeight() > 0.0f || cash <= 0 ) ){const Int observerNdx = m_player->getPlayerIndex();Player::PlayerTeamList::const_iterator teamIt;@@ -2319,30 +2327,32 @@ Bool AIPlayer::computeSuperweaponTarget(const SpecialPowerTemplate *power, Coord}-/** How much an armed target is worth on top of its price, so the shot goes where the threat is. */-const Real SUPERWEAPON_THREAT_WEIGHT = 2.0f;--/** The least an economy target counts for before the rung's weight: a captured derrick's build price+/** The least a strategic target counts for before the rung's weight: a captured derrick's build price* is next to nothing and it pays for the whole match.* ponytail: one flat floor for every kind; a per-kind income estimate if derricks still go unhit. */const Real SUPERWEAPON_ECONOMY_FLOOR = 1000.0f;-/** What pays for his army or opens his tech: a strike there is felt for the rest of the match. */-static Bool isEconomyOrTechTarget( const Object *obj )+/** What builds his army, powers his base, pays for it or opens his tech: a strike there is felt for+ * the rest of the match, where the army it could have hit is rebuilt in a minute. */+static Bool isStrategicTarget( const Object *obj ){return obj->isKindOf( KINDOF_CASH_GENERATOR ) || obj->isKindOf( KINDOF_FS_SUPPLY_CENTER ) ||obj->isKindOf( KINDOF_FS_BLACK_MARKET ) || obj->isKindOf( KINDOF_MONEY_HACKER ) ||obj->isKindOf( KINDOF_FS_INTERNET_CENTER ) || obj->isKindOf( KINDOF_FS_SUPPLY_DROPZONE ) ||- obj->isKindOf( KINDOF_FS_STRATEGY_CENTER ) || obj->isKindOf( KINDOF_FS_ADVANCED_TECH );+ obj->isKindOf( KINDOF_FS_STRATEGY_CENTER ) || obj->isKindOf( KINDOF_FS_ADVANCED_TECH ) ||+ obj->isKindOf( KINDOF_FS_FACTORY ) || obj->isKindOf( KINDOF_FS_BARRACKS ) ||+ obj->isKindOf( KINDOF_FS_WARFACTORY ) || obj->isKindOf( KINDOF_FS_AIRFIELD ) ||+ obj->isKindOf( KINDOF_FS_POWER ) || obj->isKindOf( KINDOF_FS_SUPERWEAPON );}//----------------------------------------------------------------------------------------------------------/**- * Get the target value for structures in an area. economyWeight is what an economy or tech target- * (isEconomyOrTechTarget) adds on top of its price, in prices.+ * Get the target value for structures in an area. economyWeight is what a strategic target+ * (isStrategicTarget) adds on top of its price, in prices; threatWeight what anything armed adds,+ * in its combat power. Both 0 is EA's score.*/Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real radius, Bool includeMilitaryUnits, Int observerNdx,- Real economyWeight )+ Real economyWeight, Real threatWeight ){if (radius < 4*PATHFIND_CELL_SIZE_F){@@ -2421,19 +2431,24 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real radvalue = value / 10; // Superweapons cannot be killed by any superweapon, so we don't want to target them as highly. jba.}//- // What a superweapon is for. Price alone ranks a supply stash above the tank- // column parked beside it, which is why these shots landed in the money and not- // in the army. What can shoot is worth several times its price to be rid of:- // aiCombatPower reads ThingTemplate's ThreatValue where the data sets it and- // falls back on cost, the same weighing the retreat and the counter score use.+ // The rung's threat weight: what can shoot is worth this many times its combat+ // power on top of its price (aiCombatPower reads the ThreatValue where the data+ // sets it and falls back on cost). At 2 on every rung it sent nearly every strike+ // at the army, which the player rebuilds in a minute; Easy keeps that, Medium+ // halves it and Hard drops it.//- if( includeMilitaryUnits )- value += aiCombatPower( pObj ) * SUPERWEAPON_THREAT_WEIGHT;-- // ... and the threat weight alone sent every strike at the army. What pays for- // it, and the building that opens the next tier, is the hit felt all match.- if( economyWeight > 0.0f && !applyNegValue && isEconomyOrTechTarget( pObj ) )- value += economyWeight * max( (Real)pObj->getTemplate()->calcCostToBuild( pPlayer ), SUPERWEAPON_ECONOMY_FLOOR );+ if( includeMilitaryUnits && threatWeight > 0.0f )+ value += aiCombatPower( pObj ) * threatWeight;++ // What builds and pays for the army, powers the base and opens the next tier is+ // the hit felt all match. A superweapon counts at the floor rather than its price:+ // EA's note above holds, a strike damages one and seldom kills it, and its power+ // plants are what switch it off.+ if( economyWeight > 0.0f && !applyNegValue && isStrategicTarget( pObj ) )+ {+ const Real price = pObj->isKindOf( KINDOF_FS_SUPERWEAPON ) ? 0.0f : (Real)pObj->getTemplate()->calcCostToBuild( pPlayer );+ value += economyWeight * max( price, SUPERWEAPON_ECONOMY_FLOOR );+ }if( applyNegValue ){@@ -7312,7 +7327,8 @@ void AIPlayer::buildAsap( const ThingTemplate *tmpl )* ten seconds, reaches 75: twelve and a half minutes, or seven and a half once the enemy owns a tech* building, and then one copy. A player who went seven Hard AIs against one saw a single nuke in the* whole match. The owner's call: no clock. As soon as a dozer can build a superweapon, the money- * is in the bank and DEFENSES_PER_SUPERWEAPON guns stand, the first one goes up. More follow as the+ * is in the bank and the rung's ration of guns stands (m_superweaponDefenses, DEFENSES_PER_SUPERWEAPON+ * here), the first one goes up. More follow as the* base grows, one per that many guns, as the guns grow with the army; unrationed, they took the money* the army needed. That ration binds computer players only (Player::canBuildMoreOfType), and the* lobby's superweapon setting and Pro Rules still bind beside it; canMakeUnit asks all three.@@ -7433,7 +7449,7 @@ Bool AIPlayer::richestGroundNear( const Coord3D *spot, Real radius, Coord3D *aim{Player *other = ThePlayerList->getNthPlayer( p );if( other != m_player && m_player->getRelationship( other->getDefaultTeam() ) == ENEMIES )- value += getPlayerSuperweaponValue( &pos, p, radius, TRUE, me );+ value += getPlayerSuperweaponValue( &pos, p, radius, TRUE, me, strikeEconomyWeight(), strikeThreatWeight() );}const Real distance = sqrt( (Real)(x * x + y * y) ) * step;const Real worth = value * (1.0f - 0.5f * distance / BEAM_STEER_REACH);diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 61f89ef68..e34ad0089 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -12844,6 +12844,18 @@ TEST(the_bank_target_and_the_upgrade_the_army_pays_for)CHECK_EQ( 0.0f, data.m_skill[ AISKILL_EASY ].m_beamSteerSeconds );CHECK( data.m_skill[ AISKILL_MEDIUM ].m_beamSteerSeconds > data.m_skill[ AISKILL_BRUTAL ].m_beamSteerSeconds );CHECK( data.m_skill[ AISKILL_BRUTAL ].m_beamSteerSeconds > 0.0f && data.m_skill[ AISKILL_BRUTAL ].m_beamSteerSeconds < 0.5f );+ // strikes: the higher the rung, the more a strike looks for his base over his army, and the fewer+ // guns a lower rung needs before a superweapon, so Easy and Medium can reach one at all+ for( Int s = 1; s < AISKILL_COUNT; ++s )+ {+ const AIDifficultyProfile &lower = data.m_skill[ s - 1 ];+ const AIDifficultyProfile &upper = data.m_skill[ s ];+ CHECK( upper.m_strikeEconomyWeight > lower.m_strikeEconomyWeight );+ CHECK( upper.m_strikeThreatWeight < lower.m_strikeThreatWeight );+ CHECK( upper.m_superweaponDefenses >= lower.m_superweaponDefenses );+ }+ CHECK_EQ( 0.0f, data.m_skill[ AISKILL_BRUTAL ].m_strikeThreatWeight );+ CHECK_EQ( (Int)DEFENSES_PER_SUPERWEAPON, data.m_skill[ AISKILL_BRUTAL ].m_superweaponDefenses );}@@ -16327,29 +16339,37 @@ TEST(an_open_dropdown_owns_the_rows_that_hang_past_its_panel)CHECK( !OpenWindowOwnsPoint( TRUE, boxX, boxY, boxWidth, boxHeightOpen, 900, 660 ) );}-/* Twelve finished base defences buy one superweapon, twenty-four buy two, whatever mix of silo,- uplink and storm they go to. Player::canBuildMoreOfType counts and asks this; the lobby's cap is- checked beside it and still refuses on its own. */+/* On Hard twelve finished base defences buy one superweapon, twenty-four buy two, whatever mix of+ silo, uplink and storm they go to; the lower rungs ask for fewer, from their skill profile.+ Player::canBuildMoreOfType counts and asks this; the lobby's cap is checked beside it and still+ refuses on its own. */TEST(twelve_finished_defenses_pay_for_each_superweapon){- CHECK_EQ( (Int)DEFENSES_PER_SUPERWEAPON, 12 );+ const Int H = DEFENSES_PER_SUPERWEAPON;+ CHECK_EQ( H, 12 );// fewer than twelve buys nothing, four included, which bought one before- CHECK( SuperweaponDefenseCapRefuses( 0, 0 ) );- CHECK( SuperweaponDefenseCapRefuses( 4, 0 ) );- CHECK( SuperweaponDefenseCapRefuses( 11, 0 ) );+ CHECK( SuperweaponDefenseCapRefuses( 0, 0, H ) );+ CHECK( SuperweaponDefenseCapRefuses( 4, 0, H ) );+ CHECK( SuperweaponDefenseCapRefuses( 11, 0, H ) );// twelve buy the first, and a foundation already down spends it- CHECK( !SuperweaponDefenseCapRefuses( 12, 0 ) );- CHECK( SuperweaponDefenseCapRefuses( 12, 1 ) );- CHECK( SuperweaponDefenseCapRefuses( 23, 1 ) );+ CHECK( !SuperweaponDefenseCapRefuses( 12, 0, H ) );+ CHECK( SuperweaponDefenseCapRefuses( 12, 1, H ) );+ CHECK( SuperweaponDefenseCapRefuses( 23, 1, H ) );// twenty-four the second- CHECK( !SuperweaponDefenseCapRefuses( 24, 1 ) );- CHECK( SuperweaponDefenseCapRefuses( 24, 2 ) );+ CHECK( !SuperweaponDefenseCapRefuses( 24, 1, H ) );+ CHECK( SuperweaponDefenseCapRefuses( 24, 2, H ) );// losing defences never pulls a standing superweapon down, it only stops the next one- CHECK( SuperweaponDefenseCapRefuses( 12, 2 ) );+ CHECK( SuperweaponDefenseCapRefuses( 12, 2, H ) );++ // a smaller ration buys sooner, and none asks for nothing+ CHECK( !SuperweaponDefenseCapRefuses( 4, 0, 4 ) );+ CHECK( SuperweaponDefenseCapRefuses( 4, 1, 4 ) );+ CHECK( !SuperweaponDefenseCapRefuses( 0, 0, 0 ) );+ CHECK( !SuperweaponDefenseCapRefuses( 0, 5, 0 ) );// a Sneak Attack tunnel costs nothing and buys nothing; a Tunnel Network at 800 doesCHECK( !DefenseCountsForSuperweapons( 0 ) );@@ -16387,8 +16407,8 @@ TEST(superweapon_defense_allowance_binds_computer_players_only)CHECK( SuperweaponNeedsDefenses( AsciiString( "AmericaParticleCannonUplink" ), FALSE, SUPERWEAPONS_LIMIT, TRUE ) );// and for a computer a storm's waiting hole still spends the twelve towers it stood on- CHECK( SuperweaponDefenseCapRefuses( 12, RebuildHoleHoldsSuperweapon( TRUE, FALSE ) ? 1 : 0 ) );- CHECK( !SuperweaponDefenseCapRefuses( 12, RebuildHoleHoldsSuperweapon( FALSE, FALSE ) ? 1 : 0 ) );+ CHECK( SuperweaponDefenseCapRefuses( 12, RebuildHoleHoldsSuperweapon( TRUE, FALSE ) ? 1 : 0, DEFENSES_PER_SUPERWEAPON ) );+ CHECK( !SuperweaponDefenseCapRefuses( 12, RebuildHoleHoldsSuperweapon( FALSE, FALSE ) ? 1 : 0, DEFENSES_PER_SUPERWEAPON ) );}/* The superweapon rule is a mode, and what a mode leaves you depends on who you are playing. The