]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/vehicles/vehicles.qc
unwops the projetile damage fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / vehicles.qc
index e94e73b57ba5c86eb4bd92517b04960fb8f723c1..69c0f87e51f23528c0fd5caeffb32f3844dc2f29 100644 (file)
@@ -1,5 +1,7 @@
 float autocvar_g_vehicles_crush_dmg;
 float autocvar_g_vehicles_crush_force;
+float autocvar_g_vehicles_delayspawn;
+float autocvar_g_vehicles_delayspawn_jitter;
 
 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
 void vehicles_return();
@@ -10,7 +12,10 @@ void vehicles_clearrturn();
 void vehicles_setreturn();
 
 
-#define MAX_AXH 4
+/** AuxiliaryXhair*
+    Send additional points of interest to be drawn, to vehicle owner
+**/
+float MAX_AXH = 4;
 .entity AuxiliaryXhair[MAX_AXH];
 
 float SendAuxiliaryXhair(entity to, float sf)
@@ -75,7 +80,14 @@ void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
 
 }
 */
-
+// End AuxiliaryXhair
+
+/**
+    Notifies the client that he enterd a vehicle, and sends 
+    realavent data.
+    
+    only sends vehicle_id atm (wich is a HUD_* constant, ex. HUD_SPIDERBOT)
+**/
 void CSQCVehicleSetup(entity own, float vehicle_id)
 {
        msg_entity = own;
@@ -85,9 +97,23 @@ void CSQCVehicleSetup(entity own, float vehicle_id)
        WriteByte(MSG_ONE, vehicle_id);
 }
 
+/** vehicles_locktarget
+
+    Generic target locking.
+
+    Figure out if what target is "locked" (if any), for missile tracking as such.
+
+    after calling, "if(self.lock_target != world && self.lock_strength == 1)" mean
+    you have a locked in target.
+
+    Exspects a crosshair_trace() or equivalent to be
+    dont before calling.
+
+**/
 .entity lock_target;
 .float  lock_strength;
 .float  lock_time;
+.float  lock_soundtime;
 void vehicles_locktarget(float incr, float decr, float _lock_time)
 {
     if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
@@ -98,7 +124,16 @@ void vehicles_locktarget(float incr, float decr, float _lock_time)
     }
 
     if(self.lock_time > time)
+    {
+        if(self.lock_target)
+        if(self.lock_soundtime < time)
+        {
+            self.lock_soundtime = time + 0.5;
+            play2(self.owner, "vehicles/locked.wav");
+        }
+        
         return;
+    }
 
     if(trace_ent != world)
     {
@@ -114,7 +149,22 @@ void vehicles_locktarget(float incr, float decr, float _lock_time)
 
     if(self.lock_target == world && trace_ent != world)
         self.lock_target = trace_ent;
-
+    
+    if(self.lock_target && trace_ent == self.lock_target) 
+    {            
+        if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
+        {
+            play2(self.owner, "vehicles/lock.wav");
+            self.lock_soundtime = time + 0.8;
+        }        
+        else if (self.lock_strength != 1 && self.lock_soundtime < time)
+        {            
+            play2(self.owner, "vehicles/locking.wav");
+            self.lock_soundtime = time + 0.3;
+        }
+        
+    }    
+        
     // Have a locking target
     // Trace hit current target
     if(trace_ent == self.lock_target && trace_ent != world)
@@ -135,15 +185,15 @@ void vehicles_locktarget(float incr, float decr, float _lock_time)
     }
 }
 
-
 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
-self.owner.vehicle_##fld = self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld
+self.owner.vehicle_##fld = (self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100
 
 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
 if(trace_fraction != 1) \
     acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
 
+// Hover movement support
 float  force_fromtag_power;
 float  force_fromtag_normpower;
 vector force_fromtag_origin;
@@ -159,6 +209,8 @@ vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float
     return v_forward  * force_fromtag_power;
 }
 
