]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_cmds.c
Added CL_Shutdown which took care of 14 memory leaks totaling over 30mb. (needs more...
[xonotic/darkplaces.git] / pr_cmds.c
index d35fe2f0f10ffdd1b1262fdf46f5aa85c5cd9425..a888644932c9317dd1caedcb41e493f68c293394 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -70,6 +70,8 @@ void PF_VarString(int first, char *out, int outlength)
 }
 
 char *ENGINE_EXTENSIONS =
+"DP_BUTTONCHAT "
+"DP_BUTTONUSE "
 "DP_CL_LOADSKY "
 "DP_CON_SET "
 "DP_CON_SETA "
@@ -133,6 +135,7 @@ char *ENGINE_EXTENSIONS =
 "DP_SND_STEREOWAV "
 "DP_SOLIDCORPSE "
 "DP_SPRITE32 "
+"DP_SV_BOTCLIENT "
 "DP_SV_CLIENTCOLORS "
 "DP_SV_CLIENTNAME "
 "DP_SV_DRAWONLYTOCLIENT "
@@ -164,8 +167,11 @@ char *ENGINE_EXTENSIONS =
 "NEH_CMD_PLAY2 "
 "NEH_RESTOREGAME "
 "NXQ_GFX_LETTERBOX "
+"PRYDON_CLIENTCURSOR "
 "TENEBRAE_GFX_DLIGHTS "
 "TW_SV_STEPCONTROL "
+"NEXUIZ_PLAYERMODEL "
+"NEXUIZ_PLAYERSKIN "
 ;
 
 qboolean checkextension(char *name)
@@ -350,10 +356,10 @@ PF_setmodel
 setmodel(entity, model)
 =================
 */
+static vec3_t quakemins = {-16, -16, -16}, quakemaxs = {16, 16, 16};
 void PF_setmodel (void)
 {
        edict_t *e;
-       char    *m, **check;
        model_t *mod;
        int             i;
 
@@ -362,24 +368,19 @@ void PF_setmodel (void)
                PF_WARNING("setmodel: can not modify world entity\n");
        if (e->e->free)
                PF_WARNING("setmodel: can not modify free entity\n");
-       m = G_STRING(OFS_PARM1);
-
-// check to see if model was properly precached
-       for (i=0, check = sv.model_precache ; *check ; i++, check++)
-               if (!strcmp(*check, m))
-                       break;
-
-       if (!*check)
-               PF_WARNING(va("setmodel: no precache for model \"%s\"\n", m));
-
-
-       e->v->model = PR_SetString(*check);
+       i = SV_ModelIndex(G_STRING(OFS_PARM1), 1);
+       e->v->model = PR_SetString(sv.model_precache[i]);
        e->v->modelindex = i;
 
-       mod = sv.models[ (int)e->v->modelindex];
+       mod = sv.models[i];
 
        if (mod)
-               SetMinMaxSize (e, mod->normalmins, mod->normalmaxs, true);
+       {
+               if (mod->type != mod_alias || sv_gameplayfix_setmodelrealbox.integer)
+                       SetMinMaxSize (e, mod->normalmins, mod->normalmaxs, true);
+               else
+                       SetMinMaxSize (e, quakemins, quakemaxs, true);
+       }
        else
                SetMinMaxSize (e, vec3_origin, vec3_origin, true);
 }
@@ -593,11 +594,7 @@ random()
 */
 void PF_random (void)
 {
-       float           num;
-
-       num = (rand ()&0x7fff) / ((float)0x7fff);
-
-       G_FLOAT(OFS_RETURN) = num;
+       G_FLOAT(OFS_RETURN) = lhrandom(0, 1);
 }
 
 /*
@@ -629,7 +626,6 @@ PF_ambientsound
 */
 void PF_ambientsound (void)
 {
-       char            **check;
        char            *samp;
        float           *pos;
        float           vol, attenuation;
@@ -641,15 +637,9 @@ void PF_ambientsound (void)
        attenuation = G_FLOAT(OFS_PARM3);
 
 // check to see if samp was properly precached
-       for (soundnum=0, check = sv.sound_precache ; *check ; check++, soundnum++)
-               if (!strcmp(*check,samp))
-                       break;
-
-       if (!*check)
-       {
-               Con_Printf("no precache: %s\n", samp);
+       soundnum = SV_SoundIndex(samp, 1);
+       if (!soundnum)
                return;
-       }
 
        large = false;
        if (soundnum >= 256)
@@ -1359,59 +1349,17 @@ void PF_precache_file (void)
        G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
 }
 
