]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_shotgun.qc
On second thought, undo all that shit... this system is WAYYY too hacky to
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_shotgun.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id  */ SHOTGUN,
4 /* function  */ W_Shotgun,
5 /* ammotype  */ ammo_none,
6 /* impulse   */ 2,
7 /* flags     */ WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_MUTATORBLOCKED,
8 /* rating    */ BOT_PICKUP_RATING_LOW,
9 /* color     */ '0.5 0.25 0',
10 /* modelname */ "shotgun",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairshotgun 0.65",
13 /* refname   */ "shotgun",
14 /* wepname   */ _("Shotgun")
15 );
16
17 #define SHOTGUN_SETTINGS(w_cvar,w_prop) SHOTGUN_SETTINGS_LIST(w_cvar, w_prop, SHOTGUN, shotgun)
18 #define SHOTGUN_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
19         w_cvar(id, sn, PRI,  ammo) \
20         w_cvar(id, sn, BOTH, animtime) \
21         w_cvar(id, sn, BOTH, refire) \
22         w_cvar(id, sn, PRI,  bullets) \
23         w_cvar(id, sn, BOTH, damage) \
24         w_cvar(id, sn, BOTH, force) \
25         w_cvar(id, sn, PRI,  solidpenetration) \
26         w_cvar(id, sn, PRI,  spread) \
27         w_cvar(id, sn, NONE, secondary) \
28         w_cvar(id, sn, SEC,  melee_time) \
29         w_cvar(id, sn, SEC,  melee_no_doubleslap) \
30         w_cvar(id, sn, SEC,  melee_traces) \
31         w_cvar(id, sn, SEC,  melee_swing_up) \
32         w_cvar(id, sn, SEC,  melee_swing_side) \
33         w_cvar(id, sn, SEC,  melee_nonplayerdamage) \
34         w_cvar(id, sn, SEC,  melee_multihit) \
35         w_cvar(id, sn, SEC,  melee_delay) \
36         w_cvar(id, sn, SEC,  melee_range) \
37         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
38         w_prop(id, sn, float,  reloading_time, reload_time) \
39         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
40         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
41         w_prop(id, sn, string, weaponreplace, weaponreplace) \
42         w_prop(id, sn, float,  weaponstart, weaponstart) \
43         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
44
45 #ifdef SVQC
46 SHOTGUN_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
47 #endif
48 #else
49 #ifdef SVQC
50
51 void W_Shotgun_Attack (void)
52 {
53         float   sc;
54         entity flash;
55
56         W_DecreaseAmmo(WEP_CVAR_PRI(shotgun, ammo));
57
58         W_SetupShot (self, TRUE, 5, "weapons/shotgun_fire.wav", CH_WEAPON_A, WEP_CVAR_PRI(shotgun, damage) * WEP_CVAR_PRI(shotgun, bullets));
59         for (sc = 0;sc < WEP_CVAR_PRI(shotgun, bullets);sc = sc + 1)
60                 fireBullet(w_shotorg, w_shotdir, WEP_CVAR_PRI(shotgun, spread), WEP_CVAR_PRI(shotgun, solidpenetration), WEP_CVAR_PRI(shotgun, damage), WEP_CVAR_PRI(shotgun, force), WEP_SHOTGUN, 0);
61
62         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, WEP_CVAR_PRI(shotgun, ammo));
63
64         // casing code
65         if (autocvar_g_casings >= 1)
66                 for (sc = 0;sc < WEP_CVAR_PRI(shotgun, ammo);sc = sc + 1)
67                         SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, self);
68
69         // muzzle flash for 1st person view
70         flash = spawn();
71         setmodel(flash, "models/uziflash.md3"); // precision set below
72         flash.think = SUB_Remove;
73         flash.nextthink = time + 0.06;
74         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
75         W_AttachToShotorg(flash, '5 0 0');
76 }
77
78 .float swing_prev;
79 .entity swing_alreadyhit;
80 void W_Shotgun_Melee_Think()
81 {
82         // declarations
83         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
84         entity target_victim;
85         vector targpos;
86
87         if(!self.cnt) // set start time of melee
88         {
89                 self.cnt = time;
90                 W_PlayStrengthSound(self.realowner);
91         }
92
93         makevectors(self.realowner.v_angle); // update values for v_* vectors
94
95         // calculate swing percentage based on time
96         meleetime = WEP_CVAR_SEC(shotgun, melee_time) * W_WeaponRateFactor();
97         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
98         f = ((1 - swing) * WEP_CVAR_SEC(shotgun, melee_traces));
99
100         // check to see if we can still continue, otherwise give up now
101         if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR_SEC(shotgun, melee_no_doubleslap))
102         {
103                 remove(self);
104                 return;
105         }
106
107         // if okay, perform the traces needed for this frame
108         for(i=self.swing_prev; i < f; ++i)
109         {
110                 swing_factor = ((1 - (i / WEP_CVAR_SEC(shotgun, melee_traces))) * 2 - 1);
111
112                 targpos = (self.realowner.origin + self.realowner.view_ofs
113                         + (v_forward * WEP_CVAR_SEC(shotgun, melee_range))
114                         + (v_up * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_up))
115                         + (v_right * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_side)));
116
117                 WarpZone_traceline_antilag(self, self.realowner.origin + self.realowner.view_ofs, targpos, FALSE, self, ANTILAG_LATENCY(self.realowner));
118
119                 // draw lightning beams for debugging
120                 //te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
121                 //te_customflash(targpos, 40,  2, '1 1 1');
122
123                 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body");
124
125                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
126                         && (trace_ent.takedamage == DAMAGE_AIM)
127                         && (trace_ent != self.swing_alreadyhit)
128                         && (is_player || WEP_CVAR_SEC(shotgun, melee_nonplayerdamage)))
129                 {
130                         target_victim = trace_ent; // so it persists through other calls
131
132                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
133                                 swing_damage = (WEP_CVAR_SEC(shotgun, damage) * min(1, swing_factor + 1));
134                         else
135                                 swing_damage = (WEP_CVAR_SEC(shotgun, melee_nonplayerdamage) * min(1, swing_factor + 1));
136
137                         //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
138
139                         Damage(target_victim, self.realowner, self.realowner,
140                                 swing_damage, WEP_SHOTGUN | HITTYPE_SECONDARY,
141                                 self.realowner.origin + self.realowner.view_ofs,
142                                 v_forward * WEP_CVAR_SEC(shotgun, force));
143
144                         if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOTGUN, 0, swing_damage); }
145
146                         // draw large red flash for debugging
147                         //te_customflash(targpos, 200, 2, '15 0 0');
148
149                         if(WEP_CVAR_SEC(shotgun, melee_multihit)) // allow multiple hits with one swing, but not against the same player twice.
150                         {
151                                 self.swing_alreadyhit = target_victim;
152                                 continue; // move along to next trace
153                         }
154                         else
155                         {
156                                 remove(self);
157                                 return;
158                         }
159                 }
160         }
161
162         if(time >= self.cnt + meleetime)
163         {
164                 // melee is finished
165                 remove(self);
166                 return;
167         }
168         else
169         {
170                 // set up next frame
171                 self.swing_prev = i;
172                 self.nextthink = time;
173         }
174 }
175
176 void W_Shotgun_Attack2 (void)
177 {
178         sound (self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTEN_NORM);
179         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(shotgun, animtime), w_ready);
180
181         entity meleetemp;
182         meleetemp = spawn();
183         meleetemp.realowner = self;
184         meleetemp.think = W_Shotgun_Melee_Think;
185         meleetemp.nextthink = time + WEP_CVAR_SEC(shotgun, melee_delay) * W_WeaponRateFactor();
186         W_SetupShot_Range(self, TRUE, 0, "", 0, WEP_CVAR_SEC(shotgun, damage), WEP_CVAR_SEC(shotgun, melee_range));
187 }
188
189 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
190
191 .float shotgun_primarytime;
192
193 float W_Shotgun(float req)
194 {
195         switch(req)
196         {
197                 case WR_AIM:
198                 {
199                         if(vlen(self.origin-self.enemy.origin) <= WEP_CVAR_SEC(shotgun, melee_range))
200                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
201                         else
202                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
203
204                         return TRUE;
205                 }
206                 case WR_THINK:
207                 {
208                         if(WEP_CVAR(shotgun, reload_ammo) && self.clip_load < WEP_CVAR_PRI(shotgun, ammo)) // forced reload
209                         {
210                                 // don't force reload an empty shotgun if its melee attack is active
211                                 if (!WEP_CVAR(shotgun, secondary))
212                                         WEP_ACTION(self.weapon, WR_RELOAD);
213                         }
214                         else
215                         {
216                                 if (self.BUTTON_ATCK)
217                                 {
218                                         if (time >= self.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
219                                         {
220                                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(shotgun, animtime)))
221                                                 {
222                                                         W_Shotgun_Attack();
223                                                         self.shotgun_primarytime = time + WEP_CVAR_PRI(shotgun, refire) * W_WeaponRateFactor();
224                                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(shotgun, animtime), w_ready);
225                                                 }
226                                         }
227                                 }
228                         }
229                         if (self.clip_load >= 0) // we are not currently reloading
230                         if (!self.crouch) // no crouchmelee please
231                         if (self.BUTTON_ATCK2 && WEP_CVAR(shotgun, secondary))
232                         if (weapon_prepareattack(1, WEP_CVAR_SEC(shotgun, refire)))
233                         {
234                                 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
235                                 weapon_thinkf(WFRAME_FIRE1, 0, W_Shotgun_Attack2);
236                         }
237                         
238                         return TRUE;
239                 }
240                 case WR_INIT:
241                 {
242                         precache_model ("models/uziflash.md3");
243                         precache_model ("models/weapons/g_shotgun.md3");
244                         precache_model ("models/weapons/v_shotgun.md3");
245                         precache_model ("models/weapons/h_shotgun.iqm");
246                         precache_sound ("misc/itempickup.wav");
247                         precache_sound ("weapons/shotgun_fire.wav");
248                         precache_sound ("weapons/shotgun_melee.wav");
249                         SHOTGUN_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
250                         return TRUE;
251                 }
252                 case WR_SETUP:
253                 {
254                         self.ammo_field = ammo_none;
255                         return TRUE;
256                 }
257                 case WR_CHECKAMMO1:
258                 case WR_CHECKAMMO2:
259                 {
260                         // shotgun has infinite ammo
261                         return TRUE;
262                 }
263                 case WR_CONFIG:
264                 {
265                         SHOTGUN_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
266                         return TRUE;
267                 }
268                 case WR_RELOAD:
269                 {
270                         W_Reload(WEP_CVAR_PRI(shotgun, ammo), "weapons/reload.wav"); // WEAPONTODO
271                         return TRUE;
272                 }
273                 case WR_SUICIDEMESSAGE:
274                 {
275                         return WEAPON_THINKING_WITH_PORTALS;
276                 }
277                 case WR_KILLMESSAGE:
278                 {
279                         if(w_deathtype & HITTYPE_SECONDARY)
280                                 return WEAPON_SHOTGUN_MURDER_SLAP;
281                         else
282                                 return WEAPON_SHOTGUN_MURDER;
283                 }
284         }
285
286         return TRUE;
287 }
288 #endif
289 #ifdef CSQC
290 .float prevric;
291 float W_Shotgun(float req)
292 {
293         switch(req)
294         {
295                 case WR_IMPACTEFFECT:
296                 {
297                         vector org2;
298                         org2 = w_org + w_backoff * 2;
299                         pointparticles(particleeffectnum("shotgun_impact"), org2, w_backoff * 1000, 1);
300                         if(!w_issilent && time - self.prevric > 0.25)
301                         {
302                                 if(w_random < 0.0165)
303                                         sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
304                                 else if(w_random < 0.033)
305                                         sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
306                                 else if(w_random < 0.05)
307                                         sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
308                                 self.prevric = time;
309                         }
310
311                         return TRUE;
312                 }
313                 case WR_INIT:
314                 {
315                         precache_sound("weapons/ric1.wav");
316                         precache_sound("weapons/ric2.wav");
317                         precache_sound("weapons/ric3.wav");
318                         return TRUE;
319                 }
320                 case WR_ZOOMRETICLE:
321                 {
322                         // no weapon specific image for this weapon
323                         return FALSE;
324                 }
325         }
326         return TRUE;
327 }
328 #endif
329 #endif