]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hook.qc
W_CheckProjectileDamage -- new global weapon function which check g_projectiles_damag...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hook.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(HOOK, w_hook, IT_CELLS|IT_FUEL, 0, WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, 0, "hookgun", "hook", _("Grappling Hook"))
3 #else
4 #ifdef SVQC
5 .float dmg;
6 .float dmg_edge;
7 .float dmg_radius;
8 .float dmg_force;
9 .float dmg_power;
10 .float dmg_duration;
11 .float dmg_last;
12 .float hook_refire;
13 .float hook_time_hooked;
14 .float hook_time_fueldecrease;
15
16 void W_Hook_ExplodeThink (void)
17 {
18         float dt, dmg_remaining_next, f;
19
20         dt = time - self.teleport_time;
21         dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
22
23         f = self.dmg_last - dmg_remaining_next;
24         self.dmg_last = dmg_remaining_next;
25
26         RadiusDamage (self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, self.dmg_force * f, self.projectiledeathtype, world);
27         self.projectiledeathtype |= HITTYPE_BOUNCE;
28         //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, self.dmg_force * f, self.projectiledeathtype, world);
29
30         if(dt < self.dmg_duration)
31                 self.nextthink = time + 0.05; // soon
32         else
33                 remove(self);
34 }
35
36 void W_Hook_Explode2 (void)
37 {
38         self.event_damage = SUB_Null;
39         self.touch = SUB_Null;
40         self.effects |= EF_NODRAW;
41
42         self.think = W_Hook_ExplodeThink;
43         self.nextthink = time;
44         self.dmg = autocvar_g_balance_hook_secondary_damage;
45         self.dmg_edge = autocvar_g_balance_hook_secondary_edgedamage;
46         self.dmg_radius = autocvar_g_balance_hook_secondary_radius;
47         self.dmg_force = autocvar_g_balance_hook_secondary_force;
48         self.dmg_power = autocvar_g_balance_hook_secondary_power;
49         self.dmg_duration = autocvar_g_balance_hook_secondary_duration;
50         self.teleport_time = time;
51         self.dmg_last = 1;
52         self.movetype = MOVETYPE_NONE;
53 }
54
55 void W_Hook_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
56 {
57         if (self.health <= 0)
58                 return;
59                 
60         if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, 0)) // no exceptions
61                 return; // g_projectiles_damage says to halt    
62         
63         self.health = self.health - damage;
64         
65         print(strcat("hookbomb health ", ftos(self.health), " after ", ftos(damage), " damage... (at time: ", ftos(time), ")\n"));
66         
67         if (self.health <= 0)
68                 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
69 }
70
71 void W_Hook_Touch2 (void)
72 {
73         PROJECTILE_TOUCH;
74         self.use();
75 }
76
77 void W_Hook_Attack2()
78 {
79         local entity gren;
80
81         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_hook_secondary_ammo, FALSE);
82         W_SetupShot (self, FALSE, 4, "weapons/hookbomb_fire.wav", CH_WEAPON_A, autocvar_g_balance_hook_secondary_damage);
83
84         gren = spawn ();
85         gren.owner = gren.realowner = self;
86         gren.classname = "hookbomb";
87         gren.bot_dodge = TRUE;
88         gren.bot_dodgerating = autocvar_g_balance_hook_secondary_damage;
89         gren.movetype = MOVETYPE_TOSS;
90         PROJECTILE_MAKETRIGGER(gren);
91         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
92         setorigin(gren, w_shotorg);
93         setsize(gren, '0 0 0', '0 0 0');
94
95         gren.nextthink = time + autocvar_g_balance_hook_secondary_lifetime;
96         gren.think = adaptor_think2use_hittype_splash;
97         gren.use = W_Hook_Explode2;
98         gren.touch = W_Hook_Touch2;
99         
100         gren.takedamage = DAMAGE_YES;
101         gren.health = autocvar_g_balance_hook_secondary_health;
102         gren.damageforcescale = autocvar_g_balance_hook_secondary_damageforcescale;
103         gren.event_damage = W_Hook_Damage;
104         gren.damagedbycontents = TRUE;
105
106         gren.velocity = '0 0 1' * autocvar_g_balance_hook_secondary_speed;
107         if(autocvar_g_projectiles_newton_style)
108                 gren.velocity = gren.velocity + self.velocity;
109
110         gren.gravity = autocvar_g_balance_hook_secondary_gravity;
111         //W_SetupProjectileVelocity(gren); // just falling down!
112
113         gren.angles = '0 0 0';
114         gren.flags = FL_PROJECTILE;
115
116         CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
117
118         other = gren; MUTATOR_CALLHOOK(EditProjectile);
119 }
120
121 void spawnfunc_weapon_hook (void)
122 {
123         if(g_grappling_hook) // offhand hook
124         {
125                 startitem_failed = TRUE;
126                 remove(self);
127                 return;
128         }
129         weapon_defaultspawnfunc(WEP_HOOK);
130 }
131
132 float w_hook(float req)
133 {
134         float hooked_time_max, hooked_fuel;
135                 
136         if (req == WR_AIM)
137         {
138                 // ... sorry ...
139         }
140         else if (req == WR_THINK)
141         {
142                 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
143                 {
144                         if(!self.hook)
145                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
146                         if not(self.hook_state & HOOK_FIRING)
147                         if (time > self.hook_refire)
148                         if (weapon_prepareattack(0, -1))
149                         {
150                                 W_DecreaseAmmo(ammo_fuel, autocvar_g_balance_hook_primary_fuel, FALSE);
151                                 self.hook_state |= HOOK_FIRING;
152                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hook_primary_animtime, w_ready);                         
153                         }
154                 }
155
156                 if (self.BUTTON_ATCK2)
157                 {
158                         if (weapon_prepareattack(1, autocvar_g_balance_hook_secondary_refire))
159                         {
160                                 W_Hook_Attack2();
161                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hook_secondary_animtime, w_ready);
162                         }
163                 }
164
165                 if(self.hook)
166                 {
167                         // if hooked, no bombs, and increase the timer
168                         self.hook_refire = max(self.hook_refire, time + autocvar_g_balance_hook_primary_refire * W_WeaponRateFactor());
169
170                         // hook also inhibits health regeneration, but only for 1 second
171                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
172                                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
173                 }
174
175                 if(self.hook && self.hook.state == 1)
176                 {
177                         hooked_time_max = autocvar_g_balance_hook_primary_hooked_time_max;                      
178                         if (hooked_time_max > 0)
179                         {
180                                 if ( time > self.hook_time_hooked + hooked_time_max )
181                                         self.hook_state |= HOOK_REMOVING;
182                         }
183                         
184                         hooked_fuel = autocvar_g_balance_hook_primary_hooked_fuel;
185                         if (hooked_fuel > 0)
186                         {
187                                 if ( time > self.hook_time_fueldecrease )
188                                 {
189                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
190                                         {
191                                                 if ( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
192                                                 {
193                                                         W_DecreaseAmmo(ammo_fuel, (time - self.hook_time_fueldecrease) * hooked_fuel, FALSE);
194                                                         self.hook_time_fueldecrease = time;
195                                                         // decrease next frame again
196                                                 }
197                                                 else
198                                                 {
199                                                         self.ammo_fuel = 0;
200                                                         self.hook_state |= HOOK_REMOVING;
201                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
202                                                 }
203                                         }
204                                 }
205                         }
206                 }
207                 else
208                 {
209                         self.hook_time_hooked = time;                           
210                         self.hook_time_fueldecrease = time + autocvar_g_balance_hook_primary_hooked_time_free;
211                 }
212
213                 if (self.BUTTON_CROUCH)
214                 {
215                         self.hook_state &~= HOOK_PULLING;
216                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
217                                 self.hook_state &~= HOOK_RELEASING;
218                         else
219                                 self.hook_state |= HOOK_RELEASING;
220                 }
221                 else
222                 {
223                         self.hook_state |= HOOK_PULLING;
224                         self.hook_state &~= HOOK_RELEASING;
225
226                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
227                         {
228                                 // already fired
229                                 if(self.hook)
230                                         self.hook_state |= HOOK_WAITING_FOR_RELEASE;
231                         }
232                         else
233                         {
234                                 self.hook_state |= HOOK_REMOVING;
235                                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
236                         }
237                 }
238         }
239         else if (req == WR_PRECACHE)
240         {
241                 precache_model ("models/weapons/g_hookgun.md3");
242                 precache_model ("models/weapons/v_hookgun.md3");
243                 precache_model ("models/weapons/h_hookgun.iqm");
244                 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
245                 precache_sound ("weapons/hook_fire.wav");
246                 precache_sound ("weapons/hookbomb_fire.wav");
247         }
248         else if (req == WR_SETUP)
249         {
250                 weapon_setup(WEP_HOOK);
251                 self.current_ammo = ammo_fuel;
252                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
253         }
254         else if (req == WR_CHECKAMMO1)
255         {
256                 if(self.hook)
257                         return self.ammo_fuel > 0;
258                 else
259                         return self.ammo_fuel >= autocvar_g_balance_hook_primary_fuel;
260         }
261         else if (req == WR_CHECKAMMO2)
262         {
263                 return self.ammo_cells >= autocvar_g_balance_hook_secondary_ammo;
264         }
265         else if (req == WR_RESETPLAYER)
266         {
267                 self.hook_refire = time;
268         }
269         return TRUE;
270 };
271 #endif
272 #ifdef CSQC
273 float w_hook(float req)
274 {
275         if(req == WR_IMPACTEFFECT)
276         {
277                 vector org2;
278                 org2 = w_org + w_backoff * 2;
279                 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
280                 if(!w_issilent)
281                         sound(self, CH_SHOTS, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
282         }
283         else if(req == WR_PRECACHE)
284         {
285                 precache_sound("weapons/hookbomb_impact.wav");
286         }
287         else if (req == WR_SUICIDEMESSAGE)
288                 w_deathtypestring = _("%s did the impossible");
289         else if (req == WR_KILLMESSAGE)
290                 w_deathtypestring = _("%s has run into %s's gravity bomb");
291         return TRUE;
292 }
293 #endif
294 #endif