added DP_GFX_EXTERNALTEXTURES_PERMAP extension
[xonotic/darkplaces.git] / clvm_cmds.c
1 #include "prvm_cmds.h"
2 #include "csprogs.h"
3 #include "cl_collision.h"
4
5 //============================================================================
6 // Client
7 //[515]: unsolved PROBLEMS
8 //- finish player physics code (cs_runplayerphysics)
9 //- fix R_AddDynamicLight
10 //- EntWasFreed ?
11 //- RF_DEPTHHACK is not like it should be
12 //- add builtin that sets cl.viewangles instead of reading "input_angles" global
13 //- finish lines support for R_Polygon***
14 //- insert selecttraceline into traceline somehow
15
16 //4 feature darkplaces csqc: add builtin to clientside qc for reading triangles of model meshes (useful to orient a ui along a triangle of a model mesh)
17 //4 feature darkplaces csqc: add builtins to clientside qc for gl calls
18
19 #ifndef PF_WARNING
20 #define PF_WARNING(s) do{Con_Printf(s);PRVM_PrintState();return;}while(0)
21 #endif
22
23 //[515]: really need new list ?
24 char *vm_cl_extensions =
25 "DP_CON_SET "
26 "DP_CON_SETA "
27 "DP_CON_STARTMAP "
28 "DP_EF_ADDITIVE "
29 "DP_EF_BLUE "
30 "DP_EF_FLAME "
31 "DP_EF_FULLBRIGHT "
32 "DP_EF_NODEPTHTEST "
33 "DP_EF_NODRAW "
34 "DP_EF_NOSHADOW "
35 "DP_EF_RED "
36 "DP_EF_STARDUST "
37 "DP_ENT_ALPHA "
38 "DP_ENT_CUSTOMCOLORMAP "
39 "DP_ENT_GLOW "
40 "DP_ENT_SCALE "
41 "DP_GFX_EXTERNALTEXTURES "
42 "DP_GFX_EXTERNALTEXTURES_PERMAP "
43 "DP_GFX_FOG "
44 "DP_GFX_QUAKE3MODELTAGS "
45 "DP_GFX_SKINFILES "
46 "DP_GFX_SKYBOX "
47 "DP_HALFLIFE_MAP "
48 "DP_HALFLIFE_MAP_CVAR "
49 "DP_HALFLIFE_SPRITE "
50 "DP_INPUTBUTTONS "
51 "DP_LITSPRITES "
52 "DP_LITSUPPORT "
53 "DP_MONSTERWALK "
54 "DP_MOVETYPEBOUNCEMISSILE "
55 "DP_MOVETYPEFOLLOW "
56 "DP_QC_CHANGEPITCH "
57 "DP_QC_COPYENTITY "
58 "DP_QC_CVAR_STRING "
59 "DP_QC_ETOS "
60 "DP_QC_FINDCHAIN "
61 "DP_QC_FINDCHAINFLAGS "
62 "DP_QC_FINDCHAINFLOAT "
63 "DP_QC_FINDFLAGS "
64 "DP_QC_FINDFLOAT "
65 "DP_QC_FS_SEARCH " // Black: same as in the menu qc
66 "DP_QC_GETLIGHT "
67 "DP_QC_GETSURFACE "
68 "DP_QC_GETTAGINFO "
69 "DP_QC_MINMAXBOUND "
70 "DP_QC_MULTIPLETEMPSTRINGS "
71 "DP_QC_RANDOMVEC "
72 "DP_QC_SINCOSSQRTPOW "
73 //"DP_QC_STRINGBUFFERS "        //[515]: not needed ?
74 "DP_QC_TRACEBOX "
75 //"DP_QC_TRACETOSS "
76 "DP_QC_TRACE_MOVETYPE_HITMODEL "
77 "DP_QC_TRACE_MOVETYPE_WORLDONLY "
78 "DP_QC_VECTORVECTORS "
79 "DP_QUAKE2_MODEL "
80 "DP_QUAKE2_SPRITE "
81 "DP_QUAKE3_MAP "
82 "DP_QUAKE3_MODEL "
83 "DP_REGISTERCVAR "
84 "DP_SND_DIRECTIONLESSATTNNONE "
85 "DP_SND_FAKETRACKS "
86 "DP_SND_OGGVORBIS "
87 "DP_SND_STEREOWAV "
88 "DP_SOLIDCORPSE "
89 "DP_SPRITE32 "
90 "DP_SV_EFFECT "
91 "DP_SV_ROTATINGBMODEL "
92 "DP_SV_SLOWMO "
93 "DP_TE_BLOOD "
94 "DP_TE_BLOODSHOWER "
95 "DP_TE_CUSTOMFLASH "
96 "DP_TE_EXPLOSIONRGB "
97 "DP_TE_FLAMEJET "
98 "DP_TE_PARTICLECUBE "
99 "DP_TE_PARTICLERAIN "
100 "DP_TE_PARTICLESNOW "
101 "DP_TE_PLASMABURN "
102 "DP_TE_QUADEFFECTS1 "
103 "DP_TE_SMALLFLASH "
104 "DP_TE_SPARK "
105 "DP_TE_STANDARDEFFECTBUILTINS "
106 "EXT_BITSHIFT "
107 "EXT_CSQC "
108 "FRIK_FILE "
109 "KRIMZON_SV_PARSECLIENTCOMMAND "
110 "NEH_CMD_PLAY2 "
111 "NXQ_GFX_LETTERBOX "
112 "PRYDON_CLIENTCURSOR "
113 "TENEBRAE_GFX_DLIGHTS "
114 "TW_SV_STEPCONTROL "
115 "NEXUIZ_PLAYERMODEL "
116 "NEXUIZ_PLAYERSKIN "
117 ;
118
119 sfx_t *S_FindName(const char *name);
120 void PF_registercvar (void);
121 int Sbar_GetPlayer (int index);
122 void Sbar_SortFrags (void);
123 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius);
124 void CL_ExpandCSQCEntities(int num);
125 void CSQC_RelinkAllEntities (int drawmask);
126 void CSQC_RelinkCSQCEntities (void);
127 char *Key_GetBind (int key);
128
129
130
131
132
133 // #1 void(vector ang) makevectors
134 void VM_CL_makevectors (void)
135 {
136         VM_SAFEPARMCOUNT(1, VM_CL_makevectors);
137         AngleVectors (PRVM_G_VECTOR(OFS_PARM0), prog->globals.client->v_forward, prog->globals.client->v_right, prog->globals.client->v_up);
138 }
139
140 // #2 void(entity e, vector o) setorigin
141 void VM_CL_setorigin (void)
142 {
143         prvm_edict_t    *e;
144         float   *org;
145
146         e = PRVM_G_EDICT(OFS_PARM0);
147         if (e == prog->edicts)
148                 PF_WARNING("setorigin: can not modify world entity\n");
149         if (e->priv.required->free)
150                 PF_WARNING("setorigin: can not modify free entity\n");
151         org = PRVM_G_VECTOR(OFS_PARM1);
152         VectorCopy (org, e->fields.client->origin);
153 }
154
155 // #3 void(entity e, string m) setmodel
156 void VM_CL_setmodel (void)
157 {
158         prvm_edict_t    *e;
159         const char              *m;
160         struct model_s  *mod;
161         int                             i;
162
163         VM_SAFEPARMCOUNT(2, VM_CL_setmodel);
164
165         e = PRVM_G_EDICT(OFS_PARM0);
166         m = PRVM_G_STRING(OFS_PARM1);
167         for(i=0;i<MAX_MODELS;i++)
168                 if(!cl.csqc_model_precache[i])
169                         break;
170                 else
171                 if(!strcmp(cl.csqc_model_precache[i]->name, m))
172                 {
173                         e->fields.client->model = PRVM_SetEngineString(cl.csqc_model_precache[i]->name);
174                         e->fields.client->modelindex = -(i+1);
175                         return;
176                 }
177
178         for (i=0, mod = cl.model_precache[0] ; i < MAX_MODELS ; i++, mod = cl.model_precache[i])
179                 if(mod)
180                 if(!strcmp(mod->name, m))
181                 {
182                         e->fields.client->model = PRVM_SetEngineString(mod->name);
183                         e->fields.client->modelindex = i;
184                         return;
185                 }
186         e->fields.client->modelindex = 0;
187         e->fields.client->model = 0;
188 }
189
190 // #4 void(entity e, vector min, vector max) setsize
191 void VM_CL_setsize (void)
192 {
193         prvm_edict_t    *e;
194         float                   *min, *max;
195         VM_SAFEPARMCOUNT(3, VM_CL_setsize);
196
197         e = PRVM_G_EDICT(OFS_PARM0);
198         if (e == prog->edicts)
199                 PF_WARNING("setsize: can not modify world entity\n");
200         if (e->priv.server->free)
201                 PF_WARNING("setsize: can not modify free entity\n");
202         min = PRVM_G_VECTOR(OFS_PARM1);
203         max = PRVM_G_VECTOR(OFS_PARM2);
204
205         VectorCopy (min, e->fields.client->mins);
206         VectorCopy (max, e->fields.client->maxs);
207         VectorSubtract (max, min, e->fields.client->size);
208 }
209
210 // #8 void(entity e, float chan, string samp) sound
211 void VM_CL_sound (void)
212 {
213         const char                      *sample;
214         int                                     channel;
215         prvm_edict_t            *entity;
216         int                             volume;
217         float                           attenuation;
218
219         VM_SAFEPARMCOUNT(5, VM_CL_sound);
220
221         entity = PRVM_G_EDICT(OFS_PARM0);
222         channel = (int)PRVM_G_FLOAT(OFS_PARM1);
223         sample = PRVM_G_STRING(OFS_PARM2);
224         volume = (int)(PRVM_G_FLOAT(OFS_PARM3)*255.0f);
225         attenuation = PRVM_G_FLOAT(OFS_PARM4);
226
227         if (volume < 0 || volume > 255)
228                 PF_WARNING("VM_CL_sound: volume must be in range 0-1\n");
229
230         if (attenuation < 0 || attenuation > 4)
231                 PF_WARNING("VM_CL_sound: attenuation must be in range 0-4\n");
232
233         if (channel < 0 || channel > 7)
234                 PF_WARNING("VM_CL_sound: channel must be in range 0-7\n");
235
236         S_StartSound(32768 + PRVM_NUM_FOR_EDICT(entity), channel, S_FindName(sample), entity->fields.client->origin, volume, attenuation);
237 }
238
239 // #14 entity() spawn
240 void VM_CL_spawn (void)
241 {
242         prvm_edict_t *ed;
243         ed = PRVM_ED_Alloc();
244         ed->fields.client->entnum = PRVM_NUM_FOR_EDICT(ed);     //[515]: not needed any more ?
245         VM_RETURN_EDICT(ed);
246 }
247
248 // #16 float(vector v1, vector v2, float tryents) traceline
249 void VM_CL_traceline (void)
250 {
251         float   *v1, *v2;
252         trace_t trace;
253         int             ent;
254
255         v1 = PRVM_G_VECTOR(OFS_PARM0);
256         v2 = PRVM_G_VECTOR(OFS_PARM1);
257
258         trace = CL_TraceBox(v1, vec3_origin, vec3_origin, v2, 1, &ent, 1, false);
259
260         prog->globals.client->trace_allsolid = trace.allsolid;
261         prog->globals.client->trace_startsolid = trace.startsolid;
262         prog->globals.client->trace_fraction = trace.fraction;
263         prog->globals.client->trace_inwater = trace.inwater;
264         prog->globals.client->trace_inopen = trace.inopen;
265         VectorCopy (trace.endpos, prog->globals.client->trace_endpos);
266         VectorCopy (trace.plane.normal, prog->globals.client->trace_plane_normal);
267         prog->globals.client->trace_plane_dist =  trace.plane.dist;
268         if (ent)
269                 prog->globals.client->trace_ent = ent;
270         else
271                 prog->globals.client->trace_ent = PRVM_EDICT_TO_PROG(prog->edicts);
272 }
273
274 // #19 void(string s) precache_sound
275 void VM_CL_precache_sound (void)
276 {
277         const char *n;
278         VM_SAFEPARMCOUNT(1, VM_CL_precache_sound);
279         n = PRVM_G_STRING(OFS_PARM0);
280         S_PrecacheSound(n, true, false);
281 }
282
283 // #20 void(string s) precache_model
284 void VM_CL_precache_model (void)
285 {
286         const char      *name;
287         int                     i;
288         model_t         *m;
289
290         VM_SAFEPARMCOUNT(1, VM_CL_precache_model);
291
292         name = PRVM_G_STRING(OFS_PARM0);
293         for(i=1;i<MAX_MODELS;i++)
294                 if(!cl.csqc_model_precache[i])
295                 {
296                         i = 0;
297                         break;
298                 }
299                 else
300                 if(!strcmp(cl.csqc_model_precache[i]->name, name))
301                 {
302                         i = -(i+1);
303                         break;
304                 }
305         if(i)
306         {
307                 PRVM_G_FLOAT(OFS_RETURN) = i;
308                 return;
309         }
310         PRVM_G_FLOAT(OFS_RETURN) = 0;
311         m = Mod_ForName(name, false, false, false);
312         if(m && m->loaded)
313         {
314                 for(i=1;i<MAX_MODELS;i++)
315                         if(!cl.csqc_model_precache[i])
316                                 break;
317                 if(i == MAX_MODELS)
318                         PF_WARNING("VM_CL_precache_model: no free models\n");
319                 cl.csqc_model_precache[i] = (model_t*)m;
320                 PRVM_G_FLOAT(OFS_RETURN) = -(i+1);
321                 return;
322         }
323         Con_Printf("VM_CL_precache_model: model \"%s\" not found\n", name);
324 }
325
326 int CSQC_EntitiesInBox (vec3_t mins, vec3_t maxs, int maxlist, prvm_edict_t **list)
327 {
328         prvm_edict_t    *ent;
329         int                             i, k;
330
331         ent = PRVM_NEXT_EDICT(prog->edicts);
332         for(k=0,i=1; i<prog->num_edicts ;i++, ent = PRVM_NEXT_EDICT(ent))
333         {
334                 if (ent->priv.required->free)
335                         continue;
336 //              VectorAdd(ent->fields.client->origin, ent->fields.client->mins, ent->fields.client->absmin);
337 //              VectorAdd(ent->fields.client->origin, ent->fields.client->maxs, ent->fields.client->absmax);
338                 if(BoxesOverlap(mins, maxs, ent->fields.client->absmin, ent->fields.client->absmax))
339                         list[k++] = ent;
340         }
341         return k;
342 }
343
344 // #22 entity(vector org, float rad) findradius
345 void VM_CL_findradius (void)
346 {
347         prvm_edict_t    *ent, *chain;
348         vec_t                   radius, radius2;
349         vec3_t                  org, eorg, mins, maxs;
350         int                             i, numtouchedicts;
351         prvm_edict_t    *touchedicts[MAX_EDICTS];
352
353         chain = (prvm_edict_t *)prog->edicts;
354
355         VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org);
356         radius = PRVM_G_FLOAT(OFS_PARM1);
357         radius2 = radius * radius;
358
359         mins[0] = org[0] - (radius + 1);
360         mins[1] = org[1] - (radius + 1);
361         mins[2] = org[2] - (radius + 1);
362         maxs[0] = org[0] + (radius + 1);
363         maxs[1] = org[1] + (radius + 1);
364         maxs[2] = org[2] + (radius + 1);
365         numtouchedicts = CSQC_EntitiesInBox(mins, maxs, MAX_EDICTS, touchedicts);
366         if (numtouchedicts > MAX_EDICTS)
367         {
368                 // this never happens   //[515]: for what then ?
369                 Con_Printf("CSQC_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
370                 numtouchedicts = MAX_EDICTS;
371         }
372         for (i = 0;i < numtouchedicts;i++)
373         {
374                 ent = touchedicts[i];
375                 // Quake did not return non-solid entities but darkplaces does
376                 // (note: this is the reason you can't blow up fallen zombies)
377                 if (ent->fields.client->solid == SOLID_NOT && !sv_gameplayfix_blowupfallenzombies.integer)
378                         continue;
379                 // LordHavoc: compare against bounding box rather than center so it
380                 // doesn't miss large objects, and use DotProduct instead of Length
381                 // for a major speedup
382                 VectorSubtract(org, ent->fields.client->origin, eorg);
383                 if (sv_gameplayfix_findradiusdistancetobox.integer)
384                 {
385                         eorg[0] -= bound(ent->fields.client->mins[0], eorg[0], ent->fields.client->maxs[0]);
386                         eorg[1] -= bound(ent->fields.client->mins[1], eorg[1], ent->fields.client->maxs[1]);
387                         eorg[2] -= bound(ent->fields.client->mins[2], eorg[2], ent->fields.client->maxs[2]);
388                 }
389                 else
390                         VectorMAMAM(1, eorg, 0.5f, ent->fields.client->mins, 0.5f, ent->fields.client->maxs, eorg);
391                 if (DotProduct(eorg, eorg) < radius2)
392                 {
393                         ent->fields.client->chain = PRVM_EDICT_TO_PROG(chain);
394                         chain = ent;
395                 }
396         }
397
398         VM_RETURN_EDICT(chain);
399 }
400
401 // #34 float() droptofloor
402 void VM_CL_droptofloor (void)
403 {
404         prvm_edict_t            *ent;
405         vec3_t                          end;
406         trace_t                         trace;
407         int                                     i;
408
409         // assume failure if it returns early
410         PRVM_G_FLOAT(OFS_RETURN) = 0;
411
412         ent = PRVM_PROG_TO_EDICT(prog->globals.client->self);
413         if (ent == prog->edicts)
414                 PF_WARNING("droptofloor: can not modify world entity\n");
415         if (ent->priv.server->free)
416                 PF_WARNING("droptofloor: can not modify free entity\n");
417
418         VectorCopy (ent->fields.client->origin, end);
419         end[2] -= 256;
420
421         trace = CL_TraceBox(ent->fields.client->origin, ent->fields.client->mins, ent->fields.client->maxs, end, 1, &i, 1, false);
422
423         if (trace.fraction != 1)
424         {
425                 VectorCopy (trace.endpos, ent->fields.client->origin);
426                 ent->fields.client->flags = (int)ent->fields.client->flags | FL_ONGROUND;
427 //              ent->fields.client->groundentity = PRVM_EDICT_TO_PROG(trace.ent);
428                 PRVM_G_FLOAT(OFS_RETURN) = 1;
429                 // if support is destroyed, keep suspended (gross hack for floating items in various maps)
430 //              ent->priv.server->suspendedinairflag = true;
431         }
432 }
433
434 // #35 void(float style, string value) lightstyle
435 void VM_CL_lightstyle (void)
436 {
437         int                     i;
438         const char      *c;
439
440         VM_SAFEPARMCOUNT(2, VM_CL_lightstyle);
441
442         i = (int)PRVM_G_FLOAT(OFS_PARM0);
443         c = PRVM_G_STRING(OFS_PARM1);
444         if (i >= cl.max_lightstyle)
445                 PF_WARNING("VM_CL_lightstyle >= MAX_LIGHTSTYLES\n");
446         strlcpy (cl.lightstyle[i].map,  MSG_ReadString(), sizeof (cl.lightstyle[i].map));
447         cl.lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
448         cl.lightstyle[i].length = (int)strlen(cl.lightstyle[i].map);
449 }
450
451 // #40 float(entity e) checkbottom
452 void VM_CL_checkbottom (void)
453 {
454         static int              cs_yes, cs_no;
455         prvm_edict_t    *ent;
456         vec3_t                  mins, maxs, start, stop;
457         trace_t                 trace;
458         int                             x, y, hit;
459         float                   mid, bottom;
460
461         VM_SAFEPARMCOUNT(1, VM_CL_checkbottom);
462         ent = PRVM_G_EDICT(OFS_PARM0);
463         PRVM_G_FLOAT(OFS_RETURN) = 0;
464
465         VectorAdd (ent->fields.client->origin, ent->fields.client->mins, mins);
466         VectorAdd (ent->fields.client->origin, ent->fields.client->maxs, maxs);
467
468 // if all of the points under the corners are solid world, don't bother
469 // with the tougher checks
470 // the corners must be within 16 of the midpoint
471         start[2] = mins[2] - 1;
472         for     (x=0 ; x<=1 ; x++)
473                 for     (y=0 ; y<=1 ; y++)
474                 {
475                         start[0] = x ? maxs[0] : mins[0];
476                         start[1] = y ? maxs[1] : mins[1];
477                         if (!(CL_PointSuperContents(start) & (SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY)))
478                                 goto realcheck;
479                 }
480
481         cs_yes++;
482         PRVM_G_FLOAT(OFS_RETURN) = true;
483         return;         // we got out easy
484
485 realcheck:
486         cs_no++;
487 //
488 // check it for real...
489 //
490         start[2] = mins[2];
491
492 // the midpoint must be within 16 of the bottom
493         start[0] = stop[0] = (mins[0] + maxs[0])*0.5;
494         start[1] = stop[1] = (mins[1] + maxs[1])*0.5;
495         stop[2] = start[2] - 2*sv_stepheight.value;
496         trace = CL_TraceBox (start, vec3_origin, vec3_origin, stop, 1, &hit, 1, true);
497
498         if (trace.fraction == 1.0)
499                 return;
500
501         mid = bottom = trace.endpos[2];
502
503 // the corners must be within 16 of the midpoint
504         for     (x=0 ; x<=1 ; x++)
505                 for     (y=0 ; y<=1 ; y++)
506                 {
507                         start[0] = stop[0] = x ? maxs[0] : mins[0];
508                         start[1] = stop[1] = y ? maxs[1] : mins[1];
509
510                         trace = CL_TraceBox (start, vec3_origin, vec3_origin, stop, 1, &hit, 1, true);
511
512                         if (trace.fraction != 1.0 && trace.endpos[2] > bottom)
513                                 bottom = trace.endpos[2];
514                         if (trace.fraction == 1.0 || mid - trace.endpos[2] > sv_stepheight.value)
515                                 return;
516                 }
517
518         cs_yes++;
519         PRVM_G_FLOAT(OFS_RETURN) = true;
520 }
521
522 // #41 float(vector v) pointcontents
523 void VM_CL_pointcontents (void)
524 {
525         VM_SAFEPARMCOUNT(1, VM_CL_pointcontents);
526         PRVM_G_FLOAT(OFS_RETURN) = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, CL_PointSuperContents(PRVM_G_VECTOR(OFS_PARM0)));
527 }
528
529 // #48 void(vector o, vector d, float color, float count) particle
530 void VM_CL_particle (void)
531 {
532         float   *org, *dir;
533         int             count;
534         unsigned char   color;
535         VM_SAFEPARMCOUNT(4, VM_CL_particle);
536
537         org = PRVM_G_VECTOR(OFS_PARM0);
538         dir = PRVM_G_VECTOR(OFS_PARM1);
539         color = (int)PRVM_G_FLOAT(OFS_PARM2);
540         count = (int)PRVM_G_FLOAT(OFS_PARM3);
541         CL_ParticleEffect(EFFECT_SVC_PARTICLE, count, org, org, dir, dir, NULL, color);
542 }
543
544 // #49 void(entity ent, float ideal_yaw, float speed_yaw) ChangeYaw
545 void VM_CL_changeyaw (void)
546 {
547         prvm_edict_t    *ent;
548         float                   ideal, current, move, speed;
549         VM_SAFEPARMCOUNT(3, VM_CL_changeyaw);
550
551         ent = PRVM_G_EDICT(OFS_PARM0);
552         if (ent == prog->edicts)
553                 PF_WARNING("changeyaw: can not modify world entity\n");
554         if (ent->priv.server->free)
555                 PF_WARNING("changeyaw: can not modify free entity\n");
556         current = ANGLEMOD(ent->fields.client->angles[1]);
557         ideal = PRVM_G_FLOAT(OFS_PARM1);
558         speed = PRVM_G_FLOAT(OFS_PARM2);
559
560         if (current == ideal)
561                 return;
562         move = ideal - current;
563         if (ideal > current)
564         {
565                 if (move >= 180)
566                         move = move - 360;
567         }
568         else
569         {
570                 if (move <= -180)
571                         move = move + 360;
572         }
573         if (move > 0)
574         {
575                 if (move > speed)
576                         move = speed;
577         }
578         else
579         {
580                 if (move < -speed)
581                         move = -speed;
582         }
583
584         ent->fields.client->angles[1] = ANGLEMOD (current + move);
585 }
586
587 // #63 void(entity ent, float ideal_pitch, float speed_pitch) changepitch (DP_QC_CHANGEPITCH)
588 void VM_CL_changepitch (void)
589 {
590         prvm_edict_t            *ent;
591         float                           ideal, current, move, speed;
592         VM_SAFEPARMCOUNT(3, VM_CL_changepitch);
593
594         ent = PRVM_G_EDICT(OFS_PARM0);
595         if (ent == prog->edicts)
596                 PF_WARNING("changepitch: can not modify world entity\n");
597         if (ent->priv.server->free)
598                 PF_WARNING("changepitch: can not modify free entity\n");
599         current = ANGLEMOD( ent->fields.client->angles[0] );
600         ideal = PRVM_G_FLOAT(OFS_PARM1);
601         speed = PRVM_G_FLOAT(OFS_PARM2);
602
603         if (current == ideal)
604                 return;
605         move = ideal - current;
606         if (ideal > current)
607         {
608                 if (move >= 180)
609                         move = move - 360;
610         }
611         else
612         {
613                 if (move <= -180)
614                         move = move + 360;
615         }
616         if (move > 0)
617         {
618                 if (move > speed)
619                         move = speed;
620         }
621         else
622         {
623                 if (move < -speed)
624                         move = -speed;
625         }
626
627         ent->fields.client->angles[0] = ANGLEMOD (current + move);
628 }
629
630 // #64 void(entity e, entity ignore) tracetoss (DP_QC_TRACETOSS)
631 void VM_CL_tracetoss (void)
632 {
633 /*      trace_t trace;
634         prvm_edict_t    *ent;
635         prvm_edict_t    *ignore;
636
637         ent = PRVM_G_EDICT(OFS_PARM0);
638         if (ent == prog->edicts)
639                 PF_WARNING("tracetoss: can not use world entity\n");
640         ignore = PRVM_G_EDICT(OFS_PARM1);
641
642 //FIXME
643         trace = SV_Trace_Toss (ent, ignore);
644
645         prog->globals.server->trace_allsolid = trace.allsolid;
646         prog->globals.server->trace_startsolid = trace.startsolid;
647         prog->globals.server->trace_fraction = trace.fraction;
648         prog->globals.server->trace_inwater = trace.inwater;
649         prog->globals.server->trace_inopen = trace.inopen;
650         VectorCopy (trace.endpos, prog->globals.server->trace_endpos);
651         VectorCopy (trace.plane.normal, prog->globals.server->trace_plane_normal);
652         prog->globals.server->trace_plane_dist =  trace.plane.dist;
653         if (trace.ent)
654                 prog->globals.server->trace_ent = PRVM_EDICT_TO_PROG(trace.ent);
655         else
656                 prog->globals.server->trace_ent = PRVM_EDICT_TO_PROG(prog->edicts);
657 */
658 }
659
660 // #74 void(vector pos, string samp, float vol, float atten) ambientsound
661 void VM_CL_ambientsound (void)
662 {
663         float   *f;
664         sfx_t   *s;
665         VM_SAFEPARMCOUNT(4, VM_CL_ambientsound);
666         s = S_FindName(PRVM_G_STRING(OFS_PARM0));
667         f = PRVM_G_VECTOR(OFS_PARM1);
668         S_StaticSound (s, f, PRVM_G_FLOAT(OFS_PARM2), PRVM_G_FLOAT(OFS_PARM3)*64);
669 }
670
671 // #90 void(vector v1, vector min, vector max, vector v2, float nomonsters, entity forent) tracebox (DP_QC_TRACEBOX)
672 void VM_CL_tracebox (void)
673 {
674         float   *v1, *v2, *m1, *m2;
675         trace_t trace;
676         int             ent;
677
678         v1 = PRVM_G_VECTOR(OFS_PARM0);
679         m1 = PRVM_G_VECTOR(OFS_PARM1);
680         m2 = PRVM_G_VECTOR(OFS_PARM2);
681         v2 = PRVM_G_VECTOR(OFS_PARM3);
682
683         trace = CL_TraceBox(v1, m1, m2, v2, 1, &ent, 1, false);
684
685         prog->globals.client->trace_allsolid = trace.allsolid;
686         prog->globals.client->trace_startsolid = trace.startsolid;
687         prog->globals.client->trace_fraction = trace.fraction;
688         prog->globals.client->trace_inwater = trace.inwater;
689         prog->globals.client->trace_inopen = trace.inopen;
690         VectorCopy (trace.endpos, prog->globals.client->trace_endpos);
691         VectorCopy (trace.plane.normal, prog->globals.client->trace_plane_normal);
692         prog->globals.client->trace_plane_dist =  trace.plane.dist;
693         if (ent)
694                 prog->globals.client->trace_ent = ent;
695         else
696                 prog->globals.client->trace_ent = PRVM_EDICT_TO_PROG(prog->edicts);
697 }
698
699 // #92 vector(vector org) getlight (DP_QC_GETLIGHT)
700 void VM_CL_getlight (void)
701 {
702         vec3_t ambientcolor, diffusecolor, diffusenormal;
703         vec_t *p;
704
705         VM_SAFEPARMCOUNT(1, VM_CL_getlight);
706
707         p = PRVM_G_VECTOR(OFS_PARM0);
708         VectorClear(ambientcolor);
709         VectorClear(diffusecolor);
710         VectorClear(diffusenormal);
711         if (cl.worldmodel && cl.worldmodel->brush.LightPoint)
712                 cl.worldmodel->brush.LightPoint(cl.worldmodel, p, ambientcolor, diffusecolor, diffusenormal);
713         VectorMA(ambientcolor, 0.5, diffusecolor, PRVM_G_VECTOR(OFS_RETURN));
714 }
715
716
717 //============================================================================
718 //[515]: SCENE MANAGER builtins
719 void V_CalcRefdef (void);//view.c
720 void CSQC_R_ClearScreen (void);//gl_rmain.c
721 void CSQC_R_RenderScene (void);//gl_rmain.c
722 void CSQC_AddEntity (int n);//csprogs.c
723 void CSQC_ClearCSQCEntities (void);
724
725 matrix4x4_t csqc_listenermatrix;
726 qboolean csqc_usecsqclistener = false, csqc_frame = false;//[515]: per-frame
727 qboolean csqc_onground;
728
729 static void CSQC_R_RecalcView (void)
730 {
731         extern matrix4x4_t viewmodelmatrix;
732         viewmodelmatrix = identitymatrix;
733         r_view.matrix = identitymatrix;
734         Matrix4x4_CreateFromQuakeEntity(&r_view.matrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 1);
735         Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 0.3);
736 }
737
738 //#300 void() clearscene (EXT_CSQC)
739 void VM_R_ClearScene (void)
740 {
741         VM_SAFEPARMCOUNT(0, VM_R_ClearScene);
742 //      CSQC_R_RecalcView();
743         if(csqc_frame)
744                 CSQC_ClearCSQCEntities();
745         CSQC_R_ClearScreen();
746 }
747
748 //#301 void(float mask) addentities (EXT_CSQC)
749 void VM_R_AddEntities (void)
750 {
751         VM_SAFEPARMCOUNT(1, VM_R_AddEntities);
752         csqc_drawmask = (int)PRVM_G_FLOAT(OFS_PARM0);
753 }
754
755 //#302 void(entity ent) addentity (EXT_CSQC)
756 void VM_R_AddEntity (void)
757 {
758         VM_SAFEPARMCOUNT(1, VM_R_AddEntity);
759         CSQC_AddEntity(PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(OFS_PARM0)));
760 }
761
762 //#303 float(float property, ...) setproperty (EXT_CSQC)
763 void VM_R_SetView (void)
764 {
765         int             c;
766         float   *f;
767         float   k;
768
769         if(prog->argc < 2)
770                 VM_SAFEPARMCOUNT(2, VM_R_SetView);
771
772         c = (int)PRVM_G_FLOAT(OFS_PARM0);
773         f = PRVM_G_VECTOR(OFS_PARM1);
774         k = PRVM_G_FLOAT(OFS_PARM1);
775
776         switch(c)
777         {
778         case VF_MIN:                    r_view.x = (int)f[0];
779                                                         r_view.y = (int)f[1];
780                                                         break;
781         case VF_MIN_X:                  r_view.x = (int)k;
782                                                         break;
783         case VF_MIN_Y:                  r_view.y = (int)k;
784                                                         break;
785         case VF_SIZE:                   r_view.width = (int)f[0];
786                                                         r_view.height = (int)f[1];
787                                                         break;
788         case VF_SIZE_Y:                 r_view.width = (int)k;
789                                                         break;
790         case VF_SIZE_X:                 r_view.height = (int)k;
791                                                         break;
792         case VF_VIEWPORT:               r_view.x = (int)f[0];
793                                                         r_view.y = (int)f[1];
794                                                         r_view.z = 0;
795                                                         // TODO: make sure that view_z and view_depth are set properly even if csqc does not set them!
796                                                         f = PRVM_G_VECTOR(OFS_PARM2);
797                                                         r_view.width = (int)f[0];
798                                                         r_view.height = (int)f[1];
799                                                         r_view.depth = 1;
800                                                         break;
801         case VF_FOV:                    //r_refdef.fov_x = f[0]; // FIXME!
802                                                         //r_refdef.fov_y = f[1]; // FIXME!
803                                                         break;
804         case VF_FOVX:                   //r_refdef.fov_x = k; // FIXME!
805                                                         break;
806         case VF_FOVY:                   //r_refdef.fov_y = k; // FIXME!
807                                                         break;
808         case VF_ORIGIN:                 VectorCopy(f, csqc_origin);
809                                                         CSQC_R_RecalcView();
810                                                         break;
811         case VF_ORIGIN_X:               csqc_origin[0] = k;
812                                                         CSQC_R_RecalcView();
813                                                         break;
814         case VF_ORIGIN_Y:               csqc_origin[1] = k;
815                                                         CSQC_R_RecalcView();
816                                                         break;
817         case VF_ORIGIN_Z:               csqc_origin[2] = k;
818                                                         CSQC_R_RecalcView();
819                                                         break;
820         case VF_ANGLES:                 VectorCopy(f, csqc_angles);
821                                                         CSQC_R_RecalcView();
822                                                         break;
823         case VF_ANGLES_X:               csqc_angles[0] = k;
824                                                         CSQC_R_RecalcView();
825                                                         break;
826         case VF_ANGLES_Y:               csqc_angles[1] = k;
827                                                         CSQC_R_RecalcView();
828                                                         break;
829         case VF_ANGLES_Z:               csqc_angles[2] = k;
830                                                         CSQC_R_RecalcView();
831                                                         break;
832         case VF_DRAWWORLD:              cl.csqc_vidvars.drawworld = k;
833                                                         break;
834         case VF_DRAWENGINESBAR: cl.csqc_vidvars.drawenginesbar = k;
835                                                         break;
836         case VF_DRAWCROSSHAIR:  cl.csqc_vidvars.drawcrosshair = k;
837                                                         break;
838
839         case VF_CL_VIEWANGLES:  VectorCopy(f, cl.viewangles);
840                                                         break;
841         case VF_CL_VIEWANGLES_X:cl.viewangles[0] = k;
842                                                         break;
843         case VF_CL_VIEWANGLES_Y:cl.viewangles[1] = k;
844                                                         break;
845         case VF_CL_VIEWANGLES_Z:cl.viewangles[2] = k;
846                                                         break;
847
848         default:                                Con_Printf("VM_R_SetView : unknown parm %i\n", c);
849                                                         PRVM_G_FLOAT(OFS_RETURN) = 0;
850                                                         return;
851         }
852         PRVM_G_FLOAT(OFS_RETURN) = 1;
853 }
854
855 //#304 void() renderscene (EXT_CSQC)
856 void VM_R_RenderScene (void) //#134
857 {
858         VM_SAFEPARMCOUNT(0, VM_R_RenderScene);
859
860         if(csqc_frame)
861         {
862                 CSQC_RelinkCSQCEntities();
863                 CSQC_RelinkAllEntities(csqc_drawmask);
864         }
865
866         CSQC_R_RenderScene();
867 }
868
869 //#305 void(vector org, float radius, vector lightcolours) adddynamiclight (EXT_CSQC)
870 void VM_R_AddDynamicLight (void)
871 {
872         float           *pos, *col;
873         matrix4x4_t     tempmatrix;
874         VM_SAFEPARMCOUNT(3, VM_R_AddDynamicLight);
875
876         pos = PRVM_G_VECTOR(OFS_PARM0);
877         col = PRVM_G_VECTOR(OFS_PARM2);
878         Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
879         CL_AllocDlight(NULL, &tempmatrix, PRVM_G_FLOAT(OFS_PARM1), col[0], col[1], col[2], 500, 0, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
880         //CL_AllocDlight(NULL, &tempmatrix, PRVM_G_FLOAT(OFS_PARM1), col[0], col[1], col[2], 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
881 }
882
883 //============================================================================
884
885 //#310 vector (vector v) cs_unproject (EXT_CSQC)
886 void VM_CL_unproject (void)
887 {
888         float   *f;
889         vec3_t  temp;
890
891         VM_SAFEPARMCOUNT(1, VM_CL_unproject);
892         f = PRVM_G_VECTOR(OFS_PARM0);
893         VectorSet(temp, f[2], f[0] * f[2] * -r_view.frustum_x * 2.0 / r_view.width, f[1] * f[2] * -r_view.frustum_y * 2.0 / r_view.height);
894         Matrix4x4_Transform(&r_view.matrix, temp, PRVM_G_VECTOR(OFS_RETURN));
895 }
896
897 //#311 vector (vector v) cs_project (EXT_CSQC)
898 void VM_CL_project (void)
899 {
900         float   *f;
901         vec3_t  v;
902         matrix4x4_t m;
903
904         VM_SAFEPARMCOUNT(1, VM_CL_project);
905         f = PRVM_G_VECTOR(OFS_PARM0);
906         Matrix4x4_Invert_Simple(&m, &r_view.matrix);
907         Matrix4x4_Transform(&m, f, v);
908         VectorSet(PRVM_G_VECTOR(OFS_RETURN), v[1]/v[0]/-r_view.frustum_x*0.5*r_view.width, v[2]/v[0]/-r_view.frustum_y*r_view.height*0.5, v[0]);
909 }
910
911 //#330 float(float stnum) getstatf (EXT_CSQC)
912 void VM_CL_getstatf (void)
913 {
914         int i;
915         union
916         {
917                 float f;
918                 int l;
919         }dat;
920         VM_SAFEPARMCOUNT(1, VM_CL_getstatf);
921         i = (int)PRVM_G_FLOAT(OFS_PARM0);
922         if(i < 0 || i >= MAX_CL_STATS)
923         {
924                 Con_Printf("VM_CL_getstatf: index>=MAX_CL_STATS or index<0\n");
925                 return;
926         }
927         dat.l = cl.stats[i];
928         PRVM_G_FLOAT(OFS_RETURN) =  dat.f;
929 }
930
931 //#331 float(float stnum) getstati (EXT_CSQC)
932 void VM_CL_getstati (void)
933 {
934         int i, index;
935         VM_SAFEPARMCOUNT(1, VM_CL_getstati);
936         index = (int)PRVM_G_FLOAT(OFS_PARM0);
937
938         if(index < 0 || index >= MAX_CL_STATS)
939         {
940                 Con_Printf("VM_CL_getstati: index>=MAX_CL_STATS or index<0\n");
941                 return;
942         }
943         i = cl.stats[index];
944         PRVM_G_FLOAT(OFS_RETURN) = i;
945 }
946
947 //#332 string(float firststnum) getstats (EXT_CSQC)
948 void VM_CL_getstats (void)
949 {
950         int i;
951         char *t;
952         VM_SAFEPARMCOUNT(1, VM_CL_getstats);
953         i = (int)PRVM_G_FLOAT(OFS_PARM0);
954         if(i < 0 || i > MAX_CL_STATS-4)
955         {
956                 Con_Printf("VM_CL_getstats: index>MAX_CL_STATS-4 or index<0\n");
957                 return;
958         }
959         t = VM_GetTempString();
960         strlcpy(t, (char*)&cl.stats[i], 16);
961         PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(t);
962 }
963
964 //#333 void(entity e, float mdlindex) setmodelindex (EXT_CSQC)
965 void VM_CL_setmodelindex (void)
966 {
967         int                             i;
968         prvm_edict_t    *t;
969         struct model_s  *m;
970
971         VM_SAFEPARMCOUNT(2, VM_CL_setmodelindex);
972
973         t = PRVM_G_EDICT(OFS_PARM0);
974         i = (int)PRVM_G_FLOAT(OFS_PARM1);
975
976         t->fields.client->model = 0;
977         t->fields.client->modelindex = 0;
978
979         if(!i)
980                 return;
981         if(i<0)
982         {
983                 i = -(i+1);
984                 if(i >= MAX_MODELS)
985                         PF_WARNING("VM_CL_setmodelindex >= MAX_MODELS\n");
986                 m = cl.csqc_model_precache[i];
987         }
988         else
989                 if(i >= MAX_MODELS)
990                         PF_WARNING("VM_CL_setmodelindex >= MAX_MODELS\n");
991                 else
992                         m = cl.model_precache[i];
993         if(!m)
994                 PF_WARNING("VM_CL_setmodelindex: null model\n");
995         t->fields.client->model = PRVM_SetEngineString(m->name);
996         t->fields.client->modelindex = i;
997 }
998
999 //#334 string(float mdlindex) modelnameforindex (EXT_CSQC)
1000 void VM_CL_modelnameforindex (void)
1001 {
1002         int i;
1003
1004         VM_SAFEPARMCOUNT(1, VM_CL_modelnameforindex);
1005
1006         PRVM_G_INT(OFS_RETURN) = 0;
1007         i = (int)PRVM_G_FLOAT(OFS_PARM0);
1008         if(i<0)
1009         {
1010                 i = -(i+1);
1011                 if(i >= MAX_MODELS)
1012                         PF_WARNING("VM_CL_modelnameforindex >= MAX_MODELS\n");
1013                 if(cl.csqc_model_precache[i])
1014                         PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(cl.csqc_model_precache[i]->name);
1015                 return;
1016         }
1017         if(i >= MAX_MODELS)
1018                 PF_WARNING("VM_CL_modelnameforindex >= MAX_MODELS\n");
1019         if(cl.model_precache[i])
1020                 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(cl.model_precache[i]->name);
1021 }
1022
1023 //#335 float(string effectname) particleeffectnum (EXT_CSQC)
1024 void VM_CL_particleeffectnum (void)
1025 {
1026         const char      *n;
1027         int                     i;
1028         VM_SAFEPARMCOUNT(1, VM_CL_particleeffectnum);
1029         n = PRVM_G_STRING(OFS_PARM0);
1030         i = CL_ParticleEffectIndexForName(n);
1031         if (i == 0)
1032                 i = -1;
1033         PRVM_G_FLOAT(OFS_RETURN) = i;
1034 }
1035
1036 // #336 void(entity ent, float effectnum, vector start, vector end[, float color]) trailparticles (EXT_CSQC)
1037 void VM_CL_trailparticles (void)
1038 {
1039         int                             i, entnum;
1040         float                   *start, *end;
1041         prvm_edict_t    *t;
1042         VM_SAFEPARMCOUNT(4, VM_CL_trailparticles);
1043
1044         t = PRVM_G_EDICT(OFS_PARM0);
1045         entnum  = PRVM_NUM_FOR_EDICT(t);
1046         i               = (int)PRVM_G_FLOAT(OFS_PARM1);
1047         start   = PRVM_G_VECTOR(OFS_PARM2);
1048         end             = PRVM_G_VECTOR(OFS_PARM3);
1049
1050         if (entnum >= MAX_EDICTS)
1051         {
1052                 Con_Printf("CSQC_ParseBeam: invalid entity number %i\n", entnum);
1053                 return;
1054         }
1055         if (entnum >= cl.max_csqcentities)
1056                 CL_ExpandCSQCEntities(entnum);
1057
1058         CL_ParticleEffect(i, VectorDistance(start, end), start, end, t->fields.client->velocity, t->fields.client->velocity, &cl.csqcentities[entnum], (int)PRVM_G_FLOAT(OFS_PARM4));
1059 }
1060
1061 //#337 void(float effectnum, vector origin, vector dir, float count) pointparticles (EXT_CSQC)
1062 void VM_CL_pointparticles (void)
1063 {
1064         int                     i, n;
1065         float           *f, *v;
1066         VM_SAFEPARMCOUNT(4, VM_CL_pointparticles);
1067         i = (int)PRVM_G_FLOAT(OFS_PARM0);
1068         f = PRVM_G_VECTOR(OFS_PARM1);
1069         v = PRVM_G_VECTOR(OFS_PARM2);
1070         n = (int)PRVM_G_FLOAT(OFS_PARM3);
1071         CL_ParticleEffect(i, n, f, f, v, v, NULL, 0);
1072 }
1073
1074 //#338 void(string s) cprint (EXT_CSQC)
1075 void VM_CL_centerprint (void)
1076 {
1077         char s[VM_STRINGTEMP_LENGTH];
1078         if(prog->argc < 1)
1079                 VM_SAFEPARMCOUNT(1, VM_CL_centerprint);
1080         VM_VarString(0, s, sizeof(s));
1081         SCR_CenterPrint(s);
1082 }
1083
1084 //#342 string(float keynum) getkeybind (EXT_CSQC)
1085 void VM_CL_getkeybind (void)
1086 {
1087         int i;
1088
1089         VM_SAFEPARMCOUNT(1, VM_CL_getkeybind);
1090         i = (int)PRVM_G_FLOAT(OFS_PARM0);
1091         PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(Key_GetBind(i));
1092 }
1093
1094 //#343 void(float usecursor) setcursormode (EXT_CSQC)
1095 void VM_CL_setcursormode (void)
1096 {
1097         VM_SAFEPARMCOUNT(1, VM_CL_setcursormode);
1098         cl.csqc_wantsmousemove = PRVM_G_FLOAT(OFS_PARM0);
1099         cl_ignoremousemove = true;
1100 }
1101
1102 //#345 float(float framenum) getinputstate (EXT_CSQC)
1103 void VM_CL_getinputstate (void)
1104 {
1105         int i, frame;
1106         VM_SAFEPARMCOUNT(1, VM_CL_getinputstate);
1107         frame = (int)PRVM_G_FLOAT(OFS_PARM0);
1108         for (i = 0;i < cl.movement_numqueue;i++)
1109                 if (cl.movement_queue[i].sequence == frame)
1110                 {
1111                         VectorCopy(cl.movement_queue[i].viewangles, prog->globals.client->input_angles);
1112                         //prog->globals.client->input_buttons = cl.movement_queue[i].//FIXME
1113                         VectorCopy(cl.movement_queue[i].move, prog->globals.client->input_movevalues);
1114                         prog->globals.client->input_timelength = cl.movement_queue[i].frametime;
1115                         if(cl.movement_queue[i].crouch)
1116                         {
1117                                 VectorCopy(cl.playercrouchmins, prog->globals.client->pmove_mins);
1118                                 VectorCopy(cl.playercrouchmaxs, prog->globals.client->pmove_maxs);
1119                         }
1120                         else
1121                         {
1122                                 VectorCopy(cl.playerstandmins, prog->globals.client->pmove_mins);
1123                                 VectorCopy(cl.playerstandmaxs, prog->globals.client->pmove_maxs);
1124                         }
1125                 }
1126 }
1127
1128 //#346 void(float sens) setsensitivityscaler (EXT_CSQC)
1129 void VM_CL_setsensitivityscale (void)
1130 {
1131         VM_SAFEPARMCOUNT(1, VM_CL_setsensitivityscale);
1132         cl.sensitivityscale = PRVM_G_FLOAT(OFS_PARM0);
1133 }
1134
1135 //#347 void() runstandardplayerphysics (EXT_CSQC)
1136 void VM_CL_runplayerphysics (void)
1137 {
1138 }
1139
1140 //#348 string(float playernum, string keyname) getplayerkeyvalue (EXT_CSQC)
1141 void VM_CL_getplayerkey (void)
1142 {
1143         int                     i;
1144         char            t[128];
1145         const char      *c;
1146         char            *temp;
1147
1148         VM_SAFEPARMCOUNT(2, VM_CL_getplayerkey);
1149
1150         i = (int)PRVM_G_FLOAT(OFS_PARM0);
1151         c = PRVM_G_STRING(OFS_PARM1);
1152         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
1153         Sbar_SortFrags();
1154
1155         i = Sbar_GetPlayer(i);
1156         if(i < 0)
1157                 return;
1158
1159         t[0] = 0;
1160
1161         if(!strcasecmp(c, "name"))
1162                 strcpy(t, cl.scores[i].name);
1163         else
1164                 if(!strcasecmp(c, "frags"))
1165                         sprintf(t, "%i", cl.scores[i].frags);
1166 //      else
1167 //              if(!strcasecmp(c, "ping"))
1168 //                      sprintf(t, "%i", cl.scores[i].ping);
1169 //      else
1170 //              if(!strcasecmp(c, "entertime"))
1171 //                      sprintf(t, "%f", cl.scores[i].entertime);
1172         else
1173                 if(!strcasecmp(c, "colors"))
1174                         sprintf(t, "%i", cl.scores[i].colors);
1175         else
1176                 if(!strcasecmp(c, "topcolor"))
1177                         sprintf(t, "%i", cl.scores[i].colors & 0xf0);
1178         else
1179                 if(!strcasecmp(c, "bottomcolor"))
1180                         sprintf(t, "%i", (cl.scores[i].colors &15)<<4);
1181         else
1182                 if(!strcasecmp(c, "viewentity"))
1183                         sprintf(t, "%i", i+1);
1184         if(!t[0])
1185                 return;
1186         temp = VM_GetTempString();
1187         strcpy(temp, t);
1188         PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(temp);
1189 }
1190
1191 //#349 float() isdemo (EXT_CSQC)
1192 void VM_CL_isdemo (void)
1193 {
1194         PRVM_G_FLOAT(OFS_RETURN) = cls.demoplayback;
1195 }
1196
1197 //#351 void(vector origin, vector forward, vector right, vector up) SetListener (EXT_CSQC)
1198 void VM_CL_setlistener (void)
1199 {
1200         VM_SAFEPARMCOUNT(4, VM_CL_setlistener);
1201         Matrix4x4_FromVectors(&csqc_listenermatrix, PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), PRVM_G_VECTOR(OFS_PARM3), PRVM_G_VECTOR(OFS_PARM0));
1202         csqc_usecsqclistener = true;    //use csqc listener at this frame
1203 }
1204
1205 //#352 void(string cmdname) registercommand (EXT_CSQC)
1206 void VM_CL_registercmd (void)
1207 {
1208         char *t;
1209         VM_SAFEPARMCOUNT(1, VM_CL_registercmd);
1210         if(!Cmd_Exists(PRVM_G_STRING(OFS_PARM0)))
1211         {
1212                 t = (char *)Z_Malloc(strlen(PRVM_G_STRING(OFS_PARM0))+1);
1213                 strcpy(t, PRVM_G_STRING(OFS_PARM0));
1214                 Cmd_AddCommand(t, NULL, "console command created by QuakeC");
1215         }
1216         else
1217                 Cmd_AddCommand(PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
1218
1219 }
1220
1221 //#354 float() playernum (EXT_CSQC)
1222 void VM_CL_playernum (void)
1223 {
1224         int i, k;
1225
1226         VM_SAFEPARMCOUNT(0, VM_CL_playernum);
1227
1228         for(i=k=0 ; i<cl.maxclients ; i++)
1229                 if(cl.scores[i].name[0])
1230                         k++;
1231         PRVM_G_FLOAT(OFS_RETURN) = k;
1232 }
1233
1234 //#355 float() cl_onground (EXT_CSQC)
1235 void VM_CL_onground (void)
1236 {
1237         PRVM_G_FLOAT(OFS_RETURN) = csqc_onground;
1238 }
1239
1240 //#360 float() readbyte (EXT_CSQC)
1241 void VM_CL_ReadByte (void)
1242 {
1243         PRVM_G_FLOAT(OFS_RETURN) = MSG_ReadByte();
1244 }
1245
1246 //#361 float() readchar (EXT_CSQC)
1247 void VM_CL_ReadChar (void)
1248 {
1249         PRVM_G_FLOAT(OFS_RETURN) = MSG_ReadChar();
1250 }
1251
1252 //#362 float() readshort (EXT_CSQC)
1253 void VM_CL_ReadShort (void)
1254 {
1255         PRVM_G_FLOAT(OFS_RETURN) = MSG_ReadShort();
1256 }
1257
1258 //#363 float() readlong (EXT_CSQC)
1259 void VM_CL_ReadLong (void)
1260 {
1261         PRVM_G_FLOAT(OFS_RETURN) = MSG_ReadLong();
1262 }
1263
1264 //#364 float() readcoord (EXT_CSQC)
1265 void VM_CL_ReadCoord (void)
1266 {
1267         PRVM_G_FLOAT(OFS_RETURN) = MSG_ReadCoord(cls.protocol);
1268 }
1269
1270 //#365 float() readangle (EXT_CSQC)
1271 void VM_CL_ReadAngle (void)
1272 {
1273         PRVM_G_FLOAT(OFS_RETURN) = MSG_ReadAngle(cls.protocol);
1274 }
1275
1276 //#366 string() readstring (EXT_CSQC)
1277 void VM_CL_ReadString (void)
1278 {
1279         char *t, *s;
1280         t = VM_GetTempString();
1281         s = MSG_ReadString();
1282         PRVM_G_INT(OFS_RETURN) = 0;
1283         if(s)
1284         {
1285                 strcpy(t, s);
1286                 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(t);
1287         }
1288 }
1289
1290 //#367 float() readfloat (EXT_CSQC)
1291 void VM_CL_ReadFloat (void)
1292 {
1293         PRVM_G_FLOAT(OFS_RETURN) = MSG_ReadFloat();
1294 }
1295
1296 //=================================================================//
1297
1298 // #404 void(vector org, string modelname, float startframe, float endframe, float framerate) effect (DP_SV_EFFECT)
1299 void VM_CL_effect (void)
1300 {
1301         VM_SAFEPARMCOUNT(5, VM_CL_effect);
1302         CL_Effect(PRVM_G_VECTOR(OFS_PARM0), (int)PRVM_G_FLOAT(OFS_PARM1), (int)PRVM_G_FLOAT(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), PRVM_G_FLOAT(OFS_PARM4));
1303 }
1304
1305 // #405 void(vector org, vector velocity, float howmany) te_blood (DP_TE_BLOOD)
1306 void VM_CL_te_blood (void)
1307 {
1308         float   *pos;
1309         vec3_t  pos2;
1310         VM_SAFEPARMCOUNT(3, VM_CL_te_blood);
1311         if (PRVM_G_FLOAT(OFS_PARM2) < 1)
1312                 return;
1313         pos = PRVM_G_VECTOR(OFS_PARM0);
1314         CL_FindNonSolidLocation(pos, pos2, 4);
1315         CL_ParticleEffect(EFFECT_TE_BLOOD, PRVM_G_FLOAT(OFS_PARM2), pos2, pos2, PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM1), NULL, 0);
1316 }
1317
1318 // #406 void(vector mincorner, vector maxcorner, float explosionspeed, float howmany) te_bloodshower (DP_TE_BLOODSHOWER)
1319 void VM_CL_te_bloodshower (void)
1320 {
1321         vec_t speed;
1322         vec3_t vel1, vel2;
1323         VM_SAFEPARMCOUNT(4, VM_CL_te_bloodshower);
1324         if (PRVM_G_FLOAT(OFS_PARM3) < 1)
1325                 return;
1326         speed = PRVM_G_FLOAT(OFS_PARM2);
1327         vel1[0] = -speed;
1328         vel1[1] = -speed;
1329         vel1[2] = -speed;
1330         vel2[0] = speed;
1331         vel2[1] = speed;
1332         vel2[2] = speed;
1333         CL_ParticleEffect(EFFECT_TE_BLOOD, PRVM_G_FLOAT(OFS_PARM3), PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), vel1, vel2, NULL, 0);
1334 }
1335
1336 // #407 void(vector org, vector color) te_explosionrgb (DP_TE_EXPLOSIONRGB)
1337 void VM_CL_te_explosionrgb (void)
1338 {
1339         float           *pos;
1340         vec3_t          pos2;
1341         matrix4x4_t     tempmatrix;
1342         VM_SAFEPARMCOUNT(2, VM_CL_te_explosionrgb);
1343         pos = PRVM_G_VECTOR(OFS_PARM0);
1344         CL_FindNonSolidLocation(pos, pos2, 10);
1345         CL_ParticleExplosion(pos2);
1346         Matrix4x4_CreateTranslate(&tempmatrix, pos2[0], pos2[1], pos2[2]);
1347         CL_AllocDlight(NULL, &tempmatrix, 350, PRVM_G_VECTOR(OFS_PARM1)[0], PRVM_G_VECTOR(OFS_PARM1)[1], PRVM_G_VECTOR(OFS_PARM1)[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1348 }
1349
1350 // #408 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color, float gravityflag, float randomveljitter) te_particlecube (DP_TE_PARTICLECUBE)
1351 void VM_CL_te_particlecube (void)
1352 {
1353         VM_SAFEPARMCOUNT(7, VM_CL_te_particlecube);
1354         CL_ParticleCube(PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), PRVM_G_FLOAT(OFS_PARM5), PRVM_G_FLOAT(OFS_PARM6));
1355 }
1356
1357 // #409 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color) te_particlerain (DP_TE_PARTICLERAIN)
1358 void VM_CL_te_particlerain (void)
1359 {
1360         VM_SAFEPARMCOUNT(5, VM_CL_te_particlerain);
1361         CL_ParticleRain(PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), 0);
1362 }
1363
1364 // #410 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color) te_particlesnow (DP_TE_PARTICLESNOW)
1365 void VM_CL_te_particlesnow (void)
1366 {
1367         VM_SAFEPARMCOUNT(5, VM_CL_te_particlesnow);
1368         CL_ParticleRain(PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), 1);
1369 }
1370
1371 // #411 void(vector org, vector vel, float howmany) te_spark
1372 void VM_CL_te_spark (void)
1373 {
1374         float           *pos;
1375         vec3_t          pos2;
1376         VM_SAFEPARMCOUNT(3, VM_CL_te_spark);
1377
1378         pos = PRVM_G_VECTOR(OFS_PARM0);
1379         CL_FindNonSolidLocation(pos, pos2, 4);
1380         CL_ParticleEffect(EFFECT_TE_SPARK, PRVM_G_FLOAT(OFS_PARM2), pos2, pos2, PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM1), NULL, 0);
1381 }
1382
1383 // #412 void(vector org) te_gunshotquad (DP_QUADEFFECTS1)
1384 void VM_CL_te_gunshotquad (void)
1385 {
1386         float           *pos;
1387         vec3_t          pos2;
1388         VM_SAFEPARMCOUNT(1, VM_CL_te_gunshotquad);
1389
1390         pos = PRVM_G_VECTOR(OFS_PARM0);
1391         CL_FindNonSolidLocation(pos, pos2, 4);
1392         CL_ParticleEffect(EFFECT_TE_GUNSHOTQUAD, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1393 }
1394
1395 // #413 void(vector org) te_spikequad (DP_QUADEFFECTS1)
1396 void VM_CL_te_spikequad (void)
1397 {
1398         float           *pos;
1399         vec3_t          pos2;
1400         int                     rnd;
1401         VM_SAFEPARMCOUNT(1, VM_CL_te_spikequad);
1402
1403         pos = PRVM_G_VECTOR(OFS_PARM0);
1404         CL_FindNonSolidLocation(pos, pos2, 4);
1405         CL_ParticleEffect(EFFECT_TE_SPIKEQUAD, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1406         if (rand() % 5)                 S_StartSound(-1, 0, cl.sfx_tink1, pos2, 1, 1);
1407         else
1408         {
1409                 rnd = rand() & 3;
1410                 if (rnd == 1)           S_StartSound(-1, 0, cl.sfx_ric1, pos2, 1, 1);
1411                 else if (rnd == 2)      S_StartSound(-1, 0, cl.sfx_ric2, pos2, 1, 1);
1412                 else                            S_StartSound(-1, 0, cl.sfx_ric3, pos2, 1, 1);
1413         }
1414 }
1415
1416 // #414 void(vector org) te_superspikequad (DP_QUADEFFECTS1)
1417 void VM_CL_te_superspikequad (void)
1418 {
1419         float           *pos;
1420         vec3_t          pos2;
1421         int                     rnd;
1422         VM_SAFEPARMCOUNT(1, VM_CL_te_superspikequad);
1423
1424         pos = PRVM_G_VECTOR(OFS_PARM0);
1425         CL_FindNonSolidLocation(pos, pos2, 4);
1426         CL_ParticleEffect(EFFECT_TE_SUPERSPIKEQUAD, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1427         if (rand() % 5)                 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1428         else
1429         {
1430                 rnd = rand() & 3;
1431                 if (rnd == 1)           S_StartSound(-1, 0, cl.sfx_ric1, pos2, 1, 1);
1432                 else if (rnd == 2)      S_StartSound(-1, 0, cl.sfx_ric2, pos2, 1, 1);
1433                 else                            S_StartSound(-1, 0, cl.sfx_ric3, pos2, 1, 1);
1434         }
1435 }
1436
1437 // #415 void(vector org) te_explosionquad (DP_QUADEFFECTS1)
1438 void VM_CL_te_explosionquad (void)
1439 {
1440         float           *pos;
1441         vec3_t          pos2;
1442         VM_SAFEPARMCOUNT(1, VM_CL_te_explosionquad);
1443
1444         pos = PRVM_G_VECTOR(OFS_PARM0);
1445         CL_FindNonSolidLocation(pos, pos2, 10);
1446         CL_ParticleEffect(EFFECT_TE_EXPLOSIONQUAD, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1447         S_StartSound(-1, 0, cl.sfx_r_exp3, pos2, 1, 1);
1448 }
1449
1450 // #416 void(vector org) te_smallflash (DP_TE_SMALLFLASH)
1451 void VM_CL_te_smallflash (void)
1452 {
1453         float           *pos;
1454         vec3_t          pos2;
1455         VM_SAFEPARMCOUNT(1, VM_CL_te_smallflash);
1456
1457         pos = PRVM_G_VECTOR(OFS_PARM0);
1458         CL_FindNonSolidLocation(pos, pos2, 10);
1459         CL_ParticleEffect(EFFECT_TE_SMALLFLASH, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1460 }
1461
1462 // #417 void(vector org, float radius, float lifetime, vector color) te_customflash (DP_TE_CUSTOMFLASH)
1463 void VM_CL_te_customflash (void)
1464 {
1465         float           *pos;
1466         vec3_t          pos2;
1467         matrix4x4_t     tempmatrix;
1468         VM_SAFEPARMCOUNT(4, VM_CL_te_customflash);
1469
1470         pos = PRVM_G_VECTOR(OFS_PARM0);
1471         CL_FindNonSolidLocation(pos, pos2, 4);
1472         Matrix4x4_CreateTranslate(&tempmatrix, pos2[0], pos2[1], pos2[2]);
1473         CL_AllocDlight(NULL, &tempmatrix, PRVM_G_FLOAT(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM3)[0], PRVM_G_VECTOR(OFS_PARM3)[1], PRVM_G_VECTOR(OFS_PARM3)[2], PRVM_G_FLOAT(OFS_PARM1) / PRVM_G_FLOAT(OFS_PARM2), PRVM_G_FLOAT(OFS_PARM2), 0, -1, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1474 }
1475
1476 // #418 void(vector org) te_gunshot (DP_TE_STANDARDEFFECTBUILTINS)
1477 void VM_CL_te_gunshot (void)
1478 {
1479         float           *pos;
1480         vec3_t          pos2;
1481         VM_SAFEPARMCOUNT(1, VM_CL_te_gunshot);
1482
1483         pos = PRVM_G_VECTOR(OFS_PARM0);
1484         CL_FindNonSolidLocation(pos, pos2, 4);
1485         CL_ParticleEffect(EFFECT_TE_GUNSHOT, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1486 }
1487
1488 // #419 void(vector org) te_spike (DP_TE_STANDARDEFFECTBUILTINS)
1489 void VM_CL_te_spike (void)
1490 {
1491         float           *pos;
1492         vec3_t          pos2;
1493         int                     rnd;
1494         VM_SAFEPARMCOUNT(1, VM_CL_te_spike);
1495
1496         pos = PRVM_G_VECTOR(OFS_PARM0);
1497         CL_FindNonSolidLocation(pos, pos2, 4);
1498         CL_ParticleEffect(EFFECT_TE_SPIKE, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1499         if (rand() % 5)                 S_StartSound(-1, 0, cl.sfx_tink1, pos2, 1, 1);
1500         else
1501         {
1502                 rnd = rand() & 3;
1503                 if (rnd == 1)           S_StartSound(-1, 0, cl.sfx_ric1, pos2, 1, 1);
1504                 else if (rnd == 2)      S_StartSound(-1, 0, cl.sfx_ric2, pos2, 1, 1);
1505                 else                            S_StartSound(-1, 0, cl.sfx_ric3, pos2, 1, 1);
1506         }
1507 }
1508
1509 // #420 void(vector org) te_superspike (DP_TE_STANDARDEFFECTBUILTINS)
1510 void VM_CL_te_superspike (void)
1511 {
1512         float           *pos;
1513         vec3_t          pos2;
1514         int                     rnd;
1515         VM_SAFEPARMCOUNT(1, VM_CL_te_superspike);
1516
1517         pos = PRVM_G_VECTOR(OFS_PARM0);
1518         CL_FindNonSolidLocation(pos, pos2, 4);
1519         CL_ParticleEffect(EFFECT_TE_SUPERSPIKE, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1520         if (rand() % 5)                 S_StartSound(-1, 0, cl.sfx_tink1, pos2, 1, 1);
1521         else
1522         {
1523                 rnd = rand() & 3;
1524                 if (rnd == 1)           S_StartSound(-1, 0, cl.sfx_ric1, pos2, 1, 1);
1525                 else if (rnd == 2)      S_StartSound(-1, 0, cl.sfx_ric2, pos2, 1, 1);
1526                 else                            S_StartSound(-1, 0, cl.sfx_ric3, pos2, 1, 1);
1527         }
1528 }
1529
1530 // #421 void(vector org) te_explosion (DP_TE_STANDARDEFFECTBUILTINS)
1531 void VM_CL_te_explosion (void)
1532 {
1533         float           *pos;
1534         vec3_t          pos2;
1535         VM_SAFEPARMCOUNT(1, VM_CL_te_explosion);
1536
1537         pos = PRVM_G_VECTOR(OFS_PARM0);
1538         CL_FindNonSolidLocation(pos, pos2, 10);
1539         CL_ParticleEffect(EFFECT_TE_EXPLOSION, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1540         S_StartSound(-1, 0, cl.sfx_r_exp3, pos2, 1, 1);
1541 }
1542
1543 // #422 void(vector org) te_tarexplosion (DP_TE_STANDARDEFFECTBUILTINS)
1544 void VM_CL_te_tarexplosion (void)
1545 {
1546         float           *pos;
1547         vec3_t          pos2;
1548         VM_SAFEPARMCOUNT(1, VM_CL_te_tarexplosion);
1549
1550         pos = PRVM_G_VECTOR(OFS_PARM0);
1551         CL_FindNonSolidLocation(pos, pos2, 10);
1552         CL_ParticleEffect(EFFECT_TE_TAREXPLOSION, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1553         S_StartSound(-1, 0, cl.sfx_r_exp3, pos2, 1, 1);
1554 }
1555
1556 // #423 void(vector org) te_wizspike (DP_TE_STANDARDEFFECTBUILTINS)
1557 void VM_CL_te_wizspike (void)
1558 {
1559         float           *pos;
1560         vec3_t          pos2;
1561         VM_SAFEPARMCOUNT(1, VM_CL_te_wizspike);
1562
1563         pos = PRVM_G_VECTOR(OFS_PARM0);
1564         CL_FindNonSolidLocation(pos, pos2, 4);
1565         CL_ParticleEffect(EFFECT_TE_WIZSPIKE, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1566         S_StartSound(-1, 0, cl.sfx_wizhit, pos2, 1, 1);
1567 }
1568
1569 // #424 void(vector org) te_knightspike (DP_TE_STANDARDEFFECTBUILTINS)
1570 void VM_CL_te_knightspike (void)
1571 {
1572         float           *pos;
1573         vec3_t          pos2;
1574         VM_SAFEPARMCOUNT(1, VM_CL_te_knightspike);
1575
1576         pos = PRVM_G_VECTOR(OFS_PARM0);
1577         CL_FindNonSolidLocation(pos, pos2, 4);
1578         CL_ParticleEffect(EFFECT_TE_KNIGHTSPIKE, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1579         S_StartSound(-1, 0, cl.sfx_knighthit, pos2, 1, 1);
1580 }
1581
1582 // #425 void(vector org) te_lavasplash (DP_TE_STANDARDEFFECTBUILTINS)
1583 void VM_CL_te_lavasplash (void)
1584 {
1585         VM_SAFEPARMCOUNT(1, VM_CL_te_lavasplash);
1586         CL_ParticleEffect(EFFECT_TE_LAVASPLASH, 1, PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM0), vec3_origin, vec3_origin, NULL, 0);
1587 }
1588
1589 // #426 void(vector org) te_teleport (DP_TE_STANDARDEFFECTBUILTINS)
1590 void VM_CL_te_teleport (void)
1591 {
1592         VM_SAFEPARMCOUNT(1, VM_CL_te_teleport);
1593         CL_ParticleEffect(EFFECT_TE_TELEPORT, 1, PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM0), vec3_origin, vec3_origin, NULL, 0);
1594 }
1595
1596 // #427 void(vector org, float colorstart, float colorlength) te_explosion2 (DP_TE_STANDARDEFFECTBUILTINS)
1597 void VM_CL_te_explosion2 (void)
1598 {
1599         float           *pos;
1600         vec3_t          pos2, color;
1601         matrix4x4_t     tempmatrix;
1602         int                     colorStart, colorLength;
1603         unsigned char           *tempcolor;
1604         VM_SAFEPARMCOUNT(3, VM_CL_te_explosion2);
1605
1606         pos = PRVM_G_VECTOR(OFS_PARM0);
1607         colorStart = (int)PRVM_G_FLOAT(OFS_PARM1);
1608         colorLength = (int)PRVM_G_FLOAT(OFS_PARM2);
1609         CL_FindNonSolidLocation(pos, pos2, 10);
1610         CL_ParticleExplosion2(pos2, colorStart, colorLength);
1611         tempcolor = (unsigned char *)&palette_complete[(rand()%colorLength) + colorStart];
1612         color[0] = tempcolor[0] * (2.0f / 255.0f);
1613         color[1] = tempcolor[1] * (2.0f / 255.0f);
1614         color[2] = tempcolor[2] * (2.0f / 255.0f);
1615         Matrix4x4_CreateTranslate(&tempmatrix, pos2[0], pos2[1], pos2[2]);
1616         CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1617         S_StartSound(-1, 0, cl.sfx_r_exp3, pos2, 1, 1);
1618 }
1619
1620
1621 // #428 void(entity own, vector start, vector end) te_lightning1 (DP_TE_STANDARDEFFECTBUILTINS)
1622 void VM_CL_te_lightning1 (void)
1623 {
1624         VM_SAFEPARMCOUNT(3, VM_CL_te_lightning1);
1625         CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), cl.model_bolt, true);
1626 }
1627
1628 // #429 void(entity own, vector start, vector end) te_lightning2 (DP_TE_STANDARDEFFECTBUILTINS)
1629 void VM_CL_te_lightning2 (void)
1630 {
1631         VM_SAFEPARMCOUNT(3, VM_CL_te_lightning2);
1632         CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), cl.model_bolt2, true);
1633 }
1634
1635 // #430 void(entity own, vector start, vector end) te_lightning3 (DP_TE_STANDARDEFFECTBUILTINS)
1636 void VM_CL_te_lightning3 (void)
1637 {
1638         VM_SAFEPARMCOUNT(3, VM_CL_te_lightning3);
1639         CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), cl.model_bolt3, false);
1640 }
1641
1642 // #431 void(entity own, vector start, vector end) te_beam (DP_TE_STANDARDEFFECTBUILTINS)
1643 void VM_CL_te_beam (void)
1644 {
1645         VM_SAFEPARMCOUNT(3, VM_CL_te_beam);
1646         CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), cl.model_beam, false);
1647 }
1648
1649 // #433 void(vector org) te_plasmaburn (DP_TE_PLASMABURN)
1650 void VM_CL_te_plasmaburn (void)
1651 {
1652         float           *pos;
1653         vec3_t          pos2;
1654         VM_SAFEPARMCOUNT(1, VM_CL_te_plasmaburn);
1655
1656         pos = PRVM_G_VECTOR(OFS_PARM0);
1657         CL_FindNonSolidLocation(pos, pos2, 4);
1658         CL_ParticleEffect(EFFECT_TE_PLASMABURN, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0);
1659 }
1660
1661
1662 //====================================================================
1663 //DP_QC_GETSURFACE
1664
1665 extern void clippointtosurface(model_t *model, msurface_t *surface, vec3_t p, vec3_t out);
1666 static model_t *cl_getmodel(prvm_edict_t *ed)
1667 {
1668         int modelindex;
1669         model_t *model = NULL;
1670         if (!ed || ed->priv.server->free)
1671                 return NULL;
1672         modelindex = (int)ed->fields.client->modelindex;
1673         if(!modelindex)
1674                 return NULL;
1675         if(modelindex<0)
1676         {
1677                 modelindex = -(modelindex+1);
1678                 if(modelindex < MAX_MODELS)
1679                         model = cl.csqc_model_precache[modelindex];
1680         }
1681         else
1682         {
1683                 if(modelindex < MAX_MODELS)
1684                         model = cl.model_precache[modelindex];
1685         }
1686         return model;
1687 }
1688
1689 static msurface_t *cl_getsurface(model_t *model, int surfacenum)
1690 {
1691         if (surfacenum < 0 || surfacenum >= model->nummodelsurfaces)
1692                 return NULL;
1693         return model->data_surfaces + surfacenum + model->firstmodelsurface;
1694 }
1695
1696 // #434 float(entity e, float s) getsurfacenumpoints
1697 void VM_CL_getsurfacenumpoints(void)
1698 {
1699         model_t *model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0));
1700         msurface_t *surface;
1701         // return 0 if no such surface
1702         if (!model || !(surface = cl_getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1))))
1703         {
1704                 PRVM_G_FLOAT(OFS_RETURN) = 0;
1705                 return;
1706         }
1707
1708         // note: this (incorrectly) assumes it is a simple polygon
1709         PRVM_G_FLOAT(OFS_RETURN) = surface->num_vertices;
1710 }
1711
1712 // #435 vector(entity e, float s, float n) getsurfacepoint
1713 void VM_CL_getsurfacepoint(void)
1714 {
1715         prvm_edict_t *ed;
1716         model_t *model;
1717         msurface_t *surface;
1718         int pointnum;
1719         VectorClear(PRVM_G_VECTOR(OFS_RETURN));
1720         ed = PRVM_G_EDICT(OFS_PARM0);
1721         if (!(model = cl_getmodel(ed)) || !(surface = cl_getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1))))
1722                 return;
1723         // note: this (incorrectly) assumes it is a simple polygon
1724         pointnum = (int)PRVM_G_FLOAT(OFS_PARM2);
1725         if (pointnum < 0 || pointnum >= surface->num_vertices)
1726                 return;
1727         // FIXME: implement rotation/scaling
1728         VectorAdd(&(model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.client->origin, PRVM_G_VECTOR(OFS_RETURN));
1729 }
1730
1731 // #436 vector(entity e, float s) getsurfacenormal
1732 void VM_CL_getsurfacenormal(void)
1733 {
1734         model_t *model;
1735         msurface_t *surface;
1736         vec3_t normal;
1737         VectorClear(PRVM_G_VECTOR(OFS_RETURN));
1738         if (!(model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = cl_getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1))))
1739                 return;
1740         // FIXME: implement rotation/scaling
1741         // note: this (incorrectly) assumes it is a simple polygon
1742         // note: this only returns the first triangle, so it doesn't work very
1743         // well for curved surfaces or arbitrary meshes
1744         TriangleNormal((model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex), (model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + 3, (model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + 6, normal);
1745         VectorNormalize(normal);
1746         VectorCopy(normal, PRVM_G_VECTOR(OFS_RETURN));
1747 }
1748
1749 // #437 string(entity e, float s) getsurfacetexture
1750 void VM_CL_getsurfacetexture(void)
1751 {
1752         model_t *model;
1753         msurface_t *surface;
1754         PRVM_G_INT(OFS_RETURN) = 0;
1755         if (!(model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = cl_getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1))))
1756                 return;
1757         PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(surface->texture->name);
1758 }
1759
1760 // #438 float(entity e, vector p) getsurfacenearpoint
1761 void VM_CL_getsurfacenearpoint(void)
1762 {
1763         int surfacenum, best;
1764         vec3_t clipped, p;
1765         vec_t dist, bestdist;
1766         prvm_edict_t *ed;
1767         model_t *model = NULL;
1768         msurface_t *surface;
1769         vec_t *point;
1770         PRVM_G_FLOAT(OFS_RETURN) = -1;
1771         ed = PRVM_G_EDICT(OFS_PARM0);
1772         if(!(model = cl_getmodel(ed)) || !model->num_surfaces)
1773                 return;
1774
1775         // FIXME: implement rotation/scaling
1776         point = PRVM_G_VECTOR(OFS_PARM1);
1777         VectorSubtract(point, ed->fields.client->origin, p);
1778         best = -1;
1779         bestdist = 1000000000;
1780         for (surfacenum = 0;surfacenum < model->nummodelsurfaces;surfacenum++)
1781         {
1782                 surface = model->data_surfaces + surfacenum + model->firstmodelsurface;
1783                 // first see if the nearest point on the surface's box is closer than the previous match
1784                 clipped[0] = bound(surface->mins[0], p[0], surface->maxs[0]) - p[0];
1785                 clipped[1] = bound(surface->mins[1], p[1], surface->maxs[1]) - p[1];
1786                 clipped[2] = bound(surface->mins[2], p[2], surface->maxs[2]) - p[2];
1787                 dist = VectorLength2(clipped);
1788                 if (dist < bestdist)
1789                 {
1790                         // it is, check the nearest point on the actual geometry
1791                         clippointtosurface(model, surface, p, clipped);
1792                         VectorSubtract(clipped, p, clipped);
1793                         dist += VectorLength2(clipped);
1794                         if (dist < bestdist)
1795                         {
1796                                 // that's closer too, store it as the best match
1797                                 best = surfacenum;
1798                                 bestdist = dist;
1799                         }
1800                 }
1801         }
1802         PRVM_G_FLOAT(OFS_RETURN) = best;
1803 }
1804
1805 // #439 vector(entity e, float s, vector p) getsurfaceclippedpoint
1806 void VM_CL_getsurfaceclippedpoint(void)
1807 {
1808         prvm_edict_t *ed;
1809         model_t *model;
1810         msurface_t *surface;
1811         vec3_t p, out;
1812         VectorClear(PRVM_G_VECTOR(OFS_RETURN));
1813         ed = PRVM_G_EDICT(OFS_PARM0);
1814         if (!(model = cl_getmodel(ed)) || !(surface = cl_getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1))))
1815                 return;
1816         // FIXME: implement rotation/scaling
1817         VectorSubtract(PRVM_G_VECTOR(OFS_PARM2), ed->fields.client->origin, p);
1818         clippointtosurface(model, surface, p, out);
1819         // FIXME: implement rotation/scaling
1820         VectorAdd(out, ed->fields.client->origin, PRVM_G_VECTOR(OFS_RETURN));
1821 }
1822
1823 // #443 void(entity e, entity tagentity, string tagname) setattachment
1824 void VM_CL_setattachment (void)
1825 {
1826         prvm_edict_t *e = PRVM_G_EDICT(OFS_PARM0);
1827         prvm_edict_t *tagentity = PRVM_G_EDICT(OFS_PARM1);
1828         const char *tagname = PRVM_G_STRING(OFS_PARM2);
1829         prvm_eval_t *v;
1830         int modelindex;
1831         model_t *model;
1832
1833         if (e == prog->edicts)
1834                 PF_WARNING("setattachment: can not modify world entity\n");
1835         if (e->priv.server->free)
1836                 PF_WARNING("setattachment: can not modify free entity\n");
1837
1838         if (tagentity == NULL)
1839                 tagentity = prog->edicts;
1840
1841         v = PRVM_GETEDICTFIELDVALUE(e, csqc_fieldoff_tag_entity);
1842         if (v)
1843                 v->edict = PRVM_EDICT_TO_PROG(tagentity);
1844
1845         v = PRVM_GETEDICTFIELDVALUE(e, csqc_fieldoff_tag_index);
1846         if (v)
1847                 v->_float = 0;
1848         if (tagentity != NULL && tagentity != prog->edicts && tagname && tagname[0])
1849         {
1850                 modelindex = (int)tagentity->fields.client->modelindex;
1851                 model = NULL;
1852
1853                 if(modelindex)
1854                 {
1855                         if(modelindex<0)
1856                         {
1857                                 modelindex = -(modelindex+1);
1858                                 if(modelindex < MAX_MODELS)
1859                                         model = cl.csqc_model_precache[modelindex];
1860                         }
1861                         else
1862                                 if(modelindex < MAX_MODELS)
1863                                         model = cl.model_precache[modelindex];
1864                 }
1865
1866                 if (model)
1867                 {
1868                         v->_float = Mod_Alias_GetTagIndexForName(model, (int)tagentity->fields.client->skin, tagname);
1869                         if (v->_float == 0)
1870                                 Con_DPrintf("setattachment(edict %i, edict %i, string \"%s\"): tried to find tag named \"%s\" on entity %i (model \"%s\") but could not find it\n", PRVM_NUM_FOR_EDICT(e), PRVM_NUM_FOR_EDICT(tagentity), tagname, tagname, PRVM_NUM_FOR_EDICT(tagentity), model->name);
1871                 }
1872                 else
1873                         Con_DPrintf("setattachment(edict %i, edict %i, string \"%s\"): tried to find tag named \"%s\" on entity %i but it has no model\n", PRVM_NUM_FOR_EDICT(e), PRVM_NUM_FOR_EDICT(tagentity), tagname, tagname, PRVM_NUM_FOR_EDICT(tagentity));
1874         }
1875 }
1876
1877 /////////////////////////////////////////
1878 // DP_MD3_TAGINFO extension coded by VorteX
1879
1880 int CL_GetTagIndex (prvm_edict_t *e, const char *tagname)
1881 {
1882         int i;
1883         model_t *m;
1884
1885         i = (int)e->fields.client->modelindex;
1886
1887         if(!i)
1888                 return -1;
1889         if(i<0)
1890         {
1891                 i = -(i+1);
1892                 if(i >= MAX_MODELS)
1893                         return -1;
1894                 m = cl.csqc_model_precache[i];
1895         }
1896         else
1897                 if(i >= MAX_MODELS)
1898                         return -1;
1899                 else
1900                         m = cl.model_precache[i];
1901
1902         return Mod_Alias_GetTagIndexForName(m, (int)e->fields.client->skin, tagname);
1903 };
1904
1905 // Warnings/errors code:
1906 // 0 - normal (everything all-right)
1907 // 1 - world entity
1908 // 2 - free entity
1909 // 3 - null or non-precached model
1910 // 4 - no tags with requested index
1911 // 5 - runaway loop at attachment chain
1912 extern cvar_t cl_bob;
1913 extern cvar_t cl_bobcycle;
1914 extern cvar_t cl_bobup;
1915 int CL_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
1916 {
1917         prvm_eval_t *val;
1918         int modelindex, reqframe, attachloop, i;
1919         matrix4x4_t entitymatrix, tagmatrix, attachmatrix;
1920         prvm_edict_t *attachent;
1921         model_t *model;
1922
1923         *out = identitymatrix; // warnings and errors return identical matrix
1924
1925         if (ent == prog->edicts)
1926                 return 1;
1927         if (ent->priv.server->free)
1928                 return 2;
1929
1930         modelindex = (int)ent->fields.client->modelindex;
1931
1932         if(!modelindex)
1933                 return 3;
1934         if(modelindex<0)
1935         {
1936                 modelindex = -(modelindex+1);
1937                 if(modelindex >= MAX_MODELS)
1938                         return 3;
1939                 model = cl.csqc_model_precache[modelindex];
1940         }
1941         else
1942                 if(modelindex >= MAX_MODELS)
1943                         return 3;
1944                 else
1945                         model = cl.model_precache[modelindex];
1946
1947         if (ent->fields.client->frame >= 0 && ent->fields.client->frame < model->numframes && model->animscenes)
1948                 reqframe = model->animscenes[(int)ent->fields.client->frame].firstframe;
1949         else
1950                 reqframe = 0; // if model has wrong frame, engine automatically switches to model first frame
1951
1952         // get initial tag matrix
1953         if (tagindex)
1954         {
1955                 int ret = Mod_Alias_GetTagMatrix(model, reqframe, tagindex - 1, &tagmatrix);
1956                 if (ret)
1957                         return ret;
1958         }
1959         else
1960                 tagmatrix = identitymatrix;
1961
1962         if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_entity)) && val->edict)
1963         { // DP_GFX_QUAKE3MODELTAGS, scan all chain and stop on unattached entity
1964                 attachloop = 0;
1965                 do
1966                 {
1967                         attachent = PRVM_EDICT_NUM(val->edict); // to this it entity our entity is attached
1968                         val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_index);
1969
1970                         model = NULL;
1971                         i = (int)attachent->fields.client->modelindex;
1972                         if(i<0)
1973                         {
1974                                 i = -(i+1);
1975                                 if(i < MAX_MODELS)
1976                                         model = cl.csqc_model_precache[i];
1977                         }
1978                         else
1979                                 if(i < MAX_MODELS)
1980                                         model = cl.model_precache[i];
1981
1982                         if (model && val->_float >= 1 && model->animscenes && attachent->fields.client->frame >= 0 && attachent->fields.client->frame < model->numframes)
1983                                 Mod_Alias_GetTagMatrix(model, model->animscenes[(int)attachent->fields.client->frame].firstframe, (int)val->_float - 1, &attachmatrix);
1984                         else
1985                                 attachmatrix = identitymatrix;
1986
1987                         // apply transformation by child entity matrix
1988                         val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
1989                         if (val->_float == 0)
1990                                 val->_float = 1;
1991                         Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
1992                         Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
1993                         out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
1994                         out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
1995                         out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
1996                         Matrix4x4_Copy(&tagmatrix, out);
1997
1998                         // finally transformate by matrix of tag on parent entity
1999                         Matrix4x4_Concat(out, &attachmatrix, &tagmatrix);
2000                         out->m[0][3] = attachmatrix.m[0][3] + attachmatrix.m[0][0]*tagmatrix.m[0][3] + attachmatrix.m[0][1]*tagmatrix.m[1][3] + attachmatrix.m[0][2]*tagmatrix.m[2][3];
2001                         out->m[1][3] = attachmatrix.m[1][3] + attachmatrix.m[1][0]*tagmatrix.m[0][3] + attachmatrix.m[1][1]*tagmatrix.m[1][3] + attachmatrix.m[1][2]*tagmatrix.m[2][3];
2002                         out->m[2][3] = attachmatrix.m[2][3] + attachmatrix.m[2][0]*tagmatrix.m[0][3] + attachmatrix.m[2][1]*tagmatrix.m[1][3] + attachmatrix.m[2][2]*tagmatrix.m[2][3];
2003                         Matrix4x4_Copy(&tagmatrix, out);
2004
2005                         ent = attachent;
2006                         attachloop += 1;
2007                         if (attachloop > 255) // prevent runaway looping
2008                                 return 5;
2009                 }
2010                 while ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_entity)) && val->edict);
2011         }
2012
2013         // normal or RENDER_VIEWMODEL entity (or main parent entity on attach chain)
2014         val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
2015         if (val->_float == 0)
2016                 val->_float = 1;
2017         // Alias models have inverse pitch, bmodels can't have tags, so don't check for modeltype...
2018         Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
2019         Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
2020         out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
2021         out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
2022         out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
2023
2024         if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_renderflags)) && (RF_VIEWMODEL & (int)val->_float))
2025         {// RENDER_VIEWMODEL magic
2026                 Matrix4x4_Copy(&tagmatrix, out);
2027
2028                 val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
2029                 if (val->_float == 0)
2030                         val->_float = 1;
2031
2032                 Matrix4x4_CreateFromQuakeEntity(&entitymatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], val->_float);
2033                 Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
2034                 out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
2035                 out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
2036                 out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
2037
2038                 /*
2039                 // Cl_bob, ported from rendering code
2040                 if (ent->fields.client->health > 0 && cl_bob.value && cl_bobcycle.value)
2041                 {
2042                         double bob, cycle;
2043                         // LordHavoc: this code is *weird*, but not replacable (I think it
2044                         // should be done in QC on the server, but oh well, quake is quake)
2045                         // LordHavoc: figured out bobup: the time at which the sin is at 180
2046                         // degrees (which allows lengthening or squishing the peak or valley)
2047                         cycle = sv.time/cl_bobcycle.value;
2048                         cycle -= (int)cycle;
2049                         if (cycle < cl_bobup.value)
2050                                 cycle = sin(M_PI * cycle / cl_bobup.value);
2051                         else
2052                                 cycle = sin(M_PI + M_PI * (cycle-cl_bobup.value)/(1.0 - cl_bobup.value));
2053                         // bob is proportional to velocity in the xy plane
2054                         // (don't count Z, or jumping messes it up)
2055                         bob = sqrt(ent->fields.client->velocity[0]*ent->fields.client->velocity[0] + ent->fields.client->velocity[1]*ent->fields.client->velocity[1])*cl_bob.value;
2056                         bob = bob*0.3 + bob*0.7*cycle;
2057                         out->m[2][3] += bound(-7, bob, 4);
2058                 }
2059                 */
2060         }
2061         return 0;
2062 }
2063
2064 // #451 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO)
2065 void VM_CL_gettagindex (void)
2066 {
2067         prvm_edict_t *ent = PRVM_G_EDICT(OFS_PARM0);
2068         const char *tag_name = PRVM_G_STRING(OFS_PARM1);
2069         int modelindex, tag_index;
2070
2071         if (ent == prog->edicts)
2072                 PF_WARNING("gettagindex: can't affect world entity\n");
2073         if (ent->priv.server->free)
2074                 PF_WARNING("gettagindex: can't affect free entity\n");
2075
2076         modelindex = (int)ent->fields.client->modelindex;
2077         if(modelindex < 0)
2078                 modelindex = -(modelindex+1);
2079         tag_index = 0;
2080         if (modelindex <= 0 || modelindex >= MAX_MODELS)
2081                 Con_DPrintf("gettagindex(entity #%i): null or non-precached model\n", PRVM_NUM_FOR_EDICT(ent));
2082         else
2083         {
2084                 tag_index = CL_GetTagIndex(ent, tag_name);
2085                 if (tag_index == 0)
2086                         Con_DPrintf("gettagindex(entity #%i): tag \"%s\" not found\n", PRVM_NUM_FOR_EDICT(ent), tag_name);
2087         }
2088         PRVM_G_FLOAT(OFS_RETURN) = tag_index;
2089 }
2090
2091 // #452 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO)
2092 void VM_CL_gettaginfo (void)
2093 {
2094         prvm_edict_t *e = PRVM_G_EDICT(OFS_PARM0);
2095         int tagindex = (int)PRVM_G_FLOAT(OFS_PARM1);
2096         matrix4x4_t tag_matrix;
2097         int returncode;
2098
2099         returncode = CL_GetTagMatrix(&tag_matrix, e, tagindex);
2100         Matrix4x4_ToVectors(&tag_matrix, prog->globals.client->v_forward, prog->globals.client->v_right, prog->globals.client->v_up, PRVM_G_VECTOR(OFS_RETURN));
2101
2102         switch(returncode)
2103         {
2104                 case 1:
2105                         PF_WARNING("gettagindex: can't affect world entity\n");
2106                         break;
2107                 case 2:
2108                         PF_WARNING("gettagindex: can't affect free entity\n");
2109                         break;
2110                 case 3:
2111                         Con_DPrintf("CL_GetTagMatrix(entity #%i): null or non-precached model\n", PRVM_NUM_FOR_EDICT(e));
2112                         break;
2113                 case 4:
2114                         Con_DPrintf("CL_GetTagMatrix(entity #%i): model has no tag with requested index %i\n", PRVM_NUM_FOR_EDICT(e), tagindex);
2115                         break;
2116                 case 5:
2117                         Con_DPrintf("CL_GetTagMatrix(entity #%i): runaway loop at attachment chain\n", PRVM_NUM_FOR_EDICT(e));
2118                         break;
2119         }
2120 }
2121
2122 //=================================================
2123 //[515]: here goes test/unfinished/etc.
2124
2125 //[515]: check if it is what it should be
2126 void VM_WasFreed (void)
2127 {
2128         prvm_edict_t    *e;
2129         VM_SAFEPARMCOUNT(1, VM_WasFreed);
2130
2131         e = PRVM_G_EDICT(OFS_PARM0);
2132         if (!e->priv.required->free || (e->priv.required->free && (e->priv.required->freetime < 2 || (*prog->time - e->priv.required->freetime) > 0.5 )))
2133                 PRVM_G_FLOAT(OFS_RETURN) = false;
2134         else
2135                 PRVM_G_FLOAT(OFS_RETURN) = true;
2136 }
2137
2138 void VM_CL_select_cube (void)
2139 {
2140         int             i;
2141         int             chain_of;
2142         float   *mins2, *maxs2;
2143         prvm_edict_t    *ent, *chain;
2144         vec3_t  mins1, maxs1;
2145
2146         VM_SAFEPARMCOUNT(2, VM_CL_select_cube);
2147
2148         // is the same like !(prog->flag & PRVM_FE_CHAIN) - even if the operator precedence is another
2149         if(!prog->flag & PRVM_FE_CHAIN)
2150                 PRVM_ERROR("VM_findchain: %s doesnt have a chain field !\n", PRVM_NAME);
2151
2152         chain_of = PRVM_ED_FindField("chain")->ofs;
2153         chain = prog->edicts;
2154
2155         mins2 = PRVM_G_VECTOR(OFS_PARM0);
2156         maxs2 = PRVM_G_VECTOR(OFS_PARM1);
2157
2158         ent = PRVM_NEXT_EDICT(prog->edicts);
2159         for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
2160         {
2161                 if (ent->priv.required->free)
2162                         continue;
2163                 VectorCopy(ent->fields.client->origin, mins1);
2164                 VectorAdd(mins1, ent->fields.client->maxs, maxs1);
2165                 VectorAdd(mins1, ent->fields.client->mins, mins1);
2166                 if (mins1[0] > maxs2[0] || mins1[1] > maxs2[1] || mins1[2] > maxs2[2])
2167                         continue;
2168                 if (maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2])
2169                         continue;
2170                 PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
2171                 chain = ent;
2172         }
2173
2174         VM_RETURN_EDICT(chain);
2175 }
2176
2177 void VM_CL_select_super (void)
2178 {
2179 /*      int             i;
2180         int             chain_of;
2181         float   *v[8];
2182         prvm_edict_t    *ent, *chain;
2183         vec3_t  mins1, maxs1;
2184
2185         VM_SAFEPARMCOUNT(8, VM_findchain);
2186         for(i=0;i<8;i++)
2187                 v[i] = PRVM_G_VECTOR(OFS_PARM0+i*3);
2188
2189         // is the same like !(prog->flag & PRVM_FE_CHAIN) - even if the operator precedence is another
2190         if(!prog->flag & PRVM_FE_CHAIN)
2191                 PRVM_ERROR("VM_findchain: %s doesnt have a chain field !\n", PRVM_NAME);
2192
2193         chain_of = PRVM_ED_FindField("chain")->ofs;
2194         chain = prog->edicts;
2195
2196         mins2 = PRVM_G_VECTOR(OFS_PARM0);
2197         maxs2 = PRVM_G_VECTOR(OFS_PARM1);
2198
2199         ent = PRVM_NEXT_EDICT(prog->edicts);
2200         for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
2201         {
2202                 if (ent->priv.required->free)
2203                         continue;
2204                 VectorCopy(ent->fields.client->origin, mins1);
2205                 VectorAdd(mins1, ent->fields.client->maxs, maxs1);
2206                 VectorAdd(mins1, ent->fields.client->mins, mins1);
2207                 if (mins1[0] > maxs2[0] || mins1[1] > maxs2[1] || mins1[2] > maxs2[2])
2208                         continue;
2209                 if (maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2])
2210                         continue;
2211                 PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
2212                 chain = ent;
2213         }
2214
2215         VM_RETURN_EDICT(chain);*/
2216 }
2217
2218 static int Is_Text_Color (char c, char t)
2219 {
2220         int a = 0;
2221         char c2 = c - (c & 128);
2222         char t2 = t - (t & 128);
2223
2224         if(c != '^' && c2 != '^')               return 0;
2225         if(t >= '0' && t <= '9')                a = 1;
2226         if(t2 >= '0' && t2 <= '9')              a = 1;
2227 /*      if(t >= 'A' && t <= 'Z')                a = 2;
2228         if(t2 >= 'A' && t2 <= 'Z')              a = 2;
2229
2230         if(a == 1 && scr_colortext.integer > 0)
2231                 return 1;
2232         if(a == 2 && scr_multifonts.integer > 0)
2233                 return 2;
2234 */
2235         return a;
2236 }
2237
2238 void VM_uncolorstring (void) //#170
2239 {
2240         const char      *in;
2241         char            *out;
2242         int                     k = 0, i = 0;
2243
2244         VM_SAFEPARMCOUNT(1, VM_uncolorstring);
2245         in = PRVM_G_STRING(OFS_PARM0);
2246         if(!in)
2247                 PRVM_ERROR ("VM_uncolorstring: %s: NULL\n", PRVM_NAME);
2248         VM_CheckEmptyString (in);
2249         out = VM_GetTempString();
2250
2251         while (in[k])
2252         {
2253                 if(in[k+1])
2254                 if(Is_Text_Color(in[k], in[k+1]) == 1/* || (in[k] == '&' && in[k+1] == 'r')*/)
2255                 {
2256                         k += 2;
2257                         continue;
2258                 }
2259                 out[i] = in[k];
2260                 ++k;
2261                 ++i;
2262         }
2263 }
2264
2265 void VM_CL_selecttraceline (void)
2266 {
2267         float   *v1, *v2;
2268         int             ent, ignore, csqcents;
2269
2270         v1 = PRVM_G_VECTOR(OFS_PARM0);
2271         v2 = PRVM_G_VECTOR(OFS_PARM1);
2272         ignore = (int)PRVM_G_FLOAT(OFS_PARM2);
2273         csqcents = (int)PRVM_G_FLOAT(OFS_PARM3);
2274         ent = 0;
2275
2276         if((csqcents && ignore > cl.num_csqcentities) || (!csqcents && ignore > cl.num_entities))
2277         {
2278                 Con_Printf("VM_CL_selecttraceline: out of entities\n");
2279                 return;
2280         }
2281         else
2282                 if(csqcents)
2283                         prog->globals.client->trace_fraction = CL_SelectTraceLine(v1, v2, prog->globals.client->trace_endpos, prog->globals.client->trace_plane_normal, &prog->globals.client->trace_ent, &cl.csqcentities[ignore].render, csqcents);
2284                 else
2285                         prog->globals.client->trace_fraction = CL_SelectTraceLine(v1, v2, prog->globals.client->trace_endpos, prog->globals.client->trace_plane_normal, &ent, &cl.entities[ignore].render, csqcents);
2286         PRVM_G_FLOAT(OFS_RETURN) = ent;
2287 }
2288
2289 void VM_charindex (void)
2290 {
2291         const char *s;
2292         s = PRVM_G_STRING(OFS_PARM0);
2293         if(!s)
2294                 return;
2295         if((unsigned)PRVM_G_FLOAT(OFS_PARM1) > strlen(s))
2296                 return;
2297         PRVM_G_FLOAT(OFS_RETURN) = (unsigned char)s[(int)PRVM_G_FLOAT(OFS_PARM1)];
2298 }
2299
2300 //#223 string(float c, ...) chr2str (FTE_STRINGS)
2301 void VM_chr2str (void)
2302 {
2303         char    *t;
2304         int             i;
2305         t = VM_GetTempString();
2306         for(i=0;i<prog->argc;i++)
2307                 t[i] = (unsigned char)PRVM_G_FLOAT(OFS_PARM0+i*3);
2308         t[i] = 0;
2309         PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(t);
2310 }
2311
2312 //#228 float(string s1, string s2, float len) strncmp (FTE_STRINGS)
2313 void VM_strncmp (void)
2314 {
2315         const char *s1, *s2;
2316         VM_SAFEPARMCOUNT(1, VM_strncmp);
2317         s1 = PRVM_G_STRING(OFS_PARM0);
2318         s2 = PRVM_G_STRING(OFS_PARM1);
2319         PRVM_G_FLOAT(OFS_RETURN) = strncmp(s1, s2, (size_t)PRVM_G_FLOAT(OFS_PARM2));
2320 }
2321
2322 //============================================================================
2323 //============================================================================
2324
2325 prvm_builtin_t vm_cl_builtins[] = {
2326 0,  // to be consistent with the old vm
2327 VM_CL_makevectors,                      // #1 void(vector ang) makevectors
2328 VM_CL_setorigin,                        // #2 void(entity e, vector o) setorigin
2329 VM_CL_setmodel,                         // #3 void(entity e, string m) setmodel
2330 VM_CL_setsize,                          // #4 void(entity e, vector min, vector max) setsize
2331 0,
2332 VM_break,                                       // #6 void() break
2333 VM_random,                                      // #7 float() random
2334 VM_CL_sound,                            // #8 void(entity e, float chan, string samp) sound
2335 VM_normalize,                           // #9 vector(vector v) normalize
2336 VM_error,                                       // #10 void(string e) error
2337 VM_objerror,                            // #11 void(string e) objerror
2338 VM_vlen,                                        // #12 float(vector v) vlen
2339 VM_vectoyaw,                            // #13 float(vector v) vectoyaw
2340 VM_CL_spawn,                            // #14 entity() spawn
2341 VM_remove,                                      // #15 void(entity e) remove
2342 VM_CL_traceline,                        // #16 float(vector v1, vector v2, float tryents) traceline
2343 0,
2344 VM_find,                                        // #18 entity(entity start, .string fld, string match) find
2345 VM_CL_precache_sound,           // #19 void(string s) precache_sound
2346 VM_CL_precache_model,           // #20 void(string s) precache_model
2347 0,
2348 VM_CL_findradius,                       // #22 entity(vector org, float rad) findradius
2349 0,
2350 0,
2351 VM_dprint,                                      // #25 void(string s) dprint
2352 VM_ftos,                                        // #26 void(string s) ftos
2353 VM_vtos,                                        // #27 void(string s) vtos
2354 VM_coredump,                            // #28 void() coredump
2355 VM_traceon,                                     // #29 void() traceon
2356 VM_traceoff,                            // #30 void() traceoff
2357 VM_eprint,                                      // #31 void(entity e) eprint
2358 0,
2359 NULL,                                           // #33
2360 VM_CL_droptofloor,                      // #34 float() droptofloor
2361 VM_CL_lightstyle,                       // #35 void(float style, string value) lightstyle
2362 VM_rint,                                        // #36 float(float v) rint
2363 VM_floor,                                       // #37 float(float v) floor
2364 VM_ceil,                                        // #38 float(float v) ceil
2365 NULL,                                           // #39
2366 VM_CL_checkbottom,                      // #40 float(entity e) checkbottom
2367 VM_CL_pointcontents,            // #41 float(vector v) pointcontents
2368 NULL,                                           // #42
2369 VM_fabs,                                        // #43 float(float f) fabs
2370 0,
2371 VM_cvar,                                        // #45 float(string s) cvar
2372 VM_localcmd,                            // #46 void(string s) localcmd
2373 VM_nextent,                                     // #47 entity(entity e) nextent
2374 VM_CL_particle,                         // #48 void(vector o, vector d, float color, float count) particle
2375 VM_CL_changeyaw,                        // #49 void(entity ent, float ideal_yaw, float speed_yaw) ChangeYaw
2376 NULL,                                           // #50
2377 VM_vectoangles,                         // #51 vector(vector v) vectoangles
2378 0,                      // #52 void(float to, float f) WriteByte
2379 0,                      // #53 void(float to, float f) WriteChar
2380 0,                      // #54 void(float to, float f) WriteShort
2381 0,                      // #55 void(float to, float f) WriteLong
2382 0,                      // #56 void(float to, float f) WriteCoord
2383 0,                      // #57 void(float to, float f) WriteAngle
2384 0,                      // #58 void(float to, string s) WriteString
2385 0,
2386 VM_sin,                                         // #60 float(float f) sin (DP_QC_SINCOSSQRTPOW)
2387 VM_cos,                                         // #61 float(float f) cos (DP_QC_SINCOSSQRTPOW)
2388 VM_sqrt,                                        // #62 float(float f) sqrt (DP_QC_SINCOSSQRTPOW)
2389 VM_CL_changepitch,                      // #63 void(entity ent, float ideal_pitch, float speed_pitch) changepitch (DP_QC_CHANGEPITCH)
2390 VM_CL_tracetoss,                        // #64 void(entity e, entity ignore) tracetoss (DP_QC_TRACETOSS)
2391 VM_etos,                                        // #65 string(entity ent) etos (DP_QC_ETOS)
2392 NULL,                                           // #66
2393 0,                                                              // #67
2394 0,                                                              // #68
2395 0,                                                              // #69
2396 0,                                                              // #70
2397 NULL,                                           // #71
2398 VM_cvar_set,                            // #72 void(string var, string val) cvar_set
2399 0,                                                              // #73
2400 VM_CL_ambientsound,                     // #74 void(vector pos, string samp, float vol, float atten) ambientsound
2401 VM_CL_precache_model,           // #75 string(string s) precache_model2
2402 VM_CL_precache_sound,           // #76 string(string s) precache_sound2
2403 0,                                                              // #77
2404 VM_chr,                                         // #78
2405 NULL,                                           // #79
2406 NULL,                                           // #80
2407 VM_stof,                                        // #81 float(string s) stof (FRIK_FILE)
2408 NULL,                                           // #82
2409 NULL,                                           // #83
2410 NULL,                                           // #84
2411 NULL,                                           // #85
2412 NULL,                                           // #86
2413 NULL,                                           // #87
2414 NULL,                                           // #88
2415 NULL,                                           // #89
2416 VM_CL_tracebox,                         // #90 void(vector v1, vector min, vector max, vector v2, float nomonsters, entity forent) tracebox (DP_QC_TRACEBOX)
2417 VM_randomvec,                           // #91 vector() randomvec (DP_QC_RANDOMVEC)
2418 VM_CL_getlight,                         // #92 vector(vector org) getlight (DP_QC_GETLIGHT)
2419 PF_registercvar,                        // #93 float(string name, string value) registercvar (DP_REGISTERCVAR)
2420 VM_min,                                         // #94 float(float a, floats) min (DP_QC_MINMAXBOUND)
2421 VM_max,                                         // #95 float(float a, floats) max (DP_QC_MINMAXBOUND)
2422 VM_bound,                                       // #96 float(float minimum, float val, float maximum) bound (DP_QC_MINMAXBOUND)
2423 VM_pow,                                         // #97 float(float f, float f) pow (DP_QC_SINCOSSQRTPOW)
2424 VM_findfloat,                           // #98 entity(entity start, .float fld, float match) findfloat (DP_QC_FINDFLOAT)
2425 VM_checkextension,                      // #99 float(string s) checkextension (the basis of the extension system)
2426 NULL,                                           // #100
2427 NULL,                                           // #101
2428 NULL,                                           // #102
2429 NULL,                                           // #103
2430 NULL,                                           // #104
2431 NULL,                                           // #105
2432 NULL,                                           // #106
2433 NULL,                                           // #107
2434 NULL,                                           // #108
2435 NULL,                                           // #109
2436 VM_fopen,                                       // #110 float(string filename, float mode) fopen (FRIK_FILE)
2437 VM_fclose,                                      // #111 void(float fhandle) fclose (FRIK_FILE)
2438 VM_fgets,                                       // #112 string(float fhandle) fgets (FRIK_FILE)
2439 VM_fputs,                                       // #113 void(float fhandle, string s) fputs (FRIK_FILE)
2440 VM_strlen,                                      // #114 float(string s) strlen (FRIK_FILE)
2441 VM_strcat,                                      // #115 string(string s1, string s2) strcat (FRIK_FILE)
2442 VM_substring,                           // #116 string(string s, float start, float length) substring (FRIK_FILE)
2443 VM_stov,                                        // #117 vector(string) stov (FRIK_FILE)
2444 VM_strzone,                                     // #118 string(string s) strzone (FRIK_FILE)
2445 VM_strunzone,                           // #119 void(string s) strunzone (FRIK_FILE)
2446
2447 e10, e10, e10, e10, e10, e10, e10, e10,         // #120-199
2448 e10,    //#200-209
2449 0,      //#210
2450 0,      //#211
2451 0,      //#212
2452 0,      //#213
2453 0,      //#214
2454 0,      //#215
2455 0,      //#216
2456 0,      //#217
2457 VM_bitshift,                            //#218 float(float number, float quantity) bitshift (EXT_BITSHIFT)
2458 0,      //#219
2459 0,      //#220
2460 0,      //#221
2461 VM_charindex,                           //#222 float(string str, float ofs) str2chr (FTE_STRINGS)
2462 VM_chr2str,                                     //#223 string(float c, ...) chr2str (FTE_STRINGS)
2463 0,      //#224
2464 0,      //#225
2465 0,      //#226
2466 0,      //#227
2467 VM_strncmp,                                     //#228 float(string s1, string s2, float len) strncmp (FTE_STRINGS)
2468 0,
2469 e10, e10, e10, e10, e10, e10, e10,      // #230-299
2470
2471 //======CSQC start=======//
2472 //3d world (buffer/buffering) operations
2473 VM_R_ClearScene,                        //#300 void() clearscene (EXT_CSQC)
2474 VM_R_AddEntities,                       //#301 void(float mask) addentities (EXT_CSQC)
2475 VM_R_AddEntity,                         //#302 void(entity ent) addentity (EXT_CSQC)
2476 VM_R_SetView,                           //#303 float(float property, ...) setproperty (EXT_CSQC)
2477 VM_R_RenderScene,                       //#304 void() renderscene (EXT_CSQC)
2478 VM_R_AddDynamicLight,           //#305 void(vector org, float radius, vector lightcolours) adddynamiclight (EXT_CSQC)
2479 VM_R_PolygonBegin,                      //#306 void(string texturename, float flag[, float is2d, float lines]) R_BeginPolygon
2480 VM_R_PolygonVertex,                     //#307 void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex
2481 VM_R_PolygonEnd,                        //#308 void() R_EndPolygon
2482 0,                      //#309
2483
2484 //maths stuff that uses the current view settings
2485 VM_CL_unproject,                        //#310 vector (vector v) cs_unproject (EXT_CSQC)
2486 VM_CL_project,                          //#311 vector (vector v) cs_project (EXT_CSQC)
2487 0,                      //#312
2488 0,                      //#313
2489 0,                      //#314
2490
2491 //2d (immediate) operations
2492 VM_drawline,                            //#315 void(float width, vector pos1, vector pos2, float flag) drawline (EXT_CSQC)
2493 VM_iscachedpic,                         //#316 float(string name) iscachedpic (EXT_CSQC)
2494 VM_precache_pic,                        //#317 string(string name, float trywad) precache_pic (EXT_CSQC)
2495 VM_getimagesize,                        //#318 vector(string picname) draw_getimagesize (EXT_CSQC)
2496 VM_freepic,                                     //#319 void(string name) freepic (EXT_CSQC)
2497 VM_drawcharacter,                       //#320 float(vector position, float character, vector scale, vector rgb, float alpha, float flag) drawcharacter (EXT_CSQC)
2498 VM_drawstring,                          //#321 float(vector position, string text, vector scale, vector rgb, float alpha, float flag) drawstring (EXT_CSQC)
2499 VM_drawpic,                                     //#322 float(vector position, string pic, vector size, vector rgb, float alpha, float flag) drawpic (EXT_CSQC)
2500 VM_drawfill,                            //#323 float(vector position, vector size, vector rgb, float alpha, float flag) drawfill (EXT_CSQC)
2501 VM_drawsetcliparea,                     //#324 void(float x, float y, float width, float height) drawsetcliparea
2502 VM_drawresetcliparea,           //#325 void(void) drawresetcliparea
2503 0,                      //#326
2504 0,                      //#327
2505 0,                      //#328
2506 0,                      //#329
2507
2508 VM_CL_getstatf,                         //#330 float(float stnum) getstatf (EXT_CSQC)
2509 VM_CL_getstati,                         //#331 float(float stnum) getstati (EXT_CSQC)
2510 VM_CL_getstats,                         //#332 string(float firststnum) getstats (EXT_CSQC)
2511 VM_CL_setmodelindex,            //#333 void(entity e, float mdlindex) setmodelindex (EXT_CSQC)
2512 VM_CL_modelnameforindex,        //#334 string(float mdlindex) modelnameforindex (EXT_CSQC)
2513 VM_CL_particleeffectnum,        //#335 float(string effectname) particleeffectnum (EXT_CSQC)
2514 VM_CL_trailparticles,           //#336 void(entity ent, float effectnum, vector start, vector end) trailparticles (EXT_CSQC)
2515 VM_CL_pointparticles,           //#337 void(float effectnum, vector origin [, vector dir, float count]) pointparticles (EXT_CSQC)
2516 VM_CL_centerprint,                      //#338 void(string s) cprint (EXT_CSQC)
2517 VM_print,                                       //#339 void(string s) print (EXT_CSQC)
2518 VM_keynumtostring,                      //#340 string(float keynum) keynumtostring (EXT_CSQC)
2519 VM_stringtokeynum,                      //#341 float(string keyname) stringtokeynum (EXT_CSQC)
2520 VM_CL_getkeybind,                       //#342 string(float keynum) getkeybind (EXT_CSQC)
2521 VM_CL_setcursormode,            //#343 void(float usecursor) setcursormode (EXT_CSQC)
2522 VM_getmousepos,                         //#344 vector() getmousepos (EXT_CSQC)
2523 VM_CL_getinputstate,            //#345 float(float framenum) getinputstate (EXT_CSQC)
2524 VM_CL_setsensitivityscale,      //#346 void(float sens) setsensitivityscaler (EXT_CSQC)
2525 VM_CL_runplayerphysics,         //#347 void() runstandardplayerphysics (EXT_CSQC)
2526 VM_CL_getplayerkey,                     //#348 string(float playernum, string keyname) getplayerkeyvalue (EXT_CSQC)
2527 VM_CL_isdemo,                           //#349 float() isdemo (EXT_CSQC)
2528 VM_isserver,                            //#350 float() isserver (EXT_CSQC)
2529 VM_CL_setlistener,                      //#351 void(vector origin, vector forward, vector right, vector up) SetListener (EXT_CSQC)
2530 VM_CL_registercmd,                      //#352 void(string cmdname) registercommand (EXT_CSQC)
2531 VM_WasFreed,                            //#353 float(entity ent) wasfreed (EXT_CSQC) (should be availabe on server too)
2532 VM_CL_playernum,                        //#354 float() playernum
2533 VM_CL_onground,                         //#355 float() cl_onground (EXT_CSQC)
2534 VM_charindex,                           //#356 float(string s, float num) charindex
2535 VM_CL_selecttraceline,          //#357 float(vector start, vector end, float ignore, float csqcents) selecttraceline
2536 0,                      //#358
2537 0,                      //#359
2538 VM_CL_ReadByte,                         //#360 float() readbyte (EXT_CSQC)
2539 VM_CL_ReadChar,                         //#361 float() readchar (EXT_CSQC)
2540 VM_CL_ReadShort,                        //#362 float() readshort (EXT_CSQC)
2541 VM_CL_ReadLong,                         //#363 float() readlong (EXT_CSQC)
2542 VM_CL_ReadCoord,                        //#364 float() readcoord (EXT_CSQC)
2543 VM_CL_ReadAngle,                        //#365 float() readangle (EXT_CSQC)
2544 VM_CL_ReadString,                       //#366 string() readstring (EXT_CSQC)
2545 VM_CL_ReadFloat,                        //#367 float() readfloat (EXT_CSQC)
2546 0,                      //#368
2547 0,                      //#369
2548 0,                      //#370
2549 0,                      //#371
2550 0,                      //#372
2551 0,                      //#373
2552 0,                      //#374
2553 0,                      //#375
2554 0,                      //#376
2555 0,                      //#377
2556 0,                      //#378
2557 0,                      //#379
2558 0,                      //#380
2559 0,                      //#381
2560 0,                      //#382
2561 0,                      //#383
2562 0,                      //#384
2563 0,                      //#385
2564 0,                      //#386
2565 0,                      //#387
2566 0,                      //#388
2567 0,                      //#389
2568 0,                      //#390
2569 0,                      //#391
2570 0,                      //#392
2571 0,                      //#393
2572 0,                      //#394
2573 0,                      //#395
2574 0,                      //#396
2575 0,                      //#397
2576 0,                      //#398
2577 0,                      //#399
2578 //=========CSQC end========//
2579
2580 VM_copyentity,                                  // #400 void(entity from, entity to) copyentity (DP_QC_COPYENTITY)
2581 0,
2582 VM_findchain,                                   // #402 entity(.string fld, string match) findchain (DP_QC_FINDCHAIN)
2583 VM_findchainfloat,                              // #403 entity(.float fld, float match) findchainfloat (DP_QC_FINDCHAINFLOAT)
2584 VM_CL_effect,                                   // #404 void(vector org, string modelname, float startframe, float endframe, float framerate) effect (DP_SV_EFFECT)
2585 VM_CL_te_blood,                                 // #405 void(vector org, vector velocity, float howmany) te_blood (DP_TE_BLOOD)
2586 VM_CL_te_bloodshower,                   // #406 void(vector mincorner, vector maxcorner, float explosionspeed, float howmany) te_bloodshower (DP_TE_BLOODSHOWER)
2587 VM_CL_te_explosionrgb,                  // #407 void(vector org, vector color) te_explosionrgb (DP_TE_EXPLOSIONRGB)
2588 VM_CL_te_particlecube,                  // #408 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color, float gravityflag, float randomveljitter) te_particlecube (DP_TE_PARTICLECUBE)
2589 VM_CL_te_particlerain,                  // #409 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color) te_particlerain (DP_TE_PARTICLERAIN)
2590 VM_CL_te_particlesnow,                  // #410 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color) te_particlesnow (DP_TE_PARTICLESNOW)
2591 VM_CL_te_spark,                                 // #411 void(vector org, vector vel, float howmany) te_spark (DP_TE_SPARK)
2592 VM_CL_te_gunshotquad,                   // #412 void(vector org) te_gunshotquad (DP_QUADEFFECTS1)
2593 VM_CL_te_spikequad,                             // #413 void(vector org) te_spikequad (DP_QUADEFFECTS1)
2594 VM_CL_te_superspikequad,                // #414 void(vector org) te_superspikequad (DP_QUADEFFECTS1)
2595 VM_CL_te_explosionquad,                 // #415 void(vector org) te_explosionquad (DP_QUADEFFECTS1)
2596 VM_CL_te_smallflash,                    // #416 void(vector org) te_smallflash (DP_TE_SMALLFLASH)
2597 VM_CL_te_customflash,                   // #417 void(vector org, float radius, float lifetime, vector color) te_customflash (DP_TE_CUSTOMFLASH)
2598 VM_CL_te_gunshot,                               // #418 void(vector org) te_gunshot (DP_TE_STANDARDEFFECTBUILTINS)
2599 VM_CL_te_spike,                                 // #419 void(vector org) te_spike (DP_TE_STANDARDEFFECTBUILTINS)
2600 VM_CL_te_superspike,                    // #420 void(vector org) te_superspike (DP_TE_STANDARDEFFECTBUILTINS)
2601 VM_CL_te_explosion,                             // #421 void(vector org) te_explosion (DP_TE_STANDARDEFFECTBUILTINS)
2602 VM_CL_te_tarexplosion,                  // #422 void(vector org) te_tarexplosion (DP_TE_STANDARDEFFECTBUILTINS)
2603 VM_CL_te_wizspike,                              // #423 void(vector org) te_wizspike (DP_TE_STANDARDEFFECTBUILTINS)
2604 VM_CL_te_knightspike,                   // #424 void(vector org) te_knightspike (DP_TE_STANDARDEFFECTBUILTINS)
2605 VM_CL_te_lavasplash,                    // #425 void(vector org) te_lavasplash (DP_TE_STANDARDEFFECTBUILTINS)
2606 VM_CL_te_teleport,                              // #426 void(vector org) te_teleport (DP_TE_STANDARDEFFECTBUILTINS)
2607 VM_CL_te_explosion2,                    // #427 void(vector org, float colorstart, float colorlength) te_explosion2 (DP_TE_STANDARDEFFECTBUILTINS)
2608 VM_CL_te_lightning1,                    // #428 void(entity own, vector start, vector end) te_lightning1 (DP_TE_STANDARDEFFECTBUILTINS)
2609 VM_CL_te_lightning2,                    // #429 void(entity own, vector start, vector end) te_lightning2 (DP_TE_STANDARDEFFECTBUILTINS)
2610 VM_CL_te_lightning3,                    // #430 void(entity own, vector start, vector end) te_lightning3 (DP_TE_STANDARDEFFECTBUILTINS)
2611 VM_CL_te_beam,                                  // #431 void(entity own, vector start, vector end) te_beam (DP_TE_STANDARDEFFECTBUILTINS)
2612 VM_vectorvectors,                               // #432 void(vector dir) vectorvectors (DP_QC_VECTORVECTORS)
2613 VM_CL_te_plasmaburn,                    // #433 void(vector org) te_plasmaburn (DP_TE_PLASMABURN)
2614 VM_CL_getsurfacenumpoints,              // #434 float(entity e, float s) getsurfacenumpoints (DP_QC_GETSURFACE)
2615 VM_CL_getsurfacepoint,                  // #435 vector(entity e, float s, float n) getsurfacepoint (DP_QC_GETSURFACE)
2616 VM_CL_getsurfacenormal,                 // #436 vector(entity e, float s) getsurfacenormal (DP_QC_GETSURFACE)
2617 VM_CL_getsurfacetexture,                // #437 string(entity e, float s) getsurfacetexture (DP_QC_GETSURFACE)
2618 VM_CL_getsurfacenearpoint,              // #438 float(entity e, vector p) getsurfacenearpoint (DP_QC_GETSURFACE)
2619 VM_CL_getsurfaceclippedpoint,   // #439 vector(entity e, float s, vector p) getsurfaceclippedpoint (DP_QC_GETSURFACE)
2620 0,                                                                      // #440
2621 VM_tokenize,                            // #441 float(string s) tokenize (KRIMZON_SV_PARSECLIENTCOMMAND)
2622 VM_argv,                                        // #442 string(float n) argv (KRIMZON_SV_PARSECLIENTCOMMAND)
2623 VM_CL_setattachment,            // #443 void(entity e, entity tagentity, string tagname) setattachment (DP_GFX_QUAKE3MODELTAGS)
2624 VM_search_begin,                        // #444 float(string pattern, float caseinsensitive, float quiet) search_begin (DP_FS_SEARCH)
2625 VM_search_end,                          // #445 void(float handle) search_end (DP_FS_SEARCH)
2626 VM_search_getsize,                      // #446 float(float handle) search_getsize (DP_FS_SEARCH)
2627 VM_search_getfilename,          // #447 string(float handle, float num) search_getfilename (DP_FS_SEARCH)
2628 VM_cvar_string,                         // #448 string(string s) cvar_string (DP_QC_CVAR_STRING)
2629 VM_findflags,                           // #449 entity(entity start, .float fld, float match) findflags (DP_QC_FINDFLAGS)
2630 VM_findchainflags,                      // #450 entity(.float fld, float match) findchainflags (DP_QC_FINDCHAINFLAGS)
2631 VM_CL_gettagindex,                      // #451 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO)
2632 VM_CL_gettaginfo,                       // #452 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO)
2633 0,                                                              // #453
2634 0,                                                              // #454
2635 0,                                                              // #455
2636 NULL,                                           // #456
2637 NULL,                                           // #457
2638 NULL,                                           // #458
2639 NULL,                                           // #459
2640 VM_buf_create,                          // #460 float() buf_create (DP_QC_STRINGBUFFERS)
2641 VM_buf_del,                                     // #461 void(float bufhandle) buf_del (DP_QC_STRINGBUFFERS)
2642 VM_buf_getsize,                         // #462 float(float bufhandle) buf_getsize (DP_QC_STRINGBUFFERS)
2643 VM_buf_copy,                            // #463 void(float bufhandle_from, float bufhandle_to) buf_copy (DP_QC_STRINGBUFFERS)
2644 VM_buf_sort,                            // #464 void(float bufhandle, float sortpower, float backward) buf_sort (DP_QC_STRINGBUFFERS)
2645 VM_buf_implode,                         // #465 string(float bufhandle, string glue) buf_implode (DP_QC_STRINGBUFFERS)
2646 VM_bufstr_get,                          // #466 string(float bufhandle, float string_index) bufstr_get (DP_QC_STRINGBUFFERS)
2647 VM_bufstr_set,                          // #467 void(float bufhandle, float string_index, string str) bufstr_set (DP_QC_STRINGBUFFERS)
2648 VM_bufstr_add,                          // #468 float(float bufhandle, string str, float order) bufstr_add (DP_QC_STRINGBUFFERS)
2649 VM_bufstr_free,                         // #469 void(float bufhandle, float string_index) bufstr_free (DP_QC_STRINGBUFFERS)
2650 e10, e10, e10                   // #470-499 (LordHavoc)
2651 };
2652
2653 const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t);
2654
2655 void VM_CL_Cmd_Init(void)
2656 {
2657 }
2658
2659 void VM_CL_Cmd_Reset(void)
2660 {
2661 }
2662