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