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(data): ai no longer sells its base when cash runs low

Olcay Seygan0f1d562802de
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 095c3f06e..fea56e4a5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -244,6 +244,7 @@ found and fixed — EA's own, not port damage.**
- Easy, Medium, Hard, the three the game has always had. There were six for a while, with a rung either side of Medium and one above the top; they are gone again, and nothing above the top went with them - Hard now plays what the top of that six-rung ladder played. For a while the top rung was called Brutal on the seat list; it is Hard again, the name the box always printed.
- Every level plays by your rules. No level gets extra money, cheaper units, faster building, longer vision or tougher units - in either direction. What changes is what the computer is allowed to decide: how often it looks at the map, how long it takes to react, whether it counters what you field, whether it masses before attacking, whether it pulls damaged units out.
- Hard used to break that promise without saying so. EA's skirmish scripts handed a Hard computer four free cash drops as the match went on, 10,000 early (5,000 for the GLA), another 10,000, then 15,000 and 20,000 late: up to 55,000 a game that no truck ever hauled. Every general had them. They are switched off, so Hard's bank is what its trucks and oil derricks bring in. The other grants in those scripts, the ones that pay for its first buildings, are untouched.
+- A computer that is losing keeps its base. EA's scripts had every general sell off every building it owned the moment its bank fell under 2,000 with no truck, supply building or oil derrick left, or once its last dozer, command centre and factory were gone. Ten seconds later the whole base turned into cash and the match ended on an empty field instead of a fight. That is switched off for all twelve generals at every level, so you finish a beaten opponent by knocking its buildings down.
- Easy looks around and answers late, a little sooner than it used to, and it sends its supply trucks to fit the piles. It never pulls a unit out, never builds against what you field, and stops once the opening base is up. Normal reacts a bit sooner, starts spending once the bank passes 6,000, where it used to wait for 10,000, and answers about half of what you field. A unit that is personally finished still leaves, and it still goes out for a second supply pile. Factories past the opening list stay a Hard behaviour. Hard is the opponent with nothing held back: no reaction delay at all, it builds against what it can see you fielding, it gathers an army before it commits it, and it takes a losing team off the field. Replays recorded before this change play out differently.
- Measured, not asserted: Hard beats Easy 15-0 over 32 headless matches with the seats swapped both ways, on twice the army and twice the spending.
- The ladder reads as one ladder wherever a seat is listed. Half of it was named in EA's old words - "Easy Army", "Medium Army" - and half in ours, in the same drop-down, because four separate lists answered "what is this seat called" and no two of them agreed. Every one of them says Easy AI, Medium AI, Hard AI now: the lobby, the seat itself, the game info panel and the online browser.
diff --git a/GeneralsMD/Code/Data/Scripts/SkirmishScripts.scb b/GeneralsMD/Code/Data/Scripts/SkirmishScripts.scb
index 331bd0892..df74ed38f 100644
Binary files a/GeneralsMD/Code/Data/Scripts/SkirmishScripts.scb and b/GeneralsMD/Code/Data/Scripts/SkirmishScripts.scb differ
diff --git a/Tools/ScbTool/sell_off.py b/Tools/ScbTool/sell_off.py
new file mode 100644
index 000000000..569a3b6a9
--- /dev/null
+++ b/Tools/ScbTool/sell_off.py
@@ -0,0 +1,50 @@
+"""Stop the skirmish AI from selling its whole base.
+
+Every player list in the retail file has a "<Side> Sell Off" group of two scripts. "<Side> Sell off
+check" is active and fires once when the AI is down to no dozer, no command centre and no factory,
+or under 2,000 cash with no harvester, supply building or oil derrick left; it starts a ten second
+timer and enables "<Side> Sell off", which runs PLAYER_SELL_EVERYTHING when the timer expires. This
+marks the twelve checks inactive. The sell scripts already start inactive and only the checks
+enable them, so neither runs.
+
+usage: sell_off.py <in.scb> <out.scb>
+
+The master is the retail file through opening.py H 1 4 5 6, then infantry_drop.py, then
+ai_bonus.py, then this.
+"""
+import sys
+
+import scbtool
+
+ACTIVE = 4
+EXPECTED = 12
+
+
+def main():
+ source, target = sys.argv[1], sys.argv[2]
+ table, chunks = scbtool.load(source)
+ list_chunk = next(chunk for chunk in chunks if chunk.name == "PlayerScriptsList")
+ count = 0
+ for index, script_list in enumerate(list_chunk.children):
+ for group, script in scbtool.walk_scripts(script_list.children):
+ if not group.endswith(" Sell Off"):
+ continue
+ actions = [child.fields[1] for child in script.children if child.name != "OrCondition"]
+ if script.fields[0].endswith(" Sell off"):
+ if actions != ["PLAYER_SELL_EVERYTHING"] or script.fields[ACTIVE]:
+ raise SystemExit(f"[{index}] {script.fields[0]!r} is not an inactive PLAYER_SELL_EVERYTHING")
+ continue
+ if actions != ["SET_MILLISECOND_TIMER", "ENABLE_SCRIPT"]:
+ raise SystemExit(f"[{index}] {script.fields[0]!r} does {actions}, not the sell off check")
+ if not script.fields[ACTIVE]:
+ raise SystemExit(f"[{index}] {script.fields[0]!r} is already inactive; run this on ai_bonus.py's output")
+ script.fields[ACTIVE] = 0
+ count += 1
+ if count != EXPECTED:
+ raise SystemExit(f"found {count} sell off checks, expected {EXPECTED}")
+ print(f"{count} sell off checks switched off")
+ scbtool.save(target, table, chunks)
+
+
+if __name__ == "__main__":
+ main()