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