]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_cmds.c
added cl_screen.c/h (eventually most 2D stuff should be moved here)
[xonotic/darkplaces.git] / pr_cmds.c
index e4ba51a93fcb5255775f504610455b0d36361f45..38364ccbb321f2ace8bb6b9dd8458b0a66b99503 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 See the GNU General Public License for more details.
 
@@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
+cvar_t sv_aim = {CVAR_SAVE, "sv_aim", "2"}; //"0.93"}; // LordHavoc: disabled autoaim by default
+
 #define        RETURN_EDICT(e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e))
 
 
@@ -36,7 +38,7 @@ char *PF_VarString (int       first)
 {
        int             i;
        static char out[256];
-       
+
        out[0] = 0;
        for (i=first ; i<pr_argc ; i++)
        {
@@ -62,6 +64,7 @@ DP_REGISTERCVAR \
 DP_SPRITE32 \
 DP_SV_DRAWONLYTOCLIENT \
 DP_SV_NODRAWTOCLIENT \
+DP_SV_EXTERIORMODELTOCLIENT \
 DP_SV_SETCOLOR \
 DP_SV_EFFECT \
 DP_TE_BLOOD \
@@ -259,7 +262,7 @@ void SetMinMaxSize (edict_t *e, float *min, float *max, qboolean rotate)
                
                VectorCopy (min, bounds[0]);
                VectorCopy (max, bounds[1]);
-               
+
                rmin[0] = rmin[1] = rmin[2] = 9999;
                rmax[0] = rmax[1] = rmax[2] = -9999;
                
@@ -347,16 +350,16 @@ void PF_setmodel (void)
        for (i=0, check = sv.model_precache ; *check ; i++, check++)
                if (!strcmp(*check, m))
                        break;
-                       
+
        if (!*check)
                PR_RunError ("no precache: %s\n", m);
-               
+
 
        e->v.model = m - pr_strings;
        e->v.modelindex = i; //SV_ModelIndex (m);
 
        mod = sv.models[ (int)e->v.modelindex];  // Mod_ForName (m, true);
-       
+
        if (mod)
        /*
        { // LordHavoc: corrected model bounding box, but for compatibility that means I have to break it here
@@ -371,7 +374,7 @@ void PF_setmodel (void)
                        SetMinMaxSize (e, mod->mins, mod->maxs, true);
        }
        */
-               SetMinMaxSize (e, mod->mins, mod->maxs, true);
+               SetMinMaxSize (e, mod->normalmins, mod->normalmaxs, true);
        else
                SetMinMaxSize (e, vec3_origin, vec3_origin, true);
 }
@@ -497,7 +500,7 @@ void PF_vlen (void)
 {
        float   *value1;
        float   new;
-       
+
        value1 = G_VECTOR(OFS_PARM0);
 
        new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
@@ -632,7 +635,7 @@ void PF_ambientsound (void)
        char            *samp;
        float           *pos;
        float           vol, attenuation;
-       int                     i, soundnum;
+       int                     i, soundnum, large;
 
        pos = G_VECTOR (OFS_PARM0);                     
        samp = G_STRING(OFS_PARM1);
@@ -643,20 +646,31 @@ void PF_ambientsound (void)
        for (soundnum=0, check = sv.sound_precache ; *check ; check++, soundnum++)
                if (!strcmp(*check,samp))
                        break;
-                       
+
        if (!*check)
        {
                Con_Printf ("no precache: %s\n", samp);
                return;
        }
 
-// add an svc_spawnambient command to the level signon packet
+       large = false;
+       if (soundnum >= 256)
+               large = true;
+
+       // add an svc_spawnambient command to the level signon packet
+
+       if (large)
+               MSG_WriteByte (&sv.signon, svc_spawnstaticsound2);
+       else
+               MSG_WriteByte (&sv.signon, svc_spawnstaticsound);
 
-       MSG_WriteByte (&sv.signon,svc_spawnstaticsound);
        for (i=0 ; i<3 ; i++)
                MSG_WriteFloatCoord(&sv.signon, pos[i]);
 
-       MSG_WriteByte (&sv.signon, soundnum);
+       if (large)
+               MSG_WriteShort (&sv.signon, soundnum);
+       else
+               MSG_WriteByte (&sv.signon, soundnum);
 
        MSG_WriteByte (&sv.signon, vol*255);
        MSG_WriteByte (&sv.signon, attenuation*64);
@@ -741,7 +755,7 @@ void PF_traceline (void)
        nomonsters = G_FLOAT(OFS_PARM2);
        ent = G_EDICT(OFS_PARM3);
 
-       trace = SV_Move (v1, vec3_origin, vec3_origin, v2, nomonsters, ent);
+       trace = SV_Move (v1, vec3_origin, vec3_origin, v2, nomonsters ? MOVE_NOMONSTERS : MOVE_NORMAL, ent);
 
        pr_global_struct->trace_allsolid = trace.allsolid;
        pr_global_struct->trace_startsolid = trace.startsolid;
@@ -750,11 +764,12 @@ void PF_traceline (void)
        pr_global_struct->trace_inopen = trace.inopen;
        VectorCopy (trace.endpos, pr_global_struct->trace_endpos);
        VectorCopy (trace.plane.normal, pr_global_struct->trace_plane_normal);
-       pr_global_struct->trace_plane_dist =  trace.plane.dist; 
+       pr_global_struct->trace_plane_dist =  trace.plane.dist;
        if (trace.ent)
                pr_global_struct->trace_ent = EDICT_TO_PROG(trace.ent);
        else
                pr_global_struct->trace_ent = EDICT_TO_PROG(sv.edicts);
+       // FIXME: add trace_endcontents
 }
 
 
@@ -784,7 +799,7 @@ void PF_tracebox (void)
        nomonsters = G_FLOAT(OFS_PARM4);
        ent = G_EDICT(OFS_PARM5);
 
-       trace = SV_Move (v1, m1, m2, v2, nomonsters, ent);
+       trace = SV_Move (v1, m1, m2, v2, nomonsters ? MOVE_NOMONSTERS : MOVE_NORMAL, ent);
 
        pr_global_struct->trace_allsolid = trace.allsolid;
        pr_global_struct->trace_startsolid = trace.startsolid;
@@ -991,7 +1006,7 @@ localcmd (string)
 void PF_localcmd (void)
 {
        char    *str;
-       
+
        str = G_STRING(OFS_PARM0);      
        Cbuf_AddText (str);
 }
@@ -1081,22 +1096,36 @@ void PF_dprint (void)
        Con_DPrintf ("%s",PF_VarString(0));
 }
 
