]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_hook.qc
jetpack: add a "fuel" ammo type, and use that - and let it have regeneration
[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_ammodecrease;
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");
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         gren.solid = SOLID_BBOX;
72         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
73         setorigin(gren, w_shotorg);
74
75         gren.nextthink = time + cvar("g_balance_hook_secondary_lifetime");
76         gren.think = adaptor_think2use;
77         gren.use = W_Hook_Explode2;
78         gren.touch = W_Hook_Touch2;
79
80         gren.velocity = '0 0 1' * cvar("g_balance_hook_secondary_speed");
81         if(cvar("g_projectiles_newton_style"))
82                 gren.velocity = gren.velocity + self.velocity;
83
84         gren.gravity = cvar("g_balance_hook_secondary_gravity");
85         //W_SetupProjectileVelocity(gren); // just falling down!
86
87         gren.angles = '0 0 0';
88         gren.flags = FL_PROJECTILE;
89
90         CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
91 }
92
93 void spawnfunc_weapon_hook (void)
94 {
95         if(g_grappling_hook) // offhand hook
96         {
97                 startitem_failed = TRUE;
98                 remove(self);
99                 return;
100         }
101         weapon_defaultspawnfunc(WEP_HOOK);
102 }
103
104 float w_hook(float req)
105 {
106         float hooked_time_max, hooked_ammodecrease_delay;
107                 
108         if (req == WR_AIM)
109         {
110                 // ... sorry ...
111         }
112         else if (req == WR_THINK)
113         {
114                 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
115                 {
116                         if(!self.hook)
117                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
118                         if (time > self.hook_refire)
119                         if (weapon_prepareattack(0, -1))
120                         {
121                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
122                                         self.ammo_cells = self.ammo_cells - cvar("g_balance_hook_primary_ammo");
123                                 self.hook_state |= HOOK_FIRING;
124                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hook_primary_animtime"), w_ready);                          
125                         }
126                 }
127
128                 if (self.BUTTON_ATCK2)
129                 {
130                         if (weapon_prepareattack(1, cvar("g_balance_hook_secondary_refire")))
131                         {
132                                 W_Hook_Attack2();
133                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_hook_secondary_animtime"), w_ready);
134                         }
135                 }
136
137                 if(self.hook)
138                 {
139                         // if hooked, no bombs, and increase the timer
140                         self.hook_refire = max(self.hook_refire, time + cvar("g_balance_hook_primary_refire"));
141                 }
142
143                 if(self.hook && self.hook.state == 1)
144                 {
145                         hooked_time_max = cvar("g_balance_hook_primary_hooked_time_max");                       
146                         if (hooked_time_max > 0)
147                         {
148                                 if ( time > self.hook_time_hooked + hooked_time_max )
149                                         self.hook_state |= HOOK_REMOVING;
150                         }
151                         
152                         hooked_ammodecrease_delay = cvar("g_balance_hook_primary_hooked_ammodecrease_delay");
153                         if (hooked_ammodecrease_delay > 0)
154                         {
155                                 if ( time > self.hook_time_ammodecrease )
156                                 {
157                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
158                                         {
159                                                 if ( self.ammo_cells >= frametime / hooked_ammodecrease_delay )
160                                                 {
161                                                         self.ammo_cells -= frametime / hooked_ammodecrease_delay;
162                                                         // decrease next frame again
163                                                 }
164                                                 else
165                                                 {
166                                                         self.hook_state |= HOOK_REMOVING;
167                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
168                                                 }
169                                         }
170                                 }
171                         }
172                 }
173                 else
174                 {
175                         self.hook_time_hooked = time;                           
176                         self.hook_time_ammodecrease = time + cvar("g_balance_hook_primary_hooked_time_free");
177                 }
178
179                 if (self.BUTTON_CROUCH)
180                 {
181                         self.hook_state &~= HOOK_PULLING;
182                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
183                                 self.hook_state &~= HOOK_RELEASING;
184                         else
185                                 self.hook_state |= HOOK_RELEASING;
186                 }
187                 else
188                 {
189                         self.hook_state |= HOOK_PULLING;
190                         self.hook_state &~= HOOK_RELEASING;
191
192                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
193                         {
194                                 // already fired
195                                 if(self.hook)
196                                         self.hook_state |= HOOK_WAITING_FOR_RELEASE;
197                         }
198                         else
199                         {
200                                 self.hook_state |= HOOK_REMOVING;
201                                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
202                         }
203                 }
204         }
205         else if (req == WR_PRECACHE)
206         {
207                 precache_model ("models/weapons/g_hookgun.md3");
208                 precache_model ("models/weapons/v_hookgun.md3");
209                 precache_model ("models/weapons/h_hookgun.dpm");
210                 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
211                 precache_sound ("weapons/hook_fire.wav");
212                 precache_sound ("weapons/hookbomb_fire.wav");
213         }
214         else if (req == WR_SETUP)
215         {
216                 weapon_setup(WEP_HOOK);
217                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
218         }
219         else if (req == WR_CHECKAMMO1)
220         {
221                 return self.ammo_cells >= cvar("g_balance_hook_primary_ammo");                  
222         }
223         else if (req == WR_CHECKAMMO2)
224         {
225                 return self.ammo_cells >= cvar("g_balance_hook_secondary_ammo");
226         }
227         else if (req == WR_SUICIDEMESSAGE)
228                 w_deathtypestring = "did the impossible";
229         else if (req == WR_KILLMESSAGE)
230                 w_deathtypestring = "has run into #'s gravity bomb";
231         return TRUE;
232 };