Revision | 2a791df45c2cf015e28b5e5866a027cf07cd79e7 (tree) |
---|---|
Time | 2012-05-27 17:41:49 |
Author | Benjamin Berkels <torr.samaho@quan...> |
Commiter | Benjamin Berkels |
added Dusk's FindStateLabelAndOffset extension to handle child states (part of Dusk's wound state / custom damagetype fix patch, but slightly modified to use references instead of pointers)
@@ -265,24 +265,43 @@ | ||
265 | 265 | //***************************************************************************** |
266 | 266 | // |
267 | 267 | // [BB] Try to find the state label and the correspoding offset belonging to the target state. |
268 | -void FindStateLabelAndOffset( const AActor *pActor, FState *pState, FString &stateLabel, LONG &lOffset ) | |
268 | +// [Dusk] Pretty much rewrote this based on dumpstates code, this now recurses through state | |
269 | +// children now to check them as well. This is needed to find stuff like custom pain states. | |
270 | + | |
271 | +bool FindStateAddressRecursor( AActor *pActor, FState *pState, FString prefix, FStateLabels *list, FString &label, LONG &lOffset ) | |
272 | +{ | |
273 | + for ( int i = 0; i < list->NumLabels; ++i ) { | |
274 | + if ( list->Labels[i].State != NULL ) { | |
275 | + unsigned int offset; | |
276 | + if ( pActor->InState( list->Labels[i].State, &offset, pState ) && ( offset <= 255 ) ) { | |
277 | + // Found it! | |
278 | + label = prefix + list->Labels[i].Label.GetChars(); | |
279 | + lOffset = static_cast<LONG>( offset ); | |
280 | + return true; | |
281 | + } | |
282 | + } | |
283 | + | |
284 | + // Not in there, check the children | |
285 | + if ( list->Labels[i].Children != NULL ) { | |
286 | + FString newprefix = prefix + list->Labels[i].Label.GetChars() + '.'; | |
287 | + bool found = FindStateAddressRecursor( pActor, pState, newprefix, list->Labels[i].Children, label, lOffset ); | |
288 | + if ( found == true ) | |
289 | + return true; | |
290 | + } | |
291 | + } | |
292 | + | |
293 | + return false; | |
294 | +} | |
295 | + | |
296 | +void FindStateLabelAndOffset( AActor *pActor, FState *pState, FString &stateLabel, LONG &lOffset ) | |
269 | 297 | { |
270 | 298 | stateLabel = ""; |
271 | 299 | lOffset = 0; |
272 | 300 | FStateLabels *pStateList = pActor->GetClass()->ActorInfo->StateList; |
273 | 301 | |
274 | - // Begin searching through the actor's state labels to find the state that corresponds | |
275 | - // to the given state. | |
276 | - for ( ULONG ulIdx = 0; ulIdx < static_cast<ULONG> ( pStateList->NumLabels ); ++ulIdx ) | |
277 | - { | |
278 | - unsigned int offset; | |
279 | - if ( pActor->InState ( pStateList->Labels[ulIdx].State, &offset, pState ) && ( offset <= 255 ) ) | |
280 | - { | |
281 | - lOffset = static_cast<LONG> ( offset ); | |
282 | - stateLabel = pStateList->Labels[ulIdx].Label.GetChars(); | |
283 | - return; | |
284 | - } | |
285 | - } | |
302 | + bool found = FindStateAddressRecursor( pActor, pState, "", pStateList, stateLabel, lOffset ); | |
303 | + if ( found == false && sv_showwarnings ) | |
304 | + Printf ("FindStateLabelAndOffset: Couldn't find state!\n"); | |
286 | 305 | } |
287 | 306 | |
288 | 307 | //***************************************************************************** |