From: Mario Date: Sun, 31 May 2020 21:30:02 +0000 (+1000) Subject: Add optional self parameter to some builtins that need it X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=636dc5aa3f3ead251ba04146b92651e8f6ccb8d5;p=xonotic%2Fdarkplaces.git Add optional self parameter to some builtins that need it --- diff --git a/clvm_cmds.c b/clvm_cmds.c index 56e4517f..edeb93ea 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -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) diff --git a/dpdefs/csprogsdefs.qc b/dpdefs/csprogsdefs.qc index 572f9ba7..a4910b82 100644 --- a/dpdefs/csprogsdefs.qc +++ b/dpdefs/csprogsdefs.qc @@ -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; diff --git a/sv_move.c b/sv_move.c index ced05ac1..97347278 100644 --- 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); diff --git a/svvm_cmds.c b/svvm_cmds.c index bd58183b..73a9b75f 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -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");