added DP_ASINACOSATANATAN2TAN extension which adds common trig functions missing...
[xonotic/darkplaces.git] / clvm_cmds.c
index a1a7d6e..4e284d2 100644 (file)
 //4 feature darkplaces csqc: add builtin to clientside qc for reading triangles of model meshes (useful to orient a ui along a triangle of a model mesh)
 //4 feature darkplaces csqc: add builtins to clientside qc for gl calls
 
-#ifndef PF_WARNING
-#define PF_WARNING(s) do{Con_Printf(s);PRVM_PrintState();return;}while(0)
-#endif
-
 //[515]: really need new list ?
 char *vm_cl_extensions =
 "DP_CON_SET "
@@ -39,6 +35,7 @@ char *vm_cl_extensions =
 "DP_ENT_GLOW "
 "DP_ENT_SCALE "
 "DP_GFX_EXTERNALTEXTURES "
+"DP_GFX_EXTERNALTEXTURES_PERMAP "
 "DP_GFX_FOG "
 "DP_GFX_QUAKE3MODELTAGS "
 "DP_GFX_SKINFILES "
@@ -52,6 +49,7 @@ char *vm_cl_extensions =
 "DP_MONSTERWALK "
 "DP_MOVETYPEBOUNCEMISSILE "
 "DP_MOVETYPEFOLLOW "
+"DP_QC_ASINACOSATANATAN2TAN "
 "DP_QC_CHANGEPITCH "
 "DP_QC_COPYENTITY "
 "DP_QC_CVAR_STRING "
@@ -144,9 +142,15 @@ void VM_CL_setorigin (void)
 
        e = PRVM_G_EDICT(OFS_PARM0);
        if (e == prog->edicts)
-               PF_WARNING("setorigin: can not modify world entity\n");
+       {
+               VM_Warning("setorigin: can not modify world entity\n");
+               return;
+       }
        if (e->priv.required->free)
-               PF_WARNING("setorigin: can not modify free entity\n");
+       {
+               VM_Warning("setorigin: can not modify free entity\n");
+               return;
+       }
        org = PRVM_G_VECTOR(OFS_PARM1);
        VectorCopy (org, e->fields.client->origin);
 }
@@ -195,9 +199,15 @@ void VM_CL_setsize (void)
 
        e = PRVM_G_EDICT(OFS_PARM0);
        if (e == prog->edicts)
-               PF_WARNING("setsize: can not modify world entity\n");
+       {
+               VM_Warning("setsize: can not modify world entity\n");
+               return;
+       }
        if (e->priv.server->free)
-               PF_WARNING("setsize: can not modify free entity\n");
+       {
+               VM_Warning("setsize: can not modify free entity\n");
+               return;
+       }
        min = PRVM_G_VECTOR(OFS_PARM1);
        max = PRVM_G_VECTOR(OFS_PARM2);
 
@@ -224,13 +234,22 @@ void VM_CL_sound (void)
        attenuation = PRVM_G_FLOAT(OFS_PARM4);
 
        if (volume < 0 || volume > 255)
-               PF_WARNING("VM_CL_sound: volume must be in range 0-1\n");
+       {
+               VM_Warning("VM_CL_sound: volume must be in range 0-1\n");
+               return;
+       }
 
        if (attenuation < 0 || attenuation > 4)
-               PF_WARNING("VM_CL_sound: attenuation must be in range 0-4\n");
+       {
+               VM_Warning("VM_CL_sound: attenuation must be in range 0-4\n");
+               return;
+       }
 
        if (channel < 0 || channel > 7)
-               PF_WARNING("VM_CL_sound: channel must be in range 0-7\n");
+       {
+               VM_Warning("VM_CL_sound: channel must be in range 0-7\n");
+               return;
+       }
 
        S_StartSound(32768 + PRVM_NUM_FOR_EDICT(entity), channel, S_FindName(sample), entity->fields.client->origin, volume, attenuation);
 }
@@ -314,12 +333,15 @@ void VM_CL_precache_model (void)
                        if(!cl.csqc_model_precache[i])
                                break;
                if(i == MAX_MODELS)
