From b9b0ec41c928d5e109fc963ceadea5a4018a2269 Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Tue, 11 Jun 2013 16:14:04 -0400 Subject: [PATCH] Working on cleaning up weapon spawn functions --- qcsrc/common/weapons/w_arc.qc | 5 +- qcsrc/common/weapons/w_blaster.qc | 6 +- qcsrc/common/weapons/w_crylink.qc | 6 +- qcsrc/common/weapons/w_devastator.qc | 6 +- qcsrc/common/weapons/w_electro.qc | 7 +- qcsrc/common/weapons/w_fireball.qc | 7 +- qcsrc/common/weapons/w_hagar.qc | 6 +- qcsrc/common/weapons/w_hlac.qc | 6 +- qcsrc/common/weapons/w_hook.qc | 22 ++-- qcsrc/common/weapons/w_machinegun.qc | 15 ++- qcsrc/common/weapons/w_minstanex.qc | 9 +- qcsrc/common/weapons/w_nex.qc | 7 ++ qcsrc/common/weapons/w_shockwave.qc | 11 ++ qcsrc/server/progs.src | 3 +- qcsrc/server/t_items.qc | 174 --------------------------- qcsrc/server/weapons/cl_weapons.qc | 140 +++++++++++++++++++++ 16 files changed, 202 insertions(+), 228 deletions(-) diff --git a/qcsrc/common/weapons/w_arc.qc b/qcsrc/common/weapons/w_arc.qc index 71d1fd564..ab06a8a92 100644 --- a/qcsrc/common/weapons/w_arc.qc +++ b/qcsrc/common/weapons/w_arc.qc @@ -39,10 +39,7 @@ void ArcInit(); #endif #else #ifdef SVQC -void spawnfunc_weapon_arc (void) // should this really be here? -{ - weapon_defaultspawnfunc(WEP_ARC); -} +void spawnfunc_weapon_arc() { weapon_defaultspawnfunc(WEP_ARC); } float W_Arc_Beam_Send(entity to, float sf) { diff --git a/qcsrc/common/weapons/w_blaster.qc b/qcsrc/common/weapons/w_blaster.qc index c331c5b52..e13ca5f1c 100644 --- a/qcsrc/common/weapons/w_blaster.qc +++ b/qcsrc/common/weapons/w_blaster.qc @@ -12,6 +12,7 @@ REGISTER_WEAPON( ); #else #ifdef SVQC +void spawnfunc_weapon_laser() { weapon_defaultspawnfunc(WEP_LASER); } void(float imp) W_SwitchWeapon; void() W_LastWeapon; .float swing_prev; @@ -432,11 +433,6 @@ void W_Laser_Attack(float issecondary) } } -void spawnfunc_weapon_laser(void) -{ - weapon_defaultspawnfunc(WEP_LASER); -} - float W_Laser(float request) { switch(request) diff --git a/qcsrc/common/weapons/w_crylink.qc b/qcsrc/common/weapons/w_crylink.qc index e70a9c3c1..983b3305d 100644 --- a/qcsrc/common/weapons/w_crylink.qc +++ b/qcsrc/common/weapons/w_crylink.qc @@ -12,6 +12,7 @@ REGISTER_WEAPON( ); #else #ifdef SVQC +void spawnfunc_weapon_crylink() { weapon_defaultspawnfunc(WEP_CRYLINK); } .float gravity; .float crylink_waitrelease; .entity crylink_lastgroup; @@ -577,11 +578,6 @@ void W_Crylink_Attack2 (void) } } -void spawnfunc_weapon_crylink (void) -{ - weapon_defaultspawnfunc(WEP_CRYLINK); -} - float w_crylink(float req) { float ammo_amount; diff --git a/qcsrc/common/weapons/w_devastator.qc b/qcsrc/common/weapons/w_devastator.qc index c2264c3b3..6815cc2f9 100644 --- a/qcsrc/common/weapons/w_devastator.qc +++ b/qcsrc/common/weapons/w_devastator.qc @@ -47,10 +47,8 @@ DEVASTATOR_SETTINGS(devastator) #endif #else #ifdef SVQC -void spawnfunc_weapon_rocketlauncher() -{ - weapon_defaultspawnfunc(WEP_DEVASTATOR); -} +void spawnfunc_weapon_devastator() { weapon_defaultspawnfunc(WEP_DEVASTATOR); } +void spawnfunc_weapon_rocketlauncher() { spawnfunc_weapon_devastator(); } void W_Devastator_Unregister() { diff --git a/qcsrc/common/weapons/w_electro.qc b/qcsrc/common/weapons/w_electro.qc index 74e6e5124..2e19540d0 100644 --- a/qcsrc/common/weapons/w_electro.qc +++ b/qcsrc/common/weapons/w_electro.qc @@ -17,6 +17,8 @@ vector electro_shotorigin[4]; #endif #else #ifdef SVQC +void spawnfunc_weapon_electro() { weapon_defaultspawnfunc(WEP_ELECTRO); } + .float electro_count; .float electro_secondarytime; @@ -373,11 +375,6 @@ void ElectroInit() electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4); } -void spawnfunc_weapon_electro (void) -{ - weapon_defaultspawnfunc(WEP_ELECTRO); -} - void w_electro_checkattack() { if(self.electro_count > 1) diff --git a/qcsrc/common/weapons/w_fireball.qc b/qcsrc/common/weapons/w_fireball.qc index 1bfdfaeca..f68050f38 100644 --- a/qcsrc/common/weapons/w_fireball.qc +++ b/qcsrc/common/weapons/w_fireball.qc @@ -12,6 +12,8 @@ REGISTER_WEAPON( ); #else #ifdef SVQC +void spawnfunc_weapon_fireball() { weapon_defaultspawnfunc(WEP_FIREBALL); } + .float bot_primary_fireballmooth; // whatever a mooth is .vector fireball_impactvec; .float fireball_primarytime; @@ -307,11 +309,6 @@ void W_Fireball_Attack2() other = proj; MUTATOR_CALLHOOK(EditProjectile); } -void spawnfunc_weapon_fireball (void) -{ - weapon_defaultspawnfunc(WEP_FIREBALL); -} - float w_fireball(float req) { switch(req) diff --git a/qcsrc/common/weapons/w_hagar.qc b/qcsrc/common/weapons/w_hagar.qc index aa773ea2a..18a14fb99 100644 --- a/qcsrc/common/weapons/w_hagar.qc +++ b/qcsrc/common/weapons/w_hagar.qc @@ -12,6 +12,7 @@ REGISTER_WEAPON( ); #else #ifdef SVQC +void spawnfunc_weapon_hagar() { weapon_defaultspawnfunc(WEP_HAGAR); } // NO bounce protection, as bounces are limited! void W_Hagar_Explode (void) @@ -345,11 +346,6 @@ void W_Hagar_Attack2_Load (void) } } -void spawnfunc_weapon_hagar (void) -{ - weapon_defaultspawnfunc(WEP_HAGAR); -} - float w_hagar(float req) { float ammo_amount; diff --git a/qcsrc/common/weapons/w_hlac.qc b/qcsrc/common/weapons/w_hlac.qc index d6d7de6f1..0c49744cd 100644 --- a/qcsrc/common/weapons/w_hlac.qc +++ b/qcsrc/common/weapons/w_hlac.qc @@ -12,6 +12,7 @@ REGISTER_WEAPON( ); #else #ifdef SVQC +void spawnfunc_weapon_hlac() { weapon_defaultspawnfunc(WEP_HLAC); } void W_HLAC_Touch (void) { @@ -166,11 +167,6 @@ void HLAC_fire1_02() } } -void spawnfunc_weapon_hlac (void) -{ - weapon_defaultspawnfunc(WEP_HLAC); -} - float w_hlac(float req) { float ammo_amount; diff --git a/qcsrc/common/weapons/w_hook.qc b/qcsrc/common/weapons/w_hook.qc index bbd07904f..ae0f756d4 100644 --- a/qcsrc/common/weapons/w_hook.qc +++ b/qcsrc/common/weapons/w_hook.qc @@ -12,6 +12,17 @@ REGISTER_WEAPON( ); #else #ifdef SVQC +void spawnfunc_weapon_hook() +{ + if(g_grappling_hook) // offhand hook + { + startitem_failed = TRUE; + remove(self); + return; + } + weapon_defaultspawnfunc(WEP_HOOK); +} + .float dmg; .float dmg_edge; .float dmg_radius; @@ -127,17 +138,6 @@ void W_Hook_Attack2() other = gren; MUTATOR_CALLHOOK(EditProjectile); } -void spawnfunc_weapon_hook (void) -{ - if(g_grappling_hook) // offhand hook - { - startitem_failed = TRUE; - remove(self); - return; - } - weapon_defaultspawnfunc(WEP_HOOK); -} - float w_hook(float req) { float hooked_time_max, hooked_fuel; diff --git a/qcsrc/common/weapons/w_machinegun.qc b/qcsrc/common/weapons/w_machinegun.qc index 8df318d09..78a70dc83 100644 --- a/qcsrc/common/weapons/w_machinegun.qc +++ b/qcsrc/common/weapons/w_machinegun.qc @@ -10,8 +10,21 @@ REGISTER_WEAPON( /* shortname */ "uzi", /* fullname */ _("Machine Gun") ); + +#ifdef SVQC +#endif #else #ifdef SVQC +void spawnfunc_weapon_uzi() +{ + if(autocvar_sv_q3acompat_machineshotgunswap) + if(self.classname != "droppedweapon") + { + weapon_defaultspawnfunc(WEP_SHOTGUN); + return; + } + weapon_defaultspawnfunc(WEP_UZI); +} // leilei's fancy muzzleflash stuff void UZI_Flash_Go() @@ -187,8 +200,6 @@ void uzi_mode1_fire_burst() } -void spawnfunc_weapon_machinegun(); // defined in t_items.qc - float w_uzi(float req) { float ammo_amount; diff --git a/qcsrc/common/weapons/w_minstanex.qc b/qcsrc/common/weapons/w_minstanex.qc index bfa133857..5f4c13145 100644 --- a/qcsrc/common/weapons/w_minstanex.qc +++ b/qcsrc/common/weapons/w_minstanex.qc @@ -10,6 +10,13 @@ REGISTER_WEAPON( /* shortname */ "minstanex", /* fullname */ _("MinstaNex") ); + +#ifdef SVQC +void spawnfunc_weapon_minstanex (void) +{ + weapon_defaultspawnfunc(WEP_MINSTANEX); +} +#endif #else #ifdef SVQC .float minstanex_lasthit; @@ -78,8 +85,6 @@ void W_MinstaNex_Attack (void) W_DecreaseAmmo(ammo_cells, ((g_minstagib) ? 1 : autocvar_g_balance_minstanex_ammo), autocvar_g_balance_minstanex_reload_ammo); } -void spawnfunc_weapon_minstanex (void); // defined in t_items.qc - float w_minstanex(float req) { float ammo_amount; diff --git a/qcsrc/common/weapons/w_nex.qc b/qcsrc/common/weapons/w_nex.qc index 81d4c3d58..8b0ba6074 100644 --- a/qcsrc/common/weapons/w_nex.qc +++ b/qcsrc/common/weapons/w_nex.qc @@ -10,6 +10,13 @@ REGISTER_WEAPON( /* shortname */ "nex", /* fullname */ _("Nex") ); + +#ifdef SVQC +void spawnfunc_weapon_nex (void) +{ + weapon_defaultspawnfunc(WEP_NEX); +} +#endif #else #ifdef SVQC diff --git a/qcsrc/common/weapons/w_shockwave.qc b/qcsrc/common/weapons/w_shockwave.qc index 476d4d3fd..9e8787de5 100644 --- a/qcsrc/common/weapons/w_shockwave.qc +++ b/qcsrc/common/weapons/w_shockwave.qc @@ -12,6 +12,17 @@ REGISTER_WEAPON( ); #else #ifdef SVQC +void spawnfunc_weapon_shotgun() +{ + if(autocvar_sv_q3acompat_machineshotgunswap) + if(self.classname != "droppedweapon") + { + weapon_defaultspawnfunc(WEP_UZI); + return; + } + weapon_defaultspawnfunc(WEP_SHOTGUN); +} + void W_Shotgun_Attack (void) { diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index 9cd064845..037e10449 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -16,7 +16,8 @@ sys-post.qh ../common/teams.qh ../common/util.qh ../common/counting.qh -../common/weapons/weapons.qh // TODO +weapons/cl_weapons.qh +../common/weapons/weapons.qh // WEAPONTODO ../common/urllib.qh ../common/command/markup.qh ../common/command/rpn.qh diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 66676bf2f..07ddfdd3c 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -1146,180 +1146,6 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, } } -float weaponswapping; -float internalteam; - -void weapon_defaultspawnfunc(float wpn) -{ - entity e; - float t; - var .float ammofield; - string s; - entity oldself; - float i, j; - float f; - - if(self.classname != "droppedweapon" && self.classname != "replacedweapon") - { - e = get_weaponinfo(wpn); - - if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED) - { - print("Attempted to spawn a mutator-blocked weapon; these guns will in the future require a mutator\n"); - /* - objerror("Attempted to spawn a mutator-blocked weapon rejected"); - startitem_failed = TRUE; - return; - */ - } - - s = W_Apply_Weaponreplace(e.netname); - ret_string = s; - other = e; - MUTATOR_CALLHOOK(SetWeaponreplace); - s = ret_string; - if(s == "") - { - remove(self); - startitem_failed = TRUE; - return; - } - t = tokenize_console(s); - if(t >= 2) - { - self.team = --internalteam; - oldself = self; - for(i = 1; i < t; ++i) - { - s = argv(i); - for(j = WEP_FIRST; j <= WEP_LAST; ++j) - { - e = get_weaponinfo(j); - if(e.netname == s) - { - self = spawn(); - copyentity(oldself, self); - self.classname = "replacedweapon"; - weapon_defaultspawnfunc(j); - break; - } - } - if(j > WEP_LAST) - { - print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n"); - } - } - self = oldself; - } - if(t >= 1) // always the case! - { - s = argv(0); - wpn = 0; - for(j = WEP_FIRST; j <= WEP_LAST; ++j) - { - e = get_weaponinfo(j); - if(e.netname == s) - { - wpn = j; - break; - } - } - if(j > WEP_LAST) - { - print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n"); - } - } - if(wpn == 0) - { - remove(self); - startitem_failed = TRUE; - return; - } - } - - e = get_weaponinfo(wpn); - - if(!self.respawntime) - { - if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS)) - { - self.respawntime = g_pickup_respawntime_superweapon; - self.respawntimejitter = g_pickup_respawntimejitter_superweapon; - } - else - { - self.respawntime = g_pickup_respawntime_weapon; - self.respawntimejitter = g_pickup_respawntimejitter_weapon; - } - } - - if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS)) - if(!self.superweapons_finished) - self.superweapons_finished = autocvar_g_balance_superweapons_time; - - if(e.items) - { - for(i = 0, j = 1; i < 24; ++i, j *= 2) - { - if(e.items & j) - { - ammofield = Item_CounterField(j); - if(!self.ammofield) - self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon")); - } - } - } - - // pickup anyway - if(g_pickup_weapons_anyway) - self.pickup_anyway = TRUE; - - f = FL_WEAPON; - - // no weapon-stay on superweapons - if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS)) - f |= FL_NO_WEAPON_STAY; - - // weapon stay isn't supported for teamed weapons - if(self.team) - f |= FL_NO_WEAPON_STAY; - - StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue); - if (self.modelindex) // don't precache if self was removed - weapon_action(e.weapon, WR_PRECACHE); -} - -void spawnfunc_weapon_shotgun (void); -void spawnfunc_weapon_uzi (void) { - if(autocvar_sv_q3acompat_machineshotgunswap) - if(self.classname != "droppedweapon") - { - weapon_defaultspawnfunc(WEP_SHOTGUN); - return; - } - weapon_defaultspawnfunc(WEP_UZI); -} - -void spawnfunc_weapon_shotgun (void) { - if(autocvar_sv_q3acompat_machineshotgunswap) - if(self.classname != "droppedweapon") - { - weapon_defaultspawnfunc(WEP_UZI); - return; - } - weapon_defaultspawnfunc(WEP_SHOTGUN); -} - -void spawnfunc_weapon_nex (void) -{ - weapon_defaultspawnfunc(WEP_NEX); -} - -void spawnfunc_weapon_minstanex (void) -{ - weapon_defaultspawnfunc(WEP_MINSTANEX); -} - void spawnfunc_item_rockets (void) { if(!self.ammo_rockets) self.ammo_rockets = g_pickup_rockets; diff --git a/qcsrc/server/weapons/cl_weapons.qc b/qcsrc/server/weapons/cl_weapons.qc index cec4b8dab..1b47fef3b 100644 --- a/qcsrc/server/weapons/cl_weapons.qc +++ b/qcsrc/server/weapons/cl_weapons.qc @@ -527,3 +527,143 @@ string W_Apply_Weaponreplace(string in) } return substring(out, 1, -1); } + +void weapon_defaultspawnfunc(float wpn) +{ + entity e; + float t; + var .float ammofield; + string s; + entity oldself; + float i, j; + float f; + + if(self.classname != "droppedweapon" && self.classname != "replacedweapon") + { + e = get_weaponinfo(wpn); + + if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED) + { + print("Attempted to spawn a mutator-blocked weapon; these guns will in the future require a mutator\n"); + /* + objerror("Attempted to spawn a mutator-blocked weapon rejected"); + startitem_failed = TRUE; + return; + */ + } + + s = W_Apply_Weaponreplace(e.netname); + ret_string = s; + other = e; + MUTATOR_CALLHOOK(SetWeaponreplace); + s = ret_string; + if(s == "") + { + remove(self); + startitem_failed = TRUE; + return; + } + t = tokenize_console(s); + if(t >= 2) + { + self.team = --internalteam; + oldself = self; + for(i = 1; i < t; ++i) + { + s = argv(i); + for(j = WEP_FIRST; j <= WEP_LAST; ++j) + { + e = get_weaponinfo(j); + if(e.netname == s) + { + self = spawn(); + copyentity(oldself, self); + self.classname = "replacedweapon"; + weapon_defaultspawnfunc(j); + break; + } + } + if(j > WEP_LAST) + { + print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n"); + } + } + self = oldself; + } + if(t >= 1) // always the case! + { + s = argv(0); + wpn = 0; + for(j = WEP_FIRST; j <= WEP_LAST; ++j) + { + e = get_weaponinfo(j); + if(e.netname == s) + { + wpn = j; + break; + } + } + if(j > WEP_LAST) + { + print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n"); + } + } + if(wpn == 0) + { + remove(self); + startitem_failed = TRUE; + return; + } + } + + e = get_weaponinfo(wpn); + + if(!self.respawntime) + { + if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS)) + { + self.respawntime = g_pickup_respawntime_superweapon; + self.respawntimejitter = g_pickup_respawntimejitter_superweapon; + } + else + { + self.respawntime = g_pickup_respawntime_weapon; + self.respawntimejitter = g_pickup_respawntimejitter_weapon; + } + } + + if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS)) + if(!self.superweapons_finished) + self.superweapons_finished = autocvar_g_balance_superweapons_time; + + if(e.items) + { + for(i = 0, j = 1; i < 24; ++i, j *= 2) + { + if(e.items & j) + { + ammofield = Item_CounterField(j); + if(!self.ammofield) + self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon")); + } + } + } + + // pickup anyway + if(g_pickup_weapons_anyway) + self.pickup_anyway = TRUE; + + f = FL_WEAPON; + + // no weapon-stay on superweapons + if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS)) + f |= FL_NO_WEAPON_STAY; + + // weapon stay isn't supported for teamed weapons + if(self.team) + f |= FL_NO_WEAPON_STAY; + + StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue); + if (self.modelindex) // don't precache if self was removed + weapon_action(e.weapon, WR_PRECACHE); +} -- 2.39.2