-char   pr_string_temp[128];
+// LordHavoc: added this to semi-fix the problem of using many ftos calls in a print
+#define STRINGTEMP_BUFFERS 16
+#define STRINGTEMP_LENGTH 128
+static char pr_string_temp[STRINGTEMP_BUFFERS][STRINGTEMP_LENGTH];
+static int pr_string_tempindex = 0;
+
+static char *PR_GetTempString(void)
+{
+       char *s;
+       s = pr_string_temp[pr_string_tempindex];
+       pr_string_tempindex = (pr_string_tempindex + 1) % STRINGTEMP_BUFFERS;
+       return s;
+}
 
 void PF_ftos (void)
 {
-       float   v;
+       float v;
+       char *s;
        v = G_FLOAT(OFS_PARM0);
 
-       // LordHavoc: ftos improvement
-       sprintf (pr_string_temp, "%g", v);
+       s = PR_GetTempString();
        /*
        if (v == (int)v)
-               sprintf (pr_string_temp, "%d",(int)v);
+               sprintf (s, "%d",(int)v);
        else
-               sprintf (pr_string_temp, "%5.1f",v);
+               sprintf (s, "%5.1f",v);
        */
-       G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
+       // LordHavoc: ftos improvement
+       sprintf (s, "%g", v);
+       G_INT(OFS_RETURN) = s - pr_strings;
 }
 
 void PF_fabs (void)
