]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
More documentation and some minor changes for drag code
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Tue, 25 Oct 2011 08:54:41 +0000 (11:54 +0300)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Tue, 25 Oct 2011 08:54:41 +0000 (11:54 +0300)
qcsrc/server/cheats.qc
qcsrc/server/cheats.qh
qcsrc/server/mutators/sandbox.qc

index 93faddb3ecfe8d0fa5444a90745c901ae9e823ad..d5c145f26cc144a282de1038811046c7bb0ffa49 100644 (file)
@@ -664,7 +664,7 @@ float CheatCommand(float argc)
        END_CHEAT_FUNCTION();
 }
 
-float Drag(entity e, float candrag);
+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);
@@ -716,8 +716,12 @@ float CheatFrame()
 
 // ENTITY DRAGGING
 
-float Drag(entity e, float candrag)
+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)
@@ -752,7 +756,7 @@ float Drag(entity e, float candrag)
        else
        {
                if(Drag_CanDrag(self))
-                       if(self.BUTTON_DRAG && candrag)
+                       if(self.BUTTON_DRAG && grab)
                        {
                                if(e)
                                        if(Drag_IsDraggable(e))
@@ -945,11 +949,6 @@ void Drag_MoveDrag(entity from, entity to)
        }
 }
 
-
-
-
-
-
 void DragBox_Think()
 {
        if(self.aiment && self.enemy)
index dec12cbdb84b51c74c4b2be781e8c1bd27a003fb..46152692e969e64dd9dfff6cd85f6e8b781747e1 100644 (file)
@@ -12,4 +12,4 @@ float CheatFrame();
 
 void Drag_MoveDrag(entity from, entity to); // call this from CopyBody
 
-float Drag(entity e, float candrag); // used by sandbox code
\ No newline at end of file
+float Drag(entity e, float grab); // used by sandbox code
\ No newline at end of file
index 8c94ed3aafb9cdfc30188a5542cf6b3d240de5ab..28017401af9033b3bf5d24f813f7870699d041de 100644 (file)
@@ -107,14 +107,19 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
        // if the player is close enough to their own object and facing it, they can grab it
 
        if(autocvar_sv_cheats)
-               return FALSE; // cheats already allow dragging all objects
+               return FALSE; // cheat dragging is used instead
 
+       float grab;
        crosshair_trace_plusvisibletriggers(self);
 
-       float candrag;
+       // grab 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.
+
        if(trace_ent.classname == "object" && trace_ent.realowner == self && vlen(trace_ent.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
-               candrag = TRUE; // object can be picked up
-       if(Drag(trace_ent, candrag)) // execute dragging
+               grab = TRUE; // object can be picked up
+       if(Drag(trace_ent, grab)) // execute dragging
                if(autocvar_g_sandbox_info)
                        print(strcat(self.netname, " grabbed an object at origin ", vtos(trace_ent.origin), "\n"));