+
 void PF_precache_sound (void)
 {
-       char    *s;
-       int             i;
-       int             limit = (sv.protocol == PROTOCOL_QUAKE ? 256 : MAX_SOUNDS);
-
-       if (sv.state != ss_loading)
-               PF_ERROR("PF_Precache_*: Precache can only be done in spawn functions");
-
-       s = G_STRING(OFS_PARM0);
+       SV_SoundIndex(G_STRING(OFS_PARM0), 2);
        G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
-       PR_CheckEmptyString (s);
-
-       for (i=0 ; i<limit ; i++)
-       {
-               if (!sv.sound_precache[i])
-               {
-                       sv.sound_precache[i] = s;
-                       return;
-               }
-               if (!strcmp(sv.sound_precache[i], s))
-                       return;
-       }
-       PF_ERROR("PF_precache_sound: overflow");
 }
 
 void PF_precache_model (void)
 {
-       char    *s;
-       int             i;
-       int             limit = (sv.protocol == PROTOCOL_QUAKE ? 256 : MAX_MODELS);
-
-       if (sv.state != ss_loading)
-               PF_ERROR("PF_Precache_*: Precache can only be done in spawn functions");
-
-       s = G_STRING(OFS_PARM0);
-       if (sv.worldmodel->brush.ishlbsp && ((!s) || (!s[0])))
-               return;
+       SV_ModelIndex(G_STRING(OFS_PARM0), 2);
        G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
-       PR_CheckEmptyString (s);
-
-       for (i = 0;i < limit;i++)
-       {
-               if (!sv.model_precache[i])
-               {
-                       sv.model_precache[i] = s;
-                       sv.models[i] = Mod_ForName (s, true, false, false);
-                       return;
-               }
-               if (!strcmp(sv.model_precache[i], s))
-                       return;
-       }
-       PF_ERROR("PF_precache_model: overflow");
 }
 
 
@@ -2253,8 +2201,8 @@ void PF_effect (void)
        if (!s || !s[0])
                PF_WARNING("effect: no model specified\n");
 
-       i = SV_ModelIndex(s);
-       if (i < 0)
+       i = SV_ModelIndex(s, 1);
+       if (!i)
                PF_WARNING("effect: model not precached\n");
        SV_StartEffect(G_VECTOR(OFS_PARM0), i, G_FLOAT(OFS_PARM2), G_FLOAT(OFS_PARM3), G_FLOAT(OFS_PARM4));
 }
@@ -2841,7 +2789,7 @@ void PF_stof(void)
 //float(string filename, float mode) fopen = #110; // opens a file inside quake/gamedir/data/ (mode is FILE_READ, FILE_APPEND, or FILE_WRITE), returns fhandle >= 0 if successful, or fhandle < 0 if unable to open file for any reason
 void PF_fopen(void)
 {
-       int filenum, mode, i;
+       int filenum, mode;
        char *modestring, *filename;
        for (filenum = 0;filenum < MAX_PRFILES;filenum++)
                if (pr_files[filenum] == NULL)
@@ -2870,21 +2818,7 @@ void PF_fopen(void)
                return;
        }
        filename = G_STRING(OFS_PARM0);
-       // control characters do not cause issues with any platforms I know of, but they are usually annoying to deal with
-       // ../ is parent directory on many platforms
-       // // is parent directory on Amiga
-       // / at the beginning of a path is root on unix, and parent directory on Amiga
-       // : is root of drive on Amiga (also used as a directory separator on Mac, but / works there too, so that's a bad idea)
-       // \ is a windows-ism (so it's naughty to use it, / works on all platforms)
-       for (i = 0;filename[i];i++)
-       {
-               if (filename[i] < ' ' || (filename[i] == '/' && filename[i+1] == '/') || (filename[i] == '.' && filename[i+1] == '.') || filename[i] == ':' || filename[i] == '\\' || filename[0] == '/')
-               {
-                       Con_Printf("PF_fopen: dangerous/confusing/annoying/non-portable filename \"%s\" not allowed. (contains control characters or // or .. or : or \\ or begins with /)\n", filename);
-                       G_FLOAT(OFS_RETURN) = -4;
-                       return;
-               }
-       }
+       // -4 failure (dangerous/non-portable filename) removed, FS_Open checks
        pr_files[filenum] = FS_Open(va("data/%s", filename), modestring, false);
 
        if (pr_files[filenum] == NULL && modestring == "rb")
@@ -3148,7 +3082,10 @@ int SV_GetTagIndex (edict_t *e, char *tagname)
        int tagindex, i;
        model_t *model;
 
