mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-02-07 08:21:04 +00:00
- scriptified A_SpawnSingleItem, which was the last piece of native code still referencing AInventory
This commit is contained in:
parent
2459b27895
commit
d66516ec82
3 changed files with 77 additions and 84 deletions
|
@ -40,7 +40,6 @@
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
|
|
||||||
static FRandom pr_spot ("SpecialSpot");
|
static FRandom pr_spot ("SpecialSpot");
|
||||||
static FRandom pr_spawnmace ("SpawnMace");
|
|
||||||
|
|
||||||
IMPLEMENT_CLASS(DSpotState, false, false)
|
IMPLEMENT_CLASS(DSpotState, false, false)
|
||||||
IMPLEMENT_CLASS(ASpecialSpot, false, false)
|
IMPLEMENT_CLASS(ASpecialSpot, false, false)
|
||||||
|
@ -74,7 +73,7 @@ struct FSpotList
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ struct FSpotList
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ struct FSpotList
|
||||||
{
|
{
|
||||||
for(unsigned i = 0; i < Spots.Size(); i++)
|
for(unsigned i = 0; i < Spots.Size(); i++)
|
||||||
{
|
{
|
||||||
if (Spots[i] == spot)
|
if (Spots[i] == spot)
|
||||||
{
|
{
|
||||||
Spots.Delete(i);
|
Spots.Delete(i);
|
||||||
if (Index > i) Index--;
|
if (Index > i) Index--;
|
||||||
|
@ -110,7 +109,7 @@ struct FSpotList
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -130,7 +129,7 @@ struct FSpotList
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -157,7 +156,7 @@ struct FSpotList
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -175,7 +174,7 @@ struct FSpotList
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -195,7 +194,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSpotList &list, FSpot
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -214,7 +213,7 @@ DSpotState::DSpotState ()
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -229,17 +228,17 @@ void DSpotState::OnDestroy ()
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
void DSpotState::Tick ()
|
void DSpotState::Tick ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -257,7 +256,7 @@ DEFINE_ACTION_FUNCTION(DSpotState, GetSpotState)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -273,7 +272,7 @@ FSpotList *DSpotState::FindSpotList(PClassActor *type)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -286,7 +285,7 @@ bool DSpotState::AddSpot(ASpecialSpot *spot)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -299,7 +298,7 @@ bool DSpotState::RemoveSpot(ASpecialSpot *spot)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -311,7 +310,7 @@ void DSpotState::Serialize(FSerializer &arc)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -332,7 +331,7 @@ DEFINE_ACTION_FUNCTION(DSpotState, GetNextInList)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -357,7 +356,7 @@ DEFINE_ACTION_FUNCTION(DSpotState, GetSpotWithMinMaxDistance)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -378,7 +377,7 @@ DEFINE_ACTION_FUNCTION(DSpotState, GetRandomSpot)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -390,7 +389,7 @@ void ASpecialSpot::BeginPlay()
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -400,63 +399,3 @@ void ASpecialSpot::OnDestroy()
|
||||||
if (state != NULL) state->RemoveSpot(this);
|
if (state != NULL) state->RemoveSpot(this);
|
||||||
Super::OnDestroy();
|
Super::OnDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mace spawn spot ----------------------------------------------------------
|
|
||||||
|
|
||||||
// Every mace spawn spot will execute this action. The first one
|
|
||||||
// will build a list of all mace spots in the level and spawn a
|
|
||||||
// mace. The rest of the spots will do nothing.
|
|
||||||
|
|
||||||
DEFINE_ACTION_FUNCTION(ASpecialSpot, A_SpawnSingleItem)
|
|
||||||
{
|
|
||||||
PARAM_SELF_PROLOGUE(ASpecialSpot);
|
|
||||||
PARAM_CLASS_NOT_NULL(cls, AActor);
|
|
||||||
PARAM_INT (fail_sp)
|
|
||||||
PARAM_INT (fail_co)
|
|
||||||
PARAM_INT (fail_dm)
|
|
||||||
|
|
||||||
AActor *spot = NULL;
|
|
||||||
DSpotState *state = DSpotState::GetSpotState();
|
|
||||||
|
|
||||||
if (state != NULL) spot = state->GetRandomSpot(self->GetClass(), true);
|
|
||||||
if (spot == NULL) return 0;
|
|
||||||
|
|
||||||
if (!multiplayer && pr_spawnmace() < fail_sp)
|
|
||||||
{ // Sometimes doesn't show up if not in deathmatch
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (multiplayer && !deathmatch && pr_spawnmace() < fail_co)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deathmatch && pr_spawnmace() < fail_dm)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cls == NULL)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
AActor *spawned = Spawn(cls, self->Pos(), ALLOW_REPLACE);
|
|
||||||
|
|
||||||
if (spawned)
|
|
||||||
{
|
|
||||||
spawned->SetOrigin (spot->Pos(), false);
|
|
||||||
spawned->SetZ(spawned->floorz);
|
|
||||||
// We want this to respawn.
|
|
||||||
if (!(self->flags & MF_DROPPED))
|
|
||||||
{
|
|
||||||
spawned->flags &= ~MF_DROPPED;
|
|
||||||
}
|
|
||||||
if (spawned->IsKindOf(NAME_Inventory))
|
|
||||||
{
|
|
||||||
static_cast<AInventory*>(spawned)->SpawnPointClass = self->GetClass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1601,7 +1601,7 @@ class PlayerPawn : Actor native
|
||||||
//
|
//
|
||||||
// APlayerPawn :: PickNewWeapon
|
// APlayerPawn :: PickNewWeapon
|
||||||
//
|
//
|
||||||
// Picks a new weapon for self player. Used mostly for running out of ammo,
|
// Picks a new weapon for this player. Used mostly for running out of ammo,
|
||||||
// but it also works when an ACS script explicitly takes the ready weapon
|
// but it also works when an ACS script explicitly takes the ready weapon
|
||||||
// away or the player picks up some ammo they had previously run out of.
|
// away or the player picks up some ammo they had previously run out of.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,5 +1,59 @@
|
||||||
|
|
||||||
class SpecialSpot : Actor native
|
class SpecialSpot : Actor native
|
||||||
{
|
{
|
||||||
native void A_SpawnSingleItem(class<Actor> type, int fail_sp = 0, int fail_co = 0, int fail_dm = 0);
|
// Mace spawn spot ----------------------------------------------------------
|
||||||
|
|
||||||
|
// Every mace spawn spot will execute this action. The first one
|
||||||
|
// will build a list of all mace spots in the level and spawn a
|
||||||
|
// mace. The rest of the spots will do nothing.
|
||||||
|
|
||||||
|
void A_SpawnSingleItem(class<Actor> cls, int fail_sp = 0, int fail_co = 0, int fail_dm = 0)
|
||||||
|
{
|
||||||
|
Actor spot = NULL;
|
||||||
|
let state = SpotState.GetSpotState();
|
||||||
|
|
||||||
|
if (state != NULL) spot = state.GetRandomSpot(GetClass(), true);
|
||||||
|
if (spot == NULL) return;
|
||||||
|
|
||||||
|
if (!multiplayer && random[SpawnMace]() < fail_sp)
|
||||||
|
{ // Sometimes doesn't show up if not in deathmatch
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (multiplayer && !deathmatch && random[SpawnMace]() < fail_co)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deathmatch && random[SpawnMace]() < fail_dm)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cls == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let spawned = Spawn(cls, self.Pos, ALLOW_REPLACE);
|
||||||
|
|
||||||
|
if (spawned)
|
||||||
|
{
|
||||||
|
// Setting z in two steps is necessary to proper initialize floorz before using it.
|
||||||
|
spawned.SetOrigin (spot.Pos, false);
|
||||||
|
spawned.SetZ(spawned.floorz);
|
||||||
|
// We want this to respawn.
|
||||||
|
if (!bDropped)
|
||||||
|
{
|
||||||
|
spawned.bDropped = false;
|
||||||
|
}
|
||||||
|
let inv = Inventory(spawned);
|
||||||
|
if (inv)
|
||||||
|
{
|
||||||
|
inv.SpawnPointClass = GetClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue