From a1fc8f758c7f2572d13de04ec4ed02916c0082e1 Mon Sep 17 00:00:00 2001 From: LegendaryGuard Date: Fri, 24 Jun 2022 02:29:37 +0200 Subject: [PATCH] Move spawn functions to the correct code places --- qcsrc/common/mutators/mutator/nades/nades.qc | 143 ------------------- qcsrc/common/turrets/sv_turrets.qc | 70 +++++++++ qcsrc/common/vehicles/sv_vehicles.qc | 65 +++++++++ 3 files changed, 135 insertions(+), 143 deletions(-) diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index 79afff9aa2..9899b3ea08 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -784,151 +784,8 @@ void nade_emerald_randomweapons(entity e, vector org) } //LegendGuard adds vehicle spawn option for emerald nade 20-06-2021 -entity spawnvehicle (entity e, string vehicle, Vehicle veh, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag) -{ - e.spawnflags = VHF_MULTISLOT; - - if(!respwn) { e.spawnflags |= VHF_ISVEHICLE; } - setorigin(e, orig); - bool allow_any = boolean(vehicle == "anyrandom"); - - if(vehicle == "random" || allow_any) - { - RandomSelection_Init(); - FOREACH(Vehicles, it != VEH_Null && (allow_any || !(it.spawnflags & VHF_MULTISLOT)), - { - RandomSelection_AddEnt(it, 1, 1); - }); - - veh = RandomSelection_chosen_ent; - } - else if(vehicle != "") - { - bool found = false; - FOREACH(Vehicles, it != VEH_Null, - { - if(it.netname == vehicle) - { - found = true; - veh = it; // we have the vehicle, old vehicle id is no longer required - break; - } - }); - - if(!found && veh == VEH_Null) - { - if(removeifinvalid) - { - delete(e); - return NULL; // no good - } - // select a random valid vehicle type if no valid vehicle was provided - return spawnvehicle(e, "random", VEH_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag); - } - } - - e.realowner = spawnedby; - - e.effects |= EF_DIMLIGHT; - - // TODO: Create a vehicle .entity moveflag - //if(moveflag && e.vehicle_flags == VEH_FLAG_MOVE) - // e.monster_moveflags = moveflag; - - if(IS_PLAYER(spawnedby)) - { - if(teamplay && autocvar_g_monsters_teams) - e.team = spawnedby.team; // colors handled in spawn code - - e.angles_y = spawnedby.angles_y; - } - - // TODO: Remove or not? - if(!(e.spawnflags & VHF_ISVEHICLE)) { delete(e); return NULL; } // remove even if told not to, as we didn't spawn any kind of vehicle - - // e.angles = '0 0 0'; - e.velocity = randomvec() * 150 + '0 0 325'; - e.spawnfunc_checked = true; - time = 0.4; - - vehicle_initialize(e, veh, true); - - return e; -} //LegendGuard adds turret spawn option for emerald nade 22-06-2021 -entity spawnturret (entity e, string turret, Turret tur, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag) -{ - e.spawnflags = TSF_SUSPENDED; - - if(!respwn) { e.spawnflags |= TSL_NO_RESPAWN; } - // if(invincible) { e.damage_flags |= TFL_DMG_NO; } - - setorigin(e, orig); - bool allow_any = boolean(turret == "anyrandom"); - - if(turret == "random" || allow_any) - { - RandomSelection_Init(); - FOREACH(Turrets, it != TUR_Null && (allow_any || !(it.spawnflags & TSF_SUSPENDED)), - { - RandomSelection_AddEnt(it, 1, 1); - }); - - tur = RandomSelection_chosen_ent; - } - else if(turret != "") - { - bool found = false; - FOREACH(Turrets, it != TUR_Null, - { - if(it.netname == turret) - { - found = true; - tur = it; // we have the turret, old turret id is no longer required - break; - } - }); - - if(!found && tur == TUR_Null) - { - if(removeifinvalid) - { - delete(e); - return NULL; // no good - } - // select a random valid turret type if no valid turret was provided - return spawnturret(e, "random", TUR_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag); - } - } - - e.realowner = spawnedby; - - e.effects |= EF_DIMLIGHT; - - // TODO: Create a turret .entity moveflag - //if(moveflag && e.turret_flags == TUR_FLAG_MOVE) - // e.monster_moveflags = moveflag; - - if(IS_PLAYER(spawnedby)) - { - if(teamplay && autocvar_g_monsters_teams) - e.team = spawnedby.team; // colors handled in spawn code - - // TODO: Create a turret .entity moveflag - //if(autocvar_g_monsters_owners) - // e.monster_follow = own; // using .owner makes the monster non-solid for its master - - e.angles_y = spawnedby.angles_y; - } - - // TODO: Remove or not? - if(!(e.spawnflags & TSF_SUSPENDED)) { delete(e); return NULL; } // remove even if told not to, as we didn't spawn any kind of turret - - turret_initialize(e, tur); - - return e; -} void nade_emerald_randomitem(entity e, vector org) { diff --git a/qcsrc/common/turrets/sv_turrets.qc b/qcsrc/common/turrets/sv_turrets.qc index 1b5e7cdb84..902ddff3c5 100644 --- a/qcsrc/common/turrets/sv_turrets.qc +++ b/qcsrc/common/turrets/sv_turrets.qc @@ -1415,4 +1415,74 @@ bool turret_initialize(entity this, Turret tur) return true; } + +entity spawnturret (entity e, string turret, Turret tur, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag) +{ + e.spawnflags = TSF_SUSPENDED; + + if(!respwn) { e.spawnflags |= TSL_NO_RESPAWN; } + // if(invincible) { e.damage_flags |= TFL_DMG_NO; } + + setorigin(e, orig); + bool allow_any = boolean(turret == "anyrandom"); + + if(turret == "random" || allow_any) + { + RandomSelection_Init(); + FOREACH(Turrets, it != TUR_Null && (allow_any || !(it.spawnflags & TSF_SUSPENDED)), + { + RandomSelection_AddEnt(it, 1, 1); + }); + + tur = RandomSelection_chosen_ent; + } + else if(turret != "") + { + bool found = false; + FOREACH(Turrets, it != TUR_Null, + { + if(it.netname == turret) + { + found = true; + tur = it; // we have the turret, old turret id is no longer required + break; + } + }); + + if(!found && tur == TUR_Null) + { + if(removeifinvalid) + { + delete(e); + return NULL; // no good + } + // select a random valid turret type if no valid turret was provided + return spawnturret(e, "random", TUR_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag); + } + } + + e.realowner = spawnedby; + + // TODO: Create a turret .entity moveflag + //if(moveflag && e.turret_flags == TUR_FLAG_MOVE) + // e.monster_moveflags = moveflag; + + if(IS_PLAYER(spawnedby)) + { + if(teamplay) + e.team = spawnedby.team; // colors handled in spawn code + + // TODO: Create a turret .entity moveflag + //if(autocvar_g_monsters_owners) + // e.monster_follow = own; // using .owner makes the monster non-solid for its master + + e.angles_y = spawnedby.angles_y; + } + + if(!(e.spawnflags & TSF_SUSPENDED)) { delete(e); return NULL; } // remove even if told not to, as we didn't spawn any kind of turret + + turret_initialize(e, tur); + + return e; +} #endif diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index 302b39a0d1..83fd479bfe 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -1291,3 +1291,68 @@ bool vehicle_initialize(entity this, Vehicle info, bool nodrop) return true; } + +entity spawnvehicle (entity e, string vehicle, Vehicle veh, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag) +{ + e.spawnflags = VHF_MULTISLOT; + + if(!respwn) { e.spawnflags |= VHF_ISVEHICLE; } + setorigin(e, orig); + bool allow_any = boolean(vehicle == "anyrandom"); + + if(vehicle == "random" || allow_any) + { + RandomSelection_Init(); + FOREACH(Vehicles, it != VEH_Null && (allow_any || !(it.spawnflags & VHF_MULTISLOT)), + { + RandomSelection_AddEnt(it, 1, 1); + }); + + veh = RandomSelection_chosen_ent; + } + else if(vehicle != "") + { + bool found = false; + FOREACH(Vehicles, it != VEH_Null, + { + if(it.netname == vehicle) + { + found = true; + veh = it; // we have the vehicle, old vehicle id is no longer required + break; + } + }); + + if(!found && veh == VEH_Null) + { + if(removeifinvalid) + { + delete(e); + return NULL; // no good + } + // select a random valid vehicle type if no valid vehicle was provided + return spawnvehicle(e, "random", VEH_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag); + } + } + + e.realowner = spawnedby; + + if(IS_PLAYER(spawnedby)) + { + if(teamplay) + e.team = spawnedby.team; // colors handled in spawn code + + e.angles_y = spawnedby.angles_y; + } + + if(!(e.spawnflags & VHF_ISVEHICLE)) { delete(e); return NULL; } // remove even if told not to, as we didn't spawn any kind of vehicle + + // e.angles = '0 0 0'; + e.velocity = randomvec() * 150 + '0 0 325'; + e.spawnfunc_checked = true; + time = 0.6; + + vehicle_initialize(e, veh, true); + + return e; +} -- 2.39.2