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