]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_hook.qc
make hook bomb respect g_projectiles_newton_style
[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
9 void W_Hook_ExplodeThink (void)
10 {
11         float dt, dmg_remaining, dmg_remaining_next, f;
12
13         dt = time - self.teleport_time;
14         dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
15
16         f = self.dmg_last - dmg_remaining_next;
17         self.dmg_last = dmg_remaining_next;
18
19         RadiusDamage (self, self.owner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.owner, self.dmg_force * f, self.projectiledeathtype, world);
20         //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, self.dmg_force * f, self.projectiledeathtype, world);
21
22         if(dt < self.dmg_duration)
23                 self.nextthink = time + 0.05; // soon
24         else
25                 remove(self);
26 }
27
28 void W_Hook_Explode2 (void)
29 {
30         vector org2;
31
32         org2 = findbetterlocation (self.origin, 12);
33         pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
34         sound (self, CHAN_PROJECTILE, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
35
36         self.event_damage = SUB_Null;
37         self.touch = SUB_Null;
38
39         self.think = W_Hook_ExplodeThink;
40         self.nextthink = time;
41         self.dmg = cvar("g_balance_hook_secondary_damage");
42         self.dmg_edge = cvar("g_balance_hook_secondary_edgedamage");
43         self.dmg_radius = cvar("g_balance_hook_secondary_radius");
44         self.dmg_force = cvar("g_balance_hook_secondary_force");
45         self.dmg_power = cvar("g_balance_hook_secondary_power");
46         self.dmg_duration = cvar("g_balance_hook_secondary_duration");
47         self.teleport_time = time;
48         self.dmg_last = 1;
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, '25 6 -8', 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.effects = EF_LOWPRECISION;
73         gren.modelflags = MF_TRACER2;
74         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
75         setmodel(gren, "models/grenademodel.md3"); // precision set above // FIXME replace
76         setsize(gren, '0 0 0', '0 0 0');
77         setorigin(gren, w_shotorg);
78
79         gren.nextthink = time + cvar("g_balance_hook_secondary_lifetime");
80         gren.think = adaptor_think2use;
81         gren.use = W_Hook_Explode2;
82         gren.touch = W_Hook_Touch2;
83
84         gren.velocity = '0 0 1' * cvar("g_balance_hook_secondary_speed");
85         if(cvar("g_projectiles_newton_style"))
86                 gren.velocity = gren.velocity + self.velocity;
87
88         gren.gravity = cvar("g_balance_hook_secondary_gravity");
89         //W_SetupProjectileVelocity(gren); // just falling down!
90
91         gren.angles = '0 0 0';
92         gren.flags = FL_PROJECTILE;
93 }
94
95 void spawnfunc_weapon_hook (void)
96 {
97         if(g_grappling_hook) // offhand hook
98         {
99                 startitem_failed = TRUE;
100                 remove(self);
101                 return;
102         }
103         weapon_defaultspawnfunc(WEP_HOOK);
104 }
105
106 float w_hook(float req)
107 {
108         if (req == WR_AIM)
109         {
110                 // ... sorry ...
111         }
112         else if (req == WR_THINK)
113         {
114                 if (self.BUTTON_ATCK || self.BUTTON_HOOK)
115                 {
116                         if(!self.hook)
117                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
118                         if (weapon_prepareattack(0, cvar("g_balance_hook_primary_refire")))
119                         {
120                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
121                                         self.ammo_cells = self.ammo_cells - cvar("g_balance_hook_primary_ammo");
122                                 self.hook_state |= HOOK_FIRING;
123                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hook_primary_animtime"), w_ready);
124                         }
125                 }
126
127                 if (self.BUTTON_ATCK2)
128                 {
129                         if (weapon_prepareattack(1, cvar("g_balance_hook_secondary_refire")))
130                         {
131                                 W_Hook_Attack2();
132                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hook_secondary_animtime"), w_ready);
133                         }
134                 }
135
136                 if (self.BUTTON_CROUCH)
137                 {
138                         self.hook_state (-) HOOK_PULLING;
139                         if (self.BUTTON_ATCK || self.BUTTON_HOOK)
140                                 self.hook_state (-) HOOK_RELEASING;
141                         else
142                                 self.hook_state |= HOOK_RELEASING;
143                 }
144                 else
145                 {
146                         self.hook_state |= HOOK_PULLING;
147                         self.hook_state (-) HOOK_RELEASING;
148
149                         if (self.BUTTON_ATCK || self.BUTTON_HOOK)
150                         {
151                                 // already fired
152                                 if(self.hook)
153                                         self.hook_state |= HOOK_WAITING_FOR_RELEASE;
154                         }
155                         else
156                         {
157                                 self.hook_state |= HOOK_REMOVING;
158                                 self.hook_state (-) HOOK_WAITING_FOR_RELEASE;
159                         }
160                 }
161         }
162         else if (req == WR_PRECACHE)
163         {
164                 precache_model ("models/weapons/g_hookgun.md3");
165                 precache_model ("models/weapons/v_hookgun.md3");
166                 precache_model ("models/weapons/w_hookgun.zym");
167                 precache_sound ("weapons/hook_fire.wav");
168                 precache_sound ("weapons/hook_impact.wav");
169                 precache_sound ("weapons/hookbomb_fire.wav");
170                 precache_sound ("weapons/hookbomb_impact.wav");
171         }
172         else if (req == WR_SETUP)
173         {
174                 weapon_setup(WEP_HOOK);
175         }
176         else if (req == WR_CHECKAMMO1)
177         {
178                 return self.ammo_cells >= cvar("g_balance_hook_primary_ammo");
179         }
180         else if (req == WR_CHECKAMMO2)
181         {
182                 return self.ammo_cells >= cvar("g_balance_hook_secondary_ammo");
183         }
184         else if (req == WR_SUICIDEMESSAGE)
185                 w_deathtypestring = "did the impossible";
186         else if (req == WR_KILLMESSAGE)
187                 w_deathtypestring = "has run into #'s gravity bomb";
188         return TRUE;
189 };