]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_shotgun.qc
fix a bunch of clone bugs to get desired behaviour back
[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, is_monster;
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                 is_monster = (trace_ent.flags & FL_MONSTER);
103
104                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
105                         && (trace_ent.takedamage == DAMAGE_AIM)
106                         && (trace_ent != self.swing_alreadyhit)
107                         && ((is_player || is_monster) || autocvar_g_balance_shotgun_secondary_melee_nonplayerdamage))
108                 {
109                         target_victim = trace_ent; // so it persists through other calls
110
111                         if(is_player || is_monster) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
112                                 swing_damage = (autocvar_g_balance_shotgun_secondary_damage * min(1, swing_factor + 1));
113                         else
114                                 swing_damage = (autocvar_g_balance_shotgun_secondary_melee_nonplayerdamage * min(1, swing_factor + 1));
115
116                         //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
117
118                         Damage(target_victim, self.realowner, self.realowner,
119                                 swing_damage, WEP_SHOTGUN | HITTYPE_SECONDARY,
120                                 self.realowner.origin + self.realowner.view_ofs,
121                                 v_forward * autocvar_g_balance_shotgun_secondary_force);
122
123                         if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOTGUN, 0, swing_damage); }
124
125                         // draw large red flash for debugging
126                         //te_customflash(targpos, 200, 2, '15 0 0');
127
128                         if(autocvar_g_balance_shotgun_secondary_melee_multihit) // allow multiple hits with one swing, but not against the same player twice.
129                         {
130                                 self.swing_alreadyhit = target_victim;
131                                 continue; // move along to next trace
132                         }
133                         else
134                         {
135                                 remove(self);
136                                 return;
137                         }
138                 }
139         }
140
141         if(time >= self.cnt + meleetime)
142         {
143                 // melee is finished
144                 remove(self);
145                 return;
146         }
147         else
148         {
149                 // set up next frame
150                 self.swing_prev = i;
151                 self.nextthink = time;
152         }
153 }
154
155 void W_Shotgun_Attack2 (void)
156 {
157         sound (self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTEN_NORM);
158         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_shotgun_secondary_animtime, w_ready);
159
160         entity meleetemp;
161         meleetemp = spawn();
162         meleetemp.realowner = self;
163         meleetemp.think = shotgun_meleethink;
164         meleetemp.nextthink = time + autocvar_g_balance_shotgun_secondary_melee_delay * W_WeaponRateFactor();
165         W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_shotgun_secondary_damage, autocvar_g_balance_shotgun_secondary_melee_range);
166 }
167
168 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
169
170 .float shotgun_primarytime;
171
172 float w_shotgun(float req)
173 {
174         float ammo_amount;
175         if (req == WR_AIM)
176                 if(vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_shotgun_secondary_melee_range)
177                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
178                 else
179                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
180
181         else if (req == WR_THINK)
182         {
183                 if(autocvar_g_balance_shotgun_reload_ammo && self.clip_load < autocvar_g_balance_shotgun_primary_ammo) // forced reload
184                 {
185                         // don't force reload an empty shotgun if its melee attack is active
186                         if (!(autocvar_g_balance_shotgun_secondary && self.ammo_shells < autocvar_g_balance_shotgun_primary_ammo))
187                                 weapon_action(self.weapon, WR_RELOAD);
188                 }
189                 else
190                 {
191                         if (self.BUTTON_ATCK)
192                         {
193                                 if (time >= self.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
194                                 {
195                                         if(weapon_prepareattack(0, autocvar_g_balance_shotgun_primary_animtime))
196                                         {
197                                                 W_Shotgun_Attack();
198                                                 self.shotgun_primarytime = time + autocvar_g_balance_shotgun_primary_refire * W_WeaponRateFactor();
199                                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shotgun_primary_animtime, w_ready);
200                                         }
201                                 }
202                         }
203                 }
204                 if (self.clip_load >= 0) // we are not currently reloading
205                 if (!self.crouch) // no crouchmelee please
206                 if (self.BUTTON_ATCK2 && autocvar_g_balance_shotgun_secondary)
207                 if (weapon_prepareattack(1, autocvar_g_balance_shotgun_secondary_refire))
208                 {
209                         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
210                         weapon_thinkf(WFRAME_FIRE1, 0, W_Shotgun_Attack2);
211                 }
212         }
213         else if (req == WR_PRECACHE)
214         {
215                 precache_model ("models/uziflash.md3");
216                 precache_model ("models/weapons/g_shotgun.md3");
217                 precache_model ("models/weapons/v_shotgun.md3");
218                 precache_model ("models/weapons/h_shotgun.iqm");
219                 precache_sound ("misc/itempickup.wav");
220                 precache_sound ("weapons/shotgun_fire.wav");
221                 precache_sound ("weapons/shotgun_melee.wav");
222                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
223         }
224         else if (req == WR_SETUP)
225         {
226                 weapon_setup(WEP_SHOTGUN);
227                 self.current_ammo = ammo_shells;
228         }
229         else if (req == WR_CHECKAMMO1)
230         {
231                 ammo_amount = self.ammo_shells >= autocvar_g_balance_shotgun_primary_ammo;
232                 ammo_amount += self.(weapon_load[WEP_SHOTGUN]) >= autocvar_g_balance_shotgun_primary_ammo;
233                 return ammo_amount;
234         }
235         else if (req == WR_CHECKAMMO2)
236         {
237                 // melee attack is always available
238                 return TRUE;
239         }
240         else if (req == WR_RELOAD)
241         {
242                 W_Reload(autocvar_g_balance_shotgun_primary_ammo, autocvar_g_balance_shotgun_reload_ammo, autocvar_g_balance_shotgun_reload_time, "weapons/reload.wav");
243         }
244         else if (req == WR_SUICIDEMESSAGE)
245         {
246                 return WEAPON_THINKING_WITH_PORTALS;
247         }
248         else if (req == WR_KILLMESSAGE)
249         {
250                 if(w_deathtype & HITTYPE_SECONDARY)
251                         return WEAPON_SHOTGUN_MURDER_SLAP;
252                 else
253                         return WEAPON_SHOTGUN_MURDER;
254         }
255         return TRUE;
256 }
257 #endif
258 #ifdef CSQC
259 .float prevric;
260 float w_shotgun(float req)
261 {
262         if(req == WR_IMPACTEFFECT)
263         {
264                 vector org2;
265                 org2 = w_org + w_backoff * 2;
266                 pointparticles(particleeffectnum("shotgun_impact"), org2, w_backoff * 1000, 1);
267                 if(!w_issilent && time - self.prevric > 0.25)
268                 {
269                         if(w_random < 0.0165)
270                                 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
271                         else if(w_random < 0.033)
272                                 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
273                         else if(w_random < 0.05)
274                                 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
275                         self.prevric = time;
276                 }
277         }
278         else if(req == WR_PRECACHE)
279         {
280                 precache_sound("weapons/ric1.wav");
281                 precache_sound("weapons/ric2.wav");
282                 precache_sound("weapons/ric3.wav");
283         }
284         return TRUE;
285 }
286 #endif
287 #endif