From 66b090cd44df7626a71de4d5bcc15c8645e5eb8e Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Wed, 25 Mar 2015 22:25:00 +0100 Subject: [PATCH] - Improvements to some of the actor debug CCMDs. - 'monster' and 'items' can now filter the list if an argument is passed (like with 'kill'); - added 'countitems', which will show only the 'count items' in the current map, with the same filter parameter as 'monster' and 'items'. - reorganize the code to reduce the duplication. --- src/c_cmds.cpp | 78 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index 5fc7f0fd8..778f25be1 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -889,21 +889,42 @@ CCMD(info) "the NOBLOCKMAP flag or have height/radius of 0.\n"); } -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- -CCMD(monster) -{ - AActor * mo; +typedef bool (*ActorTypeChecker) (AActor *); - if (CheckCheatmode ()) return; +static bool IsActorAMonster(AActor *mo) +{ + return mo->flags3&MF3_ISMONSTER && !(mo->flags&MF_CORPSE) && !(mo->flags&MF_FRIENDLY); +} + +static bool IsActorAnItem(AActor *mo) +{ + return mo->IsKindOf(RUNTIME_CLASS(AInventory)) && mo->flags&MF_SPECIAL; +} + +static bool IsActorACountItem(AActor *mo) +{ + return mo->IsKindOf(RUNTIME_CLASS(AInventory)) && mo->flags&MF_SPECIAL && mo->flags&MF_COUNTITEM; +} + +static void PrintFilteredActorList(const ActorTypeChecker IsActorType, const char *FilterName) +{ + AActor *mo; + const PClass *FilterClass = NULL; + + if (FilterName != NULL) + { + FilterClass = PClass::FindClass(FilterName); + if (FilterClass == NULL || FilterClass->ActorInfo == NULL) + { + Printf("%s is not an actor class.\n", FilterName); + return; + } + } TThinkerIterator it; while ( (mo = it.Next()) ) { - if (mo->flags3&MF3_ISMONSTER && !(mo->flags&MF_CORPSE) && !(mo->flags&MF_FRIENDLY)) + if ((FilterClass == NULL || mo->IsA(FilterClass)) && IsActorType(mo)) { Printf ("%s at (%d,%d,%d)\n", mo->GetClass()->TypeName.GetChars(), @@ -912,6 +933,18 @@ CCMD(monster) } } +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- +CCMD(monster) +{ + if (CheckCheatmode ()) return; + + PrintFilteredActorList(IsActorAMonster, argv.argc() > 1 ? argv[1] : NULL); +} + //----------------------------------------------------------------------------- // // @@ -919,20 +952,21 @@ CCMD(monster) //----------------------------------------------------------------------------- CCMD(items) { - AActor * mo; - if (CheckCheatmode ()) return; - TThinkerIterator it; - while ( (mo = it.Next()) ) - { - if (mo->IsKindOf(RUNTIME_CLASS(AInventory)) && mo->flags&MF_SPECIAL) - { - Printf ("%s at (%d,%d,%d)\n", - mo->GetClass()->TypeName.GetChars(), - mo->x >> FRACBITS, mo->y >> FRACBITS, mo->z >> FRACBITS); - } - } + PrintFilteredActorList(IsActorAnItem, argv.argc() > 1 ? argv[1] : NULL); +} + +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- +CCMD(countitems) +{ + if (CheckCheatmode ()) return; + + PrintFilteredActorList(IsActorACountItem, argv.argc() > 1 ? argv[1] : NULL); } //-----------------------------------------------------------------------------