-                       PF_WARNING("VM_CL_precache_model: no free models\n");
+               {
+                       VM_Warning("VM_CL_precache_model: no free models\n");
+                       return;
+               }
                cl.csqc_model_precache[i] = (model_t*)m;
                PRVM_G_FLOAT(OFS_RETURN) = -(i+1);
                return;
        }
-       Con_Printf("VM_CL_precache_model: model \"%s\" not found\n", name);
+       VM_Warning("VM_CL_precache_model: model \"%s\" not found\n", name);
 }
 
 int CSQC_EntitiesInBox (vec3_t mins, vec3_t maxs, int maxlist, prvm_edict_t **list)
@@ -410,9 +432,15 @@ void VM_CL_droptofloor (void)
 
        ent = PRVM_PROG_TO_EDICT(prog->globals.client->self);
        if (ent == prog->edicts)
-               PF_WARNING("droptofloor: can not modify world entity\n");
+       {
+               VM_Warning("droptofloor: can not modify world entity\n");
+               return;
+       }
        if (ent->priv.server->free)
-               PF_WARNING("droptofloor: can not modify free entity\n");
+       {
+               VM_Warning("droptofloor: can not modify free entity\n");
+               return;
+       }
 
        VectorCopy (ent->fields.client->origin, end);
        end[2] -= 256;
@@ -441,7 +469,10 @@ void VM_CL_lightstyle (void)
        i = (int)PRVM_G_FLOAT(OFS_PARM0);
        c = PRVM_G_STRING(OFS_PARM1);
        if (i >= cl.max_lightstyle)
-               PF_WARNING("VM_CL_lightstyle >= MAX_LIGHTSTYLES\n");
+       {
+               VM_Warning("VM_CL_lightstyle >= MAX_LIGHTSTYLES\n");
+               return;
+       }
        strlcpy (cl.lightstyle[i].map,  MSG_ReadString(), sizeof (cl.lightstyle[i].map));
        cl.lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
        cl.lightstyle[i].length = (int)strlen(cl.lightstyle[i].map);
@@ -549,9 +580,15 @@ void VM_CL_changeyaw (void)
 
        ent = PRVM_G_EDICT(OFS_PARM0);
        if (ent == prog->edicts)
-               PF_WARNING("changeyaw: can not modify world entity\n");
+       {
+               VM_Warning("changeyaw: can not modify world entity\n");
+               return;
+       }
        if (ent->priv.server->free)
-               PF_WARNING("changeyaw: can not modify free entity\n");
+       {
+               VM_Warning("changeyaw: can not modify free entity\n");
+               return;
+       }
        current = ANGLEMOD(ent->fields.client->angles[1]);
        ideal = PRVM_G_FLOAT(OFS_PARM1);
        speed = PRVM_G_FLOAT(OFS_PARM2);
@@ -592,9 +629,15 @@ void VM_CL_changepitch (void)
 
        ent = PRVM_G_EDICT(OFS_PARM0);
        if (ent == prog->edicts)
-               PF_WARNING("changepitch: can not modify world entity\n");
+       {
+               VM_Warning("changepitch: can not modify world entity\n");
+               return;
+       }
        if (ent->priv.server->free)
-               PF_WARNING("changepitch: can not modify free entity\n");
+       {
+               VM_Warning("changepitch: can not modify free entity\n");
+               return;
+       }
        current = ANGLEMOD( ent->fields.client->angles[0] );
        ideal = PRVM_G_FLOAT(OFS_PARM1);
        speed = PRVM_G_FLOAT(OFS_PARM2);
@@ -635,7 +678,10 @@ void VM_CL_tracetoss (void)
 
        ent = PRVM_G_EDICT(OFS_PARM0);
        if (ent == prog->edicts)
-               PF_WARNING("tracetoss: can not use world entity\n");
+       {
+               VM_Warning("tracetoss: can not use world entity\n");
+               return;
+       }
        ignore = PRVM_G_EDICT(OFS_PARM1);
 
 //FIXME
@@ -715,15 +761,12 @@ void VM_CL_getlight (void)
 
 //============================================================================
 //[515]: SCENE MANAGER builtins
