fix multiple bugs in sandbox code regarding sv_cheats
authorRudolf Polzer <divverent@xonotic.org>
Sun, 4 Dec 2011 15:59:10 +0000 (16:59 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Sun, 4 Dec 2011 15:59:10 +0000 (16:59 +0100)
qcsrc/server/cheats.qc
qcsrc/server/cheats.qh

index d2a21ed..c03ea7a 100644 (file)
@@ -664,7 +664,7 @@ float CheatCommand(float argc)
        END_CHEAT_FUNCTION();
 }
 
-float Drag(entity e, float grab);
+float Drag(entity e, float grab, float ischeat);
 void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
 void Drag_Finish(entity dragger);
 float Drag_IsDraggable(entity draggee);
@@ -690,13 +690,11 @@ float CheatFrame()
        switch(0)
        {
                default:
-                       if(autocvar_sv_cheats)
+                       if(self.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
                        {
                                // use cheat dragging if cheats are enabled
-                               IS_CHEAT(0, 0, CHRAME_DRAG);
                                crosshair_trace_plusvisibletriggers(self);
-                               if(Drag(trace_ent, TRUE))
-                                       DID_CHEAT();
+                               Drag(trace_ent, TRUE, TRUE);
                        }
                        else
                        {
@@ -726,7 +724,7 @@ float CheatFrame()
                                        default:
                                                break;
                                }
-                               Drag(trace_ent, drag); // execute dragging
+                               Drag(trace_ent, drag, FALSE); // execute dragging
                        }
                        break;
        }
@@ -740,59 +738,70 @@ float CheatFrame()
 
 // ENTITY DRAGGING
 
-float Drag(entity e, float pick)
+float Drag(entity e, float pick, float ischeat)
 {
+       BEGIN_CHEAT_FUNCTION();
+
        // returns TRUE when an entity has been picked up
        // If pick is TRUE, the object can also be picked up if it's not being held already
        // If pick is FALSE, only keep dragging the object if it's already being held
 
-       if(Drag_IsDragging(self))
+       switch(0)
        {
-               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)
+               default:
+                       if(Drag_IsDragging(self))
                        {
-                               Drag_SetSpeed(self, 9);
-                       }
+                               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);
-               }
-       }
-       else
-       {
-               if(Drag_CanDrag(self))
-                       if(self.BUTTON_DRAG && pick)
+                                       if(frametime)
+                                               Drag_Update(self);
+                               }
+                               else
+                               {
+                                       Drag_Finish(self);
+                               }
+                       }
+                       else
                        {
-                               if(e)
-                                       if(Drag_IsDraggable(e))
+                               if(Drag_CanDrag(self))
+                                       if(self.BUTTON_DRAG && pick)
                                        {
-                                                       if(e.draggedby)
-                                                               Drag_Finish(e.draggedby);
-                                                       if(e.tag_entity)
-                                                               detach_sameorigin(e);
-                                                       Drag_Begin(self, e, trace_endpos);
-                                                       return TRUE;
+                                               if(e)
+                                                       if(Drag_IsDraggable(e))
+                                                       {
+                                                               if(ischeat)
+                                                                       IS_CHEAT(0, 0, CHRAME_DRAG);
+                                                               if(e.draggedby)
+                                                                       Drag_Finish(e.draggedby);
+                                                               if(e.tag_entity)
+                                                                       detach_sameorigin(e);
+                                                               Drag_Begin(self, e, trace_endpos);
+                                                               if(ischeat)
+                                                                       DID_CHEAT();
+                                                               return TRUE;
+                                                       }
                                        }
                        }
+                       break;
        }
        return FALSE;
 }
index 4615269..8c27691 100644 (file)
@@ -11,5 +11,3 @@ float CheatCommand(float argc);
 float CheatFrame();
 
 void Drag_MoveDrag(entity from, entity to); // call this from CopyBody
-
-float Drag(entity e, float grab); // used by sandbox code
\ No newline at end of file