3 //============================================================================
6 char *vm_m_extensions =
13 string precache_file(string)
16 void VM_M_precache_file (void)
17 { // precache_file is only used to copy files with qcc, it does nothing
18 VM_SAFEPARMCOUNT(1,VM_precache_file);
20 PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
27 used instead of the other VM_precache_* functions in the builtin list
31 void VM_M_precache_error (void)
33 PRVM_ERROR ("PF_Precache_*: Precache can only be done in spawn functions");
40 string precache_sound (string sample)
43 void VM_M_precache_sound (void)
47 VM_SAFEPARMCOUNT(1, VM_precache_sound);
49 s = PRVM_G_STRING(OFS_PARM0);
50 PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
51 VM_CheckEmptyString (s);
53 if(snd_initialized.integer && !S_PrecacheSound (s,true, true))
55 VM_Warning("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
64 setmousetarget(float target)
67 void VM_M_setmousetarget(void)
69 VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
71 switch((int)PRVM_G_FLOAT(OFS_PARM0))
74 in_client_mouse = false;
77 in_client_mouse = true;
80 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
91 void VM_M_getmousetarget(void)
93 VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
96 PRVM_G_FLOAT(OFS_RETURN) = 2;
98 PRVM_G_FLOAT(OFS_RETURN) = 1;
107 setkeydest(float dest)
110 void VM_M_setkeydest(void)
112 VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
114 switch((int)PRVM_G_FLOAT(OFS_PARM0))
126 // key_dest = key_message
129 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
140 void VM_M_getkeydest(void)
142 VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
144 // key_game = 0, key_message = 1, key_menu = 2, unknown = 3
148 PRVM_G_FLOAT(OFS_RETURN) = 0;
151 PRVM_G_FLOAT(OFS_RETURN) = 2;
155 // PRVM_G_FLOAT(OFS_RETURN) = 1;
158 PRVM_G_FLOAT(OFS_RETURN) = 3;
166 callfunction(...,string function_name)
170 mfunction_t *PRVM_ED_FindFunction (const char *name);
171 void VM_M_callfunction(void)
177 PRVM_ERROR("VM_M_callfunction: 1 parameter is required !");
179 s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1));
182 PRVM_ERROR("VM_M_callfunction: null string !");
184 VM_CheckEmptyString(s);
186 func = PRVM_ED_FindFunction(s);
189 PRVM_ERROR("VM_M_callfunciton: function %s not found !", s);
190 else if (func->first_statement < 0)
192 // negative statements are built in functions
193 int builtinnumber = -func->first_statement;
194 prog->xfunction->builtinsprofile++;
195 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
196 prog->builtins[builtinnumber]();
198 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
203 PRVM_ExecuteProgram(func - prog->functions,"");
212 float isfunction(string function_name)
215 mfunction_t *PRVM_ED_FindFunction (const char *name);
216 void VM_M_isfunction(void)
221 VM_SAFEPARMCOUNT(1, VM_M_isfunction);
223 s = PRVM_G_STRING(OFS_PARM0);
226 PRVM_ERROR("VM_M_isfunction: null string !");
228 VM_CheckEmptyString(s);
230 func = PRVM_ED_FindFunction(s);
233 PRVM_G_FLOAT(OFS_RETURN) = false;
235 PRVM_G_FLOAT(OFS_RETURN) = true;
242 writetofile(float fhandle, entity ent)
245 void VM_M_writetofile(void)
250 VM_SAFEPARMCOUNT(2, VM_M_writetofile);
252 file = VM_GetFileHandle( (int)PRVM_G_FLOAT(OFS_PARM0) );
255 VM_Warning("VM_M_writetofile: invalid or closed file handle\n");
259 ent = PRVM_G_EDICT(OFS_PARM1);
260 if(ent->priv.required->free)
262 VM_Warning("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
266 PRVM_ED_Write (file, ent);
273 vector getresolution(float number)
276 extern unsigned short video_resolutions[][2];
277 void VM_M_getresolution(void)
280 VM_SAFEPARMCOUNT(1, VM_getresolution);
282 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
285 PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
286 PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1];
287 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
292 VM_M_findkeysforcommand
294 string findkeysforcommand(string command)
296 the returned string is an altstring
299 #define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
301 void M_FindKeysForCommand(const char *command, int *keys);
302 void VM_M_findkeysforcommand(void)
309 VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
311 cmd = PRVM_G_STRING(OFS_PARM0);
313 VM_CheckEmptyString(cmd);
315 (ret = VM_GetTempString())[0] = 0;
317 M_FindKeysForCommand(cmd, keys);
319 for(i = 0; i < NUMKEYS; i++)
320 strlcat(ret, va(" \'%i\'", keys[i]), VM_STRINGTEMP_LENGTH);
322 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(ret);
327 VM_M_getserverliststat
329 float getserverliststat(float type)
334 0 serverlist_viewcount
335 1 serverlist_totalcount
343 void VM_M_getserverliststat( void )
346 VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
348 PRVM_G_FLOAT( OFS_RETURN ) = 0;
350 type = (int)PRVM_G_FLOAT( OFS_PARM0 );
354 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
357 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
359 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
362 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
365 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
368 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
371 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
374 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
377 VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
382 ========================
383 VM_M_resetserverlistmasks
385 resetserverlistmasks()
386 ========================
388 void VM_M_resetserverlistmasks( void )
390 ServerList_ResetMasks();
395 ========================
396 VM_M_setserverlistmaskstring
398 setserverlistmaskstring(float mask, float fld, string str, float op)
401 ========================
403 void VM_M_setserverlistmaskstring( void )
407 serverlist_mask_t *mask;
410 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
411 str = PRVM_G_STRING( OFS_PARM2 );
413 PRVM_ERROR( "VM_M_setserverlistmaskstring: null string passed!" );
415 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
416 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
417 mask = &serverlist_andmasks[masknr];
418 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
419 mask = &serverlist_ormasks[masknr - 512 ];
422 VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
426 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
430 strlcpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
433 strlcpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name) );
436 strlcpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map) );
439 strlcpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod) );
442 strlcpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game) );
445 VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
450 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
454 ========================
455 VM_M_setserverlistmasknumber
457 setserverlistmasknumber(float mask, float fld, float num, float op)
461 ========================
463 void VM_M_setserverlistmasknumber( void )
466 serverlist_mask_t *mask;
469 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
471 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
472 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
473 mask = &serverlist_andmasks[masknr];
474 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
475 mask = &serverlist_ormasks[masknr - 512 ];
478 VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
482 number = (int)PRVM_G_FLOAT( OFS_PARM2 );
483 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
486 case SLIF_MAXPLAYERS:
487 mask->info.maxplayers = number;
489 case SLIF_NUMPLAYERS:
490 mask->info.numplayers = number;
493 mask->info.ping = number;
496 mask->info.protocol = number;
499 VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
504 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
509 ========================
510 VM_M_resortserverlist
513 ========================
515 void VM_M_resortserverlist( void )
517 ServerList_RebuildViewList();
522 VM_M_getserverliststring
524 string getserverliststring(float field, float hostnr)
527 void VM_M_getserverliststring(void)
529 serverlist_entry_t *cache;
532 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
534 PRVM_G_INT(OFS_RETURN) = 0;
536 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
538 if(hostnr < 0 || hostnr >= serverlist_viewcount)
540 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
543 cache = serverlist_viewlist[hostnr];
544 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
546 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
549 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
552 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
555 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
558 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
560 // TODO remove this again
562 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
565 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
568 Con_Print("VM_M_getserverliststring: bad field number passed!\n");
574 VM_M_getserverlistnumber
576 float getserverlistnumber(float field, float hostnr)
579 void VM_M_getserverlistnumber(void)
581 serverlist_entry_t *cache;
584 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
586 PRVM_G_INT(OFS_RETURN) = 0;
588 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
590 if(hostnr < 0 || hostnr >= serverlist_viewcount)
592 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
595 cache = serverlist_viewlist[hostnr];
596 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
597 case SLIF_MAXPLAYERS:
598 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
600 case SLIF_NUMPLAYERS:
601 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
604 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
607 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
610 Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
615 ========================
616 VM_M_setserverlistsort
618 setserverlistsort(float field, float descending)
619 ========================
621 void VM_M_setserverlistsort( void )
623 VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
625 serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
626 serverlist_sortdescending = (qboolean) PRVM_G_FLOAT( OFS_PARM1 );
630 ========================
631 VM_M_refreshserverlist
634 ========================
636 void VM_M_refreshserverlist( void )
638 VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
639 ServerList_QueryList(true, false);
643 ========================
644 VM_M_getserverlistindexforkey
646 float getserverlistindexforkey(string key)
647 ========================
649 void VM_M_getserverlistindexforkey( void )
652 VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
654 key = PRVM_G_STRING( OFS_PARM0 );
655 VM_CheckEmptyString( key );
657 if( !strcmp( key, "cname" ) )
658 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
659 else if( !strcmp( key, "ping" ) )
660 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
661 else if( !strcmp( key, "game" ) )
662 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
663 else if( !strcmp( key, "mod" ) )
664 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
665 else if( !strcmp( key, "map" ) )
666 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
667 else if( !strcmp( key, "name" ) )
668 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
669 else if( !strcmp( key, "maxplayers" ) )
670 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
671 else if( !strcmp( key, "numplayers" ) )
672 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
673 else if( !strcmp( key, "protocol" ) )
674 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
676 PRVM_G_FLOAT( OFS_RETURN ) = -1;
680 ========================
681 VM_M_addwantedserverlistkey
683 addwantedserverlistkey(string key)
684 ========================
686 void VM_M_addwantedserverlistkey( void )
688 VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
692 ===============================================================================
695 used only for client and menu
696 severs uses VM_SV_...
698 Write*(* data, float type, float to)
700 ===============================================================================
703 #define MSG_BROADCAST 0 // unreliable to all
704 #define MSG_ONE 1 // reliable to one (msg_entity)
705 #define MSG_ALL 2 // reliable to all
706 #define MSG_INIT 3 // write to the init string
708 sizebuf_t *VM_WriteDest (void)
714 PRVM_ERROR("VM_WriteDest: game is not server (%s)", PRVM_NAME);
716 dest = (int)PRVM_G_FLOAT(OFS_PARM1);
723 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
724 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
725 PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
727 return &svs.clients[destclient].netconnection->message;
730 return &sv.reliable_datagram;
736 PRVM_ERROR ("WriteDest: bad destination");
743 void VM_M_WriteByte (void)
745 MSG_WriteByte (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
748 void VM_M_WriteChar (void)
750 MSG_WriteChar (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
753 void VM_M_WriteShort (void)
755 MSG_WriteShort (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
758 void VM_M_WriteLong (void)
760 MSG_WriteLong (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
763 void VM_M_WriteAngle (void)
765 MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
768 void VM_M_WriteCoord (void)
770 MSG_WriteCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
773 void VM_M_WriteString (void)
775 MSG_WriteString (VM_WriteDest(), PRVM_G_STRING(OFS_PARM0));
778 void VM_M_WriteEntity (void)
780 MSG_WriteShort (VM_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
783 prvm_builtin_t vm_m_builtins[] = {
784 0, // to be consistent with the old vm
785 // common builtings (mostly)
862 VM_search_getfilename, // 77
874 VM_cvar_defstring, // 89
888 VM_M_WriteEntity, // 408
904 VM_drawresetcliparea,
905 VM_getimagesize,// 460
910 VM_cin_restart, // 465
927 VM_M_findkeysforcommand,// 610
928 VM_M_getserverliststat,
929 VM_M_getserverliststring,
932 VM_M_resetserverlistmasks,
933 VM_M_setserverlistmaskstring,
934 VM_M_setserverlistmasknumber,
935 VM_M_resortserverlist,
936 VM_M_setserverlistsort,
937 VM_M_refreshserverlist,
938 VM_M_getserverlistnumber,
939 VM_M_getserverlistindexforkey,
940 VM_M_addwantedserverlistkey // 623
943 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
945 void VM_M_Cmd_Init(void)
950 void VM_M_Cmd_Reset(void)