]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - svvm_cmds.c
Doxygen: more tweaks
[xonotic/darkplaces.git] / svvm_cmds.c
index 54776d5653b78ed7aed89053b3e953aeb1d987af..672ff70d1f8e7116237d6f81737fe2b8012a014b 100644 (file)
@@ -228,6 +228,7 @@ const char *vm_sv_extensions[] = {
 "TW_SV_STEPCONTROL",
 "ZQ_PAUSE",
 "DP_RM_CLIPGROUP",
+"DP_QC_FS_SEARCH_PACKFILE",
 NULL
 //"EXT_CSQC" // not ready yet
 };
@@ -253,7 +254,7 @@ static void VM_SV_setorigin(prvm_prog_t *prog)
                VM_Warning(prog, "setorigin: can not modify world entity\n");
                return;
        }
-       if (e->priv.server->free)
+       if (e->free)
        {
                VM_Warning(prog, "setorigin: can not modify free entity\n");
                return;
@@ -265,7 +266,7 @@ static void VM_SV_setorigin(prvm_prog_t *prog)
 }
 
 // TODO: rotate param isnt used.. could be a bug. please check this and remove it if possible [1/10/2008 Black]
-static void SetMinMaxSize (prvm_prog_t *prog, prvm_edict_t *e, float *min, float *max, qboolean rotate)
+static void SetMinMaxSize (prvm_prog_t *prog, prvm_edict_t *e, float *min, float *max, qbool rotate)
 {
        int             i;
 
@@ -304,7 +305,7 @@ static void VM_SV_setsize(prvm_prog_t *prog)
                VM_Warning(prog, "setsize: can not modify world entity\n");
                return;
        }