-void V_CalcRefdef (void);//view.c
-void CSQC_R_ClearScreen (void);//gl_rmain.c
-void CSQC_R_RenderScene (void);//gl_rmain.c
-void CSQC_AddEntity (int n);//csprogs.c
-void CSQC_ClearCSQCEntities (void);
+extern void V_CalcRefdef (void);//view.c
+extern qboolean CSQC_AddRenderEdict (prvm_edict_t *ed);//csprogs.c
+extern void CSQC_ClearCSQCEntities (void);//csprogs.c
 
 matrix4x4_t csqc_listenermatrix;
 qboolean csqc_usecsqclistener = false, csqc_frame = false;//[515]: per-frame
-qboolean csqc_onground;
 
 static void CSQC_R_RecalcView (void)
 {
@@ -731,7 +774,7 @@ static void CSQC_R_RecalcView (void)
        viewmodelmatrix = identitymatrix;
        r_view.matrix = identitymatrix;
        Matrix4x4_CreateFromQuakeEntity(&r_view.matrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 1);
-       Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 0.3);
+       Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], cl_viewmodel_scale.value);
 }
 
 //#300 void() clearscene (EXT_CSQC)
@@ -739,23 +782,46 @@ void VM_R_ClearScene (void)
 {
        VM_SAFEPARMCOUNT(0, VM_R_ClearScene);
 //     CSQC_R_RecalcView();
-       if(csqc_frame)
-               CSQC_ClearCSQCEntities();
-       CSQC_R_ClearScreen();
+       CSQC_ClearCSQCEntities();
 }
 
 //#301 void(float mask) addentities (EXT_CSQC)
+extern void CSQC_Predraw (prvm_edict_t *ed);//csprogs.c
+extern void CSQC_Think (prvm_edict_t *ed);//csprogs.c
 void VM_R_AddEntities (void)
 {
+       int                     i, drawmask;
+       prvm_edict_t *ed;
        VM_SAFEPARMCOUNT(1, VM_R_AddEntities);
-       csqc_drawmask = (int)PRVM_G_FLOAT(OFS_PARM0);
+       drawmask = (int)PRVM_G_FLOAT(OFS_PARM0);
+       CSQC_RelinkAllEntities(drawmask);
+
+       *prog->time = cl.time;
+       for(i=1;i<prog->num_edicts;i++)
+       {
+               ed = &prog->edicts[i];
+               if(ed->priv.required->free)
+                       continue;
+               VectorAdd(ed->fields.client->origin, ed->fields.client->mins, ed->fields.client->absmin);
+               VectorAdd(ed->fields.client->origin, ed->fields.client->maxs, ed->fields.client->absmax);
+               CSQC_Think(ed);
+               if(ed->priv.required->free)
+                       continue;
+               // note that for RF_USEAXIS entities, Predraw sets v_forward/v_right/v_up globals that are read by CSQC_AddRenderEdict
+               CSQC_Predraw(ed);
+               if(ed->priv.required->free)
+                       continue;
+               if(!((int)ed->fields.client->drawmask & drawmask))
+                       continue;
+               CSQC_AddRenderEdict(ed);
+       }
 }
 
 //#302 void(entity ent) addentity (EXT_CSQC)
 void VM_R_AddEntity (void)
 {
        VM_SAFEPARMCOUNT(1, VM_R_AddEntity);
-       CSQC_AddEntity(PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(OFS_PARM0)));
+       CSQC_AddRenderEdict(PRVM_G_EDICT(OFS_PARM0));
 }
 
 //#303 float(float property, ...) setproperty (EXT_CSQC)
@@ -844,8 +910,8 @@ void VM_R_SetView (void)
        case VF_CL_VIEWANGLES_Z:cl.viewangles[2] = k;
                                                        break;
 
-       default:                                Con_Printf("VM_R_SetView : unknown parm %i\n", c);
-                                                       PRVM_G_FLOAT(OFS_RETURN) = 0;
+       default:                                PRVM_G_FLOAT(OFS_RETURN) = 0;
+                                                       VM_Warning("VM_R_SetView : unknown parm %i\n", c);
                                                        return;
        }
        PRVM_G_FLOAT(OFS_RETURN) = 1;
