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