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