MCPcopy Create free account
hub / github.com/Phobos-developers/Phobos / ChangeAnimType

Method ChangeAnimType

src/Ext/Anim/Body.cpp:158–203  ·  view source on GitHub ↗

Changes type of anim in similar fashion to Next.

Source from the content-addressed store, hash-verified

156
157// Changes type of anim in similar fashion to Next.
158void AnimExt::ChangeAnimType(AnimClass* pAnim, AnimTypeClass* pNewType, bool resetLoops, bool restart)
159{
160 double percentThrough = pAnim->Animation.Value / static_cast<double>(pAnim->Type->End);
161
162 if (pNewType->End == -1)
163 {
164 pNewType->End = pNewType->GetImage()->Frames;
165
166 if (pNewType->Shadow)
167 pNewType->End /= 2;
168 }
169
170 if (pNewType->LoopEnd == -1)
171 {
172 pNewType->LoopEnd = pNewType->End;
173 }
174
175 pAnim->Type = pNewType;
176
177 if (resetLoops)
178 pAnim->RemainingIterations = static_cast<byte>(pNewType->LoopCount);
179
180 pAnim->Accum = 0;
181 pAnim->UnableToContinue = false;
182 pAnim->Reverse = pNewType->Reverse;
183
184 int rate = pNewType->Rate;
185
186 if (pNewType->RandomRate.Min || pNewType->RandomRate.Max)
187 rate = ScenarioClass::Instance->Random.RandomRanged(pNewType->RandomRate.Min, pNewType->RandomRate.Max);
188
189 if (pNewType->Normalized)
190 rate = GameOptionsClass::Instance.GetAnimSpeed(rate);
191
192 pAnim->Animation.Start(rate, pNewType->Reverse ? -1 : 1);
193
194 if (restart)
195 {
196 pAnim->Animation.Value = pNewType->Reverse ? pNewType->End : pNewType->Start;
197 pAnim->Start();
198 }
199 else
200 {
201 pAnim->Animation.Value = static_cast<int>(pNewType->End * percentThrough);
202 }
203}
204
205void AnimExt::HandleDebrisImpact(AnimTypeClass* pExpireAnim, AnimTypeClass* pWakeAnim, Iterator<AnimTypeClass*> splashAnims, HouseClass* pOwner, WarheadTypeClass* pWarhead, int nDamage,
206 CellClass* pCell, CoordStruct nLocation, bool heightFlag, bool isMeteor, bool warheadDetonate, bool explodeOnWater, bool splashAnimsPickRandom)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected