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