]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cheats.qc
More documentation and some minor changes for drag code
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cheats.qc
index 0d95c453a1e6685b1d7032dd06dd520670ae628b..d5c145f26cc144a282de1038811046c7bb0ffa49 100644 (file)
@@ -664,7 +664,7 @@ float CheatCommand(float argc)
        END_CHEAT_FUNCTION();
 }
 
-void crosshair_trace_plusvisibletriggers(entity pl);
+float Drag(entity e, float grab);
 void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
 void Drag_Finish(entity dragger);
 float Drag_IsDraggable(entity draggee);
@@ -682,6 +682,46 @@ float CheatFrame()
 {
        BEGIN_CHEAT_FUNCTION();
 
+       // Dragging can be used as either a cheat, or a tool for g_sandbox. If sv_cheats is active,
+       // the cheat dragging is used (unlimited pickup range and any entity can be carried), even if
+       // g_sandbox is enabled. Is sv_cheats is disabled but g_sandbox is not, then sandbox dragging
+       // is used (limited pickup range and only sandbox objects can be carried), grabbing itself
+       // no longer being accounted as cheating. If both sv_cheats and g_sandbox are disabled, players
+       // attempting to grab objects are reported as trying to cheat.
+
+       switch(0)
+       {
+               default:
+                       if(self.BUTTON_DRAG && !cvar("g_sandbox"))
+                       {
+                               // consider dragging a cheat only if sandbox mode is disabled
+                               IS_CHEAT(0, 0, CHRAME_DRAG);
+                       }
+                       if(autocvar_sv_cheats)
+                       {
+                               // only use cheat dragging if cheats are enabled
+                               crosshair_trace_plusvisibletriggers(self);
+                               if(Drag(trace_ent, TRUE) && !cvar("g_sandbox"))
+                                       DID_CHEAT();
+                       }
+                       break;
+       }
+
+       END_CHEAT_FUNCTION();
+}
+
+
+
+
+
+// ENTITY DRAGGING
+
+float Drag(entity e, float grab)
+{
+       // returns TRUE when an entity has been picked up
+       // If grab is TRUE, the object can also be picked up if it's not being held already
+       // If grab is FALSE, only keep dragging the object if it's already being held
+
        if(Drag_IsDragging(self))
        {
                if(self.BUTTON_DRAG)
@@ -716,49 +756,21 @@ float CheatFrame()
        else
        {
                if(Drag_CanDrag(self))
-                       if(self.BUTTON_DRAG)
+                       if(self.BUTTON_DRAG && grab)
                        {
-                               crosshair_trace_plusvisibletriggers(self);
-                               if(trace_ent)
-                                       if(Drag_IsDraggable(trace_ent))
-                                               switch(0)
-                                               {
-                                                       default:
-                                                               IS_CHEAT(0, 0, CHRAME_DRAG);
-                                                               if(trace_ent.draggedby)
-                                                                       Drag_Finish(trace_ent.draggedby);
-                                                               if(trace_ent.tag_entity)
-                                                                       detach_sameorigin(trace_ent);
-                                                               Drag_Begin(self, trace_ent, trace_endpos);
-                                                               DID_CHEAT();
-                                                               break;
-                                               }
+                               if(e)
+                                       if(Drag_IsDraggable(e))
+                                       {
+                                                       if(e.draggedby)
+                                                               Drag_Finish(e.draggedby);
+                                                       if(e.tag_entity)
+                                                               detach_sameorigin(e);
+                                                       Drag_Begin(self, e, trace_endpos);
+                                                       return TRUE;
+                                       }
                        }
        }
-
-       END_CHEAT_FUNCTION();
-}
-
-
-
-
-
-// ENTITY DRAGGING
-
-void crosshair_trace_plusvisibletriggers(entity pl)
-{
-       entity first;
-       entity e;
-       first = findchainfloat(solid, SOLID_TRIGGER);
-
-       for (e = first; e; e = e.chain)
-               if (e.model != "")
-                       e.solid = SOLID_BSP;
-
-       crosshair_trace(pl);
-
-       for (e = first; e; e = e.chain)
-               e.solid = SOLID_TRIGGER;
+       return FALSE;
 }
 
 // on dragger:
@@ -937,11 +949,6 @@ void Drag_MoveDrag(entity from, entity to)
        }
 }
 
-
-
-
-
-
 void DragBox_Think()
 {
        if(self.aiment && self.enemy)