Merge branch 'master' into TimePath/csqc_viewmodels
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 29 Nov 2015 22:59:11 +0000 (09:59 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 29 Nov 2015 23:32:37 +0000 (10:32 +1100)
# Conflicts:
# qcsrc/client/weapons/projectile.qc
# qcsrc/common/stats.qh
# qcsrc/common/weapons/all.qc
# qcsrc/common/weapons/weapon.qh
# qcsrc/server/defs.qh
# qcsrc/server/g_subs.qh
# qcsrc/server/g_world.qc

25 files changed:
qcsrc/Makefile
qcsrc/client/progs.inc
qcsrc/client/view.qc
qcsrc/client/weapons/projectile.qc
qcsrc/common/anim.qc [new file with mode: 0644]
qcsrc/common/anim.qh [new file with mode: 0644]
qcsrc/common/stats.qh
qcsrc/common/triggers/subs.qh
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/all.qh
qcsrc/common/weapons/weapon.qh
qcsrc/common/weapons/weapon/arc.qc
qcsrc/common/weapons/weapon/rifle.qc
qcsrc/lib/_all.inc
qcsrc/lib/enumclass.qh [new file with mode: 0644]
qcsrc/lib/vector.qh
qcsrc/server/cl_client.qc
qcsrc/server/cl_player.qc
qcsrc/server/defs.qh
qcsrc/server/g_subs.qc
qcsrc/server/g_subs.qh
qcsrc/server/g_world.qc
qcsrc/server/progs.inc
qcsrc/server/weapons/weaponsystem.qc
qcsrc/server/weapons/weaponsystem.qh

index 452dfc9a6451ad219bfcfd3b84c9a06b924c504f..b5b77e09ba392461593e1237d834119f90a728ba 100644 (file)
@@ -22,6 +22,7 @@ QCCFLAGS ?= \
        -fftepp -flno -futf8 -fno-bail-on-werror -fftepp-predefs \
        -frelaxed-switch -freturn-assignments \
        $(QCCFLAGS_WATERMARK) \
+       -DNDEBUG=1 \
        $(QCCFLAGS_FEATURES) \
        $(QCCFLAGS_EXTRA)
 
index 4a6b587882c744ae15e9c16036025acbbca336d6..8c443568ea206ed16e5fcc6b9919feff6cb083a0 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "weapons/projectile.qc" // TODO
 
+#include "../common/anim.qc"
 #include "../common/animdecide.qc"
 #include "../common/effects/effectinfo.qc"
 #include "../common/ent_cs.qc"
index c98400df56760fb56814319b836458b39a0ecb44..a6d05d9a62cd24ca8a9ea2f15f75b353b79feb55 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "mutators/events.qh"
 
+#include "../common/anim.qh"
 #include "../common/constants.qh"
 #include "../common/debug.qh"
 #include "../common/mapinfo.qh"
 #include "../lib/warpzone/client.qh"
 #include "../lib/warpzone/common.qh"
 
+#define EFMASK_CHEAP (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NODRAW | EF_NOSHADOW | EF_SELECTABLE | EF_TELEPORT_BIT)
+
+float autocvar_cl_viewmodel_scale;
+
+bool autocvar_cl_bobmodel;
+float autocvar_cl_bobmodel_speed;
+float autocvar_cl_bobmodel_side;
+float autocvar_cl_bobmodel_up;
+
+float autocvar_cl_followmodel;
+float autocvar_cl_followmodel_side_speed;
+float autocvar_cl_followmodel_side_highpass;
+float autocvar_cl_followmodel_side_highpass1;
+float autocvar_cl_followmodel_side_limit;
+float autocvar_cl_followmodel_side_lowpass;
+float autocvar_cl_followmodel_up_speed;
+float autocvar_cl_followmodel_up_highpass;
+float autocvar_cl_followmodel_up_highpass1;
+float autocvar_cl_followmodel_up_limit;
+float autocvar_cl_followmodel_up_lowpass;
+
+float autocvar_cl_leanmodel;
+float autocvar_cl_leanmodel_side_speed;
+float autocvar_cl_leanmodel_side_highpass;
+float autocvar_cl_leanmodel_side_highpass1;
+float autocvar_cl_leanmodel_side_lowpass;
+float autocvar_cl_leanmodel_side_limit;
+float autocvar_cl_leanmodel_up_speed;
+float autocvar_cl_leanmodel_up_highpass;
+float autocvar_cl_leanmodel_up_highpass1;
+float autocvar_cl_leanmodel_up_lowpass;
+float autocvar_cl_leanmodel_up_limit;
+
+#define lowpass(value, frac, ref_store, ret) do \
+{ \
+       float __frac = bound(0, frac, 1); \
+       ret = ref_store = ref_store * (1 - __frac) + (value) * __frac; \
+} while (0)
+
+#define lowpass_limited(value, frac, limit, ref_store, ret) do \
+{ \
+       float __ignore; lowpass(value, frac, ref_store, __ignore); \
+       ret = ref_store = bound((value) - (limit), ref_store, (value) + (limit)); \
+} while (0)
+
+#define highpass(value, frac, ref_store, ret) do \
+{ \
+       float __f; lowpass(value, frac, ref_store, __f); \
+       ret = (value) - __f; \
+} while (0)
+
+#define highpass_limited(value, frac, limit, ref_store, ret) do \
+{ \
+       float __f; lowpass_limited(value, frac, limit, ref_store, __f); \
+       ret = (value) - __f; \
+} while (0)
+
+#define lowpass3(value, fracx, fracy, fracz, ref_store, ref_out) do \
+{ \
+       lowpass(value.x, fracx, ref_store.x, ref_out.x); \
+       lowpass(value.y, fracy, ref_store.y, ref_out.y); \
+       lowpass(value.z, fracz, ref_store.z, ref_out.z); \
+} while (0)
+
+#define highpass3(value, fracx, fracy, fracz, ref_store, ref_out) do \
+{ \
+       highpass(value.x, fracx, ref_store.x, ref_out.x); \
+       highpass(value.y, fracy, ref_store.y, ref_out.y); \
+       highpass(value.z, fracz, ref_store.z, ref_out.z); \
+} while (0)
+
+#define highpass3_limited(value, fracx, limitx, fracy, limity, fracz, limitz, ref_store, ref_out) do \
+{ \
+       highpass_limited(value.x, fracx, limitx, ref_store.x, ref_out.x); \
+       highpass_limited(value.y, fracy, limity, ref_store.y, ref_out.y); \
+       highpass_limited(value.z, fracz, limitz, ref_store.z, ref_out.z); \
+} while (0)
+
+void viewmodel_animate(entity this)
+{
+       static float prevtime;
+       float frametime = (time - prevtime) * STAT(MOVEVARS_TIMESCALE);
+       prevtime = time;
+
+       if (autocvar_chase_active) return;
+       if (getstati(STAT_HEALTH) <= 0) return;
+
+       entity view = CSQCModel_server2csqc(player_localentnum - 1);
+
+       bool clonground = !(view.anim_implicit_state & ANIMIMPLICITSTATE_INAIR);
+       static bool oldonground;
+       static float hitgroundtime;
+       static float lastongroundtime;
+       if (clonground)
+       {
+               float f = time; // cl.movecmd[0].time
+               if (!oldonground)
+                       hitgroundtime = f;
+               lastongroundtime = f;
+       }
+       oldonground = clonground;
+
+       vector gunorg = '0 0 0', gunangles = '0 0 0';
+       static vector gunorg_prev = '0 0 0', gunangles_prev = '0 0 0';
+
+       bool teleported = view.csqcmodel_teleported;
+
+       // 1. if we teleported, clear the frametime... the lowpass will recover the previous value then
+       if (teleported)
+       {
+               // try to fix the first highpass; result is NOT
+               // perfect! TODO find a better fix
+               gunangles_prev = view_angles;
+               gunorg_prev = view_origin;
+       }
+
+       static vector gunorg_highpass = '0 0 0';
+
+       // 2. for the gun origin, only keep the high frequency (non-DC) parts, which is "somewhat like velocity"
+       gunorg_highpass += gunorg_prev;
+       highpass3_limited(view_origin,
+               frametime * autocvar_cl_followmodel_side_highpass1, autocvar_cl_followmodel_side_limit,
+               frametime * autocvar_cl_followmodel_side_highpass1, autocvar_cl_followmodel_side_limit,
+               frametime * autocvar_cl_followmodel_up_highpass1, autocvar_cl_followmodel_up_limit,
+               gunorg_highpass, gunorg);
+       gunorg_prev = view_origin;
+       gunorg_highpass -= gunorg_prev;
+
+       static vector gunangles_highpass = '0 0 0';
+
+       // in the highpass, we _store_ the DIFFERENCE to the actual view angles...
+       gunangles_highpass += gunangles_prev;
+       PITCH(gunangles_highpass) += 360 * floor((PITCH(view_angles) - PITCH(gunangles_highpass)) / 360 + 0.5);
+       YAW(gunangles_highpass) += 360 * floor((YAW(view_angles) - YAW(gunangles_highpass)) / 360 + 0.5);
+       ROLL(gunangles_highpass) += 360 * floor((ROLL(view_angles) - ROLL(gunangles_highpass)) / 360 + 0.5);
+       highpass3_limited(view_angles,
+               frametime * autocvar_cl_leanmodel_up_highpass1, autocvar_cl_leanmodel_up_limit,
+               frametime * autocvar_cl_leanmodel_side_highpass1, autocvar_cl_leanmodel_side_limit,
+               0, 0,
+               gunangles_highpass, gunangles);
+       gunangles_prev = view_angles;
+       gunangles_highpass -= gunangles_prev;
+
+       // 3. calculate the RAW adjustment vectors
+       gunorg.x *= (autocvar_cl_followmodel ? -autocvar_cl_followmodel_side_speed : 0);
+       gunorg.y *= (autocvar_cl_followmodel ? -autocvar_cl_followmodel_side_speed : 0);
+       gunorg.z *= (autocvar_cl_followmodel ? -autocvar_cl_followmodel_up_speed : 0);
+
+       PITCH(gunangles) *= (autocvar_cl_leanmodel ? -autocvar_cl_leanmodel_up_speed : 0);
+       YAW(gunangles) *= (autocvar_cl_leanmodel ? -autocvar_cl_leanmodel_side_speed : 0);
+       ROLL(gunangles) = 0;
+
+       static vector gunorg_adjustment_highpass;
+       static vector gunorg_adjustment_lowpass;
+       static vector gunangles_adjustment_highpass;
+       static vector gunangles_adjustment_lowpass;
+
+       // 4. perform highpass/lowpass on the adjustment vectors (turning velocity into acceleration!)
+       //    trick: we must do the lowpass LAST, so the lowpass vector IS the final vector!
+       highpass3(gunorg,
+               frametime * autocvar_cl_followmodel_side_highpass,
+               frametime * autocvar_cl_followmodel_side_highpass,
+               frametime * autocvar_cl_followmodel_up_highpass,
+               gunorg_adjustment_highpass, gunorg);
+       lowpass3(gunorg,
+               frametime * autocvar_cl_followmodel_side_lowpass,
+               frametime * autocvar_cl_followmodel_side_lowpass,
+               frametime * autocvar_cl_followmodel_up_lowpass,
+               gunorg_adjustment_lowpass, gunorg);
+       // we assume here: PITCH = 0, YAW = 1, ROLL = 2
+       highpass3(gunangles,
+               frametime * autocvar_cl_leanmodel_up_highpass,
+               frametime * autocvar_cl_leanmodel_side_highpass,
+               0,
+               gunangles_adjustment_highpass, gunangles);
+       lowpass3(gunangles,
+               frametime * autocvar_cl_leanmodel_up_lowpass,
+               frametime * autocvar_cl_leanmodel_side_lowpass,
+               0,
+               gunangles_adjustment_lowpass, gunangles);
+       float xyspeed = bound(0, vlen(vec2(view.velocity)), 400);
+
+       // vertical view bobbing code
+       // TODO: cl_bob
+
+       // horizontal view bobbing code
+       // TODO: cl_bob2
+
+       // fall bobbing code
+       // causes the view to swing down and back up when touching the ground
+       // TODO: cl_bobfall
+
+       // gun model bobbing code
+       if (autocvar_cl_bobmodel)
+       {
+               // calculate for swinging gun model
+               // the gun bobs when running on the ground, but doesn't bob when you're in the air.
+               // Sajt: I tried to smooth out the transitions between bob and no bob, which works
+               // for the most part, but for some reason when you go through a message trigger or
+               // pick up an item or anything like that it will momentarily jolt the gun.
+               vector forward, right, up;
+               float bspeed;
+               float t = 1;
+               float s = time * autocvar_cl_bobmodel_speed;
+               if (clonground)
+               {
+                       if (time - hitgroundtime < 0.2)
+                       {
+                               // just hit the ground, speed the bob back up over the next 0.2 seconds
+                               t = time - hitgroundtime;
+                               t = bound(0, t, 0.2);
+                               t *= 5;
+                       }
+               }
+               else
+               {
+                       // recently left the ground, slow the bob down over the next 0.2 seconds
+                       t = time - lastongroundtime;
+                       t = 0.2 - bound(0, t, 0.2);
+                       t *= 5;
+               }
+               bspeed = xyspeed * 0.01;
+               MAKEVECTORS(makevectors, gunangles, forward, right, up);
+               float bobr = bspeed * autocvar_cl_bobmodel_side * autocvar_cl_viewmodel_scale * sin(s) * t;
+               gunorg += bobr * right;
+               float bobu = bspeed * autocvar_cl_bobmodel_up * autocvar_cl_viewmodel_scale * cos(s * 2) * t;
+               gunorg += bobu * up;
+       }
+       this.origin += view_forward * gunorg.x + view_right * gunorg.y + view_up * gunorg.z;
+       gunangles.x = -gunangles.x; // pitch was inverted, now that actually matters
+       this.angles += gunangles;
+}
+
+.vector viewmodel_origin, viewmodel_angles;
+
+void viewmodel_draw(entity this)
+{
+       int mask = (intermission || (getstati(STAT_HEALTH) <= 0) || autocvar_chase_active) ? 0 : MASK_NORMAL;
+       float a = this.alpha;
+       int c = stof(getplayerkeyvalue(current_player, "colors"));
+       vector g = this.glowmod; // TODO: completely clientside: colormapPaletteColor(c & 0x0F, true) * 2;
+       entity me = CSQCModel_server2csqc(player_localentnum - 1);
+       int fx = ((me.csqcmodel_effects & EFMASK_CHEAP)
+               | EF_NODEPTHTEST)
+               &~ (EF_FULLBRIGHT); // can mask team color, so get rid of it
+       for (entity e = this; e; e = e.weaponchild)
+       {
+               e.drawmask = mask;
+               e.alpha = a;
+               e.colormap = c;
+               e.glowmod = g;
+               e.csqcmodel_effects = fx;
+               WITH(entity, self, e, CSQCModel_Effects_Apply());
+       }
+       {
+               static string name_last;
+               string name = Weapons_from(activeweapon).mdl;
+               if (name != name_last)
+               {
+                       name_last = name;
+                       CL_WeaponEntity_SetModel(this, name);
+                       this.viewmodel_origin = this.origin;
+                       this.viewmodel_angles = this.angles;
+               }
+               anim_update(this);
+               if (!this.animstate_override)
+                       anim_set(this, this.anim_idle, true, false, false);
+       }
+       float eta = (STAT(WEAPON_NEXTTHINK) - time); // TODO: / W_WeaponRateFactor();
+       float f = 0; // 0..1; 0: fully active
+       switch (this.state)
+       {
+               case WS_RAISE:
+               {
+                       // entity newwep = Weapons_from(activeweapon);
+                       float delay = 0.2; // TODO: newwep.switchdelay_raise;
+                       f = eta / max(eta, delay);
+                       break;
+               }
+               case WS_DROP:
+               {
+                       // entity oldwep = Weapons_from(activeweapon);
+                       float delay = 0.2; // TODO: newwep.switchdelay_drop;
+                       f = 1 - eta / max(eta, delay);
+                       break;
+               }
+               case WS_CLEAR:
+               {
+                       f = 1;
+                       break;
+               }
+       }
+       this.origin = this.viewmodel_origin;
+       this.angles = this.viewmodel_angles;
+       this.angles_x = (-90 * f * f);
+       viewmodel_animate(this);
+       setorigin(this, this.origin);
+}
+
+entity viewmodel;
+STATIC_INIT(viewmodel) {
+    viewmodel = new(viewmodel);
+       viewmodel.draw = viewmodel_draw;
+}
+
 entity porto;
 vector polyline[16];
 void Porto_Draw(entity this)
index 1591bad96b5ccba33b54f72a29acbb93cf1bad3f..2100c3f5fd41d4680937b0adfc63ff7c10cf642e 100644 (file)
@@ -280,46 +280,46 @@ NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
                self.traileffect = 0;
                switch (self.cnt)
                {
-                       #define CASE(id) case PROJECTILE_##id: setmodel(self, MDL_PROJECTILE_##id);
-                       CASE(ELECTRO)            self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
-                       CASE(ROCKET)             self.traileffect = EFFECT_TR_ROCKET.m_id; self.scale = 2; break;
-                       CASE(CRYLINK)            self.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
-                       CASE(CRYLINK_BOUNCING)   self.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
-                       CASE(ELECTRO_BEAM)       self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
-                       CASE(GRENADE)            self.traileffect = EFFECT_TR_GRENADE.m_id; break;
-                       CASE(GRENADE_BOUNCING)   self.traileffect = EFFECT_TR_GRENADE.m_id; break;
-                       CASE(MINE)               self.traileffect = EFFECT_TR_GRENADE.m_id; break;
-                       CASE(BLASTER)            self.traileffect = EFFECT_Null.m_id; break;
-                       CASE(HLAC)               self.traileffect = EFFECT_Null.m_id; break;
-                       CASE(PORTO_RED)          self.traileffect = EFFECT_TR_WIZSPIKE.m_id; self.scale = 4; break;
-                       CASE(PORTO_BLUE)         self.traileffect = EFFECT_TR_WIZSPIKE.m_id; self.scale = 4; break;
-                       CASE(HOOKBOMB)           self.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
-                       CASE(HAGAR)              self.traileffect = EFFECT_HAGAR_ROCKET.m_id; self.scale = 0.75; break;
-                       CASE(HAGAR_BOUNCING)     self.traileffect = EFFECT_HAGAR_ROCKET.m_id; self.scale = 0.75; break;
-                       CASE(FIREBALL)           self.modelindex = 0; self.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
-                       CASE(FIREMINE)           self.modelindex = 0; self.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
-                       CASE(TAG)                self.traileffect = EFFECT_TR_ROCKET.m_id; break;
-                       CASE(FLAC)               self.scale = 0.4; self.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
-                       CASE(SEEKER)             self.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
-
-                       CASE(MAGE_SPIKE)         self.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
-                       CASE(SHAMBLER_LIGHTNING) self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
-
-                       CASE(RAPTORBOMB)         self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = EFFECT_Null.m_id; break;
-                       CASE(RAPTORBOMBLET)      self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = EFFECT_Null.m_id; break;
-                       CASE(RAPTORCANNON)       self.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
-
-                       CASE(SPIDERROCKET)       self.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
-                       CASE(WAKIROCKET)         self.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
-                       CASE(WAKICANNON)         self.traileffect = EFFECT_Null.m_id; break;
-
-                       CASE(BUMBLE_GUN)         self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
-                       CASE(BUMBLE_BEAM)        self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
-
-                       CASE(RPC)                self.traileffect = EFFECT_TR_ROCKET.m_id; break;
-
-                       CASE(ROCKETMINSTA_LASER) self.traileffect = EFFECT_ROCKETMINSTA_LASER(self.team).m_id; break;
-#undef CASE
+                       #define HANDLE(id) case PROJECTILE_##id: setmodel(self, MDL_PROJECTILE_##id);
+                       HANDLE(ELECTRO)            self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
+                       HANDLE(ROCKET)             self.traileffect = EFFECT_TR_ROCKET.m_id; self.scale = 2; break;
+                       HANDLE(CRYLINK)            self.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
+                       HANDLE(CRYLINK_BOUNCING)   self.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
+                       HANDLE(ELECTRO_BEAM)       self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
+                       HANDLE(GRENADE)            self.traileffect = EFFECT_TR_GRENADE.m_id; break;
+                       HANDLE(GRENADE_BOUNCING)   self.traileffect = EFFECT_TR_GRENADE.m_id; break;
+                       HANDLE(MINE)               self.traileffect = EFFECT_TR_GRENADE.m_id; break;
+                       HANDLE(BLASTER)            self.traileffect = EFFECT_Null.m_id; break;
+                       HANDLE(HLAC)               self.traileffect = EFFECT_Null.m_id; break;
+                       HANDLE(PORTO_RED)          self.traileffect = EFFECT_TR_WIZSPIKE.m_id; self.scale = 4; break;
+                       HANDLE(PORTO_BLUE)         self.traileffect = EFFECT_TR_WIZSPIKE.m_id; self.scale = 4; break;
+                       HANDLE(HOOKBOMB)           self.traileffect = EFFECT_TR_KNIGHTSPIKE.m_id; break;
+                       HANDLE(HAGAR)              self.traileffect = EFFECT_HAGAR_ROCKET.m_id; self.scale = 0.75; break;
+                       HANDLE(HAGAR_BOUNCING)     self.traileffect = EFFECT_HAGAR_ROCKET.m_id; self.scale = 0.75; break;
+                       HANDLE(FIREBALL)           self.modelindex = 0; self.traileffect = EFFECT_FIREBALL.m_id; break; // particle effect is good enough
+                       HANDLE(FIREMINE)           self.modelindex = 0; self.traileffect = EFFECT_FIREMINE.m_id; break; // particle effect is good enough
+                       HANDLE(TAG)                self.traileffect = EFFECT_TR_ROCKET.m_id; break;
+                       HANDLE(FLAC)               self.scale = 0.4; self.traileffect = EFFECT_FLAC_TRAIL.m_id; break;
+                       HANDLE(SEEKER)             self.traileffect = EFFECT_SEEKER_TRAIL.m_id; break;
+
+                       HANDLE(MAGE_SPIKE)         self.traileffect = EFFECT_TR_VORESPIKE.m_id; break;
+                       HANDLE(SHAMBLER_LIGHTNING) self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
+
+                       HANDLE(RAPTORBOMB)         self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = EFFECT_Null.m_id; break;
+                       HANDLE(RAPTORBOMBLET)      self.gravity = 1; self.avelocity = '0 0 180'; self.traileffect = EFFECT_Null.m_id; break;
+                       HANDLE(RAPTORCANNON)       self.traileffect = EFFECT_TR_CRYLINKPLASMA.m_id; break;
+
+                       HANDLE(SPIDERROCKET)       self.traileffect = EFFECT_SPIDERBOT_ROCKET_TRAIL.m_id; break;
+                       HANDLE(WAKIROCKET)         self.traileffect = EFFECT_RACER_ROCKET_TRAIL.m_id; break;
+                       HANDLE(WAKICANNON)         self.traileffect = EFFECT_Null.m_id; break;
+
+                       HANDLE(BUMBLE_GUN)         self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
+                       HANDLE(BUMBLE_BEAM)        self.traileffect = EFFECT_TR_NEXUIZPLASMA.m_id; break;
+
+                       HANDLE(RPC)                self.traileffect = EFFECT_TR_ROCKET.m_id; break;
+
+                       HANDLE(ROCKETMINSTA_LASER) self.traileffect = EFFECT_ROCKETMINSTA_LASER(self.team).m_id; break;
+#undef HANDLE
                        default:
                                if (MUTATOR_CALLHOOK(Ent_Projectile, self))
                                        break;
diff --git a/qcsrc/common/anim.qc b/qcsrc/common/anim.qc
new file mode 100644 (file)
index 0000000..6a4dbe5
--- /dev/null
@@ -0,0 +1,49 @@
+#include "anim.qh"
+
+/**
+ * @param anim x = startframe, y = numframes, z = framerate
+ */
+void anim_set(entity e, vector anim, bool looping, bool override, bool restart)
+{
+       if (!anim) return;  // no animation was given to us! We can't use this.
+
+       if (anim.x == e.animstate_startframe)
+       {
+               if (anim.y == e.animstate_numframes)
+               {
+                       if (anim.z == e.animstate_framerate)
+                       {
+                               if (!restart) return;
+                               if (anim.y == 1)  // ZYM animation
+                                       BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT);
+                       }
+               }
+       }
+       e.animstate_startframe = anim.x;
+       e.animstate_numframes = anim.y;
+       e.animstate_framerate = anim.z;
+       e.animstate_starttime = time - 0.1 * frametime;  // shift it a little bit into the past to prevent float inaccuracy hiccups
+       e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
+       e.animstate_looping = looping;
+       e.animstate_override = override;
+       e.frame = e.animstate_startframe;
+       e.frame1time = time;
+}
+
+/**
+ * Update e.frame based on its animstate relative to time
+ */
+void anim_update(entity e)
+{
+       if (time >= e.animstate_endtime)
+       {
+               if (e.animstate_looping)
+               {
+                       e.animstate_starttime = e.animstate_endtime;
+                       e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
+               }
+               e.animstate_override = false;
+       }
+       float frameofs = bound(0, (time - e.animstate_starttime) * e.animstate_framerate, e.animstate_numframes - 1);
+       e.frame = e.animstate_startframe + frameofs;
+}
diff --git a/qcsrc/common/anim.qh b/qcsrc/common/anim.qh
new file mode 100644 (file)
index 0000000..acf6735
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef ANIM_H
+#define ANIM_H
+
+// begin engine fields
+
+/** primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4) */
+.float frame;
+/** secondary framegroup animation (strength = lerpfrac) */
+.float frame2;
+/** tertiary framegroup animation (strength = lerpfrac3) */
+.float frame3;
+/** quaternary framegroup animation (strength = lerpfrac4) */
+.float frame4;
+
+/** strength of framegroup blend */
+.float lerpfrac;
+/** strength of framegroup blend */
+.float lerpfrac3;
+/** strength of framegroup blend */
+.float lerpfrac4;
+
+/** start time of framegroup animation */
+.float frame1time;
+/** start time of framegroup animation */
+.float frame2time;
+/** start time of framegroup animation */
+.float frame3time;
+/** start time of framegroup animation */
+.float frame4time;
+
+// end engine fields
+
+// player animation state
+
+.int animstate_startframe;
+.int animstate_numframes;
+.float animstate_framerate;
+.float animstate_starttime;
+.float animstate_endtime;
+/** whether to repeat */
+.bool animstate_looping;
+/** true for one cycle, then changed to false */
+.bool animstate_override;
+
+void anim_set(entity e, vector anim, bool looping, bool override, bool restart);
+#define setanim(...) anim_set(__VA_ARGS__)
+void anim_update(entity e);
+#define updateanim(...) anim_update(__VA_ARGS__)
+
+#endif
index 6825ff76b6a89548570ff92e3d0df7287d83d40e..be3e10f5ef1bd1e06fdac0591ce4393d8fe41e67 100644 (file)
@@ -30,8 +30,13 @@ REGISTER_STAT(PL_MAX, vector, autocvar_sv_player_maxs)
 REGISTER_STAT(PL_CROUCH_MAX, vector, autocvar_sv_player_crouch_maxs)
 
 REGISTER_STAT(KH_KEYS, int)
+
 /** weapon requested to switch to; next WANTED weapon (for HUD) */
 REGISTER_STAT(SWITCHWEAPON, int)
+/** weapon currently being switched to (is copied from switchweapon once switch is possible) */
+REGISTER_STAT(SWITCHINGWEAPON, int)
+REGISTER_STAT(WEAPON_NEXTTHINK, float)
+
 REGISTER_STAT(GAMESTARTTIME, float)
 REGISTER_STAT(STRENGTH_FINISHED, float)
 REGISTER_STAT(INVINCIBLE_FINISHED, float)
@@ -57,7 +62,6 @@ REGISTER_STAT(DAMAGE_DEALT_TOTAL, int)
 REGISTER_STAT(TYPEHIT_TIME, float)
 REGISTER_STAT(LAYED_MINES, int)
 REGISTER_STAT(HAGAR_LOAD, int)
-REGISTER_STAT(SWITCHINGWEAPON, int)
 REGISTER_STAT(SUPERWEAPONS_FINISHED, float)
 REGISTER_STAT(VEHICLESTAT_HEALTH, int)
 REGISTER_STAT(VEHICLESTAT_SHIELD, int)
index fa68533f4afcb594a6d727389fc65e4d23c78482..19ccde9dca08ec764fa86fd5a0a788e915642d36 100644 (file)
@@ -47,15 +47,6 @@ void SUB_VanishOrRemove (entity ent);
 .vector destvec;
 .vector destvec2;
 
-// player animation state
-.float animstate_startframe;
-.float animstate_numframes;
-.float animstate_framerate;
-.float animstate_starttime;
-.float animstate_endtime;
-.float animstate_override;
-.float animstate_looping;
-
 .float delay;
 .float wait;
 .float lip;
index f7ba35cc407ed9e2cea30a5bd6af2dc604da5fef..849403f8713740773c0c7d780b6213b073064f96 100644 (file)
@@ -45,7 +45,7 @@
     #include "../../server/g_hook.qh"
 #endif
 #ifndef MENUQC
-#include "calculations.qc"
+       #include "calculations.qc"
 #endif
 #define IMPLEMENTATION
 #include "all.inc"
 
 // WEAPON PLUGIN SYSTEM
 
-WepSet _WepSet_FromWeapon(int a) {
+WepSet _WepSet_FromWeapon(int a)
+{
        a -= WEP_FIRST;
        if (Weapons_MAX > 24)
-       if (a >= 24) {
-               a -= 24;
-               if (Weapons_MAX > 48)
-               if (a >= 24) {
+               if (a >= 24)
+               {
                        a -= 24;
-                       return '0 0 1' * power2of(a);
+                       if (Weapons_MAX > 48)
+                               if (a >= 24)
+                               {
+                                       a -= 24;
+                                       return '0 0 1' * power2of(a);
+                               }
+                       return '0 1 0' * power2of(a);
                }
-               return '0 1 0' * power2of(a);
-       }
        return '1 0 0' * power2of(a);
 }
 #ifdef SVQC
-void WriteWepSet(float dst, WepSet w)
-{
-       if (Weapons_MAX > 48)
-       WriteInt72_t(dst, w);
-       else if (Weapons_MAX > 24)
-       WriteInt48_t(dst, w);
-       else
-       WriteInt24_t(dst, w.x);
-}
+       void WriteWepSet(float dst, WepSet w)
+       {
+               if (Weapons_MAX > 48) WriteInt72_t(dst, w);
+               else if (Weapons_MAX > 24) WriteInt48_t(dst, w);
+               else WriteInt24_t(dst, w.x);
+       }
 #endif
 #ifdef CSQC
-WepSet WepSet_GetFromStat()
-{
-       return STAT(WEAPONS);
-}
-WepSet WepSet_GetFromStat_InMap()
-{
-       return STAT(WEAPONSINMAP);
-}
-WepSet ReadWepSet()
-{
-       if (Weapons_MAX > 48)
-       return ReadInt72_t();
-       if (Weapons_MAX > 24)
-       return ReadInt48_t();
-       return ReadInt24_t() * '1 0 0';
-}
+       WepSet WepSet_GetFromStat()
+       {
+               return STAT(WEAPONS);
+       }
+       WepSet WepSet_GetFromStat_InMap()
+       {
+               return STAT(WEAPONSINMAP);
+       }
+       WepSet ReadWepSet()
+       {
+               if (Weapons_MAX > 48) return ReadInt72_t();
+               if (Weapons_MAX > 24) return ReadInt48_t();
+               return ReadInt24_t() * '1 0 0';
+       }
 #endif
 
 string W_FixWeaponOrder(string order, float complete)
@@ -104,26 +102,25 @@ string W_FixWeaponOrder(string order, float complete)
 string W_NameWeaponOrder_MapFunc(string s)
 {
        entity wi;
-       if(s == "0" || stof(s))
+       if (s == "0" || stof(s))
        {
                wi = get_weaponinfo(stof(s));
-               if(wi != WEP_Null)
-                       return wi.netname;
+               if (wi != WEP_Null) return wi.netname;
        }
        return s;
 }
 
 string W_UndeprecateName(string s)
 {
-       switch ( s )
+       switch (s)
        {
-               case "nex"            : return "vortex";
-               case "rocketlauncher" : return "devastator";
-               case "laser"          : return "blaster";
-               case "minstanex"      : return "vaporizer";
+               case "nex": return "vortex";
+               case "rocketlauncher": return "devastator";
+               case "laser": return "blaster";
+               case "minstanex": return "vaporizer";
                case "grenadelauncher": return "mortar";
-               case "uzi"            : return "machinegun";
-               default               : return s;
+               case "uzi": return "machinegun";
+               default: return s;
        }
 }
 string W_NameWeaponOrder(string order)
@@ -133,12 +130,10 @@ string W_NameWeaponOrder(string order)
 string W_NumberWeaponOrder_MapFunc(string s)
 {
        int i;
-       if(s == "0" || stof(s))
-               return s;
+       if (s == "0" || stof(s)) return s;
        s = W_UndeprecateName(s);
-       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-               if(s == get_weaponinfo(i).netname)
-                       return ftos(i);
+       for (i = WEP_FIRST; i <= WEP_LAST; ++i)
+               if (s == get_weaponinfo(i).netname) return ftos(i);
        return s;
 }
 string W_NumberWeaponOrder(string order)
@@ -162,23 +157,24 @@ float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass)
        e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
        e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
        d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
-       if(d != 0)
-               return -d; // high impulse first!
-       return
-               strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
-               -
-               strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
-               ; // low char index first!
+       if (d != 0) return -d;  // high impulse first!
+       return strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "),
+               sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
+              -
+              strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "),
+               sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
+        // low char index first!
 }
 string W_FixWeaponOrder_BuildImpulseList(string o)
 {
        int i;
        W_FixWeaponOrder_BuildImpulseList_order = o;
-       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+       for (i = WEP_FIRST; i <= WEP_LAST; ++i)
                W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
-       heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
+       heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp,
+               world);
        o = "";
-       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+       for (i = WEP_FIRST; i <= WEP_LAST; ++i)
                o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
        W_FixWeaponOrder_BuildImpulseList_order = string_null;
        return substring(o, 1, -1);
@@ -191,8 +187,7 @@ string W_FixWeaponOrder_AllowIncomplete(string order)
 
 string W_FixWeaponOrder_ForceComplete(string order)
 {
-       if(order == "")
-               order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
+       if (order == "") order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
        return W_FixWeaponOrder(order, 1);
 }
 
@@ -203,12 +198,11 @@ void W_RandomWeapons(entity e, float n)
        WepSet result;
        remaining = e.weapons;
        result = '0 0 0';
-       for(i = 0; i < n; ++i)
+       for (i = 0; i < n; ++i)
        {
                RandomSelection_Init();
-               for(j = WEP_FIRST; j <= WEP_LAST; ++j)
-                       if(remaining & WepSet_FromWeapon(j))
-                               RandomSelection_Add(world, j, string_null, 1, 1);
+               for (j = WEP_FIRST; j <= WEP_LAST; ++j)
+                       if (remaining & WepSet_FromWeapon(j)) RandomSelection_Add(world, j, string_null, 1, 1);
                result |= WepSet_FromWeapon(RandomSelection_chosen_float);
                remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
        }
@@ -225,48 +219,48 @@ string GetAmmoPicture(.int ammotype)
                case ammo_cells:   return ITEM_Cells.m_icon;
                case ammo_plasma:  return ITEM_Plasma.m_icon;
                case ammo_fuel:    return ITEM_JetpackFuel.m_icon;
-               default: return ""; // wtf, no ammo type?
+               default: return "";  // wtf, no ammo type?
        }
 }
 
 #ifdef CSQC
