]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hlac.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hlac.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(HLAC, w_hlac, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hlac", "hlac", _("Heavy Laser Assault Cannon"))
3 #else
4 #ifdef SVQC
5
6 void W_HLAC_Reload()
7 {
8         self.reload_ammo_player = ammo_cells;
9         self.reload_ammo_min = min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo);
10         self.reload_ammo_amount = autocvar_g_balance_hlac_reload_ammo;
11         self.reload_time = autocvar_g_balance_hlac_reload_time;
12         self.reload_sound = "weapons/reload.wav";
13
14         W_Reload();
15 }
16
17 void W_HLAC_Touch (void)
18 {
19         PROJECTILE_TOUCH;
20
21         self.event_damage = SUB_Null;
22         
23         if(self.projectiledeathtype & HITTYPE_SECONDARY)
24                 RadiusDamage (self, self.owner, autocvar_g_balance_hlac_secondary_damage, autocvar_g_balance_hlac_secondary_edgedamage, autocvar_g_balance_hlac_secondary_radius, world, autocvar_g_balance_hlac_secondary_force, self.projectiledeathtype, other);
25         else
26                 RadiusDamage (self, self.owner, autocvar_g_balance_hlac_primary_damage, autocvar_g_balance_hlac_primary_edgedamage, autocvar_g_balance_hlac_primary_radius, world, autocvar_g_balance_hlac_primary_force, self.projectiledeathtype, other);
27
28         remove (self);
29 }
30
31 void W_HLAC_Attack (void)
32 {
33         local entity missile;
34     float spread;
35
36         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
37         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
38         {
39                 if(autocvar_g_balance_hlac_reload_ammo)
40                 {
41                         self.clip_load -= autocvar_g_balance_hlac_primary_ammo;
42                         self.weapon_load[WEP_HLAC] = self.clip_load;
43                 }
44                 else
45                         self.ammo_cells -= autocvar_g_balance_hlac_primary_ammo;
46         }
47
48     spread = autocvar_g_balance_hlac_primary_spread_min + (autocvar_g_balance_hlac_primary_spread_add * self.misc_bulletcounter);
49     spread = min(spread,autocvar_g_balance_hlac_primary_spread_max);
50     if(self.crouch)
51         spread = spread * autocvar_g_balance_hlac_primary_spread_crouchmod;
52
53         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON, autocvar_g_balance_hlac_primary_damage);
54         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
55         if (!g_norecoil)
56         {
57                 self.punchangle_x = random () - 0.5;
58                 self.punchangle_y = random () - 0.5;
59         }
60
61         missile = spawn ();
62         missile.owner = self;
63         missile.classname = "hlacbolt";
64         missile.bot_dodge = TRUE;
65
66     missile.bot_dodgerating = autocvar_g_balance_hlac_primary_damage;
67
68         missile.movetype = MOVETYPE_FLY;
69         PROJECTILE_MAKETRIGGER(missile);
70
71         setorigin (missile, w_shotorg);
72         setsize(missile, '0 0 0', '0 0 0');
73
74         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_primary_speed, spread);
75         //missile.angles = vectoangles (missile.velocity); // csqc
76
77         missile.touch = W_HLAC_Touch;
78         missile.think = SUB_Remove;
79
80     missile.nextthink = time + autocvar_g_balance_hlac_primary_lifetime;
81
82         missile.flags = FL_PROJECTILE;
83         missile.projectiledeathtype = WEP_HLAC;
84
85         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
86
87         other = missile; MUTATOR_CALLHOOK(EditProjectile);
88 }
89
90 void W_HLAC_Attack2f (void)
91 {
92         local entity missile;
93     float spread;
94
95     spread = autocvar_g_balance_hlac_secondary_spread;
96
97
98     if(self.crouch)
99         spread = spread * autocvar_g_balance_hlac_secondary_spread_crouchmod;
100
101         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON, autocvar_g_balance_hlac_secondary_damage);
102         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
103
104         missile = spawn ();
105         missile.owner = self;
106         missile.classname = "hlacbolt";
107         missile.bot_dodge = TRUE;
108
109     missile.bot_dodgerating = autocvar_g_balance_hlac_secondary_damage;
110
111         missile.movetype = MOVETYPE_FLY;
112         PROJECTILE_MAKETRIGGER(missile);
113
114         setorigin (missile, w_shotorg);
115         setsize(missile, '0 0 0', '0 0 0');
116
117         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_secondary_speed, spread);
118         //missile.angles = vectoangles (missile.velocity); // csqc
119
120         missile.touch = W_HLAC_Touch;
121         missile.think = SUB_Remove;
122
123     missile.nextthink = time + autocvar_g_balance_hlac_secondary_lifetime;
124
125         missile.flags = FL_PROJECTILE;
126         missile.projectiledeathtype = WEP_HLAC | HITTYPE_SECONDARY;
127
128         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
129
130         other = missile; MUTATOR_CALLHOOK(EditProjectile);
131 }
132
133 void W_HLAC_Attack2 (void)
134 {
135     float i;
136
137         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
138         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
139         {
140                 if(autocvar_g_balance_hlac_reload_ammo)
141                 {
142                         self.clip_load -= autocvar_g_balance_hlac_secondary_ammo;
143                         self.weapon_load[WEP_HLAC] = self.clip_load;
144                 }
145                 else
146                         self.ammo_cells -= autocvar_g_balance_hlac_secondary_ammo;
147         }
148
149     for(i=autocvar_g_balance_hlac_secondary_shots;i>0;--i)
150         W_HLAC_Attack2f();
151
152         if (!g_norecoil)
153         {
154                 self.punchangle_x = random () - 0.5;
155                 self.punchangle_y = random () - 0.5;
156         }
157 }
158
159 // weapon frames
160 void HLAC_fire1_02()
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 (!weapon_action(self.weapon, WR_CHECKAMMO1))
171                 {
172                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
173                         w_ready();
174                         return;
175                 }
176
177                 ATTACK_FINISHED(self) = time + autocvar_g_balance_hlac_primary_refire * W_WeaponRateFactor();
178                 W_HLAC_Attack();
179                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
180         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
181         }
182         else
183         {
184                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_animtime, w_ready);
185         }
186 };
187
188 void spawnfunc_weapon_hlac (void)
189 {
190         weapon_defaultspawnfunc(WEP_HLAC);
191 }
192
193 float w_hlac(float req)
194 {
195         float ammo_amount;
196         if (req == WR_AIM)
197         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hlac_primary_speed, 0, autocvar_g_balance_hlac_primary_lifetime, FALSE);
198         else if (req == WR_THINK)
199         {
200                 if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo)) // forced reload
201                         W_HLAC_Reload();
202                 else if (self.BUTTON_ATCK)
203                 {
204                         if (weapon_prepareattack(0, autocvar_g_balance_hlac_primary_refire))
205                         {
206                                 self.misc_bulletcounter = 0;
207                                 W_HLAC_Attack();
208                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
209                         }
210                 }
211
212                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hlac_secondary)
213                 {
214                         if (weapon_prepareattack(1, autocvar_g_balance_hlac_secondary_refire))
215                         {
216                                 W_HLAC_Attack2();
217                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hlac_secondary_animtime, w_ready);
218                         }
219                 }
220         }
221         else if (req == WR_PRECACHE)
222         {
223         precache_model ("models/weapons/g_hlac.md3");
224                 precache_model ("models/weapons/v_hlac.md3");
225                 precache_model ("models/weapons/h_hlac.iqm");
226                 precache_sound ("weapons/lasergun_fire.wav");
227                 precache_sound ("weapons/reload.wav");
228
229         }
230         else if (req == WR_SETUP)
231         {
232                 weapon_setup(WEP_HLAC);
233         }
234         else if (req == WR_CHECKAMMO1)
235         {
236                 ammo_amount = self.ammo_cells >= autocvar_g_balance_hlac_primary_ammo;
237                 ammo_amount += self.weapon_load[WEP_HLAC] >= autocvar_g_balance_hlac_primary_ammo;
238                 return ammo_amount;
239         }
240         else if (req == WR_CHECKAMMO2)
241         {
242                 ammo_amount = self.ammo_cells >= autocvar_g_balance_hlac_secondary_ammo;
243                 ammo_amount += self.weapon_load[WEP_HLAC] >= autocvar_g_balance_hlac_secondary_ammo;
244                 return ammo_amount;
245         }
246         else if (req == WR_RELOAD)
247         {
248                 W_HLAC_Reload();
249         }
250         return TRUE;
251 };
252 #endif
253 #ifdef CSQC
254 float w_hlac(float req)
255 {
256         if(req == WR_IMPACTEFFECT)
257         {
258                 vector org2;
259                 org2 = w_org + w_backoff * 6;
260                 pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
261                 if(!w_issilent)
262                         sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
263         }
264         else if(req == WR_PRECACHE)
265         {
266                 precache_sound("weapons/laserimpact.wav");
267         }
268         else if (req == WR_SUICIDEMESSAGE)
269                 w_deathtypestring = _("%s should have used a smaller gun");
270         else if (req == WR_KILLMESSAGE)
271                 w_deathtypestring = _("%s was cut down by %s");
272         return TRUE;
273 }
274 #endif
275 #endif