From 057e534ac970254e91d625ca31623b850bb6b165 Mon Sep 17 00:00:00 2001 From: Mircea Kitsune Date: Sun, 6 Nov 2011 13:15:53 +0200 Subject: [PATCH] Remove non-cheat grabbing from the sandbox code, and allow it to be used for other purposes too. Any object with the .drag value set to anything other than 0 will be possible to drag without cheats, regardless of the sandbox mode. --- defaultXonotic.cfg | 2 ++ qcsrc/server/autocvars.qh | 2 ++ qcsrc/server/cheats.qc | 14 ++++++------ qcsrc/server/cl_client.qc | 37 ++++++++++++++++++++++++++++++++ qcsrc/server/defs.qh | 2 ++ qcsrc/server/mutators/sandbox.qc | 12 +++++++++++ 6 files changed, 62 insertions(+), 7 deletions(-) diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index a4880039c..dc4febe88 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -539,6 +539,8 @@ seta g_maplist_shuffle 1 "new randomization method: like selectrandom, but avoid set g_maplist_check_waypoints 0 "when 1, maps are skipped if there currently are bots, but the map has no waypoints" set samelevel 0 "when 1, always play the same level over and over again" +set g_grab 0 "enables grabbing certain objects" + set g_cloaked 0 "display all players mostly invisible" set g_player_alpha 1 set g_player_brightness 0 "set to 2 for brighter players" diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 810542fb2..38c11fc4f 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -1203,6 +1203,8 @@ float autocvar_sv_gameplayfix_gravityunaffectedbyticrate; float autocvar_g_trueaim_minrange; float autocvar_g_debug_defaultsounds; float autocvar_g_loituma; +float autocvar_g_grab; +float autocvar_g_grab_range; float autocvar_g_sandbox_info; string autocvar_g_sandbox_storage_name; float autocvar_g_sandbox_storage_autosave; diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index d5c145f26..ece6fa6cd 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -682,26 +682,26 @@ float CheatFrame() { BEGIN_CHEAT_FUNCTION(); - // Dragging can be used as either a cheat, or a tool for g_sandbox. If sv_cheats is active, + // 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), 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 + // g_grab is enabled. Is sv_cheats is disabled but g_grab is not, normal dragging is + // used (limited pickup range and only dragable objects can be carried), grabbing itself + // no longer being accounted as cheating. If both sv_cheats and g_grab are disabled, players // attempting to grab objects are reported as trying to cheat. switch(0) { default: - if(self.BUTTON_DRAG && !cvar("g_sandbox")) + if(self.BUTTON_DRAG && !autocvar_g_grab) { - // consider dragging a cheat only if sandbox mode is disabled + // consider dragging a cheat only if g_grab 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")) + if(Drag(trace_ent, TRUE) && !autocvar_g_grab) DID_CHEAT(); } break; diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 7445c6b38..1881fcb3a 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -2792,6 +2792,43 @@ void PlayerPreThink (void) PrintWelcomeMessage(); + // if the player is close enough to a dragable entity, they can grab it + if(autocvar_g_grab && !autocvar_sv_cheats) // cheat dragging is used instead + { + // 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; + makevectors(self.v_angle); + WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit, MOVE_NORMAL, self); + if(trace_ent != world) + { + 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(trace_ent.owner == self || trace_ent.realowner == self) + drag = TRUE; + if(!IsDifferentTeam(trace_ent.owner, self) || !IsDifferentTeam(trace_ent.realowner, self)) + drag = TRUE; + break; + case 3: // anyone can grab + drag = TRUE; + break; + default: + break; + } + } + Drag(trace_ent, drag); // execute dragging + } + if(self.classname == "player") { // if(self.netname == "Wazat") // bprint(self.classname, "\n"); diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index b84d03164..86446f036 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -617,6 +617,8 @@ float client_cefc_accumulatortime; .float clip_size; .float minelayer_mines; +.float grab; // 0 = can't grab, 1 = owner can grab, 2 = owner and team mates can grab, 3 = anyone can grab + #define PROJECTILE_MAKETRIGGER(e) (e).solid = SOLID_CORPSE; (e).dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE // when doing this, hagar can go through clones // #define PROJECTILE_MAKETRIGGER(e) (e).solid = SOLID_BBOX diff --git a/qcsrc/server/mutators/sandbox.qc b/qcsrc/server/mutators/sandbox.qc index 2a38941d2..73436eb3f 100644 --- a/qcsrc/server/mutators/sandbox.qc +++ b/qcsrc/server/mutators/sandbox.qc @@ -29,6 +29,16 @@ void sandbox_ObjectFunction_Touch() pointparticles(particleeffectnum(strcat("impact_", self.material)), self.origin, '0 0 0', ceil(intensity * 10)); // allow a count from 1 to 10 } +void sandbox_ObjectFunction_Think() +{ + if(autocvar_g_sandbox_editor_free < 2 && self.crypto_idfp) + self.grab = 1; + else + self.grab = 3; + + self.nextthink = time; +} + entity sandbox_ObjectEdit_Get(float permissions) { // returns the traced entity if the player can edit it, and world if not @@ -117,6 +127,8 @@ entity sandbox_ObjectSpawn(float database) e.skin = 0; e.material = string_null; e.touch = sandbox_ObjectFunction_Touch; + e.think = sandbox_ObjectFunction_Think; + e.nextthink = time; //e.effects |= EF_SELECTABLE; // don't do this all the time, maybe just when editing objects? if(!database) -- 2.39.2