-.int GetAmmoFieldFromNum(int i)
-{
-       switch(i)
+       .int GetAmmoFieldFromNum(int i)
        {
-               case 0: return ammo_shells;
-               case 1: return ammo_nails;
-               case 2: return ammo_rockets;
-               case 3: return ammo_cells;
-               case 4: return ammo_plasma;
-               case 5: return ammo_fuel;
-               default: return ammo_none;
+               switch (i)
+               {
+                       case 0: return ammo_shells;
+                       case 1: return ammo_nails;
+                       case 2: return ammo_rockets;
+                       case 3: return ammo_cells;
+                       case 4: return ammo_plasma;
+                       case 5: return ammo_fuel;
+                       default: return ammo_none;
+               }
        }
-}
 
-int GetAmmoStat(.int ammotype)
-{
-       switch(ammotype)
+       int GetAmmoStat(.int ammotype)
        {
-               case ammo_shells: return STAT_SHELLS;
-               case ammo_nails: return STAT_NAILS;
-               case ammo_rockets: return STAT_ROCKETS;
-               case ammo_cells: return STAT_CELLS;
-               case ammo_plasma: return STAT_PLASMA.m_id;
-               case ammo_fuel: return STAT_FUEL.m_id;
-               default: return -1;
+               switch (ammotype)
+               {
+                       case ammo_shells: return STAT_SHELLS;
+                       case ammo_nails: return STAT_NAILS;
+                       case ammo_rockets: return STAT_ROCKETS;
+                       case ammo_cells: return STAT_CELLS;
+                       case ammo_plasma: return STAT_PLASMA.m_id;
+                       case ammo_fuel: return STAT_FUEL.m_id;
+                       default: return -1;
+               }
        }
-}
 #endif
 
 string W_Sound(string w_snd)
 {
        string output = strcat("weapons/", w_snd);
 #ifdef SVQC
-       MUTATOR_CALLHOOK(WeaponSound, w_snd, output);
-       return weapon_sound_output;
+               MUTATOR_CALLHOOK(WeaponSound, w_snd, output);
+               return weapon_sound_output;
 #else
-       return output;
+               return output;
 #endif
 }
 