-       model = sv.models[(int)e->v->modelindex];
+       i = e->v->modelindex;
+       if (i < 1 || i >= MAX_MODELS)
+               return -1;
+       model = sv.models[i];
 
        tagindex = -1;
        if (model->data_overridetagnamesforskin && (unsigned int)e->v->skin < (unsigned int)model->numskins && model->data_overridetagnamesforskin[(unsigned int)e->v->skin].num_overridetagnames)
@@ -3236,14 +3173,18 @@ int SV_GetTagMatrix (matrix4x4_t *out, edict_t *ent, int tagindex)
                {
                        attachent = EDICT_NUM(val->edict); // to this it entity our entity is attached
                        val = GETEDICTFIELDVALUE(ent, eval_tag_index);
-                       if (val->_float) 
-                       {// got tagname on parent entity attachment tag via tag_index (and got it's matrix)
+                       Matrix4x4_CreateIdentity(&attachmatrix);
+                       if (val->_float >= 1 && attachent->v->modelindex >= 1 && attachent->v->modelindex < MAX_MODELS)
+                       {
                                model = sv.models[(int)attachent->v->modelindex];
-                               reqtag = (val->_float - 1) + attachent->v->frame*model->alias.aliasnum_tags;
-                               Matrix4x4_Copy(&attachmatrix, &model->alias.aliasdata_tags[reqtag].matrix);
+                               if (val->_float < model->alias.aliasnum_tags)
+                               {
+                                       // got tagname on parent entity attachment tag via tag_index (and got it's matrix)
+                                       model = sv.models[(int)attachent->v->modelindex];
+                                       reqtag = (val->_float - 1) + attachent->v->frame*model->alias.aliasnum_tags;
+                                       Matrix4x4_Copy(&attachmatrix, &model->alias.aliasdata_tags[reqtag].matrix);
+                               }
                        }
-                       else
-                               Matrix4x4_CreateIdentity(&attachmatrix);
 
                        // apply transformation by child entity matrix
                        val = GETEDICTFIELDVALUE(ent, eval_scale);
@@ -3267,7 +3208,7 @@ int SV_GetTagMatrix (matrix4x4_t *out, edict_t *ent, int tagindex)
                        attachloop += 1;
                        if (attachloop > 255) // prevent runaway looping
                                return 5;
-               } 
+               }
                while ((val = GETEDICTFIELDVALUE(ent, eval_tag_entity)) && val->edict);
        }
 
@@ -3567,6 +3508,40 @@ void PF_dropclient (void)
        host_client = oldhostclient;
 }
 
+//entity() spawnclient (DP_SV_BOTCLIENT)
+void PF_spawnclient (void)
+{
+       int i;
+       edict_t *ed;
+       pr_xfunction->builtinsprofile += 2;
+       ed = sv.edicts;
+       for (i = 0;i < svs.maxclients;i++)
+       {
+               if (!svs.clients[i].active)
+               {
+                       pr_xfunction->builtinsprofile += 100;
+                       SV_ConnectClient (i, NULL);
+                       ed = EDICT_NUM(i + 1);
+                       break;
+               }
+       }
+       RETURN_EDICT(ed);
+}
+
+//float(entity clent) clienttype (DP_SV_BOTCLIENT)
+void PF_clienttype (void)
+{
+       int clientnum;
+       clientnum = G_EDICTNUM(OFS_PARM0) - 1;
+       if (clientnum < 0 || clientnum >= svs.maxclients)
+               G_FLOAT(OFS_RETURN) = 3;
+       else if (!svs.clients[clientnum].active)
+               G_FLOAT(OFS_RETURN) = 0;
+       else if (svs.clients[clientnum].netconnection)
+               G_FLOAT(OFS_RETURN) = 1;
+       else
+               G_FLOAT(OFS_RETURN) = 2;
+}
 
 builtin_t pr_builtin[] =
 {
@@ -3748,8 +3723,8 @@ PF_findchainflags,                        // #450 entity(.float fld, float match) findchainflags (DP_
 PF_gettagindex,                                // #451 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO)
 PF_gettaginfo,                         // #452 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO)
 PF_dropclient,                         // #453 void(entity clent) dropclient (DP_SV_DROPCLIENT)
-NULL,                                          // #454
-NULL,                                          // #455
+PF_spawnclient,                                // #454 entity() spawnclient (DP_SV_BOTCLIENT)
+PF_clienttype,                         // #455 float(entity clent) clienttype (DP_SV_BOTCLIENT)
 NULL,                                          // #456
 NULL,                                          // #457
 NULL,                                          // #458