From 93ca8502dd5ac32bb271a435c7cd3e929706d450 Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Wed, 17 Dec 2014 21:47:00 -0600 Subject: [PATCH] - Rewrote a bunch of things for stability. --- src/actor.h | 4 +- src/p_acs.cpp | 81 +++++++++++++++++++++++++++- src/p_mobj.cpp | 6 ++- src/p_teleport.cpp | 6 +-- src/thingdef/thingdef_codeptr.cpp | 27 ++++++++-- src/thingdef/thingdef_properties.cpp | 8 +-- src/version.h | 2 +- 7 files changed, 117 insertions(+), 17 deletions(-) diff --git a/src/actor.h b/src/actor.h index 592dca47c..57736f43b 100644 --- a/src/actor.h +++ b/src/actor.h @@ -983,8 +983,8 @@ public: FNameNoInit PainType; FNameNoInit DeathType; - FNameNoInit TeleFogSourceType; - FNameNoInit TeleFogDestType; + const PClass *TeleFogSourceType; + const PClass *TeleFogDestType; FState *SpawnState; FState *SeeState; diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 866087688..54a7110a1 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4438,6 +4438,8 @@ enum EACSFunctions ACSF_PickActor, ACSF_IsPointerEqual, ACSF_CanRaiseActor, + ACSF_SetActorTeleFog, // 86 + ACSF_SwapActorTeleFog, /* Zandronum's - these must be skipped when we reach 99! -100:ResetMap(0), @@ -4749,6 +4751,72 @@ static void SetActorPitch(AActor *activator, int tid, int angle, bool interpolat } } +static void SetActorTeleFog(AActor *activator, int tid, FName telefogsrc, FName telefogdest) +{ + //Simply put, if it doesn't exist, it won't change. One can use "" in this scenario. + const PClass *check; + if (tid == 0) + { + if (activator != NULL) + { + check = PClass::FindClass(telefogsrc); + if (check != NULL) + activator->TeleFogSourceType = check; + check = PClass::FindClass(telefogdest); + if (check != NULL) + activator->TeleFogDestType = check; + } + } + else + { + FActorIterator iterator(tid); + AActor *actor; + + while ((actor = iterator.Next())) + { + check = PClass::FindClass(telefogsrc); + if (check != NULL) + activator->TeleFogSourceType = check; + check = PClass::FindClass(telefogdest); + if (check != NULL) + activator->TeleFogDestType = check; + } + } +} + +static int SwapActorTeleFog(AActor *activator, int tid) +{ + int count = 0; + if (tid == 0) + { + if ((activator == NULL) || (activator->TeleFogSourceType = activator->TeleFogDestType)) + return 0; //Does nothing if they're the same. + else + { + const PClass *temp = activator->TeleFogSourceType; + activator->TeleFogSourceType = activator->TeleFogDestType; + activator->TeleFogDestType = temp; + return 1; + } + } + else + { + FActorIterator iterator(tid); + AActor *actor; + + while ((actor = iterator.Next())) + { + if (activator->TeleFogSourceType == activator->TeleFogDestType) + continue; //They're the same. Save the effort. + const PClass *temp = activator->TeleFogSourceType; + activator->TeleFogSourceType = activator->TeleFogDestType; + activator->TeleFogDestType = temp; + count++; + } + } + return count; +} + int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args, const SDWORD *stack, int stackdepth) @@ -5662,7 +5730,18 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) SetActorPitch(activator, args[0], args[1], argCount > 2 ? !!args[2] : false); } break; - + case ACSF_SetActorTeleFog: + if (argCount >= 3) + { + SetActorTeleFog(activator, args[0], FBehavior::StaticLookupString(args[1]), FBehavior::StaticLookupString(args[2])); + } + break; + case ACSF_SwapActorTeleFog: + if (argCount >= 1) + { + return SwapActorTeleFog(activator, args[0]); + } + break; case ACSF_PickActor: if (argCount >= 5) { diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 21078b3ec..e1eed19c1 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -333,7 +333,11 @@ void AActor::Serialize (FArchive &arc) { arc << FriendPlayer; } - + if (SaveVersion >= 4518) + { + arc << TeleFogSourceType + << TeleFogDestType; + } { FString tagstr; if (arc.IsStoring() && Tag != NULL && Tag->Len() > 0) tagstr = *Tag; diff --git a/src/p_teleport.cpp b/src/p_teleport.cpp index 4b728b115..a73ff75e7 100644 --- a/src/p_teleport.cpp +++ b/src/p_teleport.cpp @@ -77,15 +77,13 @@ void ATeleportFog::PostBeginPlay () void P_SpawnTeleportFog(AActor *mobj, fixed_t x, fixed_t y, fixed_t z, bool beforeTele, bool setTarget) { AActor *mo; - FNameNoInit tf = (beforeTele ? mobj->TeleFogSourceType : mobj->TeleFogDestType); - - if (!tf) //If the actor doesn't have one, initialize the original. + if ((beforeTele ? mobj->TeleFogSourceType : mobj->TeleFogDestType) == NULL) //If the actor doesn't have one, initialize the original. { mo = Spawn(x, y, z, ALLOW_REPLACE); } else { - mo = Spawn(tf, x, y, z, ALLOW_REPLACE); + mo = Spawn((beforeTele ? mobj->TeleFogSourceType : mobj->TeleFogDestType), x, y, z, ALLOW_REPLACE); } if (mo != NULL && setTarget) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 2f6b74e90..aa643de8c 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -5385,6 +5385,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Remove) // // Sets the teleport fog(s) for the calling actor. // Takes a name of the classes for te source and destination. +// Can set both at the same time. Use "" to retain the previous fog without +// changing it. //=========================================================================== DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetTeleFog) @@ -5392,11 +5394,28 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetTeleFog) ACTION_PARAM_START(2); ACTION_PARAM_NAME(oldpos, 0); ACTION_PARAM_NAME(newpos, 1); + const PClass *check = PClass::FindClass(oldpos); + if (check != NULL) + self->TeleFogSourceType = check; - if (oldpos) - self->TeleFogSourceType = oldpos; - if (newpos) - self->TeleFogDestType = newpos; + check = PClass::FindClass(newpos); + if (check != NULL) + self->TeleFogDestType = check; } +//=========================================================================== +// +// A_SwapTeleFog +// +// Switches the source and dest telefogs around. +//=========================================================================== +DEFINE_ACTION_FUNCTION(AActor, A_SwapTeleFog) +{ + if ((self->TeleFogSourceType != self->TeleFogDestType)) //Does nothing if they're the same. + { + const PClass *temp = self->TeleFogSourceType; + self->TeleFogSourceType = self->TeleFogDestType; + self->TeleFogDestType = temp; + } +} diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 22612fa78..0c4ec25cb 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -1422,8 +1422,8 @@ DEFINE_PROPERTY(stamina, I, Actor) DEFINE_PROPERTY(telefogsourcetype, S, Actor) { PROP_STRING_PARM(str, 0); - if (str == NULL || *str == 0 || (!stricmp(str,""))) defaults->TeleFogSourceType = "TeleportFog"; - else defaults->TeleFogSourceType = str; + if (!stricmp(str,"") || *str == 0) defaults->TeleFogSourceType = PClass::FindClass("TeleportFog"); + else defaults->TeleFogSourceType = FindClassTentative(str,"TeleportFog"); } //========================================================================== @@ -1432,8 +1432,8 @@ DEFINE_PROPERTY(telefogsourcetype, S, Actor) DEFINE_PROPERTY(telefogdesttype, S, Actor) { PROP_STRING_PARM(str, 0); - if (str == NULL || *str == 0 || (!stricmp(str, ""))) defaults->TeleFogDestType = "TeleportFog"; - else defaults->TeleFogDestType = str; + if (!stricmp(str, "") || *str == 0) defaults->TeleFogDestType = PClass::FindClass("TeleportFog"); + else defaults->TeleFogDestType = FindClassTentative(str, "TeleportFog"); } //========================================================================== diff --git a/src/version.h b/src/version.h index 15d01d315..09b830438 100644 --- a/src/version.h +++ b/src/version.h @@ -76,7 +76,7 @@ const char *GetVersionString(); // Use 4500 as the base git save version, since it's higher than the // SVN revision ever got. -#define SAVEVER 4516 +#define SAVEVER 4518 #define SAVEVERSTRINGIFY2(x) #x #define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x)