r4787 - trunk/data/qcsrc/server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sun Oct 19 15:08:33 EDT 2008
Author: div0
Date: 2008-10-19 15:08:32 -0400 (Sun, 19 Oct 2008)
New Revision: 4787
Added:
trunk/data/qcsrc/server/g_hook.qh
Modified:
trunk/data/qcsrc/server/defs.qh
trunk/data/qcsrc/server/g_hook.qc
trunk/data/qcsrc/server/progs.src
Log:
hook code cleanup. Should simplify a later change to an onhand hook.
Modified: trunk/data/qcsrc/server/defs.qh
===================================================================
--- trunk/data/qcsrc/server/defs.qh 2008-10-18 22:00:50 UTC (rev 4786)
+++ trunk/data/qcsrc/server/defs.qh 2008-10-19 19:08:32 UTC (rev 4787)
@@ -255,17 +255,6 @@
void VoteStop(entity stopper);
void VoteCount();
-// Wazat's grappling hook
-.entity hook;
-void GrapplingHookFrame();
-void RemoveGrapplingHook(entity pl);
-void SetGrappleHookBindings();
-// hook impulses
-float GRAPHOOK_FIRE = 20;
-float GRAPHOOK_RELEASE = 21;
-// (note: you can change the hook impulse #'s to whatever you please)
-.float hook_time;
-
// Laser target for laser-guided weapons
.entity lasertarget;
.float laser_on;
Modified: trunk/data/qcsrc/server/g_hook.qc
===================================================================
--- trunk/data/qcsrc/server/g_hook.qc 2008-10-18 22:00:50 UTC (rev 4786)
+++ trunk/data/qcsrc/server/g_hook.qc 2008-10-19 19:08:32 UTC (rev 4787)
@@ -83,8 +83,7 @@
return 0;
}
-.float rope_length;
-.float button6_pressed_before;
+.float hook_length;
void RemoveGrapplingHook(entity pl)
{
@@ -95,8 +94,6 @@
if(pl.movetype == MOVETYPE_FLY)
pl.movetype = MOVETYPE_WALK;
- pl.hook_time = time + 0.0;
-
//pl.disableclientprediction = FALSE;
}
@@ -112,7 +109,7 @@
self.touch = SUB_Null;
self.velocity = '0 0 0';
self.movetype = MOVETYPE_NONE;
- self.rope_length = -1;
+ self.hook_length = -1;
}
void GrapplingHookThink()
@@ -160,8 +157,8 @@
}
#endif
- if(self.rope_length < 0)
- self.rope_length = vlen(org - self.origin);
+ if(self.hook_length < 0)
+ self.hook_length = vlen(org - self.origin);
if(self.state == 1)
{
@@ -192,38 +189,50 @@
if(cvar("g_grappling_hook_tarzan"))
{
- newlength = self.rope_length;
v0 = self.owner.velocity;
// first pull the rope...
- newlength = max(newlength - pullspeed * frametime, minlength);
-
- if(newlength < dist - ropestretch) // overstretched?
+ if(self.owner.hook_state & HOOK_PULLING)
{
- newlength = dist - ropestretch;
- if(self.owner.velocity * dir < 0) // only if not already moving in hook direction
- self.owner.velocity = self.owner.velocity + frametime * dir * rubberforce_overstretch;
- }
+ newlength = self.hook_length;
+ newlength = max(newlength - pullspeed * frametime, minlength);
- if(!self.owner.BUTTON_CROUCH) // crouch key = don't pull
- self.rope_length = newlength;
+ if(newlength < dist - ropestretch) // overstretched?
+ {
+ newlength = dist - ropestretch;
+ if(self.owner.velocity * dir < 0) // only if not already moving in hook direction
+ self.owner.velocity = self.owner.velocity + frametime * dir * rubberforce_overstretch;
+ }
- // then pull the player
- spd = bound(0, (dist - self.rope_length) / ropestretch, 1);
- self.owner.velocity = self.owner.velocity * (1 - frametime * ropeairfriction);
- self.owner.velocity = self.owner.velocity + frametime * dir * spd * rubberforce;
+ self.hook_length = newlength;
+ }
- dv = ((self.owner.velocity - v0) * dir) * dir;
- if(cvar("g_grappling_hook_tarzan") >= 2)
+ if(self.owner.hook_state & HOOK_RELEASING)
{
- if(self.aiment.movetype == MOVETYPE_WALK || self.aiment.movetype == MOVETYPE_TOSS)
+ newlength = dist;
+ self.hook_length = newlength;
+ }
+ else
+ {
+ // then pull the player
+ spd = bound(0, (dist - self.hook_length) / ropestretch, 1);
+ self.owner.velocity = self.owner.velocity * (1 - frametime * ropeairfriction);
+ self.owner.velocity = self.owner.velocity + frametime * dir * spd * rubberforce;
+
+ dv = ((self.owner.velocity - v0) * dir) * dir;
+ if(cvar("g_grappling_hook_tarzan") >= 2)
{
- self.owner.velocity = self.owner.velocity - dv * 0.5;
- self.aiment.velocity = self.aiment.velocity - dv * 0.5;
- self.aiment.flags = self.aiment.flags - (self.aiment.flags & FL_ONGROUND);
- self.aiment.pusher = self.owner;
- self.aiment.pushltime = time + cvar("g_maxpushtime");
+ if(self.aiment.movetype == MOVETYPE_WALK || self.aiment.movetype == MOVETYPE_TOSS)
+ {
+ self.owner.velocity = self.owner.velocity - dv * 0.5;
+ self.aiment.velocity = self.aiment.velocity - dv * 0.5;
+ self.aiment.flags = self.aiment.flags - (self.aiment.flags & FL_ONGROUND);
+ self.aiment.pusher = self.owner;
+ self.aiment.pushltime = time + cvar("g_maxpushtime");
+ }
}
+
+ self.owner.flags (-) FL_ONGROUND;
}
}
else
@@ -238,10 +247,10 @@
spd = 0;
self.owner.velocity = dir*spd;
self.owner.movetype = MOVETYPE_FLY;
+
+ self.owner.flags (-) FL_ONGROUND;
}
- self.owner.flags = self.owner.flags - (self.owner.flags & FL_ONGROUND);
-
org = org + dir*50; // get the beam out of the player's eyes
}
@@ -352,21 +361,76 @@
missile.damageforcescale = 0;
}
+// void GrapplingHookFrame()
+// {
+// // this function has been modified for Nexuiz
+// - if (self.BUTTON_HOOK && g_grappling_hook)
+// {
+// - if (!self.hook && self.hook_time <= time && !self.button6_pressed_before)
+// - if (timeoutStatus != 2) //only allow the player to fire the grappling hook if the game is not paused (timeout)
+// - FireGrapplingHook();
+// }
+// - else
+// {
+// if (self.hook)
+// RemoveGrapplingHook(self);
+// }
+// - self.button6_pressed_before = self.BUTTON_HOOK;
+// /*
+// // if I have no hook or it's not pulling yet, make sure I'm not flying!
+// if((self.hook == world || !self.hook.state) && self.movetype == MOVETYPE_FLY)
+
void GrapplingHookFrame()
{
- // this function has been modified for Nexuiz
- if (self.BUTTON_HOOK && g_grappling_hook)
+ if(g_grappling_hook && timeoutStatus != 2)
{
- if (!self.hook && self.hook_time <= time && !self.button6_pressed_before)
- if (timeoutStatus != 2) //only allow the player to fire the grappling hook if the game is not paused (timeout)
- FireGrapplingHook();
+ // offhand hook controls
+ if(self.BUTTON_HOOK)
+ {
+ if not(self.hook || (self.hook_state & HOOK_WAITING_FOR_REFIRE))
+ {
+ self.hook_state |= HOOK_FIRING;
+ self.hook_state |= HOOK_PULLING;
+ self.hook_state (-) HOOK_RELEASING;
+ self.hook_state |= HOOK_WAITING_FOR_REFIRE;
+ }
+ }
+ else
+ {
+ if(self.hook)
+ {
+ self.hook_state |= HOOK_REMOVING;
+ self.hook_state (-) HOOK_PULLING;
+ self.hook_state (-) HOOK_RELEASING;
+ self.hook_state (-) HOOK_WAITING_FOR_REFIRE;
+ }
+ }
+
+ if(self.BUTTON_CROUCH)
+ {
+ self.hook_state (-) HOOK_PULLING;
+ self.hook_state |= HOOK_RELEASING;
+ }
+ else
+ {
+ self.hook_state |= HOOK_PULLING;
+ self.hook_state (-) HOOK_RELEASING;
+ }
}
- else
+
+ if (self.hook_state & HOOK_FIRING)
{
if (self.hook)
RemoveGrapplingHook(self);
+ FireGrapplingHook();
+ self.hook_state (-) HOOK_FIRING;
}
- self.button6_pressed_before = self.BUTTON_HOOK;
+ else if(self.hook_state & HOOK_REMOVING)
+ {
+ if (self.hook)
+ RemoveGrapplingHook(self);
+ self.hook_state (-) HOOK_REMOVING;
+ }
/*
// if I have no hook or it's not pulling yet, make sure I'm not flying!
if((self.hook == world || !self.hook.state) && self.movetype == MOVETYPE_FLY)
Added: trunk/data/qcsrc/server/g_hook.qh
===================================================================
--- trunk/data/qcsrc/server/g_hook.qh (rev 0)
+++ trunk/data/qcsrc/server/g_hook.qh 2008-10-19 19:08:32 UTC (rev 4787)
@@ -0,0 +1,14 @@
+// Wazat's grappling hook
+.entity hook;
+void GrapplingHookFrame();
+void RemoveGrapplingHook(entity pl);
+void SetGrappleHookBindings();
+// (note: you can change the hook impulse #'s to whatever you please)
+.float hook_time;
+
+float HOOK_FIRING = 1;
+float HOOK_REMOVING = 2;
+float HOOK_PULLING = 4;
+float HOOK_RELEASING = 8;
+float HOOK_WAITING_FOR_REFIRE = 16;
+.float hook_state;
Modified: trunk/data/qcsrc/server/progs.src
===================================================================
--- trunk/data/qcsrc/server/progs.src 2008-10-18 22:00:50 UTC (rev 4786)
+++ trunk/data/qcsrc/server/progs.src 2008-10-19 19:08:32 UTC (rev 4787)
@@ -19,6 +19,8 @@
portals.qh
+g_hook.qh
+
scores.qh
ipban.qh
More information about the nexuiz-commits
mailing list