+// Experimental hovermode wich uses attraction/repulstion from surface insted of gravity/repulsion
+// Can possibly be use to move abt any surface (inclusing walls/celings)
 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
 {
 
@@ -166,6 +218,7 @@ vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float
     v_forward  = normalize(v_forward) * -1;
     traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
 
+    // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
     if(trace_fraction == 1.0)
     {
         force_fromtag_normpower = -0.25;
@@ -178,8 +231,13 @@ vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float
     return v_forward  * force_fromtag_power;
 }
 
+// Generic vehile projectile system
 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
 {
+    // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
+    if(inflictor.owner == self.owner)
+        return; 
+    
     self.health -= damage;
     self.velocity += force;
     if(self.health < 1)
@@ -206,17 +264,16 @@ void vehicles_projectile_explode()
        PROJECTILE_TOUCH;
 
        self.event_damage = SUB_Null;
-    sound (self, CHAN_PROJECTILE, self.target2, VOL_BASE, ATTN_NORM);
-    pointparticles(particleeffectnum(self.target3), findbetterlocation (self.origin, 16), '0 0 0', 1);
     RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
 
     remove (self);
 }
 
-entity vehicles_projectile(string _impactfx, string _impactsnd, string _mzlfx, string _mzlsound,
+entity vehicles_projectile(string _mzlfx, string _mzlsound,
                            vector _org, vector _vel,
                            float _dmg, float _radi, float _force,  float _size,
-                           float _deahtype, float _projtype, float _health)
+                           float _deahtype, float _projtype, float _health,
+                           float _cull, float _clianim)
 {
     entity proj;
 
@@ -229,8 +286,6 @@ entity vehicles_projectile(string _impactfx, string _impactsnd, string _mzlfx, s
     proj.shot_radius      = _radi;
     proj.shot_force       = _force;
     proj.totalfrags       = _deahtype;
-    proj.target2          = _impactsnd;
-    proj.target3          = _impactfx;
     proj.solid            = SOLID_BBOX;
     proj.movetype         = MOVETYPE_FLYMISSILE;
     proj.flags            = FL_PROJECTILE;
@@ -262,17 +317,23 @@ entity vehicles_projectile(string _impactfx, string _impactsnd, string _mzlfx, s
 
     setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
 
-    CSQCProjectile(proj, TRUE, _projtype, TRUE);
+    CSQCProjectile(proj, _clianim, _projtype, _cull);
 
     return proj;
 }
+// End generic vehile projectile system
 
+/** vehicles_spawn
+    Exetuted for all vehicles on (re)spawn.
+    Sets defaults for newly spawned units.
+**/
 void vehicles_spawn()
 {
     dprint("Spawning vehicle: ", self.netname, "\n");
 
     // De-own & reset
     self.vehicle_hudmodel.viewmodelforclient = self;
+
     self.owner              = world;
     self.touch              = vehicles_touch;
     self.event_damage       = vehicles_damage;
@@ -284,6 +345,7 @@ void vehicles_spawn()
     self.bot_attack         = TRUE;
     self.flags              = FL_NOTARGET;
     self.avelocity          = '0 0 0';
+    self.velocity           = '0 0 0';
 
     // Reset locking
     self.lock_strength      = 0;
@@ -331,7 +393,7 @@ void vehicles_touch()
             else if(vehicles_crushable(other))
             {
                 if(vlen(self.velocity) != 0)
-                    Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_SBCRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
+                    Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VHCRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
             }
         }
         return;
@@ -376,7 +438,11 @@ void vehicles_enter()
     self.owner          = other;
     self.switchweapon   = other.switchweapon;
 
+    // .viewmodelforclient works better.
+    //self.vehicle_hudmodel.drawonlytoclient = self.owner;
+
     self.vehicle_hudmodel.viewmodelforclient = self.owner;
+
     self.event_damage         = vehicles_damage;
     self.nextthink            = 0;
     self.owner.angles         = self.angles;
@@ -399,7 +465,7 @@ void vehicles_enter()
     self.owner.vehicle_reload1  = self.vehicle_reload1;
     self.owner.vehicle_reload2  = self.vehicle_reload2;
 
-    // Cnnt do this, hides attached objects too.
+    // Cant do this, hides attached objects too.
     //self.exteriormodeltoclient = self.owner;
     //self.tur_head.exteriormodeltoclient = self.owner;
 
@@ -435,8 +501,65 @@ void vehicles_enter()
     self.vehicle_enter();
 }
 
-void vehicles_exit(float eject)
+/** vehicles_findgoodexit
+    Locates a valid location for the player to exit the vehicle.
+    Will first try prefer_spot, then up 100 random spots arround the vehicle
+    wich are in direct line of sight and empty enougth to hold a players bbox
+**/
+vector vehicles_findgoodexit(vector prefer_spot)
 {
+    vector exitspot;
+    float mysize;
+    
+    tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
+    if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
+        return prefer_spot;
+    
+    mysize = vlen(self.maxs - self.mins);
+    float i;
+    vector v, v2;
+    v2 = 0.5 * (self.absmin + self.absmax);
+    for(i = 0; i < 100; ++i)
+    {        
+        v = randomvec();
+        v_z = 0;
+        v = v2 + normalize(v) * mysize;
+        tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
+        if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
+            return v;
+    }
+    
+    /*
+    exitspot = (self.origin + '0 0 48') + v_forward * mysize;
+    tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
+    if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
+        return exitspot;
+    
+    exitspot = (self.origin + '0 0 48') - v_forward * mysize;
+    tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
+    if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
+        return exitspot;
+
+    exitspot = (self.origin + '0 0 48') + v_right * mysize;
+    tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
+    if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
+        return exitspot;
+    
+    exitspot = (self.origin + '0 0 48') - v_right * mysize;
+    tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
+    if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
+        return exitspot;
+    */
+    
+    return self.origin;
+}
+
+/** vehicles_exit
+    Standarrd vehicle release fucntion.
+    custom code goes in self.vehicle_exit
+**/
+void vehicles_exit(float eject)
+{      
        self.flags |= FL_NOTARGET;
 
     if (self.owner)
@@ -445,8 +568,8 @@ void vehicles_exit(float eject)
         WriteByte (MSG_ONE, SVC_SETVIEWPORT);
         WriteEntity( MSG_ONE, self.owner);
 
-        WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
-        WriteAngle(MSG_ONE, 0);                 // tilt
+        WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
+        WriteAngle(MSG_ONE, 0);                 // pich
         WriteAngle(MSG_ONE, self.angles_y);     // yaw
         WriteAngle(MSG_ONE, 0);                 // roll
 
@@ -470,7 +593,7 @@ void vehicles_exit(float eject)
         self.avelocity          = '0 0 0';
 
     self.vehicle_hudmodel.viewmodelforclient = self;
-       self.tur_head.nodrawtoclient             = self;
+       self.tur_head.nodrawtoclient             = world;
     vehicles_setreturn();
 
     self.phase = time + 1;
@@ -491,7 +614,7 @@ void vehicles_regen(.float timer, .float regen_field, float field_max, float rpa
         self.regen_field = min(self.regen_field + regen * delta_time, field_max);
 
         if(self.owner)
-            self.owner.regen_field = self.regen_field / field_max;
+            self.owner.regen_field = (self.regen_field / field_max) * 100;
     }
 }
 
@@ -585,7 +708,6 @@ void vehicles_clearrturn()
             ret.nextthink   = time + 0.1;
             return;
         }
-
         ret = ret.chain;
     }
 }
