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): pay a supply upgrade by the load, not by the trip

Olcay Seygan832d5495cd89
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbb5a7292..81494ec43 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -220,6 +220,8 @@ found and fixed — EA's own, not port damage.**
- Something flagged unselectable is unselectable. The flag existed and nothing read it.
- Double-clicking to grab everything of a kind grabs what a box would, not things you can only click one at a time.
- A bounty pays what the percentage says. Rounding up a fraction that was already a whole number paid a dollar extra on every kill.
+- A supply upgrade pays for what arrives. The bonus was a flat sum handed over on arrival, so a truck turning up with one box collected the same as a full load - and a driver dropping off little and often earned several times what the upgrade is worth.
+- Taking over a defeated ally's base no longer starts his research again from scratch. A player upgrade is bought once for the whole player, and the buildings you inherit were left paying for a second copy of what you already had.
## One crate, one collector
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h
index 045eb61ac..ea8790849 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h
@@ -194,6 +194,7 @@ public:
virtual ObjectID getPreferredDockID() const = 0;
virtual UnsignedInt getActionDelayForDock( Object *dock ) = 0;
virtual Int getUpgradedSupplyBoost() const = 0;
+ virtual Int getMaxBoxes() const = 0; ///< how many boxes a full load is
/** The dock state announces how long the box it is working on takes; that window is what the
* progress bar over the worker's head fills across. (See AIDockProcessDockState.) */
@@ -237,6 +238,7 @@ public:
virtual ObjectID getPreferredDockID() const { return m_preferredDock; }
virtual UnsignedInt getActionDelayForDock( Object *dock );
virtual Int getUpgradedSupplyBoost() const { return 0; }
+ virtual Int getMaxBoxes() const { return getSupplyTruckAIUpdateModuleData()->m_maxBoxesData; }
virtual void noteDockActionWindow( UnsignedInt frames );
virtual Real getDockActionProgress() const;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h
index 6544ab2b2..a58a8bca6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h
@@ -214,6 +214,7 @@ public:
virtual void finishBuildingSound();
virtual Int getUpgradedSupplyBoost() const;
+ virtual Int getMaxBoxes() const { return getWorkerAIUpdateModuleData()->m_maxBoxesData; }
virtual void noteDockActionWindow( UnsignedInt frames );
virtual Real getDockActionProgress() const;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 501379f95..c1238d825 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -2150,6 +2150,19 @@ void Player::setObjectsEnabled(AsciiString templateTypeToAffect, Bool enable)
}
//=============================================================================
+//=============================================================================
+// Cancel an upgrade a building of the losing player still has in its queue, because the player
+// taking the assets over has it already.
+//=============================================================================
+static void cancelUpgradeInProduction(Object *obj, void *userData)
+{
+ const UpgradeTemplate *upgradeTemplate = (const UpgradeTemplate *)userData;
+ ProductionUpdateInterface *pui = ProductionUpdate::getProductionUpdateInterfaceFromObject(obj);
+
+ if (pui && pui->isUpgradeInQueue(upgradeTemplate))
+ pui->cancelUpgrade(upgradeTemplate);
+}
+
void Player::transferAssetsFromThat(Player *that)
{
Team *defaultTeam = getDefaultTeam();
@@ -2190,6 +2203,31 @@ void Player::transferAssetsFromThat(Player *that)
(*itObjs)->setTeam(defaultTeam);
}
+ // Take over what he had in the research queues. A player upgrade is bought once for the whole
+ // player, so an ally who already has one - or is already paying for it - would otherwise end up
+ // with a second copy being researched in the buildings he just inherited, paid for and useless.
+ std::vector<const UpgradeTemplate *> upgradesToCancel;
+ for (Upgrade *upgrade = that->m_upgradeList; upgrade; upgrade = upgrade->friend_getNext())
+ {
+ const UpgradeTemplate *upgradeTemplate = upgrade->getTemplate();
+
+ if (upgrade->getStatus() == UPGRADE_STATUS_IN_PRODUCTION
+ && upgradeTemplate->getUpgradeType() == UPGRADE_TYPE_PLAYER
+ && (hasUpgradeComplete(upgradeTemplate) || hasUpgradeInProduction(upgradeTemplate)))
+ {
+ upgradesToCancel.push_back(upgradeTemplate);
+ }
+ }
+
+ for (std::vector<const UpgradeTemplate *>::iterator cancelIt = upgradesToCancel.begin();
+ cancelIt != upgradesToCancel.end(); ++cancelIt)
+ {
+ that->iterateObjects(cancelUpgradeInProduction, (void *)(*cancelIt));
+ }
+
+ // and what he was part way through that we were not: otherwise it can be started a second time
+ m_upgradesInProgress.set(that->m_upgradesInProgress);
+
// transfer all his money
UnsignedInt allMoney = that->getMoney()->countMoney();
that->getMoney()->withdraw(allMoney);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp
index 0b8002936..62775f39f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp
@@ -100,12 +100,22 @@ Bool SupplyCenterDockUpdate::action( Object* docker, Object *drone )
return FALSE;
UnsignedInt value = 0;
+
+ // The upgrade bonus is a flat sum paid on arrival, so a truck that turned up with one box in it
+ // collected the whole bonus, and a driver who dropped off little and often earned several times
+ // what a full load pays. Scale it by how much of a load actually arrived. This has to be read
+ // before the boxes are unloaded below.
+ {
+ const Int maxBoxes = supplyTruckAI->getMaxBoxes();
+ if( maxBoxes > 0 )
+ value += (UnsignedInt)((supplyTruckAI->getUpgradedSupplyBoost() * supplyTruckAI->getNumberBoxes()) / maxBoxes);
+ }
+
Player *ownerPlayer = getObject()->getControllingPlayer();
while( supplyTruckAI->loseOneBox() )
value += ownerPlayer->getSupplyBoxValue();
- // Add money boost from upgrades that give extra money
- value += supplyTruckAI->getUpgradedSupplyBoost();
+ // (the upgrade bonus was added above, scaled by how full the truck was)
if( value > 0)
{