Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class ProductionUpdate : public UpdateModule, public ProductionUpdateInterface,
virtual DieModuleInterface* getDie() override { return this; }
static ProductionUpdateInterface *getProductionUpdateInterfaceFromObject( Object *obj );

/// @return the quantity modifier for the given thing template, or 1 if none found
Int getQuantityForTemplate(const ThingTemplate* thingTemplate) const;

virtual CanMakeType canQueueCreateUnit( const ThingTemplate *unitType ) const override;
virtual CanMakeType canQueueUpgrade( const UpgradeTemplate *upgrade ) const override;

Expand Down
25 changes: 25 additions & 0 deletions Generals/Code/GameEngine/Source/Common/RTS/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "Common/PlayerList.h"
#include "Common/PlayerTemplate.h"
#include "Common/ProductionPrerequisite.h"
#include "GameLogic/Module/ProductionUpdate.h"
#include "Common/Radar.h"
#include "Common/ResourceGatheringManager.h"
#include "Common/Team.h"
Expand Down Expand Up @@ -2028,6 +2029,30 @@
return;

Int costToBuild = victim->getTemplate()->calcCostToBuild(victim->getControllingPlayer());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be much nicer to have a

const Int victimValue = victim->getTemplate()->calcProductionValue(victim->getControllingPlayer());


// TheSuperHackers @bugfix zhaog100 23/03/2026
// When a unit is produced in quantity (e.g. China Red Guards come in pairs),
// the BuildCost on the template reflects the total cost for the whole batch,
// not the per-unit cost. Look up the producer's quantity modifier to get the
// correct per-unit bounty value.
ObjectID producerID = victim->getProducerID();
if (producerID != INVALID_ID)
{
Object* producer = TheGameLogic->findObjectByID(producerID);
if (producer)
{
ProductionUpdate* pu = dynamic_cast<ProductionUpdate*>(producer->getProductionUpdateInterface());

Check warning on line 2044 in Generals/Code/GameEngine/Source/Common/RTS/Player.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / vc6+t+e

'dynamic_cast' used on polymorphic type 'class ProductionUpdateInterface' with /GR-; unpredictable behavior may result

Check warning on line 2044 in Generals/Code/GameEngine/Source/Common/RTS/Player.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / vc6-profile+t+e

'dynamic_cast' used on polymorphic type 'class ProductionUpdateInterface' with /GR-; unpredictable behavior may result
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code base does not use dynamic_cast.

if (pu)
{
Int quantity = pu->getQuantityForTemplate(victim->getTemplate());
if (quantity > 1)
{
costToBuild = costToBuild / quantity;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks retail compatibility.

}
}
}
}

#if RETAIL_COMPATIBLE_CRC
Int bounty = REAL_TO_INT_CEIL(costToBuild * m_cashBountyPercent);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1395,3 +1395,21 @@ void ProductionUpdate::loadPostProcess()
UpdateModule::loadPostProcess();

}

// ------------------------------------------------------------------------------------------------
/** Get the production quantity modifier for the given thing template. */
// ------------------------------------------------------------------------------------------------
Int ProductionUpdate::getQuantityForTemplate(const ThingTemplate* thingTemplate) const
{
const ProductionUpdateModuleData* pud = getProductionUpdateModuleData();
const std::vector<QuantityModifier>& modifiers = pud->m_quantityModifiers;
for (std::vector<QuantityModifier>::const_iterator it = modifiers.begin(); it != modifiers.end(); ++it)
{
const ThingTemplate* modTemplate = TheThingFactory->findTemplate(it->m_templateName);
if (modTemplate && modTemplate->isEquivalentTo(thingTemplate))
{
return it->m_quantity;
}
}
return 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class ProductionUpdate : public UpdateModule, public ProductionUpdateInterface,
virtual DieModuleInterface* getDie() override { return this; }
static ProductionUpdateInterface *getProductionUpdateInterfaceFromObject( Object *obj );

/// @return the quantity modifier for the given thing template, or 1 if none found
Int getQuantityForTemplate(const ThingTemplate* thingTemplate) const;

virtual CanMakeType canQueueCreateUnit( const ThingTemplate *unitType ) const override;
virtual CanMakeType canQueueUpgrade( const UpgradeTemplate *upgrade ) const override;

Expand Down
24 changes: 24 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,30 @@
return;

Int costToBuild = victim->getTemplate()->calcCostToBuild(victim->getControllingPlayer());

// TheSuperHackers @bugfix zhaog100 23/03/2026
// When a unit is produced in quantity (e.g. China Red Guards come in pairs),
// the BuildCost on the template reflects the total cost for the whole batch,
// not the per-unit cost. Look up the producer's quantity modifier to get the
// correct per-unit bounty value.
ObjectID producerID = victim->getProducerID();
if (producerID != INVALID_ID)
{
Object* producer = TheGameLogic->findObjectByID(producerID);
if (producer)
{
ProductionUpdate* pu = dynamic_cast<ProductionUpdate*>(producer->getProductionUpdateInterface());

Check warning on line 2444 in GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / vc6+t+e

'dynamic_cast' used on polymorphic type 'class ProductionUpdateInterface' with /GR-; unpredictable behavior may result

Check warning on line 2444 in GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / vc6-profile+t+e

'dynamic_cast' used on polymorphic type 'class ProductionUpdateInterface' with /GR-; unpredictable behavior may result

Check warning on line 2444 in GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / vc6-releaselog+t+e

'dynamic_cast' used on polymorphic type 'class ProductionUpdateInterface' with /GR-; unpredictable behavior may result
if (pu)
{
Int quantity = pu->getQuantityForTemplate(victim->getTemplate());
if (quantity > 1)
{
costToBuild = costToBuild / quantity;
}
}
}
}

#if RETAIL_COMPATIBLE_CRC
Int bounty = REAL_TO_INT_CEIL(costToBuild * m_cashBountyPercent);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1399,3 +1399,21 @@ void ProductionUpdate::loadPostProcess()
UpdateModule::loadPostProcess();

}

// ------------------------------------------------------------------------------------------------
/** Get the production quantity modifier for the given thing template. */
// ------------------------------------------------------------------------------------------------
Int ProductionUpdate::getQuantityForTemplate(const ThingTemplate* thingTemplate) const
{
const ProductionUpdateModuleData* pud = getProductionUpdateModuleData();
const std::vector<QuantityModifier>& modifiers = pud->m_quantityModifiers;
for (std::vector<QuantityModifier>::const_iterator it = modifiers.begin(); it != modifiers.end(); ++it)
{
const ThingTemplate* modTemplate = TheThingFactory->findTemplate(it->m_templateName);
if (modTemplate && modTemplate->isEquivalentTo(thingTemplate))
{
return it->m_quantity;
}
}
return 1;
}
Loading