=======================
When a gun tries to spawn, this mutator is called. It will provide alternate
-default values of weaponreplace lists.
+weaponreplace lists.
Entity:
- weaponreplace
- weaponarena (but all and most weapons arena again won't include them)
-Also, this mutator performs the default replacements on the DEFAULTS of the
+This mutator performs the default replacements on the DEFAULTS of the
start weapon selection.
-Also: these weapons appear in the menu's priority list, BUT get a suffix
+These weapons appear in the menu's priority list, BUT get a suffix
"(Mutator weapon)".
Picking up a "new toys" weapon will not play standard weapon pickup sound, but
*/
-string i_herd_yo_liek_weaponreplace(string replacement)
+.string new_toys;
+
+float autocvar_g_new_toys_autoreplace;
+#define NT_AUTOREPLACE_NEVER 0
+#define NT_AUTOREPLACE_ALWAYS 1
+#define NT_AUTOREPLACE_RANDOM 2
+
+MUTATOR_HOOKFUNCTION(nt_SetModname)
{
- string newlist;
- float n = tokenize_console(replacement);
- string out = "";
- for(i = 0; i < n; ++i)
+ modname = "NewToys";
+ return 0;
+}
+
+float nt_IsNewToy(float w)
+{
+ switch(w)
{
- string s = argv(i);
- string r = cvar_string(strcat("g_weaponreplace_", s));
- if(r == "")
- out = strcat(out, " ", s);
- else if(r != "0")
- out = strcat(out, " ", r);
+ case WEP_SEEKER:
+ case WEP_MINE_LAYER:
+ case WEP_HLAC:
+ case WEP_RIFLE:
+ return TRUE;
+ default:
+ return FALSE;
}
- return substring(out, 1);
}
-MUTATOR_HOOKFUNCTION(nt_SetModname)
+string nt_GetFullReplacement(string w)
{
- modname = "NewToys";
- return 0;
+ switch(w)
+ {
+ case "hagar": return "seeker";
+ case "rocketlauncher": return "minelayer";
+ case "uzi": return "hlac";
+ case "nex": return "rifle";
+ default: return string_null;
+ }
+}
+
+string nt_GetReplacement(string w, float m)
+{
+ if(m == NT_AUTOREPLACE_NEVER)
+ return w;
+ string s = nt_GetFullReplacement(w);
+ if not(s)
+ return w;
+ if(m == NT_AUTOREPLACE_RANDOM)
+ s = strcat(w, " ", s);
+ return s;
}
MUTATOR_HOOKFUNCTION(nt_SetStartItems)
// rearrange start_weapon_default
// apply those bits that are set by start_weapon_defaultmask
// same for warmup
- // TODO
+
+ float i, j, k, n;
+
+ WepSet newdefault;
+ WepSet warmup_newdefault;
+
+ newdefault = '0 0 0';
+ warmup_newdefault = '0 0 0';
+
+ for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+ {
+ entity e = get_weaponinfo(i);
+ if(!e.weapon)
+ continue;
+
+ n = tokenize_console(nt_GetReplacement(e.netname, autocvar_g_new_toys_autoreplace));
+
+ for(j = 0; j < n; ++j)
+ for(k = WEP_FIRST; k <= WEP_LAST; ++k)
+ if(get_weaponinfo(k).netname == argv(j))
+ {
+ if(start_weapons & WepSet_FromWeapon(i))
+ newdefault |= WepSet_FromWeapon(k);
+ if(warmup_start_weapons & WepSet_FromWeapon(i))
+ warmup_newdefault |= WepSet_FromWeapon(k);
+ }
+ }
+
+ newdefault &= start_weapons_defaultmask;
+ start_weapons &= ~start_weapons_defaultmask;
+ start_weapons |= newdefault;
+
+ warmup_newdefault &= warmup_start_weapons_defaultmask;
+ warmup_start_weapons &= ~warmup_start_weapons_defaultmask;
+ warmup_start_weapons |= warmup_newdefault;
+
+ return 0;
+}
+
+MUTATOR_HOOKFUNCTION(nt_SetWeaponreplace)
+{
+ // otherwise, we do replace
+ if(self.new_toys)
+ {
+ // map defined replacement:
+ ret_string = self.new_toys;
+ }
+ else
+ {
+ // auto replacement:
+ ret_string = nt_GetReplacement(other.netname, autocvar_g_new_toys_autoreplace);
+ }
+
+ // apply regular weaponreplace
+ ret_string = W_Apply_Weaponreplace(ret_string);
+
+ return 0;
+}
+
+MUTATOR_HOOKFUNCTION(nt_FilterItem)
+{
+ if(nt_IsNewToy(self.weapon))
+ self.item_pickupsound = "weapons/weaponpickup_new_toys.wav";
return 0;
}
MUTATOR_DEFINITION(mutator_new_toys)
{
MUTATOR_HOOK(SetModname, nt_SetModname, CBC_ORDER_ANY);
- MUTATOR_HOOK(SetStartItems, nix_SetStartItems, CBC_ORDER_ANY);
+ MUTATOR_HOOK(SetStartItems, nt_SetStartItems, CBC_ORDER_ANY);
+ MUTATOR_HOOK(SetWeaponreplace, nt_SetWeaponreplace, CBC_ORDER_LAST);
+ MUTATOR_HOOK(FilterItem, nt_FilterItem, CBC_ORDER_ANY);
MUTATOR_ONADD
{
if(time > 1) // game loads at time 1
error("This cannot be added at runtime\n");
+
+ precache_sound("weapons/weaponpickup_new_toys.wav");
+
+ // mark the guns as ok to use by e.g. impulse 99
+ float i;
+ for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+ 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;