DP_QC_AUTOCVARS: declare a QC variable float/vector/string autocvar_foo, and it will...
[divverent/darkplaces.git] / mvm_cmds.c
1 #include "quakedef.h"
2
3 #include "prvm_cmds.h"
4 #include "clvm_cmds.h"
5 #include "menu.h"
6
7 // TODO check which strings really should be engine strings
8
9 //============================================================================
10 // Menu
11
12 char *vm_m_extensions =
13 "BX_WAL_SUPPORT "
14 "DP_CINEMATIC_DPV "
15 "DP_FONT_VARIABLEWIDTH "
16 "DP_GECKO_SUPPORT "
17 "DP_MENU_EXTRESPONSEPACKET "
18 "DP_QC_ASINACOSATANATAN2TAN "
19 "DP_QC_AUTOCVARS "
20 "DP_QC_CMD "
21 "DP_QC_CRC16 "
22 "DP_QC_CVAR_TYPE "
23 "DP_QC_CVAR_DESCRIPTION "
24 "DP_QC_FINDCHAIN_TOFIELD "
25 "DP_QC_LOG "
26 "DP_QC_RENDER_SCENE "
27 "DP_QC_STRFTIME "
28 "DP_QC_STRINGBUFFERS "
29 "DP_QC_STRINGBUFFERS_CVARLIST "
30 "DP_QC_STRINGCOLORFUNCTIONS "
31 "DP_QC_STRING_CASE_FUNCTIONS "
32 "DP_QC_STRREPLACE "
33 "DP_QC_TOKENIZEBYSEPARATOR "
34 "DP_QC_TOKENIZE_CONSOLE "
35 "DP_QC_UNLIMITEDTEMPSTRINGS "
36 "DP_QC_URI_ESCAPE "
37 "DP_QC_URI_GET "
38 "DP_QC_WHICHPACK "
39 "FTE_STRINGS "
40 ;
41
42 /*
43 =========
44 VM_M_setmousetarget
45
46 setmousetarget(float target)
47 =========
48 */
49 void VM_M_setmousetarget(void)
50 {
51         VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
52
53         switch((int)PRVM_G_FLOAT(OFS_PARM0))
54         {
55         case 1:
56                 in_client_mouse = false;
57                 break;
58         case 2:
59                 in_client_mouse = true;
60                 break;
61         default:
62                 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
63         }
64 }
65
66 /*
67 =========
68 VM_M_getmousetarget
69
70 float   getmousetarget
71 =========
72 */
73 void VM_M_getmousetarget(void)
74 {
75         VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
76
77         if(in_client_mouse)
78                 PRVM_G_FLOAT(OFS_RETURN) = 2;
79         else
80                 PRVM_G_FLOAT(OFS_RETURN) = 1;
81 }
82
83
84
85 /*
86 =========
87 VM_M_setkeydest
88
89 setkeydest(float dest)
90 =========
91 */
92 void VM_M_setkeydest(void)
93 {
94         VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
95
96         switch((int)PRVM_G_FLOAT(OFS_PARM0))
97         {
98         case 0:
99                 // key_game
100                 key_dest = key_game;
101                 break;
102         case 2:
103                 // key_menu
104                 key_dest = key_menu;
105                 break;
106         case 3:
107                 // key_menu_grabbed
108                 key_dest = key_menu_grabbed;
109                 break;
110         case 1:
111                 // key_message
112                 // key_dest = key_message
113                 // break;
114         default:
115                 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
116         }
117 }
118
119 /*
120 =========
121 VM_M_getkeydest
122
123 float   getkeydest
124 =========
125 */
126 void VM_M_getkeydest(void)
127 {
128         VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
129
130         // key_game = 0, key_message = 1, key_menu = 2, key_menu_grabbed = 3, unknown = -1
131         switch(key_dest)
132         {
133         case key_game:
134                 PRVM_G_FLOAT(OFS_RETURN) = 0;
135                 break;
136         case key_menu:
137                 PRVM_G_FLOAT(OFS_RETURN) = 2;
138                 break;
139         case key_menu_grabbed:
140                 PRVM_G_FLOAT(OFS_RETURN) = 3;
141                 break;
142         case key_message:
143                 // not supported
144                 // PRVM_G_FLOAT(OFS_RETURN) = 1;
145                 // break;
146         default:
147                 PRVM_G_FLOAT(OFS_RETURN) = -1;
148         }
149 }
150
151
152 /*
153 =========
154 VM_M_getresolution
155
156 vector  getresolution(float number)
157 =========
158 */
159 void VM_M_getresolution(void)
160 {
161         int nr, fs;
162         VM_SAFEPARMCOUNTRANGE(1, 2, VM_getresolution);
163
164         nr = (int)PRVM_G_FLOAT(OFS_PARM0);
165
166         fs = ((prog->argc <= 1) || ((int)PRVM_G_FLOAT(OFS_PARM1)));
167
168         if(nr < 0 || nr >= (fs ? video_resolutions_count : video_resolutions_hardcoded_count))
169         {
170                 PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
171                 PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
172                 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
173         }
174         else
175         {
176                 video_resolution_t *r = &((fs ? video_resolutions : video_resolutions_hardcoded)[nr]);
177                 PRVM_G_VECTOR(OFS_RETURN)[0] = r->width;
178                 PRVM_G_VECTOR(OFS_RETURN)[1] = r->height;
179                 PRVM_G_VECTOR(OFS_RETURN)[2] = r->pixelheight;
180         }
181 }
182
183 void VM_M_getgamedirinfo(void)
184 {
185         int nr, item;
186         VM_SAFEPARMCOUNT(2, VM_getgamedirinfo);
187
188         nr = (int)PRVM_G_FLOAT(OFS_PARM0);
189         item = (int)PRVM_G_FLOAT(OFS_PARM1);
190
191         PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
192
193         if(nr >= 0 && nr < fs_all_gamedirs_count)
194         {
195                 if(item == 0)
196                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( fs_all_gamedirs[nr].name );
197                 else if(item == 1)
198                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( fs_all_gamedirs[nr].description );
199         }
200 }
201
202 /*
203 =========
204 VM_M_getserverliststat
205
206 float   getserverliststat(float type)
207 =========
208 */
209 /*
210         type:
211 0       serverlist_viewcount
212 1   serverlist_totalcount
213 2       masterquerycount
214 3       masterreplycount
215 4       serverquerycount
216 5       serverreplycount
217 6       sortfield
218 7       sortflags
219 */
220 void VM_M_getserverliststat( void )
221 {
222         int type;
223         VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
224
225         PRVM_G_FLOAT( OFS_RETURN ) = 0;
226
227         type = (int)PRVM_G_FLOAT( OFS_PARM0 );
228         switch(type)
229         {
230         case 0:
231                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
232                 return;
233         case 1:
234                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
235         case 2:
236                 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
237                 return;
238         case 3:
239                 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
240                 return;
241         case 4:
242                 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
243                 return;
244         case 5:
245                 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
246                 return;
247         case 6:
248                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
249                 return;
250         case 7:
251                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortflags;
252                 return;
253         default:
254                 VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
255         }
256 }
257
258 /*
259 ========================
260 VM_M_resetserverlistmasks
261
262 resetserverlistmasks()
263 ========================
264 */
265 void VM_M_resetserverlistmasks( void )
266 {
267         VM_SAFEPARMCOUNT(0, VM_M_resetserverlistmasks);
268         ServerList_ResetMasks();
269 }
270
271
272 /*
273 ========================
274 VM_M_setserverlistmaskstring
275
276 setserverlistmaskstring(float mask, float fld, string str, float op)
277 0-511           and
278 512 - 1024      or
279 ========================
280 */
281 void VM_M_setserverlistmaskstring( void )
282 {
283         const char *str;
284         int masknr;
285         serverlist_mask_t *mask;
286         int field;
287
288         VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
289         str = PRVM_G_STRING( OFS_PARM2 );
290
291         masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
292         if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
293                 mask = &serverlist_andmasks[masknr];
294         else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
295                 mask = &serverlist_ormasks[masknr - 512 ];
296         else
297         {
298                 VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
299                 return;
300         }
301
302         field = (int) PRVM_G_FLOAT( OFS_PARM1 );
303
304         switch( field ) {
305                 case SLIF_CNAME:
306                         strlcpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
307                         break;
308                 case SLIF_NAME:
309                         strlcpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name)  );
310                         break;
311                 case SLIF_QCSTATUS:
312                         strlcpy( mask->info.qcstatus, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.qcstatus)  );
313                         break;
314                 case SLIF_PLAYERS:
315                         strlcpy( mask->info.players, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.players)  );
316                         break;
317                 case SLIF_MAP:
318                         strlcpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map)  );
319                         break;
320                 case SLIF_MOD:
321                         strlcpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod)  );
322                         break;
323                 case SLIF_GAME:
324                         strlcpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game)  );
325                         break;
326                 default:
327                         VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
328                         return;
329         }
330
331         mask->active = true;
332         mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
333 }
334
335 /*
336 ========================
337 VM_M_setserverlistmasknumber
338
339 setserverlistmasknumber(float mask, float fld, float num, float op)
340
341 0-511           and
342 512 - 1024      or
343 ========================
344 */
345 void VM_M_setserverlistmasknumber( void )
346 {
347         int number;
348         serverlist_mask_t *mask;
349         int     masknr;
350         int field;
351         VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
352
353         masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
354         if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
355                 mask = &serverlist_andmasks[masknr];
356         else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
357                 mask = &serverlist_ormasks[masknr - 512 ];
358         else
359         {
360                 VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
361                 return;
362         }
363
364         number = (int)PRVM_G_FLOAT( OFS_PARM2 );
365         field = (int) PRVM_G_FLOAT( OFS_PARM1 );
366
367         switch( field ) {
368                 case SLIF_MAXPLAYERS:
369                         mask->info.maxplayers = number;
370                         break;
371                 case SLIF_NUMPLAYERS:
372                         mask->info.numplayers = number;
373                         break;
374                 case SLIF_NUMBOTS:
375                         mask->info.numbots = number;
376                         break;
377                 case SLIF_NUMHUMANS:
378                         mask->info.numhumans = number;
379                         break;
380                 case SLIF_PING:
381                         mask->info.ping = number;
382                         break;
383                 case SLIF_PROTOCOL:
384                         mask->info.protocol = number;
385                         break;
386                 case SLIF_FREESLOTS:
387                         mask->info.freeslots = number;
388                         break;
389                 case SLIF_ISFAVORITE:
390                         mask->info.isfavorite = number != 0;
391                         break;
392                 default:
393                         VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
394                         return;
395         }
396
397         mask->active = true;
398         mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
399 }
400
401
402 /*
403 ========================
404 VM_M_resortserverlist
405
406 resortserverlist
407 ========================
408 */
409 void VM_M_resortserverlist( void )
410 {
411         VM_SAFEPARMCOUNT(0, VM_M_resortserverlist);
412         ServerList_RebuildViewList();
413 }
414
415 /*
416 =========
417 VM_M_getserverliststring
418
419 string  getserverliststring(float field, float hostnr)
420 =========
421 */
422 void VM_M_getserverliststring(void)
423 {
424         serverlist_entry_t *cache;
425         int hostnr;
426
427         VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
428
429         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
430
431         hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
432
433         if(hostnr < 0 || hostnr >= serverlist_viewcount)
434         {
435                 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
436                 return;
437         }
438         cache = serverlist_viewlist[hostnr];
439         switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
440                 case SLIF_CNAME:
441                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
442                         break;
443                 case SLIF_NAME:
444                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
445                         break;
446                 case SLIF_QCSTATUS:
447                         PRVM_G_INT (OFS_RETURN ) = PRVM_SetEngineString (cache->info.qcstatus );
448                         break;
449                 case SLIF_PLAYERS:
450                         PRVM_G_INT (OFS_RETURN ) = PRVM_SetEngineString (cache->info.players );
451                         break;
452                 case SLIF_GAME:
453                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
454                         break;
455                 case SLIF_MOD:
456                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
457                         break;
458                 case SLIF_MAP:
459                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
460                         break;
461                 // TODO remove this again
462                 case 1024:
463                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
464                         break;
465                 case 1025:
466                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
467                         break;
468                 default:
469                         Con_Print("VM_M_getserverliststring: bad field number passed!\n");
470         }
471 }
472
473 /*
474 =========
475 VM_M_getserverlistnumber
476
477 float   getserverlistnumber(float field, float hostnr)
478 =========
479 */
480 void VM_M_getserverlistnumber(void)
481 {
482         serverlist_entry_t *cache;
483         int hostnr;
484
485         VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
486
487         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
488
489         hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
490
491         if(hostnr < 0 || hostnr >= serverlist_viewcount)
492         {
493                 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
494                 return;
495         }
496         cache = serverlist_viewlist[hostnr];
497         switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
498                 case SLIF_MAXPLAYERS:
499                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
500                         break;
501                 case SLIF_NUMPLAYERS:
502                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
503                         break;
504                 case SLIF_NUMBOTS:
505                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numbots;
506                         break;
507                 case SLIF_NUMHUMANS:
508                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numhumans;
509                         break;
510                 case SLIF_FREESLOTS:
511                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.freeslots;
512                         break;
513                 case SLIF_PING:
514                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
515                         break;
516                 case SLIF_PROTOCOL:
517                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
518                         break;
519                 case SLIF_ISFAVORITE:
520                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.isfavorite;
521                         break;
522                 default:
523                         Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
524         }
525 }
526
527 /*
528 ========================
529 VM_M_setserverlistsort
530
531 setserverlistsort(float field, float flags)
532 ========================
533 */
534 void VM_M_setserverlistsort( void )
535 {
536         VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
537
538         serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
539         serverlist_sortflags = (int) PRVM_G_FLOAT( OFS_PARM1 );
540 }
541
542 /*
543 ========================
544 VM_M_refreshserverlist
545
546 refreshserverlist()
547 ========================
548 */
549 void VM_M_refreshserverlist( void )
550 {
551         VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
552         ServerList_QueryList(false, true, false, false);
553 }
554
555 /*
556 ========================
557 VM_M_getserverlistindexforkey
558
559 float getserverlistindexforkey(string key)
560 ========================
561 */
562 void VM_M_getserverlistindexforkey( void )
563 {
564         const char *key;
565         VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
566
567         key = PRVM_G_STRING( OFS_PARM0 );
568         VM_CheckEmptyString( key );
569
570         if( !strcmp( key, "cname" ) )
571                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
572         else if( !strcmp( key, "ping" ) )
573                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
574         else if( !strcmp( key, "game" ) )
575                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
576         else if( !strcmp( key, "mod" ) )
577                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
578         else if( !strcmp( key, "map" ) )
579                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
580         else if( !strcmp( key, "name" ) )
581                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
582         else if( !strcmp( key, "qcstatus" ) )
583                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_QCSTATUS;
584         else if( !strcmp( key, "players" ) )
585                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PLAYERS;
586         else if( !strcmp( key, "maxplayers" ) )
587                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
588         else if( !strcmp( key, "numplayers" ) )
589                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
590         else if( !strcmp( key, "numbots" ) )
591                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS;
592         else if( !strcmp( key, "numhumans" ) )
593                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS;
594         else if( !strcmp( key, "freeslots" ) )
595                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_FREESLOTS;
596         else if( !strcmp( key, "protocol" ) )
597                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
598         else if( !strcmp( key, "isfavorite" ) )
599                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_ISFAVORITE;
600         else
601                 PRVM_G_FLOAT( OFS_RETURN ) = -1;
602 }
603
604 /*
605 ========================
606 VM_M_addwantedserverlistkey
607
608 addwantedserverlistkey(string key)
609 ========================
610 */
611 void VM_M_addwantedserverlistkey( void )
612 {
613         VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
614 }
615
616 /*
617 ===============================================================================
618 MESSAGE WRITING
619
620 used only for client and menu
621 server uses VM_SV_...
622
623 Write*(* data, float type, float to)
624
625 ===============================================================================
626 */
627
628 #define MSG_BROADCAST   0               // unreliable to all
629 #define MSG_ONE                 1               // reliable to one (msg_entity)
630 #define MSG_ALL                 2               // reliable to all
631 #define MSG_INIT                3               // write to the init string
632
633 sizebuf_t *VM_M_WriteDest (void)
634 {
635         int             dest;
636         int             destclient;
637
638         if(!sv.active)
639                 PRVM_ERROR("VM_M_WriteDest: game is not server (%s)", PRVM_NAME);
640
641         dest = (int)PRVM_G_FLOAT(OFS_PARM1);
642         switch (dest)
643         {
644         case MSG_BROADCAST:
645                 return &sv.datagram;
646
647         case MSG_ONE:
648                 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
649                 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
650                         PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
651
652                 return &svs.clients[destclient].netconnection->message;
653
654         case MSG_ALL:
655                 return &sv.reliable_datagram;
656
657         case MSG_INIT:
658                 return &sv.signon;
659
660         default:
661                 PRVM_ERROR ("WriteDest: bad destination");
662                 break;
663         }
664
665         return NULL;
666 }
667
668 void VM_M_WriteByte (void)
669 {
670         VM_SAFEPARMCOUNT(1, VM_M_WriteByte);
671         MSG_WriteByte (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
672 }
673
674 void VM_M_WriteChar (void)
675 {
676         VM_SAFEPARMCOUNT(1, VM_M_WriteChar);
677         MSG_WriteChar (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
678 }
679
680 void VM_M_WriteShort (void)
681 {
682         VM_SAFEPARMCOUNT(1, VM_M_WriteShort);
683         MSG_WriteShort (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
684 }
685
686 void VM_M_WriteLong (void)
687 {
688         VM_SAFEPARMCOUNT(1, VM_M_WriteLong);
689         MSG_WriteLong (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
690 }
691
692 void VM_M_WriteAngle (void)
693 {
694         VM_SAFEPARMCOUNT(1, VM_M_WriteAngle);
695         MSG_WriteAngle (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
696 }
697
698 void VM_M_WriteCoord (void)
699 {
700         VM_SAFEPARMCOUNT(1, VM_M_WriteCoord);
701         MSG_WriteCoord (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
702 }
703
704 void VM_M_WriteString (void)
705 {
706         VM_SAFEPARMCOUNT(1, VM_M_WriteString);
707         MSG_WriteString (VM_M_WriteDest(), PRVM_G_STRING(OFS_PARM0));
708 }
709
710 void VM_M_WriteEntity (void)
711 {
712         VM_SAFEPARMCOUNT(1, VM_M_WriteEntity);
713         MSG_WriteShort (VM_M_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
714 }
715
716 /*
717 =================
718 VM_M_copyentity
719
720 copies data from one entity to another
721
722 copyentity(entity src, entity dst)
723 =================
724 */
725 static void VM_M_copyentity (void)
726 {
727         prvm_edict_t *in, *out;
728         VM_SAFEPARMCOUNT(2,VM_M_copyentity);
729         in = PRVM_G_EDICT(OFS_PARM0);
730         out = PRVM_G_EDICT(OFS_PARM1);
731         memcpy(out->fields.vp, in->fields.vp, prog->progs->entityfields * 4);
732 }
733
734 //#66 vector() getmousepos (EXT_CSQC)
735 static void VM_M_getmousepos(void)
736 {
737         VM_SAFEPARMCOUNT(0,VM_M_getmousepos);
738
739         if (key_consoleactive || (key_dest != key_menu && key_dest != key_menu_grabbed))
740                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), 0, 0, 0);
741         else if (in_client_mouse)
742                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_windowmouse_x * vid_conwidth.integer / vid.width, in_windowmouse_y * vid_conheight.integer / vid.height, 0);
743         else
744                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_mouse_x * vid_conwidth.integer / vid.width, in_mouse_y * vid_conheight.integer / vid.height, 0);
745 }
746
747 //#349 float() isdemo (EXT_CSQC)
748 static void VM_M_isdemo (void)
749 {
750         VM_SAFEPARMCOUNT(0, VM_M_isdemo);
751         PRVM_G_FLOAT(OFS_RETURN) = cls.demoplayback;
752 }
753
754 prvm_builtin_t vm_m_builtins[] = {
755 NULL,                                                                   //   #0 NULL function (not callable)
756 VM_checkextension,                              //   #1
757 VM_error,                                                       //   #2
758 VM_objerror,                                            //   #3
759 VM_print,                                                       //   #4
760 VM_bprint,                                                      //   #5
761 VM_sprint,                                                      //   #6
762 VM_centerprint,                                 //   #7
763 VM_normalize,                                           //   #8
764 VM_vlen,                                                                //   #9
765 VM_vectoyaw,                                            //  #10
766 VM_vectoangles,                                 //  #11
767 VM_random,                                                      //  #12
768 VM_localcmd,                                            //  #13
769 VM_cvar,                                                                //  #14
770 VM_cvar_set,                                            //  #15
771 VM_dprint,                                                      //  #16
772 VM_ftos,                                                                //  #17
773 VM_fabs,                                                                //  #18
774 VM_vtos,                                                                //  #19
775 VM_etos,                                                                //  #20
776 VM_stof,                                                                //  #21
777 VM_spawn,                                                       //  #22
778 VM_remove,                                                      //  #23
779 VM_find,                                                                //  #24
780 VM_findfloat,                                           //  #25
781 VM_findchain,                                           //  #26
782 VM_findchainfloat,                              //  #27
783 VM_precache_file,                                       //  #28
784 VM_precache_sound,                              //  #29
785 VM_coredump,                                            //  #30
786 VM_traceon,                                                     //  #31
787 VM_traceoff,                                            //  #32
788 VM_eprint,                                                      //  #33
789 VM_rint,                                                                //  #34
790 VM_floor,                                                       //  #35
791 VM_ceil,                                                                //  #36
792 VM_nextent,                                                     //  #37
793 VM_sin,                                                         //  #38
794 VM_cos,                                                         //  #39
795 VM_sqrt,                                                                //  #40
796 VM_randomvec,                                           //  #41
797 VM_registercvar,                                        //  #42
798 VM_min,                                                         //  #43
799 VM_max,                                                         //  #44
800 VM_bound,                                                       //  #45
801 VM_pow,                                                         //  #46
802 VM_M_copyentity,                                        //  #47
803 VM_fopen,                                                       //  #48
804 VM_fclose,                                                      //  #49
805 VM_fgets,                                                       //  #50
806 VM_fputs,                                                       //  #51
807 VM_strlen,                                                      //  #52
808 VM_strcat,                                                      //  #53
809 VM_substring,                                           //  #54
810 VM_stov,                                                                //  #55
811 VM_strzone,                                                     //  #56
812 VM_strunzone,                                           //  #57
813 VM_tokenize,                                            //  #58
814 VM_argv,                                                                //  #59
815 VM_isserver,                                            //  #60
816 VM_clientcount,                                 //  #61
817 VM_clientstate,                                 //  #62
818 VM_clcommand,                                           //  #63
819 VM_changelevel,                                 //  #64
820 VM_localsound,                                          //  #65
821 VM_M_getmousepos,                                       //  #66
822 VM_gettime,                                                     //  #67
823 VM_loadfromdata,                                        //  #68
824 VM_loadfromfile,                                        //  #69
825 VM_modulo,                                                      //  #70
826 VM_cvar_string,                                 //  #71
827 VM_crash,                                                       //  #72
828 VM_stackdump,                                           //  #73
829 VM_search_begin,                                        //  #74
830 VM_search_end,                                          //  #75
831 VM_search_getsize,                              //  #76
832 VM_search_getfilename,                  //  #77
833 VM_chr,                                                         //  #78
834 VM_itof,                                                                //  #79
835 VM_ftoe,                                                                //  #80
836 VM_itof,                                                                //  #81 isString
837 VM_altstr_count,                                        //  #82
838 VM_altstr_prepare,                              //  #83
839 VM_altstr_get,                                          //  #84
840 VM_altstr_set,                                          //  #85
841 VM_altstr_ins,                                          //  #86
842 VM_findflags,                                           //  #87
843 VM_findchainflags,                              //  #88
844 VM_cvar_defstring,                              //  #89
845 // deactivate support for model rendering in the menu until someone has time to do it right [3/2/2008 Andreas]
846 #if 0
847 VM_CL_setmodel,                                 // #90 void(entity e, string m) setmodel (QUAKE)
848 VM_CL_precache_model,                   // #91 void(string s) precache_model (QUAKE)
849 VM_CL_setorigin,                                // #92 void(entity e, vector o) setorigin (QUAKE)
850 #else
851 NULL,
852 NULL,
853 NULL,
854 #endif
855 NULL,                                                                   //  #93
856 NULL,                                                                   //  #94
857 NULL,                                                                   //  #95
858 NULL,                                                                   //  #96
859 NULL,                                                                   //  #97
860 NULL,                                                                   //  #98
861 NULL,                                                                   //  #99
862 NULL,                                                                   // #100
863 NULL,                                                                   // #101
864 NULL,                                                                   // #102
865 NULL,                                                                   // #103
866 NULL,                                                                   // #104
867 NULL,                                                                   // #105
868 NULL,                                                                   // #106
869 NULL,                                                                   // #107
870 NULL,                                                                   // #108
871 NULL,                                                                   // #109
872 NULL,                                                                   // #110
873 NULL,                                                                   // #111
874 NULL,                                                                   // #112
875 NULL,                                                                   // #113
876 NULL,                                                                   // #114
877 NULL,                                                                   // #115
878 NULL,                                                                   // #116
879 NULL,                                                                   // #117
880 NULL,                                                                   // #118
881 NULL,                                                                   // #119
882 NULL,                                                                   // #120
883 NULL,                                                                   // #121
884 NULL,                                                                   // #122
885 NULL,                                                                   // #123
886 NULL,                                                                   // #124
887 NULL,                                                                   // #125
888 NULL,                                                                   // #126
889 NULL,                                                                   // #127
890 NULL,                                                                   // #128
891 NULL,                                                                   // #129
892 NULL,                                                                   // #130
893 NULL,                                                                   // #131
894 NULL,                                                                   // #132
895 NULL,                                                                   // #133
896 NULL,                                                                   // #134
897 NULL,                                                                   // #135
898 NULL,                                                                   // #136
899 NULL,                                                                   // #137
900 NULL,                                                                   // #138
901 NULL,                                                                   // #139
902 NULL,                                                                   // #140
903 NULL,                                                                   // #141
904 NULL,                                                                   // #142
905 NULL,                                                                   // #143
906 NULL,                                                                   // #144
907 NULL,                                                                   // #145
908 NULL,                                                                   // #146
909 NULL,                                                                   // #147
910 NULL,                                                                   // #148
911 NULL,                                                                   // #149
912 NULL,                                                                   // #150
913 NULL,                                                                   // #151
914 NULL,                                                                   // #152
915 NULL,                                                                   // #153
916 NULL,                                                                   // #154
917 NULL,                                                                   // #155
918 NULL,                                                                   // #156
919 NULL,                                                                   // #157
920 NULL,                                                                   // #158
921 NULL,                                                                   // #159
922 NULL,                                                                   // #160
923 NULL,                                                                   // #161
924 NULL,                                                                   // #162
925 NULL,                                                                   // #163
926 NULL,                                                                   // #164
927 NULL,                                                                   // #165
928 NULL,                                                                   // #166
929 NULL,                                                                   // #167
930 NULL,                                                                   // #168
931 NULL,                                                                   // #169
932 NULL,                                                                   // #170
933 NULL,                                                                   // #171
934 NULL,                                                                   // #172
935 NULL,                                                                   // #173
936 NULL,                                                                   // #174
937 NULL,                                                                   // #175
938 NULL,                                                                   // #176
939 NULL,                                                                   // #177
940 NULL,                                                                   // #178
941 NULL,                                                                   // #179
942 NULL,                                                                   // #180
943 NULL,                                                                   // #181
944 NULL,                                                                   // #182
945 NULL,                                                                   // #183
946 NULL,                                                                   // #184
947 NULL,                                                                   // #185
948 NULL,                                                                   // #186
949 NULL,                                                                   // #187
950 NULL,                                                                   // #188
951 NULL,                                                                   // #189
952 NULL,                                                                   // #190
953 NULL,                                                                   // #191
954 NULL,                                                                   // #192
955 NULL,                                                                   // #193
956 NULL,                                                                   // #194
957 NULL,                                                                   // #195
958 NULL,                                                                   // #196
959 NULL,                                                                   // #197
960 NULL,                                                                   // #198
961 NULL,                                                                   // #199
962 NULL,                                                                   // #200
963 NULL,                                                                   // #201
964 NULL,                                                                   // #202
965 NULL,                                                                   // #203
966 NULL,                                                                   // #204
967 NULL,                                                                   // #205
968 NULL,                                                                   // #206
969 NULL,                                                                   // #207
970 NULL,                                                                   // #208
971 NULL,                                                                   // #209
972 NULL,                                                                   // #210
973 NULL,                                                                   // #211
974 NULL,                                                                   // #212
975 NULL,                                                                   // #213
976 NULL,                                                                   // #214
977 NULL,                                                                   // #215
978 NULL,                                                                   // #216
979 NULL,                                                                   // #217
980 NULL,                                                                   // #218
981 NULL,                                                                   // #219
982 NULL,                                                                   // #220
983 VM_strstrofs,                                           // #221 float(string str, string sub[, float startpos]) strstrofs (FTE_STRINGS)
984 VM_str2chr,                                             // #222 float(string str, float ofs) str2chr (FTE_STRINGS)
985 VM_chr2str,                                             // #223 string(float c, ...) chr2str (FTE_STRINGS)
986 VM_strconv,                                             // #224 string(float ccase, float calpha, float cnum, string s, ...) strconv (FTE_STRINGS)
987 VM_strpad,                                              // #225 string(float chars, string s, ...) strpad (FTE_STRINGS)
988 VM_infoadd,                                             // #226 string(string info, string key, string value, ...) infoadd (FTE_STRINGS)
989 VM_infoget,                                             // #227 string(string info, string key) infoget (FTE_STRINGS)
990 VM_strncmp,                                                     // #228 float(string s1, string s2, float len) strncmp (FTE_STRINGS)
991 VM_strncasecmp,                                 // #229 float(string s1, string s2) strcasecmp (FTE_STRINGS)
992 VM_strncasecmp,                                 // #230 float(string s1, string s2, float len) strncasecmp (FTE_STRINGS)
993 NULL,                                                                   // #231
994 NULL,                                                                   // #232
995 NULL,                                                                   // #233
996 NULL,                                                                   // #234
997 NULL,                                                                   // #235
998 NULL,                                                                   // #236
999 NULL,                                                                   // #237
1000 NULL,                                                                   // #238
1001 NULL,                                                                   // #239
1002 NULL,                                                                   // #240
1003 NULL,                                                                   // #241
1004 NULL,                                                                   // #242
1005 NULL,                                                                   // #243
1006 NULL,                                                                   // #244
1007 NULL,                                                                   // #245
1008 NULL,                                                                   // #246
1009 NULL,                                                                   // #247
1010 NULL,                                                                   // #248
1011 NULL,                                                                   // #249
1012 NULL,                                                                   // #250
1013 NULL,                                                                   // #251
1014 NULL,                                                                   // #252
1015 NULL,                                                                   // #253
1016 NULL,                                                                   // #254
1017 NULL,                                                                   // #255
1018 NULL,                                                                   // #256
1019 NULL,                                                                   // #257
1020 NULL,                                                                   // #258
1021 NULL,                                                                   // #259
1022 NULL,                                                                   // #260
1023 NULL,                                                                   // #261
1024 NULL,                                                                   // #262
1025 NULL,                                                                   // #263
1026 NULL,                                                                   // #264
1027 NULL,                                                                   // #265
1028 NULL,                                                                   // #266
1029 NULL,                                                                   // #267
1030 NULL,                                                                   // #268
1031 NULL,                                                                   // #269
1032 NULL,                                                                   // #270
1033 NULL,                                                                   // #271
1034 NULL,                                                                   // #272
1035 NULL,                                                                   // #273
1036 NULL,                                                                   // #274
1037 NULL,                                                                   // #275
1038 NULL,                                                                   // #276
1039 NULL,                                                                   // #277
1040 NULL,                                                                   // #278
1041 NULL,                                                                   // #279
1042 NULL,                                                                   // #280
1043 NULL,                                                                   // #281
1044 NULL,                                                                   // #282
1045 NULL,                                                                   // #283
1046 NULL,                                                                   // #284
1047 NULL,                                                                   // #285
1048 NULL,                                                                   // #286
1049 NULL,                                                                   // #287
1050 NULL,                                                                   // #288
1051 NULL,                                                                   // #289
1052 NULL,                                                                   // #290
1053 NULL,                                                                   // #291
1054 NULL,                                                                   // #292
1055 NULL,                                                                   // #293
1056 NULL,                                                                   // #294
1057 NULL,                                                                   // #295
1058 NULL,                                                                   // #296
1059 NULL,                                                                   // #297
1060 NULL,                                                                   // #298
1061 NULL,                                                                   // #299
1062 // deactivate support for model rendering in the menu until someone has time to do it right [3/2/2008 Andreas]
1063 #if 0
1064 // CSQC range #300-#399
1065 VM_CL_R_ClearScene,                             // #300 void() clearscene (DP_QC_RENDER_SCENE)
1066 VM_CL_R_AddEntities,                    // #301 void(float mask) addentities (DP_QC_RENDER_SCENE)
1067 VM_CL_R_AddEntity,                              // #302 void(entity ent) addentity (DP_QC_RENDER_SCENE)
1068 VM_CL_R_SetView,                                // #303 float(float property, ...) setproperty (DP_QC_RENDER_SCENE)
1069 VM_CL_R_RenderScene,                    // #304 void() renderscene (DP_QC_RENDER_SCENE)
1070 VM_CL_R_AddDynamicLight,                // #305 void(vector org, float radius, vector lightcolours) adddynamiclight (DP_QC_RENDER_SCENE)
1071 VM_CL_R_PolygonBegin,                   // #306 void(string texturename, float flag[, float is2d, float lines]) R_BeginPolygon (DP_QC_RENDER_SCENE)
1072 VM_CL_R_PolygonVertex,                  // #307 void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex (DP_QC_RENDER_SCENE)
1073 VM_CL_R_PolygonEnd,                             // #308 void() R_EndPolygon
1074 NULL/*VM_CL_R_LoadWorldModel*/,                         // #309 void(string modelname) R_LoadWorldModel
1075 // TODO: rearrange and merge all builtin lists and share as many extensions as possible between all VM instances [1/27/2008 Andreas]
1076 VM_CL_setattachment,                            // #310 void(entity e, entity tagentity, string tagname) setattachment (DP_GFX_QUAKE3MODELTAGS) (DP_QC_RENDER_SCENE)
1077 VM_CL_gettagindex,                              // #311 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO) (DP_QC_RENDER_SCENE)
1078 VM_CL_gettaginfo,                                       // #312 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO) (DP_QC_RENDER_SCENE)
1079 #else
1080 // CSQC range #300-#399
1081 NULL,           
1082 NULL,           
1083 NULL,           
1084 NULL,           
1085 NULL,           
1086 NULL,           
1087 NULL,           
1088 NULL,   
1089 NULL,   
1090 NULL,
1091 NULL,   
1092 NULL,   
1093 NULL,   
1094 #endif
1095 NULL,                                                                   // #313
1096 NULL,                                                                   // #314
1097 NULL,                                                                   // #315
1098 NULL,                                                                   // #316
1099 NULL,                                                                   // #317
1100 NULL,                                                                   // #318
1101 NULL,                                                                   // #319
1102 NULL,                                                                   // #320
1103 NULL,                                                                   // #321
1104 NULL,                                                                   // #322
1105 NULL,                                                                   // #323
1106 NULL,                                                                   // #324
1107 NULL,                                                                   // #325
1108 NULL,                                                                   // #326
1109 NULL,                                                                   // #327
1110 NULL,                                                                   // #328
1111 NULL,                                                                   // #329
1112 NULL,                                                                   // #330
1113 NULL,                                                                   // #331
1114 NULL,                                                                   // #332
1115 NULL,                                                                   // #333
1116 NULL,                                                                   // #334
1117 NULL,                                                                   // #335
1118 NULL,                                                                   // #336
1119 NULL,                                                                   // #337
1120 NULL,                                                                   // #338
1121 NULL,                                                                   // #339
1122 NULL,                                                                   // #340
1123 NULL,                                                                   // #341
1124 NULL,                                                                   // #342
1125 NULL,                                                                   // #343
1126 NULL,                                                                   // #344
1127 NULL,                                                                   // #345
1128 NULL,                                                                   // #346
1129 NULL,                                                                   // #347
1130 NULL,                                                                   // #348
1131 VM_M_isdemo,                                                            // #349
1132 NULL,                                                                   // #350
1133 NULL,                                                                   // #351
1134 NULL,                                                                   // #352
1135 NULL,                                                                   // #353
1136 NULL,                                                                   // #354
1137 NULL,                                                                   // #355
1138 NULL,                                                                   // #356
1139 NULL,                                                                   // #357
1140 NULL,                                                                   // #358
1141 NULL,                                                                   // #359
1142 NULL,                                                                   // #360
1143 NULL,                                                                   // #361
1144 NULL,                                                                   // #362
1145 NULL,                                                                   // #363
1146 NULL,                                                                   // #364
1147 NULL,                                                                   // #365
1148 NULL,                                                                   // #366
1149 NULL,                                                                   // #367
1150 NULL,                                                                   // #368
1151 NULL,                                                                   // #369
1152 NULL,                                                                   // #370
1153 NULL,                                                                   // #371
1154 NULL,                                                                   // #372
1155 NULL,                                                                   // #373
1156 NULL,                                                                   // #374
1157 NULL,                                                                   // #375
1158 NULL,                                                                   // #376
1159 NULL,                                                                   // #377
1160 NULL,                                                                   // #378
1161 NULL,                                                                   // #379
1162 NULL,                                                                   // #380
1163 NULL,                                                                   // #381
1164 NULL,                                                                   // #382
1165 NULL,                                                                   // #383
1166 NULL,                                                                   // #384
1167 NULL,                                                                   // #385
1168 NULL,                                                                   // #386
1169 NULL,                                                                   // #387
1170 NULL,                                                                   // #388
1171 NULL,                                                                   // #389
1172 NULL,                                                                   // #390
1173 NULL,                                                                   // #391
1174 NULL,                                                                   // #392
1175 NULL,                                                                   // #393
1176 NULL,                                                                   // #394
1177 NULL,                                                                   // #395
1178 NULL,                                                                   // #396
1179 NULL,                                                                   // #397
1180 NULL,                                                                   // #398
1181 NULL,                                                                   // #399
1182 NULL,                                                                   // #400
1183 VM_M_WriteByte,                                 // #401
1184 VM_M_WriteChar,                                 // #402
1185 VM_M_WriteShort,                                        // #403
1186 VM_M_WriteLong,                                 // #404
1187 VM_M_WriteAngle,                                        // #405
1188 VM_M_WriteCoord,                                        // #406
1189 VM_M_WriteString,                                       // #407
1190 VM_M_WriteEntity,                                       // #408
1191 NULL,                                                                   // #409
1192 NULL,                                                                   // #410
1193 NULL,                                                                   // #411
1194 NULL,                                                                   // #412
1195 NULL,                                                                   // #413
1196 NULL,                                                                   // #414
1197 NULL,                                                                   // #415
1198 NULL,                                                                   // #416
1199 NULL,                                                                   // #417
1200 NULL,                                                                   // #418
1201 NULL,                                                                   // #419
1202 NULL,                                                                   // #420
1203 NULL,                                                                   // #421
1204 NULL,                                                                   // #422
1205 NULL,                                                                   // #423
1206 NULL,                                                                   // #424
1207 NULL,                                                                   // #425
1208 NULL,                                                                   // #426
1209 NULL,                                                                   // #427
1210 NULL,                                                                   // #428
1211 NULL,                                                                   // #429
1212 NULL,                                                                   // #430
1213 NULL,                                                                   // #431
1214 NULL,                                                                   // #432
1215 NULL,                                                                   // #433
1216 NULL,                                                                   // #434
1217 NULL,                                                                   // #435
1218 NULL,                                                                   // #436
1219 NULL,                                                                   // #437
1220 NULL,                                                                   // #438
1221 NULL,                                                                   // #439
1222 VM_buf_create,                                  // #440 float() buf_create (DP_QC_STRINGBUFFERS)
1223 VM_buf_del,                                             // #441 void(float bufhandle) buf_del (DP_QC_STRINGBUFFERS)
1224 VM_buf_getsize,                                 // #442 float(float bufhandle) buf_getsize (DP_QC_STRINGBUFFERS)
1225 VM_buf_copy,                                    // #443 void(float bufhandle_from, float bufhandle_to) buf_copy (DP_QC_STRINGBUFFERS)
1226 VM_buf_sort,                                    // #444 void(float bufhandle, float sortpower, float backward) buf_sort (DP_QC_STRINGBUFFERS)
1227 VM_buf_implode,                                 // #445 string(float bufhandle, string glue) buf_implode (DP_QC_STRINGBUFFERS)
1228 VM_bufstr_get,                                  // #446 string(float bufhandle, float string_index) bufstr_get (DP_QC_STRINGBUFFERS)
1229 VM_bufstr_set,                                  // #447 void(float bufhandle, float string_index, string str) bufstr_set (DP_QC_STRINGBUFFERS)
1230 VM_bufstr_add,                                  // #448 float(float bufhandle, string str, float order) bufstr_add (DP_QC_STRINGBUFFERS)
1231 VM_bufstr_free,                                 // #449 void(float bufhandle, float string_index) bufstr_free (DP_QC_STRINGBUFFERS)
1232 NULL,                                                                   // #450
1233 VM_iscachedpic,                                 // #451 draw functions...
1234 VM_precache_pic,                                        // #452
1235 VM_freepic,                                                     // #453
1236 VM_drawcharacter,                                       // #454
1237 VM_drawstring,                                          // #455
1238 VM_drawpic,                                                     // #456
1239 VM_drawfill,                                            // #457
1240 VM_drawsetcliparea,                             // #458
1241 VM_drawresetcliparea,                   // #459
1242 VM_getimagesize,                                        // #460
1243 VM_cin_open,                                            // #461
1244 VM_cin_close,                                           // #462
1245 VM_cin_setstate,                                        // #463
1246 VM_cin_getstate,                                        // #464
1247 VM_cin_restart,                                         // #465
1248 VM_drawline,                                            // #466
1249 VM_drawcolorcodedstring,                // #467
1250 VM_stringwidth,                                 // #468
1251 VM_drawsubpic,                                          // #469
1252 VM_drawrotpic,                                          // #470
1253 VM_asin,                                                                // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
1254 VM_acos,                                                                // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
1255 VM_atan,                                                                // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
1256 VM_atan2,                                                       // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
1257 VM_tan,                                                         // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
1258 VM_strlennocol,                                 // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
1259 VM_strdecolorize,                                       // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
1260 VM_strftime,                                            // #478 string(float uselocaltime, string format, ...) (DP_QC_STRFTIME)
1261 VM_tokenizebyseparator,                 // #479 float(string s) tokenizebyseparator (DP_QC_TOKENIZEBYSEPARATOR)
1262 VM_strtolower,                                          // #480 string(string s) VM_strtolower : DRESK - Return string as lowercase
1263 VM_strtoupper,                                          // #481 string(string s) VM_strtoupper : DRESK - Return string as uppercase
1264 NULL,                                                                   // #482
1265 NULL,                                                                   // #483
1266 VM_strreplace,                                          // #484 string(string search, string replace, string subject) strreplace (DP_QC_STRREPLACE)
1267 VM_strireplace,                                 // #485 string(string search, string replace, string subject) strireplace (DP_QC_STRREPLACE)
1268 NULL,                                                                   // #486
1269 VM_gecko_create,                                        // #487 float gecko_create( string name )
1270 VM_gecko_destroy,                                       // #488 void gecko_destroy( string name )
1271 VM_gecko_navigate,                              // #489 void gecko_navigate( string name, string URI )
1272 VM_gecko_keyevent,                              // #490 float gecko_keyevent( string name, float key, float eventtype )
1273 VM_gecko_movemouse,                             // #491 void gecko_mousemove( string name, float x, float y )
1274 VM_gecko_resize,                                        // #492 void gecko_resize( string name, float w, float h )
1275 VM_gecko_get_texture_extent,    // #493 vector gecko_get_texture_extent( string name )
1276 VM_crc16,                                               // #494 float(float caseinsensitive, string s, ...) crc16 = #494 (DP_QC_CRC16)
1277 VM_cvar_type,                                   // #495 float(string name) cvar_type = #495; (DP_QC_CVAR_TYPE)
1278 NULL,                                                                   // #496
1279 NULL,                                                                   // #497
1280 NULL,                                                                   // #498
1281 NULL,                                                                   // #499
1282 NULL,                                                                   // #500
1283 NULL,                                                                   // #501
1284 NULL,                                                                   // #502
1285 VM_whichpack,                                   // #503 string(string) whichpack = #503;
1286 NULL,                                                                   // #504
1287 NULL,                                                                   // #505
1288 NULL,                                                                   // #506
1289 NULL,                                                                   // #507
1290 NULL,                                                                   // #508
1291 NULL,                                                                   // #509
1292 VM_uri_escape,                                  // #510 string(string in) uri_escape = #510;
1293 VM_uri_unescape,                                // #511 string(string in) uri_unescape = #511;
1294 VM_etof,                                        // #512 float(entity ent) num_for_edict = #512 (DP_QC_NUM_FOR_EDICT)
1295 VM_uri_get,                                             // #513 float(string uril, float id) uri_get = #513; (DP_QC_URI_GET)
1296 VM_tokenize_console,                                    // #514 float(string str) tokenize_console = #514; (DP_QC_TOKENIZE_CONSOLE)
1297 VM_argv_start_index,                                    // #515 float(float idx) argv_start_index = #515; (DP_QC_TOKENIZE_CONSOLE)
1298 VM_argv_end_index,                                              // #516 float(float idx) argv_end_index = #516; (DP_QC_TOKENIZE_CONSOLE)
1299 VM_buf_cvarlist,                                                // #517 void(float buf, string prefix, string antiprefix) buf_cvarlist = #517; (DP_QC_STRINGBUFFERS_CVARLIST)
1300 VM_cvar_description,                                    // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION)
1301 NULL,                                                                   // #519
1302 NULL,                                                                   // #520
1303 NULL,                                                                   // #521
1304 NULL,                                                                   // #522
1305 NULL,                                                                   // #523
1306 NULL,                                                                   // #524
1307 NULL,                                                                   // #525
1308 NULL,                                                                   // #526
1309 NULL,                                                                   // #527
1310 NULL,                                                                   // #528
1311 NULL,                                                                   // #529
1312 NULL,                                                                   // #530
1313 NULL,                                                                   // #531
1314 VM_log,                                                                 // #532
1315 NULL,                                                                   // #533
1316 NULL,                                                                   // #534
1317 NULL,                                                                   // #535
1318 NULL,                                                                   // #536
1319 NULL,                                                                   // #537
1320 NULL,                                                                   // #538
1321 NULL,                                                                   // #539
1322 NULL,                                                                   // #540
1323 NULL,                                                                   // #541
1324 NULL,                                                                   // #542
1325 NULL,                                                                   // #543
1326 NULL,                                                                   // #544
1327 NULL,                                                                   // #545
1328 NULL,                                                                   // #546
1329 NULL,                                                                   // #547
1330 NULL,                                                                   // #548
1331 NULL,                                                                   // #549
1332 NULL,                                                                   // #550
1333 NULL,                                                                   // #551
1334 NULL,                                                                   // #552
1335 NULL,                                                                   // #553
1336 NULL,                                                                   // #554
1337 NULL,                                                                   // #555
1338 NULL,                                                                   // #556
1339 NULL,                                                                   // #557
1340 NULL,                                                                   // #558
1341 NULL,                                                                   // #559
1342 NULL,                                                                   // #560
1343 NULL,                                                                   // #561
1344 NULL,                                                                   // #562
1345 NULL,                                                                   // #563
1346 NULL,                                                                   // #564
1347 NULL,                                                                   // #565
1348 NULL,                                                                   // #566
1349 NULL,                                                                   // #567
1350 NULL,                                                                   // #568
1351 NULL,                                                                   // #569
1352 NULL,                                                                   // #570
1353 NULL,                                                                   // #571
1354 NULL,                                                                   // #572
1355 NULL,                                                                   // #573
1356 NULL,                                                                   // #574
1357 NULL,                                                                   // #575
1358 NULL,                                                                   // #576
1359 NULL,                                                                   // #577
1360 NULL,                                                                   // #578
1361 NULL,                                                                   // #579
1362 NULL,                                                                   // #580
1363 NULL,                                                                   // #581
1364 NULL,                                                                   // #582
1365 NULL,                                                                   // #583
1366 NULL,                                                                   // #584
1367 NULL,                                                                   // #585
1368 NULL,                                                                   // #586
1369 NULL,                                                                   // #587
1370 NULL,                                                                   // #588
1371 NULL,                                                                   // #589
1372 NULL,                                                                   // #590
1373 NULL,                                                                   // #591
1374 NULL,                                                                   // #592
1375 NULL,                                                                   // #593
1376 NULL,                                                                   // #594
1377 NULL,                                                                   // #595
1378 NULL,                                                                   // #596
1379 NULL,                                                                   // #597
1380 NULL,                                                                   // #598
1381 NULL,                                                                   // #599
1382 NULL,                                                                   // #600
1383 VM_M_setkeydest,                                        // #601 void setkeydest(float dest)
1384 VM_M_getkeydest,                                        // #602 float getkeydest(void)
1385 VM_M_setmousetarget,                            // #603 void setmousetarget(float trg)
1386 VM_M_getmousetarget,                            // #604 float getmousetarget(void)
1387 VM_callfunction,                                // #605 void callfunction(...)
1388 VM_writetofile,                                 // #606 void writetofile(float fhandle, entity ent)
1389 VM_isfunction,                                  // #607 float isfunction(string function_name)
1390 VM_M_getresolution,                             // #608 vector getresolution(float number, [float forfullscreen])
1391 VM_keynumtostring,                              // #609 string keynumtostring(float keynum)
1392 VM_findkeysforcommand,          // #610 string findkeysforcommand(string command)
1393 VM_M_getserverliststat,                 // #611 float gethostcachevalue(float type)
1394 VM_M_getserverliststring,               // #612 string gethostcachestring(float type, float hostnr)
1395 VM_parseentitydata,                             // #613 void parseentitydata(entity ent, string data)
1396 VM_stringtokeynum,                              // #614 float stringtokeynum(string key)
1397 VM_M_resetserverlistmasks,              // #615 void resethostcachemasks(void)
1398 VM_M_setserverlistmaskstring,   // #616 void sethostcachemaskstring(float mask, float fld, string str, float op)
1399 VM_M_setserverlistmasknumber,   // #617 void sethostcachemasknumber(float mask, float fld, float num, float op)
1400 VM_M_resortserverlist,                  // #618 void resorthostcache(void)
1401 VM_M_setserverlistsort,                 // #619 void sethostcachesort(float fld, float descending)
1402 VM_M_refreshserverlist,                 // #620 void refreshhostcache(void)
1403 VM_M_getserverlistnumber,               // #621 float gethostcachenumber(float fld, float hostnr)
1404 VM_M_getserverlistindexforkey,// #622 float gethostcacheindexforkey(string key)
1405 VM_M_addwantedserverlistkey,    // #623 void addwantedhostcachekey(string key)
1406 VM_CL_getextresponse,                   // #624 string getextresponse(void)
1407 VM_netaddress_resolve,          // #625 string netaddress_resolve(string, float)
1408 VM_M_getgamedirinfo,            // #626 string getgamedirinfo(float n, float prop)
1409 NULL
1410 };
1411
1412 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
1413
1414 void VM_M_Cmd_Init(void)
1415 {
1416         r_refdef_scene_t *scene;
1417
1418         VM_Cmd_Init();
1419         VM_Polygons_Reset();
1420
1421         scene = R_GetScenePointer( RST_MENU );
1422
1423         memset (scene, 0, sizeof (*scene));
1424
1425         scene->maxtempentities = 128;
1426         scene->tempentities = (entity_render_t*) Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t) * scene->maxtempentities);
1427
1428         scene->maxentities = MAX_EDICTS + 256 + 512;
1429         scene->entities = (entity_render_t **)Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t *) * scene->maxentities);
1430
1431         scene->ambient = 32.0f;
1432 }
1433
1434 void VM_M_Cmd_Reset(void)
1435 {
1436         // note: the menu's render entities are automatically freed when the prog's pool is freed
1437
1438         //VM_Cmd_Init();
1439         VM_Cmd_Reset();
1440         VM_Polygons_Reset();
1441 }