@@ -601,15 +723,7 @@ void vehicles_setreturn()
     ret.enemy       = self;
     ret.think       = vehicles_return;
     ret.nextthink   = time + self.vehicle_respawntime;
-}
-
-float vehicles_customizeentityforclient()
-{
-    if(self.deadflag  == DEAD_DEAD)
-        return FALSE;
-    else
-        return TRUE;
-}
+} 
 
 void vehicles_configcheck(string  configname, float check_cvar)
 {
@@ -634,8 +748,8 @@ void vehicles_reset_colors()
     else
         _colormap = 1024;
 
-    _glowmod    = '0 0 0';
-    _colormod   = '0 0 0';
+    _glowmod  = '0 0 0';
+    _colormod = '0 0 0';
 
     // Find all ents attacked to main model and setup effects, colormod etc.
     e = findchainentity(tag_entity, self);
@@ -643,7 +757,7 @@ void vehicles_reset_colors()
     {
         if(e != self.vehicle_shieldent)
         {
-            e.effects   = _effects;
+            e.effects   = _effects  | EF_LOWPRECISION;
             e.colormod  = _colormod;
             e.colormap  = _colormap;
             e.alpha     = 1;
@@ -651,14 +765,15 @@ void vehicles_reset_colors()
         e = e.chain;
     }
 
-    self.vehicle_hudmodel.effects  = self.effects  = _effects;
+    self.vehicle_hudmodel.effects  = self.effects  = _effects | EF_LOWPRECISION;
     self.vehicle_hudmodel.colormod = self.colormod = _colormod;
     self.vehicle_hudmodel.colormap = self.colormap = _colormap;
+    self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
 
-    self.alpha          = 1;
-    self.avelocity      = '0 0 0';
-    self.velocity       = '0 0 0';
-
+    self.alpha     = 1;
+    self.avelocity = '0 0 0';
+    self.velocity  = '0 0 0';
+    self.effects   = _effects;
 }
 
 float vehicle_initialize(string  net_name,
@@ -669,27 +784,28 @@ float vehicle_initialize(string  net_name,
                          string  hudtag,
                          string  viewtag,
                          float   vhud,
-                         vector min_s,
-                         vector max_s,
-                         float  nodrop,
+                         vector  min_s,
+                         vector  max_s,
+                         float   nodrop,
                          void()  spawnproc,
                          float   _respawntime,
                          float() physproc,
                          void()  enterproc,
                          void(float extflag) exitfunc,
                          void() dieproc,
-                         void() thinkproc )
+                         void() thinkproc,
+                         float  use_csqc)
 {
     addstat(STAT_HUD, AS_INT,  hud);
-       addstat(STAT_VEHICLESTAT_HEALTH,  AS_FLOAT, vehicle_health);
-       addstat(STAT_VEHICLESTAT_SHIELD,  AS_FLOAT, vehicle_shield);
-       addstat(STAT_VEHICLESTAT_ENERGY,  AS_FLOAT, vehicle_energy);
+       addstat(STAT_VEHICLESTAT_HEALTH,  AS_INT, vehicle_health);
+       addstat(STAT_VEHICLESTAT_SHIELD,  AS_INT, vehicle_shield);
+       addstat(STAT_VEHICLESTAT_ENERGY,  AS_INT, vehicle_energy);
 
        addstat(STAT_VEHICLESTAT_AMMO1,   AS_INT,   vehicle_ammo1);
-       addstat(STAT_VEHICLESTAT_RELOAD1, AS_FLOAT, vehicle_reload1);
+       addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
 
        addstat(STAT_VEHICLESTAT_AMMO2,   AS_INT,   vehicle_ammo2);
-       addstat(STAT_VEHICLESTAT_RELOAD2, AS_FLOAT, vehicle_reload2);
+       addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
 
     if(bodymodel == "")
         error("vehicles: missing bodymodel!");
@@ -718,15 +834,14 @@ float vehicle_initialize(string  net_name,
     self.iscreature         = TRUE;
     self.hud                = vhud;
 
-    self.customizeentityforclient = vehicles_customizeentityforclient;
     self.vehicle_die         = dieproc;
     self.vehicle_exit        = exitfunc;
     self.vehicle_enter       = enterproc;
     self.PlayerPhysplug      = physproc;
     self.event_damage        = vehicles_damage;
     self.touch               = vehicles_touch;
-    self.think               = vehicles_spawn;
-    self.nextthink           = time;
+    self.think               = vehicles_spawn;    
+    self.nextthink           = time;        
     self.vehicle_respawntime = _respawntime;
     self.vehicle_spawn       = spawnproc;
 
@@ -768,7 +883,6 @@ float vehicle_initialize(string  net_name,
     return TRUE;
 }
 
-
 void bugmenot()
 {
     self.vehicle_exit       = self.vehicle_exit;