@@ -855,14 +921,7 @@ void VM_R_SetView (void)
 void VM_R_RenderScene (void) //#134
 {
        VM_SAFEPARMCOUNT(0, VM_R_RenderScene);
-
-       if(csqc_frame)
-       {
-               CSQC_RelinkCSQCEntities();
-               CSQC_RelinkAllEntities(csqc_drawmask);
-       }
-
-       CSQC_R_RenderScene();
+       R_RenderView();
 }
 
 //#305 void(vector org, float radius, vector lightcolours) adddynamiclight (EXT_CSQC)
@@ -920,7 +979,7 @@ void VM_CL_getstatf (void)
        i = (int)PRVM_G_FLOAT(OFS_PARM0);
        if(i < 0 || i >= MAX_CL_STATS)
        {
-               Con_Printf("VM_CL_getstatf: index>=MAX_CL_STATS or index<0\n");
+               VM_Warning("VM_CL_getstatf: index>=MAX_CL_STATS or index<0\n");
                return;
        }
        dat.l = cl.stats[i];
@@ -936,7 +995,7 @@ void VM_CL_getstati (void)
 
        if(index < 0 || index >= MAX_CL_STATS)
        {
-               Con_Printf("VM_CL_getstati: index>=MAX_CL_STATS or index<0\n");
+               VM_Warning("VM_CL_getstati: index>=MAX_CL_STATS or index<0\n");
                return;
        }
        i = cl.stats[index];
@@ -952,7 +1011,7 @@ void VM_CL_getstats (void)
        i = (int)PRVM_G_FLOAT(OFS_PARM0);
        if(i < 0 || i > MAX_CL_STATS-4)
        {
-               Con_Printf("VM_CL_getstats: index>MAX_CL_STATS-4 or index<0\n");
+               VM_Warning("VM_CL_getstats: index>MAX_CL_STATS-4 or index<0\n");
                return;
        }
        t = VM_GetTempString();
@@ -981,16 +1040,25 @@ void VM_CL_setmodelindex (void)
        {
                i = -(i+1);
                if(i >= MAX_MODELS)
-                       PF_WARNING("VM_CL_setmodelindex >= MAX_MODELS\n");
+               {
+                       VM_Warning("VM_CL_setmodelindex >= MAX_MODELS\n");
+                       return;
+               }
                m = cl.csqc_model_precache[i];
        }
        else
                if(i >= MAX_MODELS)
-                       PF_WARNING("VM_CL_setmodelindex >= MAX_MODELS\n");
+               {
+                       VM_Warning("VM_CL_setmodelindex >= MAX_MODELS\n");
+                       return;
+               }
                else
                        m = cl.model_precache[i];
        if(!m)
-               PF_WARNING("VM_CL_setmodelindex: null model\n");
+       {
+               VM_Warning("VM_CL_setmodelindex: null model\n");
+               return;
+       }
        t->fields.client->model = PRVM_SetEngineString(m->name);
        t->fields.client->modelindex = i;
 }
@@ -1008,13 +1076,19 @@ void VM_CL_modelnameforindex (void)
        {
                i = -(i+1);
                if(i >= MAX_MODELS)
-                       PF_WARNING("VM_CL_modelnameforindex >= MAX_MODELS\n");
+               {
+                       VM_Warning("VM_CL_modelnameforindex >= MAX_MODELS\n");
+                       return;
+               }
                if(cl.csqc_model_precache[i])
                        PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(cl.csqc_model_precache[i]->name);
                return;
        }
        if(i >= MAX_MODELS)
-               PF_WARNING("VM_CL_modelnameforindex >= MAX_MODELS\n");
+       {
+               VM_Warning("VM_CL_modelnameforindex >= MAX_MODELS\n");
+               return;
+       }
        if(cl.model_precache[i])
                PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(cl.model_precache[i]->name);
 }
@@ -1048,7 +1122,7 @@ void VM_CL_trailparticles (void)
 
        if (entnum >= MAX_EDICTS)
        {
-               Con_Printf("CSQC_ParseBeam: invalid entity number %i\n", entnum);
+               VM_Warning("CSQC_ParseBeam: invalid entity number %i\n", entnum);
                return;
        }
        if (entnum >= cl.max_csqcentities)
