]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - svvm_cmds.c
added DP_ASINACOSATANATAN2TAN extension which adds common trig functions missing...
[xonotic/darkplaces.git] / svvm_cmds.c
index da749e3de90d5743c82a12a1df326d55d48017d5..1bf84cb50da1fd4a4786b7711c5d380bc10749ea 100644 (file)
@@ -3,7 +3,6 @@
 //============================================================================
 // Server
 
-#define PF_WARNING(s) do{Con_Printf(s);PRVM_PrintState();return;}while(0)
 cvar_t sv_aim = {CVAR_SAVE, "sv_aim", "2", "maximum cosine angle for quake's vertical autoaim, a value above 1 completely disables the autoaim, quake used 0.93"}; //"0.93"}; // LordHavoc: disabled autoaim by default
 
 
@@ -35,6 +34,7 @@ char *vm_sv_extensions =
 "DP_ENT_SCALE "
 "DP_ENT_VIEWMODEL "
 "DP_GFX_EXTERNALTEXTURES "
+"DP_GFX_EXTERNALTEXTURES_PERMAP "
 "DP_GFX_FOG "
 "DP_GFX_QUAKE3MODELTAGS "
 "DP_GFX_SKINFILES "
@@ -48,6 +48,7 @@ char *vm_sv_extensions =
 "DP_MONSTERWALK "
 "DP_MOVETYPEBOUNCEMISSILE "
 "DP_MOVETYPEFOLLOW "
+"DP_QC_ASINACOSATANATAN2TAN "
 "DP_QC_CHANGEPITCH "
 "DP_QC_COPYENTITY "
 "DP_QC_CVAR_STRING "
@@ -155,9 +156,15 @@ void PF_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.server->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.server->origin);
        SV_LinkEdict (e, false);
@@ -197,9 +204,15 @@ void PF_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);
        SetMinMaxSize (e, min, max, false);
@@ -222,9 +235,15 @@ void PF_setmodel (void)
 
        e = PRVM_G_EDICT(OFS_PARM0);
        if (e == prog->edicts)
-               PF_WARNING("setmodel: can not modify world entity\n");
+       {
+               VM_Warning("setmodel: can not modify world entity\n");
+               return;
+       }
        if (e->priv.server->free)
-               PF_WARNING("setmodel: can not modify free entity\n");
+       {
+               VM_Warning("setmodel: can not modify free entity\n");
+               return;
+       }
        i = SV_ModelIndex(PRVM_G_STRING(OFS_PARM1), 1);
        e->fields.server->model = PRVM_SetEngineString(sv.model_precache[i]);
        e->fields.server->modelindex = i;
@@ -261,7 +280,7 @@ void PF_sprint (void)
 
        if (entnum < 1 || entnum > svs.maxclients || !svs.clients[entnum-1].active)
        {
-               Con_Print("tried to sprint to a non-client\n");
+               VM_Warning("tried to centerprint to a non-client\n");
                return;
        }
 
@@ -294,7 +313,7 @@ void PF_centerprint (void)
 
        if (entnum < 1 || entnum > svs.maxclients || !svs.clients[entnum-1].active)
        {
-               Con_Print("tried to sprint to a non-client\n");
+               VM_Warning("tried to centerprint to a non-client\n");
                return;
        }
 
@@ -404,13 +423,22 @@ void PF_sound (void)
        attenuation = PRVM_G_FLOAT(OFS_PARM4);
 
        if (volume < 0 || volume > 255)
-               PF_WARNING("SV_StartSound: volume must be in range 0-1\n");
+       {
+               VM_Warning("SV_StartSound: volume must be in range 0-1\n");
+               return;
+       }
 
        if (attenuation < 0 || attenuation > 4)
-               PF_WARNING("SV_StartSound: attenuation must be in range 0-4\n");
+       {
+               VM_Warning("SV_StartSound: attenuation must be in range 0-4\n");
+               return;
+       }
 
        if (channel < 0 || channel > 7)
-               PF_WARNING("SV_StartSound: channel must be in range 0-7\n");
+       {
+               VM_Warning("SV_StartSound: channel must be in range 0-7\n");
+               return;
+       }
 
        SV_StartSound (entity, channel, sample, volume, attenuation);
 }
@@ -555,7 +583,10 @@ void PF_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);
 
        trace = SV_Trace_Toss (ent, ignore);
@@ -722,7 +753,7 @@ void PF_stuffcmd (void)
        entnum = PRVM_G_EDICTNUM(OFS_PARM0);
        if (entnum < 1 || entnum > svs.maxclients || !svs.clients[entnum-1].active)
        {
-               Con_Print("Can't stuffcmd to a non-client\n");
+               VM_Warning("Can't stuffcmd to a non-client\n");
                return;
        }
 
@@ -839,9 +870,15 @@ void PF_walkmove (void)
 
        ent = PRVM_PROG_TO_EDICT(prog->globals.server->self);
        if (ent == prog->edicts)
-               PF_WARNING("walkmove: can not modify world entity\n");
+       {
+               VM_Warning("walkmove: can not modify world entity\n");
+               return;
+       }
        if (ent->priv.server->free)
