]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_hook.qc
now all projectile hit effects are clientside
[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
37         self.think = W_Hook_ExplodeThink;
38         self.nextthink = time;
39         self.dmg = cvar("g_balance_hook_secondary_damage");
40         self.dmg_edge = cvar("g_balance_hook_secondary_edgedamage");
41         self.dmg_radius = cvar("g_balance_hook_secondary_radius");
42         self.dmg_force = cvar("g_balance_hook_secondary_force");
43         self.dmg_power = cvar("g_balance_hook_secondary_power");
44         self.dmg_duration = cvar("g_balance_hook_secondary_duration");
45         self.teleport_time = time;
46         self.dmg_last = 1;
47         self.movetype = MOVETYPE_NONE;
48 }
49
50 void W_Hook_Touch2 (void)
51 {
52         PROJECTILE_TOUCH;
53         self.use();
54 }
55
56 void W_Hook_Attack2()
57 {
58         local entity gren;
59
60         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
61                 self.ammo_cells = self.ammo_cells - cvar("g_balance_hook_secondary_ammo");
62         W_SetupShot (self, '25 6 -8', FALSE, 4, "weapons/hookbomb_fire.wav");
63
64         gren = spawn ();
65         gren.owner = self;
66         gren.classname = "hookbomb";
67         gren.bot_dodge = TRUE;
68         gren.bot_dodgerating = cvar("g_balance_hook_secondary_damage");
69         gren.movetype = MOVETYPE_TOSS;
70         gren.solid = SOLID_BBOX;
71         gren.effects = EF_LOWPRECISION;
72         gren.modelflags = MF_TRACER2;
73         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
74         setmodel(gren, "models/grenademodel.md3"); // precision set above // FIXME replace
75         setsize(gren, '0 0 0', '0 0 0');
76         setorigin(gren, w_shotorg);
77
78         gren.nextthink = time + cvar("g_balance_hook_secondary_lifetime");
79         gren.think = adaptor_think2use;
80         gren.use = W_Hook_Explode2;
81         gren.touch = W_Hook_Touch2;
82
83         gren.velocity = '0 0 1' * cvar("g_balance_hook_secondary_speed");
84         if(cvar("g_projectiles_newton_style"))
85                 gren.velocity = gren.velocity + self.velocity;
86
87         gren.gravity = cvar("g_balance_hook_secondary_gravity");
88         //W_SetupProjectileVelocity(gren); // just falling down!
89
90         gren.angles = '0 0 0';
91         gren.flags = FL_PROJECTILE;
92
93         CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB);
94 }
95
96 void spawnfunc_weapon_hook (void)
97 {
98         if(g_grappling_hook) // offhand hook
99         {
100                 startitem_failed = TRUE;
101                 remove(self);
102                 return;
103         }
104         weapon_defaultspawnfunc(WEP_HOOK);
105 }
106
107 float w_hook(float req)
108 {
109         float hooked_time_max, hooked_ammodecrease_delay;
110                 
111         if (req == WR_AIM)
112         {
113                 // ... sorry ...
114         }
115         else if (req == WR_THINK)
116         {
117                 if (self.BUTTON_ATCK || self.BUTTON_HOOK)
118                 {
119                         if(!self.hook)
120                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
121                         if (time > self.hook_refire)
122                         if (weapon_prepareattack(0, -1))
123                         {
124                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
125                                         self.ammo_cells = self.ammo_cells - cvar("g_balance_hook_primary_ammo");
126                                 self.hook_state |= HOOK_FIRING;
127                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hook_primary_animtime"), w_ready);                          
128                         }
129                 }
130
131                 if (self.BUTTON_ATCK2)
132                 {
133                         if (weapon_prepareattack(1, cvar("g_balance_hook_secondary_refire")))
134                         {
135                                 W_Hook_Attack2();
136                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hook_secondary_animtime"), w_ready);
137                         }
138                 }
139
140                 if(self.hook)
141                 {
142                         // if hooked, no bombs, and increase the timer
143                         self.hook_refire = max(self.hook_refire, time + cvar("g_balance_hook_primary_refire"));
144                 }
145
146                 if(self.hook && self.hook.state == 1)
147                 {
148                         hooked_time_max = cvar("g_balance_hook_primary_hooked_time_max");                       
149                         if (hooked_time_max > 0)
150                         {
151                                 if ( time > self.hook_time_hooked + hooked_time_max )
152                                         self.hook_state |= HOOK_REMOVING;
153                         }
154                         
155                         hooked_ammodecrease_delay = cvar("g_balance_hook_primary_hooked_ammodecrease_delay");
156                         if (hooked_ammodecrease_delay > 0)
157                         {
158                                 if ( time > self.hook_time_ammodecrease )
159                                 {
160                                         if ( self.ammo_cells >= 1 )
161                                         {
162                                                 self.ammo_cells -= 1;
163                                                 self.hook_time_ammodecrease = time + hooked_ammodecrease_delay;
164                                         }
165                                         else
166                                         {
167                                                 self.hook_state |= HOOK_REMOVING;
168                                                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
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.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 };