3 //============================================================================
6 char *vm_m_extensions =
8 "DP_MENU_EXTRESPONSEPACKET "
9 "DP_QC_ASINACOSATANATAN2TAN "
10 "DP_QC_STRINGCOLORFUNCTIONS";
16 string precache_file(string)
19 void VM_M_precache_file (void)
20 { // precache_file is only used to copy files with qcc, it does nothing
21 VM_SAFEPARMCOUNT(1,VM_precache_file);
23 PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
30 used instead of the other VM_precache_* functions in the builtin list
34 void VM_M_precache_error (void)
36 PRVM_ERROR ("PF_Precache_*: Precache can only be done in spawn functions");
43 string precache_sound (string sample)
46 void VM_M_precache_sound (void)
50 VM_SAFEPARMCOUNT(1, VM_precache_sound);
52 s = PRVM_G_STRING(OFS_PARM0);
53 PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
54 VM_CheckEmptyString (s);
56 if(snd_initialized.integer && !S_PrecacheSound (s,true, true))
58 VM_Warning("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
67 setmousetarget(float target)
70 void VM_M_setmousetarget(void)
72 VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
74 switch((int)PRVM_G_FLOAT(OFS_PARM0))
77 in_client_mouse = false;
80 in_client_mouse = true;
83 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
94 void VM_M_getmousetarget(void)
96 VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
99 PRVM_G_FLOAT(OFS_RETURN) = 2;
101 PRVM_G_FLOAT(OFS_RETURN) = 1;
110 setkeydest(float dest)
113 void VM_M_setkeydest(void)
115 VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
117 switch((int)PRVM_G_FLOAT(OFS_PARM0))
129 // key_dest = key_message
132 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
143 void VM_M_getkeydest(void)
145 VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
147 // key_game = 0, key_message = 1, key_menu = 2, unknown = 3
151 PRVM_G_FLOAT(OFS_RETURN) = 0;
154 PRVM_G_FLOAT(OFS_RETURN) = 2;
158 // PRVM_G_FLOAT(OFS_RETURN) = 1;
161 PRVM_G_FLOAT(OFS_RETURN) = 3;
169 callfunction(...,string function_name)
173 mfunction_t *PRVM_ED_FindFunction (const char *name);
174 void VM_M_callfunction(void)
180 PRVM_ERROR("VM_M_callfunction: 1 parameter is required !");
182 s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1));
185 PRVM_ERROR("VM_M_callfunction: null string !");
187 VM_CheckEmptyString(s);
189 func = PRVM_ED_FindFunction(s);
192 PRVM_ERROR("VM_M_callfunciton: function %s not found !", s);
193 else if (func->first_statement < 0)
195 // negative statements are built in functions
196 int builtinnumber = -func->first_statement;
197 prog->xfunction->builtinsprofile++;
198 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
199 prog->builtins[builtinnumber]();
201 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
206 PRVM_ExecuteProgram(func - prog->functions,"");
215 float isfunction(string function_name)
218 mfunction_t *PRVM_ED_FindFunction (const char *name);
219 void VM_M_isfunction(void)
224 VM_SAFEPARMCOUNT(1, VM_M_isfunction);
226 s = PRVM_G_STRING(OFS_PARM0);
229 PRVM_ERROR("VM_M_isfunction: null string !");
231 VM_CheckEmptyString(s);
233 func = PRVM_ED_FindFunction(s);
236 PRVM_G_FLOAT(OFS_RETURN) = false;
238 PRVM_G_FLOAT(OFS_RETURN) = true;
245 writetofile(float fhandle, entity ent)
248 void VM_M_writetofile(void)
253 VM_SAFEPARMCOUNT(2, VM_M_writetofile);
255 file = VM_GetFileHandle( (int)PRVM_G_FLOAT(OFS_PARM0) );
258 VM_Warning("VM_M_writetofile: invalid or closed file handle\n");
262 ent = PRVM_G_EDICT(OFS_PARM1);
263 if(ent->priv.required->free)
265 VM_Warning("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
269 PRVM_ED_Write (file, ent);
276 vector getresolution(float number)
279 extern unsigned short video_resolutions[][2];
280 void VM_M_getresolution(void)
283 VM_SAFEPARMCOUNT(1, VM_getresolution);
285 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
288 PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
289 PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1];
290 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
295 VM_M_findkeysforcommand
297 string findkeysforcommand(string command)
299 the returned string is an altstring
302 #define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
304 void M_FindKeysForCommand(const char *command, int *keys);
305 void VM_M_findkeysforcommand(void)
312 VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
314 cmd = PRVM_G_STRING(OFS_PARM0);
316 VM_CheckEmptyString(cmd);
318 (ret = VM_GetTempString())[0] = 0;
320 M_FindKeysForCommand(cmd, keys);
322 for(i = 0; i < NUMKEYS; i++)
323 strlcat(ret, va(" \'%i\'", keys[i]), VM_STRINGTEMP_LENGTH);
325 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(ret);
330 VM_M_getserverliststat
332 float getserverliststat(float type)
337 0 serverlist_viewcount
338 1 serverlist_totalcount
346 void VM_M_getserverliststat( void )
349 VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
351 PRVM_G_FLOAT( OFS_RETURN ) = 0;
353 type = (int)PRVM_G_FLOAT( OFS_PARM0 );
357 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
360 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
362 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
365 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
368 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
371 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
374 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
377 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
380 VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
385 ========================
386 VM_M_resetserverlistmasks
388 resetserverlistmasks()
389 ========================
391 void VM_M_resetserverlistmasks( void )
393 ServerList_ResetMasks();
398 ========================
399 VM_M_setserverlistmaskstring
401 setserverlistmaskstring(float mask, float fld, string str, float op)
404 ========================
406 void VM_M_setserverlistmaskstring( void )
410 serverlist_mask_t *mask;
413 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
414 str = PRVM_G_STRING( OFS_PARM2 );
416 PRVM_ERROR( "VM_M_setserverlistmaskstring: null string passed!" );
418 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
419 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
420 mask = &serverlist_andmasks[masknr];
421 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
422 mask = &serverlist_ormasks[masknr - 512 ];
425 VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
429 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
433 strlcpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
436 strlcpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name) );
439 strlcpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map) );
442 strlcpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod) );
445 strlcpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game) );
448 VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
453 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
457 ========================
458 VM_M_setserverlistmasknumber
460 setserverlistmasknumber(float mask, float fld, float num, float op)
464 ========================
466 void VM_M_setserverlistmasknumber( void )
469 serverlist_mask_t *mask;
472 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
474 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
475 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
476 mask = &serverlist_andmasks[masknr];
477 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
478 mask = &serverlist_ormasks[masknr - 512 ];
481 VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
485 number = (int)PRVM_G_FLOAT( OFS_PARM2 );
486 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
489 case SLIF_MAXPLAYERS:
490 mask->info.maxplayers = number;
492 case SLIF_NUMPLAYERS:
493 mask->info.numplayers = number;
496 mask->info.ping = number;
499 mask->info.protocol = number;
502 VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
507 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
512 ========================
513 VM_M_resortserverlist
516 ========================
518 void VM_M_resortserverlist( void )
520 ServerList_RebuildViewList();
525 VM_M_getserverliststring
527 string getserverliststring(float field, float hostnr)
530 void VM_M_getserverliststring(void)
532 serverlist_entry_t *cache;
535 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
537 PRVM_G_INT(OFS_RETURN) = 0;
539 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
541 if(hostnr < 0 || hostnr >= serverlist_viewcount)
543 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
546 cache = serverlist_viewlist[hostnr];
547 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
549 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
552 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
555 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
558 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
561 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
563 // TODO remove this again
565 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
568 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
571 Con_Print("VM_M_getserverliststring: bad field number passed!\n");
577 VM_M_getserverlistnumber
579 float getserverlistnumber(float field, float hostnr)
582 void VM_M_getserverlistnumber(void)
584 serverlist_entry_t *cache;
587 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
589 PRVM_G_INT(OFS_RETURN) = 0;
591 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
593 if(hostnr < 0 || hostnr >= serverlist_viewcount)
595 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
598 cache = serverlist_viewlist[hostnr];
599 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
600 case SLIF_MAXPLAYERS:
601 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
603 case SLIF_NUMPLAYERS:
604 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
607 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
610 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
613 Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
618 ========================
619 VM_M_setserverlistsort
621 setserverlistsort(float field, float descending)
622 ========================
624 void VM_M_setserverlistsort( void )
626 VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
628 serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
629 serverlist_sortdescending = (qboolean) PRVM_G_FLOAT( OFS_PARM1 );
633 ========================
634 VM_M_refreshserverlist
637 ========================
639 void VM_M_refreshserverlist( void )
641 VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
642 ServerList_QueryList(true, false);
646 ========================
647 VM_M_getserverlistindexforkey
649 float getserverlistindexforkey(string key)
650 ========================
652 void VM_M_getserverlistindexforkey( void )
655 VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
657 key = PRVM_G_STRING( OFS_PARM0 );
658 VM_CheckEmptyString( key );
660 if( !strcmp( key, "cname" ) )
661 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
662 else if( !strcmp( key, "ping" ) )
663 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
664 else if( !strcmp( key, "game" ) )
665 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
666 else if( !strcmp( key, "mod" ) )
667 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
668 else if( !strcmp( key, "map" ) )
669 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
670 else if( !strcmp( key, "name" ) )
671 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
672 else if( !strcmp( key, "maxplayers" ) )
673 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
674 else if( !strcmp( key, "numplayers" ) )
675 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
676 else if( !strcmp( key, "protocol" ) )
677 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
679 PRVM_G_FLOAT( OFS_RETURN ) = -1;
683 ========================
684 VM_M_addwantedserverlistkey
686 addwantedserverlistkey(string key)
687 ========================
689 void VM_M_addwantedserverlistkey( void )
691 VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
695 ===============================================================================
698 used only for client and menu
699 severs uses VM_SV_...
701 Write*(* data, float type, float to)
703 ===============================================================================
706 #define MSG_BROADCAST 0 // unreliable to all
707 #define MSG_ONE 1 // reliable to one (msg_entity)
708 #define MSG_ALL 2 // reliable to all
709 #define MSG_INIT 3 // write to the init string
711 sizebuf_t *VM_WriteDest (void)
717 PRVM_ERROR("VM_WriteDest: game is not server (%s)", PRVM_NAME);
719 dest = (int)PRVM_G_FLOAT(OFS_PARM1);
726 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
727 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
728 PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
730 return &svs.clients[destclient].netconnection->message;
733 return &sv.reliable_datagram;
739 PRVM_ERROR ("WriteDest: bad destination");
746 void VM_M_WriteByte (void)
748 MSG_WriteByte (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
751 void VM_M_WriteChar (void)
753 MSG_WriteChar (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
756 void VM_M_WriteShort (void)
758 MSG_WriteShort (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
761 void VM_M_WriteLong (void)
763 MSG_WriteLong (VM_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
766 void VM_M_WriteAngle (void)
768 MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
771 void VM_M_WriteCoord (void)
773 MSG_WriteCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
776 void VM_M_WriteString (void)
778 MSG_WriteString (VM_WriteDest(), PRVM_G_STRING(OFS_PARM0));
781 void VM_M_WriteEntity (void)
783 MSG_WriteShort (VM_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
786 //string(void) getextresponse = #624; // returns the next extResponse packet that was sent to this client
787 void VM_M_getextresponse (void)
789 VM_SAFEPARMCOUNT(0,VM_argv);
791 if (net_extresponse_count <= 0)
793 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(NULL);
798 --net_extresponse_count;
799 first = (net_extresponse_last + NET_EXTRESPONSE_MAX - net_extresponse_count) % NET_EXTRESPONSE_MAX;
800 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(net_extresponse[first]);
804 prvm_builtin_t vm_m_builtins[] = {
805 0, // to be consistent with the old vm
806 // common builtings (mostly)
883 VM_search_getfilename, // 77
895 VM_cvar_defstring, // 89
909 VM_M_WriteEntity, // 408
925 VM_drawresetcliparea,
926 VM_getimagesize,// 460
931 VM_cin_restart, // 465
934 VM_asin, // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
935 VM_acos, // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
936 VM_atan, // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
937 VM_atan2, // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
938 VM_tan, // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
939 VM_strlennocol, // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
940 VM_strdecolorize, // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
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
972 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
974 void VM_M_Cmd_Init(void)
979 void VM_M_Cmd_Reset(void)