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): weapon and armour figures beside the unit portrait

Olcay Seyganbdd3ceea3c30
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6eb024c9b..99504eb02 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,7 +23,7 @@ found and fixed — EA's own, not port damage.**
- The command bar is one console standing in the middle of the bottom edge: a taller radar, your selection and the build grid side by side, with the power bar over the grid. The idle worker and rank keys sit in a row over your selection, and in multiplayer the smoke signals join them. The red under-attack lamp is gone: the ping on the radar, the voice and the line in the event feed already tell you where you are hit, and the lamp only blinked about it a second time.
- Your general's powers grow out of the console's right end, a column for each F key with its powers stacked up it, and only the powers you have take any room.
-- A single unit's name and health stand beside its portrait, and a veteran gets his gold stars there too. A group shows every type it holds in the same box, five to a row. Watching a match with nothing selected, the empty portrait box is gone and the console is the radar alone; click a unit and the box comes back.
+- A single unit's name and health stand beside its portrait, and a veteran gets his gold stars there too. Under them sit its main weapon's damage, damage a second and range, and what its armour does to gunfire, tank shells, rockets and blasts: green for less damage taken, red for more. Your own units and your allies' show as they stand, so a veteran's bonus, a Composite Armor upgrade or Hold the Line shows the moment it lands. An enemy's show only what his veterancy stars already tell you, never his upgrades or battle plans. A group shows every type it holds in the same box, five to a row. Watching a match with nothing selected, the empty portrait box is gone and the console is the radar alone; click a unit and the box comes back. Following nobody, the experience bar beside the radar is gone too, since there is no general's rank to fill it.
- The match clock hangs from the middle of the top edge with your money in its own box under it. Superweapon countdowns in the top right corner are as big as your general's power buttons. Hold Tab and the scoreboard drops down from it.
- Peace time has its own plate under your money, so the truce clock never pushes the match clock aside. When the last ten seconds start, the countdown hangs straight off that plate.
- A superweapon built, charged or fired anywhere on the map flashes its name in big letters under the clock: "Nuclear Missile launched". Yours are white, an ally's blue, an enemy's red. Each line stays four seconds and fades out. When several land at once they queue and hurry through, two seconds each with one more waiting and one second with a pile behind it, so the last news never sits stale.
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 96a0a9a25..12e84bab7 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1234,6 +1234,29 @@ TOOLTIP:StatNewWeaponFigures
"%d damage, %d range"
END
+// Beside a lone unit's portrait, short enough for a column of a quarter of it: damage a second,
+// and the armour's change to four kinds of damage.
+
+TOOLTIP:StatShortDamagePerSecond
+"DPS"
+END
+
+TOOLTIP:StatVsGuns
+"Gun"
+END
+
+TOOLTIP:StatVsShells
+"Shell"
+END
+
+TOOLTIP:StatVsRockets
+"Rocket"
+END
+
+TOOLTIP:StatVsBlast
+"Blast"
+END
+
// Under the figures: a unit's upgrades, or on an upgrade's card the units it changes.
TOOLTIP:Upgrades
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index f1744990f..36ef35f4a 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15809,6 +15809,26 @@ TOOLTIP:StatNewWeaponFigures
"%d hasar, %d menzil"
END
+TOOLTIP:StatShortDamagePerSecond
+"Hasar/sn"
+END
+
+TOOLTIP:StatVsGuns
+"Mermi"
+END
+
+TOOLTIP:StatVsShells
+"Top"
+END
+
+TOOLTIP:StatVsRockets
+"Roket"
+END
+
+TOOLTIP:StatVsBlast
+"Bomba"
+END
+
TOOLTIP:Upgrades
"GELİŞTİRMELER"
END
diff --git a/GeneralsMD/Code/Data/Window/Html/ControlBar.html b/GeneralsMD/Code/Data/Window/Html/ControlBar.html
index 0c06b2cc8..14a86e9eb 100644
--- a/GeneralsMD/Code/Data/Window/Html/ControlBar.html
+++ b/GeneralsMD/Code/Data/Window/Html/ControlBar.html
@@ -56,9 +56,14 @@
data-each="portraitcells" the selection's cells, the portrait's first and then only what it
holds, each {{cell.x}} .y .w .h
{{selinfo.x}} ... beside a lone unit's portrait: {{sel.name}}, data-each="selstars" a star
- at {{x}} for each veterancy level, and the health bar's dark groove,
- {{sel.healthshown}} "hidden" for an enemy in disguise. The health's
- figure and its lit length are Window/Html/Readout.html's
+ at {{x}} from the right for each veterancy level, the health bar's dark
+ groove, {{sel.healthshown}} "hidden" for an enemy in disguise, and
+ data-each="selweapon" the main weapon's damage, damage a second and
+ range and data-each="selarmor" the armour's change to four kinds of
+ damage, each at {{x}} with {{label}} over {{value}} and {{state}}
+ "strong", "weak" or nothing; both empty for a disguise, the weapon's
+ for an unarmed unit. The health's figure and its lit length are
+ Window/Html/Readout.html's
data-each="skillcells" a cell behind each of the general's powers, each {{cell.x}} .y .w .h
data-each="powersteel" the powers' steel, a column of it under each column of their cells from
the left, {{plate.x}} .y .w .h, against the console's right hand end and
@@ -185,14 +190,24 @@
.china .hollow { border-bottom-color: #d98a72; border-right-color: #d98a72; background-color: #290f09; }
.gla .hollow { border-bottom-color: #cbbf82; border-right-color: #cbbf82; background-color: #282311; }
- /* a lone unit's name, its veterancy as gold stars, and its health's groove, which Readout.html
- lights and writes the figure under; the text column beside the portrait is narrow, so the name
- takes two lines */
- .selinfo .name { position: absolute; left: 0; top: 0; height: 22px; line-height: 11px; font-size: 9px; font-weight: bold;
+ /* a lone unit's name, its health's groove, which Readout.html lights and writes the figure under,
+ its veterancy as gold stars at the right hand end of that figure's line, and then two rows of
+ figures, a small grey label over each: its main weapon's, and what its armour does to the damage
+ most of the fighting deals, green where it takes less and red where it takes more. The column
+ beside the portrait is 108 by 70 page pixels, so the name takes two lines and every row is cut to
+ the pixel to fit */
+ .selinfo .name { position: absolute; left: 0; top: 0; height: 20px; line-height: 10px; font-size: 9px; font-weight: bold;
color: #f1f4f6; }
- .selinfo .vet { position: absolute; top: 25px; width: 10px; height: 10px; background-size: 100% 100%;
+ .selinfo .vet { position: absolute; top: 27px; width: 9px; height: 9px; background-size: 100% 100%;
background-repeat: no-repeat; background-image: url(Icons/RankStar.svg); }
- .selinfo .health { position: absolute; left: 0; top: 40px; height: 8px; background-color: #0d1512; border-bottom: 1px solid #3f4650; }
+ .selinfo .health { position: absolute; left: 0; top: 21px; height: 4px; background-color: #0d1512; border-bottom: 1px solid #3f4650; }
+ .selinfo .figure { position: absolute; height: 16px; white-space: nowrap; }
+ .selinfo .weapon { top: 37px; }
+ .selinfo .armor { top: 54px; }
+ .selinfo .figure .label { position: absolute; left: 0; top: 0; height: 7px; line-height: 7px; font-size: 7px; color: #8a949f; }
+ .selinfo .figure .value { position: absolute; left: 0; top: 7px; height: 9px; line-height: 9px; font-size: 8px; font-weight: bold; color: #f1f4f6; }
+ .selinfo .figure.strong .value { color: #7fd36a; }
+ .selinfo .figure.weak .value { color: #ef6a4c; }
/* the general's powers' steel, a column at a time: the console's steel with its light top line,
and a dark line down the part of its right hand side that faces the battlefield */
@@ -422,11 +437,13 @@
</div>
<!-- the money, under the clock; the figure is the bar's own window over its well -->
<div class="piece moneywell {{moneyblock.shown}}" style="left: {{moneyblock.x}}px; top: {{moneyblock.y}}px; width: {{moneyblock.w}}px; height: {{moneyblock.h}}px"><div class="lip"></div></div>
- <!-- a lone unit's name, veterancy and health beside its portrait in the selection's well -->
+ <!-- a lone unit's name, health, veterancy, weapon and armour beside its portrait in the selection's well -->
<div class="piece selinfo {{selinfo.shown}}" style="left: {{selinfo.x}}px; top: {{selinfo.y}}px; width: {{selinfo.w}}px; height: {{selinfo.h}}px">
<div class="name" style="width: {{selinfo.w}}px">{{sel.name}}</div>
- <div class="vet" data-each="selstars" style="left: {{x}}px"></div>
+ <div class="vet" data-each="selstars" style="right: {{x}}px"></div>
<div class="health {{sel.healthshown}}" style="width: {{selinfo.w}}px"></div>
+ <div class="figure weapon {{state}}" data-each="selweapon" style="left: {{x}}px"><div class="label">{{label}}</div><div class="value">{{value}}</div></div>
+ <div class="figure armor {{state}}" data-each="selarmor" style="left: {{x}}px"><div class="label">{{label}}</div><div class="value">{{value}}</div></div>
</div>
<div class="piece commandcell" data-each="commandcells" style="left: {{cell.x}}px; top: {{cell.y}}px; width: {{cell.w}}px; height: {{cell.h}}px"><div class="edge" style="left: -{{ring}}px; top: -{{ring}}px; right: -{{ring}}px; bottom: -{{ring}}px; border-width: {{ring}}px"></div><div class="bevel"></div></div>
<div class="piece commandcell" data-each="portraitcells" style="left: {{cell.x}}px; top: {{cell.y}}px; width: {{cell.w}}px; height: {{cell.h}}px"><div class="edge" style="left: -{{ring}}px; top: -{{ring}}px; right: -{{ring}}px; bottom: -{{ring}}px; border-width: {{ring}}px"></div><div class="bevel"></div></div>
diff --git a/GeneralsMD/Code/Data/Window/Html/Readout.html b/GeneralsMD/Code/Data/Window/Html/Readout.html
index d19a0da5d..59b7d7816 100644
--- a/GeneralsMD/Code/Data/Window/Html/Readout.html
+++ b/GeneralsMD/Code/Data/Window/Html/Readout.html
@@ -39,11 +39,12 @@
well */
.peace { text-align: center; font-size: 11px; font-weight: bold; color: #ff3030; white-space: nowrap; }
- /* the health over ControlBar.html's groove, which stands at the same place */
- .fill { position: absolute; left: 0; top: 40px; height: 8px; background-color: #3fbf3f; }
+ /* the health over ControlBar.html's groove, which stands at the same place, and its figure on the
+ line under it, whose right hand end holds that page's veterancy stars */
+ .fill { position: absolute; left: 0; top: 21px; height: 4px; background-color: #3fbf3f; }
.fill.yellow { background-color: #e8c83a; }
.fill.red { background-color: #d8402a; }
- .figure { position: absolute; left: 0; top: 52px; height: 10px; line-height: 10px; color: #c9d2d9; }
+ .figure { position: absolute; left: 0; top: 27px; height: 9px; line-height: 9px; color: #c9d2d9; }
</style>
</head>
<body>
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index 7fee2fa62..8e746da68 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -40,6 +40,9 @@
#include "Common/Overridable.h"
#include "Common/Science.h"
#include "GameClient/Color.h"
+#include "Common/BitFlags.h"
+#include "GameLogic/WeaponBonusConditionFlags.h"
+#include "GameLogic/WeaponSetFlags.h"
// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
class Drawable;
@@ -48,6 +51,7 @@ class Image;
class Object;
class ThingTemplate;
class WeaponTemplate;
+class WeaponBonus;
class SpecialPowerTemplate;
class WindowVideoManager;
class WindowVideoManager;
@@ -800,6 +804,42 @@ struct BuildTooltipCard
IRegion2D anchor; ///< the hovered window in screen pixels, its top the grid's top for a command button
};
+/** 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;
+ }
+};
+
+/** `weapon`'s figures under `bonus`, the build tooltip's and the selected unit's alike
+ * (ControlBarPopupDescription.cpp). */
+WeaponFigures ControlBarWeaponFigures( const WeaponTemplate *weapon, const WeaponBonus &bonus );
+
+/** `thing`'s weapons in the set `setFlags` picks, each under the bonuses `bonusFlags` give it, into
+ * `figures`' slots; a template with no such set leaves them as they are. */
+void ControlBarTemplateWeaponFigures( const ThingTemplate *thing, const WeaponSetFlags &setFlags,
+ WeaponBonusConditionFlags bonusFlags, UnitFigures &figures );
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
class ControlBar : public SubsystemInterface
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
index 6bd844b6e..ac7850871 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
@@ -768,6 +768,9 @@ public:
void setClipPercentFull(Real percent, Bool allowReduction);
UnsignedInt getSuspendFXFrame( void ) const { return m_suspendFXFrame; }
+ /// the bonuses `source` fires this weapon with now; a read, which the selected unit's figures on the bar use
+ void computeBonus(const Object *source, WeaponBonusConditionFlags extraBonusFlags, WeaponBonus& bonus) const;
+
protected:
Weapon(const WeaponTemplate* tmpl, WeaponSlotType wslot);
@@ -790,8 +793,6 @@ protected:
void getFiringLineOfSightOrigin(const Object* source, Coord3D& origin) const;
- void computeBonus(const Object *source, WeaponBonusConditionFlags extraBonusFlags, WeaponBonus& bonus) const;
-
void rebuildScatterTargets();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
index 7f80696fa..c67563534 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
@@ -185,77 +185,69 @@ static void findUpgradeEffects( const ThingTemplate *thing, UpgradeEffects &effe
}
}
-/** 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
+//-------------------------------------------------------------------------------------------------
+/** 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. */
+//-------------------------------------------------------------------------------------------------
+WeaponFigures ControlBarWeaponFigures( const WeaponTemplate *weapon, const WeaponBonus &bonus )
{
- 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;
- }
-};
+ WeaponFigures figure = {};
+ if( weapon->getDamageType() == DAMAGE_HEALING || !IsHealthDamagingDamage( weapon->getDamageType() ) )
+ 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 = ( 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 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. */
+/** 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. */
//-------------------------------------------------------------------------------------------------
-static UnitFigures figuresOf( const ThingTemplate *thing, const UpgradeEffect &effect )
+void ControlBarTemplateWeaponFigures( const ThingTemplate *thing, const WeaponSetFlags &setFlags,
+ WeaponBonusConditionFlags bonusFlags, UnitFigures &figures )
{
- 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;
+ return;
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() ) )
+ if( weapon == NULL )
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;
+ figures.slots[ slot ] = ControlBarWeaponFigures( weapon, bonus );
}
+}
+
+//-------------------------------------------------------------------------------------------------
+/** `thing`'s figures with `effect` applied. */
+//-------------------------------------------------------------------------------------------------
+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;
+ ControlBarTemplateWeaponFigures( thing, setFlags, bonusFlags, figures );
return figures;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index a6d86637c..1ded395fa 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -116,6 +116,7 @@
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/JetAIUpdate.h"
#include "GameLogic/Weapon.h"
+#include "GameLogic/Armor.h"
#include "GameLogic/Object.h"
#include "GameLogic/RankInfo.h"
#include "GameLogic/GameLogic.h"
@@ -11499,9 +11500,10 @@ static void putPowerBar( HtmlValues &values, std::vector< HtmlValues > &cells )
* right panel: `cells` from the bottom up, each {{lit}} "lit" up to the way from this rank to the
* next, at {{y}} and {{h}} pixels inside the lip, and `stars` one per rank, {{lit}} up to the rank
* reached. The groove's border goes on top of its size in the page, so expframe.w and .h are cut
- * to its inside here. Watching, it is the watched player's. */
+ * to its inside here. `player` is the general it is of, the watched one while watching and NULL
+ * when nobody is, which leaves the groove empty; the caller stands the groove down then. */
//-------------------------------------------------------------------------------------------------
-static void putExperienceBar( HtmlValues &values, std::vector< HtmlValues > &cells, std::vector< HtmlValues > &stars )
+static void putExperienceBar( HtmlValues &values, const Player *player, std::vector< HtmlValues > &cells, std::vector< HtmlValues > &stars )
{
enum { FRAME_BORDER = 2, FRAME_LIP = 1, EXPERIENCE_CELLS = 10, FULL = 100 };
@@ -11511,8 +11513,6 @@ static void putExperienceBar( HtmlValues &values, std::vector< HtmlValues > &cel
values[ "expframe.h" ] = std::to_string( max( 0, height ) );
values[ "expframe.innerw" ] = std::to_string( max( 0, width - 2 * FRAME_LIP ) );
- const Player *player = TheControlBar->isObserverControlBarOn() ? TheControlBar->getObserverLookAtPlayer()
- : ThePlayerList->getLocalPlayer();
if( player == NULL )
{
cells.clear();
@@ -11907,14 +11907,39 @@ static void putWell( std::vector< HtmlValues > &wells, size_t &filled, const IRe
putPageRect( entry, "header", wellHeader( well, scale ), headed, scale );
}
-/** A lone unit's name, rank and health for the page, beside its portrait `portrait` in the
- * selection's well `well`: {{selinfo.x}} .y .w .h, {{sel.name}}, data-each="selstars" a star for
- * each veterancy level it has, {{sel.health}} "820/1000", {{sel.healthw}} the bar's lit width in
- * page pixels out of selinfo.w, and {{sel.healthstate}} "green", "yellow" or "red". */
-static void putSelectedUnit( HtmlValues &values, std::vector< HtmlValues > &stars, const IRegion2D &portrait,
- const IRegion2D &well, Bool shown )
+/** The damage a lone unit's armour is shown against, what most of the fighting deals, each under its
+ * label in the string table. */
+static const struct { DamageType type; const char *label; } SHOWN_ARMOR[] =
{
- enum { INFO_GAP = 6, HEALTH_YELLOW_PERCENT = 50, HEALTH_RED_PERCENT = 25, STAR_PITCH = 11 };
+ { DAMAGE_SMALL_ARMS, "TOOLTIP:StatVsGuns" },
+ { DAMAGE_ARMOR_PIERCING, "TOOLTIP:StatVsShells" },
+ { DAMAGE_INFANTRY_MISSILE, "TOOLTIP:StatVsRockets" },
+ { DAMAGE_EXPLOSION, "TOOLTIP:StatVsBlast" },
+};
+
+/** One column of the figures under a lone unit's health, {{x}} its left in page pixels, {{label}}
+ * over {{value}}, and {{state}} "strong", "weak" or nothing. */
+static void putFigureColumn( std::vector< HtmlValues > &columns, Int column, Int count, Int width, const char *label,
+ const std::string &value, const char *state )
+{
+ HtmlValues &entry = listEntry( columns, column );
+ entry[ "x" ] = std::to_string( column * width / count );
+ entry[ "label" ] = WideCharStringToMultiByte( TheGameText->fetch( label ).str() );
+ entry[ "value" ] = value;
+ entry[ "state" ] = state;
+}
+
+/** A lone unit's name, rank, health, main weapon and armour for the page, beside its portrait
+ * `portrait` in the selection's well `well`: {{selinfo.x}} .y .w .h, {{sel.name}},
+ * data-each="selstars" a star for each veterancy level it has, {{sel.health}} "820/1000",
+ * {{sel.healthw}} the bar's lit width in page pixels out of selinfo.w, {{sel.healthstate}} "green",
+ * "yellow" or "red", data-each="selweapon" the main weapon's damage, damage a second and range and
+ * data-each="selarmor" what its armour does to each of SHOWN_ARMOR, "-75%". Both are the object's
+ * as it stands - the weapon set it carries, its veterancy, upgrades and container, the armour set
+ * its upgrades put on - read through the same const calls the logic makes. */
+static void putSelectedUnit( HtmlValues &values, HtmlLists &lists, const IRegion2D &portrait, const IRegion2D &well, Bool shown )
+{
+ enum { INFO_GAP = 6, HEALTH_YELLOW_PERCENT = 50, HEALTH_RED_PERCENT = 25, STAR_PITCH = 11, WEAPON_FIGURES = 3 };
const Real scale = ControlBarHudScale();
IRegion2D info = portrait;
info.lo.x = portrait.hi.x + REAL_TO_INT( INFO_GAP * scale );
@@ -11924,16 +11949,25 @@ static void putSelectedUnit( HtmlValues &values, std::vector< HtmlValues > &star
const Object *object = drawable ? drawable->getObject() : NULL;
shown = shown && object != NULL;
putPageRect( values, "selinfo", info, shown, scale );
+ std::vector< HtmlValues > &stars = lists[ "selstars" ];
+ std::vector< HtmlValues > &weaponColumns = lists[ "selweapon" ];
+ std::vector< HtmlValues > &armorColumns = lists[ "selarmor" ];
stars.clear();
if( !shown )
+ {
+ weaponColumns.clear();
+ armorColumns.clear();
return;
+ }
// an enemy in disguise is what he looks like, as his portrait is (ControlBar::setPortraitByObject):
- // the disguise's name, and no rank or health, which are his own
+ // the disguise's name, and no rank, health, weapon or armour, which are his own
if( drawable->getStealthLook() == STEALTHLOOK_DISGUISED_ENEMY )
{
values[ "sel.name" ] = WideCharStringToMultiByte( drawable->getTemplate()->getDisplayName().str() );
values[ "sel.healthshown" ] = "hidden";
+ weaponColumns.clear();
+ armorColumns.clear();
return;
}
@@ -11953,6 +11987,63 @@ static void putSelectedUnit( HtmlValues &values, std::vector< HtmlValues > &star
values[ "sel.health" ] = std::to_string( health ) + "/" + std::to_string( maxHealth );
values[ "sel.healthw" ] = std::to_string( atoi( values[ "selinfo.w" ].c_str() ) * health / maxHealth );
values[ "sel.healthstate" ] = percent <= HEALTH_RED_PERCENT ? "red" : percent <= HEALTH_YELLOW_PERCENT ? "yellow" : "green";
+
+ // a unit of the local player's or an ally's shows its figures as they stand; anybody else's only
+ // with the veterancy his stars show already, since his upgrades, battle plans and horde are what
+ // he has researched and planned. A watcher is in nobody's match and sees everything
+ const Player *local = ThePlayerList->getLocalPlayer();
+ const Bool ours = localPlayerWatching() || object->getControllingPlayer() == local
+ || local->getRelationship( object->getTeam() ) == ALLIES;
+ const Int width = atoi( values[ "selinfo.w" ].c_str() );
+ UnitFigures figures = {};
+ if( ours )
+ {
+ for( Int slot = PRIMARY_WEAPON; slot < WEAPONSLOT_COUNT; slot++ )
+ {
+ const Weapon *weapon = object->getWeaponInWeaponSlot( (WeaponSlotType)slot );
+ if( weapon == NULL )
+ continue;
+ WeaponBonus bonus;
+ weapon->computeBonus( object, 0, bonus );
+ figures.slots[ slot ] = ControlBarWeaponFigures( weapon->getTemplate(), bonus );
+ }
+ }
+ else
+ {
+ enum { VETERANCY_BONUSES = ( 1 << WEAPONBONUSCONDITION_VETERAN ) | ( 1 << WEAPONBONUSCONDITION_ELITE ) | ( 1 << WEAPONBONUSCONDITION_HERO ) };
+ WeaponSetFlags setFlags = object->getWeaponSetFlags();
+ setFlags.set( WEAPONSET_PLAYER_UPGRADE, 0 );
+ ControlBarTemplateWeaponFigures( object->getTemplate(), setFlags, object->getWeaponBonusCondition() & VETERANCY_BONUSES, figures );
+ }
+ const Int main = figures.mainSlot();
+ if( main == WEAPONSLOT_COUNT )
+ weaponColumns.clear();
+ else
+ {
+ const WeaponFigures &weapon = figures.slots[ main ];
+ putFigureColumn( weaponColumns, 0, WEAPON_FIGURES, width, "TOOLTIP:StatDamage", std::to_string( REAL_TO_INT( weapon.damage ) ), "" );
+ putFigureColumn( weaponColumns, 1, WEAPON_FIGURES, width, "TOOLTIP:StatShortDamagePerSecond",
+ std::to_string( REAL_TO_INT( weapon.damage * weapon.attacksPerSecond ) ), "" );
+ putFigureColumn( weaponColumns, 2, WEAPON_FIGURES, width, "TOOLTIP:StatRange", std::to_string( REAL_TO_INT( weapon.range ) ), "" );
+ weaponColumns.resize( WEAPON_FIGURES );
+ }
+
+ // the armour, and for our own the body's damage scalar on top of it, which is where a battle plan
+ // such as Hold the Line goes (ActiveBody::attemptDamage)
+ ArmorSetFlags armorFlags;
+ for( Int set = 0; set < ARMORSET_COUNT; set++ )
+ if( object->testArmorSetFlag( (ArmorSetType)set ) && ( ours || set != ARMORSET_PLAYER_UPGRADE ) )
+ armorFlags.set( set );
+ const Armor armor( object->getTemplate()->findArmorTemplateSet( armorFlags )->getArmorTemplate() );
+ const Real scalar = ours ? object->getBodyModule()->getDamageScalar() : 1.0f;
+ const Int shownArmor = (Int)ARRAY_SIZE( SHOWN_ARMOR );
+ for( Int each = 0; each < shownArmor; each++ )
+ {
+ const Int change = REAL_TO_INT_FLOOR( armor.adjustDamage( SHOWN_ARMOR[ each ].type, PERCENT ) * scalar + 0.5f ) - PERCENT;
+ putFigureColumn( armorColumns, each, shownArmor, width, SHOWN_ARMOR[ each ].label,
+ ( change > 0 ? "+" : "" ) + std::to_string( change ) + "%", change < 0 ? "strong" : change > 0 ? "weak" : "" );
+ }
+ armorColumns.resize( shownArmor );
}
static GameWindow *numberedWindow( const char *prefix, Int number )
@@ -12333,7 +12424,10 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, I
const Int wellHeight = REAL_TO_INT( COMMAND_ROWS * ( COMMAND_CELL_HEIGHT + CELL_GAP ) * scale );
const Int consoleTopLine = foot - wellHeight - REAL_TO_INT( ( HEADER_GAP + HEADER_HEIGHT ) * scale );
const Int radarWidth = ( foot - consoleTopLine ) * RADAR_WIDTH / RADAR_HEIGHT;
- const Int radarWellWidth = radarWidth + REAL_TO_INT( ( EXPERIENCE_GAP + EXPERIENCE_WIDTH ) * scale );
+ // a watcher who has picked nobody to follow has no general's experience to show, and the groove
+ // and the room for it go
+ const Player *experiencePlayer = watching ? TheControlBar->getObserverLookAtPlayer() : ThePlayerList->getLocalPlayer();
+ const Int radarWellWidth = radarWidth + ( experiencePlayer ? REAL_TO_INT( ( EXPERIENCE_GAP + EXPERIENCE_WIDTH ) * scale ) : 0 );
const Int selectionWellWidth = REAL_TO_INT( PORTRAIT_PLACES * ( CELL_WIDTH + CELL_GAP ) * scale );
const Int gridWellWidth = REAL_TO_INT( COMMAND_COLUMNS * ( COMMAND_CELL_WIDTH + CELL_GAP ) * scale );
const ICoord2D cell = cellSize();
@@ -12379,8 +12473,8 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, I
TheControlBar->placeWindowAt( radarWindow, radar );
IRegion2D experience = radarWell;
experience.lo.x = experience.hi.x - REAL_TO_INT( EXPERIENCE_WIDTH * scale );
- putPageRect( values, "expframe", experience, leftFound, scale );
- putExperienceBar( values, lists[ "expcells" ], lists[ "rankstars" ] );
+ putPageRect( values, "expframe", experience, leftFound && experiencePlayer != NULL, scale );
+ putExperienceBar( values, experiencePlayer, lists[ "expcells" ], lists[ "rankstars" ] );
// in the selection's header, on its grid of HEADER_SLOTS from its left: the idle worker's key, the
// skills key - the rank's stars, and the button that opens the promotion screen - and in a
@@ -12623,7 +12717,7 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, I
if( multi )
portraitCell.hi.x = portraitCell.lo.x;
TheControlBar->placeWindowAt( portraitWindow, portraitCell );
- putSelectedUnit( values, lists[ "selstars" ], portraitCell, selectionWell, portraitShown && !multi );
+ putSelectedUnit( values, lists, portraitCell, selectionWell, portraitShown && !multi );
std::vector< HtmlValues > &portraitCells = lists[ "portraitcells" ];
size_t portraitFilled = 0;