@@ -274,11 +268,346 @@ string W_Model(string w_mdl)
 {
        string output = strcat("models/weapons/", w_mdl);
 #ifdef SVQC
-       MUTATOR_CALLHOOK(WeaponModel, w_mdl, output);
-       return weapon_model_output;
+               MUTATOR_CALLHOOK(WeaponModel, w_mdl, output);
+               return weapon_model_output;
 #else
-       return output;
+               return output;
+#endif
+}
+
+#ifndef MENUQC
+vector shotorg_adjustfromclient(vector vecs, float y_is_right, float algn)
+{
+       switch (algn)
+       {
+               default:
+               case 3:
+                       // right alignment
+                       break;
+               case 4:
+                       // left
+                       vecs.y = -vecs.y;
+                       break;
+               case 1:
+               case 2:
+                       // center
+                       vecs.y = 0;
+                       vecs.z -= 2;
+                       break;
+       }
+       return vecs;
+}
+
+vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn)
+{
+#ifdef SVQC
+       string s;
 #endif
+       if (visual)
+       {
+               vecs = shotorg_adjustfromclient(vecs, y_is_right, algn);
+       }
+#ifdef SVQC
+       else if (autocvar_g_shootfromeye)
+       {
+               vecs.y = vecs.z = 0;
+       }
+       else if (autocvar_g_shootfromcenter)
+       {
+               vecs.y = 0;
+               vecs.z -= 2;
+       }
+       else if ((s = autocvar_g_shootfromfixedorigin) != "")
+       {
+               vector v = stov(s);
+               if (y_is_right) v.y = -v.y;
+               if (v.x != 0) vecs.x = v.x;
+               vecs.y = v.y;
+               vecs.z = v.z;
+       }
+#endif
+       else  // just do the same as top
+       {
+               vecs = shotorg_adjustfromclient(vecs, y_is_right, algn);
+       }
+
+       return vecs;
 }
 
