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