@@ -1158,7 +1232,7 @@ void VM_CL_getplayerkey (void)
        t[0] = 0;
 
        if(!strcasecmp(c, "name"))
-               strcpy(t, cl.scores[i].name);
+               strlcpy(t, cl.scores[i].name, sizeof(t));
        else
                if(!strcasecmp(c, "frags"))
                        sprintf(t, "%i", cl.scores[i].frags);
@@ -1183,7 +1257,7 @@ void VM_CL_getplayerkey (void)
        if(!t[0])
                return;
        temp = VM_GetTempString();
-       strcpy(temp, t);
+       strlcpy(temp, t, VM_STRINGTEMP_LENGTH);
        PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(temp);
 }
 
@@ -1208,8 +1282,11 @@ void VM_CL_registercmd (void)
        VM_SAFEPARMCOUNT(1, VM_CL_registercmd);
        if(!Cmd_Exists(PRVM_G_STRING(OFS_PARM0)))
        {
-               t = (char *)Z_Malloc(strlen(PRVM_G_STRING(OFS_PARM0))+1);
-               strcpy(t, PRVM_G_STRING(OFS_PARM0));
+               size_t alloclen;
+
+               alloclen = strlen(PRVM_G_STRING(OFS_PARM0)) + 1;
+               t = (char *)Z_Malloc(alloclen);
+               memcpy(t, PRVM_G_STRING(OFS_PARM0), alloclen);
                Cmd_AddCommand(t, NULL, "console command created by QuakeC");
        }
        else
@@ -1233,7 +1310,7 @@ void VM_CL_playernum (void)
 //#355 float() cl_onground (EXT_CSQC)
 void VM_CL_onground (void)
 {
-       PRVM_G_FLOAT(OFS_RETURN) = csqc_onground;
+       PRVM_G_FLOAT(OFS_RETURN) = cl.onground;
 }
 
 //#360 float() readbyte (EXT_CSQC)
@@ -1281,7 +1358,7 @@ void VM_CL_ReadString (void)
        PRVM_G_INT(OFS_RETURN) = 0;
        if(s)
        {
-               strcpy(t, s);
+               strlcpy(t, s, VM_STRINGTEMP_LENGTH);
                PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(t);
        }
 }
@@ -1830,9 +1907,15 @@ void VM_CL_setattachment (void)
        model_t *model;
 
        if (e == prog->edicts)
-               PF_WARNING("setattachment: can not modify world entity\n");
+       {
+               VM_Warning("setattachment: can not modify world entity\n");
+               return;
+       }
        if (e->priv.server->free)
-               PF_WARNING("setattachment: can not modify free entity\n");
+       {
+               VM_Warning("setattachment: can not modify free entity\n");
+               return;
+       }
 
        if (tagentity == NULL)
                tagentity = prog->edicts;
@@ -1989,16 +2072,10 @@ int CL_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
                                val->_float = 1;
                        Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
                        Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
-                       out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
-                       out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
-                       out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
                        Matrix4x4_Copy(&tagmatrix, out);
 
                        // finally transformate by matrix of tag on parent entity
                        Matrix4x4_Concat(out, &attachmatrix, &tagmatrix);
-                       out->m[0][3] = attachmatrix.m[0][3] + attachmatrix.m[0][0]*tagmatrix.m[0][3] + attachmatrix.m[0][1]*tagmatrix.m[1][3] + attachmatrix.m[0][2]*tagmatrix.m[2][3];
-                       out->m[1][3] = attachmatrix.m[1][3] + attachmatrix.m[1][0]*tagmatrix.m[0][3] + attachmatrix.m[1][1]*tagmatrix.m[1][3] + attachmatrix.m[1][2]*tagmatrix.m[2][3];
-                       out->m[2][3] = attachmatrix.m[2][3] + attachmatrix.m[2][0]*tagmatrix.m[0][3] + attachmatrix.m[2][1]*tagmatrix.m[1][3] + attachmatrix.m[2][2]*tagmatrix.m[2][3];
                        Matrix4x4_Copy(&tagmatrix, out);
 
                        ent = attachent;
@@ -2016,9 +2093,6 @@ int CL_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
        // Alias models have inverse pitch, bmodels can't have tags, so don't check for modeltype...
        Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
        Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
