From d8acf774a604cb93e5a1100bac3edebea212bc95 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 18 Jan 2017 15:17:12 +0100 Subject: [PATCH] - scriptified the remains of AKey. - replaced Key.KeyNumber with special1. This is only for internal bookkeeping purposes so there's really no need to complicate this with a new variable when this one works just as well. --- src/CMakeLists.txt | 1 - src/am_map.cpp | 8 +-- src/g_inventory/a_keys.cpp | 59 ++++++++----------- src/g_inventory/a_keys.h | 10 +--- src/g_shared/sbarinfo_commands.cpp | 14 ++--- src/g_shared/shared_hud.cpp | 16 ++--- src/g_strife/strife_sbar.cpp | 6 +- src/namedef.h | 1 + src/p_conversation.cpp | 2 +- src/p_user.cpp | 10 ++-- wadsrc/static/zscript/inventory/inv_misc.txt | 4 +- wadsrc/static/zscript/shared/player_cheat.txt | 4 +- 12 files changed, 57 insertions(+), 78 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 366a3a663..7d6c20306 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1145,7 +1145,6 @@ set (PCH_SOURCES w_wad.cpp wi_stuff.cpp zstrformat.cpp - g_inventory/a_ammo.cpp g_inventory/a_armor.cpp g_inventory/a_keys.cpp g_inventory/a_pickups.cpp diff --git a/src/am_map.cpp b/src/am_map.cpp index 1f2b4f473..b94840d66 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -2740,8 +2740,8 @@ void AM_drawKeys () mpoint_t p; DAngle angle; - TThinkerIterator it; - AKey *key; + TThinkerIterator it(NAME_Key); + AInventory *key; while ((key = it.Next()) != NULL) { @@ -2853,7 +2853,7 @@ void AM_drawThings () // Find the key's own color. // Only works correctly if single-key locks have lower numbers than any-key locks. // That is the case for all default keys, however. - if (t->IsKindOf(RUNTIME_CLASS(AKey))) + if (t->IsKindOf(PClass::FindActor(NAME_Key))) { if (G_SkillProperty(SKILLP_EasyKey)) { @@ -2863,7 +2863,7 @@ void AM_drawThings () else if (am_showkeys) { int P_GetMapColorForKey (AInventory * key); - int c = P_GetMapColorForKey(static_cast(t)); + int c = P_GetMapColorForKey(static_cast(t)); if (c >= 0) color.FromRGB(RPART(c), GPART(c), BPART(c)); else color = AMColors[AMColors.ThingColor_CountItem]; diff --git a/src/g_inventory/a_keys.cpp b/src/g_inventory/a_keys.cpp index 31237018c..0ad6b72f1 100644 --- a/src/g_inventory/a_keys.cpp +++ b/src/g_inventory/a_keys.cpp @@ -51,7 +51,6 @@ // //=========================================================================== - //=========================================================================== // // @@ -64,29 +63,24 @@ struct OneKey bool check(AActor *owner) { - if (owner->IsKindOf(RUNTIME_CLASS(AKey))) - { - // P_GetMapColorForKey() checks the key directly - return owner->IsA(key) || owner->GetSpecies() == key->TypeName; - } - else - { - // Other calls check an actor that may have a key in its inventory. - AInventory *item; + // P_GetMapColorForKey() checks the key directly + if (owner->IsA(key) || owner->GetSpecies() == key->TypeName) return true; - for (item = owner->Inventory; item != NULL; item = item->Inventory) + // Other calls check an actor that may have a key in its inventory. + AInventory *item; + + for (item = owner->Inventory; item != NULL; item = item->Inventory) + { + if (item->IsA(key)) { - if (item->IsA(key)) - { - return true; - } - else if (item->GetSpecies() == key->TypeName) - { - return true; - } + return true; + } + else if (item->GetSpecies() == key->TypeName) + { + return true; } - return false; } + return false; } }; @@ -138,9 +132,10 @@ struct Lock // An empty key list means that any key will do if (!keylist.Size()) { + auto kt = PClass::FindActor(NAME_Key); for (AInventory * item = owner->Inventory; item != NULL; item = item->Inventory) { - if (item->IsKindOf (RUNTIME_CLASS(AKey))) + if (item->IsKindOf (kt)) { return true; } @@ -192,12 +187,12 @@ static void AddOneKey(Keygroup *keygroup, PClassActor *mi, FScanner &sc) keygroup->anykeylist.Push (k); //... but only keys get key numbers! - if (mi->IsDescendantOf(RUNTIME_CLASS(AKey))) + if (mi->IsDescendantOf(PClass::FindActor(NAME_Key))) { if (!ignorekey && - static_cast(GetDefaultByType(mi))->KeyNumber == 0) + GetDefaultByType(mi)->special1 == 0) { - static_cast(GetDefaultByType(mi))->KeyNumber=++currentnumber; + GetDefaultByType(mi)->special1 = ++currentnumber; } } } @@ -387,14 +382,15 @@ static void ParseLock(FScanner &sc) static void ClearLocks() { unsigned int i; + auto kt = PClass::FindActor(NAME_Key); for(i = 0; i < PClassActor::AllActorClasses.Size(); i++) { - if (PClassActor::AllActorClasses[i]->IsDescendantOf(RUNTIME_CLASS(AKey))) + if (PClassActor::AllActorClasses[i]->IsDescendantOf(kt)) { - AKey *key = static_cast(GetDefaultByType(PClassActor::AllActorClasses[i])); + auto key = GetDefaultByType(PClassActor::AllActorClasses[i]); if (key != NULL) { - key->KeyNumber = 0; + key->special1 = 0; } } } @@ -523,15 +519,6 @@ bool P_CheckKeys (AActor *owner, int keynum, bool remote) return false; } -//========================================================================== -// -// AKey implementation -// -//========================================================================== - -IMPLEMENT_CLASS(AKey, false, false) -DEFINE_FIELD(AKey, KeyNumber) - //========================================================================== // // These functions can be used to get color information for diff --git a/src/g_inventory/a_keys.h b/src/g_inventory/a_keys.h index a62670413..328ff04a6 100644 --- a/src/g_inventory/a_keys.h +++ b/src/g_inventory/a_keys.h @@ -1,14 +1,8 @@ #ifndef A_KEYS_H #define A_KEYS_H -#include "a_pickups.h" - -class AKey : public AInventory -{ - DECLARE_CLASS (AKey, AInventory) -public: - BYTE KeyNumber; -}; +class AActor; +class AInventory; bool P_CheckKeys (AActor *owner, int keynum, bool remote); void P_InitKeyMessages (); diff --git a/src/g_shared/sbarinfo_commands.cpp b/src/g_shared/sbarinfo_commands.cpp index ccc7d8cc3..5e1514881 100644 --- a/src/g_shared/sbarinfo_commands.cpp +++ b/src/g_shared/sbarinfo_commands.cpp @@ -416,10 +416,10 @@ class CommandDrawSwitchableImage : public CommandDrawImage for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) { PClassActor *cls = PClassActor::AllActorClasses[i]; - if (cls->IsDescendantOf(RUNTIME_CLASS(AKey))) + if (cls->IsDescendantOf(PClass::FindActor(NAME_Key))) { - AKey *key = (AKey *)GetDefaultByType(cls); - if (key->KeyNumber == keynum) + auto key = GetDefaultByType(cls); + if (key->special1 == keynum) return cls->TypeName; } } @@ -554,9 +554,9 @@ class CommandDrawSwitchableImage : public CommandDrawImage for(AInventory *item = statusBar->CPlayer->mo->Inventory;item != NULL;item = item->Inventory) { - if(item->IsKindOf(RUNTIME_CLASS(AKey))) + if(item->IsKindOf(PClass::FindActor(NAME_Key))) { - int keynum = static_cast(item)->KeyNumber; + int keynum = item->special1; if(keynum) { if(keynum == conditionalValue[0]) @@ -1474,7 +1474,7 @@ class CommandDrawNumber : public CommandDrawString num = 0; for(AInventory *item = statusBar->CPlayer->mo->Inventory;item != NULL;item = item->Inventory) { - if(item->IsKindOf(RUNTIME_CLASS(AKey))) + if(item->IsKindOf(PClass::FindActor(NAME_Key))) num++; } break; @@ -2429,7 +2429,7 @@ class CommandDrawKeyBar : public SBarInfoCommand int rowWidth = 0; for(unsigned int i = 0;i < number+keyOffset;i++) { - while(!item->Icon.isValid() || !item->IsKindOf(RUNTIME_CLASS(AKey))) + while(!item->Icon.isValid() || !item->IsKindOf(PClass::FindActor(NAME_Key))) { item = item->Inventory; if(item == NULL) diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index 981b72779..118838f79 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -385,9 +385,9 @@ static TArray KeyTypes, UnassignedKeyTypes; static int ktcmp(const void * a, const void * b) { - AKey *key1 = (AKey*)GetDefaultByType ( *(PClassActor **)a ); - AKey *key2 = (AKey*)GetDefaultByType ( *(PClassActor **)b ); - return key1->KeyNumber - key2->KeyNumber; + auto key1 = GetDefaultByType ( *(PClassActor **)a ); + auto key2 = GetDefaultByType ( *(PClassActor **)b ); + return key1->special1 - key2->special1; } static void SetKeyTypes() @@ -395,13 +395,14 @@ static void SetKeyTypes() for(unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); i++) { PClass *ti = PClassActor::AllActorClasses[i]; + auto kt = PClass::FindActor(NAME_Key); - if (ti->IsDescendantOf(RUNTIME_CLASS(AKey))) + if (ti->IsDescendantOf(kt)) { PClassActor *tia = static_cast(ti); - AKey *key = (AKey*)GetDefaultByType(tia); + AInventory *key = (AInventory*)(GetDefaultByType(tia)); - if (key->Icon.isValid() && key->KeyNumber>0) + if (key->Icon.isValid() && key->special1 > 0) { KeyTypes.Push(tia); } @@ -418,8 +419,7 @@ static void SetKeyTypes() else { // Don't leave the list empty - PClassActor *ti = RUNTIME_CLASS(AKey); - KeyTypes.Push(ti); + KeyTypes.Push(PClass::FindActor(NAME_Key)); } } diff --git a/src/g_strife/strife_sbar.cpp b/src/g_strife/strife_sbar.cpp index 5fc4a3ae6..cec529371 100644 --- a/src/g_strife/strife_sbar.cpp +++ b/src/g_strife/strife_sbar.cpp @@ -261,7 +261,7 @@ public: item != NULL; item = item->Inventory) { - if (item->IsKindOf (RUNTIME_CLASS(AKey))) + if (item->IsKindOf (PClass::FindActor(NAME_Key))) { if (i == KeyPopPos) { @@ -633,7 +633,7 @@ private: i < endpos && item != NULL; item = item->Inventory) { - if (!item->IsKindOf (RUNTIME_CLASS(AKey))) + if (!item->IsKindOf (PClass::FindActor(NAME_Key))) continue; if (i < pos) @@ -678,7 +678,7 @@ private: item != NULL; item = item->Inventory) { - if (item->IsKindOf (RUNTIME_CLASS(AKey))) + if (item->IsKindOf (PClass::FindActor(NAME_Key))) { i++; } diff --git a/src/namedef.h b/src/namedef.h index 0122dbaad..255177789 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -717,6 +717,7 @@ xx(Strength) xx(Mode) xx(PowerupType) xx(PlayerPawn) +xx(Key) // Decorate compatibility functions xx(BuiltinTypeCheck) diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index 0de02656d..ac6c2bc23 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -642,7 +642,7 @@ static void TakeStrifeItem (player_t *player, PClassActor *itemtype, int amount) return; // Don't take keys. - if (itemtype->IsDescendantOf (RUNTIME_CLASS(AKey))) + if (itemtype->IsDescendantOf (PClass::FindActor(NAME_Key))) return; // Don't take the sigil. diff --git a/src/p_user.cpp b/src/p_user.cpp index deb6fbb22..906e3180f 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -1075,12 +1075,12 @@ void APlayerPawn::GiveDeathmatchInventory() { for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) { - if (PClassActor::AllActorClasses[i]->IsDescendantOf (RUNTIME_CLASS(AKey))) + if (PClassActor::AllActorClasses[i]->IsDescendantOf (PClass::FindActor(NAME_Key))) { - AKey *key = (AKey *)GetDefaultByType (PClassActor::AllActorClasses[i]); - if (key->KeyNumber != 0) + AInventory *key = (AInventory*)GetDefaultByType (PClassActor::AllActorClasses[i]); + if (key->special1 != 0) { - key = static_cast(Spawn(static_cast(PClassActor::AllActorClasses[i]))); + key = (AInventory*)Spawn(PClassActor::AllActorClasses[i]); if (!key->CallTryPickup (this)) { key->Destroy (); @@ -1133,7 +1133,7 @@ void APlayerPawn::FilterCoopRespawnInventory (APlayerPawn *oldplayer) if ((dmflags & DF_COOP_LOSE_KEYS) && defitem == NULL && - item->IsKindOf(RUNTIME_CLASS(AKey))) + item->IsKindOf(PClass::FindActor(NAME_Key))) { item->Destroy(); } diff --git a/wadsrc/static/zscript/inventory/inv_misc.txt b/wadsrc/static/zscript/inventory/inv_misc.txt index 9bea4c7bf..9f13ab957 100644 --- a/wadsrc/static/zscript/inventory/inv_misc.txt +++ b/wadsrc/static/zscript/inventory/inv_misc.txt @@ -28,10 +28,8 @@ class ScoreItem : Inventory // //=========================================================================== -class Key : Inventory native +class Key : Inventory { - native uint8 KeyNumber; - Default { +DONTGIB; // Don't disappear due to a crusher diff --git a/wadsrc/static/zscript/shared/player_cheat.txt b/wadsrc/static/zscript/shared/player_cheat.txt index 30760fb5d..01b059540 100644 --- a/wadsrc/static/zscript/shared/player_cheat.txt +++ b/wadsrc/static/zscript/shared/player_cheat.txt @@ -157,8 +157,8 @@ extend class PlayerPawn { if (AllActorClasses[i] is "Key") { - readonly keyitem = GetDefaultByType ((class)(AllActorClasses[i])); - if (keyitem.KeyNumber != 0) + let keyitem = GetDefaultByType (AllActorClasses[i]); + if (keyitem.special1 != 0) { let item = Inventory(Spawn(AllActorClasses[i])); if (!item.CallTryPickup (self))