]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_hook.qc
hook: clear waiting for release flag
[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
10 void W_Hook_ExplodeThink (void)
11 {
12         float dt, dmg_remaining_next, f;
13
14         dt = time - self.teleport_time;
15         dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
16
17         f = self.dmg_last - dmg_remaining_next;
18         self.dmg_last = dmg_remaining_next;
19
20         RadiusDamage (self, self.owner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.owner, self.dmg_force * f, self.projectiledeathtype, world);
21         //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, self.dmg_force * f, self.projectiledeathtype, world);
22
23         if(dt < self.dmg_duration)
24                 self.nextthink = time + 0.05; // soon
25         else
26                 remove(self);
27 }
28
29 void W_Hook_Explode2 (void)
30 {
31         vector org2;
32
33         org2 = findbetterlocation (self.origin, 12);
34         pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
35         sound (self, CHAN_PROJECTILE, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
36
37         self.event_damage = SUB_Null;
38         self.touch = SUB_Null;
39
40         self.think = W_Hook_ExplodeThink;
41         self.nextthink = time;
42         self.dmg = cvar("g_balance_hook_secondary_damage");
43         self.dmg_edge = cvar("g_balance_hook_secondary_edgedamage");
44         self.dmg_radius = cvar("g_balance_hook_secondary_radius");
45         self.dmg_force = cvar("g_balance_hook_secondary_force");
46         self.dmg_power = cvar("g_balance_hook_secondary_power");
47         self.dmg_duration = cvar("g_balance_hook_secondary_duration");
48         self.teleport_time = time;
49         self.dmg_last = 1;
50         self.movetype = MOVETYPE_NONE;
51 }
52
53 void W_Hook_Touch2 (void)
54 {
55         PROJECTILE_TOUCH;
56         self.use();
57 }
58
59 void W_Hook_Attack2()
60 {
61         local entity gren;
62
63         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
64                 self.ammo_cells = self.ammo_cells - cvar("g_balance_hook_secondary_ammo");
65         W_SetupShot (self, '25 6 -8', FALSE, 4, "weapons/hookbomb_fire.wav");
66
67         gren = spawn ();
68         gren.owner = self;
69         gren.classname = "hookbomb";
70         gren.bot_dodge = TRUE;
71         gren.bot_dodgerating = cvar("g_balance_hook_secondary_damage");
72         gren.movetype = MOVETYPE_TOSS;
73         gren.solid = SOLID_BBOX;
74         gren.effects = EF_LOWPRECISION;
75         gren.modelflags = MF_TRACER2;
76         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
77         setmodel(gren, "models/grenademodel.md3"); // precision set above // FIXME replace
78         setsize(gren, '0 0 0', '0 0 0');
79         setorigin(gren, w_shotorg);
80
81         gren.nextthink = time + cvar("g_balance_hook_secondary_lifetime");
82         gren.think = adaptor_think2use;
83         gren.use = W_Hook_Explode2;
84         gren.touch = W_Hook_Touch2;
85
86         gren.velocity = '0 0 1' * cvar("g_balance_hook_secondary_speed");
87         if(cvar("g_projectiles_newton_style"))
88                 gren.velocity = gren.velocity + self.velocity;
89
90         gren.gravity = cvar("g_balance_hook_secondary_gravity");
91         //W_SetupProjectileVelocity(gren); // just falling down!
92
93         gren.angles = '0 0 0';
94         gren.flags = FL_PROJECTILE;
95 }
96
97 void spawnfunc_weapon_hook (void)
98 {
99         if(g_grappling_hook) // offhand hook
100         {
101                 startitem_failed = TRUE;
102                 remove(self);
103                 return;
104         }
105         weapon_defaultspawnfunc(WEP_HOOK);
106 }
107
108 float w_hook(float req)
109 {
110         if (req == WR_AIM)
111         {
112                 // ... sorry ...
113         }
114         else if (req == WR_THINK)
115         {
116                 if (self.BUTTON_ATCK || self.BUTTON_HOOK)
117                 {
118                         if(!self.hook)
119                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
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_cells = self.ammo_cells - cvar("g_balance_hook_primary_ammo");
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_FIRE1, 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
145                 if (self.BUTTON_CROUCH)
146                 {
147                         self.hook_state &~= HOOK_PULLING;
148                         if (self.BUTTON_ATCK || self.BUTTON_HOOK)
149                                 self.hook_state &~= HOOK_RELEASING;
150                         else
151                                 self.hook_state |= HOOK_RELEASING;
152                 }
153                 else
154                 {
155                         self.hook_state |= HOOK_PULLING;
156                         self.hook_state &~= HOOK_RELEASING;
157
158                         if (self.BUTTON_ATCK || self.BUTTON_HOOK)
159                         {
160                                 // already fired
161                                 if(self.hook)
162                                         self.hook_state |= HOOK_WAITING_FOR_RELEASE;
163                         }
164                         else
165                         {
166                                 self.hook_state |= HOOK_REMOVING;
167                                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
168                         }
169                 }
170         }
171         else if (req == WR_PRECACHE)
172         {
173                 precache_model ("models/weapons/g_hookgun.md3");
174                 precache_model ("models/weapons/v_hookgun.md3");
175                 precache_model ("models/weapons/w_hookgun.zym");
176                 precache_sound ("weapons/hook_fire.wav");
177                 precache_sound ("weapons/hook_impact.wav");
178                 precache_sound ("weapons/hookbomb_fire.wav");
179                 precache_sound ("weapons/hookbomb_impact.wav");
180         }
181         else if (req == WR_SETUP)
182         {
183                 weapon_setup(WEP_HOOK);
184                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
185         }
186         else if (req == WR_CHECKAMMO1)
187         {
188                 return self.ammo_cells >= cvar("g_balance_hook_primary_ammo");
189         }
190         else if (req == WR_CHECKAMMO2)
191         {
192                 return self.ammo_cells >= cvar("g_balance_hook_secondary_ammo");
193         }
194         else if (req == WR_SUICIDEMESSAGE)
195                 w_deathtypestring = "did the impossible";
196         else if (req == WR_KILLMESSAGE)
197                 w_deathtypestring = "has run into #'s gravity bomb";
198         return TRUE;
199 };