@@ -1108,14 +1137,18 @@ void PF_fabs (void)
 
 void PF_vtos (void)
 {
-       sprintf (pr_string_temp, "'%5.1f %5.1f %5.1f'", G_VECTOR(OFS_PARM0)[0], G_VECTOR(OFS_PARM0)[1], G_VECTOR(OFS_PARM0)[2]);
-       G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
+       char *s;
+       s = PR_GetTempString();
+       sprintf (s, "'%5.1f %5.1f %5.1f'", G_VECTOR(OFS_PARM0)[0], G_VECTOR(OFS_PARM0)[1], G_VECTOR(OFS_PARM0)[2]);
+       G_INT(OFS_RETURN) = s - pr_strings;
 }
 
 void PF_etos (void)
 {
-       sprintf (pr_string_temp, "entity %i", G_EDICTNUM(OFS_PARM0));
-       G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
+       char *s;
+       s = PR_GetTempString();
+       sprintf (s, "entity %i", G_EDICTNUM(OFS_PARM0));
+       G_INT(OFS_RETURN) = s - pr_strings;
 }
 
 void PF_Spawn (void)
@@ -1128,8 +1161,12 @@ void PF_Spawn (void)
 void PF_Remove (void)
 {
        edict_t *ed;
-       
+
        ed = G_EDICT(OFS_PARM0);
+       if (ed == sv.edicts)
+               PR_RunError("remove: tried to remove world\n");
+       if (NUM_FOR_EDICT(ed) <= svs.maxclients)
+               PR_RunError("remove: tried to remove a client\n");
        ED_Free (ed);
 }
 
@@ -1137,7 +1174,7 @@ void PF_Remove (void)
 // entity (entity start, .string field, string match) find = #5;
 void PF_Find (void)
 {
-       int             e;      
+       int             e;
        int             f;
        char    *s, *t;
        edict_t *ed;
@@ -1150,7 +1187,7 @@ void PF_Find (void)
                RETURN_EDICT(sv.edicts);
                return;
        }
-               
+
        for (e++ ; e < sv.num_edicts ; e++)
        {
                ed = EDICT_NUM(e);
@@ -1280,7 +1317,7 @@ void PF_precache_sound (void)
        
        if (sv.state != ss_loading)
                PR_RunError ("PF_Precache_*: Precache can only be done in spawn functions");
-               
+
        s = G_STRING(OFS_PARM0);
        G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
        PR_CheckEmptyString (s);
@@ -1298,7 +1335,6 @@ void PF_precache_sound (void)
        PR_RunError ("PF_precache_sound: overflow");
 }
 
-extern qboolean hlbsp;
 void PF_precache_model (void)
 {
        char    *s;
@@ -1308,7 +1344,7 @@ void PF_precache_model (void)
                PR_RunError ("PF_Precache_*: Precache can only be done in spawn functions");
                
        s = G_STRING(OFS_PARM0);
-       if (hlbsp && ((!s) || (!s[0])))
+       if (sv.worldmodel->ishlbsp && ((!s) || (!s[0])))
                return;
        G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
        PR_CheckEmptyString (s);
@@ -1318,7 +1354,7 @@ void PF_precache_model (void)
                if (!sv.model_precache[i])
                {
                        sv.model_precache[i] = s;
-                       sv.models[i] = Mod_ForName (s, true);
+                       sv.models[i] = Mod_ForName (s, true, false, false);
                        return;
                }
                if (!strcmp(sv.model_precache[i], s))
@@ -1409,7 +1445,7 @@ void PF_droptofloor (void)
        VectorCopy (ent->v.origin, end);
        end[2] -= 256;
        
-       trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, end, false, ent);
+       trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, end, MOVE_NORMAL, ent);
 
        if (trace.fraction == 1 || trace.allsolid)
                G_FLOAT(OFS_RETURN) = 0;
@@ -1533,7 +1569,6 @@ Pick a vector for the player to shoot along
 vector aim(entity, missilespeed)
 =============
 */
