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