]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Remove non-cheat grabbing from the sandbox code, and allow it to be used for other...
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Sun, 6 Nov 2011 11:15:53 +0000 (13:15 +0200)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Sun, 6 Nov 2011 11:15:53 +0000 (13:15 +0200)
defaultXonotic.cfg
qcsrc/server/autocvars.qh
qcsrc/server/cheats.qc
qcsrc/server/cl_client.qc
qcsrc/server/defs.qh
qcsrc/server/mutators/sandbox.qc

index a4880039cf48ad9c534c0236a7d95981d0691f05..dc4febe88b74c2e54c64f913ec0dc6bbfad28d94 100644 (file)
@@ -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"
index 810542fb26f293f67c204886bf78ddd688e13e29..38c11fc4f9f93f67b2739b0455a5a5d496b83d7d 100644 (file)
@@ -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;
index d5c145f26cc144a282de1038811046c7bb0ffa49..ece6fa6cd11a8d6f4f0c17bda89ea3647019adfc 100644 (file)
@@ -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;
index 7445c6b38b0cf5f2c4f4f43ea47ea3cf11ab1efc..1881fcb3a36eeb79f89add57dcb4bcec0f0ef795 100644 (file)
@@ -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");
index b84d03164d312d8c2b3b410bb8c86a602bb1fca0..86446f03678ffbb667d77dcb550fcd5926db7f42 100644 (file)
@@ -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
index 2a38941d2eaaedde0a660a89d1ba1d32d194c3b6..73436eb3f81cee08e24e0a8183baead268faafd6 100644 (file)
@@ -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)