2017-04-17 10:27:19 +00:00
|
|
|
/*
|
|
|
|
** a_pickups.cpp
|
|
|
|
** Inventory base class implementation
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2005-2016 Randy Heit
|
|
|
|
** Copyright 2005-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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "info.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "statnums.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "gstrings.h"
|
|
|
|
#include "a_morph.h"
|
|
|
|
#include "a_specialspot.h"
|
|
|
|
#include "g_game.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "d_player.h"
|
2016-09-19 10:53:42 +00:00
|
|
|
#include "serializer.h"
|
2017-04-12 23:12:04 +00:00
|
|
|
#include "vm.h"
|
2016-12-13 23:47:56 +00:00
|
|
|
#include "c_functions.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-11-30 11:24:50 +00:00
|
|
|
EXTERN_CVAR(Bool, sv_unlimited_pickup)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(AInventory, false, true)
|
2016-11-05 16:08:54 +00:00
|
|
|
|
|
|
|
IMPLEMENT_POINTERS_START(AInventory)
|
2017-01-19 19:56:31 +00:00
|
|
|
IMPLEMENT_POINTER(Owner)
|
2016-11-05 16:08:54 +00:00
|
|
|
IMPLEMENT_POINTERS_END
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-11-23 00:31:48 +00:00
|
|
|
DEFINE_FIELD_BIT(AInventory, ItemFlags, bPickupGood, IF_PICKUPGOOD)
|
|
|
|
DEFINE_FIELD_BIT(AInventory, ItemFlags, bCreateCopyMoved, IF_CREATECOPYMOVED)
|
|
|
|
DEFINE_FIELD_BIT(AInventory, ItemFlags, bInitEffectFailed, IF_INITEFFECTFAILED)
|
2017-01-19 19:56:31 +00:00
|
|
|
DEFINE_FIELD(AInventory, Owner)
|
2016-11-23 00:31:48 +00:00
|
|
|
DEFINE_FIELD(AInventory, Amount)
|
|
|
|
DEFINE_FIELD(AInventory, MaxAmount)
|
|
|
|
DEFINE_FIELD(AInventory, InterHubAmount)
|
|
|
|
DEFINE_FIELD(AInventory, RespawnTics)
|
|
|
|
DEFINE_FIELD(AInventory, Icon)
|
2018-03-18 09:02:21 +00:00
|
|
|
DEFINE_FIELD(AInventory, AltHUDIcon)
|
2016-11-23 00:31:48 +00:00
|
|
|
DEFINE_FIELD(AInventory, DropTime)
|
|
|
|
DEFINE_FIELD(AInventory, SpawnPointClass)
|
|
|
|
DEFINE_FIELD(AInventory, PickupFlash)
|
|
|
|
DEFINE_FIELD(AInventory, PickupSound)
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AInventory :: Tick
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void AInventory::Tick ()
|
|
|
|
{
|
|
|
|
if (Owner == NULL)
|
|
|
|
{
|
|
|
|
// AActor::Tick is only handling interaction with the world
|
|
|
|
// and we don't want that for owned inventory items.
|
|
|
|
Super::Tick ();
|
|
|
|
}
|
|
|
|
else if (tics != -1) // ... but at least we have to advance the states
|
|
|
|
{
|
|
|
|
tics--;
|
|
|
|
|
|
|
|
// you can cycle through multiple states in a tic
|
|
|
|
// [RH] Use <= 0 instead of == 0 so that spawnstates
|
|
|
|
// of 0 tics work as expected.
|
|
|
|
if (tics <= 0)
|
|
|
|
{
|
|
|
|
assert (state != NULL);
|
|
|
|
if (state == NULL)
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!SetState (state->GetNextState()))
|
|
|
|
return; // freed itself
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (DropTime)
|
|
|
|
{
|
|
|
|
if (--DropTime == 0)
|
|
|
|
{
|
|
|
|
flags |= GetDefault()->flags & (MF_SPECIAL|MF_SOLID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AInventory :: Serialize
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2016-09-19 10:53:42 +00:00
|
|
|
void AInventory::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 10:53:42 +00:00
|
|
|
|
|
|
|
auto def = (AInventory*)GetDefault();
|
|
|
|
arc("owner", Owner)
|
|
|
|
("amount", Amount, def->Amount)
|
|
|
|
("maxamount", MaxAmount, def->MaxAmount)
|
|
|
|
("interhubamount", InterHubAmount, def->InterHubAmount)
|
|
|
|
("respawntics", RespawnTics, def->RespawnTics)
|
|
|
|
("itemflags", ItemFlags, def->ItemFlags)
|
|
|
|
("icon", Icon, def->Icon)
|
2018-03-18 09:02:21 +00:00
|
|
|
("althudicon", AltHUDIcon, def->AltHUDIcon)
|
2016-09-19 10:53:42 +00:00
|
|
|
("pickupsound", PickupSound, def->PickupSound)
|
|
|
|
("spawnpointclass", SpawnPointClass, def->SpawnPointClass)
|
2017-02-27 23:45:16 +00:00
|
|
|
("droptime", DropTime, def->DropTime);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2017-01-19 19:56:31 +00:00
|
|
|
static int StaticLastMessageTic;
|
|
|
|
static FString StaticLastMessage;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-01-19 19:56:31 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AInventory, PrintPickupMessage)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-19 19:56:31 +00:00
|
|
|
PARAM_PROLOGUE;
|
|
|
|
PARAM_BOOL(localview);
|
|
|
|
PARAM_STRING(str);
|
|
|
|
if (str.IsNotEmpty() && localview && (StaticLastMessageTic != gametic || StaticLastMessage.Compare(str)))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-19 19:56:31 +00:00
|
|
|
StaticLastMessageTic = gametic;
|
|
|
|
StaticLastMessage = str;
|
|
|
|
const char *pstr = str.GetChars();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-01-19 19:56:31 +00:00
|
|
|
if (pstr[0] == '$') pstr = GStrings(pstr + 1);
|
|
|
|
if (pstr[0] != 0) Printf(PRINT_LOW, "%s\n", pstr);
|
|
|
|
StatusBar->FlashCrosshair();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2017-01-19 19:56:31 +00:00
|
|
|
return 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AInventory :: DepleteOrDestroy
|
|
|
|
//
|
|
|
|
// If the item is depleted, just change its amount to 0, otherwise it's destroyed.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void AInventory::DepleteOrDestroy ()
|
|
|
|
{
|
2017-01-18 22:42:08 +00:00
|
|
|
IFVIRTUAL(AInventory, DepleteOrDestroy)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-18 22:42:08 +00:00
|
|
|
VMValue params[1] = { (DObject*)this };
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, 1, nullptr, 0);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AInventory :: PrevInv
|
|
|
|
//
|
|
|
|
// Returns the previous item with IF_INVBAR set.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
AInventory *AInventory::PrevInv ()
|
|
|
|
{
|
|
|
|
AInventory *lastgood = NULL;
|
|
|
|
AInventory *item = Owner->Inventory;
|
|
|
|
|
|
|
|
while (item != NULL && item != this)
|
|
|
|
{
|
|
|
|
if (item->ItemFlags & IF_INVBAR)
|
|
|
|
{
|
|
|
|
lastgood = item;
|
|
|
|
}
|
|
|
|
item = item->Inventory;
|
|
|
|
}
|
|
|
|
return lastgood;
|
|
|
|
}
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AInventory :: NextInv
|
|
|
|
//
|
|
|
|
// Returns the next item with IF_INVBAR set.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
AInventory *AInventory::NextInv ()
|
|
|
|
{
|
|
|
|
AInventory *item = Inventory;
|
|
|
|
|
|
|
|
while (item != NULL && !(item->ItemFlags & IF_INVBAR))
|
|
|
|
{
|
|
|
|
item = item->Inventory;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
2017-01-19 22:42:12 +00:00
|
|
|
// AInventory :: CallTryPickup
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2018-11-29 23:06:20 +00:00
|
|
|
bool CallTryPickup(AInventory *item, AActor *toucher, AActor **toucher_return)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-19 22:42:12 +00:00
|
|
|
static VMFunction *func = nullptr;
|
2017-01-31 12:41:23 +00:00
|
|
|
if (func == nullptr) PClass::FindFunction(&func, NAME_Inventory, NAME_CallTryPickup);
|
2018-11-29 23:06:20 +00:00
|
|
|
VMValue params[2] = { (DObject*)item, toucher };
|
2017-01-19 22:42:12 +00:00
|
|
|
VMReturn ret[2];
|
|
|
|
int res;
|
|
|
|
AActor *tret;
|
|
|
|
ret[0].IntAt(&res);
|
|
|
|
ret[1].PointerAt((void**)&tret);
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, 2, ret, 2);
|
2017-01-19 22:42:12 +00:00
|
|
|
if (toucher_return) *toucher_return = tret;
|
|
|
|
return !!res;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// CCMD printinv
|
|
|
|
//
|
|
|
|
// Prints the console player's current inventory.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
CCMD (printinv)
|
|
|
|
{
|
|
|
|
int pnum = consoleplayer;
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
// Only allow peeking on other players' inventory in debug builds.
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
pnum = atoi (argv[1]);
|
|
|
|
if (pnum < 0 || pnum >= MAXPLAYERS)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2016-12-13 23:47:56 +00:00
|
|
|
C_PrintInv(players[pnum].mo);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:22:50 +00:00
|
|
|
CCMD (targetinv)
|
|
|
|
{
|
|
|
|
FTranslatedLineTarget t;
|
|
|
|
|
|
|
|
if (CheckCheatmode () || players[consoleplayer].mo == NULL)
|
|
|
|
return;
|
|
|
|
|
2016-12-13 23:47:56 +00:00
|
|
|
C_AimLine(&t, true);
|
2016-12-11 23:22:50 +00:00
|
|
|
|
|
|
|
if (t.linetarget)
|
|
|
|
{
|
2016-12-13 23:47:56 +00:00
|
|
|
C_PrintInv(t.linetarget);
|
2016-12-11 23:22:50 +00:00
|
|
|
}
|
|
|
|
else Printf("No target found. Targetinv cannot find actors that have "
|
|
|
|
"the NOBLOCKMAP flag or have height/radius of 0.\n");
|
|
|
|
}
|
|
|
|
|