Purge hardcoded slot 0 weapon entity use from most of the bot AI
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hagar.qc
1 #include "hagar.qh"
2 #ifndef IMPLEMENTATION
3 CLASS(Hagar, Weapon)
4 /* ammotype  */ ATTRIB(Hagar, ammo_field, .int, ammo_rockets);
5 /* impulse   */ ATTRIB(Hagar, impulse, int, 8);
6 /* flags     */ ATTRIB(Hagar, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
7 /* rating    */ ATTRIB(Hagar, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
8 /* color     */ ATTRIB(Hagar, wpcolor, vector, '1 1 0.5');
9 /* modelname */ ATTRIB(Hagar, mdl, string, "hagar");
10 #ifdef GAMEQC
11 /* model     */ ATTRIB(Hagar, m_model, Model, MDL_HAGAR_ITEM);
12 #endif
13 /* crosshair */ ATTRIB(Hagar, w_crosshair, string, "gfx/crosshairhagar");
14 /* crosshair */ ATTRIB(Hagar, w_crosshair_size, float, 0.8);
15 /* wepimg    */ ATTRIB(Hagar, model2, string, "weaponhagar");
16 /* refname   */ ATTRIB(Hagar, netname, string, "hagar");
17 /* wepname   */ ATTRIB(Hagar, m_name, string, _("Hagar"));
18
19 #define X(BEGIN, P, END, class, prefix) \
20         BEGIN(class) \
21                 P(class, prefix, ammo, float, BOTH) \
22         P(class, prefix, damageforcescale, float, BOTH) \
23         P(class, prefix, damage, float, BOTH) \
24         P(class, prefix, edgedamage, float, BOTH) \
25         P(class, prefix, force, float, BOTH) \
26         P(class, prefix, health, float, BOTH) \
27         P(class, prefix, lifetime, float, PRI) \
28         P(class, prefix, lifetime_min, float, SEC) \
29         P(class, prefix, lifetime_rand, float, SEC) \
30         P(class, prefix, load, float, SEC) \
31         P(class, prefix, load_abort, float, SEC) \
32         P(class, prefix, load_animtime, float, SEC) \
33         P(class, prefix, load_hold, float, SEC) \
34         P(class, prefix, load_linkexplode, float, SEC) \
35         P(class, prefix, load_max, float, SEC) \
36         P(class, prefix, load_releasedeath, float, SEC) \
37         P(class, prefix, load_speed, float, SEC) \
38         P(class, prefix, load_spread, float, SEC) \
39         P(class, prefix, load_spread_bias, float, SEC) \
40         P(class, prefix, radius, float, BOTH) \
41         P(class, prefix, refire, float, BOTH) \
42         P(class, prefix, reload_ammo, float, NONE) \
43         P(class, prefix, reload_time, float, NONE) \
44         P(class, prefix, secondary, float, NONE) \
45         P(class, prefix, speed, float, BOTH) \
46         P(class, prefix, spread, float, BOTH) \
47         P(class, prefix, switchdelay_drop, float, NONE) \
48         P(class, prefix, switchdelay_raise, float, NONE) \
49         P(class, prefix, weaponreplace, string,NONE) \
50         P(class, prefix, weaponstartoverride, float, NONE) \
51         P(class, prefix, weaponstart, float, NONE) \
52         P(class, prefix, weaponthrowable, float, NONE) \
53         END()
54     W_PROPS(X, Hagar, hagar)
55 #undef X
56
57 ENDCLASS(Hagar)
58 REGISTER_WEAPON(HAGAR, hagar, NEW(Hagar));
59
60 #endif
61 #ifdef IMPLEMENTATION
62 #ifdef SVQC
63 spawnfunc(weapon_hagar) { weapon_defaultspawnfunc(this, WEP_HAGAR); }
64
65 // NO bounce protection, as bounces are limited!
66
67 void W_Hagar_Explode(entity this, entity directhitentity)
68 {
69         this.event_damage = func_null;
70         RadiusDamage(this, this.realowner, WEP_CVAR_PRI(hagar, damage), WEP_CVAR_PRI(hagar, edgedamage), WEP_CVAR_PRI(hagar, radius), NULL, NULL, WEP_CVAR_PRI(hagar, force), this.projectiledeathtype, directhitentity);
71
72         delete(this);
73 }
74
75 void W_Hagar_Explode_use(entity this, entity actor, entity trigger)
76 {
77         W_Hagar_Explode(this, trigger);
78 }
79
80 void W_Hagar_Explode2(entity this, entity directhitentity)
81 {
82         this.event_damage = func_null;
83         RadiusDamage(this, this.realowner, WEP_CVAR_SEC(hagar, damage), WEP_CVAR_SEC(hagar, edgedamage), WEP_CVAR_SEC(hagar, radius), NULL, NULL, WEP_CVAR_SEC(hagar, force), this.projectiledeathtype, directhitentity);
84
85         delete(this);
86 }
87
88 void W_Hagar_Explode2_use(entity this, entity actor, entity trigger)
89 {
90         W_Hagar_Explode2(this, trigger);
91 }
92
93 void W_Hagar_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
94 {
95         if(this.health <= 0)
96                 return;
97
98         float is_linkexplode = ( ((inflictor.owner != NULL) ? (inflictor.owner == this.owner) : true)
99                 && (inflictor.projectiledeathtype & HITTYPE_SECONDARY)
100                 && (this.projectiledeathtype & HITTYPE_SECONDARY));
101
102         if(is_linkexplode)
103                 is_linkexplode = (is_linkexplode && WEP_CVAR_SEC(hagar, load_linkexplode));
104         else
105                 is_linkexplode = -1; // not secondary load, so continue as normal without exception.
106
107         if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, is_linkexplode))
108                 return; // g_projectiles_damage says to halt
109
110         this.health = this.health - damage;
111         this.angles = vectoangles(this.velocity);
112
113         if(this.health <= 0)
114                 W_PrepareExplosionByDamage(this, attacker, getthink(this));
115 }
116
117 void W_Hagar_Touch(entity this, entity toucher)
118 {
119         PROJECTILE_TOUCH(this, toucher);
120         this.use(this, NULL, toucher);
121 }
122
123 void W_Hagar_Touch2(entity this, entity toucher)
124 {
125         PROJECTILE_TOUCH(this, toucher);
126
127         if(this.cnt > 0 || toucher.takedamage == DAMAGE_AIM) {
128                 this.use(this, NULL, toucher);
129         } else {
130                 this.cnt++;
131                 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
132                 this.angles = vectoangles(this.velocity);
133                 this.owner = NULL;
134                 this.projectiledeathtype |= HITTYPE_BOUNCE;
135         }
136 }
137
138 void W_Hagar_Attack(Weapon thiswep, entity actor, .entity weaponentity)
139 {
140         entity missile;
141
142         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(hagar, ammo), weaponentity);
143
144         W_SetupShot(actor, weaponentity, false, 2, SND_HAGAR_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(hagar, damage));
145
146         Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
147
148         missile = new(missile);
149         missile.owner = missile.realowner = actor;
150         missile.bot_dodge = true;
151         missile.bot_dodgerating = WEP_CVAR_PRI(hagar, damage);
152
153         missile.takedamage = DAMAGE_YES;
154         missile.health = WEP_CVAR_PRI(hagar, health);
155         missile.damageforcescale = WEP_CVAR_PRI(hagar, damageforcescale);
156         missile.event_damage = W_Hagar_Damage;
157         missile.damagedbycontents = true;
158
159         settouch(missile, W_Hagar_Touch);
160         missile.use = W_Hagar_Explode_use;
161         setthink(missile, adaptor_think2use_hittype_splash);
162         missile.nextthink = time + WEP_CVAR_PRI(hagar, lifetime);
163         PROJECTILE_MAKETRIGGER(missile);
164         missile.projectiledeathtype = WEP_HAGAR.m_id;
165         setorigin(missile, w_shotorg);
166         setsize(missile, '0 0 0', '0 0 0');
167
168         set_movetype(missile, MOVETYPE_FLY);
169         W_SetupProjVelocity_PRI(missile, hagar);
170
171         missile.angles = vectoangles(missile.velocity);
172         missile.flags = FL_PROJECTILE;
173         IL_PUSH(g_projectiles, missile);
174         IL_PUSH(g_bot_dodge, missile);
175         missile.missile_flags = MIF_SPLASH;
176
177         CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
178
179         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
180 }
181
182 void W_Hagar_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
183 {
184         entity missile;
185
186         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo), weaponentity);
187
188         W_SetupShot(actor, weaponentity, false, 2, SND_HAGAR_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
189
190         Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
191
192         missile = new(missile);
193         missile.owner = missile.realowner = actor;
194         missile.bot_dodge = true;
195         missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
196
197         missile.takedamage = DAMAGE_YES;
198         missile.health = WEP_CVAR_SEC(hagar, health);
199         missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
200         missile.event_damage = W_Hagar_Damage;
201         missile.damagedbycontents = true;
202
203         settouch(missile, W_Hagar_Touch2);
204         missile.cnt = 0;
205         missile.use = W_Hagar_Explode2_use;
206         setthink(missile, adaptor_think2use_hittype_splash);
207         missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
208         PROJECTILE_MAKETRIGGER(missile);
209         missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
210         setorigin(missile, w_shotorg);
211         setsize(missile, '0 0 0', '0 0 0');
212
213         set_movetype(missile, MOVETYPE_BOUNCEMISSILE);
214         W_SetupProjVelocity_SEC(missile, hagar);
215
216         missile.angles = vectoangles(missile.velocity);
217         missile.flags = FL_PROJECTILE;
218         IL_PUSH(g_projectiles, missile);
219         IL_PUSH(g_bot_dodge, missile);
220         missile.missile_flags = MIF_SPLASH;
221
222         CSQCProjectile(missile, true, PROJECTILE_HAGAR_BOUNCING, true);
223
224         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
225 }
226
227 .float hagar_loadstep, hagar_loadblock, hagar_loadbeep, hagar_warning;
228 void W_Hagar_Attack2_Load_Release(entity actor, .entity weaponentity)
229 {
230         // time to release the rockets we've loaded
231
232         entity missile;
233         float counter, shots, spread_pershot;
234         vector s;
235         vector forward, right, up;
236
237         if(!actor.(weaponentity).hagar_load)
238                 return;
239
240         weapon_prepareattack_do(actor, weaponentity, true, WEP_CVAR_SEC(hagar, refire));
241
242         W_SetupShot(actor, weaponentity, false, 2, SND_HAGAR_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
243         Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
244
245         forward = v_forward;
246         right = v_right;
247         up = v_up;
248
249         shots = actor.(weaponentity).hagar_load;
250         missile = NULL;
251         for(counter = 0; counter < shots; ++counter)
252         {
253                 missile = new(missile);
254                 missile.owner = missile.realowner = actor;
255                 missile.bot_dodge = true;
256                 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
257
258                 missile.takedamage = DAMAGE_YES;
259                 missile.health = WEP_CVAR_SEC(hagar, health);
260                 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
261                 missile.event_damage = W_Hagar_Damage;
262                 missile.damagedbycontents = true;
263
264                 settouch(missile, W_Hagar_Touch); // not bouncy
265                 missile.use = W_Hagar_Explode2_use;
266                 setthink(missile, adaptor_think2use_hittype_splash);
267                 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
268                 PROJECTILE_MAKETRIGGER(missile);
269                 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
270                 setorigin(missile, w_shotorg);
271                 setsize(missile, '0 0 0', '0 0 0');
272                 set_movetype(missile, MOVETYPE_FLY);
273                 missile.missile_flags = MIF_SPLASH;
274
275                 // per-shot spread calculation: the more shots there are, the less spread is applied (based on the bias cvar)
276                 spread_pershot = ((shots - 1) / (WEP_CVAR_SEC(hagar, load_max) - 1));
277                 spread_pershot = (1 - (spread_pershot * WEP_CVAR_SEC(hagar, load_spread_bias)));
278                 spread_pershot = (WEP_CVAR_SEC(hagar, spread) * spread_pershot * g_weaponspreadfactor);
279
280                 // pattern spread calculation
281                 s = '0 0 0';
282                 if(counter == 0)
283                         s = '0 0 0';
284                 else
285                 {
286                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
287                         s.y = v_forward.x;
288                         s.z = v_forward.y;
289                 }
290                 s = s * WEP_CVAR_SEC(hagar, load_spread) * g_weaponspreadfactor;
291
292                 W_SetupProjVelocity_Explicit(missile, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_SEC(hagar, speed), 0, 0, spread_pershot, false);
293
294                 missile.angles = vectoangles(missile.velocity);
295                 missile.flags = FL_PROJECTILE;
296                 IL_PUSH(g_projectiles, missile);
297                 IL_PUSH(g_bot_dodge, missile);
298
299                 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
300
301                 MUTATOR_CALLHOOK(EditProjectile, actor, missile);
302         }
303
304         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, load_animtime), w_ready);
305         actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, refire) * W_WeaponRateFactor(actor);
306         actor.(weaponentity).hagar_load = 0;
307
308         if(weaponslot(weaponentity) == 0)
309                 actor.hagar_load = 0;
310 }
311
312 void W_Hagar_Attack2_Load(Weapon thiswep, entity actor, .entity weaponentity)
313 {
314         // loadable hagar secondary attack, must always run each frame
315
316         if(time < game_starttime)
317                 return;
318
319         bool loaded = actor.(weaponentity).hagar_load >= WEP_CVAR_SEC(hagar, load_max);
320
321         // this is different than WR_CHECKAMMO when it comes to reloading
322         bool enough_ammo;
323         if(actor.items & IT_UNLIMITED_WEAPON_AMMO)
324                 enough_ammo = true;
325         else if(autocvar_g_balance_hagar_reload_ammo)
326                 enough_ammo = actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
327         else
328                 enough_ammo = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(hagar, ammo);
329
330         bool stopped = loaded || !enough_ammo;
331
332         if(PHYS_INPUT_BUTTON_ATCK2(actor))
333         {
334                 if(PHYS_INPUT_BUTTON_ATCK(actor) && WEP_CVAR_SEC(hagar, load_abort))
335                 {
336                         if(actor.(weaponentity).hagar_load)
337                         {
338                                 // if we pressed primary fire while loading, unload all rockets and abort
339                                 actor.(weaponentity).state = WS_READY;
340                                 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo) * actor.(weaponentity).hagar_load * -1, weaponentity); // give back ammo
341                                 actor.(weaponentity).hagar_load = 0;
342                                 if(weaponslot(weaponentity) == 0)
343                                         actor.hagar_load = 0;
344                                 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
345
346                                 // pause until we can load rockets again, once we re-press the alt fire button
347                                 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor(actor);
348
349                                 // require letting go of the alt fire button before we can load again
350                                 actor.(weaponentity).hagar_loadblock = true;
351                         }
352                 }
353                 else
354                 {
355                         // check if we can attempt to load another rocket
356                         if(!stopped)
357                         {
358                                 if(!actor.(weaponentity).hagar_loadblock && actor.(weaponentity).hagar_loadstep < time)
359                                 {
360                                         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo), weaponentity);
361                                         actor.(weaponentity).state = WS_INUSE;
362                                         actor.(weaponentity).hagar_load += 1;
363                                         sound(actor, CH_WEAPON_B, SND_HAGAR_LOAD, VOL_BASE * 0.8, ATTN_NORM); // sound is too loud according to most
364
365                                         if(actor.(weaponentity).hagar_load >= WEP_CVAR_SEC(hagar, load_max))
366                                                 stopped = true;
367                                         else
368                                                 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor(actor);
369                                 }
370                         }
371                         if(stopped && !actor.(weaponentity).hagar_loadbeep && actor.(weaponentity).hagar_load) // prevents the beep from playing each frame
372                         {
373                                 // if this is the last rocket we can load, play a beep sound to notify the player
374                                 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
375                                 actor.(weaponentity).hagar_loadbeep = true;
376                                 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_hold) * W_WeaponRateFactor(actor);
377                         }
378                 }
379         }
380         else if(actor.(weaponentity).hagar_loadblock)
381         {
382                 // the alt fire button has been released, so re-enable loading if blocked
383                 actor.(weaponentity).hagar_loadblock = false;
384         }
385
386         if(actor.(weaponentity).hagar_load)
387         {
388                 // play warning sound if we're about to release
389                 if(stopped && actor.(weaponentity).hagar_loadstep - 0.5 < time && WEP_CVAR_SEC(hagar, load_hold) >= 0)
390                 {
391                         if(!actor.(weaponentity).hagar_warning) // prevents the beep from playing each frame
392                         {
393                                 // we're about to automatically release after holding time, play a beep sound to notify the player
394                                 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
395                                 actor.(weaponentity).hagar_warning = true;
396                         }
397                 }
398
399                 // release if player let go of button or if they've held it in too long
400                 if(!PHYS_INPUT_BUTTON_ATCK2(actor) || (stopped && actor.(weaponentity).hagar_loadstep < time && WEP_CVAR_SEC(hagar, load_hold) >= 0))
401                 {
402                         actor.(weaponentity).state = WS_READY;
403                         W_Hagar_Attack2_Load_Release(actor, weaponentity);
404                 }
405         }
406         else
407         {
408                 actor.(weaponentity).hagar_loadbeep = false;
409                 actor.(weaponentity).hagar_warning = false;
410
411                 // we aren't checking ammo during an attack, so we must do it here
412                 if(!(thiswep.wr_checkammo1(thiswep, actor, weaponentity) + thiswep.wr_checkammo2(thiswep, actor, weaponentity)))
413                 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
414                 {
415                         // note: this doesn't force the switch
416                         W_SwitchToOtherWeapon(actor, weaponentity);
417                         return;
418                 }
419         }
420 }
421
422 void W_Hagar_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
423 {
424         if(!(fire & 1) || actor.(weaponentity).hagar_load || actor.(weaponentity).hagar_loadblock)
425         {
426                 w_ready(thiswep, actor, weaponentity, fire);
427                 return;
428         }
429
430         if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
431         if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
432         {
433                 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
434                 w_ready(thiswep, actor, weaponentity, fire);
435                 return;
436         }
437
438         W_Hagar_Attack(thiswep, actor, weaponentity);
439
440         int slot = weaponslot(weaponentity);
441         ATTACK_FINISHED(actor, slot) = time + WEP_CVAR_PRI(hagar, refire) * W_WeaponRateFactor(actor);
442         int theframe = WFRAME_FIRE1;
443         entity this = actor.(weaponentity);
444         if(this)
445         {
446                 if(this.wframe == WFRAME_FIRE1)
447                         theframe = WFRAME_DONTCHANGE;
448         }
449         weapon_thinkf(actor, weaponentity, theframe, WEP_CVAR_PRI(hagar, refire), W_Hagar_Attack_Auto);
450 }
451
452 METHOD(Hagar, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
453 {
454     if(random()>0.15)
455         PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
456     else // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
457         PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
458 }
459 METHOD(Hagar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
460 {
461     float loadable_secondary;
462     loadable_secondary = (WEP_CVAR_SEC(hagar, load) && WEP_CVAR(hagar, secondary));
463     if(weaponslot(weaponentity) == 0)
464         actor.hagar_load = actor.(weaponentity).hagar_load;
465
466     if(loadable_secondary)
467         W_Hagar_Attack2_Load(thiswep, actor, weaponentity); // must always run each frame
468     if(autocvar_g_balance_hagar_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo))) { // forced reload
469         thiswep.wr_reload(thiswep, actor, weaponentity);
470     }
471     else if((fire & 1) && !actor.(weaponentity).hagar_load && !actor.(weaponentity).hagar_loadblock) // not while secondary is loaded or awaiting reset
472         {
473                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
474                         W_Hagar_Attack_Auto(thiswep, actor, weaponentity, fire);
475         }
476     else if((fire & 2) && !loadable_secondary && WEP_CVAR(hagar, secondary))
477     {
478         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hagar, refire)))
479         {
480             W_Hagar_Attack2(thiswep, actor, weaponentity);
481             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, refire), w_ready);
482         }
483     }
484 }
485 METHOD(Hagar, wr_gonethink, void(entity thiswep, entity actor, .entity weaponentity))
486 {
487     // we lost the weapon and want to prepare switching away
488     if(actor.(weaponentity).hagar_load)
489     {
490         actor.(weaponentity).state = WS_READY;
491         W_Hagar_Attack2_Load_Release(actor, weaponentity);
492     }
493 }
494 METHOD(Hagar, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
495 {
496         actor.hagar_load = 0;
497     actor.(weaponentity).hagar_loadblock = false;
498     if(actor.(weaponentity).hagar_load)
499     {
500         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo) * actor.(weaponentity).hagar_load * -1, weaponentity); // give back ammo if necessary
501         actor.(weaponentity).hagar_load = 0;
502     }
503 }
504 METHOD(Hagar, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
505 {
506     float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(hagar, ammo);
507     ammo_amount += actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_PRI(hagar, ammo);
508     return ammo_amount;
509 }
510 METHOD(Hagar, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
511 {
512     float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(hagar, ammo);
513     ammo_amount += actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
514     return ammo_amount;
515 }
516 METHOD(Hagar, wr_resetplayer, void(entity thiswep, entity actor))
517 {
518     actor.hagar_load = 0;
519     for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
520     {
521         .entity weaponentity = weaponentities[slot];
522         actor.(weaponentity).hagar_load = 0;
523     }
524 }
525 METHOD(Hagar, wr_playerdeath, void(entity thiswep, entity actor, .entity weaponentity))
526 {
527     // if we have any rockets loaded when we die, release them
528     if(actor.(weaponentity).hagar_load && WEP_CVAR_SEC(hagar, load_releasedeath))
529         W_Hagar_Attack2_Load_Release(actor, weaponentity);
530 }
531 METHOD(Hagar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
532 {
533     if(!actor.(weaponentity).hagar_load) // require releasing loaded rockets first
534         W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo)), SND_RELOAD);
535 }
536 METHOD(Hagar, wr_suicidemessage, Notification(entity thiswep))
537 {
538     return WEAPON_HAGAR_SUICIDE;
539 }
540 METHOD(Hagar, wr_killmessage, Notification(entity thiswep))
541 {
542     if(w_deathtype & HITTYPE_SECONDARY)
543         return WEAPON_HAGAR_MURDER_BURST;
544     else
545         return WEAPON_HAGAR_MURDER_SPRAY;
546 }
547
548 #endif
549 #ifdef CSQC
550
551 METHOD(Hagar, wr_impacteffect, void(entity thiswep, entity actor))
552 {
553     vector org2;
554     org2 = w_org + w_backoff * 6;
555     pointparticles(EFFECT_HAGAR_EXPLODE, org2, '0 0 0', 1);
556     if(!w_issilent)
557     {
558         if(w_random<0.15)
559             sound(actor, CH_SHOTS, SND_HAGEXP1, VOL_BASE, ATTN_NORM);
560         else if(w_random<0.7)
561             sound(actor, CH_SHOTS, SND_HAGEXP2, VOL_BASE, ATTN_NORM);
562         else
563             sound(actor, CH_SHOTS, SND_HAGEXP3, VOL_BASE, ATTN_NORM);
564     }
565 }
566
567 #endif
568 #endif