-       if (e->priv.server->free)
+       if (e->free)
        {
                VM_Warning(prog, "setsize: can not modify free entity\n");
                return;
@@ -326,7 +327,7 @@ static vec3_t quakemins = {-16, -16, -16}, quakemaxs = {16, 16, 16};
 static void VM_SV_setmodel(prvm_prog_t *prog)
 {
        prvm_edict_t    *e;
-       dp_model_t      *mod;
+       model_t *mod;
        int             i;
 
        VM_SAFEPARMCOUNT(2, VM_SV_setmodel);
@@ -337,7 +338,7 @@ static void VM_SV_setmodel(prvm_prog_t *prog)
                VM_Warning(prog, "setmodel: can not modify world entity\n");
                return;
        }
-       if (e->priv.server->free)
+       if (e->free)
        {
                VM_Warning(prog, "setmodel: can not modify free entity\n");
                return;
@@ -487,6 +488,9 @@ static void VM_SV_ambientsound(prvm_prog_t *prog)
        if (soundnum >= 256)
                large = true;
 
+       if(sv.protocol == PROTOCOL_NEHAHRABJP)
+               large = false;
+
        // add an svc_spawnambient command to the level signon packet
 
        if (large)
@@ -496,7 +500,7 @@ static void VM_SV_ambientsound(prvm_prog_t *prog)
 
        MSG_WriteVector(&sv.signon, pos, sv.protocol);
 
-       if (large || sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3)
+       if (large || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3)
                MSG_WriteShort (&sv.signon, soundnum);
        else
                MSG_WriteByte (&sv.signon, soundnum);
@@ -802,7 +806,7 @@ static int VM_SV_newcheckclient(prvm_prog_t *prog, int check)
                // look up the client's edict
                ent = PRVM_EDICT_NUM(i);
                // check if it is to be ignored, but never ignore the one we started on (prevent infinite loop)
-               if (i != check && (ent->priv.server->free || PRVM_serveredictfloat(ent, health) <= 0 || ((int)PRVM_serveredictfloat(ent, flags) & FL_NOTARGET)))
+               if (i != check && (ent->free || PRVM_serveredictfloat(ent, health) <= 0 || ((int)PRVM_serveredictfloat(ent, flags) & FL_NOTARGET)))
                        continue;
                // found a valid client (possibly the same one again)
                break;
@@ -849,7 +853,7 @@ static void VM_SV_checkclient(prvm_prog_t *prog)
 
        // return check if it might be visible
        ent = PRVM_EDICT_NUM(sv.lastcheck);
-       if (ent->priv.server->free || PRVM_serveredictfloat(ent, health) <= 0)
+       if (ent->free || PRVM_serveredictfloat(ent, health) <= 0)
        {
                VM_RETURN_EDICT(prog->edicts);
                return;
@@ -897,7 +901,7 @@ static void VM_SV_checkpvs(prvm_prog_t *prog)
        VectorCopy(PRVM_G_VECTOR(OFS_PARM0), viewpos);
        viewee = PRVM_G_EDICT(OFS_PARM1);
 
-       if(viewee->priv.server->free)
+       if(viewee->free)
        {
                VM_Warning(prog, "checkpvs: can not check free entity\n");
                PRVM_G_FLOAT(OFS_RETURN) = 4;
@@ -1079,7 +1083,7 @@ static void VM_SV_walkmove(prvm_prog_t *prog)
        vec3_t  move;
        mfunction_t     *oldf;
        int     oldself;
-       qboolean        settrace;
+       qbool   settrace;
 
        VM_SAFEPARMCOUNTRANGE(2, 3, VM_SV_walkmove);
 
@@ -1092,7 +1096,7 @@ static void VM_SV_walkmove(prvm_prog_t *prog)
                VM_Warning(prog, "walkmove: can not modify world entity\n");
                return;
        }
-       if (ent->priv.server->free)
+       if (ent->free)
        {
                VM_Warning(prog, "walkmove: can not modify free entity\n");
                return;
@@ -1147,7 +1151,7 @@ static void VM_SV_droptofloor(prvm_prog_t *prog)
                VM_Warning(prog, "droptofloor: can not modify world entity\n");
                return;
        }
-       if (ent->priv.server->free)
+       if (ent->free)
        {
                VM_Warning(prog, "droptofloor: can not modify free entity\n");
                return;
@@ -1303,7 +1307,7 @@ static void VM_SV_aim(prvm_prog_t *prog)
                VM_Warning(prog, "aim: can not use world entity\n");
                return;
        }
-       if (ent->priv.server->free)
+       if (ent->free)
        {
                VM_Warning(prog, "aim: can not use free entity\n");
                return;
@@ -1531,7 +1535,7 @@ static void VM_SV_makestatic(prvm_prog_t *prog)
                VM_Warning(prog, "makestatic: can not modify world entity\n");
                return;
        }
-       if (ent->priv.server->free)
+       if (ent->free)
        {
                VM_Warning(prog, "makestatic: can not modify free entity\n");
                return;
@@ -1541,17 +1545,17 @@ static void VM_SV_makestatic(prvm_prog_t *prog)
        if (PRVM_serveredictfloat(ent, modelindex) >= 256 || PRVM_serveredictfloat(ent, frame) >= 256)
                large = true;
 
-       if (large)
+       if (sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3)
        {
-               MSG_WriteByte (&sv.signon,svc_spawnstatic2);
+               MSG_WriteByte (&sv.signon,svc_spawnstatic);
                MSG_WriteShort (&sv.signon, (int)PRVM_serveredictfloat(ent, modelindex));
-               MSG_WriteShort (&sv.signon, (int)PRVM_serveredictfloat(ent, frame));
+               MSG_WriteByte (&sv.signon, (int)PRVM_serveredictfloat(ent, frame));
        }
-       else if (sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3)
+       else if (large)
        {
-               MSG_WriteByte (&sv.signon,svc_spawnstatic);
+               MSG_WriteByte (&sv.signon,svc_spawnstatic2);
                MSG_WriteShort (&sv.signon, (int)PRVM_serveredictfloat(ent, modelindex));
-               MSG_WriteByte (&sv.signon, (int)PRVM_serveredictfloat(ent, frame));
+               MSG_WriteShort (&sv.signon, (int)PRVM_serveredictfloat(ent, frame));
        }
        else
        {
@@ -1764,7 +1768,7 @@ static void VM_SV_copyentity(prvm_prog_t *prog)
                VM_Warning(prog, "copyentity: can not read world entity\n");
                return;
        }
-       if (in->priv.server->free)
+       if (in->free)
        {
                VM_Warning(prog, "copyentity: can not read free entity\n");
                return;
@@ -1775,7 +1779,7 @@ static void VM_SV_copyentity(prvm_prog_t *prog)
                VM_Warning(prog, "copyentity: can not modify world entity\n");
                return;
        }
-       if (out->priv.server->free)
+       if (out->free)
        {
                VM_Warning(prog, "copyentity: can not modify free entity\n");
                return;
@@ -2355,7 +2359,7 @@ static void VM_SV_clientcommand(prvm_prog_t *prog)
 
        temp_client = host_client;
        host_client = svs.clients + i;
-       Cmd_ExecuteString(&cmd_serverfromclient, PRVM_G_STRING(OFS_PARM1), src_client, true);
+       Cmd_ExecuteString(cmd_serverfromclient, PRVM_G_STRING(OFS_PARM1), src_client, true);
        host_client = temp_client;
 }
 
@@ -2365,7 +2369,7 @@ static void VM_SV_setattachment(prvm_prog_t *prog)
        prvm_edict_t *e = PRVM_G_EDICT(OFS_PARM0);
        prvm_edict_t *tagentity = PRVM_G_EDICT(OFS_PARM1);
        const char *tagname = PRVM_G_STRING(OFS_PARM2);
-       dp_model_t *model;
+       model_t *model;
        int tagindex;
        VM_SAFEPARMCOUNT(3, VM_SV_setattachment);
 
@@ -2374,7 +2378,7 @@ static void VM_SV_setattachment(prvm_prog_t *prog)
                VM_Warning(prog, "setattachment: can not modify world entity\n");
                return;
        }
-       if (e->priv.server->free)
+       if (e->free)
        {
                VM_Warning(prog, "setattachment: can not modify free entity\n");
                return;
@@ -2419,7 +2423,7 @@ static int SV_GetTagIndex (prvm_prog_t *prog, prvm_edict_t *e, const char *tagna
 static int SV_GetExtendedTagInfo (prvm_prog_t *prog, prvm_edict_t *e, int tagindex, int *parentindex, const char **tagname, matrix4x4_t *tag_localmatrix)
 {
        int r;
-       dp_model_t *model;
+       model_t *model;
 
        *tagname = NULL;
        *parentindex = 0;
@@ -2438,7 +2442,7 @@ static int SV_GetExtendedTagInfo (prvm_prog_t *prog, prvm_edict_t *e, int tagind
        return 1;
 }
 
-void SV_GetEntityMatrix (prvm_prog_t *prog, prvm_edict_t *ent, matrix4x4_t *out, qboolean viewmatrix)
+void SV_GetEntityMatrix (prvm_prog_t *prog, prvm_edict_t *ent, matrix4x4_t *out, qbool viewmatrix)
 {
        float scale;
        float pitchsign = 1;
@@ -2458,7 +2462,7 @@ void SV_GetEntityMatrix (prvm_prog_t *prog, prvm_edict_t *ent, matrix4x4_t *out,
 
 static int SV_GetEntityLocalTagMatrix(prvm_prog_t *prog, prvm_edict_t *ent, int tagindex, matrix4x4_t *out)
 {
-       dp_model_t *model;
+       model_t *model;
        if (tagindex >= 0 && (model = SV_GetModelFromEdict(ent)) && model->animscenes)
        {
                VM_GenerateFrameGroupBlend(prog, ent->priv.server->framegroupblend, ent);
@@ -2477,21 +2481,18 @@ static int SV_GetEntityLocalTagMatrix(prvm_prog_t *prog, prvm_edict_t *ent, int
 // 3 - null or non-precached model
 // 4 - no tags with requested index
 // 5 - runaway loop at attachment chain
-extern cvar_t cl_bob;
-extern cvar_t cl_bobcycle;
-extern cvar_t cl_bobup;
 static int SV_GetTagMatrix (prvm_prog_t *prog, matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
 {
        int ret;
        int modelindex, attachloop;
        matrix4x4_t entitymatrix, tagmatrix, attachmatrix;
-       dp_model_t *model;
+       model_t *model;
 
        *out = identitymatrix; // warnings and errors return identical matrix
 
        if (ent == prog->edicts)
                return 1;
-       if (ent->priv.server->free)
+       if (ent->free)
                return 2;
 
        modelindex = (int)PRVM_serveredictfloat(ent, modelindex);
@@ -2538,29 +2539,6 @@ static int SV_GetTagMatrix (prvm_prog_t *prog, matrix4x4_t *out, prvm_edict_t *e
 
                SV_GetEntityMatrix(prog, ent, &entitymatrix, true);
                Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
-
-               /*
-               // Cl_bob, ported from rendering code
-               if (PRVM_serveredictfloat(ent, health) > 0 && cl_bob.value && cl_bobcycle.value)
-               {
-                       double bob, cycle;
-                       // LadyHavoc: this code is *weird*, but not replacable (I think it
-                       // should be done in QC on the server, but oh well, quake is quake)
-                       // LadyHavoc: figured out bobup: the time at which the sin is at 180
-                       // degrees (which allows lengthening or squishing the peak or valley)
-                       cycle = sv.time/cl_bobcycle.value;
-                       cycle -= (int)cycle;
-                       if (cycle < cl_bobup.value)
-                               cycle = sin(M_PI * cycle / cl_bobup.value);
-                       else
-                               cycle = sin(M_PI + M_PI * (cycle-cl_bobup.value)/(1.0 - cl_bobup.value));
-                       // bob is proportional to velocity in the xy plane
-                       // (don't count Z, or jumping messes it up)
-                       bob = sqrt(PRVM_serveredictvector(ent, velocity)[0]*PRVM_serveredictvector(ent, velocity)[0] + PRVM_serveredictvector(ent, velocity)[1]*PRVM_serveredictvector(ent, velocity)[1])*cl_bob.value;
-                       bob = bob*0.3 + bob*0.7*cycle;
-                       Matrix4x4_AdjustOrigin(out, 0, 0, bound(-7, bob, 4));
-               }
-               */
        }
        return 0;
 }
@@ -2583,7 +2561,7 @@ static void VM_SV_gettagindex(prvm_prog_t *prog)
                VM_Warning(prog, "VM_SV_gettagindex(entity #%i): can't affect world entity\n", PRVM_NUM_FOR_EDICT(ent));
                return;
        }
-       if (ent->priv.server->free)
+       if (ent->free)
        {
                VM_Warning(prog, "VM_SV_gettagindex(entity #%i): can't affect free entity\n", PRVM_NUM_FOR_EDICT(ent));
                return;
@@ -2613,7 +2591,7 @@ static void VM_SV_gettaginfo(prvm_prog_t *prog)
        const char *tagname;
        int returncode;
        vec3_t forward, left, up, origin;
-       const dp_model_t *model;
+       const model_t *model;
 
        VM_SAFEPARMCOUNT(2, VM_SV_gettaginfo);
 
@@ -2679,7 +2657,7 @@ static void VM_SV_dropclient(prvm_prog_t *prog)
        }
        oldhostclient = host_client;
        host_client = svs.clients + clientnum;
-       SV_DropClient(false);
+       SV_DropClient(false, "Client dropped");
        host_client = oldhostclient;
 }
 
@@ -2742,7 +2720,7 @@ static void VM_SV_serverkey(prvm_prog_t *prog)
 static void VM_SV_setmodelindex(prvm_prog_t *prog)
 {
        prvm_edict_t    *e;
-       dp_model_t      *mod;
+       model_t *mod;
        int             i;
        VM_SAFEPARMCOUNT(2, VM_SV_setmodelindex);
 
@@ -2752,7 +2730,7 @@ static void VM_SV_setmodelindex(prvm_prog_t *prog)
                VM_Warning(prog, "setmodelindex: can not modify world entity\n");
                return;
        }
-       if (e->priv.server->free)
+       if (e->free)
        {
                VM_Warning(prog, "setmodelindex: can not modify free entity\n");
                return;
@@ -2872,6 +2850,20 @@ static void VM_SV_pointparticles(prvm_prog_t *prog)
        SV_FlushBroadcastMessages();
 }
 
+qbool SV_VM_ConsoleCommand (const char *text)
+{
+       prvm_prog_t *prog = SVVM_prog;
+       return PRVM_ConsoleCommand(prog, text, &prog->funcoffsets.ConsoleCmd, true, PRVM_EDICT_TO_PROG(sv.world.prog->edicts), sv.time,  !(!sv.active || !prog || !prog->loaded), "QC function ConsoleCmd is missing"); 
+}
+
+// #352 void(string cmdname) registercommand (EXT_CSQC)
+static void VM_SV_registercommand (prvm_prog_t *prog)
+{
+       VM_SAFEPARMCOUNT(1, VM_SV_registercmd);
+       if(!Cmd_Exists(cmd_local, PRVM_G_STRING(OFS_PARM0)))
+               Cmd_AddCommand(CF_SERVER, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
+}
+
 //PF_setpause,    // void(float pause) setpause        = #531;
 static void VM_SV_setpause(prvm_prog_t *prog) {
        int pauseValue;
@@ -2894,7 +2886,7 @@ static void VM_SV_setpause(prvm_prog_t *prog) {
 static void VM_SV_skel_create(prvm_prog_t *prog)
 {
        int modelindex = (int)PRVM_G_FLOAT(OFS_PARM0);
-       dp_model_t *model = SV_GetModelByIndex(modelindex);
+       model_t *model = SV_GetModelByIndex(modelindex);
        skeleton_t *skeleton;
        int i;
        PRVM_G_FLOAT(OFS_RETURN) = 0;
@@ -2924,7 +2916,7 @@ static void VM_SV_skel_build(prvm_prog_t *prog)
        float retainfrac = PRVM_G_FLOAT(OFS_PARM3);
        int firstbone = PRVM_G_FLOAT(OFS_PARM4) - 1;
        int lastbone = PRVM_G_FLOAT(OFS_PARM5) - 1;
-       dp_model_t *model = SV_GetModelByIndex(modelindex);
+       model_t *model = SV_GetModelByIndex(modelindex);
        int numblends;
        int bonenum;
        int blendindex;
@@ -3167,7 +3159,7 @@ static void VM_SV_skel_delete(prvm_prog_t *prog)
 static void VM_SV_frameforname(prvm_prog_t *prog)
 {
        int modelindex = (int)PRVM_G_FLOAT(OFS_PARM0);
-       dp_model_t *model = SV_GetModelByIndex(modelindex);
+       model_t *model = SV_GetModelByIndex(modelindex);
        const char *name = PRVM_G_STRING(OFS_PARM1);
        int i;
        PRVM_G_FLOAT(OFS_RETURN) = -1;
@@ -3187,7 +3179,7 @@ static void VM_SV_frameforname(prvm_prog_t *prog)
 static void VM_SV_frameduration(prvm_prog_t *prog)
 {
        int modelindex = (int)PRVM_G_FLOAT(OFS_PARM0);
-       dp_model_t *model = SV_GetModelByIndex(modelindex);
+       model_t *model = SV_GetModelByIndex(modelindex);
        int framenum = (int)PRVM_G_FLOAT(OFS_PARM1);
        PRVM_G_FLOAT(OFS_RETURN) = 0;
        if (!model || !model->animscenes || framenum < 0 || framenum >= model->numframes)
@@ -3445,7 +3437,7 @@ NULL,                                                     // #241
 NULL,                                                  // #242
 NULL,                                                  // #243
 NULL,                                                  // #244
-NULL,                                                  // #245
+VM_modulo,                                             // #245
 NULL,                                                  // #246
 NULL,                                                  // #247
 NULL,                                                  // #248
@@ -3553,7 +3545,7 @@ NULL,                                                     // #348 string(float playernum, string keyname) getplayerkeyvalue (E
 NULL,                                                  // #349 float() isdemo (EXT_CSQC)
 VM_isserver,                                   // #350 float() isserver (EXT_CSQC)
 NULL,                                                  // #351 void(vector origin, vector forward, vector right, vector up) SetListener (EXT_CSQC)
-NULL,                                                  // #352 void(string cmdname) registercommand (EXT_CSQC)
+VM_SV_registercommand,                 // #352 void(string cmdname) registercommand (EXT_CSQC)
 VM_wasfreed,                                   // #353 float(entity ent) wasfreed (EXT_CSQC) (should be availabe on server too)
 VM_SV_serverkey,                               // #354 string(string key) serverkey (EXT_CSQC)
 NULL,                                                  // #355