]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hagar.qc
Properly implement the new check for all weapons (hopefully, only testing can tell)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hagar.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(HAGAR, w_hagar, IT_ROCKETS, 8, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hagar", "hagar", _("Hagar"))
3 #else
4 #ifdef SVQC
5 // NO bounce protection, as bounces are limited!
6
7 void W_Hagar_SetAmmoCounter()
8 {
9         // set clip_load to the weapon we have switched to, if the gun uses reloading
10         if(!autocvar_g_balance_hagar_reload_ammo)
11                 self.clip_load = 0; // also keeps crosshair ammo from displaying
12         else
13         {
14                 self.clip_load = self.hagar_load;
15                 self.clip_size = autocvar_g_balance_hagar_reload_ammo; // for the crosshair ammo display
16         }
17 }
18
19 void W_Hagar_ReloadedAndReady()
20 {
21         float t;
22
23         // now do the ammo transfer
24         self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
25         while(self.clip_load < autocvar_g_balance_hagar_reload_ammo && self.ammo_rockets) // make sure we don't add more ammo than we have
26         {
27                 self.clip_load += 1;
28                 self.ammo_rockets -= 1;
29         }
30         self.hagar_load = self.clip_load;
31
32         t = ATTACK_FINISHED(self) - autocvar_g_balance_hagar_reload_time - 1;
33         ATTACK_FINISHED(self) = t;
34         w_ready();
35 }
36
37 void W_Hagar_Reload()
38 {
39         // return if reloading is disabled for this weapon
40         if(!autocvar_g_balance_hagar_reload_ammo)
41                 return;
42
43         if(!W_ReloadCheck(self.ammo_rockets, min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo)))
44                 return;
45
46         float t;
47
48         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
49
50         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_hagar_reload_time + 1;
51         ATTACK_FINISHED(self) = t;
52
53         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_hagar_reload_time, W_Hagar_ReloadedAndReady);
54
55         self.old_clip_load = self.clip_load;
56         self.clip_load = -1;
57 }
58
59 void W_Hagar_Explode (void)
60 {
61         self.event_damage = SUB_Null;
62         RadiusDamage (self, self.realowner, autocvar_g_balance_hagar_primary_damage, autocvar_g_balance_hagar_primary_edgedamage, autocvar_g_balance_hagar_primary_radius, world, autocvar_g_balance_hagar_primary_force, self.projectiledeathtype, other);
63
64         remove (self);
65 }
66
67 void W_Hagar_Explode2 (void)
68 {
69         self.event_damage = SUB_Null;
70         RadiusDamage (self, self.realowner, autocvar_g_balance_hagar_secondary_damage, autocvar_g_balance_hagar_secondary_edgedamage, autocvar_g_balance_hagar_secondary_radius, world, autocvar_g_balance_hagar_secondary_force, self.projectiledeathtype, other);
71
72         remove (self);
73 }
74
75 void W_Hagar_Touch (void)
76 {
77         PROJECTILE_TOUCH;
78         self.use ();
79 }
80
81 void W_Hagar_Touch2 (void)
82 {
83         PROJECTILE_TOUCH;
84
85         if(self.cnt > 0 || other.takedamage == DAMAGE_AIM) {
86                 self.use();
87         } else {
88                 self.cnt++;
89                 pointparticles(particleeffectnum("hagar_bounce"), self.origin, self.velocity, 1);
90                 self.angles = vectoangles (self.velocity);
91                 self.owner = world;
92                 self.projectiledeathtype |= HITTYPE_BOUNCE;
93         }
94 }
95
96 void W_Hagar_Attack (void)
97 {
98         local entity missile;
99
100         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
101         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
102         {
103                 if(autocvar_g_balance_hagar_reload_ammo)
104                 {
105                         self.clip_load -= autocvar_g_balance_hagar_primary_ammo;
106                         self.hagar_load = self.clip_load;
107                 }
108                 else
109                         self.ammo_rockets -= autocvar_g_balance_hagar_primary_ammo;
110         }
111
112         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_primary_damage);
113
114         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
115
116         missile = spawn ();
117         missile.owner = missile.realowner = self;
118         missile.classname = "missile";
119         missile.bot_dodge = TRUE;
120         missile.bot_dodgerating = autocvar_g_balance_hagar_primary_damage;
121         missile.touch = W_Hagar_Touch;
122         missile.use = W_Hagar_Explode;
123         missile.think = adaptor_think2use_hittype_splash;
124         missile.nextthink = time + autocvar_g_balance_hagar_primary_lifetime;
125         PROJECTILE_MAKETRIGGER(missile);
126         missile.projectiledeathtype = WEP_HAGAR;
127         setorigin (missile, w_shotorg);
128         setsize(missile, '0 0 0', '0 0 0');
129
130         missile.movetype = MOVETYPE_FLY;
131         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_primary);
132
133         missile.angles = vectoangles (missile.velocity);
134         missile.flags = FL_PROJECTILE;
135
136         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
137
138         other = missile; MUTATOR_CALLHOOK(EditProjectile);
139 }
140
141 void W_Hagar_Attack2 (void)
142 {
143         local entity missile;
144
145         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
146         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
147         {
148                 if(autocvar_g_balance_hagar_reload_ammo)
149                 {
150                         self.clip_load -= autocvar_g_balance_hagar_secondary_ammo;
151                         self.hagar_load = self.clip_load;
152                 }
153                 else
154                         self.ammo_rockets -= autocvar_g_balance_hagar_secondary_ammo;
155         }
156
157         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_secondary_damage);
158
159         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
160
161         missile = spawn ();
162         missile.owner = missile.realowner = self;
163         missile.classname = "missile";
164         missile.bot_dodge = TRUE;
165         missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
166         missile.touch = W_Hagar_Touch2;
167         missile.cnt = 0;
168         missile.use = W_Hagar_Explode2;
169         missile.think = adaptor_think2use_hittype_splash;
170         missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
171         PROJECTILE_MAKETRIGGER(missile);
172         missile.projectiledeathtype = WEP_HAGAR | HITTYPE_SECONDARY;
173         setorigin (missile, w_shotorg);
174         setsize(missile, '0 0 0', '0 0 0');
175
176         missile.movetype = MOVETYPE_BOUNCEMISSILE;
177         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_secondary);
178
179         missile.angles = vectoangles (missile.velocity);
180         missile.flags = FL_PROJECTILE;
181
182         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR_BOUNCING, TRUE);
183
184         other = missile; MUTATOR_CALLHOOK(EditProjectile);
185 }
186
187 void spawnfunc_weapon_hagar (void)
188 {
189         weapon_defaultspawnfunc(WEP_HAGAR);
190 }
191
192 float w_hagar(float req)
193 {
194         float ammo_amount;
195         if (req == WR_AIM)
196                 if (random()>0.15)
197                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
198                 else
199                 {
200                         // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
201                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
202                 }
203         else if (req == WR_THINK)
204         {
205                 if(autocvar_g_balance_hagar_reload_ammo && self.clip_load < min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo)) // forced reload
206                         W_Hagar_Reload();
207                 else if (self.BUTTON_ATCK)
208                 {
209                         if (weapon_prepareattack(0, autocvar_g_balance_hagar_primary_refire))
210                         {
211                                 W_Hagar_Attack();
212                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hagar_primary_refire, w_ready);
213                         }
214                 }
215                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hagar_secondary)
216                 {
217                         if (weapon_prepareattack(1, autocvar_g_balance_hagar_secondary_refire))
218                         {
219                                 W_Hagar_Attack2();
220                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hagar_secondary_refire, w_ready);
221                         }
222                 }
223         if(self.wish_reload)
224         {
225             if(self.switchweapon == self.weapon)
226             {
227                 if(self.weaponentity.state == WS_READY)
228                 {
229                     self.wish_reload = 0;
230                     W_Hagar_Reload();
231                 }
232             }
233         }
234         }
235         else if (req == WR_PRECACHE)
236         {
237                 precache_model ("models/weapons/g_hagar.md3");
238                 precache_model ("models/weapons/v_hagar.md3");
239                 precache_model ("models/weapons/h_hagar.iqm");
240                 precache_sound ("weapons/hagar_fire.wav");
241                 precache_sound ("weapons/reload.wav");
242         }
243         else if (req == WR_SETUP)
244         {
245                 weapon_setup(WEP_HAGAR);
246                 W_Hagar_SetAmmoCounter();
247         }
248         else if (req == WR_CHECKAMMO1)
249         {
250                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_primary_ammo;
251                 ammo_amount += (autocvar_g_balance_hagar_reload_ammo && self.hagar_load >= autocvar_g_balance_hagar_primary_ammo);
252                 return ammo_amount;
253         }
254         else if (req == WR_CHECKAMMO2)
255         {
256                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_secondary_ammo;
257                 ammo_amount += (autocvar_g_balance_hagar_reload_ammo && self.hagar_load >= autocvar_g_balance_hagar_secondary_ammo);
258                 return ammo_amount;
259         }
260         else if (req == WR_RELOAD)
261         {
262                 W_Hagar_Reload();
263         }
264         return TRUE;
265 };
266 #endif
267 #ifdef CSQC
268 float w_hagar(float req)
269 {
270         if(req == WR_IMPACTEFFECT)
271         {
272                 vector org2;
273                 org2 = w_org + w_backoff * 6;
274                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
275                 if(!w_issilent)
276                 {
277                         if (w_random<0.15)
278                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
279                         else if (w_random<0.7)
280                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
281                         else
282                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
283                 }
284         }
285         else if(req == WR_PRECACHE)
286         {
287                 precache_sound("weapons/hagexp1.wav");
288                 precache_sound("weapons/hagexp2.wav");
289                 precache_sound("weapons/hagexp3.wav");
290         }
291         else if (req == WR_SUICIDEMESSAGE)
292                 w_deathtypestring = "%s played with tiny rockets";
293         else if (req == WR_KILLMESSAGE)
294         {
295                 if(w_deathtype & HITTYPE_BOUNCE) // must be secondary; unchecked: SPLASH
296                         w_deathtypestring = "%s hoped %s's missiles wouldn't bounce";
297                 else // unchecked: SPLASH, SECONDARY
298                         w_deathtypestring = "%s was pummeled by %s";
299         }
300         return TRUE;
301 }
302 #endif
303 #endif