MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / updateHiddenBar

Method updateHiddenBar

game/ui/tileview/battletileview.cpp:33–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31namespace OpenApoc
32{
33void BattleTileView::updateHiddenBar()
34{
35 hiddenBarTicksAccumulated = 0;
36
37 int width = 321;
38 int height = 33;
39 Colour bar = {142, 142, 142, 255};
40 Colour black = {0, 0, 0, 0};
41
42 int totalTU = 0;
43 int remainingTU = 0;
44
45 for (auto &u : battle.units)
46 {
47 if (u.second->owner != battle.currentActiveOrganisation || !u.second->isConscious() ||
48 u.second->getAIType() == AIType::None || !u.second->canMove())
49 {
50 continue;
51 }
52 int reserve = u.second->reserveShotCost +
53 u.second->getBodyStateChangeCost(BodyState::Standing, BodyState::Kneeling);
54
55 totalTU += u.second->initialTU - reserve;
56 remainingTU += std::max(0, u.second->agent->modified_stats.time_units - reserve);
57 }
58 int maxWidth = totalTU ? clamp(width - remainingTU * width / totalTU, 0, width) : 0;
59
60 auto progressBar = mksp<RGBImage>(Vec2<int>{width, height});
61 {
62 RGBImageLock l(progressBar);
63 // Content
64 for (int x = 1; x < maxWidth; x++)
65 {
66 for (int y = 1; y < height - 1; y++)
67 {
68 l.set({x, y}, bar);
69 }
70 }
71 // Borders
72 for (int y = 1; y < height - 1; y++)
73 {
74 l.set({0, y}, bar);
75 l.set({width - 1, y}, bar);
76 }
77 for (int x = 0; x < width; x++)
78 {
79 l.set({x, 0}, bar);
80 l.set({x, height - 1}, bar);
81 }
82 // Remainder
83 for (int x = maxWidth + 1; x < width - 1; x++)
84 {
85 for (int y = 1; y < height - 1; y++)
86 {
87 l.set({x, y}, black);
88 }
89 }
90 }

Callers

nothing calls this directly

Calls 7

clampFunction · 0.85
isConsciousMethod · 0.80
getAITypeMethod · 0.80
canMoveMethod · 0.80
setMethod · 0.45
setImageMethod · 0.45

Tested by

no test coverage detected