]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_shotgun.qc
Improve functionality
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_shotgun.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(SHOTGUN, w_shotgun, IT_SHELLS, 2, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_LOW, "shotgun", "shotgun", _("Shotgun"))
3 #else
4 #ifdef SVQC
5
6 void W_Shotgun_DoReload()
7 {
8         w_ready();
9         if(W_SniperRifle_Reload(self.ammo_shells))
10                 return;
11 }
12
13 void W_Shotgun_Attack (void)
14 {
15         float   sc;
16         float   ammoamount;
17         float   bullets;
18         float   d;
19         float   f;
20         float   spread;
21         float   bulletspeed;
22         float   bulletconstant;
23         local entity flash;
24
25         if(self.sniperrifle_bulletcounter <= 0)
26                 W_Shotgun_DoReload();
27         if(self.sniperrifle_bulletcounter < 0)
28                 return; // reloading, so we are done
29
30         ammoamount = autocvar_g_balance_shotgun_primary_ammo;
31         bullets = autocvar_g_balance_shotgun_primary_bullets;
32         d = autocvar_g_balance_shotgun_primary_damage;
33         f = autocvar_g_balance_shotgun_primary_force;
34         spread = autocvar_g_balance_shotgun_primary_spread;
35         bulletspeed = autocvar_g_balance_shotgun_primary_speed;
36         bulletconstant = autocvar_g_balance_shotgun_primary_bulletconstant;
37
38         W_SetupShot (self, autocvar_g_antilag_bullets && bulletspeed >= autocvar_g_antilag_bullets, 5, "weapons/shotgun_fire.wav", CHAN_WEAPON, d * bullets);
39         for (sc = 0;sc < bullets;sc = sc + 1)
40                 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN, 0, 1, bulletconstant);
41         endFireBallisticBullet();
42         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
43                 self.ammo_shells = self.ammo_shells - ammoamount;
44
45         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, autocvar_g_balance_shotgun_primary_ammo);
46
47         // casing code
48         if (autocvar_g_casings >= 1)
49                 for (sc = 0;sc < ammoamount;sc = sc + 1)
50                         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);
51
52         // muzzle flash for 1st person view
53         flash = spawn();
54         setmodel(flash, "models/uziflash.md3"); // precision set below
55         flash.think = SUB_Remove;
56         flash.nextthink = time + 0.06;
57         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
58         W_AttachToShotorg(flash, '5 0 0');
59
60         self.sniperrifle_bulletcounter = self.sniperrifle_bulletcounter - 1;
61 }
62
63 void shotgun_meleethink (void)
64 {
65         // store time when we started swinging down inside self.cnt
66         if(!self.cnt)
67                 self.cnt = time;
68
69         makevectors(self.owner.v_angle);
70         vector angle;
71         angle = v_forward;
72
73         float meleetime;
74         meleetime = autocvar_g_balance_shotgun_secondary_melee_time * W_WeaponRateFactor();
75
76         // perform trace
77         float f;
78         f = (self.cnt + meleetime - time) / meleetime * 2 - 1;
79         vector targpos;
80         targpos = self.owner.origin + self.owner.view_ofs + angle * autocvar_g_balance_shotgun_secondary_melee_range + v_right * f * autocvar_g_balance_shotgun_secondary_melee_swing + v_up * f * autocvar_g_balance_shotgun_secondary_melee_swing;
81
82         WarpZone_traceline_antilag(self.owner, self.owner.origin + self.owner.view_ofs, targpos, FALSE, self.owner, ANTILAG_LATENCY(self.owner));
83
84         // apply the damage, also remove self
85         if(trace_fraction < 1 && trace_ent.takedamage == DAMAGE_AIM && (trace_ent.classname == "player" || trace_ent.classname == "body"))
86         {
87                 vector force;
88                 force = angle * autocvar_g_balance_shotgun_secondary_force;
89                 if(accuracy_isgooddamage(self.owner, trace_ent))
90                         accuracy_add(self.owner, WEP_SHOTGUN, 0, autocvar_g_balance_shotgun_secondary_damage * min(1, f + 1));
91                 Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_shotgun_secondary_damage * min(1, f + 1), WEP_SHOTGUN | HITTYPE_SECONDARY , self.owner.origin + self.owner.view_ofs, force);
92                 remove(self);
93         }
94         else if(time >= self.cnt + meleetime) // missed, remove ent
95                 remove(self);
96         else // continue swinging the weapon in hope of hitting someone :)
97                 self.nextthink = time;
98 }
99
100 void W_Shotgun_Attack2 (void)
101 {
102         sound (self, CHAN_PROJECTILE, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
103         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_shotgun_secondary_animtime, w_ready);
104
105         entity meleetemp;
106         meleetemp = spawn();
107         meleetemp.owner = self;
108         meleetemp.think = shotgun_meleethink;
109         meleetemp.nextthink = time + autocvar_g_balance_shotgun_secondary_melee_delay;
110         W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_shotgun_secondary_damage, autocvar_g_balance_shotgun_secondary_melee_range);
111 }
112
113 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
114
115 .float shotgun_primarytime;
116
117 float w_shotgun(float req)
118 {
119         if (req == WR_AIM)
120                 if(vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_shotgun_secondary_melee_range)
121                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
122                 else
123                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
124         else if (req == WR_THINK)
125         {
126                 if(self.sniperrifle_bulletcounter < 0) // forced reload (e.g. because interrupted)
127             self.wish_reload = 1;
128                 else
129                 {
130                         if (self.BUTTON_ATCK)
131                         {
132                                 if (time >= self.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
133                                 {
134                                         if(weapon_prepareattack(0, autocvar_g_balance_shotgun_primary_animtime))
135                                         {
136                                                 W_Shotgun_Attack();
137                                                 self.shotgun_primarytime = time + autocvar_g_balance_shotgun_primary_refire;
138                                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shotgun_primary_animtime, w_ready);
139                                         }
140                                 }
141                         }
142                         if (self.BUTTON_ATCK2 && autocvar_g_balance_shotgun_secondary)
143                         if (weapon_prepareattack(1, autocvar_g_balance_shotgun_secondary_refire))
144                         {
145                                 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
146                                 weapon_thinkf(WFRAME_FIRE1, 0, W_Shotgun_Attack2);
147                         }
148                 }
149         if(self.wish_reload)
150         {
151             if(self.switchweapon == self.weapon)
152             {
153                 if(self.weaponentity.state == WS_READY)
154                 {
155                     self.wish_reload = 0;
156                     W_SniperRifle_Reload(self.ammo_shells);
157                 }
158             }
159         }
160         }
161         else if (req == WR_PRECACHE)
162         {
163                 precache_model ("models/uziflash.md3");
164                 precache_model ("models/weapons/g_shotgun.md3");
165                 precache_model ("models/weapons/v_shotgun.md3");
166                 precache_model ("models/weapons/h_shotgun.iqm");
167                 precache_sound ("misc/itempickup.wav");
168                 precache_sound ("weapons/shotgun_fire.wav");
169                 precache_sound ("weapons/shotgun_melee.wav");
170         }
171         else if (req == WR_SETUP)
172                 weapon_setup(WEP_SHOTGUN);
173         else if (req == WR_CHECKAMMO1)
174                 return self.ammo_shells >= autocvar_g_balance_shotgun_primary_ammo;
175         else if (req == WR_CHECKAMMO2)
176         {
177                 return TRUE;
178         }
179         return TRUE;
180 };
181 #endif
182 #ifdef CSQC
183 .float prevric;
184 float w_shotgun(float req)
185 {
186         if(req == WR_IMPACTEFFECT)
187         {
188                 vector org2;
189                 org2 = w_org + w_backoff * 2;
190                 pointparticles(particleeffectnum("shotgun_impact"), org2, w_backoff * 1000, 1);
191                 if(!w_issilent && time - self.prevric > 0.25)
192                 {
193                         if(w_random < 0.0165)
194                                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
195                         else if(w_random < 0.033)
196                                 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
197                         else if(w_random < 0.05)
198                                 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
199                         self.prevric = time;
200                 }
201         }
202         else if(req == WR_PRECACHE)
203         {
204                 precache_sound("weapons/ric1.wav");
205                 precache_sound("weapons/ric2.wav");
206                 precache_sound("weapons/ric3.wav");
207         }
208         else if (req == WR_SUICIDEMESSAGE)
209                 w_deathtypestring = "%s did the impossible";
210         else if (req == WR_KILLMESSAGE)
211         {
212                 if(w_deathtype & HITTYPE_SECONDARY)
213                         w_deathtypestring = "%2$s ^7slapped %1$s ^7around a bit with a large ^2shotgun";
214                 else
215                         w_deathtypestring = "%s was gunned by %s";
216         }
217         return TRUE;
218 }
219 #endif
220 #endif