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