]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Implement DP_QC_NUDGEOUTOFSOLID extension
authorbones_was_here <bones_was_here@xonotic.au>
Sat, 15 Jul 2023 12:28:37 +0000 (22:28 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sat, 15 Jul 2023 12:28:37 +0000 (22:28 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
clvm_cmds.c
dpdefs/dpextensions.qc
prvm_cmds.c
prvm_cmds.h
svvm_cmds.c

index 587a31bb7db6ae2f25eef22d962ffc0f792478a4..05bb57a934d3f3cb743470fefbf7b6432771fd7c 100644 (file)
@@ -5545,7 +5545,7 @@ NULL,                                                     // #563
 NULL,                                                  // #564
 NULL,                                                  // #565
 VM_CL_findbox,                                 // #566 entity(vector mins, vector maxs) findbox = #566; (DP_QC_FINDBOX)
-NULL,                                                  // #567
+VM_nudgeoutofsolid,                            // #567 float(entity ent) nudgeoutofsolid = #567; (DP_QC_NUDGEOUTOFSOLID)
 NULL,                                                  // #568
 NULL,                                                  // #569
 NULL,                                                  // #570
index 558a288e49dd1f9a9158fe497f41679a25120a91..b616980a77c7fc06a3ed7a2dc3322cb76def9fbc 100644 (file)
@@ -2654,4 +2654,16 @@ entity(vector mins, vector maxs, .entity tofield) findbox_tofield = #566;
 //description:
 //Returns a chain of entities that are touching a box (a simpler findradius); supports DP_QC_FINDCHAIN_TOFIELD
 
+//DP_QC_NUDGEOUTOFSOLID
+//idea: LadyHavoc, bones_was_here
+//darkplaces implementation: LadyHavoc, bones_was_here
+//builtin definitions:
+float(entity ent) nudgeoutofsolid = #567;
+//cvar definitions:
+//sv_gameplayfix_nudgeoutofsolid_separation
+//description:
+//Attempts to move a stuck entity out of solid brushes, returning 1 if successful, 0 if it remains stuck, -1 if it wasn't stuck.
+//Note: makes only one tracebox call if the entity isn't stuck, so don't call tracebox just to see if you should call nudgeoutofsolid.
+
+
 float(float dividend, float divisor) mod = #245;
index 9554aa449236835084c10fec42de5fbe488912a1..fc39fa33067c6ea2440d4f982835f2969dfcd062 100644 (file)
@@ -5563,6 +5563,41 @@ void VM_SV_getextresponse (prvm_prog_t *prog)
        }
 }
 
+// DP_QC_NUDGEOUTOFSOLID
+// float(entity ent) nudgeoutofsolid = #567;
+void VM_nudgeoutofsolid(prvm_prog_t *prog)
+{
+       prvm_edict_t *ent;
+
+       VM_SAFEPARMCOUNTRANGE(1, 1, VM_nudgeoutofsolid);
+
+       ent = PRVM_G_EDICT(OFS_PARM0);
+       if (ent == prog->edicts)
+       {
+               VM_Warning(prog, "nudgeoutofsolid: can not modify world entity\n");
+               PRVM_G_FLOAT(OFS_RETURN) = 0;
+               return;
+       }
+       if (ent->free)
+       {
+               VM_Warning(prog, "nudgeoutofsolid: can not modify free entity\n");
+               PRVM_G_FLOAT(OFS_RETURN) = 0;
+               return;
+       }
+
+       PRVM_G_FLOAT(OFS_RETURN) = PHYS_NudgeOutOfSolid(prog, ent);
+
+       if (PRVM_G_FLOAT(OFS_RETURN) > 0)
+       {
+               if (prog == SVVM_prog)
+                       SV_LinkEdict(ent);
+               else if (prog == CLVM_prog)
+                       CL_LinkEdict(ent);
+               else
+                       Sys_Error("PHYS_NudgeOutOfSolid: cannot be called from %s VM\n", prog->name);
+       }
+}
+
 /*
 =========
 Common functions between menu.dat and clsprogs
index a5555cde87db8ca68f0fb71380fcc4ada18f1842..81556d5cf9fe9bfa30293d7372c540b103afb3f0 100644 (file)
@@ -484,6 +484,7 @@ void VM_getsurfacetriangle(prvm_prog_t *prog);
 void VM_physics_enable(prvm_prog_t *prog);
 void VM_physics_addforce(prvm_prog_t *prog);
 void VM_physics_addtorque(prvm_prog_t *prog);
+void VM_nudgeoutofsolid(prvm_prog_t *prog);
 
 void VM_coverage(prvm_prog_t *prog);
 
index 4cccd0f45219900491d25061e7e6201bd7a0d986..b97ee20841a27f9dacd45f03624a9f976ebc1399 100644 (file)
@@ -119,6 +119,7 @@ const char *vm_sv_extensions[] = {
 "DP_QC_LOG",
 "DP_QC_MINMAXBOUND",
 "DP_QC_MULTIPLETEMPSTRINGS",
+"DP_QC_NUDGEOUTOFSOLID",
 "DP_QC_NUM_FOR_EDICT",
 "DP_QC_RANDOMVEC",
 "DP_QC_SINCOSSQRTPOW",
@@ -3833,7 +3834,7 @@ NULL,                                                     // #563
 NULL,                                                  // #564
 NULL,                                                  // #565
 VM_SV_findbox,                                 // #566 entity(vector mins, vector maxs) findbox = #566; (DP_QC_FINDBOX)
-NULL,                                                  // #567
+VM_nudgeoutofsolid,                            // #567 float(entity ent) nudgeoutofsolid = #567; (DP_QC_NUDGEOUTOFSOLID)
 NULL,                                                  // #568
 NULL,                                                  // #569
 NULL,                                                  // #570