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