]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hagar.qc
Remove the wish_reload system. WR_RELOAD can replace it
[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         if (req == WR_AIM)
195                 if (random()>0.15)
196                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
197                 else
198                 {
199                         // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
200                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
201                 }
202         else if (req == WR_THINK)
203         {
204                 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
205                         W_Hagar_Reload();
206                 else if (self.BUTTON_ATCK)
207                 {
208                         if (weapon_prepareattack(0, autocvar_g_balance_hagar_primary_refire))
209                         {
210                                 W_Hagar_Attack();
211                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hagar_primary_refire, w_ready);
212                         }
213                 }
214                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hagar_secondary)
215                 {
216                         if (weapon_prepareattack(1, autocvar_g_balance_hagar_secondary_refire))
217                         {
218                                 W_Hagar_Attack2();
219                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hagar_secondary_refire, w_ready);
220                         }
221                 }
222         }
223         else if (req == WR_PRECACHE)
224         {
225                 precache_model ("models/weapons/g_hagar.md3");
226                 precache_model ("models/weapons/v_hagar.md3");
227                 precache_model ("models/weapons/h_hagar.iqm");
228                 precache_sound ("weapons/hagar_fire.wav");
229                 precache_sound ("weapons/reload.wav");
230         }
231         else if (req == WR_SETUP)
232         {
233                 weapon_setup(WEP_HAGAR);
234                 W_Hagar_SetAmmoCounter();
235         }
236         else if (req == WR_CHECKAMMO1)
237         {
238                 if(autocvar_g_balance_hagar_reload_ammo)
239                         return self.hagar_load >= autocvar_g_balance_hagar_primary_ammo;
240                 else
241                         return self.ammo_rockets >= autocvar_g_balance_hagar_primary_ammo;
242         }
243         else if (req == WR_CHECKAMMO2)
244         {
245                 if(autocvar_g_balance_hagar_reload_ammo)
246                         return self.hagar_load >= autocvar_g_balance_hagar_secondary_ammo;
247                 else
248                         return self.ammo_rockets >= autocvar_g_balance_hagar_secondary_ammo;
249         }
250         else if (req == WR_RELOAD)
251         {
252                 W_Hagar_Reload();
253         }
254         else if (req == WR_SWITCHABLE)
255         {
256                 // checks if this weapon can be switched to, when reloading is enabled
257                 // returns true if there's either enough load in the weapon to use it,
258                 // or we have enough ammo to reload the weapon to a usable point
259                 float ammo_amount;
260                 ammo_amount = min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo);
261                 return self.hagar_load >= ammo_amount || self.ammo_rockets >= ammo_amount;
262         }
263         return TRUE;
264 };
265 #endif
266 #ifdef CSQC
267 float w_hagar(float req)
268 {
269         if(req == WR_IMPACTEFFECT)
270         {
271                 vector org2;
272                 org2 = w_org + w_backoff * 6;
273                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
274                 if(!w_issilent)
275                 {
276                         if (w_random<0.15)
277                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
278                         else if (w_random<0.7)
279                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
280                         else
281                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
282                 }
283         }
284         else if(req == WR_PRECACHE)
285         {
286                 precache_sound("weapons/hagexp1.wav");
287                 precache_sound("weapons/hagexp2.wav");
288                 precache_sound("weapons/hagexp3.wav");
289         }
290         else if (req == WR_SUICIDEMESSAGE)
291                 w_deathtypestring = "%s played with tiny rockets";
292         else if (req == WR_KILLMESSAGE)
293         {
294                 if(w_deathtype & HITTYPE_BOUNCE) // must be secondary; unchecked: SPLASH
295                         w_deathtypestring = "%s hoped %s's missiles wouldn't bounce";
296                 else // unchecked: SPLASH, SECONDARY
297                         w_deathtypestring = "%s was pummeled by %s";
298         }
299         return TRUE;
300 }
301 #endif
302 #endif