]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_shotgun.qc
Merge branch 'master' into terencehill/vehicles_fixes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_shotgun.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id  */ SHOTGUN,
4 /* function  */ w_shotgun,
5 /* ammotype  */ IT_SHELLS,
6 /* impulse   */ 2,
7 /* flags     */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating    */ BOT_PICKUP_RATING_LOW,
9 /* model     */ "shotgun",
10 /* shortname */ "shotgun",
11 /* fullname  */ _("Shotgun")
12 );
13 #else
14 #ifdef SVQC
15
16 void W_Shotgun_Attack (void)
17 {
18         float   sc;
19         float   ammoamount;
20         float   bullets;
21         float   d;
22         float   f;
23         float   spread;
24         float   solidpenetration;
25         entity flash;
26
27         ammoamount = autocvar_g_balance_shotgun_primary_ammo;
28         bullets = autocvar_g_balance_shotgun_primary_bullets;
29         d = autocvar_g_balance_shotgun_primary_damage;
30         f = autocvar_g_balance_shotgun_primary_force;
31         spread = autocvar_g_balance_shotgun_primary_spread;
32         solidpenetration = autocvar_g_balance_shotgun_primary_solidpenetration;
33
34         W_DecreaseAmmo(ammo_shells, ammoamount, autocvar_g_balance_shotgun_reload_ammo);
35
36         W_SetupShot (self, TRUE, 5, "weapons/shotgun_fire.wav", CH_WEAPON_A, d * bullets);
37         for (sc = 0;sc < bullets;sc = sc + 1)
38                 fireBullet(w_shotorg, w_shotdir, spread, solidpenetration, d, f, WEP_SHOTGUN, 0);
39
40         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, autocvar_g_balance_shotgun_primary_ammo);
41
42         // casing code
43         if (autocvar_g_casings >= 1)
44                 for (sc = 0;sc < ammoamount;sc = sc + 1)
45                         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);
46
47         // muzzle flash for 1st person view
48         flash = spawn();
49         setmodel(flash, "models/uziflash.md3"); // precision set below
50         flash.think = SUB_Remove;
51         flash.nextthink = time + 0.06;
52         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
53         W_AttachToShotorg(flash, '5 0 0');
54 }
55
56 .float swing_prev;
57 .entity swing_alreadyhit;
58 void shotgun_meleethink (void)
59 {
60         // declarations
61         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
62         entity target_victim;
63         vector targpos;
64
65         if(!self.cnt) // set start time of melee
66         {
67                 self.cnt = time;
68                 W_PlayStrengthSound(self.realowner);
69         }
70
71         makevectors(self.realowner.v_angle); // update values for v_* vectors
72
73         // calculate swing percentage based on time
74         meleetime = autocvar_g_balance_shotgun_secondary_melee_time * W_WeaponRateFactor();
75         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
76         f = ((1 - swing) * autocvar_g_balance_shotgun_secondary_melee_traces);
77
78         // check to see if we can still continue, otherwise give up now
79         if((self.realowner.deadflag != DEAD_NO) && autocvar_g_balance_shotgun_secondary_melee_no_doubleslap)
80         {
81                 remove(self);
82                 return;
83         }
84
85         // if okay, perform the traces needed for this frame
86         for(i=self.swing_prev; i < f; ++i)
87         {
88                 swing_factor = ((1 - (i / autocvar_g_balance_shotgun_secondary_melee_traces)) * 2 - 1);
89
90                 targpos = (self.realowner.origin + self.realowner.view_ofs
91                         + (v_forward * autocvar_g_balance_shotgun_secondary_melee_range)
92                         + (v_up * swing_factor * autocvar_g_balance_shotgun_secondary_melee_swing_up)
93                         + (v_right * swing_factor * autocvar_g_balance_shotgun_secondary_melee_swing_side));
94
95                 WarpZone_traceline_antilag(self, self.realowner.origin + self.realowner.view_ofs, targpos, FALSE, self, ANTILAG_LATENCY(self.realowner));
96
97                 // draw lightning beams for debugging
98                 //te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
99                 //te_customflash(targpos, 40,  2, '1 1 1');
100
101                 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body");
102
103                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
104                         && (trace_ent.takedamage == DAMAGE_AIM)
105                         && (trace_ent != self.swing_alreadyhit)
106                         && (is_player || autocvar_g_balance_shotgun_secondary_melee_nonplayerdamage))
107                 {
108                         target_victim = trace_ent; // so it persists through other calls
109
110                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
111                                 swing_damage = (autocvar_g_balance_shotgun_secondary_damage * min(1, swing_factor + 1));
112                         else
113                                 swing_damage = (autocvar_g_balance_shotgun_secondary_melee_nonplayerdamage * min(1, swing_factor + 1));
114
115                         //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
116
117                         Damage(target_victim, self.realowner, self.realowner,
118                                 swing_damage, WEP_SHOTGUN | HITTYPE_SECONDARY,
119                                 self.realowner.origin + self.realowner.view_ofs,
120                                 v_forward * autocvar_g_balance_shotgun_secondary_force);
121
122                         if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOTGUN, 0, swing_damage); }
123
124                         // draw large red flash for debugging
125                         //te_customflash(targpos, 200, 2, '15 0 0');
126
127                         if(autocvar_g_balance_shotgun_secondary_melee_multihit) // allow multiple hits with one swing, but not against the same player twice.
128                         {
129                                 self.swing_alreadyhit = target_victim;
130                                 continue; // move along to next trace
131                         }
132                         else
133                         {
134                                 remove(self);
135                                 return;
136                         }
137                 }
138         }
139
140         if(time >= self.cnt + meleetime)
141         {
142                 // melee is finished
143                 remove(self);
144                 return;
145         }
146         else
147         {
148                 // set up next frame
149                 self.swing_prev = i;
150                 self.nextthink = time;
151         }
152 }
153
154 void W_Shotgun_Attack2 (void)
155 {
156         sound (self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTEN_NORM);
157         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_shotgun_secondary_animtime, w_ready);
158
159         entity meleetemp;
160         meleetemp = spawn();
161         meleetemp.realowner = self;
162         meleetemp.think = shotgun_meleethink;
163         meleetemp.nextthink = time + autocvar_g_balance_shotgun_secondary_melee_delay * W_WeaponRateFactor();
164         W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_shotgun_secondary_damage, autocvar_g_balance_shotgun_secondary_melee_range);
165 }
166
167 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
168
169 .float shotgun_primarytime;
170
171 float w_shotgun(float req)
172 {
173         float ammo_amount;
174         if (req == WR_AIM)
175                 if(vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_shotgun_secondary_melee_range)
176                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
177                 else
178                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
179
180         else if (req == WR_THINK)
181         {
182                 if(autocvar_g_balance_shotgun_reload_ammo && self.clip_load < autocvar_g_balance_shotgun_primary_ammo) // forced reload
183                 {
184                         // don't force reload an empty shotgun if its melee attack is active
185                         if (!(autocvar_g_balance_shotgun_secondary && self.ammo_shells < autocvar_g_balance_shotgun_primary_ammo))
186                                 weapon_action(self.weapon, WR_RELOAD);
187                 }
188                 else
189                 {
190                         if (self.BUTTON_ATCK)
191                         {
192                                 if (time >= self.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
193                                 {
194                                         if(weapon_prepareattack(0, autocvar_g_balance_shotgun_primary_animtime))
195                                         {
196                                                 W_Shotgun_Attack();
197                                                 self.shotgun_primarytime = time + autocvar_g_balance_shotgun_primary_refire * W_WeaponRateFactor();
198                                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shotgun_primary_animtime, w_ready);
199                                         }
200                                 }
201                         }
202                 }
203                 if (self.clip_load >= 0) // we are not currently reloading
204                 if (!self.crouch) // no crouchmelee please
205                 if (self.BUTTON_ATCK2 && autocvar_g_balance_shotgun_secondary)
206                 if (weapon_prepareattack(1, autocvar_g_balance_shotgun_secondary_refire))
207                 {
208                         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
209                         weapon_thinkf(WFRAME_FIRE1, 0, W_Shotgun_Attack2);
210                 }
211         }
212         else if (req == WR_PRECACHE)
213         {
214                 precache_model ("models/uziflash.md3");
215                 precache_model ("models/weapons/g_shotgun.md3");
216                 precache_model ("models/weapons/v_shotgun.md3");
217                 precache_model ("models/weapons/h_shotgun.iqm");
218                 precache_sound ("misc/itempickup.wav");
219                 precache_sound ("weapons/shotgun_fire.wav");
220                 precache_sound ("weapons/shotgun_melee.wav");
221                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
222         }
223         else if (req == WR_SETUP)
224         {
225                 weapon_setup(WEP_SHOTGUN);
226                 self.current_ammo = ammo_shells;
227         }
228         else if (req == WR_CHECKAMMO1)
229         {
230                 ammo_amount = self.ammo_shells >= autocvar_g_balance_shotgun_primary_ammo;
231                 ammo_amount += self.(weapon_load[WEP_SHOTGUN]) >= autocvar_g_balance_shotgun_primary_ammo;
232                 return ammo_amount;
233         }
234         else if (req == WR_CHECKAMMO2)
235         {
236                 // melee attack is always available
237                 return TRUE;
238         }
239         else if (req == WR_RELOAD)
240         {
241                 W_Reload(autocvar_g_balance_shotgun_primary_ammo, autocvar_g_balance_shotgun_reload_ammo, autocvar_g_balance_shotgun_reload_time, "weapons/reload.wav");
242         }
243         else if (req == WR_SUICIDEMESSAGE)
244         {
245                 return WEAPON_THINKING_WITH_PORTALS;
246         }
247         else if (req == WR_KILLMESSAGE)
248         {
249                 if(w_deathtype & HITTYPE_SECONDARY)
250                         return WEAPON_SHOTGUN_MURDER_SLAP;
251                 else
252                         return WEAPON_SHOTGUN_MURDER;
253         }
254         return TRUE;
255 }
256 #endif
257 #ifdef CSQC
258 .float prevric;
259 float w_shotgun(float req)
260 {
261         if(req == WR_IMPACTEFFECT)
262         {
263                 vector org2;
264                 org2 = w_org + w_backoff * 2;
265                 pointparticles(particleeffectnum("shotgun_impact"), org2, w_backoff * 1000, 1);
266                 if(!w_issilent && time - self.prevric > 0.25)
267                 {
268                         if(w_random < 0.0165)
269                                 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
270                         else if(w_random < 0.033)
271                                 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
272                         else if(w_random < 0.05)
273                                 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
274                         self.prevric = time;
275                 }
276         }
277         else if(req == WR_PRECACHE)
278         {
279                 precache_sound("weapons/ric1.wav");
280                 precache_sound("weapons/ric2.wav");
281                 precache_sound("weapons/ric3.wav");
282         }
283         return TRUE;
284 }
285 #endif
286 #endif