]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_hook.qc
do less audio spam for triggers that don't even respond to players
[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         //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_time_hooked + 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_time_ammodecrease )
162                                 {
163                                         if ( self.ammo_cells >= 1 )
164                                         {
165                                                 self.ammo_cells -= 1;
166                                                 self.hook_time_ammodecrease = time + hooked_ammodecrease_delay;
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                 {
178                         self.hook_time_hooked = time;                           
179                         self.hook_time_ammodecrease = time + cvar("g_balance_hook_primary_hooked_time_free");
180                 }
181
182                 if (self.BUTTON_CROUCH)
183                 {
184                         self.hook_state &~= HOOK_PULLING;
185                         if (self.BUTTON_ATCK || self.BUTTON_HOOK)
186                                 self.hook_state &~= HOOK_RELEASING;
187                         else
188                                 self.hook_state |= HOOK_RELEASING;
189                 }
190                 else
191                 {
192                         self.hook_state |= HOOK_PULLING;
193                         self.hook_state &~= HOOK_RELEASING;
194
195                         if (self.BUTTON_ATCK || self.BUTTON_HOOK)
196                         {
197                                 // already fired
198                                 if(self.hook)
199                                         self.hook_state |= HOOK_WAITING_FOR_RELEASE;
200                         }
201                         else
202                         {
203                                 self.hook_state |= HOOK_REMOVING;
204                                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
205                         }
206                 }
207         }
208         else if (req == WR_PRECACHE)
209         {
210                 precache_model ("models/weapons/g_hookgun.md3");
211                 precache_model ("models/weapons/v_hookgun.md3");
212                 precache_model ("models/weapons/w_hookgun.zym");
213                 precache_sound ("weapons/hook_fire.wav");
214                 precache_sound ("weapons/hook_impact.wav");
215                 precache_sound ("weapons/hookbomb_fire.wav");
216                 precache_sound ("weapons/hookbomb_impact.wav");
217         }
218         else if (req == WR_SETUP)
219         {
220                 weapon_setup(WEP_HOOK);
221                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
222         }
223         else if (req == WR_CHECKAMMO1)
224         {
225                 return self.ammo_cells >= cvar("g_balance_hook_primary_ammo");                  
226         }
227         else if (req == WR_CHECKAMMO2)
228         {
229                 return self.ammo_cells >= cvar("g_balance_hook_secondary_ammo");
230         }
231         else if (req == WR_SUICIDEMESSAGE)
232                 w_deathtypestring = "did the impossible";
233         else if (req == WR_KILLMESSAGE)
234                 w_deathtypestring = "has run into #'s gravity bomb";
235         return TRUE;
236 };