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.

fix(gamelogic): skirmish ai for generals a map has no player for

Olcay Seygan4f9d04d08112
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8d89f8135..ab0f48f7e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -45,6 +45,7 @@ found and fixed — EA's own, not port damage.**
- A Paladin under Contra no longer crashes the game. Reforged gives every Paladin a second laser for infantry, and that laser borrowed a Zero Hour weapon nothing else fires. Contra deleted it, so the laser had no gun, and the game went down a moment after the first Paladin rolled out. The laser is Reforged's own weapon now and is there whatever mod you load. The same kind of gap took the guns off Contra's Toxin Tunnel Defender and Toxin Stinger soldier, the Chemical Suits off its Rangers, and the death blast off its Demolition Scud Launcher, Toxin demo trap and Toxin Tractors (ShockWave's trap too). Where Reforged names a weapon or armour the mod dropped, the unit now keeps the mod's own, and the death blasts carry Zero Hour's charge.
- Contra's units have their attack move, guard and stop buttons again, and A, G and S press them. Contra draws its command bar with eighteen buttons and keeps those three in the last row, which our fourteen-button bar does not have, so they went missing on every Contra unit, the Cybernetic general's cyborgs among them. A button a mod puts past the end of our bar now moves to an empty one, the three orders to the places Zero Hour gives them.
- Contra's cyborgs no longer stand on black squares. Their little ground shadow is drawn the way Zero Hour draws it again, darkening the ground by the shape painted in the picture, so it comes out as a soft patch under the feet. We had been reading the shape from the picture's transparency instead, and Contra's shadow picture has none: it filled its whole square. Zero Hour's own shadows look as they did.
+- A computer opponent on ShockWave's Armor, Special Weapons or Salvage general plays on every map now. Those are the three generals ShockWave adds to Zero Hour's nine, and Shockwave Chaos renames two of them the Scumbag Artillery and Bandana generals. A map made before they existed, every one Zero Hour ships among them, has no computer player for them, so the seat started with no AI at all: its base sat idle, and clicking it with nothing selected handed it to you, which is how a player found himself running the enemy's base. The seat now takes the mod's skirmish AI for that general and builds like any other; on Tournament Desert it had three buildings up in forty seconds where it used to have none.
- A `-mod` path with `.` or `..` in it is refused. An archive counts as your mod's only when it was loaded for that mod. Two mods under `-modfactions` that define a command set with the same name both load now, and the later one wins.
## One interface
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/SidesList.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/SidesList.h
index f899a3bf5..d8dacadad 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/SidesList.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/SidesList.h
@@ -212,8 +212,8 @@ protected:
TeamsInfoRec m_teamrec;
TeamsInfoRec m_skirmishTeamrec;
- /// -modfactions: each mod's SkirmishScripts.scb players and teams, kept out of m_skirmishSides, which
- /// a map's own sides nearly fill
+ /// -modfactions: each mod's SkirmishScripts.scb players and teams; and the standard file's players for
+ /// sides the map has none for. Kept out of m_skirmishSides, which a map's own sides nearly fill
std::vector<SidesInfo> m_modSkirmishSides;
TeamsInfoRec m_modSkirmishTeamrec;
void loadModSkirmishScripts(void);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp
index 03eb43b9d..8bff5a901 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp
@@ -457,32 +457,8 @@ static Bool ParsePlayersDataChunk(DataChunkInput &file, DataChunkInfo *info, voi
return true;
}
-/**
-* ParseTeamsDataChunk - read teams data chunk.
-* Format is the newer CHUNKY format.
-* Input: DataChunkInput
-*
-*/
-static Bool ParseTeamsDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData)
-{
- SidesList *sides = (SidesList *)userData;
- while (!file.atEndOfChunk()) {
- Dict teamDict = file.readDict();
- AsciiString teamName = teamDict.getAsciiString(TheKey_teamName);
- AsciiString player = teamDict.getAsciiString(TheKey_teamOwner);
- if (sides->findSkirmishSideInfo(player)) {
- // player exists, so just add it.
- sides->addSkirmishTeam(&teamDict);
- //DEBUG_LOG(("Adding team %s\n", teamName.str()));
- } else {
- //DEBUG_LOG(("Couldn't add team %s, no player %s\n", teamName.str(), player.str()));
- }
- }
- DEBUG_ASSERTCRASH(file.atEndOfChunk(), ("Unexpected data left over."));
- return true;
-}
-
-/// a mod's ScriptTeams, kept whole until its players are known (loadModSkirmishScripts)
+/// a SkirmishScripts.scb's ScriptTeams, kept whole until its players are known
+/// (loadModSkirmishScripts, prepareForMP_or_Skirmish)
static Bool ParseModTeamsDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData)
{
while (!file.atEndOfChunk()) {
@@ -754,9 +730,10 @@ void SidesList::prepareForMP_or_Skirmish(void)
DataChunkInput file( pStrm );
file.registerParser( AsciiString("PlayerScriptsList"), AsciiString::TheEmptyString, ScriptList::ParseScriptsDataChunk );
file.registerParser( AsciiString("ScriptsPlayers"), AsciiString::TheEmptyString, ParsePlayersDataChunk );
- file.registerParser( AsciiString("ScriptTeams"), AsciiString::TheEmptyString, ParseTeamsDataChunk );
+ file.registerParser( AsciiString("ScriptTeams"), AsciiString::TheEmptyString, ParseModTeamsDataChunk );
if (!file.parse(this)) {
DEBUG_LOG(("ERROR - Unable to read in skirmish scripts.\n"));
+ static_readModTeams.clear();
return;
}
ScriptList *scripts[MAX_PLAYER_COUNT];
@@ -772,15 +749,47 @@ void SidesList::prepareForMP_or_Skirmish(void)
break;
}
}
- if (curSide == -1) continue;
+ if (curSide == -1) {
+ /* A map saved before a faction existed has no skirmish player for it: every retail map
+ lacks ShockWave's Armor, Special Weapons and Salvage generals. Player::initFromDict then
+ found no scripts, made the seat human with no AI, and the base stood idle - and the
+ takeover click handed it to whoever clicked it. The file's own player for that side
+ stands in, kept beside the map's, which nearly fill m_skirmishSides. */
+ const PlayerTemplate *pt = ThePlayerTemplateStore->findPlayerTemplate(NAMEKEY(static_readPlayerDicts[i].getAsciiString(TheKey_playerFaction)));
+ if (scripts[i] && pt && pt->isPlayableSide() && findSkirmishSideFor(pt, NULL) == NULL) {
+ DEBUG_LOG(("Skirmish map has no player for %s, using %s from the standard scripts\n", pt->getSide().str(), static_readPlayerNames[i].str()));
+ m_modSkirmishSides.push_back(SidesInfo());
+ m_modSkirmishSides.back().init(&static_readPlayerDicts[i]);
+ m_modSkirmishSides.back().setScriptList(scripts[i]);
+ scripts[i] = NULL;
+ }
+ if (scripts[i])
+ scripts[i]->deleteInstance();
+ continue;
+ }
ScriptList *pSL = getSkirmishSideInfo(curSide)->getScriptList();
getSkirmishSideInfo(curSide)->setScriptList(scripts[i]);
scripts[i] = NULL;
- if (pSL)
+ if (pSL)
pSL->deleteInstance();
scripts[i] = NULL;
}
+ for (Int t = 0; t < static_readModTeams.getNumTeams(); ++t) {
+ const Dict *teamDict = static_readModTeams.getTeamInfo(t)->getDict();
+ const AsciiString owner = teamDict->getAsciiString(TheKey_teamOwner);
+ if (findSkirmishSideInfo(owner)) {
+ addSkirmishTeam(teamDict);
+ continue;
+ }
+ for (size_t s = 0; s < m_modSkirmishSides.size(); ++s) {
+ if (m_modSkirmishSides[s].getDict()->getAsciiString(TheKey_playerName) == owner) {
+ m_modSkirmishTeamrec.addTeam(teamDict);
+ break;
+ }
+ }
+ }
+ static_readModTeams.clear();
for (i=0; i<MAX_PLAYER_COUNT; i++) {
static_readPlayerNames[i].clear();
static_readPlayerDicts[i].clear();