added DP_ASINACOSATANATAN2TAN extension which adds common trig functions missing...
[xonotic/darkplaces.git] / mvm_cmds.c
index 939127e..4391965 100644 (file)
@@ -4,7 +4,8 @@
 // Menu
 
 char *vm_m_extensions =
-"DP_CINEMATIC_DPV";
+"DP_CINEMATIC_DPV "
+"DP_QC_ASINACOSATANATAN2TAN";
 
 /*
 =========
@@ -51,7 +52,10 @@ void VM_M_precache_sound (void)
        VM_CheckEmptyString (s);
 
        if(snd_initialized.integer && !S_PrecacheSound (s,true, true))
-               Con_Printf("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
+       {
+               VM_Warning("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
+               return;
+       }
 }
 
 /*
@@ -246,15 +250,17 @@ void VM_M_writetofile(void)
 
        VM_SAFEPARMCOUNT(2, VM_M_writetofile);
 
-       file = VM_GetFileHandle( PRVM_G_FLOAT(OFS_PARM0) );
-       if( !file ) {
+       file = VM_GetFileHandle( (int)PRVM_G_FLOAT(OFS_PARM0) );
+       if( !file )
+       {
+               VM_Warning("VM_M_writetofile: invalid or closed file handle\n");
                return;
        }
 
        ent = PRVM_G_EDICT(OFS_PARM1);
        if(ent->priv.required->free)
        {
-               Con_Printf("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
+               VM_Warning("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
                return;
        }
 
@@ -274,7 +280,7 @@ void VM_M_getresolution(void)
        int nr;
        VM_SAFEPARMCOUNT(1, VM_getresolution);
 
-       nr = PRVM_G_FLOAT(OFS_PARM0);
+       nr = (int)PRVM_G_FLOAT(OFS_PARM0);
 
 
        PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
@@ -312,7 +318,7 @@ void VM_M_findkeysforcommand(void)
        M_FindKeysForCommand(cmd, keys);
 
        for(i = 0; i < NUMKEYS; i++)
-               ret = strcat(ret, va(" \'%i\'", keys[i]));
+               strlcat(ret, va(" \'%i\'", keys[i]), VM_STRINGTEMP_LENGTH);
 
        PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(ret);
 }
@@ -342,7 +348,7 @@ void VM_M_getserverliststat( void )
 
        PRVM_G_FLOAT( OFS_RETURN ) = 0;
 
-       type = PRVM_G_FLOAT( OFS_PARM0 );
+       type = (int)PRVM_G_FLOAT( OFS_PARM0 );
        switch(type)
        {
        case 0:
@@ -369,7 +375,7 @@ void VM_M_getserverliststat( void )
                PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
                return;
        default:
-               Con_Printf( "VM_M_getserverliststat: bad type %i!\n", type );
+               VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
        }
 }
 
@@ -407,13 +413,14 @@ void VM_M_setserverlistmaskstring( void )
        if( !str )
                PRVM_ERROR( "VM_M_setserverlistmaskstring: null string passed!" );
 
-       masknr = PRVM_G_FLOAT( OFS_PARM0 );
+       masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
        if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
                mask = &serverlist_andmasks[masknr];
        else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
                mask = &serverlist_ormasks[masknr - 512 ];
-       else {
-               Con_Printf( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
+       else
+       {
+               VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
                return;
        }
 
@@ -421,22 +428,22 @@ void VM_M_setserverlistmaskstring( void )
 
        switch( field ) {
                case SLIF_CNAME:
-                       strncpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
+                       strlcpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
                        break;
                case SLIF_NAME:
-                       strncpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name)  );
+                       strlcpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name)  );
                        break;
                case SLIF_MAP:
-                       strncpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map)  );
+                       strlcpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map)  );
                        break;
                case SLIF_MOD:
-                       strncpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod)  );
+                       strlcpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod)  );
                        break;
                case SLIF_GAME:
-                       strncpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game)  );
+                       strlcpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game)  );
                        break;
                default:
-                       Con_Printf( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
+                       VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
                        return;
        }
 
@@ -462,17 +469,18 @@ void VM_M_setserverlistmasknumber( void )
        int field;
        VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
 
-       masknr = PRVM_G_FLOAT( OFS_PARM0 );
+       masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
        if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
                mask = &serverlist_andmasks[masknr];
        else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
                mask = &serverlist_ormasks[masknr - 512 ];
-       else {
-               Con_Printf( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
+       else
+       {
+               VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
                return;
        }
 
-       number = PRVM_G_FLOAT( OFS_PARM2 );
+       number = (int)PRVM_G_FLOAT( OFS_PARM2 );
        field = (int) PRVM_G_FLOAT( OFS_PARM1 );
 
        switch( field ) {
@@ -489,7 +497,7 @@ void VM_M_setserverlistmasknumber( void )
                        mask->info.protocol = number;
                        break;
                default:
-                       Con_Printf( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
+                       VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
                        return;
        }
 
@@ -526,7 +534,7 @@ void VM_M_getserverliststring(void)
 
        PRVM_G_INT(OFS_RETURN) = 0;
 
-       hostnr = PRVM_G_FLOAT(OFS_PARM1);
+       hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
 
        if(hostnr < 0 || hostnr >= serverlist_viewcount)
        {
@@ -578,7 +586,7 @@ void VM_M_getserverlistnumber(void)
 
        PRVM_G_INT(OFS_RETURN) = 0;
 
-       hostnr = PRVM_G_FLOAT(OFS_PARM1);
+       hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
 
        if(hostnr < 0 || hostnr >= serverlist_viewcount)
        {
@@ -706,7 +714,7 @@ sizebuf_t *VM_WriteDest (void)
        if(!sv.active)
                PRVM_ERROR("VM_WriteDest: game is not server (%s)", PRVM_NAME);
 
-       dest = PRVM_G_FLOAT(OFS_PARM1);
+       dest = (int)PRVM_G_FLOAT(OFS_PARM1);
        switch (dest)
        {
        case MSG_BROADCAST:
@@ -735,22 +743,22 @@ sizebuf_t *VM_WriteDest (void)
 
 void VM_M_WriteByte (void)
 {
-       MSG_WriteByte (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
+       MSG_WriteByte (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
 }
 
 void VM_M_WriteChar (void)
 {
-       MSG_WriteChar (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
+       MSG_WriteChar (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
 }
 
 void VM_M_WriteShort (void)
 {
-       MSG_WriteShort (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
+       MSG_WriteShort (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
 }
 
 void VM_M_WriteLong (void)
 {
-       MSG_WriteLong (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
+       MSG_WriteLong (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
 }
 
 void VM_M_WriteAngle (void)
@@ -855,7 +863,7 @@ prvm_builtin_t vm_m_builtins[] = {
        VM_search_getfilename, // 77
        VM_chr,
        VM_itof,
-       VM_ftoi,                // 80
+       VM_ftoe,                // 80
        VM_itof,                // isString
        VM_altstr_count,
        VM_altstr_prepare,
@@ -903,7 +911,12 @@ prvm_builtin_t vm_m_builtins[] = {
        VM_cin_restart, // 465
        VM_drawline,    // 466
        0,0,0,0,        // 470
-       e10,                    // 480
+       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)
+       0,0,0,0,0,                      // 480
        e10,                    // 490
        e10,                    // 500
        e100,                   // 600