]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/vehicles/vehicles.qc
No csqc vehicles enabled for now, make raptor aim-lock a bit better when strafing...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / vehicles.qc
index ba7f9a0eca26a68e0fa3a2aa13ceb24f8d760309..cef72363d08f45bb69a3bc167b46ec4a4137aa14 100644 (file)
@@ -10,7 +10,10 @@ void vehicles_clearrturn();
 void vehicles_setreturn();
 
 
-#define MAX_AXH 4
+/** AuxiliaryXhair*
+    Send addictional points of interest to be drawn, to vehicle owner
+**/
+float MAX_AXH = 4;
 .entity AuxiliaryXhair[MAX_AXH];
 
 float SendAuxiliaryXhair(entity to, float sf)
@@ -75,6 +78,7 @@ void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
 
 }
 */
+// End AuxiliaryXhair
 
 void CSQCVehicleSetup(entity own, float vehicle_id)
 {
@@ -85,6 +89,19 @@ 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;
@@ -135,15 +152,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 +176,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 +185,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,6 +198,7 @@ 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)
 {
     self.health -= damage;
@@ -206,17 +227,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 +249,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 +280,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 vehiles 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 +308,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 +356,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 +401,13 @@ void vehicles_enter()
     self.owner          = other;
     self.switchweapon   = other.switchweapon;
 
-    self.vehicle_hudmodel.viewmodelforclient = self.owner;
+    // .viewmodelforclient works better.
+    //self.vehicle_hudmodel.drawonlytoclient = self.owner;
+
+#ifndef VEHICLES_CSQC
+        self.vehicle_hudmodel.viewmodelforclient = self.owner;
+#endif
+
     self.event_damage         = vehicles_damage;
     self.nextthink            = 0;
     self.owner.angles         = self.angles;
@@ -399,7 +430,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;
 
@@ -409,6 +440,7 @@ void vehicles_enter()
     self.team                 = self.owner.team;
     self.flags               -= FL_NOTARGET;
 
+#ifndef VEHICLES_CSQC
     msg_entity = other;
     WriteByte (MSG_ONE, SVC_SETVIEWPORT);
     WriteEntity(MSG_ONE, self.vehicle_viewport);
@@ -427,6 +459,8 @@ void vehicles_enter()
         WriteAngle(MSG_ONE,  self.angles_y);      // yaw
         WriteAngle(MSG_ONE,  0);                  // roll
     }
+#endif
+#endif
 
     vehicles_clearrturn();
 
@@ -445,8 +479,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 +504,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 +525,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;
     }
 }
 
@@ -634,8 +668,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 +677,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,52 +685,17 @@ 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;
 }
 
-//#define VEHICLES_CSQC
-#ifdef VEHICLES_CSQC
-#define VSF_ORG 2
-#define VSF_VEL 4
-#define VSF_ANG 8
-#define VSF_COLORMAP 16
-#define VSF_STAT1 32
-
-float SendVehicle(entity to, float sf)
-{
-       WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE_RACER);
-
-       WriteByte(MSG_ENTITY, self.cnt);
-
-       WriteCoord(MSG_ENTITY, self.origin_x);
-       WriteCoord(MSG_ENTITY, self.origin_y);
-       WriteCoord(MSG_ENTITY, self.origin_z);
-
-       WriteCoord(MSG_ENTITY, self.velocity_x);
-       WriteCoord(MSG_ENTITY, self.velocity_y);
-       WriteCoord(MSG_ENTITY, self.velocity_z);
-
-       WriteAngle(MSG_ENTITY, self.angles_x);
-       WriteAngle(MSG_ENTITY, self.angles_y);
-       WriteAngle(MSG_ENTITY, self.angles_z);
-
-    return TRUE;
-}
-
-void NetLinkVehicle()
-{    
-    self.SendFlags = 0xFFFFFF;
-    Net_LinkEntity(self, FALSE, 0, SendVehicle);    
-}
-#endif
-
 float vehicle_initialize(string  net_name,
                          string  bodymodel,
                          string  topmodel,
@@ -705,27 +704,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!");
@@ -754,7 +754,7 @@ float vehicle_initialize(string  net_name,
     self.iscreature         = TRUE;
     self.hud                = vhud;
 
-    self.customizeentityforclient = vehicles_customizeentityforclient;
+    //self.customizeentityforclient = vehicles_customizeentityforclient;
     self.vehicle_die         = dieproc;
     self.vehicle_exit        = exitfunc;
     self.vehicle_enter       = enterproc;
@@ -800,7 +800,10 @@ float vehicle_initialize(string  net_name,
 
     self.pos1 = self.origin;
     self.pos2 = self.angles;
-
+#ifdef VEHICLES_CSQC
+    if(use_csqc)
+        net_link_vehile();
+#endif
     return TRUE;
 }