]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
-Added the cvar sv_progs, which allows you to set the name of the server
[xonotic/darkplaces.git] / pr_edict.c
index c3595f718299ed8f956ca4b5425fc38eeb97074e..2ea21f97ffde0ba94e64756c11d6b2d90e3174cd 100644 (file)
@@ -92,6 +92,8 @@ int eval_button5;
 int eval_button6;
 int eval_button7;
 int eval_button8;
+int eval_buttonuse;
+int eval_buttonchat;
 int eval_glow_size;
 int eval_glow_trail;
 int eval_glow_color;
@@ -126,6 +128,14 @@ int eval_light_lev;
 int eval_color;
 int eval_style;
 int eval_pflags;
+int eval_cursor_active;
+int eval_cursor_screen;
+int eval_cursor_trace_start;
+int eval_cursor_trace_endpos;
+int eval_cursor_trace_ent;
+int eval_colormod;
+int eval_playermodel;
+int eval_playerskin;
 
 mfunction_t *SV_PlayerPhysicsQC;
 mfunction_t *EndFrameQC;
@@ -150,6 +160,8 @@ void FindEdictFieldOffsets(void)
        eval_button6 = FindFieldOffset("button6");
        eval_button7 = FindFieldOffset("button7");
        eval_button8 = FindFieldOffset("button8");
+       eval_buttonuse = FindFieldOffset("buttonuse");
+       eval_buttonchat = FindFieldOffset("buttonchat");
        eval_glow_size = FindFieldOffset("glow_size");
        eval_glow_trail = FindFieldOffset("glow_trail");
        eval_glow_color = FindFieldOffset("glow_color");
@@ -184,6 +196,14 @@ void FindEdictFieldOffsets(void)
        eval_color = FindFieldOffset("color");
        eval_style = FindFieldOffset("style");
        eval_pflags = FindFieldOffset("pflags");
+       eval_cursor_active = FindFieldOffset("cursor_active");
+       eval_cursor_screen = FindFieldOffset("cursor_screen");
+       eval_cursor_trace_start = FindFieldOffset("cursor_trace_start");
+       eval_cursor_trace_endpos = FindFieldOffset("cursor_trace_endpos");
+       eval_cursor_trace_ent = FindFieldOffset("cursor_trace_ent");
+       eval_colormod = FindFieldOffset("colormod");
+       eval_playermodel = FindFieldOffset("playermodel");
+       eval_playerskin = FindFieldOffset("playerskin");
 
        // LordHavoc: allowing QuakeC to override the player movement code
        SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics");
@@ -209,9 +229,21 @@ void ED_ClearEdict (edict_t *e)
        num = NUM_FOR_EDICT(e) - 1;
        if (num >= 0 && num < svs.maxclients)
        {
+               eval_t *val;
+               // set colormap and team on newly created player entity
                e->v->colormap = num + 1;
                e->v->team = (svs.clients[num].colors & 15) + 1;
+               // set netname/clientcolors back to client values so that
+               // DP_SV_CLIENTNAME and DPV_SV_CLIENTCOLORS will not immediately
+               // reset them
                e->v->netname = PR_SetString(svs.clients[num].name);
+               if ((val = GETEDICTFIELDVALUE(e, eval_clientcolors)))
+                       val->_float = svs.clients[num].colors;
+               // NEXUIZ_PLAYERMODEL and NEXUIZ_PLAYERSKIN
+               if( eval_playermodel )
+                       GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PR_SetString(svs.clients[num].playermodel);
+               if( eval_playerskin )
+                       GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PR_SetString(svs.clients[num].playerskin);
        }
 }
 
@@ -401,7 +433,7 @@ char *PR_ValueString (etype_t type, eval_t *val)
        switch (type)
        {
        case ev_string:
-               snprintf (line, sizeof (line), "%s", PR_GetString(val->string));
+               strlcpy (line, PR_GetString (val->string), sizeof (line));
                break;
        case ev_entity:
                //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict));
@@ -489,7 +521,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val)
                break;
        case ev_function:
                f = pr_functions + val->function;
