]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
increased M_MAX_EDICTS to 32768
[xonotic/darkplaces.git] / prvm_cmds.c
index 4660532fb68114f5a396b5a268ae3912cba6354a..6ff3db2530af56e649e4260d2200934f6aa5e9aa 100644 (file)
@@ -17,7 +17,8 @@ void VM_Warning(const char *fmt, ...)
        va_end(argptr);
 
        Con_Print(msg);
-       PRVM_PrintState();
+       // TODO: either add a cvar/cmd to control the state dumping or replace some of the calls with Con_Printf [9/13/2006 Black]
+       //PRVM_PrintState();
 }
 
 
@@ -29,8 +30,8 @@ void VM_Warning(const char *fmt, ...)
 static char vm_string_temp[VM_STRINGTEMP_BUFFERS][VM_STRINGTEMP_LENGTH];
 static int vm_string_tempindex = 0;
 
-// TODO: move vm_files and vm_fssearchlist to prvm_prog_t struct
-
+// TODO: (move vm_files and vm_fssearchlist to prvm_prog_t struct)
+// TODO: move vm_files and vm_fssearchlist back [9/13/2006 Black]
 char *VM_GetTempString(void)
 {
        char *s;
@@ -145,7 +146,7 @@ void VM_objerror (void)
        char string[VM_STRINGTEMP_LENGTH];
 
        VM_VarString(0, string, sizeof(string));
-       Con_Printf("======OBJECT ERROR======\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string);
+       Con_Printf("======OBJECT ERROR======\n"); // , PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string); // or include them? FIXME
        if(prog->self)
        {
                ed = PRVM_G_EDICT (prog->self->ofs);
@@ -1277,6 +1278,67 @@ void VM_sqrt (void)
        PRVM_G_FLOAT(OFS_RETURN) = sqrt(PRVM_G_FLOAT(OFS_PARM0));
 }
 
+/*
+=========
+VM_asin
+
+float  asin(float)
+=========
+*/
+void VM_asin (void)
+{
+       VM_SAFEPARMCOUNT(1,VM_asin);
+       PRVM_G_FLOAT(OFS_RETURN) = asin(PRVM_G_FLOAT(OFS_PARM0));
+}
+
+/*
+=========
+VM_acos
+float  acos(float)
+=========
+*/
+void VM_acos (void)
+{
+       VM_SAFEPARMCOUNT(1,VM_acos);
+       PRVM_G_FLOAT(OFS_RETURN) = acos(PRVM_G_FLOAT(OFS_PARM0));
+}
+
+/*
+=========
+VM_atan
+float  atan(float)
+=========
+*/
+void VM_atan (void)
+{
+       VM_SAFEPARMCOUNT(1,VM_atan);
+       PRVM_G_FLOAT(OFS_RETURN) = atan(PRVM_G_FLOAT(OFS_PARM0));
+}
+
+/*
+=========
+VM_atan2
+float  atan2(float,float)
+=========
+*/
+void VM_atan2 (void)
+{
+       VM_SAFEPARMCOUNT(2,VM_atan2);
+       PRVM_G_FLOAT(OFS_RETURN) = atan2(PRVM_G_FLOAT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1));
+}
+
+/*
+=========
+VM_tan
+float  tan(float)
+=========
+*/
+void VM_tan (void)
+{
+       VM_SAFEPARMCOUNT(1,VM_tan);
+       PRVM_G_FLOAT(OFS_RETURN) = tan(PRVM_G_FLOAT(OFS_PARM0));
+}
+
 /*
 =================
 VM_randomvec
@@ -1576,14 +1638,14 @@ void VM_fopen(void)
        if (prog->openfiles[filenum] == NULL)
        {
                PRVM_G_FLOAT(OFS_RETURN) = -1;
-               if (developer.integer >= 10)
+               if (developer.integer >= 100)
                        VM_Warning("VM_fopen: %s: %s mode %s failed\n", PRVM_NAME, filename, modestring);
        }
        else
        {
                PRVM_G_FLOAT(OFS_RETURN) = filenum;
-               if (developer.integer >= 10)
-                       VM_Warning("VM_fopen: %s: %s mode %s opened as #%i\n", PRVM_NAME, filename, modestring, filenum);
+               if (developer.integer >= 100)
+                       Con_Printf("VM_fopen: %s: %s mode %s opened as #%i\n", PRVM_NAME, filename, modestring, filenum);
        }
 }
 
@@ -1614,8 +1676,8 @@ void VM_fclose(void)
        }
        FS_Close(prog->openfiles[filenum]);
        prog->openfiles[filenum] = NULL;
-       if (developer.integer >= 10)
-               VM_Warning("VM_fclose: %s: #%i closed\n", PRVM_NAME, filenum);
+       if (developer.integer >= 100)
+               Con_Printf("VM_fclose: %s: #%i closed\n", PRVM_NAME, filenum);
 }
 
 /*
@@ -1725,6 +1787,138 @@ void VM_strlen(void)
                PRVM_G_FLOAT(OFS_RETURN) = 0;
 }
 
+// DRESK - Decolorized String
+/*
+=========
+VM_strdecolorize
+
+string strdecolorize(string s)
+=========
+*/
+// string (string s) strdecolorize = #472; // returns the passed in string with color codes stripped
+void VM_strdecolorize(void)
+{
+       char *szNewString;
+       const char *szString;
+       size_t nCnt;
+       int nPos;
+       int nFillPos;
+       int bFinished;
+               nPos = 0;
+               nFillPos = 0;
+               nCnt = 0;
+               bFinished = 0;
+
+       // Prepare Strings
+       VM_SAFEPARMCOUNT(1,VM_strdecolorize);
+       szString = PRVM_G_STRING(OFS_PARM0);
+       szNewString = VM_GetTempString();
+
+       while(!bFinished)
+       { // Traverse through String
+               if( szString[nPos] == '\n' || szString[nPos] == '\r' || szString[nPos] <= 0)
+               { // String End Found
+                       szNewString[nFillPos++] = szString[nPos];
+                       bFinished = 1;
+               }
+               else
+               if( szString[nPos] == STRING_COLOR_TAG)
+               { // Color Code Located
+                       if( szString[nPos + 1] == STRING_COLOR_TAG)
+                       { // Valid Characters to Include
+                               szNewString[nFillPos++] = szString[nPos];
+                               nPos = nPos + 1;
+                               szNewString[nFillPos++] = szString[nPos];
+                       }
+                       else
+                       if( szString[nPos + 1] >= '0' && szString[nPos + 1] <= '9' )
+                       { // Color Code Found; Increment Position
+                               nPos = nPos + 1;
+                       }
+                       else
+                       { // Unknown Color Code; Include
+                               szNewString[nFillPos++] = szString[nPos];
+                               nPos = nPos + 1;
+                       }
+               }
+               else
+                       // Include Character
+                       szNewString[nFillPos++] = szString[nPos];
+
+                       // Increment Position
+                       nPos = nPos + 1;
+       }
+
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(szNewString);
+}
+
+// DRESK - String Length (not counting color codes)
+/*
+=========
+VM_strlennocol
+
+float  strlennocol(string s)
+=========
+*/
+// float(string s) strlennocol = #471; // returns how many characters are in a string not including color codes
+// For example, ^2Dresk returns a length of 5
+void VM_strlennocol(void)
+{
+       const char *szString;
+       size_t nCnt;
+       int nPos;
+       int bFinished;
+               nPos = 0;
+               nCnt = 0;
+               bFinished = 0;
+
+       VM_SAFEPARMCOUNT(1,VM_strlennocol);
+
+       szString = PRVM_G_STRING(OFS_PARM0);
+       if(szString)
+       { // Valid String
+               while(!bFinished)
+               { // Count Characters
+                       // SV_BroadcastPrintf("Position '%d'; Character '%c'; Length '%d'\n", nPos, szString[nPos], nCnt);
+
+                       if( szString[nPos] == '\n' || szString[nPos] == '\r' || szString[nPos] <= 0)
+                       { // String End Found
+                               // SV_BroadcastPrintf("Found End of String at '%d'\n", nPos);
+                               bFinished = 1;
+                       }
+                       else
+                       if( szString[nPos] == STRING_COLOR_TAG)
+                       { // Color Code Located
+                               if( szString[nPos + 1] == STRING_COLOR_TAG)
+                               { // Increment Length; Skip Color Code
+                                       nCnt = nCnt + 1;
+                                       nPos = nPos + 1;
+                               }
+                               else
+                               if( szString[nPos + 1] >= '0' && szString[nPos + 1] <= '9' )
+                               { // Color Code Found; Increment Position
+                                       // SV_BroadcastPrintf("Found Color Codes at '%d'\n", nPos);
+                                       nPos = nPos + 1;
+                               }
+                               else
+                               { // Unknown Color Code; Increment Length!
+                                       nPos = nPos + 1;
+                                       nCnt = nCnt + 1;
+                               }
+                       }
+                       else
+                               // Increment String Length
+                               nCnt = nCnt + 1;
+
+                       // Increment Position
+                       nPos = nPos + 1;
+               }
+               PRVM_G_FLOAT(OFS_RETURN) = nCnt;
+       }
+       else
+               PRVM_G_FLOAT(OFS_RETURN) = 0;
+}
+
 /*
 =========
 VM_strcat
@@ -2389,7 +2583,7 @@ void VM_freepic(void)
        s = PRVM_G_STRING(OFS_PARM0);
 
        if(!s)
-               PRVM_ERROR ("VM_freepic: %s: NULL");
+               PRVM_ERROR ("VM_freepic: NULL");
 
        VM_CheckEmptyString (s);
 
@@ -2488,7 +2682,7 @@ void VM_drawstring(void)
        }
 
        if(pos[2] || scale[2])
-               Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && scale[2]) ? 's' : 0,((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
+               Con_Printf("VM_drawstring: z value%s from %s discarded\n",(pos[2] && scale[2]) ? "s" : " ",((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
 
        DrawQ_String (pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
        PRVM_G_FLOAT(OFS_RETURN) = 1;
@@ -2535,12 +2729,12 @@ void VM_drawpic(void)
        if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
        {
                PRVM_G_FLOAT(OFS_RETURN) = -2;
-               VM_Warning("VM_drawstring: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+               VM_Warning("VM_drawpic: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
                return;
        }
 
        if(pos[2] || size[2])
-               Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && size[2]) ? 's' : 0,((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
+               Con_Printf("VM_drawpic: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
 
        DrawQ_Pic(pos[0], pos[1], Draw_CachePic(picname, true), size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
        PRVM_G_FLOAT(OFS_RETURN) = 1;
@@ -2569,12 +2763,12 @@ void VM_drawfill(void)
        if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
        {
                PRVM_G_FLOAT(OFS_RETURN) = -2;
-               VM_Warning("VM_drawstring: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+               VM_Warning("VM_drawfill: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
                return;
        }
 
        if(pos[2] || size[2])
-               Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && size[2]) ? 's' : 0,((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
+               Con_Printf("VM_drawfill: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
 
        DrawQ_Pic(pos[0], pos[1], NULL, size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM3), flag);
        PRVM_G_FLOAT(OFS_RETURN) = 1;