Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gamelogic): ai strikes the economy, retail fire timing, faster guard scans

Olcay Seygan3bb944406fcb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4561181aa..a775ec995 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ found and fixed — EA's own, not port damage.**
- Mission timers keep EA's clock. A map's countdown still ticks 30 times a second, because the missions read a running timer's number and act on it: the second American mission declares victory when its "Win" timer drops below 1700, and on the first 60-step builds that came after 38 seconds instead of 10. The cutscene cues, the random music pick in the campaigns and the generals' challenges, the shell map's camera loop and the lightning on Eastern Everglades and Rocky Rampage were off the same way, 30 maps in all, and run on their original timing again. Custom maps get the same.
- Normal speed is now the fastest a skirmish or a mission runs. The game speed choice in the skirmish lobby offers x0.5, x0.75 and x1, and x1 is 60 steps a second; the x1.5 and x2 it used to have are gone. A lobby left on one of them, or a saved game made at one, comes back at x1, and the speed console command and a mission's own script stay between half speed and normal as well. Replays still play as fast as you ask, and network games are untouched.
- Replays and saved games from earlier versions will not load in this one. A player on an earlier version cannot join a match with a player on this version, whichever of them hosts, so a LAN party needs everyone on the same build.
+- Guns fire at their 2003 rate again. After a shot the game goes back to aiming for a step before it can fire again, which at 30 steps put a 100 millisecond Quad Cannon on a shot every 0.133 seconds; at 60 the same loop fired it every 0.100, a third faster. Shot delays and reloads are rounded to the old step and a gun's next shot is held to the old rhythm, so every weapon fires on the frames it did in 2003. A turret with no turning speed in its data rose twice as fast as it should, aircraft weighed their thrust against gravity at half strength, and a unit hit on the step before still counted as untouched for stealth. All three keep EA's timing now.
## Zero Hour on a Mac, on Linux and on the Steam Deck
@@ -191,6 +192,7 @@ 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.
## Generals powers the computer actually meant to buy
@@ -213,6 +215,8 @@ found and fixed — EA's own, not port damage.**
- With Share Income set to All Income it leaves its allies' piles alone. Every payment is already split across the team, so a computer that put a supply centre beside its ally's pile added nothing and emptied that pile twice as fast. It now expands only to piles nobody on its side is working. Over eight 2v2 matches on Twilight Flame, loads taken from an ally's pile went from 396 to 54 and the team's income stayed where it was. Replays recorded before this change play out differently.
- It leaves a pile alone when someone else is already working it. The computer only checked for its own supply centre beside a pile, so a pile inside an ally's base, or a third player's, looked free, and it walked a supply centre in next to theirs with a Patriot or a Gatling cannon after it. It now skips any pile with another side's building beside it, friend or foe. Over eight 2v2 matches on Twilight Flame, buildings it put down at a pile someone else held went from 116 to 2, and over eight four-way matches from 8 to 4, with spending where it was. Replays recorded before this change play out differently.
- It keeps its money-makers and its superweapons at home. A Hard computer with a full base looked for room further and further out until the map ended, and a black market or a Scud Storm could go up alone on ground nobody held. Those buildings, and the tech building a superweapon waits on, now go inside the base or at its edge, and when there is no room they are not built: the money goes into another factory. Expansions are held to the same standard: a supply centre only goes to a pile on its own side of the map and within reach of home, never to one with an enemy standing at it, and the next expansion waits until the last one has a gun or a guard beside it. Replays recorded before this change play out differently.
+- A guarded supply pile no longer stops its expansion. One enemy tank parked beside the nearest pile held a Hard computer's expansion for ten minutes while a free pile sat one valley over; it takes the nearest safe pile now, and the unsafe one only when nothing else is left.
+- It captures the derricks behind its own base first. Each capture used to send the engineer on to the derrick nearest where he stood, so the round walked out into the middle of the map and the ones at home waited for minutes.
## The computer spends its money
@@ -255,6 +259,7 @@ found and fixed — EA's own, not port damage.**
- It builds its economy before it comes for you. No attack leaves a computer base in the opening minutes: six on Easy, five on Medium, four on Hard, and on Medium and Hard not before its first supply drop zone or black market stands, when it can build one. Medium and Easy now put that drop zone or black market up in the opening too, where only Hard did before. And it stops sending you two tanks at a time. A group too small to matter waits at home until enough has gathered to be an attack, about two tanks' worth on Easy, two and a half on Medium and five on Hard, even when the computer thinks it is winning. In one Hard against Hard match on Twilight Flame, the USA side's first attack left at six minutes instead of three and a quarter, after its drop zone, and the two sides sent 24 attacks instead of 47, 12 of them one to four units where 43 had been. Medium sent 9 instead of 19. Replays recorded before this change play out differently.
- Medium spends what it earns. On a map with plenty of supplies its five supply centres bring in 300 a second by the middle of a match, and its plan's three factories spent a sliver of that: six Medium China games against Easy on Twilight Flame ended with 125,000 to 230,000 unspent, and Medium won one of the six inside 25 minutes. Medium now puts a quarter of its spare income into extra units, adds factories up to five once its bank passes three times what it means to keep, and sends a smaller group out on its own. The same six games went to Medium, all six.
- Its artillery stays behind its tanks. Tomahawks, SCUD Launchers, Nuke and Inferno Cannons and Rocket Buggies walked in the same crowd as the rest of an attack, and the one that came round the corner first died to the first tank it met before its long gun was any use. Each one now keeps a little behind the attack's leading unit, farther on Hard than on Easy, and still fires at whatever comes into reach on the way. Replays recorded before this change play out differently.
+- A rich start gets spent. On 50,000 starting money the computer sat on the pile through the opening, because what it spends is a share of what it earns and in the first minutes it earns nothing. What the start handed out over the default now goes out at the difficulty's pace from the first pass, factories included. At the default money nothing changes.
## The computer picks its fights
- Which enemy it goes after was the nearest one and nothing else, plus a rule with its sign the wrong way round: an opponent who had lost his units or his production had his distance treated as half the map, so the computer ignored the one it was about to beat. That is what dragged matches out.
@@ -394,6 +399,7 @@ found and fixed — EA's own, not port damage.**
- A jet shot down in the air flies on before it falls. Its wings stopped working on the frame it was hit, so it dropped almost vertically and hit the ground under the spot it was killed at, which is the one thing a plane doing three hundred knots cannot do. It keeps its lift now and gives it up over the next second or so, carrying forward and nosing over as it goes.
- And the bombers come down at all. A B-52, a Spectre gunship, a cargo plane and an A-10 all left the falling speed out of their data, and nought means the lift exactly cancels gravity: shot down, they flew on at cruising height, burning, and blew up in the air still level. Every one of them now falls at half gravity or better, and the fireball waits for the ground instead of going off on a timer somewhere over the map. Measured on the way in: a B-52 falls for 2.8 seconds and lands, where it used to detonate at a hundred feet. On the way home it still did not: after the drop a bomber flies off the map on a precise course that is allowed three times its normal lift, which held a dead one up with lift to spare. A bomber shot down after its run now comes down like one shot down before it.
- Jets that end up on top of their target swing wide and come back on a straight run. A Raptor that came over a tank too close to fire used to bank toward it and keep banking, with the tank sitting inside its turn: one ordered onto an Overlord driving along beside it circled the tank for two and a half seconds without a shot and needed 7.3 seconds to get its four missiles off. It now holds its heading until the tank is far enough behind to turn round on, and comes back lined up: 4 seconds. A target behind the wing or just past it gets the same treatment, where the jet used to turn in, find itself over the target again and fly out anyway. Over 42 staged passes with the Raptor, the MiG, the Aurora and the Stealth Fighter, aimed at targets beside, under and behind them, parked and driving, the slowest Raptor run went from 7.3 seconds to 6.4 and the slowest MiG run from 5.6 to 4.7; on average the Raptor empties its racks 0.3 seconds sooner and the MiG 0.26. The Aurora drops its bomb on the same frame as before, a jet lined up on its target flies the same run as before, and jets fighting aircraft are untouched. A replay recorded before this change, with jets attacking the ground, will not play back the same.
+- A supply truck told to go somewhere as it pulls off the dock goes there. It used to finish the docking it had just left and drive back to the supplies, throwing your order away.
## The same game on both screens, and after loading
@@ -481,6 +487,8 @@ found and fixed — EA's own, not port damage.**
- Order confirmations are filed in one step instead of scanning the whole queue.
- A dropped order's retry wait stops doubling after two steps.
- A shell's flight path is worked out the same way on every machine. The game borrowed that sum from a DirectX library that, going by its code, picks how to do it by processor: one way on Intel chips, another on everyone else's. The two answers differ in the last digits, and when both were run over half a million calculations shaped like the game's own shell paths, nearly half came out slightly different. That is enough for two machines to disagree about where a shell is. Nobody has reported it in a match, but every machine now uses the same sum whatever its processor. A replay recorded on an Intel machine with an earlier version may not play back exactly.
+- A unit that was waiting for its route when you saved moves again after the load. The queue of route requests is not in the save, so it came back waiting for an answer nobody was going to give and stood there for the rest of the match.
+- Every player's bank and the map script's counters, timers and flags are part of the check machines compare each step, so a match that starts to disagree is caught the moment it does, before the difference reaches a unit.
## Sharper textures, for free
@@ -638,6 +646,7 @@ found and fixed — EA's own, not port damage.**
- A tank thrown by a carpet bomb or a MOAB is out of your hands until it comes down. A tank hit where it stood got its controls back on the very next frame, before it had left the ground, and anything already in the air got them back at the top of its arc, so it could drive in mid-air. Now the stun lasts until it lands and a few frames after, and a tank that comes down on its roof, in water it cannot drive through, on a cliff or off the edge of the map is lost, the way the game was written to do and never did. Over one carpet bomb, 16 of 20 units that lived through it came down still stunned where none did before, and one Paladin landed on its back. Replays recorded before this change play out differently.
- Wreckage and bodies that should not bounce, don't. The data tells debris and a soldier flung by a blast to lie where they land, and fifteen entries say so, but the game never read the number and bounced all of it the same. Replays recorded before this change play out differently.
- A Sentry Drone with its gun shoots what comes near it. Two seconds after you park it the drone turns invisible, and from then on it watched enemies walk past without a shot until you gave it an order: EA's data left out the one word that lets a hidden unit open fire on its own, and the line's own comment says what the word was for. Two parked drones with three Rebels walking by and a Technical pulling up beside them used to leave all four untouched; now none of the four is left. Firing still gives the drone away, as it always did. The same goes for the Air Force, Laser and Superweapon generals' drones. Replays recorded before this change play out differently.
+- Countermeasure flares look like flares. EA's sparks lived two frames and died at two thirds of their colour, a pale flicker at the zoom you play at. They are bigger, half again as many and a hotter white, and the smoke behind each one hangs for eight seconds instead of four and a half, so a volley leaves one trail across the sky.
## The nine generals, as their own data meant them
@@ -742,6 +751,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- A thrown vehicle's crash damage hits the pile once, not once per unit.
- A dying unit is no longer promoted by its last kill.
- Healing no longer counts as damage, so a medic stops revealing its stealth unit.
+- A guard deals with the enemy in its area before it goes for a crate, and comes back for the crate once the area is clear. A unit that killed something at long range only goes for the crate if it lies within its sight, so an artillery piece no longer drives out across the front for one.
## Circles are round, and a tunnel is one tunnel
@@ -1836,6 +1846,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- The rest of the same mob. A mob is a leader and ten rioters, and a rioter only reconsiders where it is standing once every sixteen frames - but it was woken on all sixteen anyway, just to be sent back to sleep, and every mob on the map is eleven of those. EA left a note in the code asking for exactly this and never came back to it. The rioters sleep properly now, and one whose mob is dead stops being woken at all. Eight mobs on the field is eighty rioters: where all eighty were woken every frame, five are. Measured against the number in the complaint rather than a comfortable one: a hundred mobs is 1,100 men and costs 4.3 milliseconds of a 33 millisecond frame, two hundred and fifty is 2,750 men and 7.1, four hundred is 4,400 men and 12.6, and not one frame of any of those three ran over budget. Four hundred mobs is past anything a match will produce; what the rioters cost there is a fifth of a millisecond.
- The first soldier out of your barracks cost eighteen milliseconds of a thirty-three millisecond frame. A unit's models were read off the disc the moment one of its kind first appeared, and that read landed on whatever frame the unit happened to walk out on. So did the first war factory, the first supply centre, the first of everything. That is why the opening of a match was the part that jerked: the opening of a match is nothing but things appearing for the first time. Everything a match can put on the field is now read during the loading screen, which costs about three seconds there and takes the hitches out of the game. EA wrote that loading pass and left it switched off; the code carries their own comment saying it exists "so that we don't have big pauses when building those objects".
+- Guards look for enemies only where enemies stand. Each map square now knows whose units touch it, and an idle guard's search skips every square holding only its own base or nothing at all, with the same answer it got by looking at everything. Route searches stop measuring the same ground height eight times per step, and a big group order no longer runs a second search for every member that already failed to find a slot.
## The game is 64-bit
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 0d8e81bf3..afea0d88c 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -33,6 +33,7 @@ Data/Cinema/aurorablast.txt
Data/Cinema/aurorafog.txt
Data/Cinema/blastcheck.txt
Data/Cinema/demo.txt
+Data/Cinema/drawlooks.txt
Data/Cinema/explreel.txt
Data/Cinema/filterblur.txt
Data/Cinema/filterbw.txt
@@ -58,6 +59,7 @@ Data/Cinema/lsv_laser.txt
Data/Cinema/lsv_spam.txt
Data/Cinema/lsv_spam2.txt
Data/Cinema/minefx.txt
+Data/Cinema/minefx_blast.txt
Data/Cinema/minefx_desert.txt
Data/Cinema/minefx_player.txt
Data/Cinema/minefx_scene.txt
@@ -183,6 +185,7 @@ Data/Scenarios/defencereach.txt
Data/Scenarios/dozerloss.txt
Data/Scenarios/dragonfirewall.txt
Data/Scenarios/dragonflame.txt
+Data/Scenarios/drawlooks.txt
Data/Scenarios/driveby.txt
Data/Scenarios/empfriendly.txt
Data/Scenarios/exitmovebuild.txt
@@ -225,6 +228,7 @@ Data/Scenarios/mass420x2.txt
Data/Scenarios/mass840.txt
Data/Scenarios/massmove.txt
Data/Scenarios/minefx.txt
+Data/Scenarios/minefx_blast.txt
Data/Scenarios/minefx_desert.txt
Data/Scenarios/minefx_player.txt
Data/Scenarios/minefx_scene.txt
@@ -306,6 +310,7 @@ Data/Scenarios/trailer_clash.txt
Data/Scenarios/trailer_corridor.txt
Data/Scenarios/trailer_fourway.txt
Data/Scenarios/trailer_intro.txt
+Data/Scenarios/truckredirect.txt
Data/Scenarios/tunnelattack.txt
Data/Scenarios/tunnelfull.txt
Data/Scenarios/tunnelgap.txt
@@ -2955,6 +2960,7 @@ Tests/test_gametext_csf.cpp
Tests/test_global_new_alignment.cpp
Tests/test_glyph_rasteriser.cpp
Tests/test_harness.h
+Tests/test_hostile_map.inc
Tests/test_install_guard.sh
Tests/test_install_root.cpp
Tests/test_install_textures.cpp
@@ -2962,6 +2968,7 @@ Tests/test_lan_broadcast.cpp
Tests/test_linux_portable.sh
Tests/test_macos_app.sh
Tests/test_main.cpp
+Tests/test_map_ini_rollback.inc
Tests/test_miles_miniaudio.cpp
Tests/test_milesaudiomanager.cpp
Tests/test_minimap_input.inc
diff --git a/GeneralsMD/Code/Data/Cinema/drawlooks.txt b/GeneralsMD/Code/Data/Cinema/drawlooks.txt
new file mode 100644
index 000000000..1613a27b8
--- /dev/null
+++ b/GeneralsMD/Code/Data/Cinema/drawlooks.txt
@@ -0,0 +1,18 @@
+# Scenarios/drawlooks.txt on Twilight Flame: the four Direct3D 11 object looks of 528b9054 in
+# three places, one after another. Paired with the same run under -d3d9 for the before. Every
+# view faces east (heading -90), into the map, so the west edge behind seat 0's base stays out.
+# The clip is -video 60 1440; stills come out of the two clips, not from shot lines.
+#
+# 2 s seat 0's base from the west, the forward power plant on the right; it falls and the
+# base goes dark (outage)
+# 20 s the field: the Microwave column on the EMP mines, Battlemasters against Crusaders below
+# 30.5 s close on the own Black Lotus (cloak), Burton crossing her (revealed), the dozer finding her
+
+2.0 cut 700 3080 0.75 -90 4
+2.0 orbit -12 17
+
+20.0 cut 1430 3740 0.55 -90 6
+20.0 orbit 10 10
+
+30.5 cut 2280 3740 0.4 -90 8
+30.5 follow ChinaInfantryBlackLotus
diff --git a/GeneralsMD/Code/Data/Cinema/minefx_blast.txt b/GeneralsMD/Code/Data/Cinema/minefx_blast.txt
new file mode 100644
index 000000000..d989f4a52
--- /dev/null
+++ b/GeneralsMD/Code/Data/Cinema/minefx_blast.txt
@@ -0,0 +1,21 @@
+# Scenarios/minefx_blast.txt on Alpine Assault: the field close with the Red Guard walking through
+# it, the field at play distance, then the American column driving into it, held close enough that
+# a blast's earth column and the EMP ring fill a good part of the frame. The blast stills are frames
+# of the -video dump.
+
+0 hud off
+# close, the Red Guard crossing the field
+6.5 cut 780 885 0.17 -45 12
+7.5 shot
+8.1 shot
+8.7 shot
+# play distance
+9.5 cut 780 900 1.0 -45 0
+10.0 shot
+10.6 shot
+11.2 shot
+11.8 shot
+# the column hits the field
+12.5 cut 780 890 0.4 -45 14
+13.0 orbit 8 10
+24.5 end
diff --git a/GeneralsMD/Code/Data/INI/ParticleSystemReforged.ini b/GeneralsMD/Code/Data/INI/ParticleSystemReforged.ini
index e79f1fc21..b90e1c45f 100644
--- a/GeneralsMD/Code/Data/INI/ParticleSystemReforged.ini
+++ b/GeneralsMD/Code/Data/INI/ParticleSystemReforged.ini
@@ -4931,3 +4931,122 @@ ParticleSystem ReforgedAuroraColumn
IsEmitAboveGroundOnly = No
IsParticleUpTowardsEmitter = No
End
+
+; The decoy flares an aircraft drops (CountermeasureFlare). EA's sparks lived two frames and died
+; at two thirds of their colour, a pale flicker at play zoom. These are bigger, half again as many,
+; a hotter white, and live the three frames their fade was written for.
+ParticleSystem CountermeasureFlareParticleSys
+ Priority = ALWAYS_RENDER
+ IsOneShot = No
+ Shader = ADDITIVE
+ Type = PARTICLE
+ ParticleName = EXCounterMeasureFlare3.tga
+ AngleZ = 0.00 0.00
+ AngularRateZ = 0.00 0.00
+ AngularDamping = 0.00 0.00
+ VelocityDamping = 0.00 0.00
+ Gravity = -0.30
+ Lifetime = 3.00 3.00
+ SystemLifetime = 150
+ Size = 4.00 7.00
+ StartSizeRate = 0.00 -0.01
+ SizeRate = 3.00 8.00
+ SizeRateDamping = 0.99 0.99
+ Alpha1 = 1.00 1.00 0
+ Alpha2 = -2.00 0.00 150
+ Alpha3 = 0.00 0.00 0
+ Alpha4 = 0.00 0.00 0
+ Alpha5 = 0.00 0.00 0
+ Alpha6 = 0.00 0.00 0
+ Alpha7 = 0.00 0.00 0
+ Alpha8 = 0.00 0.00 0
+ Color1 = R:255 G:245 B:220 0
+ Color2 = R:0 G:0 B:0 3
+ Color3 = R:0 G:0 B:0 0
+ Color4 = R:0 G:0 B:0 0
+ Color5 = R:0 G:0 B:0 0
+ Color6 = R:0 G:0 B:0 0
+ Color7 = R:0 G:0 B:0 0
+ Color8 = R:0 G:0 B:0 0
+ ColorScale = 0.00 0.00
+ BurstDelay = 0.00 1.50
+ BurstCount = 8.00 14.00
+ InitialDelay = 0.00 15.00
+ DriftVelocity = X:0.10 Y:0.10 Z:0.10
+ VelocityType = ORTHO
+ VelOrthoX = 0.00 0.00
+ VelOrthoY = 0.00 0.00
+ VelOrthoZ = 0.00 0.00
+ VolumeType = POINT
+ IsHollow = No
+ IsGroundAligned = No
+ IsEmitAboveGroundOnly = No
+ IsParticleUpTowardsEmitter = No
+ WindMotion = Unused
+ WindAngleChangeMin = 0.000000
+ WindAngleChangeMax = 0.000000
+ WindPingPongStartAngleMin = 0.017453
+ WindPingPongStartAngleMax = 0.017453
+ WindPingPongEndAngleMin = 0.000000
+ WindPingPongEndAngleMax = 3.141593
+End
+
+; The smoke trail behind each flare: EA's, a little thicker and hanging about eight seconds instead
+; of four and a half, so a volley leaves a trail that reads as one.
+ParticleSystem CounterMeasureSmoke
+ Priority = CONSTANT
+ IsOneShot = No
+ Shader = ALPHA
+ Type = PARTICLE
+ ParticleName = EXCloud02.tga
+ AngleZ = 0.00 3.00
+ AngularRateZ = -0.01 0.01
+ AngularDamping = 1.00 1.00
+ VelocityDamping = 0.98 0.98
+ Gravity = 0.00
+ Lifetime = 210.00 270.00
+ SystemLifetime = 0
+ Size = 0.50 1.00
+ StartSizeRate = 0.00 0.00
+ SizeRate = 0.50 0.50
+ SizeRateDamping = 0.80 0.85
+ Alpha1 = 0.15 0.30 0
+ Alpha2 = 0.00 0.00 270
+ Alpha3 = 0.00 0.00 0
+ Alpha4 = 0.00 0.00 0
+ Alpha5 = 0.00 0.00 0
+ Alpha6 = 0.00 0.00 0
+ Alpha7 = 0.00 0.00 0
+ Alpha8 = 0.00 0.00 0
+ Color1 = R:218 G:218 B:218 0
+ Color2 = R:255 G:255 B:255 10
+ Color3 = R:0 G:0 B:0 0
+ Color4 = R:0 G:0 B:0 0
+ Color5 = R:0 G:0 B:0 0
+ Color6 = R:0 G:0 B:0 0
+ Color7 = R:0 G:0 B:0 0
+ Color8 = R:0 G:0 B:0 0
+ ColorScale = 0.00 0.00
+ BurstDelay = 3.00 5.00
+ BurstCount = 1.00 1.00
+ InitialDelay = 0.00 0.00
+ DriftVelocity = X:0.15 Y:0.10 Z:0.10
+ VelocityType = ORTHO
+ VelOrthoX = -0.03 0.03
+ VelOrthoY = -0.03 0.03
+ VelOrthoZ = 0.10 0.20
+ VolumeType = CYLINDER
+ VolCylinderRadius = 0.00
+ VolCylinderLength = 0.00
+ IsHollow = No
+ IsGroundAligned = No
+ IsEmitAboveGroundOnly = No
+ IsParticleUpTowardsEmitter = No
+ WindMotion = Unused
+ WindAngleChangeMin = 0.000000
+ WindAngleChangeMax = 0.000000
+ WindPingPongStartAngleMin = 0.000000
+ WindPingPongStartAngleMax = 0.000000
+ WindPingPongEndAngleMin = 0.000000
+ WindPingPongEndAngleMax = 0.000000
+End
diff --git a/GeneralsMD/Code/Data/Scenarios/drawlooks.txt b/GeneralsMD/Code/Data/Scenarios/drawlooks.txt
new file mode 100644
index 000000000..869189f1d
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/drawlooks.txt
@@ -0,0 +1,99 @@
+# The four Direct3D 11 object looks of 528b9054 (power outage, EMP, cloak, revealed) as match
+# scenes on Twilight Flame, for a before/after against -d3d9. Seat 0 is China and the local player
+# (no -observer, so its own stealth draws see-through and its detectors reveal), seat 1 America.
+# Two-seat starts: seat 0 at 537,3188, seat 1 at 1733,4205. A selector matches every unit of that
+# template in the seat, so each place has its own templates, and `attack` takes the seat's newest
+# match, which is why the forward power plant is spawned second.
+#
+# Three places, filmed one after another by Cinema/drawlooks.txt:
+# A seat 0's base at start0, frames 10..600: two power plants carry it (+20 against -11).
+# Tomahawks and Paladins come in from the east and kill the forward plant (837,2908), and the
+# base drops to +10 against -11 and goes dark while trucks, a troop crawler and Gattling
+# tanks move through it.
+# B the open field 1300..1700, 3500..4000, frames 450..950: an American Microwave column
+# drives into three Chinese EMP mines (first blast about frame 590) and stops, disabled,
+# while Battlemasters and Red Guard fight a line of Crusaders below it.
+# C the open ground 2150..2750, 3650..4000, frames 900..1450: the own Black Lotus walks east
+# under her cloak beside a Listening Outpost, finds Colonel Burton walking west (revealed),
+# and an American dozer driving past finds her (amber pulse); Tank Hunters go after Burton.
+#
+# Headless check (frames from the log): HEADLESS TALLY on ChinaPowerPlant, AmericaTankMicrowave
+# (an EMP-disabled unit drops out of the alive count) and ChinaEMPMine (each blast costs a mine
+# health), lines at the end of this file.
+#
+# generals.exe -win -borderless -xres 1280 -yres 720 -msaa 0 -quickstart -noshellmap -multiInstance
+# -fps 120 -noFPSLimit -particlecap 2500 -map "Maps\Twilight Flame\Twilight Flame.map"
+# -autoskirmish 2 -takeover -side 0 FactionChina -side 1 FactionAmerica -seed 7
+# -scenario drawlooks -cinema drawlooks -video 60 1440 drawlooks_d3d11 -maxframes 1450
+# and the same with -d3d9 for the before.
+
+# A: seat 0's base
+10 spawn 0 ChinaPowerPlant 1 start0:-240:160
+10 spawn 0 ChinaPowerPlant 1 start0:300:-280
+10 spawn 0 ChinaWarFactory 1 start0:40:-340
+10 spawn 0 ChinaBarracks 1 start0:60:320
+10 spawn 0 ChinaSupplyCenter 1 start0:-260:440
+10 spawn 0 ChinaPropagandaCenter 1 start0:-240:-200
+10 spawn 0 ChinaSpeakerTower 1 start0:280:160
+10 spawn 0 ChinaGattlingCannon 1 start0:420:300
+10 spawn 0 ChinaGattlingCannon 1 start0:-60:520
+20 spawn 0 ChinaVehicleSupplyTruck 2 start0:-160:380 60
+20 spawn 0 ChinaVehicleTroopCrawler 1 start0:-200:-320
+20 spawn 0 ChinaTankGattling 3 start0:120:-120 50
+30 move 0 ChinaVehicleSupplyTruck start0:420:-300
+30 move 0 ChinaVehicleTroopCrawler start0:300:320
+40 move 0 ChinaTankGattling start0:-120:-60
+20 spawn 1 AmericaVehicleTomahawk 4 1130 3260 40
+20 spawn 1 AmericaTankPaladin 4 1100 3150 50
+40 move 1 AmericaVehicleTomahawk start0:460:-290
+40 move 1 AmericaTankPaladin start0:420:-180
+150 forceattack 1 AmericaVehicleTomahawk 0 ChinaPowerPlant
+200 forceattack 1 AmericaTankPaladin 0 ChinaPowerPlant
+300 forceattack 1 AmericaVehicleTomahawk 0 ChinaPowerPlant
+300 forceattack 1 AmericaTankPaladin 0 ChinaPowerPlant
+330 move 0 ChinaVehicleSupplyTruck start0:-160:380
+330 move 0 ChinaVehicleTroopCrawler start0:-200:-320
+330 attackmove 0 ChinaTankGattling start0:600:-200
+
+# B: the field
+450 spawn 0 ChinaEMPMine 1 1530 3660
+450 spawn 0 ChinaEMPMine 1 1565 3625
+450 spawn 0 ChinaEMPMine 1 1495 3695
+450 spawn 1 AmericaTankCrusader 4 1560 3800 50
+450 spawn 1 AmericaTankMicrowave 3 1700 3520 50
+460 move 1 AmericaTankMicrowave 1350 3800
+540 spawn 0 ChinaTankBattleMaster 4 1200 3980 50
+540 spawn 0 ChinaInfantryRedguard 6 1150 3900 18
+550 attackmove 0 ChinaTankBattleMaster 1400 3850
+550 attackmove 0 ChinaInfantryRedguard 1380 3880
+550 attackmove 1 AmericaTankCrusader 1200 4000
+
+# C: the scouts
+900 spawn 0 ChinaInfantryBlackLotus 1 2150 3720
+900 spawn 0 ChinaVehicleListeningOutpost 1 2120 3800
+900 spawn 0 ChinaInfantryTankHunter 5 2050 3900 18
+900 spawn 1 AmericaInfantryColonelBurton 1 2780 3780
+900 spawn 1 AmericaVehicleDozer 1 2700 4000
+920 move 0 ChinaInfantryBlackLotus 2650 3700
+920 move 0 ChinaVehicleListeningOutpost 2600 3820
+920 move 1 AmericaInfantryColonelBurton 2100 3800
+1100 move 1 AmericaVehicleDozer 2250 3700
+1250 attackmove 0 ChinaInfantryTankHunter 2300 3800
+
+# timing checks, read headless
+100 tally 0 ChinaPowerPlant
+300 tally 0 ChinaPowerPlant
+400 tally 0 ChinaPowerPlant
+500 tally 0 ChinaPowerPlant
+600 tally 0 ChinaPowerPlant
+600 tally 1 AmericaVehicleTomahawk
+560 tally 1 AmericaTankMicrowave
+600 tally 1 AmericaTankMicrowave
+650 tally 1 AmericaTankMicrowave
+700 tally 1 AmericaTankMicrowave
+800 tally 1 AmericaTankMicrowave
+900 tally 1 AmericaTankMicrowave
+900 tally 0 ChinaEMPMine
+1200 tally 1 AmericaInfantryColonelBurton
+1440 tally 1 AmericaInfantryColonelBurton
+1440 tally 0 ChinaInfantryBlackLotus
diff --git a/GeneralsMD/Code/Data/Scenarios/minefx_blast.txt b/GeneralsMD/Code/Data/Scenarios/minefx_blast.txt
new file mode 100644
index 000000000..136efbd96
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/minefx_blast.txt
@@ -0,0 +1,45 @@
+# The China mine field going off under an American column on Alpine Assault, seen from the owner's
+# side: minefx_scene.txt's outpost and field round 760,900, its own traffic leaving the field, and
+# from frame 300 three groups of American vehicles driven straight at the standard mines (700,900
+# and 760,860) and the EMP mines (820,900 and 760,940). No Gattling cannon and no attack order for
+# the Battlemasters, so the column reaches the field instead of dying on the way.
+#
+# generals.exe -win -borderless -xres 1280 -yres 720 -msaa 0 -quickstart -noshellmap
+# -multiInstance -fps 120 -noFPSLimit -particlecap 2500
+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover
+# -side 0 FactionChina -side 1 FactionAmerica -seed 1
+# -scenario minefx_blast -cinema minefx_blast -video 390 720 minefx_blast -maxframes 730
+
+# the outpost
+30 spawn 0 ChinaPowerPlant 1 620 780
+30 spawn 0 ChinaBarracks 1 900 770
+30 spawn 0 ChinaBunker 1 880 1000
+
+# the field
+30 spawn 0 ChinaStandardMine 1 700 900
+30 spawn 0 ChinaEMPMine 1 820 900
+30 spawn 0 ChinaStandardMine 1 760 860
+30 spawn 0 ChinaEMPMine 1 760 940
+
+# own traffic through the field, then away from it before the Americans come
+30 spawn 0 ChinaTankBattleMaster 3 1040 900 28
+30 spawn 0 ChinaInfantryRedguard 6 960 860 14
+30 spawn 0 ChinaVehicleSupplyTruck 1 980 960
+40 move 0 ChinaTankBattleMaster 660 880
+40 move 0 ChinaInfantryRedguard 600 880
+40 move 0 ChinaVehicleSupplyTruck 620 940
+300 move 0 ChinaTankBattleMaster 560 680
+300 move 0 ChinaVehicleSupplyTruck 600 700
+300 move 0 ChinaInfantryRedguard 540 720
+
+# the American column: Crusaders and a Humvee along the north edge onto the standard mines, kept
+# 60 off the EMP field (an EMP blast disables a vehicle and it never reaches the next mine), then
+# Paladins and a Tomahawk through the EMP fields
+300 spawn 1 AmericaTankCrusader 3 1020 830 30
+300 spawn 1 AmericaVehicleHumvee 1 1080 830
+305 move 1 AmericaTankCrusader 680 870
+305 move 1 AmericaVehicleHumvee 680 870
+380 spawn 1 AmericaTankPaladin 2 1000 1040 30
+380 spawn 1 AmericaVehicleTomahawk 1 1060 1000
+385 move 1 AmericaTankPaladin 760 940
+385 move 1 AmericaVehicleTomahawk 820 900
diff --git a/GeneralsMD/Code/Data/Scenarios/truckredirect.txt b/GeneralsMD/Code/Data/Scenarios/truckredirect.txt
new file mode 100644
index 000000000..0b3377f42
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/truckredirect.txt
@@ -0,0 +1,25 @@
+# Supply trucks told to go somewhere else as they finish at a dock.
+#
+# Eight China supply trucks ferry from three piles to one supply center; at frame 597 every one of
+# them is ordered across the town. One of them has just finished docking on that frame, and the
+# supply state machine runs its "find the next dock" step before it looks at whether somebody gave
+# the truck an order, so the order was thrown away and the truck drove back to the supplies.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover
+# -side 0 FactionChina -side 1 FactionAmerica -seed 1 -maxframes 3600
+# -scenario truckredirect -logPrefix truckredirect_
+#
+# then grep the log for HEADLESS ARRIVE and HEADLESS STRAGGLER. 2026-10-14 before the fix: 7 of 8,
+# the straggler in state 14 (AI_DOCK) back at the piles. The same order at 600, 603, 608, 615 or 760
+# reached 8 of 8, so the frame is the point.
+
+1 spawn 0 ChinaSupplyCenter 1 900 900
+1 spawn 0 ChinaPowerPlant 1 760 920
+1 spawn 0 SupplyPile 1 1100 700
+1 spawn 0 SupplyPile 1 1180 950
+1 spawn 0 SupplyPile 1 1050 1150
+10 spawn 0 ChinaVehicleSupplyTruck 7 1000 1000 40
+20 dock 0 ChinaVehicleSupplyTruck 0 SupplyPile
+597 playermove 0 ChinaVehicleSupplyTruck 1150 650
+597 arrive 0 ChinaVehicleSupplyTruck 1150 650 150
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
index 83859cd59..9889a183e 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
@@ -721,6 +721,7 @@ public:
/// get the relationship between this->that.
Relationship getRelationship(const Team *that) const;
+ Bool hasTeamRelationships() const; ///< does any single team get a relationship of its own?
/// set the relationship between this->that. (note that this doesn't affect the that->this relationship.)
void setPlayerRelationship(const Player *that, Relationship r);
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Team.h b/GeneralsMD/Code/GameEngine/Include/Common/Team.h
index 96902a578..444c6a568 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Team.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Team.h
@@ -360,6 +360,10 @@ public:
*/
Relationship getRelationship(const Team *that) const;
+ /** Every player at least one of whose Objects this team takes for an enemy. Exact while no single
+ team carries a relationship of its own; when one does, all players, which is still a superset. */
+ PlayerMaskType getEnemyPlayerMask() const;
+
/**
set a special relationship between this team and that team, that overrides
the one between our Players. (note that this doesn't imply anything about the
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
index 42fe3f20a..a7fa708e7 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
@@ -233,6 +233,7 @@ struct AIDifficultyProfile
// Superweapons
Real 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
};
//-------------------------------------------------------------------------------------------------
@@ -556,6 +557,11 @@ Bool aiWantsMoreProduction( Int bank, Int bankWindowAgo, Int target, Int standin
* AI_SURPLUS_INCOME_SECONDS, and never what takes the bank under target. At share 1 that is three
* passes' income a pass, which drains a pile; a rung with a small share only tops its plan up. */
Int aiSurplusBudget( Int bank, Int target, Real incomePerSecond, Real share );
+
+/** The same for a match that started rich: share of what the bank holds over keep (the bank target or
+ * the default starting cash, whichever is more), never more than fortune, what the start handed over
+ * the default. 0 in a match at the default cash, which then plays as it did. */
+Int aiFortuneBudget( Int bank, Int keep, Int fortune, Real share );
const Real AI_SURPLUS_INCOME_SECONDS = 30.0f;
/** What a unit counts for when an upgrade is weighed: 1 with nothing known of the enemy or no weight
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
index 23829b38b..43c5ff2cd 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
@@ -1278,6 +1278,9 @@ private:
ObjectID m_queuedPathfindRequests[PATHFIND_QUEUE_LEN];
Int m_queuePRHead;
Int m_queuePRTail;
+ /* Which ids sit between head and tail, by ObjectID, so queueForPath answers "already queued"
+ without walking up to 2048 slots on every request. Derived from the ring, never saved. */
+ std::vector<bool> m_isQueuedForPath;
Int m_cumulativeCellsAllocated;
/* diagnostics only - never read by the simulation, so it stays out of xfer(). Records
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
index 4dfa4655d..f46f8c13a 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
@@ -366,6 +366,7 @@ protected:
UnsignedInt m_incomeMarkFrame; ///< ... and the frame, 0 for never
Int m_bankMark; ///< ... and the bank then
Real m_incomePerSecond; ///< smoothed over the windows measured so far
+ Int m_startFortune; ///< what the match started with over the default starting cash, 0 at the default
Bool purchaseAllowed(Int key, Int cost, AIPurchaseKind kind, Bool startable, const AsciiString &what);
void purchased(Int key, Int cost, AIPurchaseKind kind, const AsciiString &what);
Bool buyUnit(ProductionUpdateInterface *pu, const ThingTemplate *unit, AIPurchaseKind kind); ///< queueCreateUnit through the queue
@@ -446,7 +447,8 @@ protected:
/** These two read another player's estate. observerNdx is who is allowed to know: pass a
* 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 );
+ static Int getPlayerSuperweaponValue( Coord3D *center, Int playerNdx, Real radius, Bool includeMilitaryUnits = TRUE, Int observerNdx = -1,
+ Real economyWeight = 0.0f );
// End of aiplayer interface.
protected:
@@ -506,6 +508,7 @@ protected:
/// what a superweapon aimed here is worth, with the shots already on their way taken off
Int 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
void noteSuperweaponAim( const Coord3D *pos ); ///< remember a spot, so the next shot goes elsewhere
protected:
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
index cb5a054fb..f975600af 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
@@ -340,6 +340,8 @@ private:
Int m_threatValue[MAX_PLAYER_COUNT];
Int m_cashValue[MAX_PLAYER_COUNT];
Short m_coiCount; ///< number of COIs in this cell.
+ UnsignedShort m_playerCoiCount[MAX_PLAYER_COUNT]; ///< COIs in this cell whose Object belongs to each player
+ PlayerMaskType m_playerCoiMask; ///< players whose m_playerCoiCount is nonzero
Short m_cellX; ///< x-coord of this cell within the Partition Mgr coords (NOT in world coords)
Short m_cellY; ///< y-coord of this cell within the Partition Mgr coords (NOT in world coords)
@@ -360,6 +362,9 @@ public:
void loadPostProcess( void );
Int getCoiCount() const { return m_coiCount; } ///< return number of COIs touching this cell.
+ Bool hasCoiOfPlayers( PlayerMaskType players ) const { return (m_playerCoiMask & players) != 0; } ///< does any Object of these players touch this cell?
+ void addPlayerCoi( Int playerIndex );
+ void removePlayerCoi( Int playerIndex );
Int getCellX() const { return m_cellX; }
Int getCellY() const { return m_cellY; }
@@ -434,6 +439,7 @@ private:
Int m_coiInUseCount; ///< number of COIs that are actually in use
CellAndObjectIntersection *m_coiArray; ///< The array of COIs
Int m_doneFlag;
+ Int m_countedPlayer; ///< player index this module's COIs are counted under in their cells, -1 for none
DirtyStatus m_dirtyStatus;
ObjectShroudStatus m_shroudedness[MAX_PLAYER_COUNT];
ObjectShroudStatus m_shroudednessPrevious[MAX_PLAYER_COUNT]; ///<previous frames value of m_shroudedness
@@ -598,6 +604,8 @@ public:
void friend_removeAllTouchedCells() { removeAllTouchedCells(); } ///< this is only for use by PartitionManager
void friend_updateCellsTouched() { updateCellsTouched(); } ///< this is only for use by PartitionManager
Int friend_getCoiInUseCount() { return m_coiInUseCount; } ///< this is only for use by PartitionManager
+ Int friend_getCountedPlayer() const { return m_countedPlayer; } ///< only for CellAndObjectIntersection
+ void refreshCountedPlayer(); ///< move this module's per-player cell counts to its Object's current controlling player
Bool friend_collidesWith(const PartitionData *that, CollideLocAndNormal *cinfo) const { return collidesWith(that, cinfo); } ///< this is only for use by PartitionContactList
// these are only for use by getClosestObjects.
@@ -1323,7 +1331,8 @@ protected:
PartitionFilter **filters,
SimpleObjectIterator *iter, // if nonnull, append ALL satisfactory objects to the iterator (not just the single closest)
Real *closestDistArg,
- Coord3D *closestVecArg
+ Coord3D *closestVecArg,
+ PlayerMaskType onlyPlayers = PLAYERMASK_ALL
);
void shutdown( void );
@@ -1446,13 +1455,17 @@ public:
Real *closestDist = NULL,
Coord3D *closestDistVec = NULL
);
+ /** onlyPlayers skips every cell no Object of those players touches. Pass it only when the filters
+ already reject every Object outside them (an ALLOW_ENEMIES relationship filter with the asker's
+ Team::getEnemyPlayerMask), so the answer is the one a full search gives. */
Object *getClosestObject(
- const Coord3D *pos,
- Real maxDist,
- DistanceCalculationType dc,
- PartitionFilter **filters = NULL,
+ const Coord3D *pos,
+ Real maxDist,
+ DistanceCalculationType dc,
+ PartitionFilter **filters = NULL,
Real *closestDist = NULL,
- Coord3D *closestDistVec = NULL
+ Coord3D *closestDistVec = NULL,
+ PlayerMaskType onlyPlayers = PLAYERMASK_ALL
);
Real getRelativeAngle2D( const Object *obj, const Object *otherObj );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h
index a8c0e907c..a43f3d746 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h
@@ -34,9 +34,12 @@
#include "Common/StateMachine.h"
#include "Common/GameMemory.h"
+#include "Common/GameCommon.h"
-const Real DEFAULT_TURN_RATE = 0.01f;
-const Real DEFAULT_PITCH_RATE = 0.01f;
+// radians a frame for a turret whose INI names no TurretTurnRate or TurretPitchRate; EA's 0.01 was a
+// retail (30 Hz) frame's, and left as it was every such barrel rose twice as fast at 60 Hz
+const Real DEFAULT_TURN_RATE = ConvertRetailPerFrameRate(0.01f);
+const Real DEFAULT_PITCH_RATE = ConvertRetailPerFrameRate(0.01f);
/**
* The TurretAI state IDs.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
index 7290ffd7d..6ed1aaa4e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
@@ -490,6 +490,8 @@ private:
static void parseWeaponBonusSet( INI* ini, void *instance, void * /*store*/, const void* /*userData*/ );
static void parseScatterTarget( INI* ini, void *instance, void * /*store*/, const void* /*userData*/ );
static void parseShotDelay( INI* ini, void *instance, void * /*store*/, const void* /*userData*/ );
+ static void parseRetailDuration( INI* ini, void *instance, void *store, const void* /*userData*/ );
+ static Int retailFramesFromMsec( Int msec );
static const FieldParse TheWeaponTemplateFieldParseTable[]; ///< the parse table for INI definition
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Money.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Money.cpp
index 6412a5024..f7e304c7b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Money.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Money.cpp
@@ -106,7 +106,7 @@ void Money::deposit(UnsignedInt amountToDeposit, Bool playSound)
// ------------------------------------------------------------------------------------------------
void Money::crc( Xfer *xfer )
{
-
+ xfer->xferUnsignedInt( &m_money );
} // end crc
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 4f80cdfbd..d9ea923f8 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -648,6 +648,12 @@ Relationship Player::getRelationship(const Team *that) const
return NEUTRAL;
}
+//=============================================================================
+Bool Player::hasTeamRelationships() const
+{
+ return !m_teamRelations->m_map.empty();
+}
+
//=============================================================================
void Player::setPlayerRelationship(const Player *that, Relationship r)
{
@@ -4676,6 +4682,9 @@ void Player::crc( Xfer *xfer )
xfer->xferInt( &m_skillPoints );
xfer->xferInt( &m_sciencePurchasePoints );
+ // The bank, so an income or a refund that drifted is caught before it buys something.
+ xfer->xferSnapshot( &m_money );
+
} // end crc
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
index ccace143c..564a5eaff 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
@@ -902,6 +902,18 @@ void TeamPrototype::setControllingPlayer(Player *newController)
// impossible to get here with a NULL pointer.
m_owningPlayer->addTeamToList(this);
+
+ // every member changed hands without changing team; the partition counts each cell's
+ // objects per player and has to hear of it now
+ for (DLINK_ITERATOR<Team> teamIt = iterate_TeamInstanceList(); !teamIt.done(); teamIt.advance())
+ {
+ for (DLINK_ITERATOR<Object> objIt = teamIt.cur()->iterate_TeamMemberList(); !objIt.done(); objIt.advance())
+ {
+ PartitionData *pd = objIt.cur()->friend_getPartitionData();
+ if (pd)
+ pd->refreshCountedPlayer();
+ }
+ }
}
// ------------------------------------------------------------------------
@@ -1502,6 +1514,24 @@ Relationship Team::getRelationship(const Team *that) const
return getControllingPlayer()->getRelationship(that);
}
+// ------------------------------------------------------------------------
+PlayerMaskType Team::getEnemyPlayerMask() const
+{
+ // with no team-keyed override on either side, getRelationship depends only on the other
+ // team's player, so that player's default team answers for all of its teams
+ if (!m_teamRelations->m_map.empty() || getControllingPlayer()->hasTeamRelationships())
+ return PLAYERMASK_ALL;
+
+ PlayerMaskType mask = PLAYERMASK_NONE;
+ for (Int i = 0; i < ThePlayerList->getPlayerCount(); ++i)
+ {
+ Player *player = ThePlayerList->getNthPlayer(i);
+ if (getRelationship(player->getDefaultTeam()) == ENEMIES)
+ mask |= player->getPlayerMask();
+ }
+ return mask;
+}
+
// ------------------------------------------------------------------------
void Team::setTeamTargetObject(const Object *target)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
index 86211bd84..9264f580b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
@@ -1235,12 +1235,18 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons
* mostly unfinished at 45,000 on both builds, 1-0 with 5 draws before and 0-1 with 5 after, so a
* Hard that cannot close out Medium is still open.
*
- * 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 */
+ * The last column, strikeE, came in on 2026-10-14: what a supply centre, black market, hacker,
+ * drop zone, captured derrick, strategy centre or palace adds to a superweapon's or a general
+ * power's score, in multiples of its price on top of the price. Price alone and the threat weight
+ * 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 */
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 },
- /* 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 },
- /* 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 }
+ /* 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 }
};
//-------------------------------------------------------------------------------------------------
@@ -1623,6 +1629,17 @@ Int aiSurplusBudget( Int bank, Int target, Real incomePerSecond, Real share )
return byIncome < excess ? byIncome : excess;
}
+//-------------------------------------------------------------------------------------------------
+Int aiFortuneBudget( Int bank, Int keep, Int fortune, Real share )
+{
+ Int excess = bank - keep;
+ if( excess > fortune )
+ excess = fortune;
+ if( excess <= 0 )
+ return 0;
+ return REAL_TO_INT_FLOOR( share * INT_TO_REAL( excess ) );
+}
+
//-------------------------------------------------------------------------------------------------
Real aiCounterFit( Real matchup, Real weight )
{
@@ -1888,6 +1905,7 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*
{ "MinAttackPower", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_minAttackPower ) },
{ "SiegeTrail", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_siegeTrail ) },
{ "BeamSteerSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_beamSteerSeconds ) },
+ { "StrikeEconomyWeight", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_strikeEconomyWeight ) },
{ NULL, NULL, NULL, 0 }
};
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
index d180112b0..bc705f53d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
@@ -257,6 +257,8 @@ Bool AIGuardMachine::lookForInnerTarget(void)
PartitionFilter *filters[16];
Int count = 0;
+ // with f1 in the list only enemy players' cells can hold an answer
+ PlayerMaskType searchPlayers = PLAYERMASK_ALL;
// Enter Guard state
if (owner->getTemplate()->isEnterGuard())
@@ -268,6 +270,7 @@ Bool AIGuardMachine::lookForInnerTarget(void)
{
filters[count++] = &f1;
filters[count++] = &f7;
+ searchPlayers = owner->getTeam()->getEnemyPlayerMask();
}
else
{
@@ -279,6 +282,7 @@ Bool AIGuardMachine::lookForInnerTarget(void)
{
filters[count++] = &f1;
filters[count++] = &f2;
+ searchPlayers = owner->getTeam()->getEnemyPlayerMask();
}
filters[count++] = &filterMapStatus;
@@ -320,7 +324,7 @@ Bool AIGuardMachine::lookForInnerTarget(void)
// just ask for that; the above has to find ALL objects in range, but we ignore all
// but the first (closest).
//
- Object* target = ThePartitionManager->getClosestObject(&pos, visionRange, FROM_CENTER_2D, filters);
+ Object* target = ThePartitionManager->getClosestObject(&pos, visionRange, FROM_CENTER_2D, filters, NULL, NULL, searchPlayers);
if (target)
{
setNemesisID(target->getID());
@@ -754,19 +758,21 @@ StateReturnType AIGuardIdleState::update( void )
#endif
Object *owner = getMachineOwner();
AIUpdateInterface *ai = owner->getAIUpdateInterface();
- // Check to see if we have created a crate we need to pick up.
- if (ai->getCrateID() != INVALID_ID)
- {
- getMachine()->setState(AI_GUARD_GET_CRATE);
- return STATE_SLEEP(m_nextEnemyScanTime - now);
- }
// if anyone is in the inner area, return success.
- if (getGuardMachine()->lookForInnerTarget())
+ if (getGuardMachine()->lookForInnerTarget())
{
return STATE_SUCCESS; // Transitions to AIGuardInnerState.
}
+ // Check to see if we have created a crate we need to pick up. An enemy in the inner area
+ // comes first: the notice stays pending and the crate is fetched once the area is clear.
+ if (ai->getCrateID() != INVALID_ID)
+ {
+ getMachine()->setState(AI_GUARD_GET_CRATE);
+ return STATE_SLEEP(m_nextEnemyScanTime - now);
+ }
+
// See if the object we are guarding moved.
Object* targetToGuard = getGuardMachine()->findTargetToGuardByID();
if (targetToGuard)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp
index 347121afe..bf1e6c2af 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp
@@ -278,6 +278,8 @@ Bool AIGuardRetaliateMachine::lookForInnerTarget(void)
PartitionFilter *filters[16];
Int count = 0;
+ // with f1 in the list only enemy players' cells can hold an answer
+ PlayerMaskType searchPlayers = PLAYERMASK_ALL;
// Enter Guard state
if (owner->getTemplate()->isEnterGuard())
@@ -289,6 +291,7 @@ Bool AIGuardRetaliateMachine::lookForInnerTarget(void)
{
filters[count++] = &f1;
filters[count++] = &f7;
+ searchPlayers = owner->getTeam()->getEnemyPlayerMask();
}
else
{
@@ -300,6 +303,7 @@ Bool AIGuardRetaliateMachine::lookForInnerTarget(void)
{
filters[count++] = &f1;
filters[count++] = &f2;
+ searchPlayers = owner->getTeam()->getEnemyPlayerMask();
filters[count++] = &f8; //Different than guard... we won't allow acquiring of structures (unless base defenses)
// see canRetaliateFromHere
if (attackNeedsSight(owner))
@@ -322,7 +326,7 @@ Bool AIGuardRetaliateMachine::lookForInnerTarget(void)
// but the first (closest).
//
const Coord3D *pos = getPositionToGuard();
- Object* target = ThePartitionManager->getClosestObject(pos, visionRange, FROM_CENTER_2D, filters);
+ Object* target = ThePartitionManager->getClosestObject(pos, visionRange, FROM_CENTER_2D, filters, NULL, NULL, searchPlayers);
if (target)
{
setNemesisID(target->getID());
@@ -722,24 +726,21 @@ StateReturnType AIGuardRetaliateIdleState::update( void )
#endif
Object *owner = getMachineOwner();
AIUpdateInterface *ai = owner->getAIUpdateInterface();
- // Check to see if we have created a crate we need to pick up.
- if (ai->getCrateID() != INVALID_ID)
- {
- getMachine()->setState(AI_GUARD_RETALIATE_GET_CRATE);
- return STATE_SLEEP(m_nextEnemyScanTime - now);
- }
// if anyone is in the inner area, return success.
- if (getGuardMachine()->lookForInnerTarget())
+ if (getGuardMachine()->lookForInnerTarget())
{
return STATE_SUCCESS; // Transitions to AIGuardRetaliateInnerState.
}
- else
+
+ // Check to see if we have created a crate we need to pick up, once no enemy stands in the area.
+ if (ai->getCrateID() != INVALID_ID)
{
- return STATE_FAILURE;
+ getMachine()->setState(AI_GUARD_RETALIATE_GET_CRATE);
+ return STATE_SLEEP(m_nextEnemyScanTime - now);
}
- return STATE_SLEEP(m_nextEnemyScanTime - now);
+ return STATE_FAILURE;
}
//--------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
index b05e843a3..661990f0f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@@ -5332,6 +5332,7 @@ void Pathfinder::reset( void )
}
m_queuePRHead = 0;
m_queuePRTail = 0;
+ m_isQueuedForPath.clear();
m_numWallPieces = 0;
for (i=0; i<MAX_WALL_PIECES; ++i)
@@ -6711,6 +6712,11 @@ Bool Pathfinder::goalPosition(Object *obj, Coord3D *pos)
}
+/* Set when checkForAdjust turns a cell down only because of groupDest (the cell is free and
+ reachable, but a long way round from the group's goal). adjustDestination reads it to tell a
+ group spiral that would pass without groupDest from one that would fail again cell for cell. */
+static Bool theAdjustRejectedForGroup = false;
+
Bool Pathfinder::checkForAdjust(Object *obj, const LocomotorSet& locomotorSet, Bool isHuman,
Int cellX, Int cellY, PathfindLayerEnum layer,
Int iRadius, Bool center, Coord3D *dest, const Coord3D *groupDest)
@@ -6753,7 +6759,8 @@ Bool Pathfinder::checkForAdjust(Object *obj, const LocomotorSet& locomotorSet, B
Int dx = IABS(groupDest->x-adjustDest.x);
Int dy = IABS(groupDest->y-adjustDest.y);
if (1.4f*(dx+dy)<cost) {
- return false;
+ theAdjustRejectedForGroup = true;
+ return false;
}
}
*dest = adjustDest;
@@ -6906,6 +6913,7 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
// without it the formation smears.
//
Coord3D adjustDest = *dest;
+ theAdjustRejectedForGroup = false;
if (checkForAdjust(obj, locomotorSet, isHuman, i,j, layer, iRadius, center, &adjustDest, groupDest)) {
const Bool singleUnit = obj->getGroup() && obj->getGroup()->getCount() == 1;
if (!(isHuman && singleUnit)) {
@@ -6949,6 +6957,13 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
delta++;
}
if (groupDest) {
+ /* The simple adjust walks the same 400 cells round the same cell, and without groupDest a
+ cell passes on exactly the tests that already failed here, unless one was turned down only
+ for groupDest or the simple adjust reads another layer. Neither: it would fail again, and
+ in a big group order every member that found no slot paid for that second spiral. */
+ if (!theAdjustRejectedForGroup && TheTerrainLogic->getLayerForDestination(dest) == layer) {
+ return false;
+ }
// Didn't work, so just do simple adjust.
return(adjustDestination(obj, locomotorSet, dest, NULL));
}
@@ -7367,15 +7382,8 @@ Bool Pathfinder::queueForPath(ObjectID id)
#endif
/* Check & see if we are already queued. */
- Int slot = m_queuePRHead;
- while (slot != m_queuePRTail) {
- if (m_queuedPathfindRequests[slot] == id) {
- return true;
- }
- slot++;
- if (slot >= PATHFIND_QUEUE_LEN) {
- slot = 0;
- }
+ if ((size_t)id < m_isQueuedForPath.size() && m_isQueuedForPath[id]) {
+ return true;
}
// Tail is the first available slot.
@@ -7389,6 +7397,10 @@ Bool Pathfinder::queueForPath(ObjectID id)
}
m_queuedPathfindRequests[m_queuePRTail] = id;
m_queuePRTail = nextSlot;
+ if ((size_t)id >= m_isQueuedForPath.size()) {
+ m_isQueuedForPath.resize( (size_t)id + 1024, false );
+ }
+ m_isQueuedForPath[id] = true;
return true;
}
@@ -7658,6 +7670,7 @@ void Pathfinder::processPathfindQueue(void)
m_queuePRTail!=m_queuePRHead) {
++requestsThisFrame;
Object *obj = TheGameLogic->findObjectByID(m_queuedPathfindRequests[m_queuePRHead]);
+ m_isQueuedForPath[m_queuedPathfindRequests[m_queuePRHead]] = false;
m_queuedPathfindRequests[m_queuePRHead] = INVALID_ID;
if (obj) {
AIUpdateInterface *ai = obj->getAIUpdateInterface();
@@ -7743,6 +7756,7 @@ struct ExamineCellsStruct
const LocomotorSet *theLoco;
Bool centerInCell;
Bool isHuman;
+ Bool isCrusher; ///< worked out once per probe, not once per cell along it
Int radius;
const Object *obj;
PathfindCell *goalCell;
@@ -7751,10 +7765,9 @@ struct ExamineCellsStruct
/*static*/ Int Pathfinder::examineCellsCallback(Pathfinder* pathfinder, PathfindCell* from, PathfindCell* to, Int to_x, Int to_y, void* userData)
{
ExamineCellsStruct* d = (ExamineCellsStruct*)userData;
- Bool isCrusher = d->obj ? d->obj->getCrusherLevel() > 0 : false;
if (d->thePathfinder->m_isTunneling) return 1; // abort.
if (from && to) {
- if (!d->thePathfinder->validMovementPosition( isCrusher, d->theLoco->getValidSurfaces(), to, from )) {
+ if (!d->thePathfinder->validMovementPosition( d->isCrusher, d->theLoco->getValidSurfaces(), to, from )) {
return 1;
}
if ( (to->getLayer() == LAYER_GROUND) && !d->thePathfinder->m_zoneManager.isPassable(to_x, to_y) ) {
@@ -7897,6 +7910,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
info.radius = radius;
info.obj = obj;
info.isHuman = isHuman;
+ info.isCrusher = isCrusher;
info.goalCell = goalCell;
ICoord2D start, end;
start.x = parentCell->getXIndex();
@@ -7922,15 +7936,35 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
UnsignedInt newCostSoFar;
-
+ /* The parent's ground height is the same for all eight neighbours, so the downhill and cliff
+ checks below read it once per expansion rather than once per neighbour. Fetched only when
+ one of them first asks, because most expansions never need it. */
+ Bool hasParentHeight = false;
+ Real parentHeight = 0.0f;
for( int i=0; i<numNeighbors; i++ )
{
neighborFlags[i] = false;
+ // a diagonal needs one of its two orthogonal sides open; that is known before any lookup
+ // (the orthogonals all ran first), so a closed corner costs nothing
+ if (i>=firstDiagonal) {
+ // make sure one of the adjacent sides is open.
+ if (!neighborFlags[adjacent[i-4]] && !neighborFlags[adjacent[i-3]]) {
+ continue;
+ }
+ }
// determine neighbor cell to try
newCellCoord.x = parentCell->getXIndex() + delta[i].x;
newCellCoord.y = parentCell->getYIndex() + delta[i].y;
+ if (isHuman) {
+ // check if new cell is in logical map. (computer can move off logical map)
+ if (newCellCoord.x < m_logicalExtent.lo.x) continue;
+ if (newCellCoord.y < m_logicalExtent.lo.y) continue;
+ if (newCellCoord.x > m_logicalExtent.hi.x) continue;
+ if (newCellCoord.y > m_logicalExtent.hi.y) continue;
+ }
+
// get the neighboring cell
newCell = getCell(parentCell->getLayer(), newCellCoord.x, newCellCoord.y );
@@ -7938,25 +7972,13 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
if (newCell == NULL)
continue;
- Bool notZonePassable = false;
- if ((newCell->getLayer()==LAYER_GROUND) && !m_zoneManager.isPassable(newCellCoord.x, newCellCoord.y)) {
- notZonePassable = true;
- }
- if (isHuman) {
- // check if new cell is in logical map. (computer can move off logical map)
- if (newCellCoord.x < m_logicalExtent.lo.x) continue;
- if (newCellCoord.y < m_logicalExtent.lo.y) continue;
- if (newCellCoord.x > m_logicalExtent.hi.x) continue;
- if (newCellCoord.y > m_logicalExtent.hi.y) continue;
- }
-
- // check if this neighbor cell is already on the open (waiting to be tried)
+ // check if this neighbor cell is already on the open (waiting to be tried)
// or closed (already tried) lists
Bool onList = false;
if (newCell->hasInfo()) {
if (newCell->getOpen() || newCell->getClosed())
{
- // already on one of the lists
+ // already on one of the lists
onList = true;
}
}
@@ -7964,27 +7986,22 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
// we have already examined this one, so continue.
continue;
}
- if (i>=firstDiagonal) {
- // make sure one of the adjacent sides is open.
- if (!neighborFlags[adjacent[i-4]] && !neighborFlags[adjacent[i-3]]) {
- continue;
- }
+
+ Bool notZonePassable = false;
+ if ((newCell->getLayer()==LAYER_GROUND) && !m_zoneManager.isPassable(newCellCoord.x, newCellCoord.y)) {
+ notZonePassable = true;
}
// do the gravity check here
if ( locomotorSet.isDownhillOnly() )
{
- Coord3D fromPos;
- fromPos.x = parentCell->getXIndex() * PATHFIND_CELL_SIZE_F ;
- fromPos.y = parentCell->getYIndex() * PATHFIND_CELL_SIZE_F ;
- fromPos.z = TheTerrainLogic->getGroundHeight(fromPos.x , fromPos.y);
-
- Coord3D toPos;
- toPos.x = newCellCoord.x * PATHFIND_CELL_SIZE_F ;
- toPos.y = newCellCoord.y * PATHFIND_CELL_SIZE_F ;
- toPos.z = TheTerrainLogic->getGroundHeight(toPos.x , toPos.y);
+ if (!hasParentHeight) {
+ parentHeight = TheTerrainLogic->getGroundHeight(parentCell->getXIndex() * PATHFIND_CELL_SIZE_F, parentCell->getYIndex() * PATHFIND_CELL_SIZE_F);
+ hasParentHeight = true;
+ }
+ const Real toHeight = TheTerrainLogic->getGroundHeight(newCellCoord.x * PATHFIND_CELL_SIZE_F, newCellCoord.y * PATHFIND_CELL_SIZE_F);
- if ( fromPos.z < toPos.z )
+ if ( parentHeight < toHeight )
continue;
}
@@ -8062,17 +8079,13 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
newCostSoFar += 3*COST_DIAGONAL;
}
if (newCell->getType() == PathfindCell::CELL_CLIFF && !newCell->getPinched() ) {
- Coord3D fromPos;
- fromPos.x = parentCell->getXIndex() * PATHFIND_CELL_SIZE_F ;
- fromPos.y = parentCell->getYIndex() * PATHFIND_CELL_SIZE_F ;
- fromPos.z = TheTerrainLogic->getGroundHeight(fromPos.x , fromPos.y);
-
- Coord3D toPos;
- toPos.x = newCellCoord.x * PATHFIND_CELL_SIZE_F ;
- toPos.y = newCellCoord.y * PATHFIND_CELL_SIZE_F ;
- toPos.z = TheTerrainLogic->getGroundHeight(toPos.x , toPos.y);
+ if (!hasParentHeight) {
+ parentHeight = TheTerrainLogic->getGroundHeight(parentCell->getXIndex() * PATHFIND_CELL_SIZE_F, parentCell->getYIndex() * PATHFIND_CELL_SIZE_F);
+ hasParentHeight = true;
+ }
+ const Real toHeight = TheTerrainLogic->getGroundHeight(newCellCoord.x * PATHFIND_CELL_SIZE_F, newCellCoord.y * PATHFIND_CELL_SIZE_F);
- if ( fabs(fromPos.z - toPos.z)<PATHFIND_CELL_SIZE_F) {
+ if ( fabs(parentHeight - toHeight)<PATHFIND_CELL_SIZE_F) {
newCostSoFar += 7*COST_DIAGONAL;
}
} else if (newCell->getPinched()) {
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 7377e0623..824f50471 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -392,6 +392,7 @@ m_role(AIROLE_AGGRESSIVE)
m_incomeMarkFrame = 0;
m_bankMark = 0;
m_incomePerSecond = 0.0f;
+ m_startFortune = 0;
m_healerSeconds = 0;
m_healerClearSeconds = 0;
m_captureTimer = 1;
@@ -1865,14 +1866,16 @@ enum { SUPERWEAPON_REAIM_FRAMES = 600 * LOGICFRAMES_PER_SECOND };
//----------------------------------------------------------------------------------------------------------
/** 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 - and the fade on top of it
+ * 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
* 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.
*/
//----------------------------------------------------------------------------------------------------------
Int AIPlayer::superweaponScore( Coord3D *center, Int playerNdx, Real radius, Bool targetMilitaryUnits )
{
- const Int value = getPlayerSuperweaponValue( center, playerNdx, radius, targetMilitaryUnits, m_player->getPlayerIndex() );
+ const Int value = getPlayerSuperweaponValue( center, playerNdx, radius, targetMilitaryUnits, m_player->getPlayerIndex(),
+ strikeEconomyWeight() );
if( value <= 0 )
return value;
@@ -1894,6 +1897,14 @@ Int AIPlayer::superweaponScore( Coord3D *center, Int playerNdx, Real radius, Boo
return REAL_TO_INT( value * worth );
}
+//----------------------------------------------------------------------------------------------------------
+/** A Challenge or mission opponent aims as the map script was written for: price and threat alone. */
+//----------------------------------------------------------------------------------------------------------
+Real AIPlayer::strikeEconomyWeight( void )
+{
+ return isSkirmishAI() ? getSkillProfile()->m_strikeEconomyWeight : 0.0f;
+}
+
//----------------------------------------------------------------------------------------------------------
/** Remember a spot the next shot should leave alone.
*
@@ -2111,11 +2122,27 @@ 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
+ * 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 )
+{
+ 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 );
+}
+
//----------------------------------------------------------------------------------------------------------
/**
- * Get the target value for structures in an area.
+ * 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.
*/
-Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real radius, Bool includeMilitaryUnits, Int observerNdx )
+Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real radius, Bool includeMilitaryUnits, Int observerNdx,
+ Real economyWeight )
{
if (radius < 4*PATHFIND_CELL_SIZE_F)
{
@@ -2200,6 +2227,11 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad
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( applyNegValue )
{
cash -= factor * value * 5.0f; //Extremely undesired
@@ -2303,11 +2335,14 @@ Bool AIPlayer::isPossibleToBuildTeam( TeamPrototype *proto, Bool requireIdleFact
const ThingTemplate *thing = TheThingFactory->findTemplate( unitInfo[i].unitThingName );
if (thing) {
Int thingCost = thing->calcCostToBuild(m_player);
- if (NULL == findFactory(thing, true)) {
+ // One walk of the build list, not two: findFactory hands back the first idle factory
+ // when there is one and a busy one only when none is idle, so its queue says which.
+ Object *factory = findFactory(thing, true);
+ if (NULL == factory) {
// Couldn't find a factory.
return false;
}
- if (NULL != findFactory(thing, false)) {
+ if (factory->getProductionUpdateInterface()->getProductionCount() == 0) {
// Found an idle factory.
anyIdle = true;
}
@@ -3747,6 +3782,8 @@ Object *AIPlayer::findSupplyCenter(Int minimumCash, Bool holdableOnly)
{
Object *bestSupplyWarehouse = NULL;
Real bestDistSqr = 0;
+ Object *bestSafeWarehouse = NULL;
+ Real bestSafeDistSqr = 0;
Object *obj;
Coord3D enemyCenter;
enemyCenter.zero();
@@ -3825,8 +3862,19 @@ Object *AIPlayer::findSupplyCenter(Int minimumCash, Bool holdableOnly)
bestSupplyWarehouse = obj;
bestDistSqr = distSqr;
}
+ // The scripts ask "is the supply source safe" of this same pick and wait while it is
+ // not, putting guns down beside it: one enemy tank parked by the nearest pile held a
+ // Hard AI's expansion for ten minutes with a free pile one valley over. A safe dock
+ // is preferred, the nearest of them, and the unsafe nearest only when none is safe.
+ // A mission's script picked its piles by hand and keeps EA's nearest.
+ if (!holdableOnly && isSkirmishAI() && (bestSafeWarehouse==NULL || bestSafeDistSqr>distSqr) &&
+ isLocationSafe(obj->getPosition(), obj->getTemplate())) {
+ bestSafeWarehouse = obj;
+ bestSafeDistSqr = distSqr;
+ }
}
}
+ if (bestSafeWarehouse) return bestSafeWarehouse;
if (bestSupplyWarehouse) break;
minimumCash /= 2;
} while (minimumCash > 100);
@@ -4518,6 +4566,7 @@ void AIPlayer::checkReadyTeams( void )
Object *obj = iter.cur();
if (obj->getAI() && obj->getAI()->isIdle()) {
anyIdle = true;
+ break;
}
}
}
@@ -4637,9 +4686,10 @@ void AIPlayer::checkQueuedTeams( void )
}
Bool anyIdle = false;
for (DLINK_ITERATOR<Object> iter = team->m_team->iterate_TeamMemberList(); !iter.done(); iter.advance()) {
- Object *obj = iter.cur();
+ Object *obj = iter.cur();
if (obj && obj->getAI() && obj->getAI()->isIdle()) {
anyIdle = true;
+ break; // one is the answer, and this runs every frame for every team in the queue
}
}
if (anyIdle) {
@@ -7533,9 +7583,22 @@ void AIPlayer::doSpending( void )
buyUpgradesForArmy( overTarget );
if( !overTarget )
return;
- if( windowEnded )
- addProductionForIncome( bank, bankWindowAgo, target );
- trainSurplus( aiSurplusBudget( (Int)m_player->getMoney()->countMoney(), target, m_incomePerSecond, getSkillProfile()->m_surplusShare ) );
+ //
+ // A match that starts on 50,000 handed every AI a bank no income window ever saw coming: the
+ // surplus is a share of what it earns, and in the first minutes it earns nothing, so the fortune
+ // sat there while the build list ticked along. What is over the default starting cash, up to
+ // what the start gave over it, goes out at the rung's share a pass, and factories go up for it
+ // without waiting on a window. At the default cash the fortune is 0 and nothing here changes.
+ //
+ const Int keep = max( target, (Int)TheGlobalData->m_defaultStartingCash.countMoney() );
+ const Int fortune = aiFortuneBudget( bank, keep, m_startFortune, getSkillProfile()->m_surplusShare );
+ if( windowEnded || fortune > 0 )
+ addProductionForIncome( bank, bankWindowAgo, target ); // between windows bankWindowAgo is the bank itself
+ const Int surplus = aiSurplusBudget( (Int)m_player->getMoney()->countMoney(), target, m_incomePerSecond, getSkillProfile()->m_surplusShare );
+ if( fortune > surplus )
+ DEBUG_LOG(("AI ECONOMY frame %d player %d spends its starting fortune, %d of it this pass, %d in the bank, %d kept\n", now,
+ m_player->getPlayerIndex(), fortune, bank, keep));
+ trainSurplus( max( surplus, fortune ) );
}
//----------------------------------------------------------------------------------------------------------
@@ -13455,7 +13518,10 @@ void AIPlayer::doCapture( void )
if( capturer )
from = *capturer->getPosition();
- Object *target = nearestTechBuilding( &from, FALSE );
+ // The next derrick is the one nearest home, not nearest the capturer: from where it stood each
+ // capture led to the next one further out, so the round walked into the middle of the map and the
+ // derricks behind the base waited on it for minutes, or were never taken.
+ Object *target = nearestTechBuilding( &m_baseCenter, FALSE );
if( capturer == NULL )
{
@@ -14197,7 +14263,7 @@ void AIPlayer::xfer( Xfer *xfer )
{
// version
- XferVersion currentVersion = 23; // 2: scout 3: rung and role 4: scouting stamps 5: the capturer 6: parked waves 7: superweapon aims 8: the hijacker 9: tactical steps 10: the ferry and dropped riders 11: the outward placement ring 12: the pressure level 13: falling back 14: gunship Chinooks and the boarding wait 15: transport Chinooks and the lent one 16: healer and raider Helixes 17: the seen-enemy ledger 18: the fist 19: the Ambulances 20: the last Ambulance lost 21: the purchase queue's reservation 22: the measured income 23: the Ambulances bought
+ XferVersion currentVersion = 24; // 2: scout 3: rung and role 4: scouting stamps 5: the capturer 6: parked waves 7: superweapon aims 8: the hijacker 9: tactical steps 10: the ferry and dropped riders 11: the outward placement ring 12: the pressure level 13: falling back 14: gunship Chinooks and the boarding wait 15: transport Chinooks and the lent one 16: healer and raider Helixes 17: the seen-enemy ledger 18: the fist 19: the Ambulances 20: the last Ambulance lost 21: the purchase queue's reservation 22: the measured income 23: the Ambulances bought 24: the starting fortune
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -14600,6 +14666,8 @@ void AIPlayer::xfer( Xfer *xfer )
}
if( version >= 23 )
xfer->xferInt( &m_ambulancesBought );
+ if( version >= 24 )
+ xfer->xferInt( &m_startFortune );
// the ladder rung and the role, which are rolled once and must come back the same way
if( version >= 3 )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
index 22b7b6d35..8cff2a69c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
@@ -1346,6 +1346,10 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list)
*/
void AISkirmishPlayer::newMap( void )
{
+ // what the setup handed out over the default, which doSpending spends as it would a hoard
+ m_startFortune = (Int)m_player->getMoney()->countMoney() - (Int)TheGlobalData->m_defaultStartingCash.countMoney();
+ if( m_startFortune < 0 )
+ m_startFortune = 0;
/* Get our proper build list. */
AsciiString mySide = m_player->getSide();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 984bdb516..9d37c1d14 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -5931,6 +5931,40 @@ static Bool isWaitingForPassengerTurn(const Object *passenger, const Weapon *wea
return TheGameLogic->getFrame() - groupLastShotFrame < turnFrames;
}
+//----------------------------------------------------------------------------------------------------------
+/**
+ * After a shot this state hands back to aiming, which hands back here a frame later, and a weapon not
+ * ready yet goes round again: a shot can only come on every second frame after the last. Retail ran
+ * that loop at 30 Hz, so its weapons fired on a grid of two retail frames, and a 100 msec Quad Cannon
+ * (3 frames) fired every 4, 0.133 s. At 60 Hz the same loop is a grid of two logic frames, half as
+ * coarse, and the gun fired every 0.100 s. Holding the next shot to the next point of the retail grid
+ * puts every weapon this state fires back on its retail frames. Weapons fired elsewhere (FireWeaponUpdate,
+ * a point defense laser) never had the loop and keep their delays as they are.
+ */
+static void holdToRetailFireCycle( Object *obj, const Weapon *fired )
+{
+ const UnsignedInt now = TheGameLogic->getFrame();
+ if( fired->getLastShotFrame() != now )
+ return;
+
+ // every slot that fired this frame (linked turrets fire them all), and every slot a shared reload
+ // stamped; rounding a frame already on the grid leaves it there, so a slot met twice is no matter
+ const UnsignedInt CYCLE = 2 * LOGICFRAMES_PER_RETAIL_FRAME;
+ const Bool shared = obj->isReloadTimeShared();
+ for( Int slot = PRIMARY_WEAPON; slot < WEAPONSLOT_COUNT; ++slot )
+ {
+ Weapon *each = obj->getWeaponInWeaponSlot( (WeaponSlotType)slot );
+ if( !each || ( !shared && each->getLastShotFrame() != now ) )
+ continue;
+ const UnsignedInt next = each->getPossibleNextShotFrame();
+ // empty for good: privateFireWeapon parks it at 0x7fffffff
+ if( next >= 0x7fffffff )
+ continue;
+ const UnsignedInt wait = next > now ? next - now : 0;
+ each->setPossibleNextShotFrame( now + max( CYCLE, ( wait + CYCLE - 1 ) / CYCLE * CYCLE ) );
+ }
+}
+
//----------------------------------------------------------------------------------------------------------
/**
* Fire the owner's weapon once and exit.
@@ -6075,7 +6109,9 @@ StateReturnType AIAttackFireWeaponState::update()
// clear this, just in case.
obj->clearStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_IGNORING_STEALTH ) );
}
-
+
+ holdToRetailFireCycle( obj, weapon );
+
m_att->notifyFired();
return STATE_SUCCESS;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
index 74efe2660..d00053218 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
@@ -379,7 +379,8 @@ static Object *TunnelNetworkScan(Object *owner)
filters[count++] = NULL;
- Object* target = ThePartitionManager->getClosestObject(owner->getPosition(), visionRange, FROM_CENTER_2D, filters);
+ Object* target = ThePartitionManager->getClosestObject(owner->getPosition(), visionRange, FROM_CENTER_2D, filters, NULL, NULL,
+ owner->getTeam()->getEnemyPlayerMask()); // f1 lets only enemies through
return target;
}
@@ -727,12 +728,6 @@ StateReturnType AITNGuardIdleState::update( void )
#endif
Object *owner = getMachineOwner();
AIUpdateInterface *ai = owner->getAIUpdateInterface();
- // Check to see if we have created a crate we need to pick up.
- if (ai->getCrateID() != INVALID_ID)
- {
- getMachine()->setState(AI_TN_GUARD_GET_CRATE);
- return STATE_SLEEP(m_nextEnemyScanTime - now);
- }
// if anyone is in the inner area, return success.
if (getGuardMachine()->lookForInnerTarget())
@@ -757,6 +752,13 @@ StateReturnType AITNGuardIdleState::update( void )
return STATE_SUCCESS; // Transitions to AITNGuardInnerState.
}
+ // Check to see if we have created a crate we need to pick up, once no enemy stands in the area.
+ if (ai->getCrateID() != INVALID_ID)
+ {
+ getMachine()->setState(AI_TN_GUARD_GET_CRATE);
+ return STATE_SLEEP(m_nextEnemyScanTime - now);
+ }
+
if (!owner->getContainedBy() && findBestTunnel(owner->getControllingPlayer(), owner->getPosition())) {
return STATE_FAILURE; // go to AITNGuardReturnState, & enter a tunnel.
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
index ff4249874..609abac68 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
@@ -352,12 +352,20 @@ static void calcDirectionToApplyThrust(
}
/*
- get our cur vel into a useful Vector3 form
+ get our cur vel into a useful Vector3 form. The sum below adds an acceleration to a speed as
+ if they were the same thing, which only holds at the rate EA solved it at: so both go into
+ retail (30 Hz) frames first, a speed doubled and an acceleration times four. Only the
+ direction comes out, so nothing has to go back. Left per logic frame, gravity and the thrust
+ counted half as much against the speed as they did in 2003.
*/
+ const Real RETAIL_VEL = (Real)LOGICFRAMES_PER_RETAIL_FRAME;
+ const Real RETAIL_ACCEL = RETAIL_VEL * RETAIL_VEL;
Vector3 curVel(physics->getVelocity()->x, physics->getVelocity()->y, physics->getVelocity()->z);
+ curVel *= RETAIL_VEL;
+ maxAccel *= RETAIL_ACCEL;
// add gravity to our vel so that we account for it in our calcs
- curVel.Z += TheGlobalData->m_gravity;
+ curVel.Z += TheGlobalData->m_gravity * RETAIL_ACCEL;
Bool foundSolution = false;
Real distToGoalSqr = vecToGoal.Length2();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index 72d89ffb5..26dee8b0a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -941,6 +941,9 @@ void Object::setOrRestoreTeam( Team* team, Bool restoring )
// Switch //////////////////////////
m_team = team;
+ // the partition counts every cell's objects per player; move ours before anything searches
+ if (m_partitionData)
+ m_partitionData->refreshCountedPlayer();
// After Switch //////////////////////////
if (m_team)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
index 1d60570fa..6c4b463c3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
@@ -1214,7 +1214,10 @@ void CellAndObjectIntersection::addCoverage(PartitionCell *cell, PartitionData *
}
if (m_cell == NULL)
+ {
cell->friend_addToCellList(this);
+ cell->addPlayerCoi(module->friend_getCountedPlayer());
+ }
m_cell = cell;
m_module = module;
@@ -1230,6 +1233,7 @@ void CellAndObjectIntersection::removeAllCoverage()
}
m_cell->friend_removeFromCellList(this);
+ m_cell->removePlayerCoi(m_module->friend_getCountedPlayer());
m_cell = NULL;
m_module = NULL;
}
@@ -1247,6 +1251,7 @@ PartitionCell::PartitionCell()
//
m_firstCoiInCell = NULL;
m_coiCount = 0;
+ m_playerCoiMask = PLAYERMASK_NONE;
#ifdef PM_CACHE_TERRAIN_HEIGHT
m_loTerrainZ = HUGE_DIST; // huge positive
m_hiTerrainZ = -HUGE_DIST; // huge negative
@@ -1263,6 +1268,7 @@ PartitionCell::PartitionCell()
m_shroudLevel[i].m_currentShroud = 1;
m_shroudLevel[i].m_activeShroudLevel = 0;
m_airLookers[i] = 0;
+ m_playerCoiCount[i] = 0;
// default cash value is 0
m_cashValue[i] = 0;
@@ -1542,6 +1548,25 @@ void PartitionCell::friend_removeFromCellList(CellAndObjectIntersection *coi)
}
}
+//-----------------------------------------------------------------------------
+void PartitionCell::addPlayerCoi(Int playerIndex)
+{
+ if (playerIndex < 0)
+ return;
+ if (m_playerCoiCount[playerIndex]++ == 0)
+ m_playerCoiMask |= (PlayerMaskType)(1 << playerIndex);
+}
+
+//-----------------------------------------------------------------------------
+void PartitionCell::removePlayerCoi(Int playerIndex)
+{
+ if (playerIndex < 0)
+ return;
+ DEBUG_ASSERTCRASH(m_playerCoiCount[playerIndex] > 0, ("player coi count underflow"));
+ if (--m_playerCoiCount[playerIndex] == 0)
+ m_playerCoiMask &= (PlayerMaskType)~(1 << playerIndex);
+}
+
//-----------------------------------------------------------------------------
void PartitionCell::getCellCenterPos(Real& x, Real& y)
{
@@ -1622,6 +1647,7 @@ PartitionData::PartitionData()
m_coiArray = NULL;
m_coiInUseCount = 0;
m_doneFlag = 0;
+ m_countedPlayer = -1;
m_dirtyStatus = NOT_DIRTY;
m_lastCell = NULL;
for (int i = 0; i < MAX_PLAYER_COUNT; ++i)
@@ -2203,6 +2229,7 @@ void PartitionData::updateCellsTouched()
}
removeAllTouchedCells();
+ refreshCountedPlayer();
if (isSmall)
{
doSmallFill(pos.x, pos.y, majorRadius);
@@ -2258,7 +2285,31 @@ void PartitionData::updateCellsTouched()
}
//-----------------------------------------------------------------------------
-void PartitionData::invalidateShroudedStatusForPlayer(Int playerIndex)
+/** Each cell counts the COIs of every player's Objects so a search for one side's units can pass
+ over cells holding none of them. The count follows this module's m_countedPlayer, never the
+ Object directly, so taking a COI out always undoes what putting it in did; a capture, a defection
+ or a team handed to another player moves the counts here before anything can search. */
+void PartitionData::refreshCountedPlayer()
+{
+ const Player *player = m_object ? m_object->getControllingPlayer() : NULL;
+ const Int newPlayer = player ? player->getPlayerIndex() : -1;
+ if (newPlayer == m_countedPlayer)
+ return;
+
+ CellAndObjectIntersection *coi = m_coiArray;
+ for (Int i = m_coiArrayCount; i > 0; --i, ++coi)
+ {
+ if (coi->getModule())
+ {
+ coi->getCell()->removePlayerCoi(m_countedPlayer);
+ coi->getCell()->addPlayerCoi(newPlayer);
+ }
+ }
+ m_countedPlayer = newPlayer;
+}
+
+//-----------------------------------------------------------------------------
+void PartitionData::invalidateShroudedStatusForPlayer(Int playerIndex)
{
#ifndef DISABLE_INVALID_PREVENTION
if (m_shroudedness[playerIndex] != OBJECTSHROUD_INVALID && m_shroudedness[playerIndex] != OBJECTSHROUD_INVALID_BUT_PREVIOUS_VALID)
@@ -3355,7 +3406,8 @@ Object *PartitionManager::getClosestObjects(
PartitionFilter **filters,
SimpleObjectIterator *iterArg, // if nonnull, append ALL satisfactory objects to the iterator (not just the single closest)
Real *closestDistArg,
- Coord3D *closestVecArg
+ Coord3D *closestVecArg,
+ PlayerMaskType onlyPlayers
)
{
//USE_PERF_TIMER(getClosestObjects)
@@ -3481,6 +3533,11 @@ Object *PartitionManager::getClosestObjects(
if (thisCell == NULL)
continue;
+ // An idle guard asks this for enemies only, and most cells around it hold its own base
+ // or nothing; every Object there would fail the filters anyway, so the answer is the same.
+ if (onlyPlayers != PLAYERMASK_ALL && !thisCell->hasCoiOfPlayers(onlyPlayers))
+ continue;
+
for (CellAndObjectIntersection *thisCoi = thisCell->getFirstCoiInCell(); thisCoi; thisCoi = thisCoi->getNextCoi())
{
PartitionData *thisMod = thisCoi->getModule();
@@ -3652,10 +3709,11 @@ Object *PartitionManager::getClosestObject(
DistanceCalculationType dc,
PartitionFilter **filters,
Real *closestDist,
- Coord3D *closestDistVec
+ Coord3D *closestDistVec,
+ PlayerMaskType onlyPlayers
)
{
- return getClosestObjects(NULL, pos, maxDist, dc, filters, NULL, closestDist, closestDistVec);
+ return getClosestObjects(NULL, pos, maxDist, dc, filters, NULL, closestDist, closestDistVec, onlyPlayers);
}
//-----------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index da6fb1b04..6df395b77 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -1102,7 +1102,15 @@ Object* AIUpdateInterface::checkForCrateToPickup()
{
Object* crate = TheGameLogic->findObjectByID(m_crateCreated);
m_crateCreated = INVALID_ID; // we have processed it, so clear it.
- if (crate)
+ // The crate the victim dropped is the killer's to take only while it lies within sight: the
+ // notice waits until the killer's machine next looks, which for a unit busy with something
+ // else can be long after, and an artillery piece that killed at range would otherwise drive
+ // out across the front for it. Never under the 150 that salvageCrateTick (GameLogic.cpp)
+ // calls a busy computer unit from, or a short-sighted rebel would drop the notice it was given.
+ const Real reach = max( getObject()->getVisionRange(), 150.0f );
+ if (crate && ThePartitionManager->getDistanceSquared( getObject(), crate, FROM_CENTER_2D ) > reach * reach)
+ crate = NULL;
+ if (crate)
{
for (BehaviorModule** m = crate->getBehaviorModules(); *m; ++m)
{
@@ -7846,7 +7854,9 @@ void AIUpdateInterface::loadPostProcess( void )
chooseLocomotorSet(lst);
}
- if (!isMoving()) {
+ // A unit waiting for its path is on its way as much as one driving: it keeps the goal it holds,
+ // or another unit takes the spot it was ordered to.
+ if (!isMoving() && !m_waitingForPath) {
m_pathfindGoalCell.x = -1;
m_pathfindGoalCell.y = -1;
TheAI->pathfinder()->updateGoal(getObject(), getObject()->getPosition(), getObject()->getLayer());
@@ -7864,6 +7874,12 @@ void AIUpdateInterface::loadPostProcess( void )
}
}
+ // The pathfinder's queue is not saved, so a unit that was in it when the game was saved comes
+ // back waiting for a path nobody is going to look for, and stands for the rest of the match.
+ // One waiting on the retry timer is asked for again by update() and needs nothing here.
+ if (m_waitingForPath && m_queueForPathFrame == 0)
+ queueForPathOrRetry();
+
} // end loadPostProcess
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp
index 4374ea258..511b040c2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp
@@ -562,6 +562,16 @@ StateReturnType SupplyTruckWantsToPickUpOrDeliverBoxesState::update()
return STATE_FAILURE;
}
+ //
+ // We came here because the docking that sent us had ended and the truck stood idle. The machine
+ // runs this update before it checks its transitions, so an order the player gave on the frame we
+ // arrived is already running, and docking now would throw it away: the truck that was told to go
+ // somewhere else as it pulled off the dock drove back to the supplies instead. Busy is where the
+ // same order lands a frame earlier, through ownerNotDockingOrIdle.
+ //
+ if (!ownerAI->isIdle() && ownerAI->getLastCommandSource() != CMD_FROM_AI)
+ return STATE_SUCCESS;
+
Int numBoxes = update->getNumberBoxes();
if (numBoxes > 0)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp
index f0d894b59..803f9a29d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp
@@ -1516,7 +1516,7 @@ void SpecialAbilityUpdate::triggerAbilityEffect()
TheEva->setShouldPlay( EVA_BuildingStolen );
}
- target->defect( object->getControllingPlayer()->getDefaultTeam(), 1); // one frame of flash!
+ target->defect( object->getControllingPlayer()->getDefaultTeam(), ConvertRetailFrames( 1u ) ); // one retail frame of flash!
SpecialPowerModuleInterface *spmInterface = getMySPM();
if (spmInterface && spTemplate->getSpecialPowerType() == SPECIAL_BLACKLOTUS_CAPTURE_BUILDING )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp
index 8a76ac656..26932668b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp
@@ -333,7 +333,8 @@ Bool StealthUpdate::allowedToStealth( Object *stealthOwner ) const
return FALSE;
}
- if( flags & STEALTH_NOT_WHILE_TAKING_DAMAGE && self->getBodyModule()->getLastDamageTimestamp() >= now - 1 )
+ // hit this retail (30 Hz) frame or the one before, as EA's "now - 1" meant
+ if( flags & STEALTH_NOT_WHILE_TAKING_DAMAGE && self->getBodyModule()->getLastDamageTimestamp() >= now - ConvertRetailFrames( 1u ) )
{
// the healing test that used to sit here is gone: a heal no longer stamps the damage
// timestamp at all, so getting patched up does not keep a unit visible.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
index 7a0282258..91e392ceb 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
@@ -251,7 +251,7 @@ const FieldParse WeaponTemplate::TheWeaponTemplateFieldParseTable[] =
{ "ContinuousFireTwo", INI::parseInt, NULL, offsetof(WeaponTemplate, m_continuousFireTwoShotsNeeded) },
{ "ContinuousFireCoast", INI::parseDurationUnsignedInt, NULL, offsetof(WeaponTemplate, m_continuousFireCoastFrames) },
{ "AutoReloadWhenIdle", INI::parseDurationUnsignedInt, NULL, offsetof(WeaponTemplate, m_autoReloadWhenIdleFrames) },
- { "ClipReloadTime", INI::parseDurationUnsignedInt, NULL, offsetof(WeaponTemplate, m_clipReloadTime) },
+ { "ClipReloadTime", WeaponTemplate::parseRetailDuration, NULL, offsetof(WeaponTemplate, m_clipReloadTime) },
{ "DelayBetweenShots", WeaponTemplate::parseShotDelay, NULL, 0 },
{ "ShotsPerBarrel", INI::parseInt, NULL, offsetof(WeaponTemplate, m_shotsPerBarrel) },
{ "DamageDealtAtSelfPosition",INI::parseBool, NULL, offsetof(WeaponTemplate, m_damageDealtAtSelfPosition) },
@@ -445,13 +445,29 @@ void WeaponTemplate::reset( void )
self->m_maxDelayBetweenShots = self->m_minDelayBetweenShots;
}
- // No matter what we have now, we want to convert it to frames from msec.
+ // No matter what we have now, we want to convert it to frames from msec.
// ShotDelay used to use parseDurationUnsignedInt, and we are expanding on that.
- self->m_minDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots));
- self->m_maxDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots));
+ self->m_minDelayBetweenShots = retailFramesFromMsec(self->m_minDelayBetweenShots);
+ self->m_maxDelayBetweenShots = retailFramesFromMsec(self->m_maxDelayBetweenShots);
}
+//-------------------------------------------------------------------------------------------------
+/* A shot delay or a reload in msec, rounded up to whole retail (30 Hz) frames as EA's were and then
+ doubled, so it is always an even count of logic frames. Rounded at 60 Hz instead, 25 msec was 2
+ logic frames where retail had 1 of its own, and a rate-of-fire bonus floored a different count. */
+/*static*/ Int WeaponTemplate::retailFramesFromMsec( Int msec )
+{
+ const Real RETAIL_FRAMES_PER_MSEC = (Real)RETAIL_LOGICFRAMES_PER_SECOND / (Real)MSEC_PER_SECOND;
+ return ConvertRetailFrames( (Int)ceilf( (Real)msec * RETAIL_FRAMES_PER_MSEC ) );
+}
+
+//-------------------------------------------------------------------------------------------------
+/*static*/ void WeaponTemplate::parseRetailDuration( INI* ini, void * /*instance*/, void *store, const void* /*userData*/ )
+{
+ *(Int *)store = retailFramesFromMsec( INI::scanInt( ini->getNextToken() ) );
+}
+
//-------------------------------------------------------------------------------------------------
void WeaponTemplate::postProcessLoad()
{
@@ -537,26 +553,30 @@ Real WeaponTemplate::getUnmodifiedAttackRange() const
Int WeaponTemplate::getDelayBetweenShots(const WeaponBonus& bonus) const
{
// yes, divide, not multiply; the larger the rate-of-fire bonus, the shorter
- // we want the delay time to be.
+ // we want the delay time to be. Drawn and floored in retail frames, as EA's were, then doubled
+ // (retailFramesFromMsec).
+ const Int minDelay = m_minDelayBetweenShots / LOGICFRAMES_PER_RETAIL_FRAME;
+ const Int maxDelay = m_maxDelayBetweenShots / LOGICFRAMES_PER_RETAIL_FRAME;
Int delayToUse;
- if( m_minDelayBetweenShots == m_maxDelayBetweenShots )
- delayToUse = m_minDelayBetweenShots; // Random number thing doesn't like this case
+ if( minDelay == maxDelay )
+ delayToUse = minDelay; // Random number thing doesn't like this case
else
- delayToUse = GameLogicRandomValue( m_minDelayBetweenShots, m_maxDelayBetweenShots );
+ delayToUse = GameLogicRandomValue( minDelay, maxDelay );
Real bonusROF = bonus.getField(WeaponBonus::RATE_OF_FIRE);
//CRCDEBUG_LOG(("WeaponTemplate::getDelayBetweenShots() - min:%d max:%d val:%d, bonusROF=%g/%8.8X\n",
//m_minDelayBetweenShots, m_maxDelayBetweenShots, delayToUse, bonusROF, AS_INT(bonusROF)));
- return REAL_TO_INT_FLOOR(delayToUse / bonusROF);
+ return ConvertRetailFrames( REAL_TO_INT_FLOOR(delayToUse / bonusROF) );
}
//-------------------------------------------------------------------------------------------------
-Int WeaponTemplate::getClipReloadTime(const WeaponBonus& bonus) const
+Int WeaponTemplate::getClipReloadTime(const WeaponBonus& bonus) const
{
// yes, divide, not multiply; the larger the rate-of-fire bonus, the shorter
- // we want the reload time to be.
- return REAL_TO_INT_FLOOR(m_clipReloadTime / bonus.getField(WeaponBonus::RATE_OF_FIRE));
+ // we want the reload time to be. In retail frames, like getDelayBetweenShots.
+ const Int reload = m_clipReloadTime / LOGICFRAMES_PER_RETAIL_FRAME;
+ return ConvertRetailFrames( REAL_TO_INT_FLOOR(reload / bonus.getField(WeaponBonus::RATE_OF_FIRE)) );
}
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
index 1cd83b156..11c1e6322 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
@@ -8765,6 +8765,19 @@ void ScriptEngine::AdjustDebugVariableData(const AsciiString& variableName, Int
// ------------------------------------------------------------------------------------------------
void ScriptEngine::crc( Xfer *xfer )
{
+ // The map script's counters, timers and flags, so a script that drifted between machines is
+ // caught on the frame it drifts rather than when its effect reaches an object. Names are left
+ // out: they are fixed by the map and allocated in evaluation order. The end-game timers are
+ // left out too, since each machine starts them for its own player's victory or defeat.
+ xfer->xferInt( &m_numCounters );
+ for( Int i = 0; i < m_numCounters; ++i )
+ {
+ xfer->xferInt( &m_counters[ i ].value );
+ xfer->xferBool( &m_counters[ i ].isCountdownTimer );
+ }
+ xfer->xferInt( &m_numFlags );
+ for( Int i = 0; i < m_numFlags; ++i )
+ xfer->xferBool( &m_flags[ i ].value );
} // end crc
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 1156ce056..c2f9ddea8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -5362,6 +5362,14 @@ UnsignedInt GameLogic::getCRC( Int mode, AsciiString deepCRCFileName )
CRCGEN_LOG(("CRC after AI for frame %d is 0x%8.8X\n", m_frame, xferCRC->getCRC()));
}
+ marker = "MARKER:TheScriptEngine";
+ xferCRC->xferAsciiString(&marker);
+ xferCRC->xferSnapshot( TheScriptEngine );
+ if (isInGameLogicUpdate())
+ {
+ CRCGEN_LOG(("CRC after ScriptEngine for frame %d is 0x%8.8X\n", m_frame, xferCRC->getCRC()));
+ }
+
if (xferCRC->getXferMode() == XFER_SAVE)
{
marker = "MARKER:GameSave";
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 90e3299c3..b7be2f1fa 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -12030,6 +12030,13 @@ TEST(the_bank_target_and_the_upgrade_the_army_pays_for)
CHECK_EQ( 500, aiSurplusBudget( 4500, 4000, 100.0f, 1.0f ) ); // the excess, when that is less
CHECK_EQ( 0, aiSurplusBudget( 60000, 4000, 0.0f, 1.0f ) ); // nothing earned, nothing extra
+ // a rich start: what is over the default cash, up to what the start handed over it, at the rung's share
+ CHECK_EQ( 0, aiFortuneBudget( 60000, 10000, 0, 1.0f ) ); // default cash: as before
+ CHECK_EQ( 40000, aiFortuneBudget( 50000, 10000, 40000, 1.0f ) ); // Hard, on the first pass
+ CHECK_EQ( 2000, aiFortuneBudget( 50000, 10000, 40000, 0.05f ) ); // Easy
+ CHECK_EQ( 40000, aiFortuneBudget( 90000, 10000, 40000, 1.0f ) ); // never past the fortune
+ CHECK_EQ( 0, aiFortuneBudget( 9000, 10000, 40000, 1.0f ) ); // spent down to the default
+
// what counts toward an upgrade: a fighting unit at its fit, anything else at the rung's small weight,
// so a base worth 20,000 is 1,000 of reason to fortify it and a 10,000 army is 10,000 of reason to arm it
CHECK_NEAR( 1.5f, aiUpgradeWeight( TRUE, 1.5f, 0.05f ), 0.0001f );