From 0f0b0ed35b28a4e7f910d804c7f06186a41b47cc Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 13 Jan 2020 20:52:15 +1000 Subject: [PATCH] Automatically replace the New Toy weapons with health/armor spawns when New Toys is disabled, for better Nexuiz map compatibility --- qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc | 2 ++ qcsrc/common/t_items.qc | 5 +++++ qcsrc/common/weapons/weapon/hlac.qc | 9 +++++++++ qcsrc/common/weapons/weapon/minelayer.qc | 9 +++++++++ qcsrc/common/weapons/weapon/rifle.qc | 9 +++++++++ qcsrc/common/weapons/weapon/seeker.qc | 9 +++++++++ qcsrc/server/autocvars.qh | 1 + qcsrc/server/weapons/spawning.qc | 5 +++++ xonotic-server.cfg | 1 + 9 files changed, 50 insertions(+) diff --git a/qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc b/qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc index 47e1c97a9..fdcce4608 100644 --- a/qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc +++ b/qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc @@ -86,6 +86,8 @@ REGISTER_MUTATOR(nt, expr_evaluate(cvar_string("g_new_toys")) && !MUTATOR_IS_ENA if(nt_IsNewToy(it.m_id)) it.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED; }); + + cvar_settemp("sv_nexuizcompat_weaponswap", "0"); // disable compatibility so these weapons aren't auto replaced elsewhere } MUTATOR_ONROLLBACK_OR_REMOVE diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 1029f7865..9756752da 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -1384,6 +1384,11 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default void StartItem(entity this, GameItem def) { def = def.m_spawnfunc_hookreplace(def, this); + if (def.instanceOfWeapon) + { + weapon_defaultspawnfunc(this, def); + return; + } if (def.spawnflags & ITEM_FLAG_MUTATORBLOCKED) { delete(this); diff --git a/qcsrc/common/weapons/weapon/hlac.qc b/qcsrc/common/weapons/weapon/hlac.qc index 6511d22b5..dbc65b93e 100644 --- a/qcsrc/common/weapons/weapon/hlac.qc +++ b/qcsrc/common/weapons/weapon/hlac.qc @@ -2,6 +2,15 @@ #ifdef SVQC +METHOD(HLAC, m_spawnfunc_hookreplace, Weapon(HLAC this, entity e)) +{ + if (autocvar_sv_nexuizcompat_weaponswap && !Item_IsLoot(e)) + { + return ITEM_ArmorBig; + } + return this; +} + void W_HLAC_Touch(entity this, entity toucher) { float isprimary; diff --git a/qcsrc/common/weapons/weapon/minelayer.qc b/qcsrc/common/weapons/weapon/minelayer.qc index 7f60c5b57..48b869f94 100644 --- a/qcsrc/common/weapons/weapon/minelayer.qc +++ b/qcsrc/common/weapons/weapon/minelayer.qc @@ -2,6 +2,15 @@ #ifdef SVQC +METHOD(MineLayer, m_spawnfunc_hookreplace, Weapon(MineLayer this, entity e)) +{ + if (autocvar_sv_nexuizcompat_weaponswap && !Item_IsLoot(e)) + { + return ITEM_HealthBig; + } + return this; +} + void W_MineLayer_Stick(entity this, entity to) { spamsound(this, CH_SHOTS, SND_MINE_STICK, VOL_BASE, ATTN_NORM); diff --git a/qcsrc/common/weapons/weapon/rifle.qc b/qcsrc/common/weapons/weapon/rifle.qc index 7daf4ec40..9edf486a0 100644 --- a/qcsrc/common/weapons/weapon/rifle.qc +++ b/qcsrc/common/weapons/weapon/rifle.qc @@ -2,6 +2,15 @@ #ifdef SVQC +METHOD(Rifle, m_spawnfunc_hookreplace, Weapon(Rifle this, entity e)) +{ + if (autocvar_sv_nexuizcompat_weaponswap && !Item_IsLoot(e)) + { + return ITEM_ArmorBig; + } + return this; +} + void W_Rifle_FireBullet(Weapon thiswep, .entity weaponentity, float pSpread, float pDamage, float pForce, float pSolidPenetration, float pAmmo, int deathtype, float pTracer, float pShots, Sound pSound, entity actor) { float i; diff --git a/qcsrc/common/weapons/weapon/seeker.qc b/qcsrc/common/weapons/weapon/seeker.qc index d7ba289f5..9a6abb11c 100644 --- a/qcsrc/common/weapons/weapon/seeker.qc +++ b/qcsrc/common/weapons/weapon/seeker.qc @@ -2,6 +2,15 @@ #ifdef SVQC +METHOD(Seeker, m_spawnfunc_hookreplace, Weapon(Seeker this, entity e)) +{ + if (autocvar_sv_nexuizcompat_weaponswap && !Item_IsLoot(e)) + { + return ITEM_HealthBig; + } + return this; +} + // ============================ // Begin: Missile functions, these are general functions to be manipulated by other code // ============================ diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 8213aadde..111564a23 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -324,6 +324,7 @@ string autocvar_sv_motd; int autocvar_sv_name_maxlength = 64; bool autocvar_sv_precacheplayermodels; bool autocvar_sv_q3acompat_machineshotgunswap; +bool autocvar_sv_nexuizcompat_weaponswap = true; bool autocvar_sv_servermodelsonly; int autocvar_sv_spectate; float autocvar_sv_spectator_speed_multiplier; diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 93c49af9b..235893a5b 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -29,6 +29,11 @@ string W_Apply_Weaponreplace(string in) void weapon_defaultspawnfunc(entity this, Weapon wpn) { wpn = wpn.m_spawnfunc_hookreplace(wpn, this); + if (!wpn.instanceOfWeapon) + { + StartItem(this, wpn); + return; + } this.classname = wpn.m_canonical_spawnfunc; if (!Item_IsLoot(this) && !this.m_isreplaced) { diff --git a/xonotic-server.cfg b/xonotic-server.cfg index 6e040d5b0..076ace25e 100644 --- a/xonotic-server.cfg +++ b/xonotic-server.cfg @@ -488,6 +488,7 @@ sv_gameplayfix_nogravityonground 1 set sv_q3acompat_machineshotgunswap 0 "shorthand for swapping machinegun and shotgun (for Q3A map compatibility in mapinfo files)" set sv_q3defragcompat 0 "toggle for some compatibility hacks (for Q3DF map compatibility)" +set sv_nexuizcompat_weaponswap 1 "automatically replace legacy weapons with health and armor items (for Nexuiz map compatibility), automatically disabled by the New Toys mutator" set g_movement_highspeed 1 "multiplier scale for movement speed (applies to sv_maxspeed and sv_maxairspeed, also applies to air acceleration when g_movement_highspeed_q3_compat is set to 0)" set g_movement_highspeed_q3_compat 0 "apply speed modifiers to air movement in a more Q3-compatible way (only apply speed buffs and g_movement_highspeed to max air speed, not to acceleration)" -- 2.39.2