3 //============================================================================
6 char *vm_m_extensions =
9 "DP_MENU_EXTRESPONSEPACKET "
10 "DP_QC_ASINACOSATANATAN2TAN "
12 "DP_QC_STRING_CASE_FUNCTIONS "
13 "DP_QC_STRINGCOLORFUNCTIONS "
14 "DP_QC_TOKENIZEBYSEPARATOR "
15 "DP_QC_UNLIMITEDTEMPSTRINGS "
23 setmousetarget(float target)
26 void VM_M_setmousetarget(void)
28 VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
30 switch((int)PRVM_G_FLOAT(OFS_PARM0))
33 in_client_mouse = false;
36 in_client_mouse = true;
39 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
50 void VM_M_getmousetarget(void)
52 VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
55 PRVM_G_FLOAT(OFS_RETURN) = 2;
57 PRVM_G_FLOAT(OFS_RETURN) = 1;
66 setkeydest(float dest)
69 void VM_M_setkeydest(void)
71 VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
73 switch((int)PRVM_G_FLOAT(OFS_PARM0))
85 // key_dest = key_message
88 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
99 void VM_M_getkeydest(void)
101 VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
103 // key_game = 0, key_message = 1, key_menu = 2, unknown = 3
107 PRVM_G_FLOAT(OFS_RETURN) = 0;
110 PRVM_G_FLOAT(OFS_RETURN) = 2;
114 // PRVM_G_FLOAT(OFS_RETURN) = 1;
117 PRVM_G_FLOAT(OFS_RETURN) = 3;
125 callfunction(...,string function_name)
129 mfunction_t *PRVM_ED_FindFunction (const char *name);
130 void VM_M_callfunction(void)
135 VM_SAFEPARMCOUNTRANGE(1, 8, VM_M_callfunction);
137 s = PRVM_G_STRING(OFS_PARM0+(prog->argc - 1)*3);
139 VM_CheckEmptyString(s);
141 func = PRVM_ED_FindFunction(s);
144 PRVM_ERROR("VM_M_callfunciton: function %s not found !", s);
145 else if (func->first_statement < 0)
147 // negative statements are built in functions
148 int builtinnumber = -func->first_statement;
149 prog->xfunction->builtinsprofile++;
150 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
151 prog->builtins[builtinnumber]();
153 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
155 else if(func - prog->functions > 0)
158 PRVM_ExecuteProgram(func - prog->functions,"");
167 float isfunction(string function_name)
170 mfunction_t *PRVM_ED_FindFunction (const char *name);
171 void VM_M_isfunction(void)
176 VM_SAFEPARMCOUNT(1, VM_M_isfunction);
178 s = PRVM_G_STRING(OFS_PARM0);
180 VM_CheckEmptyString(s);
182 func = PRVM_ED_FindFunction(s);
185 PRVM_G_FLOAT(OFS_RETURN) = false;
187 PRVM_G_FLOAT(OFS_RETURN) = true;
194 vector getresolution(float number)
197 extern unsigned short video_resolutions[][2];
198 void VM_M_getresolution(void)
201 VM_SAFEPARMCOUNT(1, VM_getresolution);
203 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
206 PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
207 PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1];
208 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
213 VM_M_findkeysforcommand
215 string findkeysforcommand(string command)
217 the returned string is an altstring
220 #define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
222 void M_FindKeysForCommand(const char *command, int *keys);
223 void VM_M_findkeysforcommand(void)
226 char ret[VM_STRINGTEMP_LENGTH];
230 VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
232 cmd = PRVM_G_STRING(OFS_PARM0);
234 VM_CheckEmptyString(cmd);
236 M_FindKeysForCommand(cmd, keys);
239 for(i = 0; i < NUMKEYS; i++)
240 strlcat(ret, va(" \'%i\'", keys[i]), sizeof(ret));
242 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(ret);
247 VM_M_getserverliststat
249 float getserverliststat(float type)
254 0 serverlist_viewcount
255 1 serverlist_totalcount
263 void VM_M_getserverliststat( void )
266 VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
268 PRVM_G_FLOAT( OFS_RETURN ) = 0;
270 type = (int)PRVM_G_FLOAT( OFS_PARM0 );
274 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
277 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
279 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
282 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
285 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
288 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
291 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
294 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
297 VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
302 ========================
303 VM_M_resetserverlistmasks
305 resetserverlistmasks()
306 ========================
308 void VM_M_resetserverlistmasks( void )
310 VM_SAFEPARMCOUNT(0, VM_M_resetserverlistmasks);
311 ServerList_ResetMasks();
316 ========================
317 VM_M_setserverlistmaskstring
319 setserverlistmaskstring(float mask, float fld, string str, float op)
322 ========================
324 void VM_M_setserverlistmaskstring( void )
328 serverlist_mask_t *mask;
331 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
332 str = PRVM_G_STRING( OFS_PARM2 );
334 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
335 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
336 mask = &serverlist_andmasks[masknr];
337 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
338 mask = &serverlist_ormasks[masknr - 512 ];
341 VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
345 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
349 strlcpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
352 strlcpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name) );
355 strlcpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map) );
358 strlcpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod) );
361 strlcpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game) );
364 VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
369 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
373 ========================
374 VM_M_setserverlistmasknumber
376 setserverlistmasknumber(float mask, float fld, float num, float op)
380 ========================
382 void VM_M_setserverlistmasknumber( void )
385 serverlist_mask_t *mask;
388 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
390 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
391 if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
392 mask = &serverlist_andmasks[masknr];
393 else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
394 mask = &serverlist_ormasks[masknr - 512 ];
397 VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
401 number = (int)PRVM_G_FLOAT( OFS_PARM2 );
402 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
405 case SLIF_MAXPLAYERS:
406 mask->info.maxplayers = number;
408 case SLIF_NUMPLAYERS:
409 mask->info.numplayers = number;
412 mask->info.numbots = number;
415 mask->info.numhumans = number;
418 mask->info.ping = number;
421 mask->info.protocol = number;
424 VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
429 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
434 ========================
435 VM_M_resortserverlist
438 ========================
440 void VM_M_resortserverlist( void )
442 VM_SAFEPARMCOUNT(0, VM_M_resortserverlist);
443 ServerList_RebuildViewList();
448 VM_M_getserverliststring
450 string getserverliststring(float field, float hostnr)
453 void VM_M_getserverliststring(void)
455 serverlist_entry_t *cache;
458 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
460 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
462 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
464 if(hostnr < 0 || hostnr >= serverlist_viewcount)
466 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
469 cache = serverlist_viewlist[hostnr];
470 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
472 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
475 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
478 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
481 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
484 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
486 // TODO remove this again
488 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
491 PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
494 Con_Print("VM_M_getserverliststring: bad field number passed!\n");
500 VM_M_getserverlistnumber
502 float getserverlistnumber(float field, float hostnr)
505 void VM_M_getserverlistnumber(void)
507 serverlist_entry_t *cache;
510 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
512 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
514 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
516 if(hostnr < 0 || hostnr >= serverlist_viewcount)
518 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
521 cache = serverlist_viewlist[hostnr];
522 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
523 case SLIF_MAXPLAYERS:
524 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
526 case SLIF_NUMPLAYERS:
527 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
530 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numbots;
533 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numhumans;
536 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
539 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
542 Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
547 ========================
548 VM_M_setserverlistsort
550 setserverlistsort(float field, float descending)
551 ========================
553 void VM_M_setserverlistsort( void )
555 VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
557 serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
558 serverlist_sortdescending = (qboolean) PRVM_G_FLOAT( OFS_PARM1 );
562 ========================
563 VM_M_refreshserverlist
566 ========================
568 void VM_M_refreshserverlist( void )
570 VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
571 ServerList_QueryList(true, false);
575 ========================
576 VM_M_getserverlistindexforkey
578 float getserverlistindexforkey(string key)
579 ========================
581 void VM_M_getserverlistindexforkey( void )
584 VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
586 key = PRVM_G_STRING( OFS_PARM0 );
587 VM_CheckEmptyString( key );
589 if( !strcmp( key, "cname" ) )
590 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
591 else if( !strcmp( key, "ping" ) )
592 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
593 else if( !strcmp( key, "game" ) )
594 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
595 else if( !strcmp( key, "mod" ) )
596 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
597 else if( !strcmp( key, "map" ) )
598 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
599 else if( !strcmp( key, "name" ) )
600 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
601 else if( !strcmp( key, "maxplayers" ) )
602 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
603 else if( !strcmp( key, "numplayers" ) )
604 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
605 else if( !strcmp( key, "numbots" ) )
606 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS;
607 else if( !strcmp( key, "numhumans" ) )
608 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS;
609 else if( !strcmp( key, "protocol" ) )
610 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
612 PRVM_G_FLOAT( OFS_RETURN ) = -1;
616 ========================
617 VM_M_addwantedserverlistkey
619 addwantedserverlistkey(string key)
620 ========================
622 void VM_M_addwantedserverlistkey( void )
624 VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
628 ===============================================================================
631 used only for client and menu
632 server uses VM_SV_...
634 Write*(* data, float type, float to)
636 ===============================================================================
639 #define MSG_BROADCAST 0 // unreliable to all
640 #define MSG_ONE 1 // reliable to one (msg_entity)
641 #define MSG_ALL 2 // reliable to all
642 #define MSG_INIT 3 // write to the init string
644 sizebuf_t *VM_M_WriteDest (void)
650 PRVM_ERROR("VM_M_WriteDest: game is not server (%s)", PRVM_NAME);
652 dest = (int)PRVM_G_FLOAT(OFS_PARM1);
659 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
660 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
661 PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
663 return &svs.clients[destclient].netconnection->message;
666 return &sv.reliable_datagram;
672 PRVM_ERROR ("WriteDest: bad destination");
679 void VM_M_WriteByte (void)
681 VM_SAFEPARMCOUNT(1, VM_M_WriteByte);
682 MSG_WriteByte (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
685 void VM_M_WriteChar (void)
687 VM_SAFEPARMCOUNT(1, VM_M_WriteChar);
688 MSG_WriteChar (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
691 void VM_M_WriteShort (void)
693 VM_SAFEPARMCOUNT(1, VM_M_WriteShort);
694 MSG_WriteShort (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
697 void VM_M_WriteLong (void)
699 VM_SAFEPARMCOUNT(1, VM_M_WriteLong);
700 MSG_WriteLong (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
703 void VM_M_WriteAngle (void)
705 VM_SAFEPARMCOUNT(1, VM_M_WriteAngle);
706 MSG_WriteAngle (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
709 void VM_M_WriteCoord (void)
711 VM_SAFEPARMCOUNT(1, VM_M_WriteCoord);
712 MSG_WriteCoord (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
715 void VM_M_WriteString (void)
717 VM_SAFEPARMCOUNT(1, VM_M_WriteString);
718 MSG_WriteString (VM_M_WriteDest(), PRVM_G_STRING(OFS_PARM0));
721 void VM_M_WriteEntity (void)
723 VM_SAFEPARMCOUNT(1, VM_M_WriteEntity);
724 MSG_WriteShort (VM_M_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
727 //string(void) getextresponse = #624; // returns the next extResponse packet that was sent to this client
728 void VM_M_getextresponse (void)
730 VM_SAFEPARMCOUNT(0,VM_argv);
732 if (net_extresponse_count <= 0)
733 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
737 --net_extresponse_count;
738 first = (net_extresponse_last + NET_EXTRESPONSE_MAX - net_extresponse_count) % NET_EXTRESPONSE_MAX;
739 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(net_extresponse[first]);
747 copies data from one entity to another
749 copyentity(entity src, entity dst)
752 static void VM_M_copyentity (void)
754 prvm_edict_t *in, *out;
755 VM_SAFEPARMCOUNT(2,VM_M_copyentity);
756 in = PRVM_G_EDICT(OFS_PARM0);
757 out = PRVM_G_EDICT(OFS_PARM1);
758 memcpy(out->fields.vp, in->fields.vp, prog->progs->entityfields * 4);
761 prvm_builtin_t vm_m_builtins[] = {
762 NULL, // #0 NULL function (not callable)
763 VM_checkextension, // #1
769 VM_centerprint, // #7
773 VM_vectoangles, // #11
789 VM_findchainfloat, // #27
790 VM_precache_file, // #28
791 VM_precache_sound, // #29
804 VM_registercvar, // #42
809 VM_M_copyentity, // #47
823 VM_clientcount, // #61
824 VM_clientstate, // #62
826 VM_changelevel, // #64
827 VM_localsound, // #65
828 VM_getmousepos, // #66
830 VM_loadfromdata, // #68
831 VM_loadfromfile, // #69
833 VM_cvar_string, // #71
836 VM_search_begin, // #74
837 VM_search_end, // #75
838 VM_search_getsize, // #76
839 VM_search_getfilename, // #77
843 VM_itof, // #81 isString
844 VM_altstr_count, // #82
845 VM_altstr_prepare, // #83
846 VM_altstr_get, // #84
847 VM_altstr_set, // #85
848 VM_altstr_ins, // #86
850 VM_findchainflags, // #88
851 VM_cvar_defstring, // #89
1163 VM_M_WriteByte, // #401
1164 VM_M_WriteChar, // #402
1165 VM_M_WriteShort, // #403
1166 VM_M_WriteLong, // #404
1167 VM_M_WriteAngle, // #405
1168 VM_M_WriteCoord, // #406
1169 VM_M_WriteString, // #407
1170 VM_M_WriteEntity, // #408
1213 VM_iscachedpic, // #451 draw functions...
1214 VM_precache_pic, // #452
1216 VM_drawcharacter, // #454
1217 VM_drawstring, // #455
1219 VM_drawfill, // #457
1220 VM_drawsetcliparea, // #458
1221 VM_drawresetcliparea, // #459
1222 VM_getimagesize, // #460
1223 VM_cin_open, // #461
1224 VM_cin_close, // #462
1225 VM_cin_setstate, // #463
1226 VM_cin_getstate, // #464
1227 VM_cin_restart, // #465
1228 VM_drawline, // #466
1233 VM_asin, // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
1234 VM_acos, // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
1235 VM_atan, // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
1236 VM_atan2, // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
1237 VM_tan, // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
1238 VM_strlennocol, // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
1239 VM_strdecolorize, // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
1240 VM_strftime, // #478 string(float uselocaltime, string format, ...) (DP_QC_STRFTIME)
1241 VM_tokenizebyseparator, // #479 float(string s) tokenizebyseparator (DP_QC_TOKENIZEBYSEPARATOR)
1242 VM_strtolower, // #480 string(string s) VM_strtolower : DRESK - Return string as lowercase
1243 VM_strtoupper, // #481 string(string s) VM_strtoupper : DRESK - Return string as uppercase
1363 VM_M_setkeydest, // #601 menu functions...
1364 VM_M_getkeydest, // #602
1365 VM_M_setmousetarget, // #603
1366 VM_M_getmousetarget, // #604
1367 VM_M_callfunction, // #605
1368 VM_writetofile, // #606
1369 VM_M_isfunction, // #607
1370 VM_M_getresolution, // #608
1371 VM_keynumtostring, // #609
1372 VM_M_findkeysforcommand, // #610
1373 VM_M_getserverliststat, // #611
1374 VM_M_getserverliststring, // #612
1375 VM_parseentitydata, // #613
1376 VM_stringtokeynum, // #614
1377 VM_M_resetserverlistmasks, // #615
1378 VM_M_setserverlistmaskstring,// #616
1379 VM_M_setserverlistmasknumber,// #617
1380 VM_M_resortserverlist, // #618
1381 VM_M_setserverlistsort, // #619
1382 VM_M_refreshserverlist, // #620
1383 VM_M_getserverlistnumber, // #621
1384 VM_M_getserverlistindexforkey,// #622
1385 VM_M_addwantedserverlistkey,// #623
1386 VM_M_getextresponse // #624
1389 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
1391 void VM_M_Cmd_Init(void)
1396 void VM_M_Cmd_Reset(void)