]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - svvm_cmds.c
NudgeOutOfSolid: add a wasn't-stuck result
[xonotic/darkplaces.git] / svvm_cmds.c
index e77f965079b79d70760fe9eec548ffa509175543..25e8798296113768ef5c4069433b285dc1c34f59 100644 (file)
@@ -229,6 +229,7 @@ const char *vm_sv_extensions[] = {
 "ZQ_PAUSE",
 "DP_RM_CLIPGROUP",
 "DP_QC_FS_SEARCH_PACKFILE",
+"DP_QC_FINDBOX",
 NULL
 //"EXT_CSQC" // not ready yet
 };
@@ -1005,7 +1006,7 @@ static void VM_SV_findradius(prvm_prog_t *prog)
        else
                chainfield = prog->fieldoffsets.chain;
        if (chainfield < 0)
-               prog->error_cmd("VM_findchain: %s doesnt have the specified chain field !", prog->name);
+               prog->error_cmd("VM_SV_findradius: %s doesnt have the specified chain field !", prog->name);
 
        chain = (prvm_edict_t *)prog->edicts;
 
@@ -1056,6 +1057,50 @@ static void VM_SV_findradius(prvm_prog_t *prog)
        VM_RETURN_EDICT(chain);
 }
 
+/*
+=================
+VM_SV_findbox
+
+Returns a chain of entities that are touching a box (a simpler findradius); supports DP_QC_FINDCHAIN_TOFIELD
+
+findbox (mins, maxs)
+=================
+*/
+static void VM_SV_findbox(prvm_prog_t *prog)
+{
+       prvm_edict_t *chain;
+       int i, numtouchedicts;
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
+       int chainfield;
+
+       VM_SAFEPARMCOUNTRANGE(2, 3, VM_SV_findbox);
+
+       if(prog->argc == 3)
+               chainfield = PRVM_G_INT(OFS_PARM2);
+       else
+               chainfield = prog->fieldoffsets.chain;
+       if (chainfield < 0)
+               prog->error_cmd("VM_SV_findbox: %s doesnt have the specified chain field !", prog->name);
+
+       chain = (prvm_edict_t *)prog->edicts;
+
+       numtouchedicts = SV_EntitiesInBox(PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), MAX_EDICTS, touchedicts);
+       if (numtouchedicts > MAX_EDICTS)
+       {
+               // this never happens
+               Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
+               numtouchedicts = MAX_EDICTS;
+       }
+       for (i = 0; i < numtouchedicts; ++i)
+       {
+               prog->xfunction->builtinsprofile++;
+               PRVM_EDICTFIELDEDICT(touchedicts[i], chainfield) = PRVM_EDICT_TO_PROG(chain);
+               chain = touchedicts[i];
+       }
+
+       VM_RETURN_EDICT(chain);
+}
+
 static void VM_SV_precache_sound(prvm_prog_t *prog)
 {
        VM_SAFEPARMCOUNT(1, VM_SV_precache_sound);
@@ -1166,7 +1211,7 @@ static void VM_SV_droptofloor(prvm_prog_t *prog)
                end[2] -= 256; // Quake, QuakeWorld
 
        if (sv_gameplayfix_droptofloorstartsolid_nudgetocorrect.integer)
-               SV_NudgeOutOfSolid(ent);
+               PHYS_NudgeOutOfSolid(prog, ent);
 
        VectorCopy(PRVM_serveredictvector(ent, origin), entorigin);
        VectorCopy(PRVM_serveredictvector(ent, mins), entmins);
@@ -1192,7 +1237,7 @@ static void VM_SV_droptofloor(prvm_prog_t *prog)
                        Con_DPrintf("droptofloor at %f %f %f - FIXED BADLY PLACED ENTITY\n", PRVM_serveredictvector(ent, origin)[0], PRVM_serveredictvector(ent, origin)[1], PRVM_serveredictvector(ent, origin)[2]);
                        VectorCopy (trace.endpos, PRVM_serveredictvector(ent, origin));
                        if (sv_gameplayfix_droptofloorstartsolid_nudgetocorrect.integer)
-                               SV_NudgeOutOfSolid(ent);
+                               PHYS_NudgeOutOfSolid(prog, ent);
                        SV_LinkEdict(ent);
                        PRVM_serveredictfloat(ent, flags) = (int)PRVM_serveredictfloat(ent, flags) | FL_ONGROUND;
                        PRVM_serveredictedict(ent, groundentity) = PRVM_EDICT_TO_PROG(trace.ent);
@@ -1409,11 +1454,21 @@ static sizebuf_t *WriteDest(prvm_prog_t *prog)
        case MSG_ONE:
                ent = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(msg_entity));
                entnum = PRVM_NUM_FOR_EDICT(ent);
-               if (entnum < 1 || entnum > svs.maxclients || !svs.clients[entnum-1].active || !svs.clients[entnum-1].netconnection)
+               if (entnum < 1 || entnum > svs.maxclients)
                {
                        VM_Warning(prog, "WriteDest: tried to write to non-client\n");
                        return &sv.reliable_datagram;
                }
+               else if (!svs.clients[entnum-1].active)
+               {
+                       VM_Warning(prog, "WriteDest: tried to write to a disconnected client\n");
+                       return &sv.reliable_datagram;
+               }
+               else if (!svs.clients[entnum-1].netconnection)
+               {
+                       VM_Warning(prog, "WriteDest: tried to write to a bot client\n");
+                       return &sv.reliable_datagram;
+               }
                else
                        return &svs.clients[entnum-1].netconnection->message;
 
@@ -1790,8 +1845,7 @@ static void VM_SV_copyentity(prvm_prog_t *prog)
                return;
        }
        memcpy(out->fields.fp, in->fields.fp, prog->entityfields * sizeof(prvm_vec_t));
-       if (VectorCompare(PRVM_serveredictvector(out, absmin), PRVM_serveredictvector(out, absmax)))
-               return;
+
        SV_LinkEdict(out);
 }
 
@@ -2697,13 +2751,13 @@ static void VM_SV_clienttype(prvm_prog_t *prog)
        VM_SAFEPARMCOUNT(1, VM_SV_clienttype);
        clientnum = PRVM_G_EDICTNUM(OFS_PARM0) - 1;
        if (clientnum < 0 || clientnum >= svs.maxclients)
-               PRVM_G_FLOAT(OFS_RETURN) = 3;
+               PRVM_G_FLOAT(OFS_RETURN) = 3; // CLIENTTYPE_NOTACLIENT
        else if (!svs.clients[clientnum].active)
-               PRVM_G_FLOAT(OFS_RETURN) = 0;
+               PRVM_G_FLOAT(OFS_RETURN) = 0; // CLIENTTYPE_DISCONNECTED
        else if (svs.clients[clientnum].netconnection)
-               PRVM_G_FLOAT(OFS_RETURN) = 1;
+               PRVM_G_FLOAT(OFS_RETURN) = 1; // CLIENTTYPE_REAL
        else
-               PRVM_G_FLOAT(OFS_RETURN) = 2;
+               PRVM_G_FLOAT(OFS_RETURN) = 2; // CLIENTTYPE_BOT
 }
 
 /*
@@ -3764,7 +3818,7 @@ NULL,                                                     // #562
 NULL,                                                  // #563
 NULL,                                                  // #564
 NULL,                                                  // #565
-NULL,                                                  // #566
+VM_SV_findbox,                                 // #566 entity(vector mins, vector maxs) findbox = #566; (DP_QC_FINDBOX)
 NULL,                                                  // #567
 NULL,                                                  // #568
 NULL,                                                  // #569