3 //============================================================================
6 char *vm_m_extensions =
8 "DP_QC_ASINACOSATANATAN2TAN "
9 "DP_QC_STRINGCOLORFUNCTIONS";
15 string precache_file(string)
18 void VM_M_precache_file (void)
19 { // precache_file is only used to copy files with qcc, it does nothing
20 VM_SAFEPARMCOUNT(1,VM_precache_file);
22 PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
29 used instead of the other VM_precache_* functions in the builtin list
33 void VM_M_precache_error (void)
35 PRVM_ERROR ("PF_Precache_*: Precache can only be done in spawn functions");
42 string precache_sound (string sample)
45 void VM_M_precache_sound (void)
49 VM_SAFEPARMCOUNT(1, VM_precache_sound);
51 s = PRVM_G_STRING(OFS_PARM0);
52 PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
53 VM_CheckEmptyString (s);
55 if(snd_initialized.integer && !S_PrecacheSound (s,true, true))
57 VM_Warning("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
66 setmousetarget(float target)
69 void VM_M_setmousetarget(void)
71 VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
73 switch((int)PRVM_G_FLOAT(OFS_PARM0))
76 in_client_mouse = false;
79 in_client_mouse = true;
82 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
93 void VM_M_getmousetarget(void)
95 VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
98 PRVM_G_FLOAT(OFS_RETURN) = 2;
100 PRVM_G_FLOAT(OFS_RETURN) = 1;
109 setkeydest(float dest)
112 void VM_M_setkeydest(void)
114 VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
116 switch((int)PRVM_G_FLOAT(OFS_PARM0))
128 // key_dest = key_message
131 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
142 void VM_M_getkeydest(void)
144 VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
146 // key_game = 0, key_message = 1, key_menu = 2, unknown = 3
150 PRVM_G_FLOAT(OFS_RETURN) = 0;
153 PRVM_G_FLOAT(OFS_RETURN) = 2;
157 // PRVM_G_FLOAT(OFS_RETURN) = 1;
160 PRVM_G_FLOAT(OFS_RETURN) = 3;
168 callfunction(...,string function_name)
172 mfunction_t *PRVM_ED_FindFunction (const char *name);
173 void VM_M_callfunction(void)
179 PRVM_ERROR("VM_M_callfunction: 1 parameter is required !");
181 s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1));
184 PRVM_ERROR("VM_M_callfunction: null string !");
186 VM_CheckEmptyString(s);
188 func = PRVM_ED_FindFunction(s);
191 PRVM_ERROR("VM_M_callfunciton: function %s not found !", s);
192 else if (func->first_statement < 0)
194 // negative statements are built in functions
195 int builtinnumber = -func->first_statement;
196 prog->xfunction->builtinsprofile++;
197 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
198 prog->builtins[builtinnumber]();
200 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
205 PRVM_ExecuteProgram(func - prog->functions,"");
214 float isfunction(string function_name)
217 mfunction_t *PRVM_ED_FindFunction (const char *name);
218 void VM_M_isfunction(void)
223 VM_SAFEPARMCOUNT(1, VM_M_isfunction);
225 s = PRVM_G_STRING(OFS_PARM0);
228 PRVM_ERROR("VM_M_isfunction: null string !");
230 VM_CheckEmptyString(s);
232 func = PRVM_ED_FindFunction(s);
235 PRVM_G_FLOAT(OFS_RETURN) = false;
237 PRVM_G_FLOAT(OFS_RETURN) = true;
244 writetofile(float fhandle, entity ent)
247 void VM_M_writetofile(void)
252 VM_SAFEPARMCOUNT(2, VM_M_writetofile);
254 file = VM_GetFileHandle( (int)PRVM_G_FLOAT(OFS_PARM0) );
257 VM_Warning("VM_M_writetofile: invalid or closed file handle\n");
261 ent = PRVM_G_EDICT(OFS_PARM1);
262 if(ent->priv.required->free)
264 VM_Warning("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
268 PRVM_ED_Write (file, ent);
275 vector getresolution(float number)
278 extern unsigned short video_resolutions[][2];
279 void VM_M_getresolution(void)
282 VM_SAFEPARMCOUNT(1, VM_getresolution);
284 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
287 PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
288 PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1];
289 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
294 VM_M_findkeysforcommand
296 string findkeysforcommand(string command)
298 the returned string is an altstring
301 #define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
303 void M_FindKeysForCommand(const char *command, int *keys);
304 void VM_M_findkeysforcommand(void)
311 VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
313 cmd = PRVM_G_STRING(OFS_PARM0);
315 VM_CheckEmptyString(cmd);
317 (ret = VM_GetTempString())[0] = 0;
319 M_FindKeysForCommand(cmd, keys);
321 for(i = 0; i < NUMKEYS; i++)
322 strlcat(ret, va(" \'%i\'", keys[i]), VM_STRINGTEMP_LENGTH);
324 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(ret);
329 VM_M_getserverliststat
331 float getserverliststat(float type)
336 0 serverlist_viewcount
337 1 serverlist_totalcount
345 void VM_M_getserverliststat( void )
348 VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
350 PRVM_G_FLOAT( OFS_RETURN ) = 0;
352 type = (int)PRVM_G_FLOAT( OFS_PARM0 );
356 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
359 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
361 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
364 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
367 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
370 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
373 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
376 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
379 VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
384 ========================
385 VM_M_resetserverlistmasks
387 resetserverlistmasks()
388 ========================
390 void VM_M_resetserverlistmasks( void )
392 ServerList_ResetMasks();
397 ========================
398 VM_M_setserverlistmaskstring
400 setserverlistmaskstring(float mask, float fld, string str, float op)
403 ========================
405 void VM_M_setserverlistmaskstring( void )
409 serverlist_mask_t *mask;
412 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
413 str = PRVM_G_STRING( OFS_PARM2 );
415 PRVM_ERROR( "VM_M_setserverlistmaskstring: null string passed!" );
417 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
418 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
419 mask = &serverlist_andmasks[masknr];
420 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
421 mask = &serverlist_ormasks[masknr - 512 ];
424 VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
428 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
432 strlcpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
435 strlcpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name) );
438 strlcpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map) );
441 strlcpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod) );
444 strlcpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game) );
447 VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
452 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
456 ========================
457 VM_M_setserverlistmasknumber
459 setserverlistmasknumber(float mask, float fld, float num, float op)
463 ========================
465 void VM_M_setserverlistmasknumber( void )
468 serverlist_mask_t *mask;
471 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
473 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
474 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
475 mask = &serverlist_andmasks[masknr];
476 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
477 mask = &serverlist_ormasks[masknr - 512 ];
480 VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
484 number = (int)PRVM_G_FLOAT( OFS_PARM2 );
485 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
488 case SLIF_MAXPLAYERS:
489 mask->info.maxplayers = number;
491 case SLIF_NUMPLAYERS:
492 mask->info.numplayers = number;
495 mask->info.ping = number;
498 mask->info.protocol = number;
501 VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
506 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
511 ========================
512 VM_M_resortserverlist
515 ========================
517 void VM_M_resortserverlist( void )
519 ServerList_RebuildViewList();
524 VM_M_getserverliststring
526 string getserverliststring(float field, float hostnr)
529 void VM_M_getserverliststring(void)
531 serverlist_entry_t *cache;
534 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
536 PRVM_G_INT(OFS_RETURN) = 0;
538 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
540 if(hostnr < 0 || hostnr >= serverlist_viewcount)
542 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
545 cache = serverlist_viewlist[hostnr];
546 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
548 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
551 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
554 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
557 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
560 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
562 // TODO remove this again
564 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
567 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
570 Con_Print("VM_M_getserverliststring: bad field number passed!\n");
576 VM_M_getserverlistnumber
578 float getserverlistnumber(float field, float hostnr)
581 void VM_M_getserverlistnumber(void)
583 serverlist_entry_t *cache;
586 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
588 PRVM_G_INT(OFS_RETURN) = 0;
590 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
592 if(hostnr < 0 || hostnr >= serverlist_viewcount)
594 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
597 cache = serverlist_viewlist[hostnr];
598 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
599 case SLIF_MAXPLAYERS:
600 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
602 case SLIF_NUMPLAYERS:
603 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
606 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
609 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
612 Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
617 ========================
618 VM_M_setserverlistsort
620 setserverlistsort(float field, float descending)
621 ========================
623 void VM_M_setserverlistsort( void )
625 VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
627 serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
628 serverlist_sortdescending = (qboolean) PRVM_G_FLOAT( OFS_PARM1 );
632 ========================
633 VM_M_refreshserverlist
636 ========================
638 void VM_M_refreshserverlist( void )
640 VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
641 ServerList_QueryList(true, false);
645 ========================
646 VM_M_getserverlistindexforkey
648 float getserverlistindexforkey(string key)
649 ========================
651 void VM_M_getserverlistindexforkey( void )
654 VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
656 key = PRVM_G_STRING( OFS_PARM0 );
657 VM_CheckEmptyString( key );
659 if( !strcmp( key, "cname" ) )
660 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
661 else if( !strcmp( key, "ping" ) )
662 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
663 else if( !strcmp( key, "game" ) )
664 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
665 else if( !strcmp( key, "mod" ) )
666 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
667 else if( !strcmp( key, "map" ) )
668 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
669 else if( !strcmp( key, "name" ) )
670 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
671 else if( !strcmp( key, "maxplayers" ) )
672 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
673 else if( !strcmp( key, "numplayers" ) )
674 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
675 else if( !strcmp( key, "protocol" ) )
676 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
678 PRVM_G_FLOAT( OFS_RETURN ) = -1;
682 ========================
683 VM_M_addwantedserverlistkey
685 addwantedserverlistkey(string key)
686 ========================
688 void VM_M_addwantedserverlistkey( void )
690 VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
694 ===============================================================================
697 used only for client and menu
698 severs uses VM_SV_...
700 Write*(* data, float type, float to)
702 ===============================================================================
705 #define MSG_BROADCAST 0 // unreliable to all
706 #define MSG_ONE 1 // reliable to one (msg_entity)
707 #define MSG_ALL 2 // reliable to all
708 #define MSG_INIT 3 // write to the init string
710 sizebuf_t *VM_WriteDest (void)
716 PRVM_ERROR("VM_WriteDest: game is not server (%s)", PRVM_NAME);
718 dest = (int)PRVM_G_FLOAT(OFS_PARM1);
725 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
726 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
727 PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
729 return &svs.clients[destclient].netconnection->message;
732 return &sv.reliable_datagram;
738 PRVM_ERROR ("WriteDest: bad destination");
745 void VM_M_WriteByte (void)
747 MSG_WriteByte (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
750 void VM_M_WriteChar (void)
752 MSG_WriteChar (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
755 void VM_M_WriteShort (void)
757 MSG_WriteShort (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
760 void VM_M_WriteLong (void)
762 MSG_WriteLong (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
765 void VM_M_WriteAngle (void)
767 MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
770 void VM_M_WriteCoord (void)
772 MSG_WriteCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
775 void VM_M_WriteString (void)
777 MSG_WriteString (VM_WriteDest(), PRVM_G_STRING(OFS_PARM0));
780 void VM_M_WriteEntity (void)
782 MSG_WriteShort (VM_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
785 //string(void) getextresponse = #624; // returns the next extResponse packet that was sent to this client
786 void VM_M_getextresponse (void)
788 VM_SAFEPARMCOUNT(0,VM_argv);
790 if (net_extresponse_count <= 0)
792 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(NULL);
797 --net_extresponse_count;
798 first = (net_extresponse_last + NET_EXTRESPONSE_MAX - net_extresponse_count) % NET_EXTRESPONSE_MAX;
799 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(net_extresponse[first]);
803 prvm_builtin_t vm_m_builtins[] = {
804 0, // to be consistent with the old vm
805 // common builtings (mostly)
882 VM_search_getfilename, // 77
894 VM_cvar_defstring, // 89
908 VM_M_WriteEntity, // 408
924 VM_drawresetcliparea,
925 VM_getimagesize,// 460
930 VM_cin_restart, // 465
933 VM_asin, // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
934 VM_acos, // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
935 VM_atan, // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
936 VM_atan2, // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
937 VM_tan, // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
938 VM_strlennocol, // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
939 VM_strdecolorize, // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
954 VM_M_findkeysforcommand,// 610
955 VM_M_getserverliststat,
956 VM_M_getserverliststring,
959 VM_M_resetserverlistmasks,
960 VM_M_setserverlistmaskstring,
961 VM_M_setserverlistmasknumber,
962 VM_M_resortserverlist,
963 VM_M_setserverlistsort,
964 VM_M_refreshserverlist,
965 VM_M_getserverlistnumber,
966 VM_M_getserverlistindexforkey,
967 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)