]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_hook.qc
Fixed some typos
[divverent/nexuiz.git] / data / qcsrc / server / w_hook.qc
1 .float dmg;
2 .float dmg_edge;
3 .float dmg_radius;
4 .float dmg_force;
5 .float dmg_power;
6 .float dmg_duration;
7 .float dmg_last;
8 .float hook_refire;
9 .float hook_time_hooked;
10 .float hook_time_fueldecrease;
11
12 void W_Hook_ExplodeThink (void)
13 {
14         float dt, dmg_remaining_next, f;
15
16         dt = time - self.teleport_time;
17         dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
18
19         f = self.dmg_last - dmg_remaining_next;
20         self.dmg_last = dmg_remaining_next;
21
22         RadiusDamage (self, self.owner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.owner, self.dmg_force * f, self.projectiledeathtype, world);
23         self.projectiledeathtype |= HITTYPE_BOUNCE;
24         //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, self.dmg_force * f, self.projectiledeathtype, world);
25
26         if(dt < self.dmg_duration)
27                 self.nextthink = time + 0.05; // soon
28         else
29                 remove(self);
30 }
31
32 void W_Hook_Explode2 (void)
33 {
34         self.event_damage = SUB_Null;
35         self.touch = SUB_Null;
36         self.effects |= EF_NODRAW;
37
38         self.think = W_Hook_ExplodeThink;
39         self.nextthink = time;
40         self.dmg = cvar("g_balance_hook_secondary_damage");
41         self.dmg_edge = cvar("g_balance_hook_secondary_edgedamage");
42         self.dmg_radius = cvar("g_balance_hook_secondary_radius");
43         self.dmg_force = cvar("g_balance_hook_secondary_force");
44         self.dmg_power = cvar("g_balance_hook_secondary_power");
45         self.dmg_duration = cvar("g_balance_hook_secondary_duration");
46         self.teleport_time = time;
47         self.dmg_last = 1;
48         self.movetype = MOVETYPE_NONE;
49 }
50
51 void W_Hook_Touch2 (void)
52 {
53         PROJECTILE_TOUCH;
54         self.use();
55 }
56
57 void W_Hook_Attack2()
58 {
59         local entity gren;
60
61         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
62                 self.ammo_cells = self.ammo_cells - cvar("g_balance_hook_secondary_ammo");
63         W_SetupShot (self, FALSE, 4, "weapons/hookbomb_fire.wav", cvar("g_balance_hook_secondary_damage"));
64
65         gren = spawn ();
66         gren.owner = self;
67         gren.classname = "hookbomb";
68         gren.bot_dodge = TRUE;
69         gren.bot_dodgerating = cvar("g_balance_hook_secondary_damage");
70         gren.movetype = MOVETYPE_TOSS;
71         PROJECTILE_MAKETRIGGER(gren);
72         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
73         setorigin(gren, w_shotorg);
74         setsize(gren, '0 0 0', '0 0 0');
75
76         gren.nextthink = time + cvar("g_balance_hook_secondary_lifetime");
77         gren.think = adaptor_think2use;
78         gren.use = W_Hook_Explode2;
79         gren.touch = W_Hook_Touch2;
80
81         gren.velocity = '0 0 1' * cvar("g_balance_hook_secondary_speed");
82         if(cvar("g_projectiles_newton_style"))
83                 gren.velocity = gren.velocity + self.velocity;
84
85         gren.gravity = cvar("g_balance_hook_secondary_gravity");
86         //W_SetupProjectileVelocity(gren); // just falling down!
87
88         gren.angles = '0 0 0';
89         gren.flags = FL_PROJECTILE;
90
91         CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
92 }
93
94 void spawnfunc_weapon_hook (void)
95 {
96         if(g_grappling_hook) // offhand hook
97         {
98                 startitem_failed = TRUE;
99                 remove(self);
100                 return;
101         }
102         weapon_defaultspawnfunc(WEP_HOOK);
103 }
104
105 float w_hook(float req)
106 {
107         float hooked_time_max, hooked_fuel;
108                 
109         if (req == WR_AIM)
110         {
111                 // ... sorry ...
112         }
113         else if (req == WR_THINK)
114         {
115                 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
116                 {
117                         if(!self.hook)
118                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
119                         if not(self.hook_state & HOOK_FIRING)
120                         if (time > self.hook_refire)
121                         if (weapon_prepareattack(0, -1))
122                         {
123                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
124                                         self.ammo_fuel = self.ammo_fuel - cvar("g_balance_hook_primary_fuel");
125                                 self.hook_state |= HOOK_FIRING;
126                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hook_primary_animtime"), w_ready);                          
127                         }
128                 }
129
130                 if (self.BUTTON_ATCK2)
131                 {
132                         if (weapon_prepareattack(1, cvar("g_balance_hook_secondary_refire")))
133                         {
134                                 W_Hook_Attack2();
135                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_hook_secondary_animtime"), w_ready);
136                         }
137                 }
138
139                 if(self.hook)
140                 {
141                         // if hooked, no bombs, and increase the timer
142                         self.hook_refire = max(self.hook_refire, time + cvar("g_balance_hook_primary_refire"));
143
144                         // hook also inhibits health regeneration, but only for 1 second
145                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
146                                 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
147                 }
148
149                 if(self.hook && self.hook.state == 1)
150                 {
151                         hooked_time_max = cvar("g_balance_hook_primary_hooked_time_max");                       
152                         if (hooked_time_max > 0)
153                         {
154                                 if ( time > self.hook_time_hooked + hooked_time_max )
155                                         self.hook_state |= HOOK_REMOVING;
156                         }
157                         
158                         hooked_fuel = cvar("g_balance_hook_primary_hooked_fuel");
159                         if (hooked_fuel > 0)
160                         {
161                                 if ( time > self.hook_time_fueldecrease )
162                                 {
163                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
164                                         {
165                                                 if ( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
166                                                 {
167                                                         self.ammo_fuel -= (time - self.hook_time_fueldecrease) * hooked_fuel;
168                                                         self.hook_time_fueldecrease = time;
169                                                         // decrease next frame again
170                                                 }
171                                                 else
172                                                 {
173                                                         self.ammo_fuel = 0;
174                                                         self.hook_state |= HOOK_REMOVING;
175                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
176                                                 }
177                                         }
178                                 }
179                         }
180                 }
181                 else
182                 {
183                         self.hook_time_hooked = time;                           
184                         self.hook_time_fueldecrease = time + cvar("g_balance_hook_primary_hooked_time_free");
185                 }
186
187                 if (self.BUTTON_CROUCH)
188                 {
189                         self.hook_state &~= HOOK_PULLING;
190                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
191                                 self.hook_state &~= HOOK_RELEASING;
192                         else
193                                 self.hook_state |= HOOK_RELEASING;
194                 }
195                 else
196                 {
197                         self.hook_state |= HOOK_PULLING;
198                         self.hook_state &~= HOOK_RELEASING;
199
200                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
201                         {
202                                 // already fired
203                                 if(self.hook)
204                                         self.hook_state |= HOOK_WAITING_FOR_RELEASE;
205                         }
206                         else
207                         {
208                                 self.hook_state |= HOOK_REMOVING;
209                                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
210                         }
211                 }
212         }
213         else if (req == WR_PRECACHE)
214         {
215                 precache_model ("models/weapons/g_hookgun.md3");
216                 precache_model ("models/weapons/v_hookgun.md3");
217                 precache_model ("models/weapons/h_hookgun.dpm");
218                 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
219                 precache_sound ("weapons/hook_fire.wav");
220                 precache_sound ("weapons/hookbomb_fire.wav");
221         }
222         else if (req == WR_SETUP)
223         {
224                 weapon_setup(WEP_HOOK);
225                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
226         }
227         else if (req == WR_CHECKAMMO1)
228         {
229                 if(self.hook)
230                         return self.ammo_fuel > 0;
231                 else
232                         return self.ammo_fuel >= cvar("g_balance_hook_primary_fuel");
233         }
234         else if (req == WR_CHECKAMMO2)
235         {
236                 return self.ammo_cells >= cvar("g_balance_hook_secondary_ammo");
237         }
238         else if (req == WR_SUICIDEMESSAGE)
239                 w_deathtypestring = "did the impossible";
240         else if (req == WR_KILLMESSAGE)
241                 w_deathtypestring = "has run into #'s gravity bomb";
242         else if (req == WR_RESETPLAYER)
243         {
244                 self.hook_refire = time;
245         }
246         return TRUE;
247 };