]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
changed lhrandom to use the full RAND_MAX limit (more random, after all the low bits...
[xonotic/darkplaces.git] / prvm_cmds.c
index 4d2c97373a0c04bb20d28d4e3d7575bac6b491ec..e9d9afe6067afeade4747df5b1cf5864f4280731 100644 (file)
@@ -97,8 +97,8 @@ string        search_getfilename(float handle, float num)
 
 string chr(float ascii)
 
-float  etof(entity ent)
-entity ftoe(float num)
+float  itof(intt ent)
+intt   ftoi(float num)
                
 perhaps only : Menu : WriteMsg 
 ===============================
@@ -150,6 +150,7 @@ string      gethostcachestring(float type, float hostnr)
 
 #include "quakedef.h"
 #include "progdefs.h"
+#include "progsvm.h"
 #include "clprogdefs.h"
 #include "mprogdefs.h"
 
@@ -391,8 +392,6 @@ void VM_sprint (void)
        }
        
        client = svs.clients + clientnum;
-       if (!client->netconnection)
-               return;
        VM_VarString(1, string, sizeof(string));
        MSG_WriteChar(&client->message,svc_print);
        MSG_WriteString(&client->message, string);
@@ -560,13 +559,9 @@ float random()
 */
 void VM_random (void)
 {
-       float           num;
-
        VM_SAFEPARMCOUNT(0,VM_random);
 
-       num = (rand ()&0x7fff) / ((float)0x7fff);
-
-       PRVM_G_FLOAT(OFS_RETURN) = num;
+       PRVM_G_FLOAT(OFS_RETURN) = lhrandom(0, 1);
 }
 
 /*
@@ -627,7 +622,7 @@ void VM_localsound(void)
 
        s = PRVM_G_STRING(OFS_PARM0);
 
-       if(!S_LocalSound(s, true))
+       if(!S_LocalSound (s))
        {
                Con_Printf("VM_localsound: Failed to play %s for %s !\n", s, PRVM_NAME);
                PRVM_G_FLOAT(OFS_RETURN) = -4;
@@ -839,28 +834,28 @@ void VM_stof(void)
 
 /*
 ========================
-VM_etof
+VM_itof
 
-float etof(entity ent)
+float itof(intt ent)
 ========================
 */
-void VM_etof(void)
+void VM_itof(void)
 {
-       VM_SAFEPARMCOUNT(1, VM_etof);
+       VM_SAFEPARMCOUNT(1, VM_itof);
        PRVM_G_FLOAT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
 }
 
 /*
 ========================
-VM_ftoe
+VM_itoe
 
-entity ftoe(float num)
+intt ftoi(float num)
 ========================
 */
-void VM_ftoe(void)
+void VM_ftoi(void)
 {
        int ent;
-       VM_SAFEPARMCOUNT(1, VM_ftoe);
+       VM_SAFEPARMCOUNT(1, VM_ftoi);
 
        ent = PRVM_G_FLOAT(OFS_PARM0);
        if(PRVM_PROG_TO_EDICT(ent)->p.e->free)
@@ -1041,7 +1036,7 @@ void VM_findchain (void)
                if (strcmp(t,s))
                        continue;
 
-               PRVM_E_FLOAT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
+               PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
                chain = ent;
        }
 
@@ -1084,10 +1079,10 @@ void VM_findchainfloat (void)
                prog->xfunction->builtinsprofile++;
                if (ent->p.e->free)
                        continue;
-               if (E_FLOAT(ent,f) != s)
+               if (PRVM_E_FLOAT(ent,f) != s)
                        continue;
 
-               PRVM_E_FLOAT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
+               PRVM_E_INT(ent,chain_of) = PRVM_EDICT_TO_PROG(chain);
                chain = ent;
        }
 
@@ -1137,8 +1132,8 @@ void VM_precache_sound (void)
        s = PRVM_G_STRING(OFS_PARM0);
        PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
        VM_CheckEmptyString (s);
-       
-       if(!S_PrecacheSound(s,true, true, true))
+
+       if(!S_PrecacheSound (s,true, true))
                Con_Printf("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
 }
 
@@ -1542,7 +1537,7 @@ void VM_registercvar (void)
                return;
        }
 
-       Cvar_Get(name, value, 0);
+       Cvar_Get(name, value, flags);
 
        PRVM_G_FLOAT(OFS_RETURN) = 1; // success
 }
@@ -1912,8 +1907,8 @@ void VM_strcat(void)
 {
        char *s;
 
-       if(prog->argc < 2
-               PRVM_ERROR("VM_strcat wrong parameter count (min. 2 expected ) !\n");
+       if(prog->argc < 1
+               PRVM_ERROR("VM_strcat wrong parameter count (min. 1 expected ) !\n");
        
        s = VM_GetTempString();
        VM_VarString(0, s, VM_STRINGTEMP_LENGTH);
@@ -1997,9 +1992,14 @@ strunzone(string s)
 //void(string s) strunzone = #119; // removes a copy of a string from the string zone (you can not use that string again or it may crash!!!)
 void VM_strunzone(void)
 {
+       char *str;
        VM_SAFEPARMCOUNT(1,VM_strunzone);
 
-       Mem_Free(PRVM_G_STRING(OFS_PARM0));
+       str = PRVM_G_STRING(OFS_PARM0);
+       if( developer.integer && !Mem_IsAllocated( VM_STRINGS_MEMPOOL, str ) )
+               PRVM_ERROR( "VM_strunzone: Zone string already freed in %s!", PRVM_NAME );
+       else
+               Mem_Free( str );
 }
 
 /*
@@ -2987,6 +2987,7 @@ void VM_M_getkeydest(void)
 VM_M_callfunction
 
        callfunction(...,string function_name)
+Extension: pass 
 =========
 */
 mfunction_t *PRVM_ED_FindFunction (const char *name);
@@ -3341,8 +3342,8 @@ prvm_builtin_t vm_m_builtins[] = {
        VM_search_getsize,
        VM_search_getfilename, // 77
        VM_chr, 
-       VM_etof,
-       VM_ftoe,// 80
+       VM_itof,
+       VM_ftoi,// 80
        e10,                    // 90
        e10,                    // 100
        e100,                   // 200