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(gameengine): a mod faction's rank grants the mod's rank sciences

Olcay Seygan196af66a6f49
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9af58744..eddc8a980 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,7 +27,7 @@ found and fixed — EA's own, not port damage.**
- 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, so a mod plays with Reforged's rules. 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.json` in the folder names the mod and its version. The names stand beside the version number in the options menu, in the order the mods were given, and go into every replay you record, so a replay made with mods says which ones, and the replay list marks it as another version when the game is running without them.
- Joining a LAN game that runs different mods used to end in a box about a mismatch and nothing else. It names the host's mods now, or tells you the host plays without any.
-- Two total conversions in one match. Add `-modfactions` to the mods you give, and each mod's armies join Zero Hour's own instead of replacing them: the faction list reads "ShockWave - USA" and "The End of Days - USA" under plain "USA", and a ShockWave army can fight an End of Days one. Each side builds from its own mod's units, weapons, upgrades and generals' powers, and each looks and sounds like its own mod: a ShockWave tank wears ShockWave's model and textures even where The End of Days replaces the same file, and speaks with ShockWave's voice. Playing a mod's faction, your buttons, build pictures, unit names and tooltips are that mod's, set in our American command bar whichever side you picked. The End of Days' Russia is in the list under its own name. Menus, lobby and colours stay ours whatever mods you load. The skirmish AI lays out a mod's base from the mod's own buildings, but it still trains the army it knows from Zero Hour.
+- Two total conversions in one match. Add `-modfactions` to the mods you give, and each mod's armies join Zero Hour's own instead of replacing them: the faction list reads "ShockWave - USA" and "The End of Days - USA" under plain "USA", and a ShockWave army can fight an End of Days one. Each side builds from its own mod's units, weapons, upgrades and generals' powers, and each looks and sounds like its own mod: a ShockWave tank wears ShockWave's model and textures even where The End of Days replaces the same file, and speaks with ShockWave's voice. Playing a mod's faction, your buttons, build pictures, unit names and tooltips are that mod's, set in our American command bar whichever side you picked. The End of Days' Russia is in the list under its own name. Each mod general's promotion screen holds that mod's own powers, with the mod's pictures, and they unlock with your rank; ShockWave's and The End of Days' screens used to open empty, because a rank granted only Zero Hour's own rank marks and the mod's powers asked for the mod's. Menus, lobby and colours stay ours whatever mods you load. The skirmish AI lays out a mod's base from the mod's own buildings, but it still trains the army it knows from Zero Hour.
- A patch for a mod stays with that mod. Give it with `-modpatch` right after the mod it changes, and its files replace that mod's one for one, even beside a second total conversion: a ShockWave balance patch reaches ShockWave's armies and leaves The End of Days alone. Given first, a patch changes Zero Hour's own files. The launcher's MODS page marks each mod a patch or a full mod, and a `mod.json` can say `"patch": true`. With two full mods switched on the launcher now plays them side by side; before, ShockWave and The End of Days together stopped the game at startup.
## One interface
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
index e6ff684a9..6f2d016c0 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h
@@ -207,6 +207,9 @@ public:
/// set. Finders ask this on a miss, so a definition of the mod's own X never falls through to retail's.
Bool findRetailName( const AsciiString &name, ModNameType type, AsciiString *retailName ) const;
Bool findRetailKey( NameKeyType key, ModNameType type, NameKeyType *retailKey ) const;
+ /// mod (0-based) defines a `type` called name, which its own INI then names "M<n>~name"
+ Bool defines( Int mod, ModNameType type, const AsciiString &name ) const
+ { return mod >= 0 && mod < (Int)m_mods.size() && m_mods[ mod ].byType[ type ].count( name.str() ) != 0; }
static const char *const FactionFiles[]; ///< what scanMods reads and the mod passes load, NULL-ended; no ".ini" is a directory
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
index fe1a3747c..831563a0b 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
@@ -863,6 +863,8 @@ private:
using grantScience() instead.
*/
Bool addScience(ScienceType science);
+ /// a rank's science, and under -modfactions the player's mod's own copy of it too
+ void addRankScience(ScienceType science);
public:
Int getSkillPoints() const { return m_skillPoints; }
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 7237f6247..c2622df37 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -56,6 +56,7 @@
#include "Common/DisabledTypes.h"
#include "Common/GameState.h"
#include "Common/GlobalData.h"
+#include "Common/INI.h"
#include "Common/MessageStream.h"
#include "Common/MiscAudio.h"
#include "Common/PerfTimer.h"
@@ -2694,7 +2695,7 @@ void Player::resetSciences()
{
for (ScienceVec::const_iterator it = rank->m_sciencesGranted.begin(); it != rank->m_sciencesGranted.end(); ++it)
{
- addScience(*it);
+ addRankScience(*it);
}
}
}
@@ -2703,6 +2704,23 @@ void Player::resetSciences()
TheScriptEngine->notifyOfAcquiredScience(getPlayerIndex(), *it);
}
+//=============================================================================
+/** Rank.ini is retail's and grants retail's SCIENCE_Rank<n>. Under -modfactions a mod that defines its
+ * own rank sciences has every science of its generals ask for those, "M<n>~SCIENCE_Rank3", so a
+ * player of that mod's faction gets the mod's copy beside retail's or none of the mod's promotions
+ * ever has its prerequisites. */
+void Player::addRankScience(ScienceType science)
+{
+ addScience(science);
+ const Int mod = getPlayerTemplate() ? getPlayerTemplate()->getModIndex() : -1;
+ const AsciiString name = TheScienceStore->getInternalNameForScience(science);
+ if (!TheModNamespace.defines(mod, MODNAME_SCIENCE, name))
+ return;
+ AsciiString modName;
+ modName.format("M%d~%s", mod + 1, name.str());
+ addScience(TheScienceStore->getScienceFromInternalName(modName));
+}
+
//=============================================================================
/// returns TRUE if sciences were gained/lost.
Bool Player::addScience(ScienceType science)
@@ -2906,7 +2924,7 @@ Bool Player::setRankLevel(Int newLevel)
for (ScienceVec::const_iterator it = rank->m_sciencesGranted.begin(); it != rank->m_sciencesGranted.end(); ++it)
{
- addScience(*it);
+ addRankScience(*it);
}
m_levelDown = rank->m_skillPointsNeeded;