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