+#define shotorg_adjust shotorg_adjust_values
+
+/**
+ * supported formats:
+ *
+ * 1. simple animated model, muzzle flash handling on h_ model:
+ *    h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
+ *      tags:
+ *        shot = muzzle end (shot origin, also used for muzzle flashes)
+ *        shell = casings ejection point (must be on the right hand side of the gun)
+ *        weapon = attachment for v_tuba.md3
+ *    v_tuba.md3 - first and third person model
+ *    g_tuba.md3 - pickup model
+ *
+ * 2. simple animated model, muzzle flash handling on v_ model:
+ *    h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
+ *      tags:
+ *        weapon = attachment for v_tuba.md3
+ *    v_tuba.md3 - first and third person model
+ *      tags:
+ *        shot = muzzle end (shot origin, also used for muzzle flashes)
+ *        shell = casings ejection point (must be on the right hand side of the gun)
+ *    g_tuba.md3 - pickup model
+ *
+ * 3. fully animated model, muzzle flash handling on h_ model:
+ *    h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
+ *      tags:
+ *        shot = muzzle end (shot origin, also used for muzzle flashes)
+ *        shell = casings ejection point (must be on the right hand side of the gun)
+ *        handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
+ *    v_tuba.md3 - third person model
+ *    g_tuba.md3 - pickup model
+ *
+ * 4. fully animated model, muzzle flash handling on v_ model:
+ *    h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
+ *      tags:
+ *        shot = muzzle end (shot origin)
+ *        shell = casings ejection point (must be on the right hand side of the gun)
+ *    v_tuba.md3 - third person model
+ *      tags:
+ *        shot = muzzle end (for muzzle flashes)
+ *    g_tuba.md3 - pickup model
+ *
+ * writes:
+ *   this.origin, this.angles
+ *   this.weaponchild
+ *   this.movedir, this.view_ofs
+ *   attachment stuff
+ *   anim stuff
+ * to free:
+ *   call again with ""
+ *   remove the ent
+ */
+void CL_WeaponEntity_SetModel(entity this, string name)
+{
+       if (name == "")
+       {
+               this.model = "";
+               if (this.weaponchild) remove(this.weaponchild);
+               this.weaponchild = NULL;
+               this.movedir = '0 0 0';
+               this.spawnorigin = '0 0 0';
+               this.oldorigin = '0 0 0';
+               this.anim_fire1  = '0 1 0.01';
+               this.anim_fire2  = '0 1 0.01';
+               this.anim_idle   = '0 1 0.01';
+               this.anim_reload = '0 1 0.01';
+       }
+       else
+       {
+               // if there is a child entity, hide it until we're sure we use it
+               if (this.weaponchild) this.weaponchild.model = "";
+               _setmodel(this, W_Model(strcat("v_", name, ".md3")));
+               int v_shot_idx;  // used later
+               (v_shot_idx = gettagindex(this, "shot")) || (v_shot_idx = gettagindex(this, "tag_shot"));
+
+               _setmodel(this, W_Model(strcat("h_", name, ".iqm")));
+               // preset some defaults that work great for renamed zym files (which don't need an animinfo)
+               this.anim_fire1  = animfixfps(this, '0 1 0.01', '0 0 0');
+               this.anim_fire2  = animfixfps(this, '1 1 0.01', '0 0 0');
+               this.anim_idle   = animfixfps(this, '2 1 0.01', '0 0 0');
+               this.anim_reload = animfixfps(this, '3 1 0.01', '0 0 0');
+
+               // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
+               // if we don't, this is a "real" animated model
+               string t;
+               if ((t = "weapon", gettagindex(this, t)) || (t = "tag_weapon", gettagindex(this, t)))
+               {
+                       if (!this.weaponchild)
+                       {
+                               this.weaponchild = new(weaponchild);
+#ifdef CSQC
+                               this.weaponchild.drawmask = MASK_NORMAL;
+                               this.weaponchild.renderflags |= RF_VIEWMODEL;
+#endif
+                       }
+                       _setmodel(this.weaponchild, W_Model(strcat("v_", name, ".md3")));
+                       setattachment(this.weaponchild, this, t);
+               }
+               else
+               {
+                       if (this.weaponchild) remove(this.weaponchild);
+                       this.weaponchild = NULL;
+               }
+
+               setorigin(this, '0 0 0');
+               this.angles = '0 0 0';
+               this.frame = 0;
+#ifdef SVQC
+               this.viewmodelforclient = NULL;
+#else
+               this.renderflags &= ~RF_VIEWMODEL;
+#endif
+               if (v_shot_idx)  // v_ model attached to invisible h_ model
+               {
+                       this.movedir = gettaginfo(this.weaponchild, v_shot_idx);
+               }
+               else
+               {
+                       int idx;
+                       if ((idx = gettagindex(this, "shot")) || (idx = gettagindex(this, "tag_shot")))
+                       {
+                               this.movedir = gettaginfo(this, idx);
+                       }
+                       else
+                       {
+                               LOG_WARNINGF("weapon model %s does not support the 'shot' tag, will display shots TOTALLY wrong\n",
+                                       this.model);
+                               this.movedir = '0 0 0';
+                       }
+               }
+               {
+                       int idx = 0;
+                       // v_ model attached to invisible h_ model
+                       if (this.weaponchild
+                           && ((idx = gettagindex(this.weaponchild, "shell")) || (idx = gettagindex(this.weaponchild, "tag_shell"))))
+                       {
+                               this.spawnorigin = gettaginfo(this.weaponchild, idx);
+                       }
+                       else if ((idx = gettagindex(this, "shell")) || (idx = gettagindex(this, "tag_shell")))
+                       {
+                               this.spawnorigin = gettaginfo(this, idx);
+                       }
+                       else
+                       {
+                               LOG_WARNINGF("weapon model %s does not support the 'shell' tag, will display casings wrong\n",
+                                       this.model);
+                               this.spawnorigin = this.movedir;
+                       }
+               }
+               if (v_shot_idx)
+               {
+                       this.oldorigin = '0 0 0';  // use regular attachment
+               }
+               else
+               {
+                       int idx;
+                       if (this.weaponchild)
+                               (idx = gettagindex(this, "weapon")) || (idx = gettagindex(this, "tag_weapon"));
+                       else
+                               (idx = gettagindex(this, "handle")) || (idx = gettagindex(this, "tag_handle"));
+                       if (idx)
+                       {
+                               this.oldorigin = this.movedir - gettaginfo(this, idx);
+                       }
+                       else
+                       {
+                               LOG_WARNINGF(
+                                       "weapon model %s does not support the 'handle' tag "
+                                       "and neither does the v_ model support the 'shot' tag, "
+                                       "will display muzzle flashes TOTALLY wrong\n",
+                                       this.model);
+                               this.oldorigin = '0 0 0';  // there is no way to recover from this
+                       }
+               }
+
+#ifdef SVQC
+               this.viewmodelforclient = this.owner;
+#else
+               this.renderflags |= RF_VIEWMODEL;
+#endif
+       }
+
+       this.view_ofs = '0 0 0';
+
+       if (this.movedir.x >= 0)
+       {
+#ifdef SVQC
+               int algn = this.owner.cvar_cl_gunalign;
+#else
+               int algn = autocvar_cl_gunalign;
+#endif
+               vector v = this.movedir;
+               this.movedir = shotorg_adjust(v, false, false, algn);
+               this.view_ofs = shotorg_adjust(v, false, true, algn) - v;
+       }
+       int compressed_shotorg = compressShotOrigin(this.movedir);
+       // make them match perfectly
+#ifdef SVQC
+       this.movedir = decompressShotOrigin(this.owner.stat_shotorg = compressed_shotorg);
+#else
+       this.movedir = decompressShotOrigin(compressed_shotorg);
+#endif
+
+       this.spawnorigin += this.view_ofs;  // offset the casings origin by the same amount
+
+       // check if an instant weapon switch occurred
+       setorigin(this, this.view_ofs);
+       // reset animstate now
+       this.wframe = WFRAME_IDLE;
+       setanim(this, this.anim_idle, true, false, true);
+}
+#endif
+
+#ifndef MENUQC
+
+REGISTER_NET_TEMP(wframe)
+#ifdef CSQC
+NET_HANDLE(wframe, bool isNew)
+{
+       vector a;
+       a.x = ReadCoord();
+    a.y = ReadCoord();
+    a.z = ReadCoord();
+       bool restartanim = ReadByte();
+       anim_set(viewmodel, a, !restartanim, restartanim, restartanim);
+       viewmodel.state = ReadByte();
+       viewmodel.alpha = ReadByte() / 255;
+       return true;
+}
+#endif
+
+#ifdef SVQC
+void wframe_send(entity actor, entity weaponentity, vector a, bool restartanim)
+{
+       if (!IS_REAL_CLIENT(actor)) return;
+       int channel = MSG_ONE;
+       msg_entity = actor;
+       WriteHeader(channel, wframe);
+       WriteCoord(channel, a.x);
+       WriteCoord(channel, a.y);
+       WriteCoord(channel, a.z);
+       WriteByte(channel, restartanim);
+       WriteByte(channel, weaponentity.state);
+       WriteByte(channel, weaponentity.alpha * 255);
+}
+#endif
+
+REGISTER_NET_TEMP(wglow)
+#ifdef CSQC
+NET_HANDLE(wglow, bool isNew)
+{
+       vector g = '0 0 0';
+       g.x = ReadCoord();
+       g.y = ReadCoord();
+       g.z = ReadCoord();
+       viewmodel.glowmod = g;
+       return true;
+}
+#endif
+
+#ifdef SVQC
+void wglow_send(entity actor, vector g)
+{
+       if (!IS_REAL_CLIENT(actor)) return;
+       int channel = MSG_ONE;
+       msg_entity = actor;
+       WriteHeader(channel, wglow);
+       WriteCoord(channel, g.x);
+       WriteCoord(channel, g.y);
+       WriteCoord(channel, g.z);
+}
+#endif
+
+#endif
+
 #endif
