]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
corrected a few LittleLongs to LittleFloat in md3 loading (EEP those were bad)
[xonotic/darkplaces.git] / pr_edict.c
index db12799b4d7e5d8df22354c22ce31d90b3690f1d..9f22b1e4dae18769f48bf0d44039fbab0d7a176f 100644 (file)
@@ -119,9 +119,14 @@ int eval_movement;
 int eval_pmodel;
 int eval_punchvector;
 int eval_viewzoom;
 int eval_pmodel;
 int eval_punchvector;
 int eval_viewzoom;
+int eval_clientcolors;
+int eval_tag_entity;
+int eval_tag_index;
 
 mfunction_t *SV_PlayerPhysicsQC;
 mfunction_t *EndFrameQC;
 
 mfunction_t *SV_PlayerPhysicsQC;
 mfunction_t *EndFrameQC;
+//KrimZon - SERVER COMMANDS IN QUAKEC
+mfunction_t *SV_ParseClientCommandQC;
 
 int FindFieldOffset(const char *field)
 {
 
 int FindFieldOffset(const char *field)
 {
@@ -168,11 +173,16 @@ void FindEdictFieldOffsets(void)
        eval_pmodel = FindFieldOffset("pmodel");
        eval_punchvector = FindFieldOffset("punchvector");
        eval_viewzoom = FindFieldOffset("viewzoom");
        eval_pmodel = FindFieldOffset("pmodel");
        eval_punchvector = FindFieldOffset("punchvector");
        eval_viewzoom = FindFieldOffset("viewzoom");
+       eval_clientcolors = FindFieldOffset("clientcolors");
+       eval_tag_entity = FindFieldOffset("tag_entity");
+       eval_tag_index = FindFieldOffset("tag_index");
 
        // LordHavoc: allowing QuakeC to override the player movement code
        SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics");
        // LordHavoc: support for endframe
        EndFrameQC = ED_FindFunction ("EndFrame");
 
        // LordHavoc: allowing QuakeC to override the player movement code
        SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics");
        // LordHavoc: support for endframe
        EndFrameQC = ED_FindFunction ("EndFrame");
+       //KrimZon - SERVER COMMANDS IN QUAKEC
+       SV_ParseClientCommandQC = ED_FindFunction ("SV_ParseClientCommand");
 }
 
 /*
 }
 
 /*
@@ -184,8 +194,17 @@ Sets everything to NULL
 */
 void ED_ClearEdict (edict_t *e)
 {
 */
 void ED_ClearEdict (edict_t *e)
 {
+       int num;
        memset (e->v, 0, progs->entityfields * 4);
        memset (e->v, 0, progs->entityfields * 4);
-       e->free = false;
+       e->e->free = false;
+       // LordHavoc: for consistency set these here
+       num = NUM_FOR_EDICT(e) - 1;
+       if (num >= 0 && num < svs.maxclients)
+       {
+               e->v->colormap = num + 1;
+               e->v->team = (svs.clients[num].colors & 15) + 1;
+               e->v->netname = PR_SetString(svs.clients[num].name);
+       }
 }
 
 /*
 }
 
 /*
@@ -209,17 +228,19 @@ edict_t *ED_Alloc (void)
                e = EDICT_NUM(i);
                // the first couple seconds of server time can involve a lot of
                // freeing and allocating, so relax the replacement policy
                e = EDICT_NUM(i);
                // the first couple seconds of server time can involve a lot of
                // freeing and allocating, so relax the replacement policy
-               if (e->free && ( e->freetime < 2 || sv.time - e->freetime > 0.5 ) )
+               if (e->e->free && ( e->e->freetime < 2 || sv.time - e->e->freetime > 0.5 ) )
                {
                        ED_ClearEdict (e);
                        return e;
                }
        }
                {
                        ED_ClearEdict (e);
                        return e;
                }
        }
-       
+
        if (i == MAX_EDICTS)
                Host_Error ("ED_Alloc: no free edicts");
        if (i == MAX_EDICTS)
                Host_Error ("ED_Alloc: no free edicts");
-               
+
        sv.num_edicts++;
        sv.num_edicts++;
+       if (sv.num_edicts >= sv.max_edicts)
+               SV_IncreaseEdicts();
        e = EDICT_NUM(i);
        ED_ClearEdict (e);
 
        e = EDICT_NUM(i);
        ED_ClearEdict (e);
 
@@ -238,7 +259,7 @@ void ED_Free (edict_t *ed)
 {
        SV_UnlinkEdict (ed);            // unlink from world bsp
 
 {
        SV_UnlinkEdict (ed);            // unlink from world bsp
 
-       ed->free = true;
+       ed->e->free = true;
        ed->v->model = 0;
        ed->v->takedamage = 0;
        ed->v->modelindex = 0;
        ed->v->model = 0;
        ed->v->takedamage = 0;
        ed->v->modelindex = 0;
@@ -249,8 +270,8 @@ void ED_Free (edict_t *ed)
        VectorClear(ed->v->angles);
        ed->v->nextthink = -1;
        ed->v->solid = 0;
        VectorClear(ed->v->angles);
        ed->v->nextthink = -1;
        ed->v->solid = 0;
-       
-       ed->freetime = sv.time;
+
+       ed->e->freetime = sv.time;
 }
 
 //===========================================================================
 }
 
 //===========================================================================
@@ -264,7 +285,7 @@ ddef_t *ED_GlobalAtOfs (int ofs)
 {
        ddef_t          *def;
        int                     i;
 {
        ddef_t          *def;
        int                     i;
-       
+
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
@@ -283,7 +304,7 @@ ddef_t *ED_FieldAtOfs (int ofs)
 {
        ddef_t          *def;
        int                     i;
 {
        ddef_t          *def;
        int                     i;
-       
+
        for (i=0 ; i<progs->numfielddefs ; i++)
        {
                def = &pr_fielddefs[i];
        for (i=0 ; i<progs->numfielddefs ; i++)
        {
                def = &pr_fielddefs[i];
@@ -375,7 +396,8 @@ char *PR_ValueString (etype_t type, eval_t *val)
                sprintf (line, "%s", PR_GetString(val->string));
                break;
        case ev_entity:
                sprintf (line, "%s", PR_GetString(val->string));
                break;
        case ev_entity:
-               n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict));
+               //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict));
+               n = val->edict;
                if (n < 0 || n >= MAX_EDICTS)
                        sprintf (line, "entity %i (invalid!)", n);
                else
                if (n < 0 || n >= MAX_EDICTS)
                        sprintf (line, "entity %i (invalid!)", n);
                else
@@ -557,7 +579,7 @@ void ED_Print (edict_t *ed)
        int             type;
        char    tempstring[8192], tempstring2[260]; // temporary string buffers
 
        int             type;
        char    tempstring[8192], tempstring2[260]; // temporary string buffers
 
-       if (ed->free)
+       if (ed->e->free)
        {
                Con_Printf ("FREE\n");
                return;
        {
                Con_Printf ("FREE\n");
                return;
@@ -632,7 +654,7 @@ void ED_Write (qfile_t *f, edict_t *ed)
 
        FS_Printf (f, "{\n");
 
 
        FS_Printf (f, "{\n");
 
-       if (ed->free)
+       if (ed->e->free)
        {
                FS_Printf (f, "}\n");
                return;
        {
                FS_Printf (f, "}\n");
                return;
@@ -720,7 +742,7 @@ void ED_Count (void)
        for (i=0 ; i<sv.num_edicts ; i++)
        {
                ent = EDICT_NUM(i);
        for (i=0 ; i<sv.num_edicts ; i++)
        {
                ent = EDICT_NUM(i);
-               if (ent->free)
+               if (ent->e->free)
                        continue;
                active++;
                if (ent->v->solid)
                        continue;
                active++;
                if (ent->v->solid)
@@ -774,7 +796,7 @@ void ED_WriteGlobals (qfile_t *f)
 
                name = PR_GetString(def->s_name);
                FS_Printf (f,"\"%s\" ", name);
 
                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\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
        }
        FS_Printf (f,"}\n");
 }
        }
        FS_Printf (f,"}\n");
 }
@@ -792,7 +814,7 @@ void ED_ParseGlobals (const char *data)
        while (1)
        {
                // parse key
        while (1)
        {
                // parse key
-               if (!COM_ParseToken (&data))
+               if (!COM_ParseToken(&data, false))
                        Host_Error ("ED_ParseEntity: EOF without closing brace");
                if (com_token[0] == '}')
                        break;
                        Host_Error ("ED_ParseEntity: EOF without closing brace");
                if (com_token[0] == '}')
                        break;
@@ -800,7 +822,7 @@ void ED_ParseGlobals (const char *data)
                strcpy (keyname, com_token);
 
                // parse value
                strcpy (keyname, com_token);
 
                // parse value
-               if (!COM_ParseToken (&data))
+               if (!COM_ParseToken(&data, false))
                        Host_Error ("ED_ParseEntity: EOF without closing brace");
 
                if (com_token[0] == '}')
                        Host_Error ("ED_ParseEntity: EOF without closing brace");
 
                if (com_token[0] == '}')
@@ -877,11 +899,11 @@ qboolean  ED_ParseEpair (void *base, ddef_t *key, const char *s)
        case ev_string:
                *(string_t *)d = PR_SetString(ED_NewString(s));
                break;
        case ev_string:
                *(string_t *)d = PR_SetString(ED_NewString(s));
                break;
-               
+
        case ev_float:
                *(float *)d = atof (s);
                break;
        case ev_float:
                *(float *)d = atof (s);
                break;
-               
+
        case ev_vector:
                strcpy (string, s);
                v = string;
        case ev_vector:
                strcpy (string, s);
                v = string;
@@ -897,7 +919,12 @@ qboolean   ED_ParseEpair (void *base, ddef_t *key, const char *s)
                break;
 
        case ev_entity:
                break;
 
        case ev_entity:
-               *(int *)d = EDICT_TO_PROG(EDICT_NUM(atoi (s)));
+               i = atoi (s);
+               if (i < 0 || i >= MAX_EDICTS)
+                       Con_DPrintf("ED_ParseEpair: ev_entity reference too large (edict %i >= MAX_EDICTS %i)\n", i, MAX_EDICTS);
+               while (i >= sv.max_edicts)
+                       SV_IncreaseEdicts();
+               *(int *)d = EDICT_TO_PROG(EDICT_NUM(i));
                break;
 
        case ev_field:
                break;
 
        case ev_field:
@@ -955,7 +982,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
        while (1)
        {
        // parse key
        while (1)
        {
        // parse key
-               if (!COM_ParseToken (&data))
+               if (!COM_ParseToken(&data, false))
                        Host_Error ("ED_ParseEntity: EOF without closing brace");
                if (com_token[0] == '}')
                        break;
                        Host_Error ("ED_ParseEntity: EOF without closing brace");
                if (com_token[0] == '}')
                        break;
@@ -985,7 +1012,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
                }
 
        // parse value
                }
 
        // parse value
-               if (!COM_ParseToken (&data))
+               if (!COM_ParseToken(&data, false))
                        Host_Error ("ED_ParseEntity: EOF without closing brace");
 
                if (com_token[0] == '}')
                        Host_Error ("ED_ParseEntity: EOF without closing brace");
 
                if (com_token[0] == '}')
@@ -1017,7 +1044,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
        }
 
        if (!init)
        }
 
        if (!init)
-               ent->free = true;
+               ent->e->free = true;
 
        return data;
 }
 
        return data;
 }
@@ -1041,18 +1068,21 @@ to call ED_CallSpawnFunctions () to let the objects initialize themselves.
 void ED_LoadFromFile (const char *data)
 {
        edict_t *ent;
 void ED_LoadFromFile (const char *data)
 {
        edict_t *ent;
-       int inhibit;
+       int parsed, inhibited, spawned, died;
        mfunction_t *func;
 
        ent = NULL;
        mfunction_t *func;
 
        ent = NULL;
-       inhibit = 0;
+       parsed = 0;
+       inhibited = 0;
+       spawned = 0;
+       died = 0;
        pr_global_struct->time = sv.time;
        pr_global_struct->time = sv.time;
-       
+
 // parse ents
        while (1)
        {
 // parse the opening brace
 // parse ents
        while (1)
        {
 // parse the opening brace
-               if (!COM_ParseToken (&data))
+               if (!COM_ParseToken(&data, false))
                        break;
                if (com_token[0] != '{')
                        Host_Error ("ED_LoadFromFile: found %s when expecting {",com_token);
                        break;
                if (com_token[0] != '{')
                        Host_Error ("ED_LoadFromFile: found %s when expecting {",com_token);
@@ -1062,14 +1092,15 @@ void ED_LoadFromFile (const char *data)
                else
                        ent = ED_Alloc ();
                data = ED_ParseEdict (data, ent);
                else
                        ent = ED_Alloc ();
                data = ED_ParseEdict (data, ent);
+               parsed++;
 
 // remove things from different skill levels or deathmatch
                if (deathmatch.integer)
                {
                        if (((int)ent->v->spawnflags & SPAWNFLAG_NOT_DEATHMATCH))
                        {
 
 // remove things from different skill levels or deathmatch
                if (deathmatch.integer)
                {
                        if (((int)ent->v->spawnflags & SPAWNFLAG_NOT_DEATHMATCH))
                        {
-                               ED_Free (ent);  
-                               inhibit++;
+                               ED_Free (ent);
+                               inhibited++;
                                continue;
                        }
                }
                                continue;
                        }
                }
@@ -1078,7 +1109,7 @@ void ED_LoadFromFile (const char *data)
                          || (current_skill >= 2 && ((int)ent->v->spawnflags & SPAWNFLAG_NOT_HARD  )))
                {
                        ED_Free (ent);
                          || (current_skill >= 2 && ((int)ent->v->spawnflags & SPAWNFLAG_NOT_HARD  )))
                {
                        ED_Free (ent);
-                       inhibit++;
+                       inhibited++;
                        continue;
                }
 
                        continue;
                }
 
@@ -1109,9 +1140,12 @@ void ED_LoadFromFile (const char *data)
 
                pr_global_struct->self = EDICT_TO_PROG(ent);
                PR_ExecuteProgram (func - pr_functions, "");
 
                pr_global_struct->self = EDICT_TO_PROG(ent);
                PR_ExecuteProgram (func - pr_functions, "");
+               spawned++;
+               if (ent->e->free)
+                       died++;
        }
 
        }
 
-       Con_DPrintf ("%i entities inhibited\n", inhibit);
+       Con_DPrintf ("%i entities parsed, %i inhibited, %i spawned (%i removed self, %i stayed)\n", parsed, inhibited, spawned, died, spawned - died);
 }
 
 
 }
 
 
@@ -1158,7 +1192,10 @@ dpfield_t dpfields[] =
        {ev_float, "ping"},
        {ev_vector, "movement"},
        {ev_float, "pmodel"},
        {ev_float, "ping"},
        {ev_vector, "movement"},
        {ev_float, "pmodel"},
-       {ev_vector, "punchvector"}
+       {ev_vector, "punchvector"},
+       {ev_float, "clientcolors"},
+       {ev_entity, "tag_entity"},
+       {ev_float, "tag_index"}
 };
 
 /*
 };
 
 /*
@@ -1166,6 +1203,7 @@ dpfield_t dpfields[] =
 PR_LoadProgs
 ===============
 */
 PR_LoadProgs
 ===============
 */
+extern void PR_Cmd_Reset (void);
 void PR_LoadProgs (void)
 {
        int i;
 void PR_LoadProgs (void)
 {
        int i;
@@ -1380,6 +1418,7 @@ void PR_LoadProgs (void)
 
        FindEdictFieldOffsets(); // LordHavoc: update field offset list
        PR_Execute_ProgsLoaded();
 
        FindEdictFieldOffsets(); // LordHavoc: update field offset list
        PR_Execute_ProgsLoaded();
+       PR_Cmd_Reset();
 }
 
 
 }
 
 
@@ -1400,7 +1439,7 @@ void PR_Fields_f (void)
        for (ednum = 0;ednum < MAX_EDICTS;ednum++)
        {
                ed = EDICT_NUM(ednum);
        for (ednum = 0;ednum < MAX_EDICTS;ednum++)
        {
                ed = EDICT_NUM(ednum);
-               if (ed->free)
+               if (ed->e->free)
                        continue;
                for (i = 1;i < progs->numfielddefs;i++)
                {
                        continue;
                for (i = 1;i < progs->numfielddefs;i++)
                {
@@ -1506,6 +1545,7 @@ void PR_Globals_f (void)
 PR_Init
 ===============
 */
 PR_Init
 ===============
 */
+extern void PR_Cmd_Init(void);
 void PR_Init (void)
 {
        Cmd_AddCommand ("edict", ED_PrintEdict_f);
 void PR_Init (void)
 {
        Cmd_AddCommand ("edict", ED_PrintEdict_f);
@@ -1549,15 +1589,24 @@ void PR_Init (void)
 
        progs_mempool = Mem_AllocPool("progs.dat");
        edictstring_mempool = Mem_AllocPool("edict strings");
 
        progs_mempool = Mem_AllocPool("progs.dat");
        edictstring_mempool = Mem_AllocPool("edict strings");
+
+       PR_Cmd_Init();
 }
 
 // LordHavoc: turned EDICT_NUM into a #define for speed reasons
 }
 
 // LordHavoc: turned EDICT_NUM into a #define for speed reasons
-edict_t *EDICT_NUM_ERROR(int n)
+edict_t *EDICT_NUM_ERROR(int n, char *filename, int fileline)
 {
 {
-       Host_Error ("EDICT_NUM: bad number %i", n);
+       Host_Error ("EDICT_NUM: bad number %i (called at %s:%i)", n, filename, fileline);
        return NULL;
 }
 
        return NULL;
 }
 
+/*
+int NUM_FOR_EDICT_ERROR(edict_t *e)
+{
+       Host_Error ("NUM_FOR_EDICT: bad pointer %p (world is %p, entity number would be %i)", e, sv.edicts, e - sv.edicts);
+       return 0;
+}
+
 int NUM_FOR_EDICT(edict_t *e)
 {
        int n;
 int NUM_FOR_EDICT(edict_t *e)
 {
        int n;
@@ -1567,13 +1616,13 @@ int NUM_FOR_EDICT(edict_t *e)
        return n;
 }
 
        return n;
 }
 
-int NoCrash_NUM_FOR_EDICT(edict_t *e)
-{
-       return e - sv.edicts;
-}
+//int NoCrash_NUM_FOR_EDICT(edict_t *e)
+//{
+//     return e - sv.edicts;
+//}
 
 //#define      EDICT_TO_PROG(e) ((qbyte *)(((edict_t *)e)->v) - (qbyte *)(sv.edictsfields))
 
 //#define      EDICT_TO_PROG(e) ((qbyte *)(((edict_t *)e)->v) - (qbyte *)(sv.edictsfields))
-//#define PROG_TO_EDICT(e) (sv.edictstable[(e) / (progs->entityfields * 4)])
+//#define PROG_TO_EDICT(e) (sv.edicts + ((e) / (progs->entityfields * 4)))
 int EDICT_TO_PROG(edict_t *e)
 {
        int n;
 int EDICT_TO_PROG(edict_t *e)
 {
        int n;
@@ -1587,7 +1636,8 @@ edict_t *PROG_TO_EDICT(int n)
 {
        if ((unsigned int)n >= (unsigned int)sv.max_edicts)
                Host_Error("PROG_TO_EDICT: invalid edict number %i\n", n);
 {
        if ((unsigned int)n >= (unsigned int)sv.max_edicts)
                Host_Error("PROG_TO_EDICT: invalid edict number %i\n", n);
-       return sv.edictstable[n]; // EXPERIMENTAL
-       //return sv.edictstable[(n) / (progs->entityfields * 4)];
+       return sv.edicts + n; // EXPERIMENTAL
+       //return sv.edicts + ((n) / (progs->entityfields * 4));
 }
 }
+*/