]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Add optional self parameter to some builtins that need it
authorMario <mario@smbclan.net>
Sun, 31 May 2020 21:30:02 +0000 (07:30 +1000)
committerMario <mario@smbclan.net>
Sun, 31 May 2020 21:30:02 +0000 (07:30 +1000)
clvm_cmds.c
dpdefs/csprogsdefs.qc
sv_move.c
svvm_cmds.c

index 56e4517fbfb65641f07feb45a96dd66cef5aff49..edeb93ea339695e8c3a31b678241a512df2bab45 100644 (file)
@@ -521,7 +521,7 @@ static void VM_CL_findradius (prvm_prog_t *prog)
        VM_RETURN_EDICT(chain);
 }
 
-// #34 float() droptofloor
+// #34 float([ent]) droptofloor
 static void VM_CL_droptofloor (prvm_prog_t *prog)
 {
        prvm_edict_t            *ent;
@@ -533,7 +533,11 @@ static void VM_CL_droptofloor (prvm_prog_t *prog)
        // assume failure if it returns early
        PRVM_G_FLOAT(OFS_RETURN) = 0;
 
-       ent = PRVM_PROG_TO_EDICT(PRVM_clientglobaledict(self));
+       // optional entity parameter for self (EXT_ENTITYPARAM)
+       if (prog->argc >= 0)
+               ent = PRVM_G_EDICT(OFS_PARM0);
+       else
+               ent = PRVM_PROG_TO_EDICT(PRVM_clientglobaledict(self));
        if (ent == prog->edicts)
        {
                VM_Warning(prog, "droptofloor: can not modify world entity\n");
@@ -3615,7 +3619,7 @@ static qboolean CL_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qb
 ===============
 VM_CL_walkmove
 
-float(float yaw, float dist[, settrace]) walkmove
+float(float yaw, float dist[, settrace, ent]) walkmove
 ===============
 */
 static void VM_CL_walkmove (prvm_prog_t *prog)
@@ -3627,12 +3631,16 @@ static void VM_CL_walkmove (prvm_prog_t *prog)
        int     oldself;
        qboolean        settrace;
 
-       VM_SAFEPARMCOUNTRANGE(2, 3, VM_CL_walkmove);
+       VM_SAFEPARMCOUNTRANGE(2, 4, VM_CL_walkmove);
 
        // assume failure if it returns early
        PRVM_G_FLOAT(OFS_RETURN) = 0;
 
-       ent = PRVM_PROG_TO_EDICT(PRVM_clientglobaledict(self));
+       // optional entity parameter for self (EXT_ENTITYPARAM)
+       if (prog->argc >= 4)
+               ent = PRVM_G_EDICT(OFS_PARM3);
+       else
+               ent = PRVM_PROG_TO_EDICT(PRVM_clientglobaledict(self));
        if (ent == prog->edicts)
        {
                VM_Warning(prog, "walkmove: can not modify world entity\n");
@@ -4191,7 +4199,7 @@ VM_coredump,                                      // #28 void() coredump (QUAKE)
 VM_traceon,                                            // #29 void() traceon (QUAKE)
 VM_traceoff,                                   // #30 void() traceoff (QUAKE)
 VM_eprint,                                             // #31 void(entity e) eprint (QUAKE)
-VM_CL_walkmove,                                        // #32 float(float yaw, float dist[, float settrace]) walkmove (QUAKE)
+VM_CL_walkmove,                                        // #32 float(float yaw, float dist[, float settrace, entity ent]) walkmove (QUAKE)
 NULL,                                                  // #33 (QUAKE)
 VM_CL_droptofloor,                             // #34 float() droptofloor (QUAKE)
 VM_CL_lightstyle,                              // #35 void(float style, string value) lightstyle (QUAKE)
index 572f9ba779837b5749e6fdea11623aefc9b7f276..a4910b823bee8e8a6997f2b207d163b9e5d2538f 100644 (file)
@@ -360,8 +360,8 @@ void() coredump = #28;
 void() traceon = #29;
 void() traceoff = #30;
 void(entity e) eprint = #31;
-// settrace optional
-float(float yaw, float dist, float settrace) walkmove = #32;
+// settrace and ent optional
+float(float yaw, float dist, float settrace, entity ent) walkmove = #32;
 
 float() droptofloor = #34;
 void(float style, string value) lightstyle = #35;
index ced05ac1b1ca03260b359dfb716b6cba8cd9e273..97347278348f6ace2a36957de1a03418977e79b1 100644 (file)
--- a/sv_move.c
+++ b/sv_move.c
@@ -259,9 +259,15 @@ static qboolean SV_StepDirection (prvm_edict_t *ent, float yaw, float dist)
        prvm_prog_t *prog = SVVM_prog;
        vec3_t          move, oldorigin;
        float           delta;
+       int saveSelf;
 
        PRVM_serveredictfloat(ent, ideal_yaw) = yaw;
+       
+       // Mario: since changeyaw has no parameters, copy self to ent temporarily (EXT_ENTITYPARAM)
+       saveSelf = PRVM_serverglobaledict(self);
+       PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(ent);
        VM_changeyaw(prog);
+       PRVM_serverglobaledict(self) = saveSelf;
 
        yaw = yaw*M_PI*2 / 360;
        move[0] = cos(yaw)*dist;
@@ -422,9 +428,13 @@ void VM_SV_MoveToGoal(prvm_prog_t *prog)
        prvm_edict_t            *ent, *goal;
        float           dist;
 
-       VM_SAFEPARMCOUNT(1, SV_MoveToGoal);
+       VM_SAFEPARMCOUNTRANGE(1, 2, SV_MoveToGoal);
 
-       ent = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
+       // optional entity parameter for self (EXT_ENTITYPARAM)
+       if (prog->argc >= 2)
+               ent = PRVM_G_EDICT(OFS_PARM1);
+       else
+               ent = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
        goal = PRVM_PROG_TO_EDICT(PRVM_serveredictedict(ent, goalentity));
        dist = PRVM_G_FLOAT(OFS_PARM0);
 
index bd58183b46f50c010005397240ab58dd41c48dcd..73a9b75f66ca27eb7d6cd62524506dec0f06ab6f 100644 (file)
@@ -828,7 +828,7 @@ If there is more than one valid option, they are cycled each frame
 If (self.origin + self.viewofs) is not in the PVS of the current target,
 it is not returned at all.
 
-name checkclient ()
+name checkclient ([ent])
 =================
 */
 int c_invis, c_notvis;
@@ -837,7 +837,7 @@ static void VM_SV_checkclient(prvm_prog_t *prog)
        prvm_edict_t    *ent, *self;
        vec3_t  view;
 
-       VM_SAFEPARMCOUNT(0, VM_SV_checkclient);
+       VM_SAFEPARMCOUNTRANGE(0, 1, VM_SV_checkclient);
 
        // find a new check if on a new frame
        if (sv.time - sv.lastchecktime >= 0.1)
@@ -855,7 +855,11 @@ static void VM_SV_checkclient(prvm_prog_t *prog)
        }
 
        // if current entity can't possibly see the check entity, return 0
-       self = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
+       // optional entity parameter for self (EXT_ENTITYPARAM)
+       if (prog->argc >= 1)
+               self = PRVM_G_EDICT(OFS_PARM0);
+       else
+               self = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
        VectorAdd(PRVM_serveredictvector(self, origin), PRVM_serveredictvector(self, view_ofs), view);
        if (sv.worldmodel && checkpvsbytes && !sv.worldmodel->brush.BoxTouchingPVS(sv.worldmodel, checkpvs, view, view))
        {
@@ -1068,7 +1072,7 @@ static void VM_SV_precache_model(prvm_prog_t *prog)
 ===============
 VM_SV_walkmove
 
-float(float yaw, float dist[, settrace]) walkmove
+float(float yaw, float dist[, settrace, ent]) walkmove
 ===============
 */
 static void VM_SV_walkmove(prvm_prog_t *prog)
@@ -1080,12 +1084,16 @@ static void VM_SV_walkmove(prvm_prog_t *prog)
        int     oldself;
        qboolean        settrace;
 
-       VM_SAFEPARMCOUNTRANGE(2, 3, VM_SV_walkmove);
+       VM_SAFEPARMCOUNTRANGE(2, 4, VM_SV_walkmove);
 
        // assume failure if it returns early
        PRVM_G_FLOAT(OFS_RETURN) = 0;
 
-       ent = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
+       // optional entity parameter for self (EXT_ENTITYPARAM)
+       if (prog->argc >= 4)
+               ent = PRVM_G_EDICT(OFS_PARM3);
+       else
+               ent = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
        if (ent == prog->edicts)
        {
                VM_Warning(prog, "walkmove: can not modify world entity\n");
@@ -1125,7 +1133,7 @@ static void VM_SV_walkmove(prvm_prog_t *prog)
 ===============
 VM_SV_droptofloor
 
-void() droptofloor
+void([ent]) droptofloor
 ===============
 */
 
@@ -1140,7 +1148,11 @@ static void VM_SV_droptofloor(prvm_prog_t *prog)
        // assume failure if it returns early
        PRVM_G_FLOAT(OFS_RETURN) = 0;
 
-       ent = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
+       // optional entity parameter for self (EXT_ENTITYPARAM)
+       if (prog->argc >= 1)
+               ent = PRVM_G_EDICT(OFS_PARM0);
+       else
+               ent = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
        if (ent == prog->edicts)
        {
                VM_Warning(prog, "droptofloor: can not modify world entity\n");