index eb7a48f7ff6a68c2c41a1c75adc105c8ee1037c2..47568b31a072fc94127d679fc6219aa910e1c88d 100644 (file)
@@ -172,4 +172,41 @@ STATIC_INIT(register_weapons_done)
     weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
 }
 
+#ifndef MENUQC
+
+.entity weaponchild;
+.entity exteriorweaponentity;
+.vector weaponentity_glowmod;
+
+//.int weapon; // current weapon
+#ifdef SVQC
+.int switchweapon = _STAT(SWITCHWEAPON);
+.int switchingweapon = _STAT(SWITCHINGWEAPON);
+#endif
+.string weaponname; // name of .weapon
+
+.vector spawnorigin; // for casings
+
+// weapon animation vectors:
+.vector anim_fire1;
+.vector anim_fire2;
+.vector anim_idle;
+.vector anim_reload;
+
+// static frame globals
+
+ENUMCLASS(WFRAME)
+CASE(WFRAME, DONTCHANGE)
+CASE(WFRAME, FIRE1)
+CASE(WFRAME, FIRE2)
+CASE(WFRAME, IDLE)
+CASE(WFRAME, RELOAD)
+ENUMCLASS_END(WFRAME)
+
+.WFRAME wframe;
+
+vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn);
+void CL_WeaponEntity_SetModel(entity this, string name);
+#endif
+
 #endif
index 3016b501f8941741dbba3ca8b1e97d5b7caa3fab..71e121f81201ea0b39504c46a63ed72290b0ddfd 100644 (file)
@@ -18,6 +18,18 @@ int weaponslot(.entity weaponentity)
        return 0;
 }
 
+// weapon states (actor.(weaponentity).state)
+/** no weapon selected */
+const int WS_CLEAR  = 0;
+/** raise frame */
+const int WS_RAISE  = 1;
+/** deselecting frame */
+const int WS_DROP   = 2;
+/** fire state */
+const int WS_INUSE  = 3;
+/** idle frame */
+const int WS_READY  = 4;
+
 #ifdef SVQC
 .int ammo_shells;
 .int ammo_nails;
index 83d7e3fcbf23ec1ca254557df940f6a94a5fade7..7c9d64c01abed4d09077f4a29d2e0546dee57ac2 100644 (file)
@@ -670,7 +670,7 @@ void Arc_Smoke()
                                                weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
                                        else
                                        #endif
-                                               weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
+                                               weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, WEP_CVAR(arc, beam_animtime), w_ready);
                                }
 
                                if((!actor.arc_beam) || wasfreed(actor.arc_beam))
index e7cd2606c1c4a5abbeb8ab5589a53708dc274dbb..be9788fcc7414649398387b3be54be5685c4a990 100644 (file)
@@ -87,7 +87,7 @@ void W_Rifle_Attack2()
 }
 
 .void() rifle_bullethail_attackfunc;
-.float rifle_bullethail_frame;
+.WFRAME rifle_bullethail_frame;
 .float rifle_bullethail_animtime;
 .float rifle_bullethail_refire;
 void W_Rifle_BulletHail_Continue(Weapon thiswep, entity actor, .entity weaponentity, int fire)
@@ -113,7 +113,7 @@ void W_Rifle_BulletHail_Continue(Weapon thiswep, entity actor, .entity weaponent
        }
 }
 