-               PF_WARNING("walkmove: can not modify free entity\n");
+       {
+               VM_Warning("walkmove: can not modify free entity\n");
+               return;
+       }
        yaw = PRVM_G_FLOAT(OFS_PARM0);
        dist = PRVM_G_FLOAT(OFS_PARM1);
 
@@ -884,9 +921,15 @@ void PF_droptofloor (void)
 
        ent = PRVM_PROG_TO_EDICT(prog->globals.server->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.server->origin, end);
        end[2] -= 256;
@@ -989,9 +1032,15 @@ void PF_aim (void)
 
        ent = PRVM_G_EDICT(OFS_PARM0);
        if (ent == prog->edicts)
-               PF_WARNING("aim: can not use world entity\n");
+       {
+               VM_Warning("aim: can not use world entity\n");
+               return;
+       }
        if (ent->priv.server->free)
-               PF_WARNING("aim: can not use free entity\n");
+       {
+               VM_Warning("aim: can not use free entity\n");
+               return;
+       }
        speed = PRVM_G_FLOAT(OFS_PARM1);
 
        VectorCopy (ent->fields.server->origin, start);
@@ -1069,9 +1118,15 @@ void PF_changeyaw (void)
 
        ent = PRVM_PROG_TO_EDICT(prog->globals.server->self);
        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.server->angles[1]);
        ideal = ent->fields.server->ideal_yaw;
        speed = ent->fields.server->yaw_speed;
@@ -1116,22 +1171,28 @@ void PF_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.server->angles[0] );
        if ((val = PRVM_GETEDICTFIELDVALUE(ent, eval_idealpitch)))
                ideal = val->_float;
        else
        {
-               PF_WARNING("PF_changepitch: .float idealpitch and .float pitch_speed must be defined to use changepitch\n");
+               VM_Warning("PF_changepitch: .float idealpitch and .float pitch_speed must be defined to use changepitch\n");
                return;
        }
        if ((val = PRVM_GETEDICTFIELDVALUE(ent, eval_pitch_speed)))
                speed = val->_float;
        else
        {
-               PF_WARNING("PF_changepitch: .float idealpitch and .float pitch_speed must be defined to use changepitch\n");
+               VM_Warning("PF_changepitch: .float idealpitch and .float pitch_speed must be defined to use changepitch\n");
                return;
        }
 
@@ -1194,14 +1255,14 @@ sizebuf_t *WriteDest (void)
                entnum = PRVM_NUM_FOR_EDICT(ent);
                if (entnum < 1 || entnum > svs.maxclients || !svs.clients[entnum-1].active || !svs.clients[entnum-1].netconnection)
                {
-                       Con_Printf ("WriteDest: tried to write to non-client\n");
+                       VM_Warning ("WriteDest: tried to write to non-client\n");
                        return &sv.reliable_datagram;
                }
                else
                        return &svs.clients[entnum-1].netconnection->message;
 
        default:
-               Con_Printf ("WriteDest: bad destination\n");
+               VM_Warning ("WriteDest: bad destination\n");
        case MSG_ALL:
                return &sv.reliable_datagram;
 
@@ -1270,9 +1331,15 @@ void PF_makestatic (void)
 
        ent = PRVM_G_EDICT(OFS_PARM0);
        if (ent == prog->edicts)
-               PF_WARNING("makestatic: can not modify world entity\n");
+       {
+               VM_Warning("makestatic: can not modify world entity\n");
+               return;
+       }
        if (ent->priv.server->free)
-               PF_WARNING("makestatic: can not modify free entity\n");
+       {
+               VM_Warning("makestatic: can not modify free entity\n");
+               return;
+       }
 
        large = false;
        if (ent->fields.server->modelindex >= 256 || ent->fields.server->frame >= 256)
@@ -1369,7 +1436,7 @@ void PF_registercvar (void)
 // check for overlap with a command
        if (Cmd_Exists (name))
        {
-               Con_Printf("PF_registercvar: %s is a command\n", name);
+               VM_Warning("PF_registercvar: %s is a command\n", name);
                return;
        }
 
@@ -1502,7 +1569,7 @@ void PF_SV_AddStat (void)
                vm_autosentstats = (autosentstat_t *)Z_Malloc((MAX_CL_STATS-32) * sizeof(autosentstat_t));
                if(!vm_autosentstats)
                {
-                       Con_Printf("PF_SV_AddStat: not enough memory\n");
+                       VM_Warning("PF_SV_AddStat: not enough memory\n");
                        return;
                }
        }
@@ -1513,17 +1580,17 @@ void PF_SV_AddStat (void)
 
        if(i < 0)
        {
-               Con_Printf("PF_SV_AddStat: index may not be less than 32\n");
+               VM_Warning("PF_SV_AddStat: index may not be less than 32\n");
                return;
        }
        if(i >= (MAX_CL_STATS-32))
        {
-               Con_Printf("PF_SV_AddStat: index >= MAX_CL_STATS\n");
+               VM_Warning("PF_SV_AddStat: index >= MAX_CL_STATS\n");
                return;
        }
        if(i > (MAX_CL_STATS-32-4) && type == 1)
        {
-               Con_Printf("PF_SV_AddStat: index > (MAX_CL_STATS-4) with string\n");
+               VM_Warning("PF_SV_AddStat: index > (MAX_CL_STATS-4) with string\n");
                return;
        }
        vm_autosentstats[i].type                = type;
