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.

feat(gameclient): reforged's figures and upgrades in the build popup

Olcay Seygan2ae7f3941b33
diff --git a/GeneralsMD/Code/Data/German/Generals.str b/GeneralsMD/Code/Data/German/Generals.str
index 7badcf314..63e80067b 100644
--- a/GeneralsMD/Code/Data/German/Generals.str
+++ b/GeneralsMD/Code/Data/German/Generals.str
@@ -14589,10 +14589,66 @@ TOOLTIP:SupplyPileFull
"\n Belegt: Das Haufenlimit hält deine Sammler fern"
END
+TOOLTIP:StatTime
+"Bauzeit"
+END
+
+TOOLTIP:StatDamage
+"Schaden"
+END
+
+TOOLTIP:StatRange
+"Reichweite"
+END
+
+TOOLTIP:StatHealth
+"Gesundheit"
+END
+
+TOOLTIP:StatAttackSpeed
+"Angriffstempo"
+END
+
+TOOLTIP:StatDamagePerSecond
+"Schaden pro Sekunde"
+END
+
+TOOLTIP:StatArmor
+"Panzerung"
+END
+
+TOOLTIP:StatArmorStronger
+"stärker"
+END
+
+TOOLTIP:StatNewWeapon
+"Neue Waffe"
+END
+
+TOOLTIP:StatNewWeaponGround
+"Bodenwaffe"
+END
+
+TOOLTIP:StatNewWeaponAir
+"Luftabwehrwaffe"
+END
+
+TOOLTIP:StatNewWeaponFigures
+"%d Schaden, %d Reichweite"
+END
+
TOOLTIP:Upgrades
"AUFRÜSTUNGEN"
END
+TOOLTIP:UpgradeChanges
+"ÄNDERUNGEN"
+END
+
+TOOLTIP:UpgradeOwned
+"vorhanden"
+END
+
GUI:PeaceTimeOff
"Keine Friedenszeit"
END
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index c99662d84..b45532913 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -804,12 +804,78 @@ TOOLTIP:SupplyPileFull
"\n Taken: the pile limit keeps your gatherers out"
END
+// The build tooltip card's figures, a label and its value each.
+
+TOOLTIP:StatTime
+"Build time"
+END
+
+TOOLTIP:StatSeconds
+"%ds"
+END
+
+TOOLTIP:StatDamage
+"Damage"
+END
+
+TOOLTIP:StatRange
+"Range"
+END
+
+TOOLTIP:StatHealth
+"Health"
+END
+
+TOOLTIP:StatAttackSpeed
+"Attack speed"
+END
+
+TOOLTIP:StatPerSecond
+"/s"
+END
+
+TOOLTIP:StatDamagePerSecond
+"Damage per second"
+END
+
+TOOLTIP:StatArmor
+"Armor"
+END
+
+TOOLTIP:StatArmorStronger
+"stronger"
+END
+
+TOOLTIP:StatNewWeapon
+"New weapon"
+END
+
+TOOLTIP:StatNewWeaponGround
+"Ground weapon"
+END
+
+TOOLTIP:StatNewWeaponAir
+"Anti-air weapon"
+END
+
+TOOLTIP:StatNewWeaponFigures
+"%d damage, %d range"
+END
+
// Under the figures: a unit's upgrades, or on an upgrade's card the units it changes.
TOOLTIP:Upgrades
"UPGRADES"
END
+TOOLTIP:UpgradeChanges
+"CHANGES"
+END
+
+TOOLTIP:UpgradeOwned
+"owned"
+END
+
// Peace time - the lobby combo box, its tooltip, the corner countdown and the three things the game
// says while the clock runs. Tools/peacetime_layout.py selfcheck fails if any of these goes missing.
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index 50ae55e80..b5d058091 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15409,10 +15409,74 @@ GUI:CantBuildTooManyDerrickDefenses
"Bu petrol kuyularının çevresinde zaten iki savunmanız var."
END
+TOOLTIP:StatTime
+"Üretim süresi"
+END
+
+TOOLTIP:StatSeconds
+"%d sn"
+END
+
+TOOLTIP:StatDamage
+"Hasar"
+END
+
+TOOLTIP:StatRange
+"Menzil"
+END
+
+TOOLTIP:StatHealth
+"Can"
+END
+
+TOOLTIP:StatAttackSpeed
+"Atış hızı"
+END
+
+TOOLTIP:StatPerSecond
+"/sn"
+END
+
+TOOLTIP:StatDamagePerSecond
+"Saniyelik hasar"
+END
+
+TOOLTIP:StatArmor
+"Zırh"
+END
+
+TOOLTIP:StatArmorStronger
+"güçlenir"
+END
+
+TOOLTIP:StatNewWeapon
+"Yeni silah"
+END
+
+TOOLTIP:StatNewWeaponGround
+"Kara silahı"
+END
+
+TOOLTIP:StatNewWeaponAir
+"Uçaksavar silahı"
+END
+
+TOOLTIP:StatNewWeaponFigures
+"%d hasar, %d menzil"
+END
+
TOOLTIP:Upgrades
"GELİŞTİRMELER"
END
+TOOLTIP:UpgradeChanges
+"ETKİLEDİKLERİ"
+END
+
+TOOLTIP:UpgradeOwned
+"alındı"
+END
+
GUI:HudStatArmy
"Ordu değeri"
END
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
index 52810beea..fd10a4bfa 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
@@ -91,12 +91,16 @@
#include "GameClient/ControlBar.h"
#include "GameClient/DisplayStringManager.h"
#include "GameLogic/GameLogic.h"
+#include "GameLogic/Damage.h"
+#include "GameLogic/Module/FireWeaponWhenDeadBehavior.h"
+#include "GameLogic/Module/MaxHealthUpgrade.h"
#include "GameLogic/Module/OverchargeBehavior.h"
#include "GameLogic/Module/ProductionUpdate.h"
#include "GameLogic/ScriptEngine.h"
#include "GameNetwork/NetworkInterface.h"
#include "GameNetwork/GameSpy/ThreadUtils.h" // WideCharStringToMultiByte
+#include "GameLogic/Weapon.h" // WeaponTemplate/WeaponBonus for the build tooltip's figures
#ifdef _INTERNAL
// for occasional debugging...
//#pragma optimize("", off)
@@ -109,6 +113,400 @@ static AnimateWindowManager *theAnimateWindowManager = NULL;
static GameWindow *prevWindow = NULL;
static Bool useAnimation = FALSE;
+//-------------------------------------------------------------------------------------------------
+/** What the build tooltip says beyond retail's name, price and description, piece by piece, the
+ * way Reforged's card laid it out; ControlBarPopupDescription.wnd gets it as lines of its text. */
+//-------------------------------------------------------------------------------------------------
+/** One line of what an upgrade does: the figure under `label`, a string table label, goes from `from` to `to`. */
+struct BuildTooltipChange
+{
+ const char *label;
+ std::string from;
+ std::string to;
+};
+
+/** An upgrade and what it does to one unit. On a unit's card `name` is the upgrade's; on an
+ * upgrade's card it is the unit's. */
+struct BuildTooltipUpgrade
+{
+ UnicodeString name;
+ Bool owned; ///< the player has it already
+ std::vector< BuildTooltipChange > changes;
+};
+
+struct BuildTooltipCard
+{
+ Bool hasStats; ///< a unit's card: the figures below are there
+ Int buildSeconds;
+ Int health; ///< 0 for a body that cannot be hurt
+ Int damage; ///< the main weapon's, with the upgrades the player owns; 0 for no weapon
+ Int range;
+ Real attacksPerSecond; ///< shots a second over a whole clip and its reload
+ Int damagePerSecond;
+ std::vector< BuildTooltipUpgrade > upgrades; ///< a unit's upgrades, or the units an upgrade changes
+};
+
+/** One weapon slot's figures; `weapon` NULL for a slot with nothing in it that hurts. */
+struct WeaponFigures
+{
+ const WeaponTemplate *weapon;
+ Real damage;
+ Real range;
+ Real attacksPerSecond;
+};
+
+/** A unit's health and its weapons, slot by slot. */
+struct UnitFigures
+{
+ Real health;
+ WeaponFigures slots[ WEAPONSLOT_COUNT ];
+
+ /** The slot with the most damage a second, WEAPONSLOT_COUNT for an unarmed unit. */
+ Int mainSlot( void ) const
+ {
+ Int best = WEAPONSLOT_COUNT;
+ for( Int slot = PRIMARY_WEAPON; slot < WEAPONSLOT_COUNT; ++slot )
+ if( slots[ slot ].weapon && ( best == WEAPONSLOT_COUNT || slots[ slot ].damage * slots[ slot ].attacksPerSecond
+ > slots[ best ].damage * slots[ best ].attacksPerSecond ) )
+ best = slot;
+ return best;
+ }
+};
+
+//-------------------------------------------------------------------------------------------------
+/** What an upgrade does to a unit, as far as the build tooltip counts it: the modules it triggers
+ * on that unit, added together. */
+//-------------------------------------------------------------------------------------------------
+struct UpgradeEffect
+{
+ Bool weaponSet; ///< WeaponSetUpgrade: the PLAYER_UPGRADE weapon set
+ Bool weaponBonus; ///< WeaponBonusUpgrade: the PLAYER_UPGRADE weapon bonus
+ Bool armor; ///< ArmorUpgrade, which the tooltip names without a figure
+ Real addHealth; ///< MaxHealthUpgrade
+};
+
+static void addEffect( UpgradeEffect &into, const UpgradeEffect &effect )
+{
+ into.weaponSet = into.weaponSet || effect.weaponSet;
+ into.weaponBonus = into.weaponBonus || effect.weaponBonus;
+ into.armor = into.armor || effect.armor;
+ into.addHealth += effect.addHealth;
+}
+
+typedef std::map< std::string, UpgradeEffect > UpgradeEffects;
+
+//-------------------------------------------------------------------------------------------------
+/** Every upgrade that triggers one of `thing`'s weapon, armour or health upgrade modules, by the
+ * upgrade's name, and what it does. A module that wants all its triggers at once is counted under
+ * each of them alone. */
+// ponytail: RequiresAllTriggers is read as any trigger; no stock unit hangs a figure on two upgrades at once
+//-------------------------------------------------------------------------------------------------
+static void findUpgradeEffects( const ThingTemplate *thing, UpgradeEffects &effects )
+{
+ const ModuleInfo &modules = thing->getBehaviorModuleInfo();
+ for( Int m = 0; m < modules.getCount(); ++m )
+ {
+ const AsciiString &module = modules.getNthName( m );
+ UpgradeEffect effect = {};
+ if( module.compareNoCase( "WeaponSetUpgrade" ) == 0 )
+ effect.weaponSet = TRUE;
+ else if( module.compareNoCase( "WeaponBonusUpgrade" ) == 0 )
+ effect.weaponBonus = TRUE;
+ else if( module.compareNoCase( "ArmorUpgrade" ) == 0 )
+ effect.armor = TRUE;
+ else if( module.compareNoCase( "MaxHealthUpgrade" ) == 0 )
+ effect.addHealth = static_cast< const MaxHealthUpgradeModuleData * >( modules.getNthData( m ) )->m_addMaxHealth;
+ else
+ continue;
+
+ const UpgradeMuxData &mux = static_cast< const UpgradeModuleData * >( modules.getNthData( m ) )->m_upgradeMuxData;
+ for( size_t trigger = 0; trigger < mux.m_activationUpgradeNames.size(); ++trigger )
+ addEffect( effects[ mux.m_activationUpgradeNames[ trigger ].str() ], effect );
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The bomb `thing` sets off when it kills itself: the largest death weapon of a FireWeaponWhenDead
+ * module that is on from the start and fires on a SUICIDED death. The Terrorist, and a bike with one
+ * riding it, shoot TerroristSuicideWeapon, 999999 damage that reaches nobody but the shooter, so that
+ * his death fires the real bomb. */
+// ponytail: a bomb an upgrade swaps in (Demo's fire pack, Anthrax Beta and Gamma) is not read; the object's live modules would have it
+//-------------------------------------------------------------------------------------------------
+static const WeaponTemplate *suicideBomb( const ThingTemplate *thing )
+{
+ const WeaponTemplate *best = NULL;
+ const ModuleInfo &modules = thing->getBehaviorModuleInfo();
+ for( Int m = 0; m < modules.getCount(); ++m )
+ {
+ if( modules.getNthName( m ).compareNoCase( "FireWeaponWhenDeadBehavior" ) != 0 )
+ continue;
+ const FireWeaponWhenDeadBehaviorModuleData *data = static_cast< const FireWeaponWhenDeadBehaviorModuleData * >( modules.getNthData( m ) );
+ if( !data->m_initiallyActive || !data->m_upgradeMuxData.m_activationUpgradeNames.empty() || data->m_deathWeapon == NULL
+ || !getDeathTypeFlag( data->m_dieMuxData.m_deathTypes, DEATH_SUICIDED ) )
+ continue;
+ const WeaponBonus none;
+ if( best == NULL || data->m_deathWeapon->getPrimaryDamage( none ) > best->getPrimaryDamage( none ) )
+ best = data->m_deathWeapon;
+ }
+ return best;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A clip fires its shots a delay apart and then reloads in place of the last delay. A weapon that
+ * does no damage, the dummies that hold a slot until an upgrade fills it, is none, and so is one
+ * that heals, clears or unloads: a dozer's mine disarming "weapon" does 1 damage at a range of 5
+ * so that it can be aimed, and an Ambulance's cleanup is the same. A weapon that reaches nobody but
+ * its user stands for the bomb his death fires, and one whose blast kills its user goes off once,
+ * so it has no rate and no damage a second. */
+//-------------------------------------------------------------------------------------------------
+static WeaponFigures weaponFigures( const ThingTemplate *thing, const WeaponTemplate *weapon, const WeaponBonus &bonus )
+{
+ WeaponFigures figure = {};
+ if( ( weapon->getAffectsMask() & ( WEAPON_AFFECTS_ALLIES | WEAPON_AFFECTS_ENEMIES | WEAPON_AFFECTS_NEUTRALS ) ) == 0 )
+ {
+ weapon = suicideBomb( thing );
+ if( weapon == NULL )
+ return figure;
+ }
+ const DamageType type = weapon->getDamageType();
+ if( type == DAMAGE_HEALING || type == DAMAGE_DISARM || type == DAMAGE_HAZARD_CLEANUP || type == DAMAGE_DEPLOY
+ || !IsHealthDamagingDamage( type ) )
+ return figure;
+
+ const Real damage = weapon->getPrimaryDamage( bonus );
+ if( damage <= 0.0f )
+ return figure;
+ const Real delay = max( 1.0f, INT_TO_REAL( weapon->getMinDelayBetweenShots() + weapon->getMaxDelayBetweenShots() ) * 0.5f
+ / bonus.getField( WeaponBonus::RATE_OF_FIRE ) );
+ const Int clip = weapon->getClipSize();
+ const Real cycle = clip > 0 ? ( clip - 1 ) * delay + max( 1, weapon->getClipReloadTime( bonus ) ) : delay;
+
+ figure.weapon = weapon;
+ figure.damage = damage;
+ figure.range = weapon->getAttackRange( bonus );
+ figure.attacksPerSecond = weapon->getAffectsMask() & WEAPON_KILLS_SELF ? 0.0f : ( clip > 0 ? clip : 1 ) * LOGICFRAMES_PER_SECOND / cycle;
+ return figure;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** `thing`'s figures with `effect` applied, read off the template the way Weapon::computeBonus
+ * reads an object: the game's own weapon bonuses and the weapon's extra ones. */
+//-------------------------------------------------------------------------------------------------
+static UnitFigures figuresOf( const ThingTemplate *thing, const UpgradeEffect &effect )
+{
+ UnitFigures figures = {};
+ figures.health = thing->calcMaxHealth() + effect.addHealth;
+
+ WeaponSetFlags setFlags;
+ if( effect.weaponSet )
+ setFlags.set( WEAPONSET_PLAYER_UPGRADE );
+ const WeaponBonusConditionFlags bonusFlags = effect.weaponBonus ? ( 1 << WEAPONBONUSCONDITION_PLAYER_UPGRADE ) : 0;
+ const WeaponTemplateSet *set = thing->findWeaponTemplateSet( setFlags );
+ for( Int slot = PRIMARY_WEAPON; set && slot < WEAPONSLOT_COUNT; ++slot )
+ {
+ const WeaponTemplate *weapon = set->getNth( (WeaponSlotType)slot );
+ if( weapon == NULL )
+ continue;
+
+ WeaponBonus bonus;
+ TheGlobalData->m_weaponBonusSet->appendBonuses( bonusFlags, bonus );
+ if( weapon->getExtraBonus() )
+ weapon->getExtraBonus()->appendBonuses( bonusFlags, bonus );
+ figures.slots[ slot ] = weaponFigures( thing, weapon, bonus );
+ }
+ return figures;
+}
+
+static std::string wholeFigure( Real value )
+{
+ return std::to_string( REAL_TO_INT( value ) );
+}
+
+/** Attacks a second, two decimals and the string table's unit: "1.25/s". */
+static std::string rateFigure( Real value )
+{
+ char text[ 32 ];
+ snprintf( text, sizeof( text ), "%.2f", value );
+ return text + WideCharStringToMultiByte( TheGameText->fetch( "TOOLTIP:StatPerSecond" ).str() );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The lines that tell `from` and `to` apart. The main weapon is compared figure by figure when
+ * the upgrade leaves it in its slot; any other weapon the upgrade puts in, a Ranger's grenade or a
+ * Humvee's missile, is a line of its own with its damage and range. Then the armour, when
+ * `effect` changes it. */
+//-------------------------------------------------------------------------------------------------
+static void putChanges( const UnitFigures &from, const UnitFigures &to, const UpgradeEffect &effect,
+ std::vector< BuildTooltipChange > &changes )
+{
+ if( wholeFigure( from.health ) != wholeFigure( to.health ) )
+ {
+ const BuildTooltipChange health = { "TOOLTIP:StatHealth", wholeFigure( from.health ), wholeFigure( to.health ) };
+ changes.push_back( health );
+ }
+
+ const Int main = from.mainSlot();
+ if( main != WEAPONSLOT_COUNT && to.slots[ main ].weapon )
+ {
+ const WeaponFigures &before = from.slots[ main ];
+ const WeaponFigures &after = to.slots[ main ];
+ const BuildTooltipChange damage = { "TOOLTIP:StatDamage", wholeFigure( before.damage ), wholeFigure( after.damage ) };
+ const BuildTooltipChange speed = { "TOOLTIP:StatAttackSpeed", rateFigure( before.attacksPerSecond ), rateFigure( after.attacksPerSecond ) };
+ const BuildTooltipChange perSecond = { "TOOLTIP:StatDamagePerSecond", wholeFigure( before.damage * before.attacksPerSecond ),
+ wholeFigure( after.damage * after.attacksPerSecond ) };
+ const BuildTooltipChange range = { "TOOLTIP:StatRange", wholeFigure( before.range ), wholeFigure( after.range ) };
+
+ const BuildTooltipChange *candidates[] = { &damage, &speed, &perSecond, &range };
+ for( Int each = 0; each < (Int)ARRAY_SIZE( candidates ); ++each )
+ if( candidates[ each ]->from != candidates[ each ]->to )
+ changes.push_back( *candidates[ each ] );
+ }
+
+ for( Int slot = PRIMARY_WEAPON; slot < WEAPONSLOT_COUNT; ++slot )
+ {
+ const WeaponFigures &after = to.slots[ slot ];
+ if( ( slot == main && main != WEAPONSLOT_COUNT && after.weapon ) || after.weapon == NULL || after.weapon == from.slots[ slot ].weapon )
+ continue;
+
+ // named by what it aims at, since TOW puts in one missile for the ground and one for the air
+ const Int aims = after.weapon->getAntiMask();
+ const Bool atGround = ( aims & WEAPON_ANTI_GROUND ) != 0;
+ const Bool atAir = ( aims & WEAPON_ANTI_AIRBORNE_VEHICLE ) != 0;
+ const char *label = atGround == atAir ? "TOOLTIP:StatNewWeapon" : ( atAir ? "TOOLTIP:StatNewWeaponAir" : "TOOLTIP:StatNewWeaponGround" );
+
+ UnicodeString figures;
+ figures.format( TheGameText->fetch( "TOOLTIP:StatNewWeaponFigures" ), REAL_TO_INT( after.damage ), REAL_TO_INT( after.range ) );
+ const BuildTooltipChange weapon = { label, "", WideCharStringToMultiByte( figures.str() ) };
+ changes.push_back( weapon );
+ }
+
+ if( effect.armor )
+ {
+ const BuildTooltipChange armor = { "TOOLTIP:StatArmor", "", WideCharStringToMultiByte( TheGameText->fetch( "TOOLTIP:StatArmorStronger" ).str() ) };
+ changes.push_back( armor );
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The effect of every upgrade in `effects` the player has, leaving out `leftOut`. */
+//-------------------------------------------------------------------------------------------------
+static UpgradeEffect ownedEffect( const UpgradeEffects &effects, const Player *player, const std::string &leftOut )
+{
+ UpgradeEffect owned = {};
+ for( UpgradeEffects::const_iterator upgrade = effects.begin(); upgrade != effects.end(); ++upgrade )
+ {
+ const UpgradeTemplate *known = TheUpgradeCenter->findUpgrade( upgrade->first.c_str() );
+ if( upgrade->first != leftOut && known && player->hasUpgradeComplete( known ) )
+ addEffect( owned, upgrade->second );
+ }
+ return owned;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** What the build button that sells `upgrade` calls it, so a unit's card and the upgrade's own card
+ * say the same name: the upgrade's own label reads "Ranger Flash-Bang Grenades" where its button
+ * reads "Flash-Bang Grenades". The selection's own buttons first, since several buttons sell one
+ * upgrade under labels that differ ("Flash-Bang Grenade" on one, "Grenades" on the Barracks'); then
+ * any button; the upgrade's label when no button sells it. */
+//-------------------------------------------------------------------------------------------------
+static UnicodeString upgradeButtonName( const UpgradeTemplate *upgrade )
+{
+ const Drawable *selected = TheInGameUI->getFirstSelectedDrawable();
+ const Object *seller = selected ? selected->getObject() : NULL;
+ const CommandSet *set = seller ? TheControlBar->findCommandSet( seller->getCommandSetString() ) : NULL;
+ for( Int slot = 0; set && slot < MAX_COMMANDS_PER_SET; ++slot )
+ {
+ const CommandButton *button = set->getCommandButton( slot );
+ if( button && button->getUpgradeTemplate() == upgrade && button->getTextLabel().isNotEmpty() )
+ return TheGameText->fetch( button->getTextLabel() );
+ }
+
+ for( const CommandButton *button = TheControlBar->getCommandButtons(); button; button = button->getNext() )
+ if( button->getUpgradeTemplate() == upgrade && button->getTextLabel().isNotEmpty() )
+ return TheGameText->fetch( button->getTextLabel() );
+ return TheGameText->fetch( upgrade->getDisplayNameLabel() );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A unit's card: its figures with the upgrades the player owns, and each upgrade that changes one
+ * of them with what it changes, from the figure without it to the figure with it. */
+//-------------------------------------------------------------------------------------------------
+static void putUnitFigures( BuildTooltipCard &card, const ThingTemplate *thing, const Player *player )
+{
+ UpgradeEffects effects;
+ findUpgradeEffects( thing, effects );
+
+ const UpgradeEffect owned = ownedEffect( effects, player, "" );
+ const UnitFigures now = figuresOf( thing, owned );
+ card.health = REAL_TO_INT( now.health );
+ const Int main = now.mainSlot();
+ if( main != WEAPONSLOT_COUNT )
+ {
+ const WeaponFigures &weapon = now.slots[ main ];
+ card.damage = REAL_TO_INT( weapon.damage );
+ card.range = REAL_TO_INT( weapon.range );
+ card.attacksPerSecond = weapon.attacksPerSecond;
+ card.damagePerSecond = REAL_TO_INT( weapon.damage * weapon.attacksPerSecond );
+ }
+
+ for( UpgradeEffects::const_iterator effect = effects.begin(); effect != effects.end(); ++effect )
+ {
+ const UpgradeTemplate *upgrade = TheUpgradeCenter->findUpgrade( effect->first.c_str() );
+ if( upgrade == NULL )
+ continue;
+
+ BuildTooltipUpgrade entry;
+ entry.name = upgradeButtonName( upgrade );
+ entry.owned = player->hasUpgradeComplete( upgrade );
+ UpgradeEffect without = ownedEffect( effects, player, effect->first );
+ UpgradeEffect with = without;
+ addEffect( with, effect->second );
+ putChanges( figuresOf( thing, without ), figuresOf( thing, with ), effect->second, entry.changes );
+ if( !entry.changes.empty() )
+ card.upgrades.push_back( entry );
+ }
+}
+
+enum
+{
+ UPGRADE_TARGETS_SHOWN = 6, ///< the most units an upgrade's card lists
+};
+
+//-------------------------------------------------------------------------------------------------
+/** An upgrade's card: the units of the player's side it changes a figure of, each with the change
+ * from the plain unit. The units are what the side's build buttons make, each name once: walking
+ * every template found the campaign's copies of a Ranger or a Crusader as well, one of them with a
+ * range of 999996. Done only when the card is filled in, on hovering and when the bar changes. */
+//-------------------------------------------------------------------------------------------------
+static void putUpgradeTargets( BuildTooltipCard &card, const UpgradeTemplate *upgrade, const Player *player )
+{
+ const UpgradeEffect plain = {};
+ std::set< WideCharString > named;
+ for( const CommandButton *button = TheControlBar->getCommandButtons(); button; button = button->getNext() )
+ {
+ if( card.upgrades.size() >= UPGRADE_TARGETS_SHOWN )
+ break;
+ const ThingTemplate *thing = button->getThingTemplate();
+ if( thing == NULL || thing->getDefaultOwningSide() != player->getSide() || named.count( thing->getDisplayName().str() ) )
+ continue;
+
+ UpgradeEffects effects;
+ findUpgradeEffects( thing, effects );
+ UpgradeEffects::const_iterator effect = effects.find( upgrade->getUpgradeName().str() );
+ if( effect == effects.end() )
+ continue;
+
+ BuildTooltipUpgrade entry;
+ entry.name = thing->getDisplayName();
+ entry.owned = FALSE;
+ putChanges( figuresOf( thing, plain ), figuresOf( thing, effect->second ), effect->second, entry.changes );
+ if( entry.changes.empty() )
+ continue;
+ named.insert( thing->getDisplayName().str() );
+ card.upgrades.push_back( entry );
+ }
+}
+
void ControlBarPopupDescriptionUpdateFunc( WindowLayout *layout, void *param )
{
if(TheScriptEngine->isGameEnding())
@@ -290,6 +688,7 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
UnsignedInt costToBuild = 0;
UnicodeString cardWarning; // why it cannot be bought right now, empty when it can
UnicodeString cardRequires; // "Requires: ..." naming what is still missing
+ BuildTooltipCard card = BuildTooltipCard();
if(commandButton)
{
@@ -439,8 +838,14 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
cost.format( TheGameText->fetch("TOOLTIP:Cost"), costToBuild );
}
+ // retail tells you the price and nothing about what you get: the card adds the build time,
+ // health and the main weapon's figures, all read off the template, there is no Object yet
+ card.hasStats = TRUE;
+ card.buildSeconds = ControlBar_secondsFromFrames( (Real)thingTemplate->calcTimeToBuild( player ) );
+ putUnitFigures( card, thingTemplate, player );
+
// ask each prerequisite to give us a list of the non satisfied prerequisites
- for( Int i=0; i<thingTemplate->getPrereqCount(); i++ )
+ for( Int i=0; i<thingTemplate->getPrereqCount(); i++ )
{
prereq = thingTemplate->getNthPrereq(i);
requiresList = prereq->getRequiresList(player);
@@ -460,6 +865,8 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
}
else if( upgradeTemplate )
{
+ putUpgradeTargets( card, upgradeTemplate, player );
+
//We are looking at an upgrade purchase icon. Maybe we already purchased it?
Bool hasUpgradeAlready = player->hasUpgradeComplete( upgradeTemplate );
@@ -615,7 +1022,78 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
}
- // the layout's one text: the description, then why it cannot be bought and what it still needs
+ // the layout's one text, in the order Reforged's card had it: the description, the unit's figures
+ // counted with the upgrades the player owns, every upgrade that moves one of them and by how much
+ // (on an upgrade's own button, the units it changes), then why it cannot be bought now and what
+ // it still needs
+ if( card.hasStats )
+ {
+ UnicodeString figures;
+ auto row = [&]( const char *label, const UnicodeString &value )
+ {
+ figures.concat( u"\n" );
+ figures.concat( TheGameText->fetch( label ) );
+ figures.concat( u": " );
+ figures.concat( value );
+ };
+ auto number = []( Int value )
+ {
+ UnicodeString text;
+ text.format( u"%d", value );
+ return text;
+ };
+ if( card.health > 0 )
+ row( "TOOLTIP:StatHealth", number( card.health ) );
+ if( card.damage > 0 )
+ {
+ // a bomb that kills its carrier goes off once, so it has no rate
+ const Bool once = card.attacksPerSecond <= 0.0f;
+ row( "TOOLTIP:StatDamage", number( card.damage ) );
+ row( "TOOLTIP:StatAttackSpeed", once ? UnicodeString( u"-" ) : UnicodeString( MultiByteToWideCharSingleLine( rateFigure( card.attacksPerSecond ).c_str() ).c_str() ) );
+ row( "TOOLTIP:StatDamagePerSecond", once ? UnicodeString( u"-" ) : number( card.damagePerSecond ) );
+ row( "TOOLTIP:StatRange", number( card.range ) );
+ }
+ UnicodeString seconds;
+ seconds.format( TheGameText->fetch( "TOOLTIP:StatSeconds" ), card.buildSeconds );
+ row( "TOOLTIP:StatTime", seconds );
+ if( !descrip.isEmpty() )
+ descrip.concat( u"\n" );
+ descrip.concat( figures );
+ }
+ if( !card.upgrades.empty() )
+ {
+ descrip.concat( u"\n\n" );
+ descrip.concat( TheGameText->fetch( card.hasStats ? "TOOLTIP:Upgrades" : "TOOLTIP:UpgradeChanges" ) );
+ for( size_t each = 0; each < card.upgrades.size(); ++each )
+ {
+ const BuildTooltipUpgrade &upgrade = card.upgrades[ each ];
+ WideCharString upgradeName = upgrade.name.str();
+ const size_t marker = upgradeName.find( u'&' );
+ if( marker != WideCharString::npos )
+ upgradeName.erase( marker, 1 );
+ descrip.concat( u"\n" );
+ descrip.concat( upgradeName.c_str() );
+ if( upgrade.owned )
+ {
+ descrip.concat( u" (" );
+ descrip.concat( TheGameText->fetch( "TOOLTIP:UpgradeOwned" ) );
+ descrip.concat( u")" );
+ }
+ for( size_t change = 0; change < upgrade.changes.size(); ++change )
+ {
+ const BuildTooltipChange &line = upgrade.changes[ change ];
+ descrip.concat( u"\n " );
+ descrip.concat( TheGameText->fetch( line.label ) );
+ descrip.concat( u": " );
+ if( !line.from.empty() )
+ {
+ descrip.concat( MultiByteToWideCharSingleLine( line.from.c_str() ).c_str() );
+ descrip.concat( u" → " );
+ }
+ descrip.concat( MultiByteToWideCharSingleLine( line.to.c_str() ).c_str() );
+ }
+ }
+ }
if( !cardWarning.isEmpty() )
{
descrip.concat( u"\n\n" );