]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hagar.qc
Attempt to further simplify the reload code, as requested. First part of the first...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hagar.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(HAGAR, w_hagar, IT_ROCKETS, 8, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hagar", "hagar", _("Hagar"))
3 #else
4 #ifdef SVQC
5 // NO bounce protection, as bounces are limited!
6
7 void W_Hagar_Reload()
8 {
9         W_Reload(ammo_rockets, min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo), autocvar_g_balance_hagar_reload_ammo, autocvar_g_balance_hagar_reload_time, "weapons/reload.wav");
10 }
11
12 void W_Hagar_Explode (void)
13 {
14         self.event_damage = SUB_Null;
15         RadiusDamage (self, self.realowner, autocvar_g_balance_hagar_primary_damage, autocvar_g_balance_hagar_primary_edgedamage, autocvar_g_balance_hagar_primary_radius, world, autocvar_g_balance_hagar_primary_force, self.projectiledeathtype, other);
16
17         remove (self);
18 }
19
20 void W_Hagar_Explode2 (void)
21 {
22         self.event_damage = SUB_Null;
23         RadiusDamage (self, self.realowner, autocvar_g_balance_hagar_secondary_damage, autocvar_g_balance_hagar_secondary_edgedamage, autocvar_g_balance_hagar_secondary_radius, world, autocvar_g_balance_hagar_secondary_force, self.projectiledeathtype, other);
24
25         remove (self);
26 }
27
28 void W_Hagar_Touch (void)
29 {
30         PROJECTILE_TOUCH;
31         self.use ();
32 }
33
34 void W_Hagar_Touch2 (void)
35 {
36         PROJECTILE_TOUCH;
37
38         if(self.cnt > 0 || other.takedamage == DAMAGE_AIM) {
39                 self.use();
40         } else {
41                 self.cnt++;
42                 pointparticles(particleeffectnum("hagar_bounce"), self.origin, self.velocity, 1);
43                 self.angles = vectoangles (self.velocity);
44                 self.owner = world;
45                 self.projectiledeathtype |= HITTYPE_BOUNCE;
46         }
47 }
48
49 void W_Hagar_Attack (void)
50 {
51         local entity missile;
52
53         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
54         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
55         {
56                 if(autocvar_g_balance_hagar_reload_ammo)
57                 {
58                         self.clip_load -= autocvar_g_balance_hagar_primary_ammo;
59                         self.weapon_load[WEP_HAGAR] = self.clip_load;
60                 }
61                 else
62                         self.ammo_rockets -= autocvar_g_balance_hagar_primary_ammo;
63         }
64
65         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_primary_damage);
66
67         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
68
69         missile = spawn ();
70         missile.owner = missile.realowner = self;
71         missile.classname = "missile";
72         missile.bot_dodge = TRUE;
73         missile.bot_dodgerating = autocvar_g_balance_hagar_primary_damage;
74         missile.touch = W_Hagar_Touch;
75         missile.use = W_Hagar_Explode;
76         missile.think = adaptor_think2use_hittype_splash;
77         missile.nextthink = time + autocvar_g_balance_hagar_primary_lifetime;
78         PROJECTILE_MAKETRIGGER(missile);
79         missile.projectiledeathtype = WEP_HAGAR;
80         setorigin (missile, w_shotorg);
81         setsize(missile, '0 0 0', '0 0 0');
82
83         missile.movetype = MOVETYPE_FLY;
84         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_primary);
85
86         missile.angles = vectoangles (missile.velocity);
87         missile.flags = FL_PROJECTILE;
88
89         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
90
91         other = missile; MUTATOR_CALLHOOK(EditProjectile);
92 }
93
94 void W_Hagar_Attack2 (void)
95 {
96         local entity missile;
97
98         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
99         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
100         {
101                 if(autocvar_g_balance_hagar_reload_ammo)
102                 {
103                         self.clip_load -= autocvar_g_balance_hagar_secondary_ammo;
104                         self.weapon_load[WEP_HAGAR] = self.clip_load;
105                 }
106                 else
107                         self.ammo_rockets -= autocvar_g_balance_hagar_secondary_ammo;
108         }
109
110         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_secondary_damage);
111
112         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
113
114         missile = spawn ();
115         missile.owner = missile.realowner = self;
116         missile.classname = "missile";
117         missile.bot_dodge = TRUE;
118         missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
119         missile.touch = W_Hagar_Touch2;
120         missile.cnt = 0;
121         missile.use = W_Hagar_Explode2;
122         missile.think = adaptor_think2use_hittype_splash;
123         missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
124         PROJECTILE_MAKETRIGGER(missile);
125         missile.projectiledeathtype = WEP_HAGAR | HITTYPE_SECONDARY;
126         setorigin (missile, w_shotorg);
127         setsize(missile, '0 0 0', '0 0 0');
128
129         missile.movetype = MOVETYPE_BOUNCEMISSILE;
130         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_secondary);
131
132         missile.angles = vectoangles (missile.velocity);
133         missile.flags = FL_PROJECTILE;
134
135         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR_BOUNCING, TRUE);
136
137         other = missile; MUTATOR_CALLHOOK(EditProjectile);
138 }
139
140 void spawnfunc_weapon_hagar (void)
141 {
142         weapon_defaultspawnfunc(WEP_HAGAR);
143 }
144
145 float w_hagar(float req)
146 {
147         float ammo_amount;
148         if (req == WR_AIM)
149                 if (random()>0.15)
150                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
151                 else
152                 {
153                         // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
154                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
155                 }
156         else if (req == WR_THINK)
157         {
158                 if(autocvar_g_balance_hagar_reload_ammo && self.clip_load < min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo)) // forced reload
159                         W_Hagar_Reload();
160                 else if (self.BUTTON_ATCK)
161                 {
162                         if (weapon_prepareattack(0, autocvar_g_balance_hagar_primary_refire))
163                         {
164                                 W_Hagar_Attack();
165                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hagar_primary_refire, w_ready);
166                         }
167                 }
168                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hagar_secondary)
169                 {
170                         if (weapon_prepareattack(1, autocvar_g_balance_hagar_secondary_refire))
171                         {
172                                 W_Hagar_Attack2();
173                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hagar_secondary_refire, w_ready);
174                         }
175                 }
176         }
177         else if (req == WR_PRECACHE)
178         {
179                 precache_model ("models/weapons/g_hagar.md3");
180                 precache_model ("models/weapons/v_hagar.md3");
181                 precache_model ("models/weapons/h_hagar.iqm");
182                 precache_sound ("weapons/hagar_fire.wav");
183                 precache_sound ("weapons/reload.wav");
184         }
185         else if (req == WR_SETUP)
186         {
187                 weapon_setup(WEP_HAGAR);
188         }
189         else if (req == WR_CHECKAMMO1)
190         {
191                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_primary_ammo;
192                 ammo_amount += self.weapon_load[WEP_HAGAR] >= autocvar_g_balance_hagar_primary_ammo;
193                 return ammo_amount;
194         }
195         else if (req == WR_CHECKAMMO2)
196         {
197                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_secondary_ammo;
198                 ammo_amount += self.weapon_load[WEP_HAGAR] >= autocvar_g_balance_hagar_secondary_ammo;
199                 return ammo_amount;
200         }
201         else if (req == WR_RELOAD)
202         {
203                 W_Hagar_Reload();
204         }
205         return TRUE;
206 };
207 #endif
208 #ifdef CSQC
209 float w_hagar(float req)
210 {
211         if(req == WR_IMPACTEFFECT)
212         {
213                 vector org2;
214                 org2 = w_org + w_backoff * 6;
215                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
216                 if(!w_issilent)
217                 {
218                         if (w_random<0.15)
219                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
220                         else if (w_random<0.7)
221                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
222                         else
223                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
224                 }
225         }
226         else if(req == WR_PRECACHE)
227         {
228                 precache_sound("weapons/hagexp1.wav");
229                 precache_sound("weapons/hagexp2.wav");
230                 precache_sound("weapons/hagexp3.wav");
231         }
232         else if (req == WR_SUICIDEMESSAGE)
233                 w_deathtypestring = _("%s played with tiny rockets");
234         else if (req == WR_KILLMESSAGE)
235         {
236                 if(w_deathtype & HITTYPE_BOUNCE) // must be secondary; unchecked: SPLASH
237                         w_deathtypestring = _("%s hoped %s's missiles wouldn't bounce");
238                 else // unchecked: SPLASH, SECONDARY
239                         w_deathtypestring = _("%s was pummeled by %s");
240         }
241         return TRUE;
242 }
243 #endif
244 #endif