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): keep each army's AI and scripts in its own namespace

Olcay Seygan305afec973f0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 942a04a07..b16d6592b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -347,6 +347,9 @@ found and fixed, EA's own, not port damage.**
## Mods
- A mod is a folder now. Start the game with `-mod` and the folder, and its archives count, and so do the plain files under its `Data` and `Art` folders, which the game used to ignore. A modder can drop in one changed file without packing an archive first.
+- A computer player on a mod's army now plays that mod's own plan. Contra's scripts pressed Zero Hour's buttons of the same name, so its GLA stash trucks never trained a worker and earned about a thousand in ten minutes, and its scripts looked for supply piles under a name no map uses. On Hard Contra's GLA now earns 18,000 to 36,000 in the same ten minutes, its USA and China about twice what they did.
+- Zero Hour's armies play the very same match with a mod loaded as without it, on every difficulty. Their computer players used to look through the mod's units for a scout too, and one that nobody could train cost them the scout.
+- A long army name in a room now shrinks to fit the field, and only that name.
- A mod's armies always stand beside Zero Hour's, never over them, one mod or five. Contra alone used to swap every USA, China and GLA in the room for its own and leave you nothing else to play. Now the list holds Zero Hour's armies and under them "Contra - Tank General" and the rest, so a Contra general can fight a plain Zero Hour China in one match. No switch asks for this and none turns it off. A plain Random stays with Zero Hour's armies; a mod's army plays when somebody picks it or ticks it into a Custom Selection. On the army screen each mod's generals gather under one heading a country, "Contra - USA", where Contra's twelve used to make twelve headings and run off the screen. Playing a mod's army you hear that mod's music tracks, so the Enhanced Music pack for Contra plays in the match.
- Reforged stays on top of every mod. This build's balance, its fixes to EA's data, its AI and its menus load after the mod and win where they touch the same unit, weapon or button, on Zero Hour's armies; a mod's army keeps its own numbers and buttons. A change that names something the mod renamed or removed is passed over instead of stopping the game, which is how ShockWave starts and plays. A mod's own copy of a file Reforged ships, the skirmish setup screen among them, is ignored, and so are any upscaled art archives it carries. The one exception is the skirmish AI's scripts: a mod's are written for its own generals, so they replace Reforged's, and Reforged's smarter AI plays them.
- A mod no longer repaints the game around it. Shockwave Chaos set the whole skirmish lobby in Comic Sans, with its own yellow-edged boxes, loading bars, main menu backdrop and score screens, because its archives replaced the font list, the shell's image sheets and the pictures they are cut from. Every menu and lobby layout, the fonts, the shell's colours and frames and the in-match screens are ours now under any mod. The mod's units, their build pictures and its generals with their portraits still come from the mod, and its new generals still appear in the lobby's faction list.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h
index 362c6214e..9393c537e 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h
@@ -649,6 +649,9 @@ public:
Bool isEquivalentTo(const ThingTemplate* tt) const;
+ /// the -mod whose army this is, read off the "M<n>~" on its name; -1 for retail's
+ Int getModIndex() const;
+
UnsignedByte getCrushableLevel() const { return m_crushableLevel; }
UnsignedByte getCrusherLevel() const { return m_crusherLevel; }
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
index 0533b6c2a..05e9e3371 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
@@ -400,9 +400,10 @@ const ThingTemplate *ThingFactory::findSideReskin( const ThingTemplate *tmplate,
// skip a Toxin player's chassis was swapped for Chem_GLAVehicleTechnical itself, a unit with no
// weapon or locomotor: the Arms Dealer charged for a Technical and nothing drove out.
const ThingTemplate *found = NULL;
+ const Int mod = tmplate->getModIndex();
for (const ThingTemplate *t = m_firstTemplate; t != NULL && found == NULL; t = t->friend_getNextTemplate())
{
- if (t->getDefaultOwningSide() == side && t->getBuildVariations().empty() && t->isEquivalentTo( tmplate ))
+ if (t->getDefaultOwningSide() == side && t->getModIndex() == mod && t->getBuildVariations().empty() && t->isEquivalentTo( tmplate ))
found = (const ThingTemplate *)t->getFinalOverride();
}
m_sideReskins[ key ] = found;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp
index 38d315ffd..1f8986e9d 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp
@@ -41,6 +41,7 @@
#define DEFINE_BUILDABLE_STATUS_NAMES // for BuildableStatusNames[]
#include "Common/DamageFX.h"
+#include "Common/FileSystem.h"
#include "Common/GameAudio.h"
#include "Common/GameCommon.h"
#include "Common/GlobalData.h"
@@ -1642,6 +1643,15 @@ UnsignedInt ThingTemplate::getMaxSimultaneousOfType() const
+//-------------------------------------------------------------------------------------------------
+Int ThingTemplate::getModIndex() const
+{
+ Int mod = -1;
+ AsciiString bareName;
+ FileSystem::splitModName( getName(), &mod, &bareName );
+ return mod;
+}
+
//-------------------------------------------------------------------------------------------------
Bool ThingTemplate::isEquivalentTo(const ThingTemplate* tt) const
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetComboBox.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetComboBox.cpp
index af3019717..349072440 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetComboBox.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetComboBox.cpp
@@ -53,7 +53,9 @@
#include "Common/AudioEventRTS.h"
#include "Common/GameAudio.h"
#include "Common/Debug.h"
+#include "Common/GlobalData.h"
#include "GameClient/DisplayStringManager.h"
+#include "GameClient/GameFont.h"
#include "GameClient/GameWindow.h"
#include "GameClient/Gadget.h"
#include "GameClient/GameWindowManager.h"
@@ -87,6 +89,34 @@ static Int dropDownHeight( WinInstanceData *listInstData, Int lines, Bool scroll
return (fontHeight + (scrolls ? 1 : 2)) * lines + (scrolls ? 6 : 4);
}
+// A seat's Army field was cut for "China Tank General"; a mod's name in front of that runs into the
+// arrow. Only the picked label goes smaller, and the next short one is back at the combo's own size.
+static void fitFieldToLabel( GameWindow *combo, GameWindow *field, const UnicodeString &label )
+{
+ static const Int FIELD_MARGIN = 6;
+ static const Int SMALLEST_POINT_SIZE = 8;
+
+ if( !TheGlobalData->m_modFactions )
+ return;
+
+ Int fieldWidth, fieldHeight;
+ field->winGetSize( &fieldWidth, &fieldHeight );
+
+ GameFont *font = combo->winGetFont();
+ DisplayString *measured = TheDisplayStringManager->newDisplayString();
+ measured->setFont( font );
+ measured->setText( label );
+ while( measured->getWidth() > fieldWidth - FIELD_MARGIN && font->pointSize > SMALLEST_POINT_SIZE )
+ {
+ font = TheFontLibrary->getFont( font->nameString, font->pointSize - 1, font->bold );
+ measured->setFont( font );
+ }
+ TheDisplayStringManager->freeDisplayString( measured );
+
+ if( font != field->winGetFont() )
+ field->winSetFont( font );
+}
+
///////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -471,9 +501,10 @@ WindowMsgHandledType GadgetComboBoxSystem( GameWindow *window, UnsignedInt msg,
tempUString = GadgetListBoxGetTextAndColor( comboData->listBox, &color, mData2, 0 );
GadgetTextEntrySetTextColor(comboData->editBox, color);
-
+
+ fitFieldToLabel(window, comboData->editBox, tempUString);
GadgetTextEntrySetText(comboData->editBox, tempUString);
-
+
TheWindowManager->winSendSystemMsg( window->winGetOwner(),
GCM_SELECTED,
(WindowMsgData)window,
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index b9e916186..1a8544a7d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -37,6 +37,7 @@
#include "Common/GlobalData.h"
#include "Common/PerfTimer.h"
#include "Common/Player.h"
+#include "Common/PlayerTemplate.h"
#include "Common/SpecialPower.h"
#include "Common/Team.h"
#include "Common/ThingFactory.h"
@@ -3254,6 +3255,19 @@ static Real templateFramesToKill( const ThingTemplate *attacker, const ThingTemp
return frames;
}
+static Int playerArmyMod( const Player *player )
+{
+ const PlayerTemplate *faction = player->getPlayerTemplate();
+ return faction != NULL ? faction->getModIndex() : -1;
+}
+
+/** A mod's America carries retail's side name, so a scan of every template by side or by kind walks
+ * into the other army: a retail Ranger's job went to a mod's cheaper rifleman nobody can train here. */
+static Bool isOwnArmy( const Player *player, const ThingTemplate *tmpl )
+{
+ return tmpl->getModIndex() == playerArmyMod( player );
+}
+
/*static*/ void AIPlayer::prepareMatchupTables( void )
{
theFramesToKillCache.clear();
@@ -3261,14 +3275,16 @@ static Real templateFramesToKill( const ThingTemplate *attacker, const ThingTemp
theDetectsStealthCache.clear();
Bool skirmishAI = FALSE;
- std::vector<AsciiString> sides;
+ typedef std::pair<AsciiString, Int> SideInMod;
+ std::vector<SideInMod> sides;
for( Int i = 0; i < ThePlayerList->getPlayerCount(); ++i )
{
Player *player = ThePlayerList->getNthPlayer( i );
if( player->isSkirmishAIPlayer() )
skirmishAI = TRUE;
- if( std::find( sides.begin(), sides.end(), player->getSide() ) == sides.end() )
- sides.push_back( player->getSide() );
+ const SideInMod side( player->getSide(), playerArmyMod( player ) );
+ if( std::find( sides.begin(), sides.end(), side ) == sides.end() )
+ sides.push_back( side );
}
if( !skirmishAI )
return;
@@ -3283,7 +3299,7 @@ static Real templateFramesToKill( const ThingTemplate *attacker, const ThingTemp
{
if( tmpl->friend_getBuildCost() <= 0 || tmpl->isKindOf( KINDOF_STRUCTURE ) || tmpl->getBuildable() == BSTATUS_NO )
continue;
- if( std::find( sides.begin(), sides.end(), tmpl->getDefaultOwningSide() ) != sides.end() )
+ if( std::find( sides.begin(), sides.end(), SideInMod( tmpl->getDefaultOwningSide(), tmpl->getModIndex() ) ) != sides.end() )
units.push_back( tmpl );
}
for( size_t a = 0; a < units.size(); ++a )
@@ -3558,11 +3574,11 @@ static Bool templateCanStealth( const ThingTemplate *tmpl )
}
/** Some unit that goes invisible from the factory waits on this science: the USA's Pathfinder. */
-static Bool unlocksStealthUnit( ScienceType science )
+static Bool unlocksStealthUnit( const Player *player, ScienceType science )
{
for( const ThingTemplate *tmpl = TheThingFactory->firstTemplate(); tmpl; tmpl = tmpl->friend_getNextTemplate() )
{
- if( !templateCanStealth( tmpl ) )
+ if( !templateCanStealth( tmpl ) || !isOwnArmy( player, tmpl ) )
continue;
for( Int p = 0; p < tmpl->getPrereqCount(); ++p )
{
@@ -5560,7 +5576,7 @@ void AIPlayer::doUpgradesAndSkills( void )
if (m_persona == AIPERSONA_SNEAKY) {
for (Int s = 0; s < skillset->m_numSkills; ++s) {
const ScienceType science = skillset->m_skills[s];
- if (unlocksStealthUnit(science) && m_player->isCapableOfPurchasingScience(science))
+ if (unlocksStealthUnit(m_player, science) && m_player->isCapableOfPurchasingScience(science))
m_player->attemptToPurchaseScience(science);
}
}
@@ -16181,7 +16197,7 @@ static const ThingTemplate *cheapestScoutTemplate( Player *player )
continue; // those have a job
if( t->isKindOf( KINDOF_AIRCRAFT ) || t->isKindOf( KINDOF_IMMOBILE ) )
continue;
- if( !player->canBuild( t ) )
+ if( !isOwnArmy( player, t ) || !player->canBuild( t ) )
continue;
Int cost = t->calcCostToBuild( player );
@@ -16652,7 +16668,7 @@ static const ThingTemplate *cheapestCapturerTemplate( Player *player )
{
if( !t->isKindOf( KINDOF_INFANTRY ) || t->isKindOf( KINDOF_DOZER ) )
continue;
- if( !player->canBuild( t ) )
+ if( !isOwnArmy( player, t ) || !player->canBuild( t ) )
continue;
const Int cost = t->calcCostToBuild( player );
@@ -17002,7 +17018,7 @@ static const ThingTemplate *cheapestHijackerTemplate( Player *player )
for( const ThingTemplate *t = TheThingFactory->firstTemplate(); t; t = t->friend_getNextTemplate() )
{
- if( !t->isKindOf( KINDOF_INFANTRY ) || !couldBuildUnit( player, t ) )
+ if( !t->isKindOf( KINDOF_INFANTRY ) || !isOwnArmy( player, t ) || !couldBuildUnit( player, t ) )
continue;
const Int cost = t->calcCostToBuild( player );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp
index ae105a798..1c13b442a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp
@@ -54,6 +54,8 @@
#include "Common/GlobalData.h"
#include "Common/PlayerTemplate.h"
#include "Common/RandomMapGenerator.h"
+#include "Common/ThingFactory.h"
+#include "Common/ThingTemplate.h"
#include "Common/WellKnownKeys.h"
#include "Common/Xfer.h"
#include "GameLogic/AI.h"
@@ -513,10 +515,30 @@ struct ModScriptNames
case Parameter::UPGRADE: type = MODNAME_UPGRADE; break;
case Parameter::SCIENCE: type = MODNAME_SCIENCE; break;
case Parameter::SPECIAL_POWER: type = MODNAME_SPECIALPOWER; break;
- case Parameter::COMMAND_BUTTON: type = MODNAME_COMMANDBUTTON; break;
+ case Parameter::COMMAND_BUTTON:
+ case Parameter::COMMANDBUTTON_ABILITY:
+ case Parameter::COMMANDBUTTON_ALL_ABILITIES: type = MODNAME_COMMANDBUTTON; break;
default: return;
}
- parm->friend_setString(TheModNamespace.modName(mod, type, parm->getString()));
+ const AsciiString modded = TheModNamespace.modName(mod, type, parm->getString());
+ if (type != MODNAME_OBJECT || !namesMapObject(parm->getString(), modded))
+ parm->friend_setString(modded);
+ }
+ /** Maps stay retail's under every mod, so what stands on them is retail's: a mod's script asking
+ * after a SupplyDock means the map's, and M<n>~SupplyDock stands nowhere. Contra's stash trucks
+ * never left home for a pile. */
+ Bool namesMapObject(const AsciiString& name, const AsciiString& modded) const
+ {
+ const ThingTemplate *modTemplate = TheThingFactory->findTemplate(modded, FALSE);
+ if (modTemplate == NULL || modded == name || TheThingFactory->findTemplate(name, FALSE) == NULL)
+ return FALSE;
+ for (Int i = 0; i < ThePlayerTemplateStore->getPlayerTemplateCount(); ++i)
+ {
+ const PlayerTemplate *faction = ThePlayerTemplateStore->getNthPlayerTemplate(i);
+ if (faction->getModIndex() == mod && faction->getSide() == modTemplate->getDefaultOwningSide())
+ return FALSE;
+ }
+ return TRUE;
}
void script(Script *s) const
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp
index 016fa4813..a7964835b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp
@@ -44,8 +44,6 @@
#include "GameClient/GadgetPushButton.h"
#include "GameClient/GameText.h"
#include "GameClient/Display.h"
-#include "GameClient/DisplayStringManager.h"
-#include "GameClient/GameFont.h"
#include "GameClient/Image.h"
#include "GameClient/Mouse.h"
#include "GameClient/UIStyle.h"
@@ -313,34 +311,6 @@ void PopulateColorComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myG
// -----------------------------------------------------------------------------
-// a seat's Army field was cut for "China Tank General"; a mod's name in front of that runs into the arrow
-static void shrinkComboToFit(GameWindow *combo, const UnicodeString &label)
-{
- static const Int FIELD_MARGIN = 6;
- static const Int SMALLEST_POINT_SIZE = 8;
-
- GameWindow *field = GadgetComboBoxGetEditBox(combo);
- Int fieldWidth, fieldHeight;
- field->winGetSize(&fieldWidth, &fieldHeight);
-
- GameFont *fieldFont = field->winGetFont();
- GameFont *font = fieldFont;
- DisplayString *measured = TheDisplayStringManager->newDisplayString();
- measured->setFont(font);
- measured->setText(label);
- while (measured->getWidth() > fieldWidth - FIELD_MARGIN && font->pointSize > SMALLEST_POINT_SIZE)
- {
- font = TheFontLibrary->getFont(font->nameString, font->pointSize - 1, font->bold);
- measured->setFont(font);
- }
- TheDisplayStringManager->freeDisplayString(measured);
-
- if (font != fieldFont)
- GadgetComboBoxSetFont(combo, font);
-}
-
-// -----------------------------------------------------------------------------
-
void PopulatePlayerTemplateComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool allowObservers)
{
Int numPlayerTemplates = ThePlayerTemplateStore->getPlayerTemplateCount();
@@ -415,7 +385,6 @@ void PopulatePlayerTemplateComboBox(Int comboBox, GameWindow *comboArray[], Game
label = UnicodeString(modName);
label.concat(UnicodeString(u" - "));
label.concat(sideLabel);
- shrinkComboToFit(comboArray[comboBox], label);
}
newIndex = GadgetComboBoxAddEntry(comboArray[comboBox], label, def->getColor());
GadgetComboBoxSetItemData(comboArray[comboBox], newIndex, (void *)(intptr_t)c);