]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/vehicles/vehicles.qc
Merge branch 'master' into terencehill/vehicles_fixes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / vehicles.qc
index a79fcc62a4e2df25044e7d4a55e7647ecf4273f4..b9740b5d88bfa5bee49fc6589962ef61298ed672 100644 (file)
@@ -16,14 +16,14 @@ void vehicles_return();
 void vehicles_enter();
 void vehicles_touch();
 void vehicles_reset_colors();
-void vehicles_clearrturn();
+void vehicles_clearreturn();
 void vehicles_setreturn();
 
 
 /** AuxiliaryXhair*
     Send additional points of interest to be drawn, to vehicle owner
 **/
-float MAX_AXH = 4;
+const float MAX_AXH = 4;
 .entity AuxiliaryXhair[MAX_AXH];
 
 float SendAuxiliaryXhair(entity to, float sf)
@@ -46,7 +46,7 @@ float SendAuxiliaryXhair(entity to, float sf)
 
 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
 {
-    if (clienttype(own) != CLIENTTYPE_REAL)
+    if (!IS_REAL_CLIENT(own))
         return;
 
     entity axh;
@@ -101,15 +101,15 @@ void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
 **/
 void CSQCVehicleSetup(entity own, float vehicle_id)
 {
-    if (clienttype(own) != CLIENTTYPE_REAL)
+    if (!IS_REAL_CLIENT(own))
         return;
-       
+
        msg_entity = own;
 
        WriteByte(MSG_ONE, SVC_TEMPENTITY);
        WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
        if(vehicle_id != 0)
-           WriteByte(MSG_ONE, vehicle_id);        
+           WriteByte(MSG_ONE, vehicle_id);
        else
         WriteByte(MSG_ONE, 1 + own.vehicle.vehicle_weapon2mode + HUD_VEHICLE_LAST);
 }
@@ -131,7 +131,7 @@ void CSQCVehicleSetup(entity own, float vehicle_id)
 .float  lock_strength;
 .float  lock_time;
 .float  lock_soundtime;
-float  DAMAGE_TARGETDRONE = 10;
+const float    DAMAGE_TARGETDRONE = 10;
 
 vector targetdrone_getnewspot()
 {
@@ -275,7 +275,7 @@ void vehicles_locktarget(float incr, float decr, float _lock_time)
         if(trace_ent.deadflag != DEAD_NO)
             trace_ent = world;
 
-        if not (trace_ent.vehicle_flags & VHF_ISVEHICLE ||
+        if(!trace_ent.vehicle_flags & VHF_ISVEHICLE ||
                                trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET ||
                                trace_ent.takedamage == DAMAGE_TARGETDRONE)
             trace_ent = world;
@@ -442,7 +442,7 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
         proj.flags           = FL_PROJECTILE | FL_NOTARGET;
 
     if(_mzlsound)
-        sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTN_NORM);
+        sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
 
     if(_mzlfx)
         pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
@@ -456,6 +456,30 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
 }
 // End generic vehile projectile system
 
+void vehicles_reset()
+{
+       if(self.owner)
+       {
+               entity oldself = self;
+               self = self.owner;
+               vehicles_exit(VHEF_RELESE);
+               self = oldself;
+       }
+       self.alpha      = -1;
+       self.movetype   = MOVETYPE_NONE;
+       self.effects    = EF_NODRAW;
+       self.colormod  = '0 0 0';
+       self.avelocity = '0 0 0';
+       self.velocity  = '0 0 0';
+       self.event_damage = func_null;
+       self.solid = SOLID_NOT;
+       self.deadflag = DEAD_NO;
+
+       self.touch = func_null;
+       self.nextthink = 0;
+       vehicles_setreturn();
+}
+
 /** vehicles_spawn
     Exetuted for all vehicles on (re)spawn.
     Sets defaults for newly spawned units.
@@ -470,6 +494,7 @@ void vehicles_spawn()
     self.owner              = world;
     self.touch              = vehicles_touch;
     self.event_damage       = vehicles_damage;
+    self.reset              = vehicles_reset;
     self.iscreature         = TRUE;
     self.teleportable       = FALSE; // no teleporting for vehicles, too buggy
     self.damagedbycontents     = TRUE;
@@ -492,10 +517,10 @@ void vehicles_spawn()
     setorigin(self, self.pos1 + '0 0 0');
     // Show it
     pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
-    
+
     if(self.vehicle_controller)
         self.team = self.vehicle_controller.team;
-       
+
     vehicles_reset_colors();
     self.vehicle_spawn(VHSF_NORMAL);
 }
@@ -503,16 +528,16 @@ void vehicles_spawn()
 // Better way of determening whats crushable needed! (fl_crushable?)
 float vehicles_crushable(entity e)
 {
-    if(e.classname == "player")
+    if(IS_PLAYER(e))
         return TRUE;
 
-    if(e.classname == "monster_zombie")
+    if(e.flags & FL_MONSTER)
         return TRUE;
 
     return FALSE;
 }
 
-void vehilces_impact(float _minspeed, float _speedfac, float _maxpain)
+void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
 {
     if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
         return;
@@ -537,6 +562,9 @@ void vehilces_impact(float _minspeed, float _speedfac, float _maxpain)
 .void() vehicle_impact;
 void vehicles_touch()
 {
+       if(MUTATOR_CALLHOOK(VehicleTouch))
+               return;
+
     // Vehicle currently in use
     if(self.owner)
     {
@@ -556,7 +584,7 @@ void vehicles_touch()
         return;
     }
 
-    if(other.classname != "player")
+    if (!IS_PLAYER(other))
         return;
 
     if(other.deadflag != DEAD_NO)
@@ -571,8 +599,8 @@ var float autocvar_g_vehicles_allow_bots = 0;
 void vehicles_enter()
 {
    // Remove this when bots know how to use vehicles
-   
-    if (clienttype(other) == CLIENTTYPE_BOT)    
+
+    if (IS_BOT_CLIENT(other))
         if (autocvar_g_vehicles_allow_bots)
             dprint("Bot enters vehicle\n"); // This is where we need to disconnect (some, all?) normal bot AI and hand over to vehicle's _aiframe()
         else
@@ -628,18 +656,18 @@ void vehicles_enter()
     //self.exteriormodeltoclient = self.owner;
     //self.tur_head.exteriormodeltoclient = self.owner;
 
-    other.flags &~= FL_ONGROUND;
-    self.flags  &~= FL_ONGROUND;
+    other.flags &= ~FL_ONGROUND;
+    self.flags  &= ~FL_ONGROUND;
 
     self.team                 = self.owner.team;
     self.flags               -= FL_NOTARGET;
-    
-    if (clienttype(other) == CLIENTTYPE_REAL)
+
+    if (IS_REAL_CLIENT(other))
     {
         msg_entity = other;
         WriteByte (MSG_ONE, SVC_SETVIEWPORT);
         WriteEntity(MSG_ONE, self.vehicle_viewport);
-                
+
         WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
         if(self.tur_head)
         {
@@ -655,10 +683,10 @@ void vehicles_enter()
         }
     }
 
-    vehicles_clearrturn();
+    vehicles_clearreturn();
 
     CSQCVehicleSetup(self.owner, self.hud);
-    
+
     vh_player = other;
     vh_vehicle = self;
     MUTATOR_CALLHOOK(VehicleEnter);
@@ -732,36 +760,36 @@ void vehicles_exit(float eject)
     entity _vehicle;
     entity _player;
     entity _oldself = self;
-    
+
     if(vehicles_exit_running)
     {
         dprint("^1vehicles_exit allready running! this is not good..\n");
         return;
     }
-    
+
     vehicles_exit_running = TRUE;
-    if(self.flags & FL_CLIENT)
+    if(IS_CLIENT(self))
     {
         _vehicle = self.vehicle;
-            
+
         if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
         {
             _vehicle.vehicle_exit(eject);
             self = _oldself;
             vehicles_exit_running = FALSE;
-            return;            
+            return;
         }
     }
     else
         _vehicle = self;
-    
+
     _player = _vehicle.owner;
-    
+
     self = _vehicle;
 
     if (_player)
     {
-        if (clienttype(_player) == CLIENTTYPE_REAL)
+        if (IS_REAL_CLIENT(_player))
         {
             msg_entity = _player;
             WriteByte (MSG_ONE, SVC_SETVIEWPORT);
@@ -772,13 +800,13 @@ void vehicles_exit(float eject)
             WriteAngle(MSG_ONE, _vehicle.angles_y);
             WriteAngle(MSG_ONE, 0);
         }
-        
+
         setsize(_player, PL_MIN,PL_MAX);
 
         _player.takedamage     = DAMAGE_AIM;
         _player.solid          = SOLID_SLIDEBOX;
         _player.movetype       = MOVETYPE_WALK;
-        _player.effects        &~= EF_NODRAW;
+        _player.effects        &= ~EF_NODRAW;
         _player.alpha          = 1;
         _player.PlayerPhysplug = func_null;
         _player.vehicle        = world;
@@ -790,15 +818,14 @@ void vehicles_exit(float eject)
         CSQCVehicleSetup(_player, HUD_NORMAL);
     }
     _vehicle.flags |= FL_NOTARGET;
-    
+
     if(_vehicle.deadflag == DEAD_NO)
         _vehicle.avelocity          = '0 0 0';
-    
+
     _vehicle.tur_head.nodrawtoclient             = world;
-    
+
     if(!teamplay)
         _vehicle.team = 0;
-    else
 
     vh_player = _player;
     vh_vehicle = _vehicle;
@@ -807,18 +834,18 @@ void vehicles_exit(float eject)
     _vehicle = vh_vehicle;
 
     _vehicle.team = _vehicle.tur_head.team;
-        
-    sound (_vehicle, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTN_NORM);
-    _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;   
+
+    sound (_vehicle, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTEN_NORM);
+    _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
     _vehicle.phase = time + 1;
-    
+
     _vehicle.vehicle_exit(eject);
-    
+
     vehicles_setreturn();
-    vehicles_reset_colors();        
+    vehicles_reset_colors();
     _vehicle.owner = world;
     self = _oldself;
-    
+
     vehicles_exit_running = FALSE;
 }
 
@@ -830,7 +857,7 @@ void vehicles_regen(float timer, .float regen_field, float field_max, float rpau
     {
         if(_healthscale)
             regen = regen * (self.vehicle_health / self.tur_health);
-            
+
         self.regen_field = min(self.regen_field + regen * delta_time, field_max);
 
         if(self.owner)
@@ -878,24 +905,24 @@ void vehicles_painframe()
 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
 {
     self.dmg_time = time;
-    
+
     if(DEATH_ISWEAPON(deathtype, WEP_NEX))
         damage *= autocvar_g_vehicles_nex_damagerate;
-        
+
     if(DEATH_ISWEAPON(deathtype, WEP_UZI))
         damage *= autocvar_g_vehicles_uzi_damagerate;
-        
+
     if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
         damage *= autocvar_g_vehicles_rifle_damagerate;
-        
+
     if(DEATH_ISWEAPON(deathtype, WEP_MINSTANEX))
         damage *= autocvar_g_vehicles_minstanex_damagerate;
 
     if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
         damage *= autocvar_g_vehicles_tag_damagerate;
-    
+
     self.enemy = attacker;
-    
+
     if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
     {
         if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
@@ -914,7 +941,7 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, float deat
         self.vehicle_shieldent.alpha       = 0.45;
         self.vehicle_shieldent.angles      = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
         self.vehicle_shieldent.nextthink   = time;
-        self.vehicle_shieldent.effects &~= EF_NODRAW;
+        self.vehicle_shieldent.effects &= ~EF_NODRAW;
 
         self.vehicle_shield -= damage;
 
@@ -926,11 +953,11 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, float deat
             self.vehicle_shieldent.alpha    = 0.75;
 
                if(sound_allowed(MSG_BROADCAST, attacker))
-                spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);   // FIXME: PLACEHOLDER
+                spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);   // FIXME: PLACEHOLDER
         }
         else
                if(sound_allowed(MSG_BROADCAST, attacker))
-                spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTN_NORM);  // FIXME: PLACEHOLDER
+                spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM);  // FIXME: PLACEHOLDER
 
     }
     else
@@ -938,9 +965,9 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, float deat
         self.vehicle_health -= damage;
 
         if(sound_allowed(MSG_BROADCAST, attacker))
-            spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);  // FIXME: PLACEHOLDER
+            spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);  // FIXME: PLACEHOLDER
     }
-    
+
        if(self.damageforcescale < 1 && self.damageforcescale > 0)
                self.velocity += force * self.damageforcescale;
        else
@@ -962,7 +989,7 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, float deat
     }
 }
 
-void vehicles_clearrturn()
+void vehicles_clearreturn()
 {
     entity ret;
     // Remove "return helper", if any.
@@ -1053,7 +1080,7 @@ void vehicles_setreturn()
 {
     entity ret;
 
-    vehicles_clearrturn();
+    vehicles_clearreturn();
 
     ret = spawn();
     ret.classname   = "vehicle_return";
@@ -1061,19 +1088,16 @@ void vehicles_setreturn()
     ret.team        = self.team;
     ret.think       = vehicles_showwp;
 
-    if(self.deadflag != DEAD_NO)
-    {
-        ret.cnt         = time + self.vehicle_respawntime;
-        ret.nextthink   = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 5);
-    }
-    else
-    {
-        ret.nextthink   = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 1);
-    }
+       if(self.deadflag != DEAD_NO)
+       {
+               ret.cnt = max(game_starttime, time) + self.vehicle_respawntime;
+               ret.nextthink = max(game_starttime, time) + max(0, self.vehicle_respawntime - 5);
+       }
+       else
+               ret.nextthink = max(game_starttime, time) + max(0, self.vehicle_respawntime - 1);
 
     setmodel(ret, "null");
     setorigin(ret, self.pos1 + '0 0 96');
-
 }
 
 void vehicles_reset_colors()
@@ -1131,7 +1155,7 @@ void vehicle_use()
         self.active = ACTIVE_NOT;
     else
         self.active = ACTIVE_ACTIVE;
-    
+
     if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO)
     {
         dprint("^3Eat shit yall!\n");
@@ -1140,18 +1164,18 @@ void vehicle_use()
     }
     else if(self.active == ACTIVE_NOT && self.deadflag != DEAD_NO)
     {
-        
+
     }
 }
 
-float vehicle_addplayerslot(    entity _owner, 
-                                entity _slot, 
-                                float _hud, 
+float vehicle_addplayerslot(    entity _owner,
+                                entity _slot,
+                                float _hud,
                                 string _hud_model,
-                                float() _framefunc, 
+                                float() _framefunc,
                                 void(float) _exitfunc)
 {
-    if not (_owner.vehicle_flags & VHF_MULTISLOT)
+    if (!(_owner.vehicle_flags & VHF_MULTISLOT))
         _owner.vehicle_flags |= VHF_MULTISLOT;
 
     _slot.PlayerPhysplug = _framefunc;
@@ -1162,13 +1186,13 @@ float vehicle_addplayerslot(    entity _owner,
     _slot.vehicle_hudmodel = spawn();
     _slot.vehicle_hudmodel.viewmodelforclient = _slot;
     _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
-    
+
     setmodel(_slot.vehicle_hudmodel, _hud_model);
     setmodel(_slot.vehicle_viewport, "null");
-    
+
     setattachment(_slot.vehicle_hudmodel, _slot, "");
     setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
-    
+
     return TRUE;
 }
 
@@ -1196,7 +1220,7 @@ float vehicle_initialize(string  net_name,
 {
        if(!autocvar_g_vehicles)
                return FALSE;
-       
+
     if(self.targetname)
     {
         self.vehicle_controller = find(world, target, self.targetname);
@@ -1206,19 +1230,19 @@ float vehicle_initialize(string  net_name,
         }
         else
         {
-            self.team = self.vehicle_controller.team;        
+            self.team = self.vehicle_controller.team;
             self.use = vehicle_use;
-            
+
             if(teamplay)
             {
                 if(self.vehicle_controller.team == 0)
                     self.active = ACTIVE_NOT;
                 else
-                    self.active = ACTIVE_ACTIVE;                
+                    self.active = ACTIVE_ACTIVE;
             }
         }
     }
-    
+
     precache_sound("onslaught/ons_hit2.wav");
     precache_sound("onslaught/electricity_explode.wav");
 
@@ -1271,15 +1295,17 @@ float vehicle_initialize(string  net_name,
     self.event_damage        = func_null;
     self.touch               = vehicles_touch;
     self.think               = vehicles_spawn;
-    self.nextthink           = time;
-    self.vehicle_respawntime = _respawntime;
     self.vehicle_spawn       = spawnproc;
+       self.vehicle_respawntime = max(0, _respawntime);
     self.effects             = EF_NODRAW;
-    if(g_assault || !autocvar_g_vehicles_delayspawn)
-        self.nextthink = time + 0.5;
-    else
-        self.nextthink = time + _respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
+       self.dphitcontentsmask   = DPCONTENTS_BODY | DPCONTENTS_SOLID;
+       if(!autocvar_g_vehicles_delayspawn || !self.vehicle_respawntime)
+               self.nextthink = time;
+       else
+               self.nextthink = max(time, game_starttime) + max(0, self.vehicle_respawntime + ((random() * 2 - 1) * autocvar_g_vehicles_delayspawn_jitter));
 
+       if(autocvar_g_playerclip_collisions)
+               self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
 
     if(autocvar_g_nodepthtestplayers)
         self.effects = self.effects | EF_NODEPTHTEST;
@@ -1305,22 +1331,25 @@ float vehicle_initialize(string  net_name,
     }
 
     setsize(self, min_s, max_s);
-    if not (nodrop)
+    if (!nodrop)
     {
         setorigin(self, self.origin);
         tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
         setorigin(self, trace_endpos);
     }
-    
+
     self.pos1 = self.origin;
     self.pos2 = self.angles;
     self.tur_head.team = self.team;
 
+       if(MUTATOR_CALLHOOK(VehicleSpawn))
+               return FALSE;
+
     return TRUE;
 }
 
-vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname, 
-                         float _pichlimit_min, float _pichlimit_max, 
+vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
+                         float _pichlimit_min, float _pichlimit_max,
                          float _rotlimit_min, float _rotlimit_max, float _aimspeed)
 {
     vector vtmp, vtag;
@@ -1332,14 +1361,14 @@ vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string
     ftmp = _aimspeed * frametime;
     vtmp_y = bound(-ftmp, vtmp_y, ftmp);
     vtmp_x = bound(-ftmp, vtmp_x, ftmp);
-    _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);    
+    _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
     _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
     return vtag;
 }
 
 void vehicles_gib_explode()
 {
-       sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
+       sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
        pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
        remove(self);
 }
@@ -1362,23 +1391,23 @@ entity vehicle_tossgib(entity _template, vector _vel, string _tag, float _burn,
        _gib.movetype = MOVETYPE_TOSS;
        _gib.solid = SOLID_CORPSE;
        _gib.colormod = '-0.5 -0.5 -0.5';
-       _gib.effects = EF_LOWPRECISION; 
+       _gib.effects = EF_LOWPRECISION;
        _gib.avelocity = _rot;
-       
+
        if(_burn)
                _gib.effects |= EF_FLAME;
-       
+
        if(_explode)
        {
-               _gib.think = vehicles_gib_explode; 
+               _gib.think = vehicles_gib_explode;
                _gib.nextthink = time + random() * _explode;
                _gib.touch = vehicles_gib_explode;
        }
        else
        {
                _gib.cnt = time + _maxtime;
-               _gib.think = vehicles_gib_think; 
-               _gib.nextthink = time + _maxtime - 1;           
+               _gib.think = vehicles_gib_think;
+               _gib.nextthink = time + _maxtime - 1;
                _gib.alpha = 1;
        }
        return _gib;