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