From e2e15b70ac75802f434d1fc07026b294e87a23ef Mon Sep 17 00:00:00 2001 From: Junior Date: Sun, 6 Sep 2026 01:18:00 +0200 Subject: [PATCH] Fix swapped hilight arrows for warrior/explorer top-bar counters The tutorial hilight subsystem draws an arrow over a unit-type's free/total counter in the top screen bar when the corresponding "working free stat" hilight is active. The three-branch chain in drawTopScreenBar paired the warrior counter (i == WARRIOR) with the explorers hilight and the explorer counter (i == EXPLORER) with the warriors hilight -- a copy-paste swap. As a result a script requesting the explorers stat drew its arrow over the warrior counter and vice versa. Replace the three near-duplicate branches with a single table indexed by i so the hilight id is driven by the same index as everything else and the pairing cannot be swapped again. The table order follows the UnitConsts ordering (WORKER, EXPLORER, WARRIOR), which differs from the Hilight enum's numeric order, so it is spelled out explicitly. Pure UI draw path; no simulation, checksum, or replay impact. Ported from PR #129 (feat/ai-trainer-support), original commit d8e69de86b067b78c605411a48877ddc8979de4b by kylelutze. --- src/GameGUI.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/GameGUI.cpp b/src/GameGUI.cpp index 4a6421f72..a5763c0e1 100644 --- a/src/GameGUI.cpp +++ b/src/GameGUI.cpp @@ -4030,17 +4030,19 @@ void GameGUI::drawTopScreenBar(void) globalContainer->gfx->drawString(dec+22, 0, globalContainer->littleFont, FormatableString("%0 / %1").arg(free).arg(tot).c_str()); globalContainer->littleFont->popStyle(); - if(i==WORKER && hilights.find(HilightWorkersWorkingFreeStat) != hilights.end()) - { - arrowPositions.push_back(HilightArrowPosition(dec+22, 32, 39)); - } - - else if(i==WARRIOR && hilights.find(HilightExplorersWorkingFreeStat) != hilights.end()) - { - arrowPositions.push_back(HilightArrowPosition(dec+22, 32, 39)); - } - - else if(i==EXPLORER && hilights.find(HilightWarriorsWorkingFreeStat) != hilights.end()) + // Tutorial hilight arrow for this counter. The sprite, the free/total + // counter, and the arrow position above all key off the unit-type index + // i (WORKER=0, EXPLORER=1, WARRIOR=2 from UnitConsts.h); the matching + // hilight id must too. This table keeps that pairing in one place so it + // cannot be silently swapped. Indices follow the UnitConsts ordering, + // NOT the Hilight* enum's numeric order (which lists explorer/warrior + // the other way around), so the mapping is spelled out explicitly. + static const int hilightForUnitType[3] = { + HilightWorkersWorkingFreeStat, // i == WORKER + HilightExplorersWorkingFreeStat, // i == EXPLORER + HilightWarriorsWorkingFreeStat, // i == WARRIOR + }; + if(hilights.find(hilightForUnitType[i]) != hilights.end()) { arrowPositions.push_back(HilightArrowPosition(dec+22, 32, 39)); }