- added script variable access for native code so that many more classes can be fully exported. Tested with the puzzle items.

This commit is contained in:
Christoph Oelckers 2017-01-15 18:16:36 +01:00
parent 179b6e1a39
commit 156f9c488e
12 changed files with 23 additions and 120 deletions

View file

@ -1153,7 +1153,6 @@ set (PCH_SOURCES
g_inventory/a_health.cpp g_inventory/a_health.cpp
g_inventory/a_keys.cpp g_inventory/a_keys.cpp
g_inventory/a_pickups.cpp g_inventory/a_pickups.cpp
g_inventory/a_puzzleitems.cpp
g_inventory/a_weaponpiece.cpp g_inventory/a_weaponpiece.cpp
g_inventory/a_weapons.cpp g_inventory/a_weapons.cpp
g_strife/strife_sbar.cpp g_strife/strife_sbar.cpp

View file

@ -2248,11 +2248,11 @@ void Net_DoCommand (int type, BYTE **stream, int player)
if (gamestate == GS_LEVEL && !paused) if (gamestate == GS_LEVEL && !paused)
{ {
AInventory *item = players[player].mo->Inventory; AInventory *item = players[player].mo->Inventory;
auto pitype = PClass::FindActor(NAME_PuzzleItem);
while (item != NULL) while (item != NULL)
{ {
AInventory *next = item->Inventory; 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); players[player].mo->UseInventory (item);
} }

View file

@ -94,7 +94,6 @@ enum
CLASSREG_PClass, CLASSREG_PClass,
CLASSREG_PClassActor, CLASSREG_PClassActor,
CLASSREG_PClassInventory, CLASSREG_PClassInventory,
CLASSREG_PClassPuzzleItem,
CLASSREG_PClassWeapon, CLASSREG_PClassWeapon,
CLASSREG_PClassPlayerPawn, CLASSREG_PClassPlayerPawn,
CLASSREG_PClassType, CLASSREG_PClassType,

View file

@ -3115,7 +3115,6 @@ PClass *ClassReg::RegisterClass()
&PClass::RegistrationInfo, &PClass::RegistrationInfo,
&PClassActor::RegistrationInfo, &PClassActor::RegistrationInfo,
&PClassInventory::RegistrationInfo, &PClassInventory::RegistrationInfo,
&PClassPuzzleItem::RegistrationInfo,
&PClassWeapon::RegistrationInfo, &PClassWeapon::RegistrationInfo,
&PClassPlayerPawn::RegistrationInfo, &PClassPlayerPawn::RegistrationInfo,
&PClassType::RegistrationInfo, &PClassType::RegistrationInfo,

View file

@ -530,7 +530,6 @@ bool P_CheckKeys (AActor *owner, int keynum, bool remote)
//========================================================================== //==========================================================================
IMPLEMENT_CLASS(AKey, false, false) IMPLEMENT_CLASS(AKey, false, false)
DEFINE_FIELD(AKey, KeyNumber) DEFINE_FIELD(AKey, KeyNumber)
//========================================================================== //==========================================================================

View file

@ -16,24 +16,4 @@ void P_DeinitKeyMessages ();
int P_GetMapColorForLock (int lock); int P_GetMapColorForLock (int lock);
int P_GetMapColorForKey (AInventory *key); 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 #endif

View file

@ -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<PClassPuzzleItem *>(newclass)->PuzzFailMessage = PuzzFailMessage;
}

View file

@ -747,6 +747,8 @@ void cht_Give (player_t *player, const char *name, int amount)
if (giveall || stricmp (name, "artifacts") == 0) if (giveall || stricmp (name, "artifacts") == 0)
{ {
auto pitype = PClass::FindActor(NAME_PuzzleItem);
for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i)
{ {
type = PClassActor::AllActorClasses[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); AInventory *def = (AInventory*)GetDefaultByType (type);
if (def->Icon.isValid() && def->MaxAmount > 1 && if (def->Icon.isValid() && def->MaxAmount > 1 &&
!type->IsDescendantOf (RUNTIME_CLASS(APuzzleItem)) && !type->IsDescendantOf (pitype) &&
!type->IsDescendantOf (RUNTIME_CLASS(APowerup)) && !type->IsDescendantOf (RUNTIME_CLASS(APowerup)) &&
!type->IsDescendantOf (RUNTIME_CLASS(AArmor))) !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) if (giveall || stricmp (name, "puzzlepieces") == 0)
{ {
auto pitype = PClass::FindActor(NAME_PuzzleItem);
for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i)
{ {
type = PClassActor::AllActorClasses[i]; type = PClassActor::AllActorClasses[i];
if (type->IsDescendantOf (RUNTIME_CLASS(APuzzleItem))) if (type->IsDescendantOf (pitype))
{ {
AInventory *def = (AInventory*)GetDefaultByType (type); AInventory *def = (AInventory*)GetDefaultByType (type);
if (def->Icon.isValid()) 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) if (takeall || stricmp (name, "artifacts") == 0)
{ {
auto pitype = PClass::FindActor(NAME_PuzzleItem);
for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i)
{ {
type = PClassActor::AllActorClasses[i]; type = PClassActor::AllActorClasses[i];
if (type->IsDescendantOf (RUNTIME_CLASS (AInventory))) 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 (APowerup)) &&
!type->IsDescendantOf (RUNTIME_CLASS (AArmor)) && !type->IsDescendantOf (RUNTIME_CLASS (AArmor)) &&
!type->IsDescendantOf (RUNTIME_CLASS (AWeapon)) && !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) if (takeall || stricmp (name, "puzzlepieces") == 0)
{ {
auto pitype = PClass::FindActor(NAME_PuzzleItem);
for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i)
{ {
type = PClassActor::AllActorClasses[i]; type = PClassActor::AllActorClasses[i];
if (type->IsDescendantOf (RUNTIME_CLASS (APuzzleItem))) if (type->IsDescendantOf (pitype))
{ {
AActor *puzzlepiece = player->mo->FindInventory(static_cast<PClassActor *>(type)); AActor *puzzlepiece = player->mo->FindInventory(static_cast<PClassActor *>(type));

View file

@ -166,6 +166,8 @@ xx(MiniMissileLauncher)
xx(StrifeGrenadeLauncher) xx(StrifeGrenadeLauncher)
xx(Mauler) xx(Mauler)
xx(BackpackItem) xx(BackpackItem)
xx(PuzzleItem)
xx(PuzzleItemNumber)
xx(AcolyteBlue) xx(AcolyteBlue)
xx(SpectralLightningV1) xx(SpectralLightningV1)

View file

@ -2138,11 +2138,12 @@ FUNC(LS_UsePuzzleItem)
if (!it) return false; if (!it) return false;
// Check player's inventory for puzzle item // Check player's inventory for puzzle item
auto pitype = PClass::FindActor(NAME_PuzzleItem);
for (item = it->Inventory; item != NULL; item = item->Inventory) for (item = it->Inventory; item != NULL; item = item->Inventory)
{ {
if (item->IsKindOf (RUNTIME_CLASS(APuzzleItem))) if (item->IsKindOf (pitype))
{ {
if (static_cast<APuzzleItem*>(item)->PuzzleItemNumber == arg0) if (item->IntVar(NAME_PuzzleItemNumber) == arg0)
{ {
if (it->UseInventory (item)) if (it->UseInventory (item))
{ {

View file

@ -1978,25 +1978,6 @@ DEFINE_CLASS_PROPERTY(autouse, I, HealthPickup)
defaults->autousemode = i; 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<PClassPuzzleItem *>(info)->PuzzFailMessage = str;
}
//========================================================================== //==========================================================================
// //
//========================================================================== //==========================================================================

View file

@ -87,10 +87,13 @@ class MapRevealer : Inventory
// //
//=========================================================================== //===========================================================================
class PuzzleItem : Inventory native class PuzzleItem : Inventory
{ {
native int PuzzleItemNumber; /*meta*/ int PuzzleItemNumber;
native meta String PuzzFailMessage; /*meta*/ String PuzzFailMessage;
property Number: PuzzleItemNumber;
property FailMessage: PuzzFailMessage;
Default Default
{ {
@ -99,7 +102,7 @@ class PuzzleItem : Inventory native
Inventory.DefMaxAmount; Inventory.DefMaxAmount;
Inventory.UseSound "PuzzleSuccess"; Inventory.UseSound "PuzzleSuccess";
Inventory.PickupSound "misc/i_pkup"; Inventory.PickupSound "misc/i_pkup";
PuzzleItem.FailMessage("TXT_USEPUZZLEFAILED"); PuzzleItem.FailMessage("$TXT_USEPUZZLEFAILED");
} }
override bool HandlePickup (Inventory item) override bool HandlePickup (Inventory item)