From ca97e0da06b5145f598d84624a33a443c38e511a Mon Sep 17 00:00:00 2001 From: LegendaryGuard Date: Tue, 5 Jul 2022 01:12:35 +0200 Subject: [PATCH] Add cvars to limit spawn counts for vehicles and turrets, plus spawned turrets in DM-like gamemodes don't attack against owner except Tesla turret --- qcsrc/common/turrets/sv_turrets.qc | 25 +++++++++++++++++++++++++ qcsrc/common/turrets/sv_turrets.qh | 5 ++++- qcsrc/common/vehicles/sv_vehicles.qc | 12 +++++++++++- qcsrc/common/vehicles/sv_vehicles.qh | 3 +++ turrets.cfg | 2 ++ vehicles.cfg | 2 ++ 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/qcsrc/common/turrets/sv_turrets.qc b/qcsrc/common/turrets/sv_turrets.qc index 0d4dd74e4a..88804768b1 100644 --- a/qcsrc/common/turrets/sv_turrets.qc +++ b/qcsrc/common/turrets/sv_turrets.qc @@ -203,6 +203,9 @@ void turret_die(entity this) sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1); + if (this.tur_spawned) + tmp_turcount--; + tur.tr_death(tur, this); delete(this.tur_head); @@ -229,6 +232,14 @@ void turret_damage(entity this, entity inflictor, entity attacker, float damage, if(!this.active) return; + if(this.realowner == attacker) + { + if(autocvar_g_friendlyfire) + damage = damage * autocvar_g_friendlyfire; + else + return; + } + if(SAME_TEAM(this, attacker)) { if(autocvar_g_friendlyfire) @@ -1116,6 +1127,9 @@ void turret_think(entity this) // Check if we have a vailid enemy, and try to find one if we dont. + // Don't attack against owner + if (turret_select_target(this) == this.realowner) return; + // g_turrets_targetscan_maxdelay forces a target re-scan at least this often float do_target_scan = 0; if((this.target_select_time + autocvar_g_turrets_targetscan_maxdelay) < time) @@ -1137,6 +1151,8 @@ void turret_think(entity this) if(do_target_scan) { this.enemy = turret_select_target(this); + // Don't attack against owner + if (this.enemy == this.realowner) return; this.target_select_time = time; } @@ -1418,7 +1434,14 @@ bool turret_initialize(entity this, Turret tur) entity spawnturret (entity e, string turret, Turret tur, entity spawnedby, entity own, vector orig, bool respwn, bool invincible, bool removeifinvalid, int moveflag, bool optional) { + if (autocvar_g_turrets_max <= 0 || autocvar_g_turrets_max_perplayer <= 0) { print_to(own, "Turret spawning is disabled"); return NULL; } + + if (tmp_turcount >= autocvar_g_turrets_max) { print_to(own, "The maximum turret count has been reached"); return NULL; } + + if (tmp_turcount >= autocvar_g_turrets_max_perplayer) { print_to(own, "You can't spawn any more turrets"); return NULL; } + e.spawnflags = TSF_SUSPENDED; + e.tur_spawned = true; if(!respwn) { e.spawnflags |= TSL_NO_RESPAWN; } if(invincible) { e.damage_flags |= TFL_DMG_NO; } @@ -1485,6 +1508,8 @@ entity spawnturret (entity e, string turret, Turret tur, entity spawnedby, entit // spawn! turret_initialize(e, tur); + tmp_turcount++; + //LOG_INFOF("^1tur.netname^3: %s", tur.netname); if (optional) diff --git a/qcsrc/common/turrets/sv_turrets.qh b/qcsrc/common/turrets/sv_turrets.qh index a9eb6e25bb..83d971f43c 100644 --- a/qcsrc/common/turrets/sv_turrets.qh +++ b/qcsrc/common/turrets/sv_turrets.qh @@ -4,6 +4,8 @@ bool autocvar_g_turrets; float autocvar_g_turrets_aimidle_delay; +int autocvar_g_turrets_max; +int autocvar_g_turrets_max_perplayer; bool autocvar_g_turrets_nofire; bool autocvar_g_turrets_reloadcvars; float autocvar_g_turrets_targetscan_maxdelay; @@ -36,8 +38,8 @@ TR_PROPS_COMMON(X, , ) .float tur_dist_enemy; // distance to enemy .float tur_dist_aimpos; // distance to aim location .float tur_dist_impact_to_aimpos; // distance impact<->aim +.bool tur_spawned; // spawned turret using spawnturret .float volly_counter; // decrement counter from .shot_volly to 0 - .float target_select_time; // last time turret had a valid target .float target_validate_time; // throttle re-validation of current target @@ -89,6 +91,7 @@ bool turret_closetotarget(entity this, vector targ, float range); .entity pathgoal; +int tmp_turcount; float turret_count; // debugging diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index c41889a056..8a02b47f4d 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -519,11 +519,13 @@ void vehicles_setreturn(entity veh) if(IS_DEAD(veh)) { - if (veh.cannot_respawn) + if (veh.cannot_respawn) { sound (veh, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); Send_Effect(EFFECT_EXPLOSION_BIG, veh.origin + '0 0 100', '0 0 0', 1); + tmp_vehcount--; + delete(veh); return; } @@ -1309,6 +1311,12 @@ bool vehicle_initialize(entity this, Vehicle info, bool nodrop) entity spawnvehicle (entity e, string vehicle, Vehicle veh, entity spawnedby, entity own, vector orig, bool no_respwn, bool removeifinvalid, bool optional, bool nodrop) { + if (autocvar_g_vehicles_max <= 0 || autocvar_g_vehicles_max_perplayer <= 0) { print_to(own, "Vehicle spawning is disabled"); return NULL; } + + if (tmp_vehcount >= autocvar_g_vehicles_max) { print_to(own, "The maximum vehicle count has been reached"); return NULL; } + + if (tmp_vehcount >= autocvar_g_vehicles_max_perplayer) { print_to(own, "You can't spawn any more vehicles"); return NULL; } + e.spawnflags = VHF_MULTISLOT; // if this spawnflag isn't, it won't be spawned @@ -1374,5 +1382,7 @@ entity spawnvehicle (entity e, string vehicle, Vehicle veh, entity spawnedby, en // spawn! vehicle_initialize(e, veh, nodrop); + tmp_vehcount++; + return e; } diff --git a/qcsrc/common/vehicles/sv_vehicles.qh b/qcsrc/common/vehicles/sv_vehicles.qh index a28fe077eb..a7d9bf1c46 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qh +++ b/qcsrc/common/vehicles/sv_vehicles.qh @@ -15,6 +15,8 @@ float autocvar_g_vehicles_crush_force = 50; float autocvar_g_vehicles_crush_minspeed = 100; bool autocvar_g_vehicles_delayspawn = true; float autocvar_g_vehicles_delayspawn_jitter = 10; +int autocvar_g_vehicles_max; +int autocvar_g_vehicles_max_perplayer; float autocvar_g_vehicles_allow_bots; int autocvar_g_vehicles_exit_attempts = 25; float autocvar_g_vehicles_thinkrate = 0.1; @@ -95,6 +97,7 @@ const int VHEF_NORMAL = 0; /// User pressed exit key const int VHEF_EJECT = 1; /// User pressed exit key 3 times fast (not implemented) or vehicle is dying const int VHEF_RELEASE = 2; /// Release ownership, client possibly allready dissconnected / went spec / changed team / used "kill" (not implemented) +int tmp_vehcount; float vehicles_exit_running; // macros diff --git a/turrets.cfg b/turrets.cfg index 882af02f96..70576910b6 100644 --- a/turrets.cfg +++ b/turrets.cfg @@ -1,6 +1,8 @@ set g_turrets 1 set g_turrets_reloadcvars 0 set g_turrets_nofire 0 +set g_turrets_max 10 +set g_turrets_max_perplayer 2 set g_turrets_targetscan_mindelay 0.1 "delay target rescanning to lower resource usage" set g_turrets_targetscan_maxdelay 1 "scan at least this often" diff --git a/vehicles.cfg b/vehicles.cfg index 7aa6e888f9..2b2df0ea8a 100644 --- a/vehicles.cfg +++ b/vehicles.cfg @@ -6,6 +6,8 @@ set g_vehicles_steal 1 "allow stealing enemy vehicles in teamplay modes" set g_vehicles_steal_show_waypoint 1 "show a waypoint above the thief" set g_vehicles_delayspawn 1 set g_vehicles_delayspawn_jitter 10 +set g_vehicles_max 10 +set g_vehicles_max_perplayer 2 set g_vehicles_teams 1 "allow team specific vehicles" set g_vehicles_teleportable 0 -- 2.39.2