]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hook.qc
Merge remote branch 'origin/master' into samual/flyingspectators
[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_Touch2 (void)
56 {
57         PROJECTILE_TOUCH;
58         self.use();
59 }
60
61 void W_Hook_Attack2()
62 {
63         local entity gren;
64
65         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_hook_secondary_ammo, FALSE);
66         W_SetupShot (self, FALSE, 4, "weapons/hookbomb_fire.wav", CH_WEAPON_A, autocvar_g_balance_hook_secondary_damage);
67
68         gren = spawn ();
69         gren.owner = gren.realowner = self;
70         gren.classname = "hookbomb";
71         gren.bot_dodge = TRUE;
72         gren.bot_dodgerating = autocvar_g_balance_hook_secondary_damage;
73         gren.movetype = MOVETYPE_TOSS;
74         PROJECTILE_MAKETRIGGER(gren);
75         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
76         setorigin(gren, w_shotorg);
77         setsize(gren, '0 0 0', '0 0 0');
78
79         gren.nextthink = time + autocvar_g_balance_hook_secondary_lifetime;
80         gren.think = adaptor_think2use_hittype_splash;
81         gren.use = W_Hook_Explode2;
82         gren.touch = W_Hook_Touch2;
83
84         gren.velocity = '0 0 1' * autocvar_g_balance_hook_secondary_speed;
85         if(autocvar_g_projectiles_newton_style)
86                 gren.velocity = gren.velocity + self.velocity;
87
88         gren.gravity = autocvar_g_balance_hook_secondary_gravity;
89         //W_SetupProjectileVelocity(gren); // just falling down!
90
91         gren.angles = '0 0 0';
92         gren.flags = FL_PROJECTILE;
93
94         CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
95
96         other = gren; MUTATOR_CALLHOOK(EditProjectile);
97 }
98
99 void spawnfunc_weapon_hook (void)
100 {
101         if(g_grappling_hook) // offhand hook
102         {
103                 startitem_failed = TRUE;
104                 remove(self);
105                 return;
106         }
107         weapon_defaultspawnfunc(WEP_HOOK);
108 }
109
110 float w_hook(float req)
111 {
112         float hooked_time_max, hooked_fuel;
113                 
114         if (req == WR_AIM)
115         {
116                 // ... sorry ...
117         }
118         else if (req == WR_THINK)
119         {
120                 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
121                 {
122                         if(!self.hook)
123                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
124                         if not(self.hook_state & HOOK_FIRING)
125                         if (time > self.hook_refire)
126                         if (weapon_prepareattack(0, -1))
127                         {
128                                 W_DecreaseAmmo(ammo_fuel, autocvar_g_balance_hook_primary_fuel, FALSE);
129                                 self.hook_state |= HOOK_FIRING;
130                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hook_primary_animtime, w_ready);                         
131                         }
132                 }
133
134                 if (self.BUTTON_ATCK2)
135                 {
136                         if (weapon_prepareattack(1, autocvar_g_balance_hook_secondary_refire))
137                         {
138                                 W_Hook_Attack2();
139                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hook_secondary_animtime, w_ready);
140                         }
141                 }
142
143                 if(self.hook)
144                 {
145                         // if hooked, no bombs, and increase the timer
146                         self.hook_refire = max(self.hook_refire, time + autocvar_g_balance_hook_primary_refire);
147
148                         // hook also inhibits health regeneration, but only for 1 second
149                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
150                                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
151                 }
152
153                 if(self.hook && self.hook.state == 1)
154                 {
155                         hooked_time_max = autocvar_g_balance_hook_primary_hooked_time_max;                      
156                         if (hooked_time_max > 0)
157                         {
158                                 if ( time > self.hook_time_hooked + hooked_time_max )
159                                         self.hook_state |= HOOK_REMOVING;
160                         }
161                         
162                         hooked_fuel = autocvar_g_balance_hook_primary_hooked_fuel;
163                         if (hooked_fuel > 0)
164                         {
165                                 if ( time > self.hook_time_fueldecrease )
166                                 {
167                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
168                                         {
169                                                 if ( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
170                                                 {
171                                                         W_DecreaseAmmo(ammo_fuel, (time - self.hook_time_fueldecrease) * hooked_fuel, FALSE);
172                                                         self.hook_time_fueldecrease = time;
173                                                         // decrease next frame again
174                                                 }
175                                                 else
176                                                 {
177                                                         self.ammo_fuel = 0;
178                                                         self.hook_state |= HOOK_REMOVING;
179                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
180                                                 }
181                                         }
182                                 }
183                         }
184                 }
185                 else
186                 {
187                         self.hook_time_hooked = time;                           
188                         self.hook_time_fueldecrease = time + autocvar_g_balance_hook_primary_hooked_time_free;
189                 }
190
191                 if (self.BUTTON_CROUCH)
192                 {
193                         self.hook_state &~= HOOK_PULLING;
194                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
195                                 self.hook_state &~= HOOK_RELEASING;
196                         else
197                                 self.hook_state |= HOOK_RELEASING;
198                 }
199                 else
200                 {
201                         self.hook_state |= HOOK_PULLING;
202                         self.hook_state &~= HOOK_RELEASING;
203
204                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
205                         {
206                                 // already fired
207                                 if(self.hook)
208                                         self.hook_state |= HOOK_WAITING_FOR_RELEASE;
209                         }
210                         else
211                         {
212                                 self.hook_state |= HOOK_REMOVING;
213                                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
214                         }
215                 }
216         }
217         else if (req == WR_PRECACHE)
218         {
219                 precache_model ("models/weapons/g_hookgun.md3");
220                 precache_model ("models/weapons/v_hookgun.md3");
221                 precache_model ("models/weapons/h_hookgun.iqm");
222                 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
223                 precache_sound ("weapons/hook_fire.wav");
224                 precache_sound ("weapons/hookbomb_fire.wav");
225         }
226         else if (req == WR_SETUP)
227         {
228                 weapon_setup(WEP_HOOK);
229                 self.current_ammo = ammo_fuel;
230                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
231         }
232         else if (req == WR_CHECKAMMO1)
233         {
234                 if(self.hook)
235                         return self.ammo_fuel > 0;
236                 else
237                         return self.ammo_fuel >= autocvar_g_balance_hook_primary_fuel;
238         }
239         else if (req == WR_CHECKAMMO2)
240         {
241                 return self.ammo_cells >= autocvar_g_balance_hook_secondary_ammo;
242         }
243         else if (req == WR_RESETPLAYER)
244         {
245                 self.hook_refire = time;
246         }
247         return TRUE;
248 };
249 #endif
250 #ifdef CSQC
251 float w_hook(float req)
252 {
253         if(req == WR_IMPACTEFFECT)
254         {
255                 vector org2;
256                 org2 = w_org + w_backoff * 2;
257                 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
258                 if(!w_issilent)
259                         sound(self, CH_SHOTS, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
260         }
261         else if(req == WR_PRECACHE)
262         {
263                 precache_sound("weapons/hookbomb_impact.wav");
264         }
265         else if (req == WR_SUICIDEMESSAGE)
266                 w_deathtypestring = _("%s did the impossible");
267         else if (req == WR_KILLMESSAGE)
268                 w_deathtypestring = _("%s has run into %s's gravity bomb");
269         return TRUE;
270 }
271 #endif
272 #endif