]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_hlac.qc
Add weaponstartoverride property to 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 */ IT_CELLS,
6 /* impulse  */ 6,
7 /* flags    */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH,
8 /* rating   */ BOT_PICKUP_RATING_MID,
9 /* model    */ "hlac",
10 /* netname  */ "hlac",
11 /* fullname */ _("Heavy Laser Assault Cannon")
12 );
13
14 #define HLAC_SETTINGS(w_cvar,w_prop) \
15         w_cvar(WEP_HLAC, hlac, MO_BOTH, ammo) \
16         w_cvar(WEP_HLAC, hlac, MO_BOTH, animtime) \
17         w_cvar(WEP_HLAC, hlac, MO_BOTH, damage) \
18         w_cvar(WEP_HLAC, hlac, MO_BOTH, edgedamage) \
19         w_cvar(WEP_HLAC, hlac, MO_BOTH, force) \
20         w_cvar(WEP_HLAC, hlac, MO_BOTH, lifetime) \
21         w_cvar(WEP_HLAC, hlac, MO_BOTH, radius) \
22         w_cvar(WEP_HLAC, hlac, MO_BOTH, refire) \
23         w_cvar(WEP_HLAC, hlac, MO_BOTH, speed) \
24         w_cvar(WEP_HLAC, hlac, MO_BOTH, spread_crouchmod) \
25         w_cvar(WEP_HLAC, hlac, MO_PRI,  spread_add) \
26         w_cvar(WEP_HLAC, hlac, MO_PRI,  spread_max) \
27         w_cvar(WEP_HLAC, hlac, MO_PRI,  spread_min) \
28         w_cvar(WEP_HLAC, hlac, MO_NONE, secondary) \
29         w_cvar(WEP_HLAC, hlac, MO_SEC,  shots) \
30         w_cvar(WEP_HLAC, hlac, MO_SEC,  spread) \
31         w_prop(WEP_HLAC, hlac, float,  reloading_ammo, reload_ammo) \
32         w_prop(WEP_HLAC, hlac, float,  reloading_time, reload_time) \
33         w_prop(WEP_HLAC, hlac, float,  switchdelay_raise, switchdelay_raise) \
34         w_prop(WEP_HLAC, hlac, float,  switchdelay_drop, switchdelay_drop) \
35         w_prop(WEP_HLAC, hlac, string, weaponreplace, weaponreplace) \
36         w_prop(WEP_HLAC, hlac, float,  weaponstart, weaponstart) \
37         w_prop(WEP_HLAC, hlac, float,  weaponstartoverride, weaponstartoverride)
38
39 #ifdef SVQC
40 HLAC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
41 #endif
42 #else
43 #ifdef SVQC
44 void spawnfunc_weapon_hlac() { weapon_defaultspawnfunc(WEP_HLAC); }
45
46 void W_HLAC_Touch (void)
47 {
48         float isprimary;
49
50         PROJECTILE_TOUCH;
51
52         self.event_damage = func_null;
53         
54         isprimary = !(self.projectiledeathtype & HITTYPE_SECONDARY);
55         
56         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);
57
58         remove (self);
59 }
60
61 void W_HLAC_Attack (void)
62 {
63         entity missile;
64     float spread;
65
66         W_DecreaseAmmo(ammo_cells, WEP_CVAR_PRI(hlac, ammo), autocvar_g_balance_hlac_reload_ammo);
67
68     spread = WEP_CVAR_PRI(hlac, spread_min) + (WEP_CVAR_PRI(hlac, spread_add) * self.misc_bulletcounter);
69     spread = min(spread,WEP_CVAR_PRI(hlac, spread_max));
70     if(self.crouch)
71         spread = spread * WEP_CVAR_PRI(hlac, spread_crouchmod);
72
73         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_A, WEP_CVAR_PRI(hlac, damage));
74         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
75         if (!autocvar_g_norecoil)
76         {
77                 self.punchangle_x = random () - 0.5;
78                 self.punchangle_y = random () - 0.5;
79         }
80
81         missile = spawn ();
82         missile.owner = missile.realowner = self;
83         missile.classname = "hlacbolt";
84         missile.bot_dodge = TRUE;
85
86     missile.bot_dodgerating = WEP_CVAR_PRI(hlac, damage);
87
88         missile.movetype = MOVETYPE_FLY;
89         PROJECTILE_MAKETRIGGER(missile);
90
91         setorigin (missile, w_shotorg);
92         setsize(missile, '0 0 0', '0 0 0');
93
94         W_SetupProjectileVelocity(missile, WEP_CVAR_PRI(hlac, speed), spread);
95         //missile.angles = vectoangles (missile.velocity); // csqc
96
97         missile.touch = W_HLAC_Touch;
98         missile.think = SUB_Remove;
99
100     missile.nextthink = time + WEP_CVAR_PRI(hlac, lifetime);
101
102         missile.flags = FL_PROJECTILE;
103         missile.projectiledeathtype = WEP_HLAC;
104
105         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
106
107         other = missile; MUTATOR_CALLHOOK(EditProjectile);
108 }
109
110 void W_HLAC_Attack2f (void)
111 {
112         entity missile;
113     float spread;
114
115     spread = WEP_CVAR_SEC(hlac, spread);
116
117
118     if(self.crouch)
119         spread = spread * WEP_CVAR_SEC(hlac, spread_crouchmod);
120
121         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_A, WEP_CVAR_SEC(hlac, damage));
122         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
123
124         missile = spawn ();
125         missile.owner = missile.realowner = self;
126         missile.classname = "hlacbolt";
127         missile.bot_dodge = TRUE;
128
129     missile.bot_dodgerating = WEP_CVAR_SEC(hlac, damage);
130
131         missile.movetype = MOVETYPE_FLY;
132         PROJECTILE_MAKETRIGGER(missile);
133
134         setorigin (missile, w_shotorg);
135         setsize(missile, '0 0 0', '0 0 0');
136
137         W_SetupProjectileVelocity(missile, WEP_CVAR_SEC(hlac, speed), spread);
138         //missile.angles = vectoangles (missile.velocity); // csqc
139
140         missile.touch = W_HLAC_Touch;
141         missile.think = SUB_Remove;
142
143     missile.nextthink = time + WEP_CVAR_SEC(hlac, lifetime);
144
145         missile.flags = FL_PROJECTILE;
146         missile.missile_flags = MIF_SPLASH; 
147         missile.projectiledeathtype = WEP_HLAC | HITTYPE_SECONDARY;
148
149         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
150
151         other = missile; MUTATOR_CALLHOOK(EditProjectile);
152 }
153
154 void W_HLAC_Attack2 (void)
155 {
156     float i;
157
158         W_DecreaseAmmo(ammo_cells, WEP_CVAR_SEC(hlac, ammo), autocvar_g_balance_hlac_reload_ammo);
159
160     for(i=WEP_CVAR_SEC(hlac, shots);i>0;--i)
161         W_HLAC_Attack2f();
162
163         if (!autocvar_g_norecoil)
164         {
165                 self.punchangle_x = random () - 0.5;
166                 self.punchangle_y = random () - 0.5;
167         }
168 }
169
170 // weapon frames
171 void HLAC_fire1_02()
172 {
173         if(self.weapon != self.switchweapon) // abort immediately if switching
174         {
175                 w_ready();
176                 return;
177         }
178
179         if (self.BUTTON_ATCK)
180         {
181                 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1))
182                 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
183                 {
184                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
185                         w_ready();
186                         return;
187                 }
188
189                 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(hlac, refire) * W_WeaponRateFactor();
190                 W_HLAC_Attack();
191                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
192         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), HLAC_fire1_02);
193         }
194         else
195         {
196                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, animtime), w_ready);
197         }
198 }
199
200 float w_hlac(float req)
201 {
202         float ammo_amount;
203         switch(req)
204         {
205                 case WR_AIM:
206                 {
207                         self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hlac, speed), 0, WEP_CVAR_PRI(hlac, lifetime), FALSE);
208                         return TRUE;
209                 }
210                 case WR_THINK:
211                 {
212                         if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) // forced reload
213                                 WEP_ACTION(self.weapon, WR_RELOAD);
214                         else if (self.BUTTON_ATCK)
215                         {
216                                 if (weapon_prepareattack(0, WEP_CVAR_PRI(hlac, refire)))
217                                 {
218                                         self.misc_bulletcounter = 0;
219                                         W_HLAC_Attack();
220                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), HLAC_fire1_02);
221                                 }
222                         }
223
224                         else if (self.BUTTON_ATCK2 && WEP_CVAR(hlac, secondary))
225                         {
226                                 if (weapon_prepareattack(1, WEP_CVAR_SEC(hlac, refire)))
227                                 {
228                                         W_HLAC_Attack2();
229                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hlac, animtime), w_ready);
230                                 }
231                         }
232                         
233                         return TRUE;
234                 }
235                 case WR_INIT:
236                 {
237                         precache_model ("models/weapons/g_hlac.md3");
238                         precache_model ("models/weapons/v_hlac.md3");
239                         precache_model ("models/weapons/h_hlac.iqm");
240                         precache_sound ("weapons/lasergun_fire.wav");
241                         HLAC_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
242                         return TRUE;
243                 }
244                 case WR_SETUP:
245                 {
246                         self.current_ammo = ammo_cells;
247                         return TRUE;
248                 }
249                 case WR_CHECKAMMO1:
250                 {
251                         ammo_amount = self.ammo_cells >= 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.ammo_cells >= 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         }
304         return TRUE;
305 }
306 #endif
307 #endif