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))
54 Con_Printf("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
61 setmousetarget(float target)
64 void VM_M_setmousetarget(void)
66 VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
68 switch((int)PRVM_G_FLOAT(OFS_PARM0))
71 in_client_mouse = false;
74 in_client_mouse = true;
77 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
88 void VM_M_getmousetarget(void)
90 VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
93 PRVM_G_FLOAT(OFS_RETURN) = 2;
95 PRVM_G_FLOAT(OFS_RETURN) = 1;
104 setkeydest(float dest)
107 void VM_M_setkeydest(void)
109 VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
111 switch((int)PRVM_G_FLOAT(OFS_PARM0))
123 // key_dest = key_message
126 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
137 void VM_M_getkeydest(void)
139 VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
141 // key_game = 0, key_message = 1, key_menu = 2, unknown = 3
145 PRVM_G_FLOAT(OFS_RETURN) = 0;
148 PRVM_G_FLOAT(OFS_RETURN) = 2;
152 // PRVM_G_FLOAT(OFS_RETURN) = 1;
155 PRVM_G_FLOAT(OFS_RETURN) = 3;
163 callfunction(...,string function_name)
167 mfunction_t *PRVM_ED_FindFunction (const char *name);
168 void VM_M_callfunction(void)
174 PRVM_ERROR("VM_M_callfunction: 1 parameter is required !");
176 s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1));
179 PRVM_ERROR("VM_M_callfunction: null string !");
181 VM_CheckEmptyString(s);
183 func = PRVM_ED_FindFunction(s);
186 PRVM_ERROR("VM_M_callfunciton: function %s not found !", s);
187 else if (func->first_statement < 0)
189 // negative statements are built in functions
190 int builtinnumber = -func->first_statement;
191 prog->xfunction->builtinsprofile++;
192 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
193 prog->builtins[builtinnumber]();
195 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
200 PRVM_ExecuteProgram(func - prog->functions,"");
209 float isfunction(string function_name)
212 mfunction_t *PRVM_ED_FindFunction (const char *name);
213 void VM_M_isfunction(void)
218 VM_SAFEPARMCOUNT(1, VM_M_isfunction);
220 s = PRVM_G_STRING(OFS_PARM0);
223 PRVM_ERROR("VM_M_isfunction: null string !");
225 VM_CheckEmptyString(s);
227 func = PRVM_ED_FindFunction(s);
230 PRVM_G_FLOAT(OFS_RETURN) = false;
232 PRVM_G_FLOAT(OFS_RETURN) = true;
239 writetofile(float fhandle, entity ent)
242 void VM_M_writetofile(void)
247 VM_SAFEPARMCOUNT(2, VM_M_writetofile);
249 file = VM_GetFileHandle( (int)PRVM_G_FLOAT(OFS_PARM0) );
254 ent = PRVM_G_EDICT(OFS_PARM1);
255 if(ent->priv.required->free)
257 Con_Printf("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
261 PRVM_ED_Write (file, ent);
268 vector getresolution(float number)
271 extern unsigned short video_resolutions[][2];
272 void VM_M_getresolution(void)
275 VM_SAFEPARMCOUNT(1, VM_getresolution);
277 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
280 PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
281 PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1];
282 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
287 VM_M_findkeysforcommand
289 string findkeysforcommand(string command)
291 the returned string is an altstring
294 #define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
296 void M_FindKeysForCommand(const char *command, int *keys);
297 void VM_M_findkeysforcommand(void)
304 VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
306 cmd = PRVM_G_STRING(OFS_PARM0);
308 VM_CheckEmptyString(cmd);
310 (ret = VM_GetTempString())[0] = 0;
312 M_FindKeysForCommand(cmd, keys);
314 for(i = 0; i < NUMKEYS; i++)
315 ret = strcat(ret, va(" \'%i\'", keys[i]));
317 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(ret);
322 VM_M_getserverliststat
324 float getserverliststat(float type)
329 0 serverlist_viewcount
330 1 serverlist_totalcount
338 void VM_M_getserverliststat( void )
341 VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
343 PRVM_G_FLOAT( OFS_RETURN ) = 0;
345 type = (int)PRVM_G_FLOAT( OFS_PARM0 );
349 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
352 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
354 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
357 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
360 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
363 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
366 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
369 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
372 Con_Printf( "VM_M_getserverliststat: bad type %i!\n", type );
377 ========================
378 VM_M_resetserverlistmasks
380 resetserverlistmasks()
381 ========================
383 void VM_M_resetserverlistmasks( void )
385 ServerList_ResetMasks();
390 ========================
391 VM_M_setserverlistmaskstring
393 setserverlistmaskstring(float mask, float fld, string str, float op)
396 ========================
398 void VM_M_setserverlistmaskstring( void )
402 serverlist_mask_t *mask;
405 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
406 str = PRVM_G_STRING( OFS_PARM2 );
408 PRVM_ERROR( "VM_M_setserverlistmaskstring: null string passed!" );
410 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
411 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
412 mask = &serverlist_andmasks[masknr];
413 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
414 mask = &serverlist_ormasks[masknr - 512 ];
416 Con_Printf( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
420 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
424 strncpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
427 strncpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name) );
430 strncpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map) );
433 strncpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod) );
436 strncpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game) );
439 Con_Printf( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
444 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
448 ========================
449 VM_M_setserverlistmasknumber
451 setserverlistmasknumber(float mask, float fld, float num, float op)
455 ========================
457 void VM_M_setserverlistmasknumber( void )
460 serverlist_mask_t *mask;
463 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
465 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
466 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
467 mask = &serverlist_andmasks[masknr];
468 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
469 mask = &serverlist_ormasks[masknr - 512 ];
471 Con_Printf( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
475 number = (int)PRVM_G_FLOAT( OFS_PARM2 );
476 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
479 case SLIF_MAXPLAYERS:
480 mask->info.maxplayers = number;
482 case SLIF_NUMPLAYERS:
483 mask->info.numplayers = number;
486 mask->info.ping = number;
489 mask->info.protocol = number;
492 Con_Printf( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
497 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
502 ========================
503 VM_M_resortserverlist
506 ========================
508 void VM_M_resortserverlist( void )
510 ServerList_RebuildViewList();
515 VM_M_getserverliststring
517 string getserverliststring(float field, float hostnr)
520 void VM_M_getserverliststring(void)
522 serverlist_entry_t *cache;
525 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
527 PRVM_G_INT(OFS_RETURN) = 0;
529 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
531 if(hostnr < 0 || hostnr >= serverlist_viewcount)
533 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
536 cache = serverlist_viewlist[hostnr];
537 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
539 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
542 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
545 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
548 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
551 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
553 // TODO remove this again
555 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
558 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
561 Con_Print("VM_M_getserverliststring: bad field number passed!\n");
567 VM_M_getserverlistnumber
569 float getserverlistnumber(float field, float hostnr)
572 void VM_M_getserverlistnumber(void)
574 serverlist_entry_t *cache;
577 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
579 PRVM_G_INT(OFS_RETURN) = 0;
581 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
583 if(hostnr < 0 || hostnr >= serverlist_viewcount)
585 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
588 cache = serverlist_viewlist[hostnr];
589 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
590 case SLIF_MAXPLAYERS:
591 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
593 case SLIF_NUMPLAYERS:
594 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
597 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
600 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
603 Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
608 ========================
609 VM_M_setserverlistsort
611 setserverlistsort(float field, float descending)
612 ========================
614 void VM_M_setserverlistsort( void )
616 VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
618 serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
619 serverlist_sortdescending = (qboolean) PRVM_G_FLOAT( OFS_PARM1 );
623 ========================
624 VM_M_refreshserverlist
627 ========================
629 void VM_M_refreshserverlist( void )
631 VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
632 ServerList_QueryList(true, false);
636 ========================
637 VM_M_getserverlistindexforkey
639 float getserverlistindexforkey(string key)
640 ========================
642 void VM_M_getserverlistindexforkey( void )
645 VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
647 key = PRVM_G_STRING( OFS_PARM0 );
648 VM_CheckEmptyString( key );
650 if( !strcmp( key, "cname" ) )
651 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
652 else if( !strcmp( key, "ping" ) )
653 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
654 else if( !strcmp( key, "game" ) )
655 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
656 else if( !strcmp( key, "mod" ) )
657 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
658 else if( !strcmp( key, "map" ) )
659 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
660 else if( !strcmp( key, "name" ) )
661 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
662 else if( !strcmp( key, "maxplayers" ) )
663 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
664 else if( !strcmp( key, "numplayers" ) )
665 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
666 else if( !strcmp( key, "protocol" ) )
667 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
669 PRVM_G_FLOAT( OFS_RETURN ) = -1;
673 ========================
674 VM_M_addwantedserverlistkey
676 addwantedserverlistkey(string key)
677 ========================
679 void VM_M_addwantedserverlistkey( void )
681 VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
685 ===============================================================================
688 used only for client and menu
689 severs uses VM_SV_...
691 Write*(* data, float type, float to)
693 ===============================================================================
696 #define MSG_BROADCAST 0 // unreliable to all
697 #define MSG_ONE 1 // reliable to one (msg_entity)
698 #define MSG_ALL 2 // reliable to all
699 #define MSG_INIT 3 // write to the init string
701 sizebuf_t *VM_WriteDest (void)
707 PRVM_ERROR("VM_WriteDest: game is not server (%s)", PRVM_NAME);
709 dest = (int)PRVM_G_FLOAT(OFS_PARM1);
716 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
717 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
718 PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
720 return &svs.clients[destclient].netconnection->message;
723 return &sv.reliable_datagram;
729 PRVM_ERROR ("WriteDest: bad destination");
736 void VM_M_WriteByte (void)
738 MSG_WriteByte (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
741 void VM_M_WriteChar (void)
743 MSG_WriteChar (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
746 void VM_M_WriteShort (void)
748 MSG_WriteShort (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
751 void VM_M_WriteLong (void)
753 MSG_WriteLong (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
756 void VM_M_WriteAngle (void)
758 MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
761 void VM_M_WriteCoord (void)
763 MSG_WriteCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
766 void VM_M_WriteString (void)
768 MSG_WriteString (VM_WriteDest(), PRVM_G_STRING(OFS_PARM0));
771 void VM_M_WriteEntity (void)
773 MSG_WriteShort (VM_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
776 prvm_builtin_t vm_m_builtins[] = {
777 0, // to be consistent with the old vm
778 // common builtings (mostly)
855 VM_search_getfilename, // 77
867 VM_cvar_defstring, // 89
881 VM_M_WriteEntity, // 408
897 VM_drawresetcliparea,
898 VM_getimagesize,// 460
903 VM_cin_restart, // 465
920 VM_M_findkeysforcommand,// 610
921 VM_M_getserverliststat,
922 VM_M_getserverliststring,
925 VM_M_resetserverlistmasks,
926 VM_M_setserverlistmaskstring,
927 VM_M_setserverlistmasknumber,
928 VM_M_resortserverlist,
929 VM_M_setserverlistsort,
930 VM_M_refreshserverlist,
931 VM_M_getserverlistnumber,
932 VM_M_getserverlistindexforkey,
933 VM_M_addwantedserverlistkey // 623
936 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
938 void VM_M_Cmd_Init(void)
943 void VM_M_Cmd_Reset(void)