diff --git a/src/g_shared/a_specialspot.cpp b/src/g_shared/a_specialspot.cpp index dd65014f4..163f1a25c 100644 --- a/src/g_shared/a_specialspot.cpp +++ b/src/g_shared/a_specialspot.cpp @@ -40,7 +40,6 @@ #include "vm.h" static FRandom pr_spot ("SpecialSpot"); -static FRandom pr_spawnmace ("SpawnMace"); IMPLEMENT_CLASS(DSpotState, 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++) { - if (Spots[i] == spot) + if (Spots[i] == spot) { Spots.Delete(i); 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); 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(spawned)->SpawnPointClass = self->GetClass(); - } - } - return 0; -} - diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index b56a60a54..391ae38a6 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -1601,7 +1601,7 @@ class PlayerPawn : Actor native // // 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 // away or the player picks up some ammo they had previously run out of. // diff --git a/wadsrc/static/zscript/shared/specialspot.txt b/wadsrc/static/zscript/shared/specialspot.txt index c0bf84de5..baacd286f 100644 --- a/wadsrc/static/zscript/shared/specialspot.txt +++ b/wadsrc/static/zscript/shared/specialspot.txt @@ -1,5 +1,59 @@ class SpecialSpot : Actor native { - native void A_SpawnSingleItem(class 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 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(); + } + } + } + + }