-void W_Rifle_BulletHail(.entity weaponentity, float mode, void() AttackFunc, float fr, float animtime, float refire)
+void W_Rifle_BulletHail(.entity weaponentity, float mode, void() AttackFunc, WFRAME fr, float animtime, float refire)
 {SELFPARAM();
        // if we get here, we have at least one bullet to fire
        AttackFunc();
index 24d2df747cf1c3dd649189e8b4a77382532b9b7b..9f7004c345ae8ca98c05a83434112b17fab2360e 100644 (file)
@@ -36,6 +36,7 @@
 #include "cvar.qh"
 #include "defer.qh"
 #include "draw.qh"
+#include "enumclass.qh"
 #include "file.qh"
 #include "functional.qh"
 #include "i18n.qh"
diff --git a/qcsrc/lib/enumclass.qh b/qcsrc/lib/enumclass.qh
new file mode 100644 (file)
index 0000000..2959565
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef ENUMCLASS_H
+#define ENUMCLASS_H
+
+#include "oo.qh"
+
+// purpose: prevent transposed parameter passing
+
+#if NDEBUG
+
+// zero overhead mode, use this for releases
+
+#define ENUMCLASS(id) typedef int id; enum {
+#define CASE(class, id) class##_##id,
+#define ENUMCLASS_END(id) };
+
+#else
+
+// edict overhead mode, use this for type checking
+
+#define ENUMCLASS(id) CLASS(id, Object)
+#define CASE(class, id) class class##_##id; STATIC_INIT(class##_##id) { class##_##id = NEW(class); }
+#define ENUMCLASS_END(id) ENDCLASS(id)
+
+#endif
+
+#endif
index d6eee7aceae92104220446b7ee56659daa79c9b0..776bf6eedb888c8fd0df39b4d37b3ca0321894ca 100644 (file)
@@ -67,6 +67,16 @@ float boxesoverlap(vector m1, vector m2, vector m3, vector m4) { return m2_x >=
 /** requires the same as boxesoverlap, but is a stronger condition */
 float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs) { return smins.x >= bmins.x && smaxs.x <= bmaxs.x && smins.y >= bmins.y && smaxs.y <= bmaxs.y && smins.z >= bmins.z && smaxs.z <= bmaxs.z; }
 
+#define PITCH(v) (v).x
+#define YAW(v) (v).y
+#define ROLL(v) (v).z
+
+#define MAKEVECTORS(f, angles, forward, right, up) do { \
+       f(angles); \
+       forward = v_forward; \
+       right = v_right; \
+       up = v_up; \
+} while (0)
 
 noref vector _vec2;
 #define vec2(v) (_vec2 = (v), _vec2.z = 0, _vec2)
index 2731c82445d3d82bffabb5b0017ba2069fd6f2f3..0cc6a0b65d745e6a0b784ecbf3fa362714df8a5e 100644 (file)
@@ -1690,6 +1690,7 @@ void SpectateCopy(entity spectatee)
        self.switchweapon = spectatee.switchweapon;
        self.switchingweapon = spectatee.switchingweapon;
        self.weapon = spectatee.weapon;
+       self.weapon_nextthink = spectatee.weapon_nextthink;
        self.vortex_charge = spectatee.vortex_charge;
        self.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
        self.hagar_load = spectatee.hagar_load;
@@ -2147,6 +2148,8 @@ void PlayerUseKey()
 }
 
 
