move box dragging to cheats.qc too
authordiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Mon, 25 Jan 2010 17:04:09 +0000 (17:04 +0000)
committerdiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Mon, 25 Jan 2010 17:04:09 +0000 (17:04 +0000)
git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8552 f962a42d-fe04-0410-a3ab-8c8b0445ebaa

data/qcsrc/server/cheats.qc
data/qcsrc/server/cheats.qh
data/qcsrc/server/cl_client.qc

index 04f78c4..51a0785 100644 (file)
@@ -12,7 +12,9 @@ float autocvar_sv_cheats;
 #define CHIMPULSE_TELEPORT 143
 #define CHIMPULSE_R00T 148
 
-float CheatsAllowed(float i, float argc) // the cheat gets passed as argument for possible future ACL checking
+#define CHRAME_DRAG 1
+
+float CheatsAllowed(float i, float argc, float fr) // the cheat gets passed as argument for possible future ACL checking
 {
        if(i == CHIMPULSE_CLONE_MOVING || i == CHIMPULSE_CLONE_STANDING)
                if(self.lip < sv_clones)
@@ -28,7 +30,7 @@ float CheatsAllowed(float i, float argc) // the cheat gets passed as argument fo
 
 float CheatImpulse(float i)
 {
-       if not(CheatsAllowed(i, 0))
+       if not(CheatsAllowed(i, 0, 0))
                return 0;
        switch(i)
        {
@@ -208,7 +210,7 @@ float CheatImpulse(float i)
 
 float CheatCommand(float argc)
 {
-       if not(CheatsAllowed(0, argc))
+       if not(CheatsAllowed(0, argc, 0))
                return 0;
        string cmd;
        cmd = argv(0);
@@ -526,3 +528,251 @@ float CheatCommand(float argc)
        }
        return 0;
 }
+
+void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
+void Drag_Finish(entity dragger);
+float Drag_IsDraggable(entity draggee);
+float Drag_MayChangeAngles(entity draggee);
+void Drag_MoveForward(entity dragger);
+void Drag_SetSpeed(entity dragger, float s);
+void Drag_MoveBackward(entity dragger);
+void Drag_Update(entity dragger);
+float Drag_CanDrag(entity dragger);
+float Drag_IsDragging(entity dragger);
+void Drag_MoveDrag(entity from, entity to);
+.entity dragentity;
+
+float CheatFrame()
+{
+       float cheating;
+       cheating = 0;
+
+       if(CheatsAllowed(0, 0, CHRAME_DRAG))
+               if(Drag_CanDrag(self))
+                       if(self.BUTTON_DRAG)
+                               if(!self.dragentity)
+                                       if(self.cursor_trace_ent)
+                                               if(Drag_IsDraggable(self.cursor_trace_ent))
+                                               {
+                                                       if(self.cursor_trace_ent.draggedby)
+                                                               Drag_Finish(self.cursor_trace_ent.draggedby);
+                                                       if(self.cursor_trace_ent.tag_entity)
+                                                               detach_sameorigin(self.cursor_trace_ent);
+                                                       Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
+                                                       ++cheating;
+                                               }
+       if(Drag_IsDragging(self))
+       {
+               if(self.BUTTON_DRAG)
+               {
+                       if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
+                       {
+                               Drag_MoveForward(self);
+                               self.impulse = 0;
+                       }
+                       else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
+                       {
+                               Drag_MoveBackward(self);
+                               self.impulse = 0;
+                       }
+                       else if(self.impulse >= 1 && self.impulse <= 9)
+                       {
+                               Drag_SetSpeed(self, self.impulse - 1);
+                       }
+                       else if(self.impulse == 14)
+                       {
+                               Drag_SetSpeed(self, 9);
+                       }
+
+                       if(frametime)
+                               Drag_Update(self);
+               }
+               else
+               {
+                       Drag_Finish(self);
+               }
+       }
+
+       return cheating;
+}
+
+
+
+
+
+// ENTITY DRAGGING
+
+// on dragger:
+.float draggravity;
+.float dragspeed; // speed of mouse wheel action
+.float dragdistance; // distance of dragentity's draglocalvector from view_ofs
+.vector draglocalvector; // local attachment vector of the dragentity
+.float draglocalangle;
+// on draggee:
+.entity draggedby;
+.float dragmovetype;
+void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
+{
+       float tagscale;
+
+       draggee.dragmovetype = draggee.movetype;
+       draggee.draggravity = draggee.gravity;
+       draggee.movetype = MOVETYPE_WALK;
+       draggee.gravity = 0.00001;
+       draggee.flags &~= FL_ONGROUND;
+       draggee.draggedby = dragger;
+
+       dragger.dragentity = draggee;
+
+       dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
+       dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
+       touchpoint = touchpoint - gettaginfo(draggee, 0);
+       tagscale = pow(vlen(v_forward), -2);
+       dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
+       dragger.draglocalvector_y = touchpoint * v_right * tagscale;
+       dragger.draglocalvector_z = touchpoint * v_up * tagscale;
+
+       dragger.dragspeed = 64;
+}
+
+void Drag_Finish(entity dragger)
+{
+       entity draggee;
+       draggee = dragger.dragentity;
+       if(dragger)
+               dragger.dragentity = world;
+       draggee.draggedby = world;
+       draggee.movetype = draggee.dragmovetype;
+       draggee.gravity = draggee.draggravity;
+
+       switch(draggee.movetype)
+       {
+               case MOVETYPE_TOSS:
+               case MOVETYPE_WALK:
+               case MOVETYPE_STEP:
+               case MOVETYPE_FLYMISSILE:
+               case MOVETYPE_BOUNCE:
+               case MOVETYPE_BOUNCEMISSILE:
+               case MOVETYPE_PHYSICS:
+                       break;
+               default:
+                       draggee.velocity = '0 0 0';
+                       break;
+       }
+
+       if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
+       {
+               draggee.velocity = '0 0 0';
+               draggee.flags |= FL_ONGROUND; // floating items are FUN
+       }
+}
+
+float Drag_IsDraggable(entity draggee)
+{
+       // TODO add more checks for bad stuff here
+       if(draggee.classname == "func_bobbing")
+               return FALSE;
+       if(draggee.classname == "door") // FIXME find out why these must be excluded, or work around the problem (trying to drag these causes like 4 fps)
+               return FALSE;
+       if(draggee.classname == "plat")
+               return FALSE;
+       if(draggee.classname == "func_button")
+               return FALSE;
+       if(draggee.model == "")
+               return FALSE;
+       if(draggee.classname == "spectator")
+               return FALSE;
+       if(draggee.classname == "observer")
+               return FALSE;
+       if(draggee.classname == "exteriorweaponentity")
+               return FALSE;
+
+       return TRUE;
+}
+
+float Drag_MayChangeAngles(entity draggee)
+{
+       // TODO add more checks for bad stuff here
+       if(substring(draggee.model, 0, 1) == "*")
+               return FALSE;
+       return TRUE;
+}
+
+void Drag_MoveForward(entity dragger)
+{
+       dragger.dragdistance += dragger.dragspeed;
+}
+
+void Drag_SetSpeed(entity dragger, float s)
+{
+       dragger.dragspeed = pow(2, s);
+}
+
+void Drag_MoveBackward(entity dragger)
+{
+       dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
+}
+
+void Drag_Update(entity dragger)
+{
+       vector curorigin, neworigin, goodvelocity;
+       float f;
+       entity draggee;
+
+       draggee = dragger.dragentity;
+       draggee.flags &~= FL_ONGROUND;
+
+       curorigin = gettaginfo(draggee, 0);
+       curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
+       makevectors(dragger.v_angle);
+       neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
+       goodvelocity = (neworigin - curorigin) * (1 / frametime);
+
+       while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
+               dragger.draglocalangle += 360;
+       while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
+               dragger.draglocalangle -= 360;
+
+       f = min(frametime * 10, 1);
+       draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
+
+       if(Drag_MayChangeAngles(draggee))
+               draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
+
+       draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
+
+       te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
+}
+
+float Drag_CanDrag(entity dragger)
+{
+       return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
+}
+
+float Drag_IsDragging(entity dragger)
+{
+       if(!dragger.dragentity)
+               return FALSE;
+       if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
+       {
+               dragger.dragentity = world;
+               return FALSE;
+       }
+       if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
+       {
+               Drag_Finish(dragger);
+               return FALSE;
+       }
+       return TRUE;
+}
+
+void Drag_MoveDrag(entity from, entity to)
+{
+       if(from.draggedby)
+       {
+               to.draggedby = from.draggedby;
+               to.draggedby.dragentity = to;
+               from.draggedby = world;
+       }
+}
+
index b3baa4a..863ffb2 100644 (file)
@@ -1,2 +1,3 @@
 float CheatImpulse(float i);
 float CheatCommand(float argc);
+float CheatFrame();
index ed5488c..d566911 100644 (file)
@@ -2727,181 +2727,6 @@ void PlayerPreThink (void)
        target_voicescript_next(self);
 }
 
-// on dragger:
-.entity dragentity;
-.float draggravity;
-.float dragspeed; // speed of mouse wheel action
-.float dragdistance; // distance of dragentity's draglocalvector from view_ofs
-.vector draglocalvector; // local attachment vector of the dragentity
-.float draglocalangle;
-// on draggee:
-.entity draggedby;
-.float dragmovetype;
-void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
-{
-       float tagscale;
-
-       draggee.dragmovetype = draggee.movetype;
-       draggee.draggravity = draggee.gravity;
-       draggee.movetype = MOVETYPE_WALK;
-       draggee.gravity = 0.00001;
-       draggee.flags &~= FL_ONGROUND;
-       draggee.draggedby = dragger;
-
-       dragger.dragentity = draggee;
-
-       dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
-       dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
-       touchpoint = touchpoint - gettaginfo(draggee, 0);
-       tagscale = pow(vlen(v_forward), -2);
-       dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
-       dragger.draglocalvector_y = touchpoint * v_right * tagscale;
-       dragger.draglocalvector_z = touchpoint * v_up * tagscale;
-
-       dragger.dragspeed = 64;
-}
-
-void Drag_Finish(entity dragger)
-{
-       entity draggee;
-       draggee = dragger.dragentity;
-       if(dragger)
-               dragger.dragentity = world;
-       draggee.draggedby = world;
-       draggee.movetype = draggee.dragmovetype;
-       draggee.gravity = draggee.draggravity;
-
-       switch(draggee.movetype)
-       {
-               case MOVETYPE_TOSS:
-               case MOVETYPE_WALK:
-               case MOVETYPE_STEP:
-               case MOVETYPE_FLYMISSILE:
-               case MOVETYPE_BOUNCE:
-               case MOVETYPE_BOUNCEMISSILE:
-               case MOVETYPE_PHYSICS:
-                       break;
-               default:
-                       draggee.velocity = '0 0 0';
-                       break;
-       }
-
-       if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
-       {
-               draggee.velocity = '0 0 0';
-               draggee.flags |= FL_ONGROUND; // floating items are FUN
-       }
-}
-
-float Drag_IsDraggable(entity draggee)
-{
-       // TODO add more checks for bad stuff here
-       if(draggee.classname == "func_bobbing")
-               return FALSE;
-       if(draggee.classname == "door") // FIXME find out why these must be excluded, or work around the problem (trying to drag these causes like 4 fps)
-               return FALSE;
-       if(draggee.classname == "plat")
-               return FALSE;
-       if(draggee.classname == "func_button")
-               return FALSE;
-       if(draggee.model == "")
-               return FALSE;
-       if(draggee.classname == "spectator")
-               return FALSE;
-       if(draggee.classname == "observer")
-               return FALSE;
-       if(draggee.classname == "exteriorweaponentity")
-               return FALSE;
-
-       return TRUE;
-}
-
-float Drag_MayChangeAngles(entity draggee)
-{
-       // TODO add more checks for bad stuff here
-       if(substring(draggee.model, 0, 1) == "*")
-               return FALSE;
-       return TRUE;
-}
-
-void Drag_MoveForward(entity dragger)
-{
-       dragger.dragdistance += dragger.dragspeed;
-}
-
-void Drag_SetSpeed(entity dragger, float s)
-{
-       dragger.dragspeed = pow(2, s);
-}
-
-void Drag_MoveBackward(entity dragger)
-{
-       dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
-}
-
-void Drag_Update(entity dragger)
-{
-       vector curorigin, neworigin, goodvelocity;
-       float f;
-       entity draggee;
-
-       draggee = dragger.dragentity;
-       draggee.flags &~= FL_ONGROUND;
-
-       curorigin = gettaginfo(draggee, 0);
-       curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
-       makevectors(dragger.v_angle);
-       neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
-       goodvelocity = (neworigin - curorigin) * (1 / frametime);
-
-       while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
-               dragger.draglocalangle += 360;
-       while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
-               dragger.draglocalangle -= 360;
-
-       f = min(frametime * 10, 1);
-       draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
-
-       if(Drag_MayChangeAngles(draggee))
-               draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
-
-       draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
-
-       te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
-}
-
-float Drag_CanDrag(entity dragger)
-{
-       return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
-}
-
-float Drag_IsDragging(entity dragger)
-{
-       if(!dragger.dragentity)
-               return FALSE;
-       if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
-       {
-               dragger.dragentity = world;
-               return FALSE;
-       }
-       if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
-       {
-               Drag_Finish(dragger);
-               return FALSE;
-       }
-       return TRUE;
-}
-
-void Drag_MoveDrag(entity from, entity to)
-{
-       if(from.draggedby)
-       {
-               to.draggedby = from.draggedby;
-               to.draggedby.dragentity = to;
-               from.draggedby = world;
-       }
-}
-
 float isInvisibleString(string s)
 {
        float i, n, c;
@@ -2991,51 +2816,7 @@ void PlayerPostThink (void)
                return;
 #endif
 
-       if(sv_cheats || self.maycheat)
-               if(Drag_CanDrag(self))
-                       if(self.BUTTON_DRAG)
-                               if(!self.dragentity)
-                                       if(self.cursor_trace_ent)
-                                               if(Drag_IsDraggable(self.cursor_trace_ent))
-                                               {
-                                                       if(self.cursor_trace_ent.draggedby)
-                                                               Drag_Finish(self.cursor_trace_ent.draggedby);
-                                                       if(self.cursor_trace_ent.tag_entity)
-                                                               detach_sameorigin(self.cursor_trace_ent);
-                                                       Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
-                                               }
-
-       if(Drag_IsDragging(self))
-       {
-               if(self.BUTTON_DRAG)
-               {
-                       if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
-                       {
-                               Drag_MoveForward(self);
-                               self.impulse = 0;
-                       }
-                       else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
-                       {
-                               Drag_MoveBackward(self);
-                               self.impulse = 0;
-                       }
-                       else if(self.impulse >= 1 && self.impulse <= 9)
-                       {
-                               Drag_SetSpeed(self, self.impulse - 1);
-                       }
-                       else if(self.impulse == 14)
-                       {
-                               Drag_SetSpeed(self, 9);
-                       }
-
-                       if(frametime)
-                               Drag_Update(self);
-               }
-               else
-               {
-                       Drag_Finish(self);
-               }
-       }
+       CheatFrame();
 
        if(self.classname == "player") {
                CheckRules_Player();