-               snprintf (line, sizeof (line), "%s", PR_GetString(f->s_name));
+               strlcpy (line, PR_GetString (f->s_name), sizeof (line));
                break;
        case ev_field:
                def = ED_FieldAtOfs ( val->_int );
@@ -576,7 +608,7 @@ For debugging
 */
 // LordHavoc: optimized this to print out much more quickly (tempstring)
 // LordHavoc: changed to print out every 4096 characters (incase there are a lot of fields to print)
-void ED_Print (edict_t *ed)
+void ED_Print(edict_t *ed)
 {
        int             l;
        ddef_t  *d;
@@ -588,7 +620,7 @@ void ED_Print (edict_t *ed)
 
        if (ed->e->free)
        {
-               Con_Print("FREE\n");
+               Con_Print("FREE\n");
                return;
        }
 
@@ -614,7 +646,7 @@ void ED_Print (edict_t *ed)
 
                if (strlen(name) > 256)
                {
-                       strncpy(tempstring2, name, 256);
+                       memcpy (tempstring2, name, 256);
                        tempstring2[256] = tempstring2[257] = tempstring2[258] = '.';
                        tempstring2[259] = 0;
                        name = tempstring2;
@@ -627,7 +659,7 @@ void ED_Print (edict_t *ed)
                name = PR_ValueString(d->type, (eval_t *)v);
                if (strlen(name) > 256)
                {
-                       strncpy(tempstring2, name, 256);
+                       memcpy(tempstring2, name, 256);
                        tempstring2[256] = tempstring2[257] = tempstring2[258] = '.';
                        tempstring2[259] = 0;
                        name = tempstring2;
@@ -636,12 +668,12 @@ void ED_Print (edict_t *ed)
                strlcat (tempstring, "\n", sizeof (tempstring));
                if (strlen(tempstring) >= 4096)
                {
-                       Con_Printf("%s", tempstring);
+                       Con_Print(tempstring);
                        tempstring[0] = 0;
                }
        }
        if (tempstring[0])
-               Con_Printf("%s", tempstring);
+               Con_Print(tempstring);
 }
 
 /*
@@ -659,11 +691,11 @@ void ED_Write (qfile_t *f, edict_t *ed)
        char    *name;
        int             type;
 
-       FS_Print(f, "{\n");
+       FS_Print(f, "{\n");
 
        if (ed->e->free)
        {
-               FS_Print(f, "}\n");
+               FS_Print(f, "}\n");
                return;
        }
 
@@ -684,16 +716,16 @@ void ED_Write (qfile_t *f, edict_t *ed)
                if (j == type_size[type])
                        continue;
 
-               FS_Printf (f,"\"%s\" ",name);
-               FS_Printf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
+               FS_Printf(f,"\"%s\" ",name);
+               FS_Printf(f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
        }
 
-       FS_Print(f, "}\n");
+       FS_Print(f, "}\n");
 }
 
 void ED_PrintNum (int ent)
 {
-       ED_Print (EDICT_NUM(ent));
+       ED_Print(EDICT_NUM(ent));
 }
 
 /*
@@ -707,7 +739,7 @@ void ED_PrintEdicts (void)
 {
        int             i;
 
-       Con_Printf ("%i entities\n", sv.num_edicts);
+       Con_Printf("%i entities\n", sv.num_edicts);
        for (i=0 ; i<sv.num_edicts ; i++)
                ED_PrintNum (i);
 }
@@ -726,7 +758,7 @@ void ED_PrintEdict_f (void)
        i = atoi (Cmd_Argv(1));
        if (i < 0 || i >= sv.num_edicts)
        {
-               Con_Printf("Bad edict number\n");
+               Con_Print("Bad edict number\n");
                return;
        }
        ED_PrintNum (i);
@@ -760,11 +792,11 @@ void ED_Count (void)
                        step++;
        }
 
-       Con_Printf ("num_edicts:%3i\n", sv.num_edicts);
-       Con_Printf ("active    :%3i\n", active);
-       Con_Printf ("view      :%3i\n", models);
-       Con_Printf ("touch     :%3i\n", solid);
-       Con_Printf ("step      :%3i\n", step);
+       Con_Printf("num_edicts:%3i\n", sv.num_edicts);
+       Con_Printf("active    :%3i\n", active);
+       Con_Printf("view      :%3i\n", models);
+       Con_Printf("touch     :%3i\n", solid);
+       Con_Printf("step      :%3i\n", step);
 
 }
 
@@ -789,7 +821,7 @@ void ED_WriteGlobals (qfile_t *f)
        char            *name;
        int                     type;
 
-       FS_Print(f,"{\n");
+       FS_Print(f,"{\n");
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
@@ -802,10 +834,10 @@ void ED_WriteGlobals (qfile_t *f)
                        continue;
 
                name = PR_GetString(def->s_name);
-               FS_Printf (f,"\"%s\" ", name);
-               FS_Printf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
+               FS_Printf(f,"\"%s\" ", name);
+               FS_Printf(f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
        }
-       FS_Print(f,"}\n");
+       FS_Print(f,"}\n");
 }
 
 /*
@@ -822,7 +854,7 @@ void ED_EdictSet_f(void)
 
        if(Cmd_Argc() != 4)
        {
-               Con_Printf("edictset <edict number> <field> <value>\n");
+               Con_Print("edictset <edict number> <field> <value>\n");
                return;
        }
        ed = EDICT_NUM(atoi(Cmd_Argv(1)));
@@ -866,7 +898,7 @@ void ED_ParseGlobals (const char *data)
                key = ED_FindGlobal (keyname);
                if (!key)
                {
-                       Con_DPrintf ("'%s' is not a global\n", keyname);
+                       Con_DPrintf("'%s' is not a global\n", keyname);
                        continue;
                }
 
@@ -946,13 +978,12 @@ qboolean ED_ParseEpair(edict_t *ent, ddef_t *key, const char *s)
                {
                        while (*s && *s <= ' ')
                                s++;
-                       if (!*s)
-                               break;
-                       val->vector[i] = atof(s);
+                       if (*s)
+                               val->vector[i] = atof(s);
+                       else
+                               val->vector[i] = 0;
                        while (*s > ' ')
                                s++;
-                       if (!*s)
-                               break;
                }
                break;
 
@@ -977,14 +1008,15 @@ qboolean ED_ParseEpair(edict_t *ent, ddef_t *key, const char *s)
                        Con_DPrintf("ED_ParseEpair: Can't find field %s\n", s);
                        return false;
                }
-               val->_int = G_INT(def->ofs);
+               //val->_int = G_INT(def->ofs); // AK Please check this - seems to be an org. quake bug
+               val->_int = def->ofs;
                break;
 
        case ev_function:
                func = ED_FindFunction(s);
                if (!func)
                {
-                       Con_Printf ("ED_ParseEpair: Can't find function %s\n", s);
+                       Con_Printf("ED_ParseEpair: Can't find function %s\n", s);
                        return false;
                }
                val->function = func - pr_functions;
@@ -1066,7 +1098,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
                key = ED_FindField (keyname);
                if (!key)
                {
-                       Con_DPrintf ("'%s' is not a field\n", keyname);
+                       Con_DPrintf("'%s' is not a field\n", keyname);
                        continue;
                }
 
@@ -1156,8 +1188,8 @@ void ED_LoadFromFile (const char *data)
 //
                if (!ent->v->classname)
                {
-                       Con_Print("No classname for:\n");
-                       ED_Print (ent);
+                       Con_Print("No classname for:\n");
+                       ED_Print(ent);
                        ED_Free (ent);
                        continue;
                }
@@ -1169,21 +1201,21 @@ void ED_LoadFromFile (const char *data)
                {
                        if (developer.integer) // don't confuse non-developers with errors
                        {
-                               Con_Print("No spawn function for:\n");
-                               ED_Print (ent);
+                               Con_Print("No spawn function for:\n");
+                               ED_Print(ent);
                        }
                        ED_Free (ent);
                        continue;
                }
 
                pr_global_struct->self = EDICT_TO_PROG(ent);
-               PR_ExecuteProgram (func - pr_functions, "");
+               PR_ExecuteProgram (func - pr_functions, "QC function spawn is missing");
                spawned++;
                if (ent->e->free)
                        died++;
        }
 
-       Con_DPrintf ("%i entities parsed, %i inhibited, %i spawned (%i removed self, %i stayed)\n", parsed, inhibited, spawned, died, spawned - died);
+       Con_DPrintf("%i entities parsed, %i inhibited, %i spawned (%i removed self, %i stayed)\n", parsed, inhibited, spawned, died, spawned - died);
 }
 
 
@@ -1198,46 +1230,57 @@ dpfield_t;
 
 dpfield_t dpfields[] =
 {
-       {ev_float, "gravity"},
+       {ev_entity, "cursor_trace_ent"},
+       {ev_entity, "drawonlytoclient"},
+       {ev_entity, "exteriormodeltoclient"},
+       {ev_entity, "nodrawtoclient"},
+       {ev_entity, "tag_entity"},
+       {ev_entity, "viewmodelforclient"},
+       {ev_float, "alpha"},
+       {ev_float, "ammo_cells1"},
+       {ev_float, "ammo_lava_nails"},
+       {ev_float, "ammo_multi_rockets"},
+       {ev_float, "ammo_nails1"},
+       {ev_float, "ammo_plasma"},
+       {ev_float, "ammo_rockets1"},
+       {ev_float, "ammo_shells1"},
        {ev_float, "button3"},
        {ev_float, "button4"},
        {ev_float, "button5"},
        {ev_float, "button6"},
        {ev_float, "button7"},
        {ev_float, "button8"},
+       {ev_float, "buttonchat"},
+       {ev_float, "buttonuse"},
+       {ev_float, "clientcolors"},
+       {ev_float, "cursor_active"},
+       {ev_float, "fullbright"},
+       {ev_float, "glow_color"},
        {ev_float, "glow_size"},
        {ev_float, "glow_trail"},
-       {ev_float, "glow_color"},
-       {ev_float, "items2"},
-       {ev_float, "scale"},
-       {ev_float, "alpha"},
-       {ev_float, "renderamt"},
-       {ev_float, "rendermode"},
-       {ev_float, "fullbright"},
-       {ev_float, "ammo_shells1"},
-       {ev_float, "ammo_nails1"},
-       {ev_float, "ammo_lava_nails"},
-       {ev_float, "ammo_rockets1"},
-       {ev_float, "ammo_multi_rockets"},
-       {ev_float, "ammo_cells1"},
-       {ev_float, "ammo_plasma"},
+       {ev_float, "gravity"},
        {ev_float, "idealpitch"},
-       {ev_float, "pitch_speed"},
-       {ev_entity, "viewmodelforclient"},
-       {ev_entity, "nodrawtoclient"},
-       {ev_entity, "exteriormodeltoclient"},
-       {ev_entity, "drawonlytoclient"},
+       {ev_float, "items2"},
+       {ev_float, "light_lev"},
+       {ev_float, "pflags"},
        {ev_float, "ping"},
-       {ev_vector, "movement"},
+       {ev_float, "pitch_speed"},
        {ev_float, "pmodel"},
-       {ev_vector, "punchvector"},
-       {ev_float, "clientcolors"},
-       {ev_entity, "tag_entity"},
-       {ev_float, "tag_index"},
-       {ev_float, "light_lev"},
-       {ev_float, "color"},
+       {ev_float, "renderamt"}, // HalfLife support
+       {ev_float, "rendermode"}, // HalfLife support
+       {ev_float, "scale"},
        {ev_float, "style"},
-       {ev_float, "pflags"}
+       {ev_float, "tag_index"},
+       {ev_float, "viewzoom"},
+       {ev_vector, "color"},
+       {ev_vector, "colormod"},
+       {ev_vector, "cursor_screen"},
+       {ev_vector, "cursor_trace_endpos"},
+       {ev_vector, "cursor_trace_start"},
+       {ev_vector, "movement"},
+       {ev_vector, "punchvector"},
+       {ev_string, "playermodel"},
+       {ev_string, "playerskin"}
 };
 
 /*
@@ -1246,14 +1289,16 @@ PR_LoadProgs
 ===============
 */
 extern void PR_Cmd_Reset (void);
-void PR_LoadProgs (void)
+void PR_LoadProgs (const char *progsname)
 {
        int i;
        dstatement_t *st;
        ddef_t *infielddefs;
-       void *temp;
        dfunction_t *dfunctions;
 
+       if (!progsname || !*progsname) 
+               Host_Error("PR_LoadProgs: passed empty progsname");
+
 // flush the non-C variable lookup cache
        for (i=0 ; i<GEFV_CACHESIZE ; i++)
                gefvCache[i].field[0] = 0;
@@ -1261,16 +1306,11 @@ void PR_LoadProgs (void)
        Mem_EmptyPool(progs_mempool);
        Mem_EmptyPool(edictstring_mempool);
 
-       temp = FS_LoadFile ("progs.dat", false);
-       if (!temp)
-               Host_Error ("PR_LoadProgs: couldn't load progs.dat");
-
-       progs = (dprograms_t *)Mem_Alloc(progs_mempool, fs_filesize);
-
-       memcpy(progs, temp, fs_filesize);
-       Mem_Free(temp);
+       progs = (dprograms_t *)FS_LoadFile (progsname, progs_mempool, false);
+       if (!progs)
+               Host_Error ("PR_LoadProgs: couldn't load %s", progsname);
 
-       Con_DPrintf ("Programs occupy %iK.\n", fs_filesize/1024);
+       Con_DPrintf("Programs occupy %iK.\n", fs_filesize/1024);
 
        pr_crc = CRC_Block((qbyte *)progs, fs_filesize);
 
@@ -1474,7 +1514,7 @@ void PR_Fields_f (void)
        int *v;
        if (!sv.active)
        {
-               Con_Printf("no progs loaded\n");
+               Con_Print("no progs loaded\n");
                return;
        }
        counts = Mem_Alloc(tempmempool, progs->numfielddefs * sizeof(int));
@@ -1543,7 +1583,7 @@ void PR_Fields_f (void)
                }
                if (strlen(name) > 256)
                {
-                       strncpy(tempstring2, name, 256);
+                       memcpy(tempstring2, name, 256);
                        tempstring2[256] = tempstring2[257] = tempstring2[258] = '.';
                        tempstring2[259] = 0;
                        name = tempstring2;
@@ -1556,7 +1596,7 @@ void PR_Fields_f (void)
                strlcat (tempstring, "\n", sizeof (tempstring));
                if (strlen(tempstring) >= 4096)
                {
-                       Con_Printf("%s", tempstring);
+                       Con_Print(tempstring);
                        tempstring[0] = 0;
                }
                if (counts[i])
@@ -1574,7 +1614,7 @@ void PR_Globals_f (void)
        int i;
        if (!sv.active)
        {
-               Con_Printf("no progs loaded\n");
+               Con_Print("no progs loaded\n");
                return;
        }
        for (i = 0;i < progs->numglobaldefs;i++)
@@ -1630,8 +1670,8 @@ void PR_Init (void)
        Cvar_RegisterVariable (&pr_boundscheck);
        Cvar_RegisterVariable (&pr_traceqc);
 
-       progs_mempool = Mem_AllocPool("progs.dat");
-       edictstring_mempool = Mem_AllocPool("edict strings");
+       progs_mempool = Mem_AllocPool("progs.dat", 0, NULL);
+       edictstring_mempool = Mem_AllocPool("edict strings", 0, NULL);
 
        PR_Cmd_Init();
 }