// good
return 1;
}
- backtrace("WARNING: when adding mutator: adding failed\n");
- Mutator_Remove(func, name);
+
+ backtrace("WARNING: when adding mutator: adding failed, rolling back\n");
+
+ if(func(MUTATOR_ROLLING_BACK) != 0)
+ {
+ // baaaaad
+ error("WARNING: when adding mutator: rolling back failed");
+ }
return 0;
}
void Mutator_Remove(float(float) func, string name)
#define MUTATOR_REMOVING 0
#define MUTATOR_ADDING 1
+#define MUTATOR_ROLLING_BACK 2
typedef float(float) mutatorfunc_t;
float Mutator_Add(mutatorfunc_t func, string name);
void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
#define MUTATOR_DEFINITION(name) float MUTATOR_##name(float mode)
#define MUTATOR_DECLARATION(name) float MUTATOR_##name(float mode)
#define MUTATOR_HOOKFUNCTION(name) float HOOKFUNCTION_##name()
-#define MUTATOR_HOOK(cb,func,order) do { if(mode == MUTATOR_ADDING) { if(!HOOK_##cb) HOOK_##cb = CallbackChain_New(#cb); if(!CallbackChain_Add(HOOK_##cb,HOOKFUNCTION_##func,order)) { print("HOOK FAILED: ", #func, "\n"); return 1; } } else if(mode == MUTATOR_REMOVING) { if(HOOK_##cb) CallbackChain_Remove(HOOK_##cb,HOOKFUNCTION_##func); } } while(0)
+#define MUTATOR_HOOK(cb,func,order) do { if(mode == MUTATOR_ADDING) { if(!HOOK_##cb) HOOK_##cb = CallbackChain_New(#cb); if(!CallbackChain_Add(HOOK_##cb,HOOKFUNCTION_##func,order)) { print("HOOK FAILED: ", #func, "\n"); return 1; } } else if(mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK) { if(HOOK_##cb) CallbackChain_Remove(HOOK_##cb,HOOKFUNCTION_##func); } } while(0)
#define MUTATOR_ONADD if(mode == MUTATOR_ADDING)
#define MUTATOR_ONREMOVE if(mode == MUTATOR_REMOVING)
+#define MUTATOR_ONROLLBACK_OR_REMOVE if(mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
#define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
#define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
ctf_Initialize();
}
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ // we actually cannot roll back ctf_Initialize here
+ // BUT: we don't need to! If this gets called, adding always
+ // succeeds.
+ }
+
MUTATOR_ONREMOVE
{
- error("This is a game type and it cannot be removed at runtime.");
+ print("This is a game type and it cannot be removed at runtime.");
+ return -1;
}
return 0;
freezetag_Initialize();
}
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ // we actually cannot roll back freezetag_Initialize here
+ // BUT: we don't need to! If this gets called, adding always
+ // succeeds.
+ }
+
MUTATOR_ONREMOVE
{
- error("This is a game type and it cannot be removed at runtime.");
+ print("This is a game type and it cannot be removed at runtime.");
+ return -1;
}
return 0;
ka_Initialize();
}
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ // we actually cannot roll back ka_Initialize here
+ // BUT: we don't need to! If this gets called, adding always
+ // succeeds.
+ }
+
MUTATOR_ONREMOVE
{
- error("This is a game type and it cannot be removed at runtime.");
+ print("This is a game type and it cannot be removed at runtime.");
+ return -1;
}
return 0;
kh_Initialize();
}
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ // we actually cannot roll back kh_Initialize here
+ // BUT: we don't need to! If this gets called, adding always
+ // succeeds.
+ }
+
MUTATOR_ONREMOVE
{
- error("This is a game type and it cannot be removed at runtime.");
+ print("This is a game type and it cannot be removed at runtime.");
+ return -1;
}
return 0;
InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
}
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ // we actually cannot roll back nb_delayedinit here
+ // BUT: we don't need to! If this gets called, adding always
+ // succeeds.
+ }
+
+ MUTATOR_ONREMOVE
+ {
+ print("This is a game type and it cannot be removed at runtime.");
+ return -1;
+ }
+
return 0;
}
MUTATOR_ONADD
{
- //InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
+ if(time > 1) // game loads at time 1
+ error("This is a game type and it cannot be added at runtime.");
+ }
+
+ MUTATOR_ONREMOVE
+ {
+ print("This is a game type and it cannot be removed at runtime.");
+ return -1;
}
return 0;
// the jump part of the dodge cannot be ramped
.float dodging_single_action;
-void dodging_Initialize() {
- // print("dodging_Initialize\n");
-
- self.last_FORWARD_KEY_time = 0;
- self.last_BACKWARD_KEY_time = 0;
- self.last_RIGHT_KEY_time = 0;
- self.last_LEFT_KEY_time = 0;
- self.last_dodging_time = 0;
- self.dodging_action = 0;
- self.dodging_velocity_gain = 0;
- self.dodging_single_action = 0;
- self.dodging_direction_x = 0;
- self.dodging_direction_y = 0;
-}
-
MUTATOR_HOOKFUNCTION(dodging_GetCvars) {
GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_dodging_timeout, "cl_dodging_timeout");
return 0;
MUTATOR_ONADD
{
g_dodging = 1;
- dodging_Initialize();
}
// this just turns off the cvar.
- MUTATOR_ONREMOVE
- {
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
g_dodging = 0;
}
+ MUTATOR_ONREMOVE
+ {
+ }
+
return 0;
}
if(nt_IsNewToy(i))
get_weaponinfo(i).spawnflags &~= WEP_FLAG_MUTATORBLOCKED;
}
+
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ float i;
+ for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+ if(nt_IsNewToy(i))
+ get_weaponinfo(i).spawnflags |= WEP_FLAG_MUTATORBLOCKED;
+ }
+
MUTATOR_ONREMOVE
{
- error("This cannot be removed at runtime\n");
+ print("This cannot be removed at runtime\n");
+ return -1;
}
return 0;
NIX_precache();
}
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ // nothing to roll back
+ }
+
MUTATOR_ONREMOVE
{
// as the PlayerSpawn hook will no longer run, NIX is turned off by this!
MUTATOR_DEFINITION(mutator_physical_items)
{
+ MUTATOR_HOOK(Item_Spawn, item_spawning, CBC_ORDER_ANY);
+
// check if we have a physics engine
- if not(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE"))
+ MUTATOR_ONADD
{
- dprint("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items.\n");
- return FALSE;
+ if not(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE"))
+ {
+ dprint("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items.\n");
+ return -1;
+ }
}
- MUTATOR_HOOK(Item_Spawn, item_spawning, CBC_ORDER_ANY);
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ // nothing to roll back
+ }
- return FALSE;
+ MUTATOR_ONREMOVE
+ {
+ print("This cannot be removed at runtime\n");
+ return -1;
+ }
+
+ return 0;
}
//MUTATOR_HOOK(MakePlayerObserver, superspec_MakePlayerObserver, CBC_ORDER_ANY);
MUTATOR_HOOK(ClientDisconnect, superspec_ClientDisconnect, CBC_ORDER_ANY);
- MUTATOR_ONADD
- {
- }
-
- MUTATOR_ONREMOVE
- {
- }
-
return 0;
}
sandbox_Database_Load();
}
+ MUTATOR_ONROLLBACK_OR_REMOVE
+ {
+ // nothing to roll back
+ }
+
+ MUTATOR_ONREMOVE
+ {
+ // nothing to remove
+ }
+
return FALSE;
}