]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_hlac.qc
80ad5661dbee138aaa56f69dde445687108c3d26
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_hlac.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ HLAC,
4 /* function */ W_HLAC,
5 /* ammotype */ ammo_cells,
6 /* impulse  */ 6,
7 /* flags    */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH,
8 /* rating   */ BOT_PICKUP_RATING_MID,
9 /* color        */ '0 1 0',
10 /* model    */ "hlac",
11 /* netname  */ "hlac",
12 /* fullname */ _("Heavy Laser Assault Cannon")
13 );
14
15 #define HLAC_SETTINGS(w_cvar,w_prop) HLAC_SETTINGS_LIST(w_cvar, w_prop, HLAC, hlac)
16 #define HLAC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
17         w_cvar(id, sn, BOTH, ammo) \
18         w_cvar(id, sn, BOTH, animtime) \
19         w_cvar(id, sn, BOTH, damage) \
20         w_cvar(id, sn, BOTH, edgedamage) \
21         w_cvar(id, sn, BOTH, force) \
22         w_cvar(id, sn, BOTH, lifetime) \
23         w_cvar(id, sn, BOTH, radius) \
24         w_cvar(id, sn, BOTH, refire) \
25         w_cvar(id, sn, BOTH, speed) \
26         w_cvar(id, sn, BOTH, spread_crouchmod) \
27         w_cvar(id, sn, PRI,  spread_add) \
28         w_cvar(id, sn, PRI,  spread_max) \
29         w_cvar(id, sn, PRI,  spread_min) \
30         w_cvar(id, sn, NONE, secondary) \
31         w_cvar(id, sn, SEC,  shots) \
32         w_cvar(id, sn, SEC,  spread) \
33         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
34         w_prop(id, sn, float,  reloading_time, reload_time) \
35         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
36         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
37         w_prop(id, sn, string, weaponreplace, weaponreplace) \
38         w_prop(id, sn, float,  weaponstart, weaponstart) \
39         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
40
41 #ifdef SVQC
42 HLAC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
43 #endif
44 #else
45 #ifdef SVQC
46 void spawnfunc_weapon_hlac() { weapon_defaultspawnfunc(WEP_HLAC); }
47
48 void W_HLAC_Touch (void)
49 {
50         float isprimary;
51
52         PROJECTILE_TOUCH;
53
54         self.event_damage = func_null;
55         
56         isprimary = !(self.projectiledeathtype & HITTYPE_SECONDARY);
57         
58         RadiusDamage(self, self.realowner, WEP_CVAR_BOTH(hlac, isprimary, damage), WEP_CVAR_BOTH(hlac, isprimary, edgedamage), WEP_CVAR_BOTH(hlac, isprimary, radius), world, world, WEP_CVAR_BOTH(hlac, isprimary, force), self.projectiledeathtype, other);
59
60         remove (self);
61 }
62
63 void W_HLAC_Attack (void)
64 {
65         entity missile;
66     float spread;
67
68         W_DecreaseAmmo(WEP_CVAR_PRI(hlac, ammo));
69
70     spread = WEP_CVAR_PRI(hlac, spread_min) + (WEP_CVAR_PRI(hlac, spread_add) * self.misc_bulletcounter);
71     spread = min(spread,WEP_CVAR_PRI(hlac, spread_max));
72     if(self.crouch)
73         spread = spread * WEP_CVAR_PRI(hlac, spread_crouchmod);
74
75         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_A, WEP_CVAR_PRI(hlac, damage));
76         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
77         if (!autocvar_g_norecoil)
78         {
79                 self.punchangle_x = random () - 0.5;
80                 self.punchangle_y = random () - 0.5;
81         }
82
83         missile = spawn ();
84         missile.owner = missile.realowner = self;
85         missile.classname = "hlacbolt";
86         missile.bot_dodge = TRUE;
87
88     missile.bot_dodgerating = WEP_CVAR_PRI(hlac, damage);
89
90         missile.movetype = MOVETYPE_FLY;
91         PROJECTILE_MAKETRIGGER(missile);
92
93         setorigin (missile, w_shotorg);
94         setsize(missile, '0 0 0', '0 0 0');
95
96         W_SetupProjVelocity_Basic(missile, WEP_CVAR_PRI(hlac, speed), spread);
97         //missile.angles = vectoangles (missile.velocity); // csqc
98
99         missile.touch = W_HLAC_Touch;
100         missile.think = SUB_Remove;
101
102     missile.nextthink = time + WEP_CVAR_PRI(hlac, lifetime);
103
104         missile.flags = FL_PROJECTILE;
105         missile.projectiledeathtype = WEP_HLAC;
106
107         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
108
109         other = missile; MUTATOR_CALLHOOK(EditProjectile);
110 }
111
112 void W_HLAC_Attack2()
113 {
114         entity missile;
115     float spread;
116
117     spread = WEP_CVAR_SEC(hlac, spread);
118
119
120     if(self.crouch)
121         spread = spread * WEP_CVAR_SEC(hlac, spread_crouchmod);
122
123         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_A, WEP_CVAR_SEC(hlac, damage));
124         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
125
126         missile = spawn ();
127         missile.owner = missile.realowner = self;
128         missile.classname = "hlacbolt";
129         missile.bot_dodge = TRUE;
130
131     missile.bot_dodgerating = WEP_CVAR_SEC(hlac, damage);
132
133         missile.movetype = MOVETYPE_FLY;
134         PROJECTILE_MAKETRIGGER(missile);
135
136         setorigin (missile, w_shotorg);
137         setsize(missile, '0 0 0', '0 0 0');
138
139         W_SetupProjVelocity_Basic(missile, WEP_CVAR_SEC(hlac, speed), spread);
140         //missile.angles = vectoangles (missile.velocity); // csqc
141
142         missile.touch = W_HLAC_Touch;
143         missile.think = SUB_Remove;
144
145     missile.nextthink = time + WEP_CVAR_SEC(hlac, lifetime);
146
147         missile.flags = FL_PROJECTILE;
148         missile.missile_flags = MIF_SPLASH; 
149         missile.projectiledeathtype = WEP_HLAC | HITTYPE_SECONDARY;
150
151         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
152
153         other = missile; MUTATOR_CALLHOOK(EditProjectile);
154 }
155
156 // weapon frames
157 void W_HLAC_Attack_Frame()
158 {
159         if(self.weapon != self.switchweapon) // abort immediately if switching
160         {
161                 w_ready();
162                 return;
163         }
164
165         if (self.BUTTON_ATCK)
166         {
167                 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1))
168                 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
169                 {
170                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
171                         w_ready();
172                         return;
173                 }
174
175                 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(hlac, refire) * W_WeaponRateFactor();
176                 W_HLAC_Attack();
177                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
178         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
179         }
180         else
181         {
182                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, animtime), w_ready);
183         }
184 }
185
186 void W_HLAC_Attack2_Frame()
187 {
188     float i;
189
190         W_DecreaseAmmo(WEP_CVAR_SEC(hlac, ammo));
191
192     for(i=WEP_CVAR_SEC(hlac, shots);i>0;--i)
193         W_HLAC_Attack2();
194
195         if (!autocvar_g_norecoil)
196         {
197                 self.punchangle_x = random () - 0.5;
198                 self.punchangle_y = random () - 0.5;
199         }
200 }
201
202 float W_HLAC(float req)
203 {
204         float ammo_amount;
205         switch(req)
206         {
207                 case WR_AIM:
208                 {
209                         self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hlac, speed), 0, WEP_CVAR_PRI(hlac, lifetime), FALSE);
210                         return TRUE;
211                 }
212                 case WR_THINK:
213                 {
214                         if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) // forced reload
215                                 WEP_ACTION(self.weapon, WR_RELOAD);
216                         else if (self.BUTTON_ATCK)
217                         {
218                                 if (weapon_prepareattack(0, WEP_CVAR_PRI(hlac, refire)))
219                                 {
220                                         self.misc_bulletcounter = 0;
221                                         W_HLAC_Attack();
222                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
223                                 }
224                         }
225
226                         else if (self.BUTTON_ATCK2 && WEP_CVAR(hlac, secondary))
227                         {
228                                 if (weapon_prepareattack(1, WEP_CVAR_SEC(hlac, refire)))
229                                 {
230                                         W_HLAC_Attack2_Frame();
231                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hlac, animtime), w_ready);
232                                 }
233                         }
234                         
235                         return TRUE;
236                 }
237                 case WR_INIT:
238                 {
239                         precache_model ("models/weapons/g_hlac.md3");
240                         precache_model ("models/weapons/v_hlac.md3");
241                         precache_model ("models/weapons/h_hlac.iqm");
242                         precache_sound ("weapons/lasergun_fire.wav");
243                         HLAC_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
244                         return TRUE;
245                 }
246                 case WR_CHECKAMMO1:
247                 {
248                         ammo_amount = self.AMMO_VAL(WEP_HLAC) >= WEP_CVAR_PRI(hlac, ammo);
249                         ammo_amount += self.(weapon_load[WEP_HLAC]) >= WEP_CVAR_PRI(hlac, ammo);
250                         return ammo_amount;
251                 }
252                 case WR_CHECKAMMO2:
253                 {
254                         ammo_amount = self.AMMO_VAL(WEP_HLAC) >= WEP_CVAR_SEC(hlac, ammo);
255                         ammo_amount += self.(weapon_load[WEP_HLAC]) >= WEP_CVAR_SEC(hlac, ammo);
256                         return ammo_amount;
257                 }
258                 case WR_CONFIG:
259                 {
260                         HLAC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
261                         return TRUE;
262                 }
263                 case WR_RELOAD:
264                 {
265                         W_Reload(min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo)), "weapons/reload.wav");
266                         return TRUE;
267                 }
268                 case WR_SUICIDEMESSAGE:
269                 {
270                         return WEAPON_HLAC_SUICIDE;
271                 }
272                 case WR_KILLMESSAGE:
273                 {
274                         return WEAPON_HLAC_MURDER;
275                 }
276         }
277         return TRUE;
278 }
279 #endif
280 #ifdef CSQC
281 float W_HLAC(float req)
282 {
283         switch(req)
284         {
285                 case WR_IMPACTEFFECT:
286                 {
287                         vector org2;
288                         org2 = w_org + w_backoff * 6;
289                         pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
290                         if(!w_issilent)
291                                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
292                                 
293                         return TRUE;
294                 }
295                 case WR_INIT:
296                 {
297                         precache_sound("weapons/laserimpact.wav");
298                         return TRUE;
299                 }
300         }
301         return TRUE;
302 }
303 #endif
304 #endif