]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - csprogs.c
Added support for assigning coop and deathmatch global float values to optional CSQC...
[xonotic/darkplaces.git] / csprogs.c
index 26aa822add799951628e00d3dcc2f53017eaa2e6..bb51c500407901a6684019106685cb94aa4169de 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -178,7 +178,6 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
 
        if ((e->render.colormap > 0 && e->render.colormap <= cl.maxclients) || e->render.colormap >= 1024)
        {
-               int cb;
                unsigned char *cbcolor;
                int palcol;
                if (e->render.colormap >= 1024)
@@ -186,13 +185,11 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
                else
                        palcol = cl.scores[e->render.colormap-1].colors;
 
-               cb = (palcol & 0xF) << 4;cb += (cb >= 128 && cb < 224) ? 4 : 12;
-               cbcolor = (unsigned char *) (&palette_complete[cb]);
+               cbcolor = (unsigned char *) (&palette_pantscolormap[palcol & 0xF]);
                e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f);
                e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f);
-               cb = (palcol & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12;
-               cbcolor = (unsigned char *) (&palette_complete[cb]);
+               cbcolor = (unsigned char *) (&palette_shirtcolormap[(palcol & 0xF0) >> 4]);
                e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f);
@@ -400,6 +397,56 @@ void CL_VM_Parse_CenterPrint (const char *msg)
        CSQC_END
 }
 
+void CL_VM_UpdateIntermissionState (int intermission)
+{
+       prvm_eval_t *val;
+       if(cl.csqc_loaded)
+       {
+               CSQC_BEGIN
+               val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.intermission);
+               if(val)
+                       val->_float = intermission;
+               CSQC_END
+       }
+}
+void CL_VM_UpdateCoopDeathmatchGlobals (int gametype)
+{
+       // Avoid global names for clean(er) coding
+       int localcoop;
+       int localdeathmatch;
+
+       prvm_eval_t *val;
+       if(cl.csqc_loaded)
+       {
+               if(gametype == GAME_COOP)
+               {
+                       localcoop = 1;
+                       localdeathmatch = 0;
+               }
+               else
+               if(gametype == GAME_DEATHMATCH)
+               {
+                       localcoop = 0;
+                       localdeathmatch = 1;
+               }
+               else
+               {
+                       // How did the ServerInfo send an unknown gametype?
+                       // Better just assign the globals as 0...
+                       localcoop = 0;
+                       localdeathmatch = 0;
+               }
+               CSQC_BEGIN
+               val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.coop);
+               if(val)
+                       val->_float = localcoop;
+               val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.deathmatch);
+               if(val)
+                       val->_float = localdeathmatch;
+               CSQC_END
+       }
+}
+
 float CL_VM_Event (float event)                //[515]: needed ? I'd say "YES", but don't know for what :D
 {
        float r = 0;
@@ -539,6 +586,7 @@ void CL_VM_Init (void)
        fs_offset_t csprogsdatasize;
        int csprogsdatacrc, requiredcrc;
        int requiredsize;
+       prvm_eval_t *val;
 
        // reset csqc_progcrc after reading it, so that changing servers doesn't
        // expect csqc on the next server
@@ -636,6 +684,11 @@ void CL_VM_Init (void)
        prog->globals.client->mapname = PRVM_SetEngineString(cl.worldmodel->name);
        prog->globals.client->player_localentnum = cl.playerentity;
 
+       // set map description (use world entity 0)
+       val = PRVM_EDICTFIELDVALUE(prog->edicts, prog->fieldoffsets.message);
+       if(val)
+               val->string = PRVM_SetEngineString(cl.levelname);
+
        // call the prog init
        PRVM_ExecuteProgram(prog->funcoffsets.CSQC_Init, "QC function CSQC_Init is missing");
 
@@ -644,6 +697,9 @@ void CL_VM_Init (void)
 
        cl.csqc_vidvars.drawcrosshair = false;
        cl.csqc_vidvars.drawenginesbar = false;
+
+       // Update Coop and Deathmatch Globals (at this point the client knows them from ServerInfo)
+       CL_VM_UpdateCoopDeathmatchGlobals(cl.gametype);
 }
 
 void CL_VM_ShutDown (void)