+void wglow_send(entity actor, vector g);
+
 /*
 =============
 PlayerPreThink
@@ -2322,22 +2325,28 @@ void PlayerPreThink ()
 
                if(frametime)
                {
-                       if(self.weapon == WEP_VORTEX.m_id && WEP_CVAR(vortex, charge))
+                       vector g;
+                       if (IS_SPEC(self))
+                       {
+                               g = self.enemy.weaponentity_glowmod;
+                       }
+                       else if(self.weapon == WEP_VORTEX.m_id && WEP_CVAR(vortex, charge))
                        {
-                               self.weaponentity_glowmod_x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
-                               self.weaponentity_glowmod_y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
-                               self.weaponentity_glowmod_z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
+                               g.x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
+                               g.y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
+                               g.z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
 
                                if(self.vortex_charge > WEP_CVAR(vortex, charge_animlimit))
                                {
-                                       self.weaponentity_glowmod_x = self.weaponentity_glowmod.x + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
-                                       self.weaponentity_glowmod_y = self.weaponentity_glowmod.y + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
-                                       self.weaponentity_glowmod_z = self.weaponentity_glowmod.z + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
+                                       g.x += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
+                                       g.y += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
+                                       g.z += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
                                }
                        }
                        else
-                               self.weaponentity_glowmod = colormapPaletteColor(self.clientcolors & 0x0F, true) * 2;
-
+                               g = colormapPaletteColor(self.clientcolors & 0x0F, true) * 2;
+                       if (g != self.weaponentity_glowmod)
+                               wglow_send(self, self.weaponentity_glowmod = g);
                        player_powerups();
                }
 
index a9a5d03cbe2e93965f73b25e603cfbc31a5f5288..22ef4bdffa5d2283d8170677850ee443ad731bff 100644 (file)
@@ -9,6 +9,7 @@
 #include "teamplay.qh"
 #include "weapons/throwing.qh"
 #include "command/common.qh"
+#include "../common/anim.qh"
 #include "../common/animdecide.qh"
 #include "../common/csqcmodel_settings.qh"
 #include "../common/deathtypes/all.qh"
@@ -154,16 +155,6 @@ void player_anim ()
                animbits |= ANIMSTATE_DUCK;
        animdecide_setstate(self, animbits, false);
        animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
-
-       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
-       {
-               if (self.(weaponentity))
-               {
-                       updateanim(self.(weaponentity));
-                       if (!self.(weaponentity).animstate_override)
-                               setanim(self.(weaponentity), self.(weaponentity).anim_idle, true, false, false);
-               }
-       }
 }
 
 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
index 9c2dc4064097acbd97f5cc0ffb6260b3a89c57c4..a18dd3c43029e6d27c0c164fbc788d79738da5e7 100644 (file)
@@ -91,14 +91,7 @@ float server_is_dedicated;
 .float fade_time;
 .float fade_rate;
 
-// weapon animation vectors:
-.vector anim_fire1;
-.vector anim_fire2;
-.vector anim_idle;
-.vector anim_reload;
-
 void() player_setupanimsformodel;
-void setanim(entity e, vector anim, float looping, float override, float restart);
 
 .string mdl;
 
@@ -149,33 +142,16 @@ const float MAX_DAMAGEEXTRARADIUS = 16;
 .entity item_pickupsound_ent;
 .entity item_model_ent;
 
-// definitions for weaponsystem
-// more WEAPONTODO: move these to their proper files
-.entity exteriorweaponentity;
-.vector weaponentity_glowmod;
-
-//.int weapon; // current weapon
-.int switchweapon = _STAT(SWITCHWEAPON);
-.int switchingweapon = _STAT(SWITCHINGWEAPON); // weapon currently being switched to (is copied from switchweapon once switch is possible)
-.string weaponname; // name of .weapon
-
 // WEAPONTODO
 .float autoswitch;
 float client_hasweapon(entity cl, float wpn, float andammo, float complain);
 void w_clear(Weapon thiswep, entity actor, .entity weaponentity, int fire);
 void w_ready(Weapon thiswep, entity actor, .entity weaponentity, int fire);
 // VorteX: standalone think for weapons, so normal think on weaponentity can be reserved by weaponflashes (which needs update even player dies)
-.float weapon_nextthink;
+.float weapon_nextthink = _STAT(WEAPON_NEXTTHINK);
 .void(Weapon thiswep, entity actor, .entity weaponentity, int fire) weapon_think;
 
 
-// weapon states (self.weaponentity.state)
-const int WS_CLEAR                     = 0; // no weapon selected
-const int WS_RAISE                     = 1; // raise frame
-const int WS_DROP                              = 2; // deselecting frame
-const int WS_INUSE                     = 3; // fire state
-const int WS_READY                     = 4; // idle frame
-
 // there is 2 weapon tics that can run in one server frame
 const int W_TICSPERFRAME = 2;
 
@@ -212,8 +188,6 @@ float nJoinAllowed(entity ignore);
 float playerid_last;
 .float noalign;                // if set to 1, the item or spawnpoint won't be dropped to the floor
 
-.vector spawnorigin;
-
 .vector death_origin;
 .vector killer_origin;
 
index f2e3da898645ddfb755f0bd852e7a077988efa94..f7dcf3073a114b4dbf7078bc9e71cd7f0853c925 100644 (file)
@@ -11,50 +11,6 @@ spawnfunc(info_null)
        // if anything breaks, tell the mapper to fix his map! info_null is meant to remove itself immediately.
 }
 
-void setanim(entity e, vector anim, float looping, float override, float restart)
-{
-       if (!anim)
-               return; // no animation was given to us! We can't use this.
-
-       if (anim.x == e.animstate_startframe)
-       if (anim.y == e.animstate_numframes)
-       if (anim.z == e.animstate_framerate)
-       {
-               if(restart)
-               {
-                       if(restart > 0)
-                       if(anim.y == 1) // ZYM animation
-                               BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT);
-               }
-               else
-                       return;
-       }
-       e.animstate_startframe = anim.x;
-       e.animstate_numframes = anim.y;
-       e.animstate_framerate = anim.z;
-       e.animstate_starttime = servertime - 0.1 * serverframetime; // shift it a little bit into the past to prevent float inaccuracy hiccups
-       e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
-       e.animstate_looping = looping;
-       e.animstate_override = override;
-       e.frame = e.animstate_startframe;
-       e.frame1time = servertime;
-}
-
-void updateanim(entity e)
-{
-       if (time >= e.animstate_endtime)
-       {
-               if (e.animstate_looping)
-               {
-                       e.animstate_starttime = e.animstate_endtime;
-                       e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
-               }
-               e.animstate_override = false;
-       }
-       e.frame = e.animstate_startframe + bound(0, (time - e.animstate_starttime) * e.animstate_framerate, e.animstate_numframes - 1);
-       //print(ftos(time), " -> ", ftos(e.frame), "\n");
-}
-
 /*
 ==================
 main
index cebf61b7040d1b24302c4662e395272aadbd4a3f..81516f9357c56344f932fe70b439f282a6ddc72e 100644 (file)
@@ -9,12 +9,6 @@ void() SUB_CalcAngleMoveDone;
 
 spawnfunc(info_null);
 
-void setanim(entity e, vector anim, float looping, float override, float restart);
-
-void updateanim(entity e);
-
-
-
 /*
 ==================
 SUB_Friction
index a7036ca4f29b70fa19aeb25756d4cfc701de71af..9587d3cd1e2e4d103109bc77c8f3d21019eecea1 100644 (file)
@@ -1409,8 +1409,8 @@ void FixIntermissionClient(entity e)
                        if(e.(weaponentity))
                        {
                                e.(weaponentity).effects = EF_NODRAW;
-                               if (e.(weaponentity).(weaponentity))
-                                       e.(weaponentity).(weaponentity).effects = EF_NODRAW;
+                               if (e.(weaponentity).weaponchild)
+                                       e.(weaponentity).weaponchild.effects = EF_NODRAW;
                        }
                }
                if(IS_REAL_CLIENT(e))
index e23909812d27dd6494ace3e26b6a9aa42ce49d7a..5c79a0d88429e478effa0bbd766e66b83e2d5d6a 100644 (file)
@@ -53,6 +53,7 @@
 #include "weapons/weaponstats.qc"
 #include "weapons/weaponsystem.qc"
 
+#include "../common/anim.qc"
 #include "../common/animdecide.qc"
 #include "../common/campaign_file.qc"
 #include "../common/campaign_setup.qc"
index 3ea45ad46814ca7dfcc306288048b41cded229fb..54bc2c9a5f2dba2336a7b7a47ed73d9f9d9fe891 100644 (file)
 #include "../../common/weapons/all.qh"
 #include "../../lib/csqcmodel/sv_model.qh"
 
-vector shotorg_adjustfromclient(vector vecs, float y_is_right, float algn)
-{
-       switch (algn)
-       {
-               default: case 3: break; // right alignment
-               case 4: vecs.y = -vecs.y;
-                       break;              // left
-               case 1: case 2: vecs.y = 0;
-                       vecs.z -= 2;
-                       break;              // center
-       }
-
-       return vecs;
-}
-
-vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn)
-{
-       string s;
-
-       if (visual)
-       {
-               vecs = shotorg_adjustfromclient(vecs, y_is_right, algn);
-       }
-       else if (autocvar_g_shootfromeye)
-       {
-               vecs.y = vecs.z = 0;
-       }
-       else if (autocvar_g_shootfromcenter)
-       {
-               vecs.y = 0;
-               vecs.z -= 2;
-       }
-       else if ((s = autocvar_g_shootfromfixedorigin) != "")
-       {
-               vector v = stov(s);
-               if (y_is_right) v.y = -v.y;
-               if (v.x != 0) vecs.x = v.x;
-               vecs.y = v.y;
-               vecs.z = v.z;
-       }
-       else  // just do the same as top
-       {
-               vecs = shotorg_adjustfromclient(vecs, y_is_right, algn);
-       }
-
-       return vecs;
-}
-
-vector shotorg_adjust(vector vecs, bool y_is_right, bool visual, int algn)
-{
-       return shotorg_adjust_values(vecs, y_is_right, visual, algn);
-}
-
 .int state;
 
 .float weapon_frametime;
@@ -92,9 +39,6 @@ float W_WeaponSpeedFactor()
 }
 
 
-void weapon_thinkf(entity actor, .entity weaponentity, float fr, float t, void(Weapon thiswep, entity actor,
-    .entity weaponentity, int fire) func);
-
 bool CL_Weaponentity_CustomizeEntityForClient()
 {
        SELFPARAM();
@@ -103,219 +47,13 @@ bool CL_Weaponentity_CustomizeEntityForClient()
        return true;
 }
 
-/*
- * supported formats:
- *
- * 1. simple animated model, muzzle flash handling on h_ model:
- *    h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
- *      tags:
- *        shot = muzzle end (shot origin, also used for muzzle flashes)
- *        shell = casings ejection point (must be on the right hand side of the gun)
- *        weapon = attachment for v_tuba.md3
- *    v_tuba.md3 - first and third person model
- *    g_tuba.md3 - pickup model
- *
- * 2. simple animated model, muzzle flash handling on v_ model:
- *    h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
- *      tags:
- *        weapon = attachment for v_tuba.md3
- *    v_tuba.md3 - first and third person model
- *      tags:
- *        shot = muzzle end (shot origin, also used for muzzle flashes)
- *        shell = casings ejection point (must be on the right hand side of the gun)
- *    g_tuba.md3 - pickup model
- *
- * 3. fully animated model, muzzle flash handling on h_ model:
- *    h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
- *      tags:
- *        shot = muzzle end (shot origin, also used for muzzle flashes)
- *        shell = casings ejection point (must be on the right hand side of the gun)
- *        handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
- *    v_tuba.md3 - third person model
- *    g_tuba.md3 - pickup model
- *
- * 4. fully animated model, muzzle flash handling on v_ model:
- *    h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
- *      tags:
- *        shot = muzzle end (shot origin)
- *        shell = casings ejection point (must be on the right hand side of the gun)
- *    v_tuba.md3 - third person model
- *      tags:
- *        shot = muzzle end (for muzzle flashes)
- *    g_tuba.md3 - pickup model
- */
-
-// writes:
-//   this.origin, this.angles
-//   this.weaponentity
-//   this.movedir, this.view_ofs
-//   attachment stuff
-//   anim stuff
-// to free:
-//   call again with ""
-//   remove the ent
-void CL_WeaponEntity_SetModel(entity this, .entity weaponentity, string name)
-{
-       if (name != "")
-       {
-               // if there is a child entity, hide it until we're sure we use it
-               if (this.(weaponentity)) this.(weaponentity).model = "";
-               _setmodel(this, W_Model(strcat("v_", name, ".md3")));
-               int v_shot_idx = gettagindex(this, "shot");  // used later
-               if (!v_shot_idx) v_shot_idx = gettagindex(this, "tag_shot");
-
-               _setmodel(this, W_Model(strcat("h_", name, ".iqm")));
-               // preset some defaults that work great for renamed zym files (which don't need an animinfo)
-               this.anim_fire1  = animfixfps(this, '0 1 0.01', '0 0 0');
-               this.anim_fire2  = animfixfps(this, '1 1 0.01', '0 0 0');
-               this.anim_idle   = animfixfps(this, '2 1 0.01', '0 0 0');
-               this.anim_reload = animfixfps(this, '3 1 0.01', '0 0 0');
-
-               // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
-               // if we don't, this is a "real" animated model
-               if (gettagindex(this, "weapon"))
-               {
-                       if (!this.(weaponentity)) this.(weaponentity) = new(weaponentity);
-                       _setmodel(this.(weaponentity), W_Model(strcat("v_", name, ".md3")));
-                       setattachment(this.(weaponentity), this, "weapon");
-               }
-               else if (gettagindex(this, "tag_weapon"))
-               {
-                       if (!this.(weaponentity)) this.(weaponentity) = new(weaponentity);
-                       _setmodel(this.(weaponentity), W_Model(strcat("v_", name, ".md3")));
-                       setattachment(this.(weaponentity), this, "tag_weapon");
-               }
-               else
-               {
-                       if (this.(weaponentity)) remove(this.(weaponentity));
-                       this.(weaponentity) = NULL;
-               }
-
-               setorigin(this, '0 0 0');
-               this.angles = '0 0 0';
-               this.frame = 0;
-               this.viewmodelforclient = NULL;
-
-               float idx;
-
-               if (v_shot_idx)  // v_ model attached to invisible h_ model
-               {
-                       this.movedir = gettaginfo(this.(weaponentity), v_shot_idx);
-               }
-               else
-               {
-                       idx = gettagindex(this, "shot");
-                       if (!idx) idx = gettagindex(this, "tag_shot");
-                       if (idx)
-                       {
-                               this.movedir = gettaginfo(this, idx);
-                       }
-                       else
-                       {
-                               LOG_INFO("WARNING: weapon model ", this.model,
-                                       " does not support the 'shot' tag, will display shots TOTALLY wrong\n");
-                               this.movedir = '0 0 0';
-                       }
-               }
-
-               if (this.(weaponentity))  // v_ model attached to invisible h_ model
-               {
-                       idx = gettagindex(this.(weaponentity), "shell");
-                       if (!idx) idx = gettagindex(this.(weaponentity), "tag_shell");
-                       if (idx) this.spawnorigin = gettaginfo(this.(weaponentity), idx);
-               }
-               else
-               {
-                       idx = 0;
-               }
-               if (!idx)
-               {
-                       idx = gettagindex(this, "shell");
-                       if (!idx) idx = gettagindex(this, "tag_shell");
-                       if (idx)
-                       {
-                               this.spawnorigin = gettaginfo(this, idx);
-                       }
-                       else
-                       {
-                               LOG_INFO("WARNING: weapon model ", this.model,
-                                       " does not support the 'shell' tag, will display casings wrong\n");
-                               this.spawnorigin = this.movedir;
-                       }
-               }
-
-               if (v_shot_idx)
-               {
-                       this.oldorigin = '0 0 0';  // use regular attachment
-               }
-               else
-               {
-                       if (this.(weaponentity))
-                       {
-                               idx = gettagindex(this, "weapon");
-                               if (!idx) idx = gettagindex(this, "tag_weapon");
-                       }
-                       else
-                       {
-                               idx = gettagindex(this, "handle");
-                               if (!idx) idx = gettagindex(this, "tag_handle");
-                       }
-                       if (idx)
-                       {
-                               this.oldorigin = this.movedir - gettaginfo(this, idx);
-                       }
-                       else
-                       {
-                               LOG_INFO("WARNING: weapon model ", this.model,
-                                       " does not support the 'handle' tag and neither does the v_ model support the 'shot' tag, will display muzzle flashes TOTALLY wrong\n");
-                               this.oldorigin = '0 0 0';  // there is no way to recover from this
-                       }
-               }
-
-               this.viewmodelforclient = this.owner;
-       }
-       else
-       {
-               this.model = "";
-               if (this.(weaponentity)) remove(this.(weaponentity));
-               this.(weaponentity) = NULL;
-               this.movedir = '0 0 0';
-               this.spawnorigin = '0 0 0';
-               this.oldorigin = '0 0 0';
-               this.anim_fire1  = '0 1 0.01';
-               this.anim_fire2  = '0 1 0.01';
-               this.anim_idle   = '0 1 0.01';
-               this.anim_reload = '0 1 0.01';
-       }
-
-       this.view_ofs = '0 0 0';
-
-       if (this.movedir.x >= 0)
-       {
-               vector v0 = this.movedir;
-               this.movedir = shotorg_adjust(v0, false, false, this.owner.cvar_cl_gunalign);
-               this.view_ofs = shotorg_adjust(v0, false, true, this.owner.cvar_cl_gunalign) - v0;
-       }
-       this.owner.stat_shotorg = compressShotOrigin(this.movedir);
-       this.movedir = decompressShotOrigin(this.owner.stat_shotorg); // make them match perfectly
-
-       this.spawnorigin += this.view_ofs;                            // offset the casings origin by the same amount
-
-       // check if an instant weapon switch occurred
-       setorigin(this, this.view_ofs);
-       // reset animstate now
-       this.wframe = WFRAME_IDLE;
-       setanim(this, this.anim_idle, true, false, true);
-}
-
-vector CL_Weapon_GetShotOrg(float wpn)
+vector CL_Weapon_GetShotOrg(int wpn)
 {
        entity wi = Weapons_from(wpn);
        entity e = spawn();
-       .entity weaponentity = weaponentities[0];
-       CL_WeaponEntity_SetModel(e, weaponentity, wi.mdl);
+       CL_WeaponEntity_SetModel(e, wi.mdl);
        vector ret = e.movedir;
-       CL_WeaponEntity_SetModel(e, weaponentity, "");
+       CL_WeaponEntity_SetModel(e, "");
        remove(e);
        return ret;
 }
