]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cheats.qc
Add bad cvar
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cheats.qc
index e35adab354d95b4062667fa9e1178d29444fd38f..57a09fe3808ac8997b2a557010fb442e24827dc8 100644 (file)
@@ -89,8 +89,7 @@ float CheatsAllowed(float i, float argc, float fr) // the cheat gets passed as a
        ADD_CHEATS(self,cheating); \
        return attempting
 #define IS_CHEAT(i,argc,fr) \
-       ++attempting; \
-       if(!CheatsAllowed(i,argc,fr)) \
+       if((++attempting, !CheatsAllowed(i,argc,fr))) \
                break
 
 float CheatImpulse(float i)
@@ -229,7 +228,7 @@ float CheatImpulse(float i)
                        IS_CHEAT(i, 0, 0);
                        FOR_EACH_PLAYER(e)
                        {
-                               get_model_parameters(e.playermodel, e.skinindex);
+                               get_model_parameters(e.playermodel, e.skin);
                                if(get_model_parameters_sex == "Female")
                                {
                                        makevectors(e.angles);
@@ -664,7 +663,7 @@ float CheatCommand(float argc)
        END_CHEAT_FUNCTION();
 }
 
-float Drag(entity e, float dist);
+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);
@@ -682,20 +681,51 @@ float CheatFrame()
 {
        BEGIN_CHEAT_FUNCTION();
 
+       // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
+       // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
+       // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
+       // grabbing itself no longer being accounted as cheating.
+
        switch(0)
        {
                default:
-                       if(self.BUTTON_DRAG && !cvar("g_sandbox"))
+                       if(self.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
                        {
-                               // consider dragging a cheat only if sandbox mode is disabled
-                               IS_CHEAT(0, 0, CHRAME_DRAG);
+                               // use cheat dragging if cheats are enabled
+                               crosshair_trace_plusvisibletriggers(self);
+                               Drag(trace_ent, TRUE, TRUE);
                        }
-                       if(autocvar_sv_cheats)
+                       else
                        {
-                               // only use non-sandbox dragging if cheats are enabled
+                               // drag is TRUE if the object can be picked up. While an object is being carried, the Drag() function
+                               // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
+                               // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
+                               // it goes out of range while slinging it around.
+
+                               float drag;
                                crosshair_trace_plusvisibletriggers(self);
-                               if(Drag(trace_ent, FALSE) && !cvar("g_sandbox"))
-                                       DID_CHEAT();
+                               if(vlen(self.origin - trace_ent.origin) <= autocvar_g_grab_range)
+                               {
+                                       switch(trace_ent.grab)
+                                       {
+                                               case 0: // can't grab
+                                                       break;
+                                               case 1: // owner can grab
+                                                       if(trace_ent.owner == self || trace_ent.realowner == self)
+                                                               drag = TRUE;
+                                                       break;
+                                               case 2: // owner and team mates can grab
+                                                       if(!IsDifferentTeam(trace_ent.owner, self) || !IsDifferentTeam(trace_ent.realowner, self) || trace_ent.team == self.team)
+                                                               drag = TRUE;
+                                                       break;
+                                               case 3: // anyone can grab
+                                                       drag = TRUE;
+                                                       break;
+                                               default:
+                                                       break;
+                                       }
+                               }
+                               Drag(trace_ent, drag, FALSE); // execute dragging
                        }
                        break;
        }
@@ -709,60 +739,70 @@ float CheatFrame()
 
 // ENTITY DRAGGING
 
-float Drag(entity e, float dist)
+float Drag(entity e, float pick, float ischeat)
 {
-       float inrange;
-       if(vlen(e.origin - self.origin) <= dist || !dist)
-               inrange = TRUE;
+       BEGIN_CHEAT_FUNCTION();
 
-       if(Drag_IsDragging(self))
+       // 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
+
+       switch(0)
        {
-               if(self.BUTTON_DRAG && inrange)
-               {
-                       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 && inrange)
+                                       if(frametime)
+                                               Drag_Update(self);
+                               }
+                               else
+                               {
+                                       Drag_Finish(self);
+                               }
+                       }
+                       else
                        {
-                               crosshair_trace_plusvisibletriggers(self);
-                               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;
 }
@@ -835,6 +875,8 @@ void Drag_Finish(entity dragger)
 float Drag_IsDraggable(entity draggee)
 {
        // TODO add more checks for bad stuff here
+       if(draggee == world)
+               return FALSE;
        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)
@@ -943,11 +985,6 @@ void Drag_MoveDrag(entity from, entity to)
        }
 }
 
-
-
-
-
-
 void DragBox_Think()
 {
        if(self.aiment && self.enemy)