From fc15be8689d3648d40199e4b4a3f50ebe7790a42 Mon Sep 17 00:00:00 2001 From: Braden Obrzut Date: Sat, 23 Jan 2016 21:47:20 -0500 Subject: [PATCH] - Improved DrawSwitchableImage keyslot condition to include key species. - Fixed: currentpos command would crash if not in game. --- src/c_cmds.cpp | 11 +++++++-- src/g_shared/sbarinfo_commands.cpp | 39 ++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index 3cfbf1c65..233c31d29 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -1083,8 +1083,15 @@ CCMD(nextsecret) CCMD(currentpos) { AActor *mo = players[consoleplayer].mo; - Printf("Current player position: (%1.3f,%1.3f,%1.3f), angle: %1.3f, floorheight: %1.3f, sector:%d, lightlevel: %d\n", - FIXED2FLOAT(mo->X()), FIXED2FLOAT(mo->Y()), FIXED2FLOAT(mo->Z()), mo->angle/float(ANGLE_1), FIXED2FLOAT(mo->floorz), mo->Sector->sectornum, mo->Sector->lightlevel); + if(mo) + { + Printf("Current player position: (%1.3f,%1.3f,%1.3f), angle: %1.3f, floorheight: %1.3f, sector:%d, lightlevel: %d\n", + FIXED2FLOAT(mo->X()), FIXED2FLOAT(mo->Y()), FIXED2FLOAT(mo->Z()), mo->angle/float(ANGLE_1), FIXED2FLOAT(mo->floorz), mo->Sector->sectornum, mo->Sector->lightlevel); + } + else + { + Printf("You are not in game!"); + } } //----------------------------------------------------------------------------- diff --git a/src/g_shared/sbarinfo_commands.cpp b/src/g_shared/sbarinfo_commands.cpp index 7a874328f..f91d5841c 100644 --- a/src/g_shared/sbarinfo_commands.cpp +++ b/src/g_shared/sbarinfo_commands.cpp @@ -412,6 +412,21 @@ class CommandDrawSwitchableImage : public CommandDrawImage return compare != value; } } + // Key species are used to allow altnerates for existing key slots. + static FName LookupKeySpecies(int keynum) + { + for(unsigned int i = 0;i < PClass::m_Types.Size();++i) + { + const PClass *cls = PClass::m_Types[i]; + if(cls->IsDescendantOf(RUNTIME_CLASS(AKey))) + { + AKey *key = (AKey *)GetDefaultByType(cls); + if(key->KeyNumber == keynum) + return cls->TypeName; + } + } + return FName(); + } public: CommandDrawSwitchableImage(SBarInfo *script) : CommandDrawImage(script), @@ -442,6 +457,7 @@ class CommandDrawSwitchableImage : public CommandDrawImage condition = KEYSLOT; sc.MustGetToken(TK_IntConst); conditionalValue[0] = sc.Number; + keySpecies[0] = LookupKeySpecies(conditionalValue[0]); } else if(sc.Compare("armortype")) { @@ -468,6 +484,8 @@ class CommandDrawSwitchableImage : public CommandDrawImage { sc.MustGetToken(TK_IntConst); conditionalValue[1] = sc.Number; + if(condition == KEYSLOT) + keySpecies[1] = LookupKeySpecies(conditionalValue[1]); } else if(condition == ARMORTYPE) { @@ -541,11 +559,21 @@ class CommandDrawSwitchableImage : public CommandDrawImage if(item->IsKindOf(RUNTIME_CLASS(AKey))) { int keynum = static_cast(item)->KeyNumber; - - if(keynum == conditionalValue[0]) - found1 = true; - if(conditionAnd && keynum == conditionalValue[1]) // two keys - found2 = true; + if(keynum) + { + if(keynum == conditionalValue[0]) + found1 = true; + if(conditionAnd && keynum == conditionalValue[1]) // two keys + found2 = true; + } + else + { + FName species = item->GetSpecies(); + if(species == keySpecies[0]) + found1 = true; + if(conditionAnd && species == keySpecies[1]) + found2 = true; + } } } @@ -639,6 +667,7 @@ class CommandDrawSwitchableImage : public CommandDrawImage Operator conditionalOperator[2]; FString inventoryItem[2]; int armorType[2]; + FName keySpecies[2]; }; ////////////////////////////////////////////////////////////////////////////////