-       out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
-       out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
-       out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
 
        if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_renderflags)) && (RF_VIEWMODEL & (int)val->_float))
        {// RENDER_VIEWMODEL magic
@@ -2030,9 +2104,6 @@ int CL_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
 
                Matrix4x4_CreateFromQuakeEntity(&entitymatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], val->_float);
                Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
-               out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
-               out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
-               out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
 
                /*
                // Cl_bob, ported from rendering code
@@ -2053,7 +2124,7 @@ int CL_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
                        // (don't count Z, or jumping messes it up)
                        bob = sqrt(ent->fields.client->velocity[0]*ent->fields.client->velocity[0] + ent->fields.client->velocity[1]*ent->fields.client->velocity[1])*cl_bob.value;
                        bob = bob*0.3 + bob*0.7*cycle;
-                       out->m[2][3] += bound(-7, bob, 4);
+                       Matrix4x4_AdjustOrigin(out, 0, 0, bound(-7, bob, 4));
                }
                */
        }
@@ -2068,9 +2139,15 @@ void VM_CL_gettagindex (void)
        int modelindex, tag_index;
 
        if (ent == prog->edicts)
-               PF_WARNING("gettagindex: can't affect world entity\n");
+       {
+               VM_Warning("gettagindex: can't affect world entity\n");
+               return;
+       }
        if (ent->priv.server->free)
-               PF_WARNING("gettagindex: can't affect free entity\n");
+       {
+               VM_Warning("gettagindex: can't affect free entity\n");
+               return;
+       }
 
        modelindex = (int)ent->fields.client->modelindex;
        if(modelindex < 0)
@@ -2101,10 +2178,10 @@ void VM_CL_gettaginfo (void)
        switch(returncode)
        {
                case 1:
-                       PF_WARNING("gettagindex: can't affect world entity\n");
+                       VM_Warning("gettagindex: can't affect world entity\n");
                        break;
                case 2:
-                       PF_WARNING("gettagindex: can't affect free entity\n");
+                       VM_Warning("gettagindex: can't affect free entity\n");
                        break;
                case 3:
                        Con_DPrintf("CL_GetTagMatrix(entity #%i): null or non-precached model\n", PRVM_NUM_FOR_EDICT(e));
@@ -2220,7 +2297,7 @@ static int Is_Text_Color (char c, char t)
        char c2 = c - (c & 128);
        char t2 = t - (t & 128);
 
-       if(c != '^' && c2 != '^')               return 0;
+       if(c != STRING_COLOR_TAG && c2 != STRING_COLOR_TAG)             return 0;
        if(t >= '0' && t <= '9')                a = 1;
        if(t2 >= '0' && t2 <= '9')              a = 1;
 /*     if(t >= 'A' && t <= 'Z')                a = 2;
@@ -2274,7 +2351,7 @@ void VM_CL_selecttraceline (void)
 
        if((csqcents && ignore > cl.num_csqcentities) || (!csqcents && ignore > cl.num_entities))
        {
-               Con_Printf("VM_CL_selecttraceline: out of entities\n");
+               VM_Warning("VM_CL_selecttraceline: out of entities\n");
                return;
        }
        else
@@ -2646,7 +2723,17 @@ VM_bufstr_get,                           // #466 string(float bufhandle, float string_index) bufstr_get
 VM_bufstr_set,                         // #467 void(float bufhandle, float string_index, string str) bufstr_set (DP_QC_STRINGBUFFERS)
 VM_bufstr_add,                         // #468 float(float bufhandle, string str, float order) bufstr_add (DP_QC_STRINGBUFFERS)
 VM_bufstr_free,                                // #469 void(float bufhandle, float string_index) bufstr_free (DP_QC_STRINGBUFFERS)
-e10, e10, e10                  // #470-499 (LordHavoc)
+NULL,                                          // #470
+VM_asin,                                       // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
+VM_acos,                                       // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
+VM_atan,                                       // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
+VM_atan2,                                      // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
+VM_tan,                                                // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
+NULL,                                          // #476
+NULL,                                          // #477
+NULL,                                          // #478
+NULL,                                          // #479
+e10, e10                       // #480-499 (LordHavoc)
 };
 
 const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t);