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