From 156f9c488e7b61c56135c82cc81f21e696d4a199 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 15 Jan 2017 18:16:36 +0100 Subject: [PATCH] - added script variable access for native code so that many more classes can be fully exported. Tested with the puzzle items. --- src/CMakeLists.txt | 1 - src/d_net.cpp | 4 +- src/dobject.h | 1 - src/dobjtype.cpp | 1 - src/g_inventory/a_keys.cpp | 1 - src/g_inventory/a_keys.h | 20 ------ src/g_inventory/a_puzzleitems.cpp | 65 -------------------- src/m_cheat.cpp | 13 ++-- src/namedef.h | 2 + src/p_lnspec.cpp | 5 +- src/scripting/thingdef_properties.cpp | 19 ------ wadsrc/static/zscript/inventory/inv_misc.txt | 11 ++-- 12 files changed, 23 insertions(+), 120 deletions(-) delete mode 100644 src/g_inventory/a_puzzleitems.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 014c405b8..1c8ae0abb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1153,7 +1153,6 @@ set (PCH_SOURCES g_inventory/a_health.cpp g_inventory/a_keys.cpp g_inventory/a_pickups.cpp - g_inventory/a_puzzleitems.cpp g_inventory/a_weaponpiece.cpp g_inventory/a_weapons.cpp g_strife/strife_sbar.cpp diff --git a/src/d_net.cpp b/src/d_net.cpp index 0ebb7de38..c47ae6bd1 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2248,11 +2248,11 @@ void Net_DoCommand (int type, BYTE **stream, int player) if (gamestate == GS_LEVEL && !paused) { AInventory *item = players[player].mo->Inventory; - + auto pitype = PClass::FindActor(NAME_PuzzleItem); while (item != NULL) { AInventory *next = item->Inventory; - if (item->ItemFlags & IF_INVBAR && !(item->IsKindOf(RUNTIME_CLASS(APuzzleItem)))) + if (item->ItemFlags & IF_INVBAR && !(item->IsKindOf(pitype))) { players[player].mo->UseInventory (item); } diff --git a/src/dobject.h b/src/dobject.h index dc550355e..b37380342 100644 --- a/src/dobject.h +++ b/src/dobject.h @@ -94,7 +94,6 @@ enum CLASSREG_PClass, CLASSREG_PClassActor, CLASSREG_PClassInventory, - CLASSREG_PClassPuzzleItem, CLASSREG_PClassWeapon, CLASSREG_PClassPlayerPawn, CLASSREG_PClassType, diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 2c4b06521..d289847e1 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -3115,7 +3115,6 @@ PClass *ClassReg::RegisterClass() &PClass::RegistrationInfo, &PClassActor::RegistrationInfo, &PClassInventory::RegistrationInfo, - &PClassPuzzleItem::RegistrationInfo, &PClassWeapon::RegistrationInfo, &PClassPlayerPawn::RegistrationInfo, &PClassType::RegistrationInfo, diff --git a/src/g_inventory/a_keys.cpp b/src/g_inventory/a_keys.cpp index 286286ef7..31237018c 100644 --- a/src/g_inventory/a_keys.cpp +++ b/src/g_inventory/a_keys.cpp @@ -530,7 +530,6 @@ bool P_CheckKeys (AActor *owner, int keynum, bool remote) //========================================================================== IMPLEMENT_CLASS(AKey, false, false) - DEFINE_FIELD(AKey, KeyNumber) //========================================================================== diff --git a/src/g_inventory/a_keys.h b/src/g_inventory/a_keys.h index bb5336fb4..a62670413 100644 --- a/src/g_inventory/a_keys.h +++ b/src/g_inventory/a_keys.h @@ -16,24 +16,4 @@ void P_DeinitKeyMessages (); int P_GetMapColorForLock (int lock); int P_GetMapColorForKey (AInventory *key); - -// PuzzleItems work in conjunction with the UsePuzzleItem special -class PClassPuzzleItem : public PClassInventory -{ - DECLARE_CLASS(PClassPuzzleItem, PClassInventory); -protected: -public: - virtual void DeriveData(PClass *newclass); - FString PuzzFailMessage; -}; - -class APuzzleItem : public AInventory -{ - DECLARE_CLASS_WITH_META(APuzzleItem, AInventory, PClassPuzzleItem) -public: - - int PuzzleItemNumber; -}; - - #endif diff --git a/src/g_inventory/a_puzzleitems.cpp b/src/g_inventory/a_puzzleitems.cpp deleted file mode 100644 index ecb2fb9dd..000000000 --- a/src/g_inventory/a_puzzleitems.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* -** a_puzzleitems.cpp -** Implements Hexen's puzzle items. -** -**--------------------------------------------------------------------------- -** Copyright 2002-2016 Randy Heit -** Copyright 2006-2016 Cheistoph Oelckers -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions -** are met: -** -** 1. Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in the -** documentation and/or other materials provided with the distribution. -** 3. The name of the author may not be used to endorse or promote products -** derived from this software without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -**--------------------------------------------------------------------------- -** -*/ - -#include "info.h" -#include "a_pickups.h" -#include "a_artifacts.h" -#include "gstrings.h" -#include "p_local.h" -#include "s_sound.h" -#include "c_console.h" -#include "doomstat.h" -#include "v_font.h" -#include "a_keys.h" - - -IMPLEMENT_CLASS(PClassPuzzleItem, false, false) -IMPLEMENT_CLASS(APuzzleItem, false, false) - -DEFINE_FIELD(APuzzleItem, PuzzleItemNumber) -DEFINE_FIELD(PClassPuzzleItem, PuzzFailMessage) - -//=========================================================================== -// -// -// -//=========================================================================== - -void PClassPuzzleItem::DeriveData(PClass *newclass) -{ - Super::DeriveData(newclass); - assert(newclass->IsKindOf(RUNTIME_CLASS(PClassPuzzleItem))); - static_cast(newclass)->PuzzFailMessage = PuzzFailMessage; -} diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index bbf366995..3af00c012 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -747,6 +747,8 @@ void cht_Give (player_t *player, const char *name, int amount) if (giveall || stricmp (name, "artifacts") == 0) { + auto pitype = PClass::FindActor(NAME_PuzzleItem); + for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) { type = PClassActor::AllActorClasses[i]; @@ -754,7 +756,7 @@ void cht_Give (player_t *player, const char *name, int amount) { AInventory *def = (AInventory*)GetDefaultByType (type); if (def->Icon.isValid() && def->MaxAmount > 1 && - !type->IsDescendantOf (RUNTIME_CLASS(APuzzleItem)) && + !type->IsDescendantOf (pitype) && !type->IsDescendantOf (RUNTIME_CLASS(APowerup)) && !type->IsDescendantOf (RUNTIME_CLASS(AArmor))) { @@ -772,10 +774,11 @@ void cht_Give (player_t *player, const char *name, int amount) if (giveall || stricmp (name, "puzzlepieces") == 0) { + auto pitype = PClass::FindActor(NAME_PuzzleItem); for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) { type = PClassActor::AllActorClasses[i]; - if (type->IsDescendantOf (RUNTIME_CLASS(APuzzleItem))) + if (type->IsDescendantOf (pitype)) { AInventory *def = (AInventory*)GetDefaultByType (type); if (def->Icon.isValid()) @@ -954,13 +957,14 @@ void cht_Take (player_t *player, const char *name, int amount) if (takeall || stricmp (name, "artifacts") == 0) { + auto pitype = PClass::FindActor(NAME_PuzzleItem); for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) { type = PClassActor::AllActorClasses[i]; if (type->IsDescendantOf (RUNTIME_CLASS (AInventory))) { - if (!type->IsDescendantOf (RUNTIME_CLASS (APuzzleItem)) && + if (!type->IsDescendantOf (pitype) && !type->IsDescendantOf (RUNTIME_CLASS (APowerup)) && !type->IsDescendantOf (RUNTIME_CLASS (AArmor)) && !type->IsDescendantOf (RUNTIME_CLASS (AWeapon)) && @@ -980,11 +984,12 @@ void cht_Take (player_t *player, const char *name, int amount) if (takeall || stricmp (name, "puzzlepieces") == 0) { + auto pitype = PClass::FindActor(NAME_PuzzleItem); for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) { type = PClassActor::AllActorClasses[i]; - if (type->IsDescendantOf (RUNTIME_CLASS (APuzzleItem))) + if (type->IsDescendantOf (pitype)) { AActor *puzzlepiece = player->mo->FindInventory(static_cast(type)); diff --git a/src/namedef.h b/src/namedef.h index cfed6c63e..61430219b 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -166,6 +166,8 @@ xx(MiniMissileLauncher) xx(StrifeGrenadeLauncher) xx(Mauler) xx(BackpackItem) +xx(PuzzleItem) +xx(PuzzleItemNumber) xx(AcolyteBlue) xx(SpectralLightningV1) diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index 9fde1af22..ec8c8d2fa 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -2138,11 +2138,12 @@ FUNC(LS_UsePuzzleItem) if (!it) return false; // Check player's inventory for puzzle item + auto pitype = PClass::FindActor(NAME_PuzzleItem); for (item = it->Inventory; item != NULL; item = item->Inventory) { - if (item->IsKindOf (RUNTIME_CLASS(APuzzleItem))) + if (item->IsKindOf (pitype)) { - if (static_cast(item)->PuzzleItemNumber == arg0) + if (item->IntVar(NAME_PuzzleItemNumber) == arg0) { if (it->UseInventory (item)) { diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 69ef02e88..6d6c166a4 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -1978,25 +1978,6 @@ DEFINE_CLASS_PROPERTY(autouse, I, HealthPickup) defaults->autousemode = i; } -//========================================================================== -// -//========================================================================== -DEFINE_CLASS_PROPERTY(number, I, PuzzleItem) -{ - PROP_INT_PARM(i, 0); - defaults->PuzzleItemNumber = i; -} - -//========================================================================== -// -//========================================================================== -DEFINE_CLASS_PROPERTY(failmessage, T, PuzzleItem) -{ - PROP_STRING_PARM(str, 0); - assert(info->IsKindOf(RUNTIME_CLASS(PClassPuzzleItem))); - static_cast(info)->PuzzFailMessage = str; -} - //========================================================================== // //========================================================================== diff --git a/wadsrc/static/zscript/inventory/inv_misc.txt b/wadsrc/static/zscript/inventory/inv_misc.txt index 9c5ffc205..9bea4c7bf 100644 --- a/wadsrc/static/zscript/inventory/inv_misc.txt +++ b/wadsrc/static/zscript/inventory/inv_misc.txt @@ -87,10 +87,13 @@ class MapRevealer : Inventory // //=========================================================================== -class PuzzleItem : Inventory native +class PuzzleItem : Inventory { - native int PuzzleItemNumber; - native meta String PuzzFailMessage; + /*meta*/ int PuzzleItemNumber; + /*meta*/ String PuzzFailMessage; + + property Number: PuzzleItemNumber; + property FailMessage: PuzzFailMessage; Default { @@ -99,7 +102,7 @@ class PuzzleItem : Inventory native Inventory.DefMaxAmount; Inventory.UseSound "PuzzleSuccess"; Inventory.PickupSound "misc/i_pkup"; - PuzzleItem.FailMessage("TXT_USEPUZZLEFAILED"); + PuzzleItem.FailMessage("$TXT_USEPUZZLEFAILED"); } override bool HandlePickup (Inventory item)