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