@@ -1546,14 +1613,26 @@ void PF_copyentity (void)
        prvm_edict_t *in, *out;
        in = PRVM_G_EDICT(OFS_PARM0);
        if (in == prog->edicts)
-               PF_WARNING("copyentity: can not read world entity\n");
+       {
+               VM_Warning("copyentity: can not read world entity\n");
+               return;
+       }
        if (in->priv.server->free)
-               PF_WARNING("copyentity: can not read free entity\n");
+       {
+               VM_Warning("copyentity: can not read free entity\n");
+               return;
+       }
        out = PRVM_G_EDICT(OFS_PARM1);
        if (out == prog->edicts)
-               PF_WARNING("copyentity: can not modify world entity\n");
+       {
+               VM_Warning("copyentity: can not modify world entity\n");
+               return;
+       }
        if (out->priv.server->free)
-               PF_WARNING("copyentity: can not modify free entity\n");
+       {
+               VM_Warning("copyentity: can not modify free entity\n");
+               return;
+       }
        memcpy(out->fields.server, in->fields.server, prog->progs->entityfields * 4);
 }
 
@@ -1613,11 +1692,17 @@ void PF_effect (void)
        const char *s;
        s = PRVM_G_STRING(OFS_PARM1);
        if (!s || !s[0])
-               PF_WARNING("effect: no model specified\n");
+       {
+               VM_Warning("effect: no model specified\n");
+               return;
+       }
 
        i = SV_ModelIndex(s, 1);
        if (!i)
-               PF_WARNING("effect: model not precached\n");
+       {
+               VM_Warning("effect: model not precached\n");
+               return;
+       }
        SV_StartEffect(PRVM_G_VECTOR(OFS_PARM0), i, (int)PRVM_G_FLOAT(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4));
 }
 
@@ -2242,9 +2327,15 @@ void PF_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;
@@ -2294,7 +2385,7 @@ void SV_GetEntityMatrix (prvm_edict_t *ent, matrix4x4_t *out, qboolean viewmatri
        if (viewmatrix)
                Matrix4x4_CreateFromQuakeEntity(out, ent->fields.server->origin[0], ent->fields.server->origin[1], ent->fields.server->origin[2] + ent->fields.server->view_ofs[2], ent->fields.server->v_angle[0], ent->fields.server->v_angle[1], ent->fields.server->v_angle[2], scale);
        else
-               Matrix4x4_CreateFromQuakeEntity(out, ent->fields.server->origin[0], ent->fields.server->origin[1], ent->fields.server->origin[2], -ent->fields.server->angles[0], ent->fields.server->angles[1], ent->fields.server->angles[2], scale * 0.333);
+               Matrix4x4_CreateFromQuakeEntity(out, ent->fields.server->origin[0], ent->fields.server->origin[1], ent->fields.server->origin[2], -ent->fields.server->angles[0], ent->fields.server->angles[1], ent->fields.server->angles[2], scale * cl_viewmodel_scale.value);
 }
 
 int SV_GetEntityLocalTagMatrix(prvm_edict_t *ent, int tagindex, matrix4x4_t *out)
@@ -2402,7 +2493,7 @@ int SV_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
                        // (don't count Z, or jumping messes it up)
                        bob = sqrt(ent->fields.server->velocity[0]*ent->fields.server->velocity[0] + ent->fields.server->velocity[1]*ent->fields.server->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));
                }
                */
        }
@@ -2418,9 +2509,15 @@ void PF_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.server->modelindex;
        tag_index = 0;
@@ -2449,10 +2546,10 @@ void PF_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("SV_GetTagMatrix(entity #%i): null or non-precached model\n", PRVM_NUM_FOR_EDICT(e));
@@ -2473,9 +2570,15 @@ void PF_dropclient (void)
        client_t *oldhostclient;
        clientnum = PRVM_G_EDICTNUM(OFS_PARM0) - 1;
        if (clientnum < 0 || clientnum >= svs.maxclients)
-               PF_WARNING("dropclient: not a client\n");
+       {
+               VM_Warning("dropclient: not a client\n");
+               return;
+       }
        if (!svs.clients[clientnum].active)
-               PF_WARNING("dropclient: that client slot is not connected\n");
+       {
+               VM_Warning("dropclient: that client slot is not connected\n");
+               return;
+       }
        oldhostclient = host_client;
        host_client = svs.clients + clientnum;
        SV_DropClient(false);
@@ -2748,11 +2851,11 @@ VM_bufstr_set,                          // #467 void(float bufhandle, float string_index, string str)
 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)
 PF_SV_AddStat,                         // #470 void(float index, float type, .void field) SV_AddStat (EXT_CSQC)
-NULL,                                          // #471
-NULL,                                          // #472
-NULL,                                          // #473
-NULL,                                          // #474
-NULL,                                          // #475
+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