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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameclient): unit figures and upgrade effects in the build tooltip
Olcay Seygan036cfa24a9da
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 84de1af64..d3c778c80 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -505,7 +505,7 @@ found and fixed — EA's own, not port damage.**- The bar's own buttons are drawn to match, steel caps lit gold under the pointer and pressed in when pushed. The menu is a small square with three bars in the screen's top left corner. The idle worker button is a key like the smoke signals', a hard hat on it, in a steel step against the middle panel's bottom left corner, where it no longer hides the end of the power bar, and the build buttons sit down level with it, a few pixels over the bottom of the screen. Each of the fourteen build places is its own dark cell with steel running between them, so an empty place reads as a slot waiting for a button. The power bar is sunk into the same steel plate as the build grid, the plate carried on upward as wide as it, and the money's block sits on top of that plate with no seam between them: the build grid, the power and the money read as one piece. The power bar is as long as the build grid on every side, where it used to change length from one faction to the next, and the money sits over the grid's middle. The build grid's panel no longer carries an empty strip down its left side. There is no chat button any more: Enter opens the chat as it always did. The portrait sits in the radar's lit steel too. The experience bar beside it is ten gold rungs in a sunk groove, climbing from the bottom as you earn your way to the next rank, and your rank stands in a steel tab on the portrait's top right corner, a key sunk in it like the idle worker's with one star for every rank there is, gold up to the one you hold. The portrait's grid is steel between dark cells on every side, where America's was drawn in blue lines that matched nothing else on the bar. That key is the promotions button: point at it and it comes up with a gold rim, it blinks bright in your side's own steel while you have a promotion to spend, and a click opens the promotion screen. That screen is rebuilt in the same steel and half its old size: each rank's promotions stand in a grid of build-button cells five wide, like the command grid, an empty place a dark hole, each rank in a steel well of its own with its heading, the wells a plate's thickness apart, the grid's steel laid over the edge of every picture so the picture sits in its cell like a card in a frame, your rank and the points to spend on one line over the experience bar, and Done in the last row's spare place. A gold rim marks what you have bought and a light one what you can buy now. The bar has no minimise arrow any more: it is only as big as what it holds. The radar sits sunk in a bezel of lit steel, bright along the top and shadowed down the right, and the build grid and the money wear the same steel, the figure in a dark window of its own, and the under-attack light is a long red lamp set in a steel tab on its top left corner, dark until you are hit and then blinking. No words on it, so it reads the same in any language.- The general's powers you have bought and can fire, the column that climbed the right edge of the screen, stand over the portrait now in a tray of the bar's own steel. The first sits in the corner against the right edge of the screen, and each one you gain takes the place to the left of the last, three to a row before a new row starts above, so the tray is only ever as big as what you hold and an empty one takes no room at all. Each power sits on a dark cell three quarters the size of a build button, where the side's old tray art used to frame it. It is always out; there is no button to fold it away.- Three buttons sit in a step of the radar's own steel, on its right: the smoke signals Alt+Z, X and C send, placed in the middle of your view for your allies to see. Each is a key sunk into the steel with a sharp white picture on it instead of a word: a crosshair to attack, a shield to defend, an eye to look. Point at one and it comes up out of its well as lit steel with a gold rim, and it sinks in darker while you hold the button down. They rise into place one after another from the bottom of the screen when the match starts. A game with nobody on your side to see the smoke, a skirmish against the computer or a replay, has no signal buttons at all.-- Tooltips wear the bar's steel. Point at a build button and a card opens right above it rather than in a fixed box at the side: the name on a steel header in your side's colour with the price in gold at its end, every "Power Supplied: 5" or "Strong: infantry" line of the description laid out as a label and a bold figure, the build time, damage and range under a rule, and "not enough money" or what you still need in a sunk red note at the bottom. Point at something on the battlefield and a small dark box beside the pointer names it, its owner's colour in a stripe down the left edge.+- Tooltips wear the bar's steel. Point at a build button and a card opens right above it rather than in a fixed box at the side: the name on a steel header in your side's colour with the price in gold at its end, every "Power Supplied: 5" or "Strong: infantry" line of the description laid out as a label and a bold figure, then the unit's health, damage, attacks a second, damage a second, range and build time in gold, counted with the upgrades you own. Under them every upgrade that touches the unit and what it does to it: a Gattling Tank's card says Chain Guns takes its damage from 15 to 18 and its damage a second from 37 to 46, a Humvee's that TOW adds a 50 damage missile with a range of 317, and an upgrade you already bought turns gold. Point at the upgrade itself and the card lists the units it changes, Composite Armor putting a Crusader from 480 health to 680. At the bottom, "not enough money" or what you still need in a sunk red note at the bottom. Point at something on the battlefield and a small dark box beside the pointer names it, its owner's colour in a stripe down the left edge.- The readout in the top right corner is a box of its own and always there: the time of day, the match time and the real time beside it, the logic rate and the frame rate, the renderer and the frame number. In a network game it adds how many frames are ready out of the input delay, the room's frame rate and the traffic in and out, and under a unit limit your count against it.## Placing buildingsdiff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 89e427d55..0ec32af0e 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -934,6 +934,52 @@ 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: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.strindex cf6c7e4c7..9852162f1 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -15581,6 +15581,50 @@ 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:StatNewWeaponFigures+"%d hasar, %d menzil"+END++TOOLTIP:Upgrades+"GELİŞTİRMELER"+END++TOOLTIP:UpgradeChanges+"ETKİLEDİKLERİ"+END++TOOLTIP:UpgradeOwned+"alındı"+END+GUI:HudToggles"Şeritler"ENDdiff --git a/GeneralsMD/Code/Data/Window/Html/Tooltip.html b/GeneralsMD/Code/Data/Window/Html/Tooltip.htmlindex dcce8b782..7fc3edb10 100644--- a/GeneralsMD/Code/Data/Window/Html/Tooltip.html+++ b/GeneralsMD/Code/Data/Window/Html/Tooltip.html@@ -24,8 +24,16 @@{{name}} the button's name{{cost}} what it costs, {{costkind}} "money" or "science" (promotion points),{{cost.shown}} "hidden" when it costs nothing- {{time}} {{damage}} {{range}} build time with its unit, the best weapon's damage and range;- {{stats.shown}} and {{weapon.shown}}+ {{health}} {{damage}} {{speed}} {{dps}} {{range}} {{time}} the unit's figures with the+ upgrades its player owns: health, then its main weapon (the one with+ the most damage a second) as damage, attacks a second with their unit,+ damage a second and range, and the build time with its unit;+ {{stats.shown}}, {{health.shown}} and {{weapon.shown}}+ data-each="upgrades" a unit's upgrades, or on an upgrade's card the units it changes+ ({{upgradeskind}} "unit" or "upgrade", {{upgrades.shown}}): {{kind}}+ "upgrade" with {{name}} and {{owned}} "owned", then its lines, "change"+ with {{label}} {{from}} {{to}}, or "remark" with {{label}} {{to}} for+ what has no figure (armour){{warning}} why it cannot be bought right now, {{warning.shown}}{{requires}} "Requires: ...", {{requires.shown}}tip only:@@ -44,10 +52,11 @@.hidden { display: none; }/* the box: the panels' dark body under a steel rim, lit along the top and left */- #box { position: absolute; background-color: rgba(8, 12, 16, 0.96); border: 1px solid #1a2026;+ /* opaque: at 0.96 the money figure under a card showed through it */+ #box { position: absolute; background-color: #080c10; border: 1px solid #1a2026;border-top-color: #aab4bf; border-left-color: #8a949f; }- .china #box { background-color: rgba(20, 8, 6, 0.96); border-top-color: #d98a72; border-left-color: #b8604b; }- .gla #box { background-color: rgba(18, 16, 7, 0.96); border-top-color: #cbbf82; border-left-color: #a99d62; }+ .china #box { background-color: #140806; border-top-color: #d98a72; border-left-color: #b8604b; }+ .gla #box { background-color: #121007; border-top-color: #cbbf82; border-left-color: #a99d62; }#box.card { width: 210px; }/* the card's header: the rail's steel, the name on it and the cost at its right hand end */@@ -57,8 +66,12 @@.gla .head { background: linear-gradient(to bottom, #8f8249, #48401e); }.name { font-size: 9px; font-weight: bold; color: #ffffff; }.cost { float: right; margin-left: 6px; font-size: 9px; font-weight: bold; color: #e8d27a; }- .cost .star { display: inline-block; width: 8px; height: 8px; margin-right: 2px; background-image: url(Icons/RankStar.svg); }- .cost.money .star { display: none; }+ /* a promotion's star is its own float left of the figure: inline in the figure's float it fell to+ a second line */+ .star { float: right; width: 8px; height: 8px; margin: 2px 0 0 6px; background-image: url(Icons/RankStar.svg);+ background-size: 100% 100%; background-repeat: no-repeat; }+ .cost.science { margin-left: 2px; }+ .star.money { display: none; }.cost.science .dollar { display: none; }/* the body: rows as label and value, prose in a softer grey, a gap where the text left a blank line */@@ -78,6 +91,27 @@.gla .stats { border-top-color: #37321c; }.stats .value { color: #e8d27a; }+ /* the upgrades under another rule: each name in green, Dota's colour for what an upgrade adds, gold+ once it is owned, and under it every figure it moves, from the plain one to the upgraded one.+ An upgrade's card lists the units it changes in the same shape */+ .upgrades { margin: 0 6px 5px 6px; padding-top: 3px; border-top: 1px solid #2c343c; line-height: 11px; }+ .china .upgrades { border-top-color: #3e1f19; }+ .gla .upgrades { border-top-color: #37321c; }+ .caption { color: #8a949f; font-size: 7px; font-weight: bold; }+ .upgrades.unit .forupgrade, .upgrades.upgrade .forunit { display: none; }+ .entry .name { font-size: 8px; font-weight: bold; color: #8fd46a; }+ .entry.owned .name { color: #e8d27a; }+ .entry .mark { color: #a89f6a; }+ .entry.change, .entry.remark { padding-left: 6px; }+ .entry .from { color: #f1f4f6; }+ .entry .arrow { color: #8a949f; }+ .entry .to { font-weight: bold; color: #8fd46a; }+ .entry.owned .to { color: #e8d27a; }+ .entry.upgrade .label, .entry.upgrade .from, .entry.upgrade .arrow, .entry.upgrade .to { display: none; }+ .entry.change .name, .entry.change .mark, .entry.remark .name, .entry.remark .mark { display: none; }+ .entry.remark .from, .entry.remark .arrow, .entry .mark { display: none; }+ .entry.upgrade.owned .mark { display: inline; }+/* a note sunk into the card: dark on top, lit below, the warning in the under-attack lamp's red */.note { margin: 0 6px 6px 6px; padding: 3px 5px 3px 5px; line-height: 10px; background-color: #1b232b;border: 1px solid #06090b; border-bottom-color: #4b535e; border-right-color: #4b535e; }@@ -97,7 +131,8 @@<div id="box" class="{{kind}}" style="left: {{box.x}}px; top: {{box.y}}px; border-left-color: {{accent}}"><div class="cardonly"><div class="head">- <span class="cost {{costkind}} {{cost.shown}}"><span class="star"></span><span class="dollar">$</span>{{cost}}</span>+ <span class="cost {{costkind}} {{cost.shown}}"><span class="dollar">$</span>{{cost}}</span>+ <span class="star {{costkind}} {{cost.shown}}"></span><span class="name">{{name}}</span></div></div>@@ -107,9 +142,16 @@</div><div class="cardonly"><div class="stats {{stats.shown}}">- <div class="line"><span class="label">{{text:TOOLTIP:StatTime}}: </span><span class="value">{{time}}</span></div>+ <div class="line {{health.shown}}"><span class="label">{{text:TOOLTIP:StatHealth}}: </span><span class="value">{{health}}</span></div><div class="line {{weapon.shown}}"><span class="label">{{text:TOOLTIP:StatDamage}}: </span><span class="value">{{damage}}</span></div>+ <div class="line {{weapon.shown}}"><span class="label">{{text:TOOLTIP:StatAttackSpeed}}: </span><span class="value">{{speed}}</span></div>+ <div class="line {{weapon.shown}}"><span class="label">{{text:TOOLTIP:StatDamagePerSecond}}: </span><span class="value">{{dps}}</span></div><div class="line {{weapon.shown}}"><span class="label">{{text:TOOLTIP:StatRange}}: </span><span class="value">{{range}}</span></div>+ <div class="line"><span class="label">{{text:TOOLTIP:StatTime}}: </span><span class="value">{{time}}</span></div>+ </div>+ <div class="upgrades {{upgradeskind}} {{upgrades.shown}}">+ <div class="caption"><span class="forunit">{{text:TOOLTIP:Upgrades}}</span><span class="forupgrade">{{text:TOOLTIP:UpgradeChanges}}</span></div>+ <div class="entry {{kind}} {{owned}}" data-each="upgrades"><span class="name">{{name}}</span><span class="mark"> ({{text:TOOLTIP:UpgradeOwned}})</span><span class="label">{{label}}: </span><span class="from">{{from}}</span><span class="arrow"> → </span><span class="to">{{to}}</span></div></div><div class="note warning {{warning.shown}}">{{warning}}</div><div class="note requires {{requires.shown}}">{{requires}}</div>diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.hindex f62fae369..7e6c6e041 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h@@ -602,6 +602,9 @@ public:/// calculate how much money it will take the given player to build this unitInt calcCostToBuild( const Player* player) const;+ /// the health it is built with, before any upgrade; 0 for a body that cannot be hurt+ Real calcMaxHealth( void ) const;+/// Used only by Skirmish AI. Everyone else should call calcCostToBuild.Int friend_getBuildCost() const { return m_buildCost; }diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 6e16d934b..82922bb82 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -677,6 +677,23 @@ enum ControlBarStages/** What the build tooltip says, piece by piece, so Window/Html/Tooltip.html can lay each piece out* on its own: ControlBarPopupDescription.wnd gets the same pieces run together into one 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{UnicodeString name;@@ -685,10 +702,14 @@ struct BuildTooltipCardUnicodeString requires; ///< "Requires: ..." naming what is still missingUnsignedInt cost; ///< 0 for nothing to payBool costsScience; ///< the cost is promotion points rather than money- Bool hasStats; ///< DetailedBuildTooltips: the three figures below are there+ Bool hasStats; ///< DetailedBuildTooltips: the figures below are thereInt buildSeconds;- Int damage; ///< the best weapon's, before any bonus; 0 for no weapon+ 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 weaponInt 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 changesIRegion2D anchor; ///< the hovered window, in screen pixels};diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cppindex 27b9eb00a..78db00ff6 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp@@ -64,6 +64,7 @@#include "GameClient/Shadow.h"#include "GameLogic/Armor.h"+#include "GameLogic/Module/ActiveBody.h"#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Module/SpecialPowerModule.h"#include "GameLogic/Object.h"@@ -1542,6 +1543,27 @@ Int ThingTemplate::calcCostToBuild( const Player* player) constreturn getBuildCost() * factionModifier * player->getHandicap()->getHandicap(Handicap::BUILDCOST, this);}+//-------------------------------------------------------------------------------------------------+/** Every body module that can be hurt keeps its health in ActiveBodyModuleData; the one that+ * cannot, InactiveBody, is not on the list and answers zero. */+//-------------------------------------------------------------------------------------------------+Real ThingTemplate::calcMaxHealth( void ) const+{+ static const char *BODIES_WITH_HEALTH[] =+ { "ActiveBody", "StructureBody", "HiveStructureBody", "UndeadBody", "HighlanderBody", "ImmortalBody", NULL };++ const ModuleInfo &modules = getBehaviorModuleInfo();+ for( Int m = 0; m < modules.getCount(); ++m )+ {+ for( const char **body = BODIES_WITH_HEALTH; *body != NULL; ++body )+ {+ if( modules.getNthName( m ).compareNoCase( *body ) == 0 )+ return static_cast<const ActiveBodyModuleData *>( modules.getNthData( m ) )->m_maxHealth;+ }+ }+ return 0.0f;+}+//-------------------------------------------------------------------------------------------------/** NOTE that we're not paying attention to m_override here, instead the portions* that retrieve template data values use the get() wrappers, which *DO* paydiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cppindex 999cb2ae2..5fa51a302 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp@@ -88,11 +88,14 @@#include "GameClient/Controlbar.h"#include "GameClient/DisplayStringManager.h"#include "GameLogic/GameLogic.h"+#include "GameLogic/Damage.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 detailed build tooltip#ifdef _INTERNAL// for occasional debugging...@@ -127,6 +130,291 @@ static void silenceLayout( WindowLayout *layout )silenceWindowTree( window );}+//-------------------------------------------------------------------------------------------------+/** 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 );+ }+}++/** 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;+ }+};++//-------------------------------------------------------------------------------------------------+/** `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 for the conditions+ * set. 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. */+//-------------------------------------------------------------------------------------------------+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 );+ if( set == NULL )+ return figures;++ for( Int slot = PRIMARY_WEAPON; slot < WEAPONSLOT_COUNT; ++slot )+ {+ const WeaponTemplate *weapon = set->getNth( (WeaponSlotType)slot );+ if( weapon == NULL || weapon->getDamageType() == DAMAGE_HEALING || !IsHealthDamagingDamage( weapon->getDamageType() ) )+ continue;++ WeaponBonus bonus;+ TheGlobalData->m_weaponBonusSet->appendBonuses( bonusFlags, bonus );+ if( weapon->getExtraBonus() )+ weapon->getExtraBonus()->appendBonuses( bonusFlags, bonus );++ const Real damage = weapon->getPrimaryDamage( bonus );+ if( damage <= 0.0f )+ continue;+ 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;++ WeaponFigures &figure = figures.slots[ slot ];+ figure.weapon = weapon;+ figure.damage = damage;+ figure.range = weapon->getAttackRange( bonus );+ figure.attacksPerSecond = ( clip > 0 ? clip : 1 ) * LOGICFRAMES_PER_SECOND / cycle;+ }+ 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;++ UnicodeString figures;+ figures.format( TheGameText->fetch( "TOOLTIP:StatNewWeaponFigures" ), REAL_TO_INT( after.damage ), REAL_TO_INT( after.range ) );+ const BuildTooltipChange weapon = { "TOOLTIP:StatNewWeapon", "", 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;+}++//-------------------------------------------------------------------------------------------------+/** 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 = TheGameText->fetch( upgrade->getDisplayNameLabel() );+ 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< std::wstring > 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())@@ -454,28 +742,7 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,{card.hasStats = TRUE;card.buildSeconds = ControlBar_secondsFromFrames( (Real)thingTemplate->calcTimeToBuild( player ) );-- // no bonuses: these are the template's own numbers, before veterancy or upgrades- WeaponBonus noBonus;- Real bestRange = 0.0f;- Real bestDamage = 0.0f;- const WeaponTemplateSet *wts = thingTemplate->findWeaponTemplateSet( WeaponSetFlags() );- if( wts )- {- for( Int ws = PRIMARY_WEAPON; ws < WEAPONSLOT_COUNT; ++ws )- {- const WeaponTemplate *wt = wts->getNth( (WeaponSlotType)ws );- if( wt == NULL )- continue;- if( wt->getUnmodifiedAttackRange() > bestRange )- bestRange = wt->getUnmodifiedAttackRange();- if( wt->getPrimaryDamage( noBonus ) > bestDamage )- bestDamage = wt->getPrimaryDamage( noBonus );- }- }-- card.damage = REAL_TO_INT( bestDamage );- card.range = REAL_TO_INT( bestRange );+ putUnitFigures( card, thingTemplate, player );}// ask each prerequisite to give us a list of the non satisfied prerequisites@@ -499,6 +766,9 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,}else if( upgradeTemplate ){+ if( TheGlobalData->m_detailedBuildTooltips )+ putUpgradeTargets( card, upgradeTemplate, player );+//We are looking at an upgrade purchase icon. Maybe we already purchased it?Bool hasUpgradeAlready = player->hasUpgradeComplete( upgradeTemplate );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 993427c49..cb1301852 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -12612,8 +12612,8 @@ static std::string tooltipName( const UnicodeString &label )//-------------------------------------------------------------------------------------------------/** The build tooltip's values: {{name}}, {{cost}} with {{costkind}} "money" or "science" and* {{cost.shown}}, data-each="lines" out of the description, {{warning}} and {{requires}} each with- * its .shown, and the three figures {{time}} {{damage}} {{range}} with {{stats.shown}} and- * {{weapon.shown}}. */+ * its .shown, the figures {{time}} {{health}} {{damage}} {{speed}} {{dps}} {{range}} with+ * {{stats.shown}}, {{health.shown}} and {{weapon.shown}}, and data-each="upgrades". *///-------------------------------------------------------------------------------------------------static void putBuildTooltipCard( const BuildTooltipCard &card, HtmlValues &values, HtmlLists &lists ){@@ -12631,10 +12631,40 @@ static void putBuildTooltipCard( const BuildTooltipCard &card, HtmlValues &valueUnicodeString seconds;seconds.format( TheGameText->fetch( "TOOLTIP:StatSeconds" ), card.buildSeconds );values[ "time" ] = WideCharStringToMultiByte( seconds.str() );+ values[ "health" ] = std::to_string( card.health );values[ "damage" ] = std::to_string( card.damage );values[ "range" ] = std::to_string( card.range );+ char speed[ 32 ];+ snprintf( speed, sizeof( speed ), "%.2f", card.attacksPerSecond );+ values[ "speed" ] = speed + WideCharStringToMultiByte( TheGameText->fetch( "TOOLTIP:StatPerSecond" ).str() );+ values[ "dps" ] = std::to_string( card.damagePerSecond );values[ "stats.shown" ] = card.hasStats ? "shown" : "hidden";+ values[ "health.shown" ] = card.hasStats && card.health > 0 ? "shown" : "hidden";values[ "weapon.shown" ] = card.hasStats && card.damage > 0 ? "shown" : "hidden";++ // a unit's card lists its upgrades; an upgrade's card lists the units it changes+ values[ "upgrades.shown" ] = card.upgrades.empty() ? "hidden" : "shown";+ values[ "upgradeskind" ] = card.hasStats ? "unit" : "upgrade";+ std::vector< HtmlValues > &upgrades = lists[ "upgrades" ];+ for( size_t each = 0; each < card.upgrades.size(); ++each )+ {+ const BuildTooltipUpgrade &upgrade = card.upgrades[ each ];+ HtmlValues head;+ head[ "kind" ] = "upgrade";+ head[ "name" ] = WideCharStringToMultiByte( upgrade.name.str() );+ head[ "owned" ] = upgrade.owned ? "owned" : "";+ upgrades.push_back( head );+ for( size_t change = 0; change < upgrade.changes.size(); ++change )+ {+ HtmlValues line;+ line[ "kind" ] = upgrade.changes[ change ].from.empty() ? "remark" : "change";+ line[ "owned" ] = head[ "owned" ];+ line[ "label" ] = WideCharStringToMultiByte( TheGameText->fetch( upgrade.changes[ change ].label ).str() );+ line[ "from" ] = upgrade.changes[ change ].from;+ line[ "to" ] = upgrade.changes[ change ].to;+ upgrades.push_back( line );+ }+ }}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 33e815727..baf7a699c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -2240,33 +2240,12 @@ Bool AIPlayer::selectTeamToReinforce( Int minPriority )// ------------------------------------------------------------------------------------------------/** Determine the next team to build. Return true if one was selected. */// -------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------/** The health a unit template is built with. Every body module that can be hurt keeps it in- * ActiveBodyModuleData; the one that cannot, InactiveBody, is not on the list and answers zero. */-//--------------------------------------------------------------------------------------------------static Real computeTemplateMaxHealth( const ThingTemplate *tmpl )-{- static const char *BODIES_WITH_HEALTH[] =- { "ActiveBody", "StructureBody", "HiveStructureBody", "UndeadBody", "HighlanderBody", "ImmortalBody", NULL };-- const ModuleInfo &modules = tmpl->getBehaviorModuleInfo();- for( Int m = 0; m < modules.getCount(); ++m )- {- for( const char **body = BODIES_WITH_HEALTH; *body != NULL; ++body )- {- if( modules.getNthName( m ).compareNoCase( *body ) == 0 )- return static_cast<const ActiveBodyModuleData *>( modules.getNthData( m ) )->m_maxHealth;- }- }- return 0.0f;-}-static Real templateMaxHealth( const ThingTemplate *tmpl ){std::map<const ThingTemplate *, Real>::const_iterator known = theMaxHealthCache.find( tmpl );if( known != theMaxHealthCache.end() )return known->second;- const Real health = computeTemplateMaxHealth( tmpl );+ const Real health = tmpl->calcMaxHealth();theMaxHealthCache[ tmpl ] = health;return health;}