]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add cvars to limit spawn counts for vehicles and turrets, plus spawned turrets in...
authorLegendaryGuard <rootuser999@gmail.com>
Mon, 4 Jul 2022 23:12:35 +0000 (01:12 +0200)
committerLegendaryGuard <rootuser999@gmail.com>
Mon, 4 Jul 2022 23:12:35 +0000 (01:12 +0200)
qcsrc/common/turrets/sv_turrets.qc
qcsrc/common/turrets/sv_turrets.qh
qcsrc/common/vehicles/sv_vehicles.qc
qcsrc/common/vehicles/sv_vehicles.qh
turrets.cfg
vehicles.cfg

index 0d4dd74e4a57cedd687d4a53d3a1de744155c359..88804768b14ffb3673b6cb65bd4fc79a596cb07e 100644 (file)
@@ -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)
index a9eb6e25bb467d8902a6e00d98f63b73c21cd6ec..83d971f43c0231e90f3800f1b2a089e8595c8a37 100644 (file)
@@ -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
index c41889a0567e265ac94218aedff486546528b9f6..8a02b47f4de8aab09174baaa499b9a4416d31a3c 100644 (file)
@@ -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;
 }
index a28fe077eb600d4590ba7a5bd09ded25232b2df4..a7d9bf1c469d3fba5c8f248c1e96fb4b8cc31270 100644 (file)
@@ -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
index 882af02f96429ea299930ed8e7f2cd7367aa13bd..70576910b60ffe21e28eabb897427cf0d4cd9568 100644 (file)
@@ -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"
index 7aa6e888f9f0fb4007421595b3fc96ea1b7d7b76..2b2df0ea8ac736ef4d05e75354613418e963f54d 100644 (file)
@@ -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