Commit MetaInfo

Revision2a791df45c2cf015e28b5e5866a027cf07cd79e7 (tree)
Time2012-05-27 17:41:49
AuthorBenjamin Berkels <torr.samaho@quan...>
CommiterBenjamin Berkels

Log Message

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)

Change Summary

Incremental Difference

diff -r d354b587d47e -r 2a791df45c2c src/sv_commands.cpp
--- a/src/sv_commands.cpp Sun May 27 10:21:28 2012 +0200
+++ b/src/sv_commands.cpp Sun May 27 10:41:49 2012 +0200
@@ -265,24 +265,43 @@
265265 //*****************************************************************************
266266 //
267267 // [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 )
269297 {
270298 stateLabel = "";
271299 lOffset = 0;
272300 FStateLabels *pStateList = pActor->GetClass()->ActorInfo->StateList;
273301
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");
286305 }
287306
288307 //*****************************************************************************
Show on old repository browser