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