]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_hook.qc
use DP_QC_TOKENIZE_CONSOLE if available
[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_datehooked;
10 .float hook_datehooked_delay;
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         //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, self.dmg_force * f, self.projectiledeathtype, world);
24
25         if(dt < self.dmg_duration)
26                 self.nextthink = time + 0.05; // soon
27         else
28                 remove(self);
29 }
30
31 void W_Hook_Explode2 (void)
32 {
33         vector org2;
34
35         org2 = findbetterlocation (self.origin, 12);
36         pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
37         sound (self, CHAN_PROJECTILE, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
38
39         self.event_damage = SUB_Null;
40         self.touch = SUB_Null;
41
42         self.think = W_Hook_ExplodeThink;
43         self.nextthink = time;
44         self.dmg = cvar("g_balance_hook_secondary_damage");
45         self.dmg_edge = cvar("g_balance_hook_secondary_edgedamage");
46         self.dmg_radius = cvar("g_balance_hook_secondary_radius");
47         self.dmg_force = cvar("g_balance_hook_secondary_force");
48         self.dmg_power = cvar("g_balance_hook_secondary_power");
49         self.dmg_duration = cvar("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         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
66                 self.ammo_cells = self.ammo_cells - cvar("g_balance_hook_secondary_ammo");
67         W_SetupShot (self, '25 6 -8', FALSE, 4, "weapons/hookbomb_fire.wav");
68
69         gren = spawn ();
70         gren.owner = self;
71         gren.classname = "hookbomb";
72         gren.bot_dodge = TRUE;
73         gren.bot_dodgerating = cvar("g_balance_hook_secondary_damage");
74         gren.movetype = MOVETYPE_TOSS;
75         gren.solid = SOLID_BBOX;
76         gren.effects = EF_LOWPRECISION;
77         gren.modelflags = MF_TRACER2;
78         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
79         setmodel(gren, "models/grenademodel.md3"); // precision set above // FIXME replace
80         setsize(gren, '0 0 0', '0 0 0');
81         setorigin(gren, w_shotorg);
82
83         gren.nextthink = time + cvar("g_balance_hook_secondary_lifetime");
84         gren.think = adaptor_think2use;
85         gren.use = W_Hook_Explode2;
86         gren.touch = W_Hook_Touch2;
87
88         gren.velocity = '0 0 1' * cvar("g_balance_hook_secondary_speed");
89         if(cvar("g_projectiles_newton_style"))
90                 gren.velocity = gren.velocity + self.velocity;
91
92         gren.gravity = cvar("g_balance_hook_secondary_gravity");
93         //W_SetupProjectileVelocity(gren); // just falling down!
94
95         gren.angles = '0 0 0';
96         gren.flags = FL_PROJECTILE;
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_ammodecrease_delay;
113                 
114         if (req == WR_AIM)
115         {
116                 // ... sorry ...
117         }
118         else if (req == WR_THINK)
119         {
120                 if (self.BUTTON_ATCK || self.BUTTON_HOOK)
121                 {
122                         if(!self.hook)
123                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
124                         if (time > self.hook_refire)
125                         if (weapon_prepareattack(0, -1))
126                         {
127                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
128                                         self.ammo_cells = self.ammo_cells - cvar("g_balance_hook_primary_ammo");
129                                 self.hook_state |= HOOK_FIRING;
130                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hook_primary_animtime"), w_ready);                          
131                         }
132                 }
133
134                 if (self.BUTTON_ATCK2)
135                 {
136                         if (weapon_prepareattack(1, cvar("g_balance_hook_secondary_refire")))
137                         {
138                                 W_Hook_Attack2();
139                                 weapon_thinkf(WFRAME_FIRE1, cvar("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 + cvar("g_balance_hook_primary_refire"));
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_datehooked + hooked_time_max )
155                                         self.hook_state |= HOOK_REMOVING;
156                         }
157                         
158                         hooked_ammodecrease_delay = cvar("g_balance_hook_primary_hooked_ammodecrease_delay");
159                         if (hooked_ammodecrease_delay > 0)
160                         {
161                                 if ( time > self.hook_datehooked_delay + hooked_ammodecrease_delay )
162                                 {
163                                         if ( self.ammo_cells >= 1 )
164                                         {
165                                                 self.ammo_cells -= 1;
166                                                 self.hook_datehooked_delay = time;
167                                         }
168                                         else
169                                         {
170                                                 self.hook_state |= HOOK_REMOVING;
171                                                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
172                                         }
173                                 }
174                         }
175                 }
176                 else
177                         self.hook_datehooked = self.hook_datehooked_delay = time;                               
178
179                 if (self.BUTTON_CROUCH)
180                 {
181                         self.hook_state &~= HOOK_PULLING;
182                         if (self.BUTTON_ATCK || 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.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/w_hookgun.zym");
210                 precache_sound ("weapons/hook_fire.wav");
211                 precache_sound ("weapons/hook_impact.wav");
212                 precache_sound ("weapons/hookbomb_fire.wav");
213                 precache_sound ("weapons/hookbomb_impact.wav");
214         }
215         else if (req == WR_SETUP)
216         {
217                 weapon_setup(WEP_HOOK);
218                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
219         }
220         else if (req == WR_CHECKAMMO1)
221         {
222                 return self.ammo_cells >= cvar("g_balance_hook_primary_ammo");                  
223         }
224         else if (req == WR_CHECKAMMO2)
225         {
226                 return self.ammo_cells >= cvar("g_balance_hook_secondary_ammo");
227         }
228         else if (req == WR_SUICIDEMESSAGE)
229                 w_deathtypestring = "did the impossible";
230         else if (req == WR_KILLMESSAGE)
231                 w_deathtypestring = "has run into #'s gravity bomb";
232         return TRUE;
233 };