@@ -330,69 +68,37 @@ void CL_Weaponentity_Think()
        .entity weaponentity = this.weaponentity_fld;
        if (this.owner.(weaponentity) != this)
        {
-               if (this.(weaponentity)) remove(this.(weaponentity));
+               // owner has new gun; remove self
+               if (this.weaponchild) remove(this.weaponchild);
                remove(this);
                return;
        }
        if (this.owner.deadflag != DEAD_NO)
        {
+               // owner died; disappear
                this.model = "";
-               if (this.(weaponentity)) this.(weaponentity).model = "";
+               if (this.weaponchild) this.weaponchild.model = "";
                return;
        }
-       if (this.weaponname != this.owner.weaponname || this.dmg != this.owner.modelindex
+       if (this.weaponname != this.owner.weaponname
+           || this.dmg != this.owner.modelindex
            || this.deadflag != this.owner.deadflag)
        {
+               // owner changed weapons; update appearance
                this.weaponname = this.owner.weaponname;
                this.dmg = this.owner.modelindex;
                this.deadflag = this.owner.deadflag;
 
-               CL_WeaponEntity_SetModel(this, weaponentity, this.owner.weaponname);
+               CL_WeaponEntity_SetModel(this, this.owner.weaponname);
        }
 
-       int tb = (this.effects & (EF_TELEPORT_BIT | EF_RESTARTANIM_BIT));
-       this.effects = this.owner.effects & EFMASK_CHEAP;
-       this.effects &= ~EF_LOWPRECISION;
-       this.effects &= ~EF_FULLBRIGHT;  // can mask team color, so get rid of it
-       this.effects &= ~EF_TELEPORT_BIT;
-       this.effects &= ~EF_RESTARTANIM_BIT;
-       this.effects |= tb;
-       if (weaponentity != weaponentities[0]) this.effects |= EF_NODRAW;
+       this.effects = EF_NODRAW;  // TODO: don't render this entity at all
 
        if (this.owner.alpha == default_player_alpha) this.alpha = default_weapon_alpha;
        else if (this.owner.alpha != 0) this.alpha = this.owner.alpha;
        else this.alpha = 1;
 
-       this.glowmod = this.owner.weaponentity_glowmod;
-       this.colormap = this.owner.colormap;
-       if (this.(weaponentity))
-       {
-               this.(weaponentity).effects = this.effects;
-               this.(weaponentity).alpha = this.alpha;
-               this.(weaponentity).colormap = this.colormap;
-               this.(weaponentity).glowmod = this.glowmod;
-       }
-
-       this.angles = '0 0 0';
-
-       float f = this.weapon_nextthink - time;
-       if (this.state == WS_RAISE && !intermission_running)
-       {
-               entity newwep = Weapons_from(this.owner.switchweapon);
-               f = f * g_weaponratefactor / max(f, newwep.switchdelay_raise);
-               this.angles_x = -90 * f * f;
-       }
-       else if (this.state == WS_DROP && !intermission_running)
-       {
-               entity oldwep = Weapons_from(this.owner.weapon);
-               f = 1 - f * g_weaponratefactor / max(f, oldwep.switchdelay_drop);
-               this.angles_x = -90 * f * f;
-       }
-       else if (this.state == WS_CLEAR)
-       {
-               f = 1;
-               this.angles_x = -90 * f * f;
-       }
+       if (this.weaponchild) this.weaponchild.effects = this.effects;
 }
 
 void CL_ExteriorWeaponentity_Think()
@@ -443,31 +149,27 @@ void CL_ExteriorWeaponentity_Think()
 }
 
 // spawning weaponentity for client
-void CL_SpawnWeaponentity(entity e, .entity weaponentity)
+void CL_SpawnWeaponentity(entity actor, .entity weaponentity)
 {
-       entity view = e.(weaponentity) = new(weaponentity);
+       entity view = actor.(weaponentity) = new(weaponentity);
        make_pure(view);
        view.solid = SOLID_NOT;
-       view.owner = e;
+       view.owner = actor;
        setmodel(view, MDL_Null);  // precision set when changed
        setorigin(view, '0 0 0');
-       view.angles = '0 0 0';
-       view.viewmodelforclient = e;
-       view.flags = 0;
        view.weaponentity_fld = weaponentity;
        view.think = CL_Weaponentity_Think;
-       view.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
        view.nextthink = time;
+       view.viewmodelforclient = actor;
+       view.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
 
        if (weaponentity == weaponentities[0])
        {
-               entity exterior = e.exteriorweaponentity = new(exteriorweaponentity);
+               entity exterior = actor.exteriorweaponentity = new(exteriorweaponentity);
                make_pure(exterior);
                exterior.solid = SOLID_NOT;
-               exterior.exteriorweaponentity = exterior;
-               exterior.owner = e;
+               exterior.owner = actor;
                setorigin(exterior, '0 0 0');
-               exterior.angles = '0 0 0';
                exterior.think = CL_ExteriorWeaponentity_Think;
                exterior.nextthink = time;
 
@@ -513,7 +215,7 @@ bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary
                        if (mine.owner == actor) return false;
 
        if (thiswep == WEP_SHOTGUN)
-               if (!secondary && WEP_CVAR(shotgun, secondary) == 1) return false;             // no clicking, just allow
+               if (!secondary && WEP_CVAR(shotgun, secondary) == 1) return false;           // no clicking, just allow
 
        if (thiswep == Weapons_from(actor.switchweapon) && time - actor.prevdryfire > 1) // only play once BEFORE starting to switch weapons
        {
@@ -608,7 +310,13 @@ bool weapon_prepareattack(Weapon thiswep, entity actor, .entity weaponentity, bo
        return false;
 }
 
-void weapon_thinkf(entity actor, .entity weaponentity, float fr, float t, void(Weapon thiswep, entity actor,
+void wframe_send(entity actor, entity weaponentity, vector a, bool restartanim);
+
+/**
+ * @param t defer thinking until time + t
+ * @param func next think function
+ */
+void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,
        .entity weaponentity, int fire) func)
 {
        entity this = actor.(weaponentity);
@@ -618,13 +326,9 @@ void weapon_thinkf(entity actor, .entity weaponentity, float fr, float t, void(W
                fr = this.wframe;
                restartanim = false;
        }
-       else if (fr == WFRAME_IDLE)
-       {
-               restartanim = false;
-       }
        else
        {
-               restartanim = true;
+               restartanim = fr != WFRAME_IDLE;
        }
 
        vector of = v_forward;
@@ -641,7 +345,8 @@ void weapon_thinkf(entity actor, .entity weaponentity, float fr, float t, void(W
                else  // if (fr == WFRAME_RELOAD)
                        a = this.anim_reload;
                a.z *= g_weaponratefactor;
-               setanim(this, a, restartanim == false, restartanim, restartanim);
+               entity e;
+               FOR_EACH_CLIENT(e) if (e == actor || (IS_SPEC(e) && e.enemy == actor)) wframe_send(e, this, a, restartanim);
        }
 
        v_forward = of;
@@ -665,7 +370,8 @@ void weapon_thinkf(entity actor, .entity weaponentity, float fr, float t, void(W
                this.weapon_nextthink = time;
                // dprint("reset weapon animation timer at ", ftos(time), "\n");
        }
-       this.weapon_nextthink = this.weapon_nextthink + t;
+       this.weapon_nextthink += t;
+       if (weaponentity == weaponentities[0]) actor.weapon_nextthink = this.weapon_nextthink;
        this.weapon_think = func;
        // dprint("next ", ftos(this.weapon_nextthink), "\n");
 
@@ -696,11 +402,11 @@ bool forbidWeaponUse(entity player)
 
 void W_WeaponFrame(entity actor)
 {
-       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+       .entity weaponentity = weaponentities[0];  // TODO: unhardcode
        entity this = actor.(weaponentity);
        if (frametime) actor.weapon_frametime = frametime;
 
-       if (!this || actor.health < 1) return; // Dead player can't use weapons and injure impulse commands
+       if (!this || actor.health < 1) return;  // Dead player can't use weapons and injure impulse commands
 
 
        if (forbidWeaponUse(actor))
@@ -880,9 +586,11 @@ void W_AttachToShotorg(entity actor, entity flash, vector offset)
        flash.owner = actor;
        flash.angles_z = random() * 360;
 
-       entity this = actor.(weaponentity);
-       if (gettagindex(this, "shot")) setattachment(flash, this, "shot");
-       else setattachment(flash, this, "tag_shot");
+       entity view = actor.(weaponentity);
+       entity exterior = actor.exteriorweaponentity;
+
+       if (gettagindex(view, "shot")) setattachment(flash, view, "shot");
+       else setattachment(flash, view, "tag_shot");
        setorigin(flash, offset);
 
        entity xflash = spawn();
@@ -890,15 +598,15 @@ void W_AttachToShotorg(entity actor, entity flash, vector offset)
 
        flash.viewmodelforclient = actor;
 
-       if (this.oldorigin.x > 0)
+       if (view.oldorigin.x > 0)
        {
-               setattachment(xflash, actor.exteriorweaponentity, "");
-               setorigin(xflash, this.oldorigin + offset);
+               setattachment(xflash, exterior, "");
+               setorigin(xflash, view.oldorigin + offset);
        }
        else
        {
-               if (gettagindex(actor.exteriorweaponentity, "shot")) setattachment(xflash, actor.exteriorweaponentity, "shot");
-               else setattachment(xflash, actor.exteriorweaponentity, "tag_shot");
+               if (gettagindex(exterior, "shot")) setattachment(xflash, exterior, "shot");
+               else setattachment(xflash, exterior, "tag_shot");
                setorigin(xflash, offset);
        }
 }
index 97e6c72b4be3698caee7cfca657bf4fd4858c4f2..0000ac2155b762298e15bbb956187955cbec7fb5 100644 (file)
@@ -1,23 +1,11 @@
 #ifndef WEAPONSYSTEM_H
 #define WEAPONSYSTEM_H
 
-.float wframe;
 
 float internalteam;
 float weaponswapping;
 entity weapon_dropevent_item;
 
-// VorteX: static frame globals
-const float WFRAME_DONTCHANGE = -1;
-const float WFRAME_FIRE1 = 0;
-const float WFRAME_FIRE2 = 1;
-const float WFRAME_IDLE = 2;
-const float WFRAME_RELOAD = 3;
-
-vector shotorg_adjust(vector vecs, bool y_is_right, bool visual, int algn);
-
-vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn);
-
 void CL_SpawnWeaponentity(entity e, .entity weaponentity);
 
 vector CL_Weapon_GetShotOrg(float wpn);
@@ -44,6 +32,6 @@ bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponenti
 
 void weapon_prepareattack_do(entity actor, .entity weaponentity, float secondary, float attacktime);
 
-void weapon_thinkf(entity actor, .entity weaponentity, float fr, float t, void(Weapon thiswep, entity actor, .entity weaponentity, int fire) func);
+void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor, .entity weaponentity, int fire) func);
 
 #endif