mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-07 09:50:45 +00:00
167 lines
4.8 KiB
C++
167 lines
4.8 KiB
C++
/*
|
|
** 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.
|
|
**---------------------------------------------------------------------------
|
|
**
|
|
*/
|
|
|
|
#include <assert.h>
|
|
|
|
#include "info.h"
|
|
#include "m_random.h"
|
|
#include "p_local.h"
|
|
#include "s_sound.h"
|
|
#include "gi.h"
|
|
#include "p_lnspec.h"
|
|
#include "sbar.h"
|
|
#include "statnums.h"
|
|
#include "c_dispatch.h"
|
|
#include "gstrings.h"
|
|
#include "templates.h"
|
|
#include "a_morph.h"
|
|
#include "a_specialspot.h"
|
|
#include "g_level.h"
|
|
#include "g_game.h"
|
|
#include "doomstat.h"
|
|
#include "d_player.h"
|
|
#include "p_spec.h"
|
|
#include "serializer.h"
|
|
#include "vm.h"
|
|
#include "c_functions.h"
|
|
#include "g_levellocals.h"
|
|
#include "vm.h"
|
|
|
|
EXTERN_CVAR(Bool, sv_unlimited_pickup)
|
|
|
|
|
|
//===========================================================================
|
|
//
|
|
// This is only native so it can have some static storage for comparison.
|
|
//
|
|
//===========================================================================
|
|
static int StaticLastMessageTic;
|
|
static FString StaticLastMessage;
|
|
|
|
void PrintPickupMessage(bool localview, const FString &str)
|
|
{
|
|
if (str.IsNotEmpty() && localview && (StaticLastMessageTic != gametic || StaticLastMessage.Compare(str)))
|
|
{
|
|
StaticLastMessageTic = gametic;
|
|
StaticLastMessage = str;
|
|
const char *pstr = str.GetChars();
|
|
|
|
if (pstr[0] == '$') pstr = GStrings(pstr + 1);
|
|
if (pstr[0] != 0) Printf(PRINT_LOW, "%s\n", pstr);
|
|
StatusBar->FlashCrosshair();
|
|
}
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// AInventory :: DepleteOrDestroy
|
|
//
|
|
// If the item is depleted, just change its amount to 0, otherwise it's destroyed.
|
|
//
|
|
//===========================================================================
|
|
|
|
void DepleteOrDestroy (AActor *item)
|
|
{
|
|
IFVIRTUALPTRNAME(item, NAME_Inventory, DepleteOrDestroy)
|
|
{
|
|
VMValue params[1] = { item };
|
|
VMCall(func, params, 1, nullptr, 0);
|
|
}
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// AInventory :: CallTryPickup
|
|
//
|
|
//===========================================================================
|
|
|
|
bool CallTryPickup(AActor *item, AActor *toucher, AActor **toucher_return)
|
|
{
|
|
static VMFunction *func = nullptr;
|
|
if (func == nullptr) PClass::FindFunction(&func, NAME_Inventory, NAME_CallTryPickup);
|
|
VMValue params[2] = { (DObject*)item, toucher };
|
|
VMReturn ret[2];
|
|
int res;
|
|
AActor *tret;
|
|
ret[0].IntAt(&res);
|
|
ret[1].PointerAt((void**)&tret);
|
|
VMCall(func, params, 2, ret, 2);
|
|
if (toucher_return) *toucher_return = tret;
|
|
return !!res;
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// 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
|
|
C_PrintInv(players[pnum].mo);
|
|
}
|
|
|
|
CCMD (targetinv)
|
|
{
|
|
FTranslatedLineTarget t;
|
|
|
|
if (CheckCheatmode () || players[consoleplayer].mo == NULL)
|
|
return;
|
|
|
|
C_AimLine(&t, true);
|
|
|
|
if (t.linetarget)
|
|
{
|
|
C_PrintInv(t.linetarget);
|
|
}
|
|
else Printf("No target found. Targetinv cannot find actors that have "
|
|
"the NOBLOCKMAP flag or have height/radius of 0.\n");
|
|
}
|
|
|