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

Method getFrame

game/state/rules/battle/damage.cpp:89–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89sp<Image> HazardType::getFrame(unsigned age, int offset)
90{
91 if (fire)
92 {
93 // Explanation how fire frames work is at the end of battlehazard.h
94 // Round stage to nearest 0,5
95 int stage = (age + 2) / 5 * 5;
96 // Get min and max frames for this stage
97 int minFrame = clamp((stage - 5) / 10, 0, 11);
98 int maxFrame = clamp((stage + 5 + 5) / 10, 0, 11);
99 // Trunc offset if it's too big
100 if (minFrame + offset > maxFrame)
101 {
102 offset = 0;
103 }
104 int frame = minFrame + offset;
105 // Scale to the actual frames of the doodad (crude support for more/less frames)
106 return doodadType->frames[frame * doodadType->frames.size() / 12].image;
107 }
108 else
109 {
110 if (age >= 2 * maxLifetime)
111 {
112 LogError("Age must be lower than max lifetime");
113 return nullptr;
114 }
115 int frame = age * doodadType->frames.size() / (2 * maxLifetime);
116 while (frame + offset >= (int)doodadType->frames.size())
117 offset -= (doodadType->frames.size() - frame);
118 return doodadType->frames[frame + offset].image;
119 }
120}
121
122int HazardType::getLifetime(GameState &state)
123{

Callers 1

drawMethod · 0.80

Calls 2

clampFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected