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 %i !\n",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 %i !\n",prog->globals.generic[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 !\n");
176 s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1));
179 PRVM_ERROR("VM_M_callfunction: null string !\n");
181 VM_CheckEmptyString(s);
183 func = PRVM_ED_FindFunction(s);
186 PRVM_ERROR("VM_M_callfunciton: function %s not found !\n", 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 !\n");
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( 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 = 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;
289 string keynumtostring(float keynum)
292 void VM_M_keynumtostring(void)
296 VM_SAFEPARMCOUNT(1, VM_M_keynumtostring);
298 keynum = PRVM_G_FLOAT(OFS_PARM0);
300 tmp = VM_GetTempString();
302 strcpy(tmp, Key_KeynumToString(keynum));
304 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(tmp);
311 float stringtokeynum(string key)
314 void VM_M_stringtokeynum( void )
317 VM_SAFEPARMCOUNT( 1, VM_M_keynumtostring );
319 str = PRVM_G_STRING( OFS_PARM0 );
321 PRVM_G_INT(OFS_RETURN) = Key_StringToKeynum( str );
326 VM_M_findkeysforcommand
328 string findkeysforcommand(string command)
330 the returned string is an altstring
333 #define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
335 void M_FindKeysForCommand(const char *command, int *keys);
336 void VM_M_findkeysforcommand(void)
343 VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
345 cmd = PRVM_G_STRING(OFS_PARM0);
347 VM_CheckEmptyString(cmd);
349 (ret = VM_GetTempString())[0] = 0;
351 M_FindKeysForCommand(cmd, keys);
353 for(i = 0; i < NUMKEYS; i++)
354 ret = strcat(ret, va(" \'%i\'", keys[i]));
356 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(ret);
361 VM_M_getserverliststat
363 float getserverliststat(float type)
368 0 serverlist_viewcount
369 1 serverlist_totalcount
377 void VM_M_getserverliststat( void )
380 VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
382 PRVM_G_FLOAT( OFS_RETURN ) = 0;
384 type = PRVM_G_FLOAT( OFS_PARM0 );
388 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
391 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
393 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
396 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
399 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
402 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
405 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
408 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
411 Con_Printf( "VM_M_getserverliststat: bad type %i!\n", type );
416 ========================
417 VM_M_resetserverlistmasks
419 resetserverlistmasks()
420 ========================
422 void VM_M_resetserverlistmasks( void )
424 ServerList_ResetMasks();
429 ========================
430 VM_M_setserverlistmaskstring
432 setserverlistmaskstring(float mask, float fld, string str, float op)
435 ========================
437 void VM_M_setserverlistmaskstring( void )
441 serverlist_mask_t *mask;
444 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
445 str = PRVM_G_STRING( OFS_PARM2 );
447 PRVM_ERROR( "VM_M_setserverlistmaskstring: null string passed!" );
449 masknr = PRVM_G_FLOAT( OFS_PARM0 );
450 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
451 mask = &serverlist_andmasks[masknr];
452 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
453 mask = &serverlist_ormasks[masknr - 512 ];
455 Con_Printf( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
459 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
463 strncpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
466 strncpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name) );
469 strncpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map) );
472 strncpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod) );
475 strncpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game) );
478 Con_Printf( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
483 mask->tests[field] = (int) PRVM_G_FLOAT( OFS_PARM3 );
487 ========================
488 VM_M_setserverlistmasknumber
490 setserverlistmasknumber(float mask, float fld, float num, float op)
494 ========================
496 void VM_M_setserverlistmasknumber( void )
499 serverlist_mask_t *mask;
502 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
504 masknr = PRVM_G_FLOAT( OFS_PARM0 );
505 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
506 mask = &serverlist_andmasks[masknr];
507 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
508 mask = &serverlist_ormasks[masknr - 512 ];
510 Con_Printf( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
514 number = PRVM_G_FLOAT( OFS_PARM2 );
515 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
518 case SLIF_MAXPLAYERS:
519 mask->info.maxplayers = number;
521 case SLIF_NUMPLAYERS:
522 mask->info.numplayers = number;
525 mask->info.ping = number;
528 mask->info.protocol = number;
531 Con_Printf( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
536 mask->tests[field] = (int) PRVM_G_FLOAT( OFS_PARM3 );
541 ========================
542 VM_M_resortserverlist
545 ========================
547 void VM_M_resortserverlist( void )
549 ServerList_RebuildViewList();
554 VM_M_getserverliststring
556 string getserverliststring(float field, float hostnr)
559 void VM_M_getserverliststring(void)
561 serverlist_entry_t *cache;
564 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
566 PRVM_G_INT(OFS_RETURN) = 0;
568 hostnr = PRVM_G_FLOAT(OFS_PARM1);
570 if(hostnr < 0 || hostnr >= serverlist_viewcount)
572 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
575 cache = serverlist_viewlist[hostnr];
576 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
578 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
581 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
584 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
587 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
590 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
592 // TODO remove this again
594 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
597 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
600 Con_Print("VM_M_getserverliststring: bad field number passed!\n");
606 VM_M_getserverlistnumber
608 float getserverlistnumber(float field, float hostnr)
611 void VM_M_getserverlistnumber(void)
613 serverlist_entry_t *cache;
616 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
618 PRVM_G_INT(OFS_RETURN) = 0;
620 hostnr = PRVM_G_FLOAT(OFS_PARM1);
622 if(hostnr < 0 || hostnr >= serverlist_viewcount)
624 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
627 cache = serverlist_viewlist[hostnr];
628 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
629 case SLIF_MAXPLAYERS:
630 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
632 case SLIF_NUMPLAYERS:
633 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
636 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
639 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
642 Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
647 ========================
648 VM_M_setserverlistsort
650 setserverlistsort(float field, float descending)
651 ========================
653 void VM_M_setserverlistsort( void )
655 VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
657 serverlist_sortbyfield = (int) PRVM_G_FLOAT( OFS_PARM0 );
658 serverlist_sortdescending = (qboolean) PRVM_G_FLOAT( OFS_PARM1 );
662 ========================
663 VM_M_refreshserverlist
666 ========================
668 void VM_M_refreshserverlist( void )
670 VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
671 ServerList_QueryList();
675 ========================
676 VM_M_getserverlistindexforkey
678 float getserverlistindexforkey(string key)
679 ========================
681 void VM_M_getserverlistindexforkey( void )
684 VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
686 key = PRVM_G_STRING( OFS_PARM0 );
687 VM_CheckEmptyString( key );
689 if( !strcmp( key, "cname" ) )
690 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
691 else if( !strcmp( key, "ping" ) )
692 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
693 else if( !strcmp( key, "game" ) )
694 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
695 else if( !strcmp( key, "mod" ) )
696 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
697 else if( !strcmp( key, "map" ) )
698 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
699 else if( !strcmp( key, "name" ) )
700 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
701 else if( !strcmp( key, "maxplayers" ) )
702 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
703 else if( !strcmp( key, "numplayers" ) )
704 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
705 else if( !strcmp( key, "protocol" ) )
706 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
708 PRVM_G_FLOAT( OFS_RETURN ) = -1;
712 ========================
713 VM_M_addwantedserverlistkey
715 addwantedserverlistkey(string key)
716 ========================
718 void VM_M_addwantedserverlistkey( void )
720 VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
724 ===============================================================================
727 used only for client and menu
728 severs uses VM_SV_...
730 Write*(* data, float type, float to)
732 ===============================================================================
735 #define MSG_BROADCAST 0 // unreliable to all
736 #define MSG_ONE 1 // reliable to one (msg_entity)
737 #define MSG_ALL 2 // reliable to all
738 #define MSG_INIT 3 // write to the init string
740 sizebuf_t *VM_WriteDest (void)
746 PRVM_ERROR("VM_WriteDest: game is not server (%s)\n", PRVM_NAME);
748 dest = PRVM_G_FLOAT(OFS_PARM1);
755 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
756 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active)
757 PRVM_ERROR("VM_clientcommand: %s: invalid client !\n", PRVM_NAME);
759 return &svs.clients[destclient].message;
762 return &sv.reliable_datagram;
768 PRVM_ERROR ("WriteDest: bad destination");
775 void VM_M_WriteByte (void)
777 MSG_WriteByte (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
780 void VM_M_WriteChar (void)
782 MSG_WriteChar (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
785 void VM_M_WriteShort (void)
787 MSG_WriteShort (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
790 void VM_M_WriteLong (void)
792 MSG_WriteLong (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
795 void VM_M_WriteAngle (void)
797 MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
800 void VM_M_WriteCoord (void)
802 MSG_WriteCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
805 void VM_M_WriteString (void)
807 MSG_WriteString (VM_WriteDest(), PRVM_G_STRING(OFS_PARM0));
810 void VM_M_WriteEntity (void)
812 MSG_WriteShort (VM_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
815 prvm_builtin_t vm_m_builtins[] = {
816 0, // to be consistent with the old vm
817 // common builtings (mostly)
894 VM_search_getfilename, // 77
917 VM_M_WriteEntity, // 408
933 VM_drawresetcliparea,
934 VM_getimagesize,// 460
939 VM_cin_restart, // 465
955 VM_M_findkeysforcommand,// 610
956 VM_M_getserverliststat,
957 VM_M_getserverliststring,
960 VM_M_resetserverlistmasks,
961 VM_M_setserverlistmaskstring,
962 VM_M_setserverlistmasknumber,
963 VM_M_resortserverlist,
964 VM_M_setserverlistsort,
965 VM_M_refreshserverlist,
966 VM_M_getserverlistnumber,
967 VM_M_getserverlistindexforkey,
968 VM_M_addwantedserverlistkey // 623
971 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
973 void VM_M_Cmd_Init(void)
978 void VM_M_Cmd_Reset(void)