-cvar_t sv_aim = {"sv_aim", "0.93"};
 void PF_aim (void)
 {
        edict_t *ent, *check, *bestent;
@@ -1552,9 +1587,9 @@ void PF_aim (void)
 // try sending a trace straight
        VectorCopy (pr_global_struct->v_forward, dir);
        VectorMA (start, 2048, dir, end);
-       tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent);
+       tr = SV_Move (start, vec3_origin, vec3_origin, end, MOVE_NORMAL, ent);
        if (tr.ent && tr.ent->v.takedamage == DAMAGE_AIM
-       && (!teamplay.value || ent->v.team <=0 || ent->v.team != tr.ent->v.team) )
+       && (!teamplay.integer || ent->v.team <=0 || ent->v.team != tr.ent->v.team) )
        {
                VectorCopy (pr_global_struct->v_forward, G_VECTOR(OFS_RETURN));
                return;
@@ -1573,7 +1608,7 @@ void PF_aim (void)
                        continue;
                if (check == ent)
                        continue;
-               if (teamplay.value && ent->v.team > 0 && ent->v.team == check->v.team)
+               if (teamplay.integer && ent->v.team > 0 && ent->v.team == check->v.team)
                        continue;       // don't aim at teammate
                for (j=0 ; j<3 ; j++)
                        end[j] = check->v.origin[j]
@@ -1583,7 +1618,7 @@ void PF_aim (void)
                dist = DotProduct (dir, pr_global_struct->v_forward);
                if (dist < bestdist)
                        continue;       // to far to turn
-               tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent);
+               tr = SV_Move (start, vec3_origin, vec3_origin, end, MOVE_NORMAL, ent);
                if (tr.ent == check)
                {       // can shoot at this one
                        bestdist = dist;
@@ -1619,7 +1654,7 @@ void PF_changeyaw (void)
        float           ideal, current, move, speed;
        
        ent = PROG_TO_EDICT(pr_global_struct->self);
-       current = anglemod( ent->v.angles[1] );
+       current = ANGLEMOD(ent->v.angles[1]);
        ideal = ent->v.ideal_yaw;
        speed = ent->v.yaw_speed;
        
@@ -1647,7 +1682,7 @@ void PF_changeyaw (void)
                        move = -speed;
        }
        
-       ent->v.angles[1] = anglemod (current + move);
+       ent->v.angles[1] = ANGLEMOD (current + move);
 }
 
 /*
@@ -1662,7 +1697,7 @@ void PF_changepitch (void)
        eval_t          *val;
        
        ent = G_EDICT(OFS_PARM0);
-       current = anglemod( ent->v.angles[0] );
+       current = ANGLEMOD( ent->v.angles[0] );
        if ((val = GETEDICTFIELDVALUE(ent, eval_idealpitch)))
                ideal = val->_float;
        else
@@ -1702,7 +1737,7 @@ void PF_changepitch (void)
                        move = -speed;
        }
        
-       ent->v.angles[0] = anglemod (current + move);
+       ent->v.angles[0] = ANGLEMOD (current + move);
 }
 
 /*
@@ -1799,23 +1834,27 @@ int SV_ModelIndex (char *name);
 void PF_makestatic (void)
 {
        edict_t *ent;
-       int             i;
+       int             i, large;
        
        ent = G_EDICT(OFS_PARM0);
 
-       i = SV_ModelIndex(pr_strings + ent->v.model);
-       if (i >= 256)
+       large = false;
+       if (ent->v.modelindex >= 256 || ent->v.frame >= 256)
+               large = true;
+
+       if (large)
        {
                MSG_WriteByte (&sv.signon,svc_spawnstatic2);
-               MSG_WriteShort (&sv.signon, i);
+               MSG_WriteShort (&sv.signon, ent->v.modelindex);
+               MSG_WriteShort (&sv.signon, ent->v.frame);
        }
        else
        {
                MSG_WriteByte (&sv.signon,svc_spawnstatic);
-               MSG_WriteByte (&sv.signon, i);
+               MSG_WriteByte (&sv.signon, ent->v.modelindex);
+               MSG_WriteByte (&sv.signon, ent->v.frame);
        }
 
-       MSG_WriteByte (&sv.signon, ent->v.frame);
        MSG_WriteByte (&sv.signon, ent->v.colormap);
        MSG_WriteByte (&sv.signon, ent->v.skin);
        for (i=0 ; i<3 ; i++)