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