From: Mircea Kitsune Date: Tue, 25 Oct 2011 08:54:41 +0000 (+0300) Subject: More documentation and some minor changes for drag code X-Git-Tag: xonotic-v0.6.0~35^2~18^2~192 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=a86fa5a48ac75276db3da34fd3721678517c62fa;ds=sidebyside More documentation and some minor changes for drag code --- diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index 93faddb3ec..d5c145f26c 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -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) diff --git a/qcsrc/server/cheats.qh b/qcsrc/server/cheats.qh index dec12cbdb8..46152692e9 100644 --- a/qcsrc/server/cheats.qh +++ b/qcsrc/server/cheats.qh @@ -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 diff --git a/qcsrc/server/mutators/sandbox.qc b/qcsrc/server/mutators/sandbox.qc index 8c94ed3aaf..28017401af 100644 --- a/qcsrc/server/mutators/sandbox.qc +++ b/qcsrc/server/mutators/sandbox.qc @@ -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"));