2 // Basically every vm builtin cmd should be in here.
3 // All 3 builtin and extension lists can be found here
4 // cause large (I think they will) parts are from pr_cmds the same copyright like in pr_cmds
10 // LordHavoc: changed this to NOT use a return statement, so that it can be used in functions that must return a value
11 void VM_Warning(const char *fmt, ...)
14 char msg[MAX_INPUTLINE];
17 dpvsnprintf(msg,sizeof(msg),fmt,argptr);
21 // TODO: either add a cvar/cmd to control the state dumping or replace some of the calls with Con_Printf [9/13/2006 Black]
26 //============================================================================
29 // TODO DONE: move vm_files and vm_fssearchlist to prvm_prog_t struct
30 // TODO: move vm_files and vm_fssearchlist back [9/13/2006 Black]
31 // TODO: (move vm_files and vm_fssearchlist to prvm_prog_t struct again) [2007-01-23 LordHavoc]
32 // TODO: will this war ever end? [2007-01-23 LordHavoc]
34 void VM_CheckEmptyString (const char *s)
37 PRVM_ERROR ("%s: Bad string", PRVM_NAME);
40 //============================================================================
43 void VM_VarString(int first, char *out, int outlength)
49 outend = out + outlength - 1;
50 for (i = first;i < prog->argc && out < outend;i++)
52 s = PRVM_G_STRING((OFS_PARM0+i*3));
53 while (out < outend && *s)
63 returns true if the extension is supported by the server
65 checkextension(extensionname)
69 // kind of helper function
70 static qboolean checkextension(const char *name)
74 len = (int)strlen(name);
76 for (e = prog->extensionstring;*e;e++)
83 while (*e && *e != ' ')
85 if ((e - start) == len && !strncasecmp(start, name, len))
91 void VM_checkextension (void)
93 VM_SAFEPARMCOUNT(1,VM_checkextension);
95 PRVM_G_FLOAT(OFS_RETURN) = checkextension(PRVM_G_STRING(OFS_PARM0));
102 This is a TERMINAL error, which will kill off the entire prog.
111 char string[VM_STRINGTEMP_LENGTH];
113 VM_VarString(0, string, sizeof(string));
114 Con_Printf("======%s ERROR in %s:\n%s\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string);
115 if (prog->globaloffsets.self >= 0)
117 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
121 PRVM_ERROR ("%s: Program error in function %s:\n%s\nTip: read above for entity information\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string);
128 Dumps out self, then an error message. The program is aborted and self is
129 removed, but the level can continue.
134 void VM_objerror (void)
137 char string[VM_STRINGTEMP_LENGTH];
139 VM_VarString(0, string, sizeof(string));
140 Con_Printf("======OBJECT ERROR======\n"); // , PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string); // or include them? FIXME
141 if (prog->globaloffsets.self >= 0)
143 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
149 // objerror has to display the object fields -> else call
150 PRVM_ERROR ("VM_objecterror: self not defined !");
151 Con_Printf("%s OBJECT ERROR in %s:\n%s\nTip: read above for entity information\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string);
165 char string[VM_STRINGTEMP_LENGTH];
167 VM_VarString(0, string, sizeof(string));
175 broadcast print to everyone on server
180 void VM_bprint (void)
182 char string[VM_STRINGTEMP_LENGTH];
186 VM_Warning("VM_bprint: game is not server(%s) !\n", PRVM_NAME);
190 VM_VarString(0, string, sizeof(string));
191 SV_BroadcastPrint(string);
196 VM_sprint (menu & client but only if server.active == true)
198 single print to a specific client
200 sprint(float clientnum,...[string])
203 void VM_sprint (void)
207 char string[VM_STRINGTEMP_LENGTH];
209 //find client for this entity
210 clientnum = (int)PRVM_G_FLOAT(OFS_PARM0);
211 if (!sv.active || clientnum < 0 || clientnum >= svs.maxclients || !svs.clients[clientnum].active)
213 VM_Warning("VM_sprint: %s: invalid client or server is not active !\n", PRVM_NAME);
217 client = svs.clients + clientnum;
218 if (!client->netconnection)
221 VM_VarString(1, string, sizeof(string));
222 MSG_WriteChar(&client->netconnection->message,svc_print);
223 MSG_WriteString(&client->netconnection->message, string);
230 single print to the screen
232 centerprint(clientent, value)
235 void VM_centerprint (void)
237 char string[VM_STRINGTEMP_LENGTH];
239 VM_VarString(0, string, sizeof(string));
240 SCR_CenterPrint(string);
247 vector normalize(vector)
250 void VM_normalize (void)
256 VM_SAFEPARMCOUNT(1,VM_normalize);
258 value1 = PRVM_G_VECTOR(OFS_PARM0);
260 f = VectorLength2(value1);
264 VectorScale(value1, f, newvalue);
267 VectorClear(newvalue);
269 VectorCopy (newvalue, PRVM_G_VECTOR(OFS_RETURN));
281 VM_SAFEPARMCOUNT(1,VM_vlen);
282 PRVM_G_FLOAT(OFS_RETURN) = VectorLength(PRVM_G_VECTOR(OFS_PARM0));
289 float vectoyaw(vector)
292 void VM_vectoyaw (void)
297 VM_SAFEPARMCOUNT(1,VM_vectoyaw);
299 value1 = PRVM_G_VECTOR(OFS_PARM0);
301 if (value1[1] == 0 && value1[0] == 0)
305 yaw = (int) (atan2(value1[1], value1[0]) * 180 / M_PI);
310 PRVM_G_FLOAT(OFS_RETURN) = yaw;
318 vector vectoangles(vector)
321 void VM_vectoangles (void)
327 VM_SAFEPARMCOUNT(1,VM_vectoangles);
329 value1 = PRVM_G_VECTOR(OFS_PARM0);
331 if (value1[1] == 0 && value1[0] == 0)
341 // LordHavoc: optimized a bit
344 yaw = (atan2(value1[1], value1[0]) * 180 / M_PI);
348 else if (value1[1] > 0)
353 forward = sqrt(value1[0]*value1[0] + value1[1]*value1[1]);
354 pitch = (atan2(value1[2], forward) * 180 / M_PI);
359 PRVM_G_FLOAT(OFS_RETURN+0) = pitch;
360 PRVM_G_FLOAT(OFS_RETURN+1) = yaw;
361 PRVM_G_FLOAT(OFS_RETURN+2) = 0;
368 Returns a number from 0<= num < 1
373 void VM_random (void)
375 VM_SAFEPARMCOUNT(0,VM_random);
377 PRVM_G_FLOAT(OFS_RETURN) = lhrandom(0, 1);
384 Each entity can have eight independant sound sources, like voice,
387 Channel 0 is an auto-allocate channel, the others override anything
388 already running on that entity/channel pair.
390 An attenuation of 0 will play full volume everywhere in the level.
391 Larger attenuations will drop off.
400 prvm_edict_t *entity;
404 entity = PRVM_G_EDICT(OFS_PARM0);
405 channel = PRVM_G_FLOAT(OFS_PARM1);
406 sample = PRVM_G_STRING(OFS_PARM2);
407 volume = PRVM_G_FLOAT(OFS_PARM3) * 255;
408 attenuation = PRVM_G_FLOAT(OFS_PARM4);
410 if (volume < 0 || volume > 255)
411 Host_Error ("SV_StartSound: volume = %i", volume);
413 if (attenuation < 0 || attenuation > 4)
414 Host_Error ("SV_StartSound: attenuation = %f", attenuation);
416 if (channel < 0 || channel > 7)
417 Host_Error ("SV_StartSound: channel = %i", channel);
419 SV_StartSound (entity, channel, sample, volume, attenuation);
427 localsound(string sample)
430 void VM_localsound(void)
434 VM_SAFEPARMCOUNT(1,VM_localsound);
436 s = PRVM_G_STRING(OFS_PARM0);
438 if(!S_LocalSound (s))
440 PRVM_G_FLOAT(OFS_RETURN) = -4;
441 VM_Warning("VM_localsound: Failed to play %s for %s !\n", s, PRVM_NAME);
445 PRVM_G_FLOAT(OFS_RETURN) = 1;
457 PRVM_ERROR ("%s: break statement", PRVM_NAME);
460 //============================================================================
466 Sends text over to the client's execution buffer
468 [localcmd (string, ...) or]
472 void VM_localcmd (void)
474 char string[VM_STRINGTEMP_LENGTH];
475 VM_VarString(0, string, sizeof(string));
476 Cbuf_AddText(string);
488 VM_SAFEPARMCOUNT(1,VM_cvar);
490 PRVM_G_FLOAT(OFS_RETURN) = Cvar_VariableValue(PRVM_G_STRING(OFS_PARM0));
497 const string VM_cvar_string (string)
500 void VM_cvar_string(void)
503 VM_SAFEPARMCOUNT(1,VM_cvar_string);
505 name = PRVM_G_STRING(OFS_PARM0);
507 VM_CheckEmptyString(name);
509 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Cvar_VariableString(name));
514 ========================
517 const string VM_cvar_defstring (string)
518 ========================
520 void VM_cvar_defstring (void)
523 VM_SAFEPARMCOUNT(1,VM_cvar_string);
525 name = PRVM_G_STRING(OFS_PARM0);
527 VM_CheckEmptyString(name);
529 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Cvar_VariableDefString(name));
535 void cvar_set (string,string)
538 void VM_cvar_set (void)
540 VM_SAFEPARMCOUNT(2,VM_cvar_set);
542 Cvar_Set(PRVM_G_STRING(OFS_PARM0), PRVM_G_STRING(OFS_PARM1));
552 void VM_dprint (void)
554 char string[VM_STRINGTEMP_LENGTH];
555 if (developer.integer)
557 VM_VarString(0, string, sizeof(string));
559 Con_Printf("%s", string);
561 Con_Printf("%s: %s", PRVM_NAME, string);
579 VM_SAFEPARMCOUNT(1, VM_ftos);
581 v = PRVM_G_FLOAT(OFS_PARM0);
583 if ((float)((int)v) == v)
584 sprintf(s, "%i", (int)v);
587 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(s);
602 VM_SAFEPARMCOUNT(1,VM_fabs);
604 v = PRVM_G_FLOAT(OFS_PARM0);
605 PRVM_G_FLOAT(OFS_RETURN) = fabs(v);
620 VM_SAFEPARMCOUNT(1,VM_vtos);
622 sprintf (s, "'%5.1f %5.1f %5.1f'", PRVM_G_VECTOR(OFS_PARM0)[0], PRVM_G_VECTOR(OFS_PARM0)[1], PRVM_G_VECTOR(OFS_PARM0)[2]);
623 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(s);
638 VM_SAFEPARMCOUNT(1, VM_etos);
640 sprintf (s, "entity %i", PRVM_G_EDICTNUM(OFS_PARM0));
641 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(s);
648 float stof(...[string])
653 char string[VM_STRINGTEMP_LENGTH];
654 VM_VarString(0, string, sizeof(string));
655 PRVM_G_FLOAT(OFS_RETURN) = atof(string);
659 ========================
663 ========================
667 VM_SAFEPARMCOUNT(1, VM_itof);
668 PRVM_G_FLOAT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
672 ========================
675 entity ftoe(float num)
676 ========================
681 VM_SAFEPARMCOUNT(1, VM_ftoe);
683 ent = (int)PRVM_G_FLOAT(OFS_PARM0);
684 if (ent < 0 || ent >= MAX_EDICTS || PRVM_PROG_TO_EDICT(ent)->priv.required->free)
685 ent = 0; // return world instead of a free or invalid entity
687 PRVM_G_INT(OFS_RETURN) = ent;
694 string strftime(float uselocaltime, string[, string ...])
697 void VM_strftime(void)
701 char fmt[VM_STRINGTEMP_LENGTH];
702 char result[VM_STRINGTEMP_LENGTH];
703 VM_VarString(0, fmt, sizeof(fmt));
705 if (PRVM_G_FLOAT(OFS_PARM0))
711 PRVM_G_FLOAT(OFS_RETURN) = 0;
714 strftime(result, sizeof(result), fmt, tm);
715 PRVM_G_FLOAT(OFS_RETURN) = PRVM_SetTempString(result);
729 prog->xfunction->builtinsprofile += 20;
730 ed = PRVM_ED_Alloc();
742 void VM_remove (void)
745 prog->xfunction->builtinsprofile += 20;
747 VM_SAFEPARMCOUNT(1, VM_remove);
749 ed = PRVM_G_EDICT(OFS_PARM0);
750 if( PRVM_NUM_FOR_EDICT(ed) <= prog->reserved_edicts )
752 if (developer.integer >= 1)
753 VM_Warning( "VM_remove: tried to remove the null entity or a reserved entity!\n" );
755 else if( ed->priv.required->free )
757 if (developer.integer >= 1)
758 VM_Warning( "VM_remove: tried to remove an already freed entity!\n" );
762 // if (ed == prog->edicts)
763 // PRVM_ERROR ("remove: tried to remove world");
764 // if (PRVM_NUM_FOR_EDICT(ed) <= sv.maxclients)
765 // Host_Error("remove: tried to remove a client");
772 entity find(entity start, .string field, string match)
783 VM_SAFEPARMCOUNT(3,VM_find);
785 e = PRVM_G_EDICTNUM(OFS_PARM0);
786 f = PRVM_G_INT(OFS_PARM1);
787 s = PRVM_G_STRING(OFS_PARM2);
789 // LordHavoc: apparently BloodMage does a find(world, weaponmodel, "") and
790 // expects it to find all the monsters, so we must be careful to support
793 for (e++ ; e < prog->num_edicts ; e++)
795 prog->xfunction->builtinsprofile++;
796 ed = PRVM_EDICT_NUM(e);
797 if (ed->priv.required->free)
799 t = PRVM_E_STRING(ed,f);
809 VM_RETURN_EDICT(prog->edicts);
816 entity findfloat(entity start, .float field, float match)
817 entity findentity(entity start, .entity field, entity match)
820 // LordHavoc: added this for searching float, int, and entity reference fields
821 void VM_findfloat (void)
828 VM_SAFEPARMCOUNT(3,VM_findfloat);
830 e = PRVM_G_EDICTNUM(OFS_PARM0);
831 f = PRVM_G_INT(OFS_PARM1);
832 s = PRVM_G_FLOAT(OFS_PARM2);
834 for (e++ ; e < prog->num_edicts ; e++)
836 prog->xfunction->builtinsprofile++;
837 ed = PRVM_EDICT_NUM(e);
838 if (ed->priv.required->free)
840 if (PRVM_E_FLOAT(ed,f) == s)
847 VM_RETURN_EDICT(prog->edicts);
854 entity findchain(.string field, string match)
857 // chained search for strings in entity fields
858 // entity(.string field, string match) findchain = #402;
859 void VM_findchain (void)
864 prvm_edict_t *ent, *chain;
866 VM_SAFEPARMCOUNT(2,VM_findchain);
868 if (prog->fieldoffsets.chain < 0)
869 PRVM_ERROR("VM_findchain: %s doesnt have a chain field !", PRVM_NAME);
871 chain = prog->edicts;
873 f = PRVM_G_INT(OFS_PARM0);
874 s = PRVM_G_STRING(OFS_PARM1);
876 // LordHavoc: apparently BloodMage does a find(world, weaponmodel, "") and
877 // expects it to find all the monsters, so we must be careful to support
880 ent = PRVM_NEXT_EDICT(prog->edicts);
881 for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
883 prog->xfunction->builtinsprofile++;
884 if (ent->priv.required->free)
886 t = PRVM_E_STRING(ent,f);
892 PRVM_EDICTFIELDVALUE(ent,prog->fieldoffsets.chain)->edict = PRVM_NUM_FOR_EDICT(chain);
896 VM_RETURN_EDICT(chain);
903 entity findchainfloat(.string field, float match)
904 entity findchainentity(.string field, entity match)
907 // LordHavoc: chained search for float, int, and entity reference fields
908 // entity(.string field, float match) findchainfloat = #403;
909 void VM_findchainfloat (void)
914 prvm_edict_t *ent, *chain;
916 VM_SAFEPARMCOUNT(2, VM_findchainfloat);
918 if (prog->fieldoffsets.chain < 0)
919 PRVM_ERROR("VM_findchainfloat: %s doesnt have a chain field !", PRVM_NAME);
921 chain = (prvm_edict_t *)prog->edicts;
923 f = PRVM_G_INT(OFS_PARM0);
924 s = PRVM_G_FLOAT(OFS_PARM1);
926 ent = PRVM_NEXT_EDICT(prog->edicts);
927 for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
929 prog->xfunction->builtinsprofile++;
930 if (ent->priv.required->free)
932 if (PRVM_E_FLOAT(ent,f) != s)
935 PRVM_EDICTFIELDVALUE(ent,prog->fieldoffsets.chain)->edict = PRVM_EDICT_TO_PROG(chain);
939 VM_RETURN_EDICT(chain);
943 ========================
946 entity findflags(entity start, .float field, float match)
947 ========================
949 // LordHavoc: search for flags in float fields
950 void VM_findflags (void)
957 VM_SAFEPARMCOUNT(3, VM_findflags);
960 e = PRVM_G_EDICTNUM(OFS_PARM0);
961 f = PRVM_G_INT(OFS_PARM1);
962 s = (int)PRVM_G_FLOAT(OFS_PARM2);
964 for (e++ ; e < prog->num_edicts ; e++)
966 prog->xfunction->builtinsprofile++;
967 ed = PRVM_EDICT_NUM(e);
968 if (ed->priv.required->free)
970 if (!PRVM_E_FLOAT(ed,f))
972 if ((int)PRVM_E_FLOAT(ed,f) & s)
979 VM_RETURN_EDICT(prog->edicts);
983 ========================
986 entity findchainflags(.float field, float match)
987 ========================
989 // LordHavoc: chained search for flags in float fields
990 void VM_findchainflags (void)
995 prvm_edict_t *ent, *chain;
997 VM_SAFEPARMCOUNT(2, VM_findchainflags);
999 if (prog->fieldoffsets.chain < 0)
1000 PRVM_ERROR("VM_findchainflags: %s doesnt have a chain field !", PRVM_NAME);
1002 chain = (prvm_edict_t *)prog->edicts;
1004 f = PRVM_G_INT(OFS_PARM0);
1005 s = (int)PRVM_G_FLOAT(OFS_PARM1);
1007 ent = PRVM_NEXT_EDICT(prog->edicts);
1008 for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
1010 prog->xfunction->builtinsprofile++;
1011 if (ent->priv.required->free)
1013 if (!PRVM_E_FLOAT(ent,f))
1015 if (!((int)PRVM_E_FLOAT(ent,f) & s))
1018 PRVM_EDICTFIELDVALUE(ent,prog->fieldoffsets.chain)->edict = PRVM_EDICT_TO_PROG(chain);
1022 VM_RETURN_EDICT(chain);
1032 void VM_coredump (void)
1034 VM_SAFEPARMCOUNT(0,VM_coredump);
1036 Cbuf_AddText("prvm_edicts ");
1037 Cbuf_AddText(PRVM_NAME);
1048 void PRVM_StackTrace(void);
1049 void VM_stackdump (void)
1051 VM_SAFEPARMCOUNT(0, VM_stackdump);
1066 VM_SAFEPARMCOUNT(0, VM_crash);
1068 PRVM_ERROR("Crash called by %s",PRVM_NAME);
1078 void VM_traceon (void)
1080 VM_SAFEPARMCOUNT(0,VM_traceon);
1092 void VM_traceoff (void)
1094 VM_SAFEPARMCOUNT(0,VM_traceoff);
1096 prog->trace = false;
1106 void VM_eprint (void)
1108 VM_SAFEPARMCOUNT(1,VM_eprint);
1110 PRVM_ED_PrintNum (PRVM_G_EDICTNUM(OFS_PARM0));
1123 VM_SAFEPARMCOUNT(1,VM_rint);
1125 f = PRVM_G_FLOAT(OFS_PARM0);
1127 PRVM_G_FLOAT(OFS_RETURN) = floor(f + 0.5);
1129 PRVM_G_FLOAT(OFS_RETURN) = ceil(f - 0.5);
1139 void VM_floor (void)
1141 VM_SAFEPARMCOUNT(1,VM_floor);
1143 PRVM_G_FLOAT(OFS_RETURN) = floor(PRVM_G_FLOAT(OFS_PARM0));
1155 VM_SAFEPARMCOUNT(1,VM_ceil);
1157 PRVM_G_FLOAT(OFS_RETURN) = ceil(PRVM_G_FLOAT(OFS_PARM0));
1165 entity nextent(entity)
1168 void VM_nextent (void)
1173 i = PRVM_G_EDICTNUM(OFS_PARM0);
1176 prog->xfunction->builtinsprofile++;
1178 if (i == prog->num_edicts)
1180 VM_RETURN_EDICT(prog->edicts);
1183 ent = PRVM_EDICT_NUM(i);
1184 if (!ent->priv.required->free)
1186 VM_RETURN_EDICT(ent);
1192 //=============================================================================
1199 changelevel(string map)
1202 void VM_changelevel (void)
1204 VM_SAFEPARMCOUNT(1, VM_changelevel);
1208 VM_Warning("VM_changelevel: game is not server (%s)\n", PRVM_NAME);
1212 // make sure we don't issue two changelevels
1213 if (svs.changelevel_issued)
1215 svs.changelevel_issued = true;
1217 Cbuf_AddText (va("changelevel %s\n",PRVM_G_STRING(OFS_PARM0)));
1229 VM_SAFEPARMCOUNT(1,VM_sin);
1230 PRVM_G_FLOAT(OFS_RETURN) = sin(PRVM_G_FLOAT(OFS_PARM0));
1241 VM_SAFEPARMCOUNT(1,VM_cos);
1242 PRVM_G_FLOAT(OFS_RETURN) = cos(PRVM_G_FLOAT(OFS_PARM0));
1254 VM_SAFEPARMCOUNT(1,VM_sqrt);
1255 PRVM_G_FLOAT(OFS_RETURN) = sqrt(PRVM_G_FLOAT(OFS_PARM0));
1267 VM_SAFEPARMCOUNT(1,VM_asin);
1268 PRVM_G_FLOAT(OFS_RETURN) = asin(PRVM_G_FLOAT(OFS_PARM0));
1279 VM_SAFEPARMCOUNT(1,VM_acos);
1280 PRVM_G_FLOAT(OFS_RETURN) = acos(PRVM_G_FLOAT(OFS_PARM0));
1291 VM_SAFEPARMCOUNT(1,VM_atan);
1292 PRVM_G_FLOAT(OFS_RETURN) = atan(PRVM_G_FLOAT(OFS_PARM0));
1298 float atan2(float,float)
1301 void VM_atan2 (void)
1303 VM_SAFEPARMCOUNT(2,VM_atan2);
1304 PRVM_G_FLOAT(OFS_RETURN) = atan2(PRVM_G_FLOAT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1));
1315 VM_SAFEPARMCOUNT(1,VM_tan);
1316 PRVM_G_FLOAT(OFS_RETURN) = tan(PRVM_G_FLOAT(OFS_PARM0));
1323 Returns a vector of length < 1 and > 0
1328 void VM_randomvec (void)
1333 VM_SAFEPARMCOUNT(0, VM_randomvec);
1338 temp[0] = (rand()&32767) * (2.0 / 32767.0) - 1.0;
1339 temp[1] = (rand()&32767) * (2.0 / 32767.0) - 1.0;
1340 temp[2] = (rand()&32767) * (2.0 / 32767.0) - 1.0;
1342 while (DotProduct(temp, temp) >= 1);
1343 VectorCopy (temp, PRVM_G_VECTOR(OFS_RETURN));
1346 temp[0] = (rand()&32767) * (2.0 / 32767.0) - 1.0;
1347 temp[1] = (rand()&32767) * (2.0 / 32767.0) - 1.0;
1348 temp[2] = (rand()&32767) * (2.0 / 32767.0) - 1.0;
1349 // length returned always > 0
1350 length = (rand()&32766 + 1) * (1.0 / 32767.0) / VectorLength(temp);
1351 VectorScale(temp,length, temp);*/
1352 //VectorCopy(temp, PRVM_G_VECTOR(OFS_RETURN));
1355 //=============================================================================
1361 float registercvar (string name, string value, float flags)
1364 void VM_registercvar (void)
1366 const char *name, *value;
1369 VM_SAFEPARMCOUNT(3,VM_registercvar);
1371 name = PRVM_G_STRING(OFS_PARM0);
1372 value = PRVM_G_STRING(OFS_PARM1);
1373 flags = (int)PRVM_G_FLOAT(OFS_PARM2);
1374 PRVM_G_FLOAT(OFS_RETURN) = 0;
1376 if(flags > CVAR_MAXFLAGSVAL)
1379 // first check to see if it has already been defined
1380 if (Cvar_FindVar (name))
1383 // check for overlap with a command
1384 if (Cmd_Exists (name))
1386 VM_Warning("VM_registercvar: %s is a command\n", name);
1390 Cvar_Get(name, value, flags);
1392 PRVM_G_FLOAT(OFS_RETURN) = 1; // success
1399 returns the minimum of two supplied floats
1401 float min(float a, float b, ...[float])
1406 // LordHavoc: 3+ argument enhancement suggested by FrikaC
1407 if (prog->argc == 2)
1408 PRVM_G_FLOAT(OFS_RETURN) = min(PRVM_G_FLOAT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1));
1409 else if (prog->argc >= 3)
1412 float f = PRVM_G_FLOAT(OFS_PARM0);
1413 for (i = 1;i < prog->argc;i++)
1414 if (PRVM_G_FLOAT((OFS_PARM0+i*3)) < f)
1415 f = PRVM_G_FLOAT((OFS_PARM0+i*3));
1416 PRVM_G_FLOAT(OFS_RETURN) = f;
1419 PRVM_ERROR("VM_min: %s must supply at least 2 floats", PRVM_NAME);
1426 returns the maximum of two supplied floats
1428 float max(float a, float b, ...[float])
1433 // LordHavoc: 3+ argument enhancement suggested by FrikaC
1434 if (prog->argc == 2)
1435 PRVM_G_FLOAT(OFS_RETURN) = max(PRVM_G_FLOAT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1));
1436 else if (prog->argc >= 3)
1439 float f = PRVM_G_FLOAT(OFS_PARM0);
1440 for (i = 1;i < prog->argc;i++)
1441 if (PRVM_G_FLOAT((OFS_PARM0+i*3)) > f)
1442 f = PRVM_G_FLOAT((OFS_PARM0+i*3));
1443 PRVM_G_FLOAT(OFS_RETURN) = f;
1446 PRVM_ERROR("VM_max: %s must supply at least 2 floats", PRVM_NAME);
1453 returns number bounded by supplied range
1455 float bound(float min, float value, float max)
1458 void VM_bound (void)
1460 VM_SAFEPARMCOUNT(3,VM_bound);
1461 PRVM_G_FLOAT(OFS_RETURN) = bound(PRVM_G_FLOAT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1), PRVM_G_FLOAT(OFS_PARM2));
1468 returns a raised to power b
1470 float pow(float a, float b)
1475 VM_SAFEPARMCOUNT(2,VM_pow);
1476 PRVM_G_FLOAT(OFS_RETURN) = pow(PRVM_G_FLOAT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1));
1483 copies data from one entity to another
1485 copyentity(entity src, entity dst)
1488 void VM_copyentity (void)
1490 prvm_edict_t *in, *out;
1491 VM_SAFEPARMCOUNT(2,VM_copyentity);
1492 in = PRVM_G_EDICT(OFS_PARM0);
1493 out = PRVM_G_EDICT(OFS_PARM1);
1494 memcpy(out->fields.vp, in->fields.vp, prog->progs->entityfields * 4);
1497 void VM_Files_Init(void)
1500 for (i = 0;i < PRVM_MAX_OPENFILES;i++)
1501 prog->openfiles[i] = NULL;
1504 void VM_Files_CloseAll(void)
1507 for (i = 0;i < PRVM_MAX_OPENFILES;i++)
1509 if (prog->openfiles[i])
1510 FS_Close(prog->openfiles[i]);
1511 prog->openfiles[i] = NULL;
1515 qfile_t *VM_GetFileHandle( int index )
1517 if (index < 0 || index >= PRVM_MAX_OPENFILES)
1519 Con_Printf("VM_GetFileHandle: invalid file handle %i used in %s\n", index, PRVM_NAME);
1522 if (prog->openfiles[index] == NULL)
1524 Con_Printf("VM_GetFileHandle: no such file handle %i (or file has been closed) in %s\n", index, PRVM_NAME);
1527 return prog->openfiles[index];
1534 float fopen(string filename, float mode)
1537 // float(string filename, float mode) fopen = #110;
1538 // opens a file inside quake/gamedir/data/ (mode is FILE_READ, FILE_APPEND, or FILE_WRITE),
1539 // returns fhandle >= 0 if successful, or fhandle < 0 if unable to open file for any reason
1543 const char *modestring, *filename;
1545 VM_SAFEPARMCOUNT(2,VM_fopen);
1547 for (filenum = 0;filenum < PRVM_MAX_OPENFILES;filenum++)
1548 if (prog->openfiles[filenum] == NULL)
1550 if (filenum >= PRVM_MAX_OPENFILES)
1552 PRVM_G_FLOAT(OFS_RETURN) = -2;
1553 VM_Warning("VM_fopen: %s ran out of file handles (%i)\n", PRVM_NAME, PRVM_MAX_OPENFILES);
1556 mode = (int)PRVM_G_FLOAT(OFS_PARM1);
1559 case 0: // FILE_READ
1562 case 1: // FILE_APPEND
1565 case 2: // FILE_WRITE
1569 PRVM_G_FLOAT(OFS_RETURN) = -3;
1570 VM_Warning("VM_fopen: %s: no such mode %i (valid: 0 = read, 1 = append, 2 = write)\n", PRVM_NAME, mode);
1573 filename = PRVM_G_STRING(OFS_PARM0);
1575 prog->openfiles[filenum] = FS_Open(va("data/%s", filename), modestring, false, false);
1576 if (prog->openfiles[filenum] == NULL && mode == 0)
1577 prog->openfiles[filenum] = FS_Open(va("%s", filename), modestring, false, false);
1579 if (prog->openfiles[filenum] == NULL)
1581 PRVM_G_FLOAT(OFS_RETURN) = -1;
1582 if (developer.integer >= 100)
1583 VM_Warning("VM_fopen: %s: %s mode %s failed\n", PRVM_NAME, filename, modestring);
1587 PRVM_G_FLOAT(OFS_RETURN) = filenum;
1588 if (developer.integer >= 100)
1589 Con_Printf("VM_fopen: %s: %s mode %s opened as #%i\n", PRVM_NAME, filename, modestring, filenum);
1597 fclose(float fhandle)
1600 //void(float fhandle) fclose = #111; // closes a file
1601 void VM_fclose(void)
1605 VM_SAFEPARMCOUNT(1,VM_fclose);
1607 filenum = (int)PRVM_G_FLOAT(OFS_PARM0);
1608 if (filenum < 0 || filenum >= PRVM_MAX_OPENFILES)
1610 VM_Warning("VM_fclose: invalid file handle %i used in %s\n", filenum, PRVM_NAME);
1613 if (prog->openfiles[filenum] == NULL)
1615 VM_Warning("VM_fclose: no such file handle %i (or file has been closed) in %s\n", filenum, PRVM_NAME);
1618 FS_Close(prog->openfiles[filenum]);
1619 prog->openfiles[filenum] = NULL;
1620 if (developer.integer >= 100)
1621 Con_Printf("VM_fclose: %s: #%i closed\n", PRVM_NAME, filenum);
1628 string fgets(float fhandle)
1631 //string(float fhandle) fgets = #112; // reads a line of text from the file and returns as a tempstring
1635 char string[VM_STRINGTEMP_LENGTH];
1638 VM_SAFEPARMCOUNT(1,VM_fgets);
1640 filenum = (int)PRVM_G_FLOAT(OFS_PARM0);
1641 if (filenum < 0 || filenum >= PRVM_MAX_OPENFILES)
1643 VM_Warning("VM_fgets: invalid file handle %i used in %s\n", filenum, PRVM_NAME);
1646 if (prog->openfiles[filenum] == NULL)
1648 VM_Warning("VM_fgets: no such file handle %i (or file has been closed) in %s\n", filenum, PRVM_NAME);
1654 c = FS_Getc(prog->openfiles[filenum]);
1655 if (c == '\r' || c == '\n' || c < 0)
1657 if (end < VM_STRINGTEMP_LENGTH - 1)
1661 // remove \n following \r
1664 c = FS_Getc(prog->openfiles[filenum]);
1666 FS_UnGetc(prog->openfiles[filenum], (unsigned char)c);
1668 if (developer.integer >= 100)
1669 Con_Printf("fgets: %s: %s\n", PRVM_NAME, string);
1671 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(string);
1673 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
1680 fputs(float fhandle, string s)
1683 //void(float fhandle, string s) fputs = #113; // writes a line of text to the end of the file
1687 char string[VM_STRINGTEMP_LENGTH];
1690 VM_SAFEPARMCOUNT(2,VM_fputs);
1692 filenum = (int)PRVM_G_FLOAT(OFS_PARM0);
1693 if (filenum < 0 || filenum >= PRVM_MAX_OPENFILES)
1695 VM_Warning("VM_fputs: invalid file handle %i used in %s\n", filenum, PRVM_NAME);
1698 if (prog->openfiles[filenum] == NULL)
1700 VM_Warning("VM_fputs: no such file handle %i (or file has been closed) in %s\n", filenum, PRVM_NAME);
1703 VM_VarString(1, string, sizeof(string));
1704 if ((stringlength = (int)strlen(string)))
1705 FS_Write(prog->openfiles[filenum], string, stringlength);
1706 if (developer.integer >= 100)
1707 Con_Printf("fputs: %s: %s\n", PRVM_NAME, string);
1714 float strlen(string s)
1717 //float(string s) strlen = #114; // returns how many characters are in a string
1718 void VM_strlen(void)
1720 VM_SAFEPARMCOUNT(1,VM_strlen);
1722 PRVM_G_FLOAT(OFS_RETURN) = strlen(PRVM_G_STRING(OFS_PARM0));
1725 // DRESK - Decolorized String
1730 string strdecolorize(string s)
1733 // string (string s) strdecolorize = #472; // returns the passed in string with color codes stripped
1734 void VM_strdecolorize(void)
1736 char szNewString[VM_STRINGTEMP_LENGTH];
1737 const char *szString;
1748 VM_SAFEPARMCOUNT(1,VM_strdecolorize);
1749 szString = PRVM_G_STRING(OFS_PARM0);
1752 { // Traverse through String
1753 if( szString[nPos] == '\n' || szString[nPos] == '\r' || szString[nPos] <= 0)
1754 { // String End Found
1755 szNewString[nFillPos++] = szString[nPos];
1759 if( szString[nPos] == STRING_COLOR_TAG)
1760 { // Color Code Located
1761 if( szString[nPos + 1] == STRING_COLOR_TAG)
1762 { // Valid Characters to Include
1763 szNewString[nFillPos++] = szString[nPos];
1765 szNewString[nFillPos++] = szString[nPos];
1768 if( szString[nPos + 1] >= '0' && szString[nPos + 1] <= '9' )
1769 { // Color Code Found; Increment Position
1773 { // Unknown Color Code; Include
1774 szNewString[nFillPos++] = szString[nPos];
1779 // Include Character
1780 szNewString[nFillPos++] = szString[nPos];
1782 // Increment Position
1786 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(szNewString);
1789 // DRESK - String Length (not counting color codes)
1794 float strlennocol(string s)
1797 // float(string s) strlennocol = #471; // returns how many characters are in a string not including color codes
1798 // For example, ^2Dresk returns a length of 5
1799 void VM_strlennocol(void)
1801 const char *szString;
1809 VM_SAFEPARMCOUNT(1,VM_strlennocol);
1811 szString = PRVM_G_STRING(OFS_PARM0);
1814 { // Count Characters
1815 // SV_BroadcastPrintf("Position '%d'; Character '%c'; Length '%d'\n", nPos, szString[nPos], nCnt);
1817 if( szString[nPos] == '\n' || szString[nPos] == '\r' || szString[nPos] <= 0)
1818 { // String End Found
1819 // SV_BroadcastPrintf("Found End of String at '%d'\n", nPos);
1823 if( szString[nPos] == STRING_COLOR_TAG)
1824 { // Color Code Located
1825 if( szString[nPos + 1] == STRING_COLOR_TAG)
1826 { // Increment Length; Skip Color Code
1831 if( szString[nPos + 1] >= '0' && szString[nPos + 1] <= '9' )
1832 { // Color Code Found; Increment Position
1833 // SV_BroadcastPrintf("Found Color Codes at '%d'\n", nPos);
1837 { // Unknown Color Code; Increment Length!
1843 // Increment String Length
1846 // Increment Position
1849 PRVM_G_FLOAT(OFS_RETURN) = nCnt;
1856 string strcat(string,string,...[string])
1859 //string(string s1, string s2) strcat = #115;
1860 // concatenates two strings (for example "abc", "def" would return "abcdef")
1861 // and returns as a tempstring
1862 void VM_strcat(void)
1864 char s[VM_STRINGTEMP_LENGTH];
1867 PRVM_ERROR("VM_strcat wrong parameter count (min. 1 expected ) !");
1869 VM_VarString(0, s, sizeof(s));
1870 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(s);
1877 string substring(string s, float start, float length)
1880 // string(string s, float start, float length) substring = #116;
1881 // returns a section of a string as a tempstring
1882 void VM_substring(void)
1884 int i, start, length;
1886 char string[VM_STRINGTEMP_LENGTH];
1888 VM_SAFEPARMCOUNT(3,VM_substring);
1890 s = PRVM_G_STRING(OFS_PARM0);
1891 start = (int)PRVM_G_FLOAT(OFS_PARM1);
1892 length = (int)PRVM_G_FLOAT(OFS_PARM2);
1893 for (i = 0;i < start && *s;i++, s++);
1894 for (i = 0;i < (int)sizeof(string) - 1 && *s && i < length;i++, s++)
1897 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(string);
1904 vector stov(string s)
1907 //vector(string s) stov = #117; // returns vector value from a string
1910 char string[VM_STRINGTEMP_LENGTH];
1912 VM_SAFEPARMCOUNT(1,VM_stov);
1914 VM_VarString(0, string, sizeof(string));
1915 Math_atov(string, PRVM_G_VECTOR(OFS_RETURN));
1922 string strzone(string s)
1925 //string(string s, ...) strzone = #118; // makes a copy of a string into the string zone and returns it, this is often used to keep around a tempstring for longer periods of time (tempstrings are replaced often)
1926 void VM_strzone(void)
1929 char string[VM_STRINGTEMP_LENGTH];
1932 VM_SAFEPARMCOUNT(1,VM_strzone);
1934 VM_VarString(0, string, sizeof(string));
1935 alloclen = strlen(string) + 1;
1936 PRVM_G_INT(OFS_RETURN) = PRVM_AllocString(alloclen, &out);
1937 memcpy(out, string, alloclen);
1947 //void(string s) strunzone = #119; // removes a copy of a string from the string zone (you can not use that string again or it may crash!!!)
1948 void VM_strunzone(void)
1950 VM_SAFEPARMCOUNT(1,VM_strunzone);
1951 PRVM_FreeString(PRVM_G_INT(OFS_PARM0));
1956 VM_command (used by client and menu)
1958 clientcommand(float client, string s) (for client and menu)
1961 //void(entity e, string s) clientcommand = #440; // executes a command string as if it came from the specified client
1962 //this function originally written by KrimZon, made shorter by LordHavoc
1963 void VM_clcommand (void)
1965 client_t *temp_client;
1968 VM_SAFEPARMCOUNT(2,VM_clcommand);
1970 i = (int)PRVM_G_FLOAT(OFS_PARM0);
1971 if (!sv.active || i < 0 || i >= svs.maxclients || !svs.clients[i].active)
1973 VM_Warning("VM_clientcommand: %s: invalid client/server is not active !\n", PRVM_NAME);
1977 temp_client = host_client;
1978 host_client = svs.clients + i;
1979 Cmd_ExecuteString (PRVM_G_STRING(OFS_PARM1), src_client);
1980 host_client = temp_client;
1988 float tokenize(string s)
1991 //float(string s) tokenize = #441; // takes apart a string into individal words (access them with argv), returns how many
1992 //this function originally written by KrimZon, made shorter by LordHavoc
1993 //20040203: rewritten by LordHavoc (no longer uses allocations)
1996 void VM_tokenize (void)
2001 char tokenbuf[MAX_INPUTLINE];
2005 VM_SAFEPARMCOUNT(1,VM_tokenize);
2007 p = PRVM_G_STRING(OFS_PARM0);
2010 while(COM_ParseToken(&p, false))
2012 if (num_tokens >= (int)(sizeof(tokens)/sizeof(tokens[0])))
2015 tokenlen = strlen(com_token) + 1;
2016 if (pos + tokenlen > sizeof(tokenbuf))
2018 tokens[num_tokens++] = PRVM_SetEngineString(tokenbuf + pos);
2019 memcpy(tokenbuf + pos, com_token, tokenlen);
2022 tokens[num_tokens++] = PRVM_SetTempString(com_token);
2026 PRVM_G_FLOAT(OFS_RETURN) = num_tokens;
2029 //string(float n) argv = #442; // returns a word from the tokenized string (returns nothing for an invalid index)
2030 //this function originally written by KrimZon, made shorter by LordHavoc
2035 VM_SAFEPARMCOUNT(1,VM_argv);
2037 token_num = (int)PRVM_G_FLOAT(OFS_PARM0);
2039 if (token_num >= 0 && token_num < num_tokens)
2040 PRVM_G_INT(OFS_RETURN) = tokens[token_num];
2042 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
2052 void VM_isserver(void)
2054 VM_SAFEPARMCOUNT(0,VM_serverstate);
2056 PRVM_G_FLOAT(OFS_RETURN) = sv.active;
2066 void VM_clientcount(void)
2068 VM_SAFEPARMCOUNT(0,VM_clientcount);
2070 PRVM_G_FLOAT(OFS_RETURN) = svs.maxclients;
2080 void VM_clientstate(void)
2082 VM_SAFEPARMCOUNT(0,VM_clientstate);
2084 PRVM_G_FLOAT(OFS_RETURN) = cls.state;
2091 float getostype(void)
2093 */ // not used at the moment -> not included in the common list
2094 void VM_getostype(void)
2096 VM_SAFEPARMCOUNT(0,VM_getostype);
2101 OS_MAC - not supported
2105 PRVM_G_FLOAT(OFS_RETURN) = 0;
2106 #elif defined(MACOSX)
2107 PRVM_G_FLOAT(OFS_RETURN) = 2;
2109 PRVM_G_FLOAT(OFS_RETURN) = 1;
2117 vector getmousepos()
2120 void VM_getmousepos(void)
2123 VM_SAFEPARMCOUNT(0,VM_getmousepos);
2125 PRVM_G_VECTOR(OFS_RETURN)[0] = in_mouse_x * vid_conwidth.integer / vid.width;
2126 PRVM_G_VECTOR(OFS_RETURN)[1] = in_mouse_y * vid_conheight.integer / vid.height;
2127 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
2137 void VM_gettime(void)
2139 VM_SAFEPARMCOUNT(0,VM_gettime);
2141 PRVM_G_FLOAT(OFS_RETURN) = (float) realtime;
2148 loadfromdata(string data)
2151 void VM_loadfromdata(void)
2153 VM_SAFEPARMCOUNT(1,VM_loadentsfromfile);
2155 PRVM_ED_LoadFromFile(PRVM_G_STRING(OFS_PARM0));
2159 ========================
2162 parseentitydata(entity ent, string data)
2163 ========================
2165 void VM_parseentitydata(void)
2170 VM_SAFEPARMCOUNT(2, VM_parseentitydata);
2172 // get edict and test it
2173 ent = PRVM_G_EDICT(OFS_PARM0);
2174 if (ent->priv.required->free)
2175 PRVM_ERROR ("VM_parseentitydata: %s: Can only set already spawned entities (entity %i is free)!", PRVM_NAME, PRVM_NUM_FOR_EDICT(ent));
2177 data = PRVM_G_STRING(OFS_PARM1);
2179 // parse the opening brace
2180 if (!COM_ParseTokenConsole(&data) || com_token[0] != '{' )
2181 PRVM_ERROR ("VM_parseentitydata: %s: Couldn't parse entity data:\n%s", PRVM_NAME, data );
2183 PRVM_ED_ParseEdict (data, ent);
2190 loadfromfile(string file)
2193 void VM_loadfromfile(void)
2195 const char *filename;
2198 VM_SAFEPARMCOUNT(1,VM_loadfromfile);
2200 filename = PRVM_G_STRING(OFS_PARM0);
2201 if (FS_CheckNastyPath(filename, false))
2203 PRVM_G_FLOAT(OFS_RETURN) = -4;
2204 VM_Warning("VM_loadfromfile: %s dangerous or non-portable filename \"%s\" not allowed. (contains : or \\ or begins with .. or /)\n", PRVM_NAME, filename);
2208 // not conform with VM_fopen
2209 data = (char *)FS_LoadFile(filename, tempmempool, false, NULL);
2211 PRVM_G_FLOAT(OFS_RETURN) = -1;
2213 PRVM_ED_LoadFromFile(data);
2224 float mod(float val, float m)
2227 void VM_modulo(void)
2230 VM_SAFEPARMCOUNT(2,VM_module);
2232 val = (int) PRVM_G_FLOAT(OFS_PARM0);
2233 m = (int) PRVM_G_FLOAT(OFS_PARM1);
2235 PRVM_G_FLOAT(OFS_RETURN) = (float) (val % m);
2238 void VM_Search_Init(void)
2241 for (i = 0;i < PRVM_MAX_OPENSEARCHES;i++)
2242 prog->opensearches[i] = NULL;
2245 void VM_Search_Reset(void)
2248 // reset the fssearch list
2249 for(i = 0; i < PRVM_MAX_OPENSEARCHES; i++)
2251 if(prog->opensearches[i])
2252 FS_FreeSearch(prog->opensearches[i]);
2253 prog->opensearches[i] = NULL;
2261 float search_begin(string pattern, float caseinsensitive, float quiet)
2264 void VM_search_begin(void)
2267 const char *pattern;
2268 int caseinsens, quiet;
2270 VM_SAFEPARMCOUNT(3, VM_search_begin);
2272 pattern = PRVM_G_STRING(OFS_PARM0);
2274 VM_CheckEmptyString(pattern);
2276 caseinsens = (int)PRVM_G_FLOAT(OFS_PARM1);
2277 quiet = (int)PRVM_G_FLOAT(OFS_PARM2);
2279 for(handle = 0; handle < PRVM_MAX_OPENSEARCHES; handle++)
2280 if(!prog->opensearches[handle])
2283 if(handle >= PRVM_MAX_OPENSEARCHES)
2285 PRVM_G_FLOAT(OFS_RETURN) = -2;
2286 VM_Warning("VM_search_begin: %s ran out of search handles (%i)\n", PRVM_NAME, PRVM_MAX_OPENSEARCHES);
2290 if(!(prog->opensearches[handle] = FS_Search(pattern,caseinsens, quiet)))
2291 PRVM_G_FLOAT(OFS_RETURN) = -1;
2293 PRVM_G_FLOAT(OFS_RETURN) = handle;
2300 void search_end(float handle)
2303 void VM_search_end(void)
2306 VM_SAFEPARMCOUNT(1, VM_search_end);
2308 handle = (int)PRVM_G_FLOAT(OFS_PARM0);
2310 if(handle < 0 || handle >= PRVM_MAX_OPENSEARCHES)
2312 VM_Warning("VM_search_end: invalid handle %i used in %s\n", handle, PRVM_NAME);
2315 if(prog->opensearches[handle] == NULL)
2317 VM_Warning("VM_search_end: no such handle %i in %s\n", handle, PRVM_NAME);
2321 FS_FreeSearch(prog->opensearches[handle]);
2322 prog->opensearches[handle] = NULL;
2329 float search_getsize(float handle)
2332 void VM_search_getsize(void)
2335 VM_SAFEPARMCOUNT(1, VM_M_search_getsize);
2337 handle = (int)PRVM_G_FLOAT(OFS_PARM0);
2339 if(handle < 0 || handle >= PRVM_MAX_OPENSEARCHES)
2341 VM_Warning("VM_search_getsize: invalid handle %i used in %s\n", handle, PRVM_NAME);
2344 if(prog->opensearches[handle] == NULL)
2346 VM_Warning("VM_search_getsize: no such handle %i in %s\n", handle, PRVM_NAME);
2350 PRVM_G_FLOAT(OFS_RETURN) = prog->opensearches[handle]->numfilenames;
2355 VM_search_getfilename
2357 string search_getfilename(float handle, float num)
2360 void VM_search_getfilename(void)
2362 int handle, filenum;
2363 VM_SAFEPARMCOUNT(2, VM_search_getfilename);
2365 handle = (int)PRVM_G_FLOAT(OFS_PARM0);
2366 filenum = (int)PRVM_G_FLOAT(OFS_PARM1);
2368 if(handle < 0 || handle >= PRVM_MAX_OPENSEARCHES)
2370 VM_Warning("VM_search_getfilename: invalid handle %i used in %s\n", handle, PRVM_NAME);
2373 if(prog->opensearches[handle] == NULL)
2375 VM_Warning("VM_search_getfilename: no such handle %i in %s\n", handle, PRVM_NAME);
2378 if(filenum < 0 || filenum >= prog->opensearches[handle]->numfilenames)
2380 VM_Warning("VM_search_getfilename: invalid filenum %i in %s\n", filenum, PRVM_NAME);
2384 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog->opensearches[handle]->filenames[filenum]);
2391 string chr(float ascii)
2397 VM_SAFEPARMCOUNT(1, VM_chr);
2399 tmp[0] = (unsigned char) PRVM_G_FLOAT(OFS_PARM0);
2402 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(tmp);
2405 //=============================================================================
2406 // Draw builtins (client & menu)
2412 float iscachedpic(string pic)
2415 void VM_iscachedpic(void)
2417 VM_SAFEPARMCOUNT(1,VM_iscachedpic);
2419 // drawq hasnt such a function, thus always return true
2420 PRVM_G_FLOAT(OFS_RETURN) = false;
2427 string precache_pic(string pic)
2430 void VM_precache_pic(void)
2434 VM_SAFEPARMCOUNT(1, VM_precache_pic);
2436 s = PRVM_G_STRING(OFS_PARM0);
2437 PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
2438 VM_CheckEmptyString (s);
2440 // AK Draw_CachePic is supposed to always return a valid pointer
2441 if( Draw_CachePic(s, false)->tex == r_texture_notexture )
2442 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
2452 void VM_freepic(void)
2456 VM_SAFEPARMCOUNT(1,VM_freepic);
2458 s = PRVM_G_STRING(OFS_PARM0);
2459 VM_CheckEmptyString (s);
2468 float drawcharacter(vector position, float character, vector scale, vector rgb, float alpha, float flag)
2471 void VM_drawcharacter(void)
2473 float *pos,*scale,*rgb;
2476 VM_SAFEPARMCOUNT(6,VM_drawcharacter);
2478 character = (char) PRVM_G_FLOAT(OFS_PARM1);
2481 PRVM_G_FLOAT(OFS_RETURN) = -1;
2482 VM_Warning("VM_drawcharacter: %s passed null character !\n",PRVM_NAME);
2486 pos = PRVM_G_VECTOR(OFS_PARM0);
2487 scale = PRVM_G_VECTOR(OFS_PARM2);
2488 rgb = PRVM_G_VECTOR(OFS_PARM3);
2489 flag = (int)PRVM_G_FLOAT(OFS_PARM5);
2491 if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
2493 PRVM_G_FLOAT(OFS_RETURN) = -2;
2494 VM_Warning("VM_drawcharacter: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
2498 if(pos[2] || scale[2])
2499 Con_Printf("VM_drawcharacter: z value%c from %s discarded\n",(pos[2] && scale[2]) ? 's' : 0,((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
2501 if(!scale[0] || !scale[1])
2503 PRVM_G_FLOAT(OFS_RETURN) = -3;
2504 VM_Warning("VM_drawcharacter: scale %s is null !\n", (scale[0] == 0) ? ((scale[1] == 0) ? "x and y" : "x") : "y");
2508 DrawQ_String (pos[0], pos[1], &character, 1, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
2509 PRVM_G_FLOAT(OFS_RETURN) = 1;
2516 float drawstring(vector position, string text, vector scale, vector rgb, float alpha, float flag)
2519 void VM_drawstring(void)
2521 float *pos,*scale,*rgb;
2524 VM_SAFEPARMCOUNT(6,VM_drawstring);
2526 string = PRVM_G_STRING(OFS_PARM1);
2527 pos = PRVM_G_VECTOR(OFS_PARM0);
2528 scale = PRVM_G_VECTOR(OFS_PARM2);
2529 rgb = PRVM_G_VECTOR(OFS_PARM3);
2530 flag = (int)PRVM_G_FLOAT(OFS_PARM5);
2532 if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
2534 PRVM_G_FLOAT(OFS_RETURN) = -2;
2535 VM_Warning("VM_drawstring: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
2539 if(!scale[0] || !scale[1])
2541 PRVM_G_FLOAT(OFS_RETURN) = -3;
2542 VM_Warning("VM_drawstring: scale %s is null !\n", (scale[0] == 0) ? ((scale[1] == 0) ? "x and y" : "x") : "y");
2546 if(pos[2] || scale[2])
2547 Con_Printf("VM_drawstring: z value%s from %s discarded\n",(pos[2] && scale[2]) ? "s" : " ",((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
2549 DrawQ_String (pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
2550 PRVM_G_FLOAT(OFS_RETURN) = 1;
2556 float drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag)
2559 void VM_drawpic(void)
2561 const char *picname;
2562 float *size, *pos, *rgb;
2565 VM_SAFEPARMCOUNT(6,VM_drawpic);
2567 picname = PRVM_G_STRING(OFS_PARM1);
2568 VM_CheckEmptyString (picname);
2570 // is pic cached ? no function yet for that
2573 PRVM_G_FLOAT(OFS_RETURN) = -4;
2574 VM_Warning("VM_drawpic: %s: %s not cached !\n", PRVM_NAME, picname);
2578 pos = PRVM_G_VECTOR(OFS_PARM0);
2579 size = PRVM_G_VECTOR(OFS_PARM2);
2580 rgb = PRVM_G_VECTOR(OFS_PARM3);
2581 flag = (int) PRVM_G_FLOAT(OFS_PARM5);
2583 if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
2585 PRVM_G_FLOAT(OFS_RETURN) = -2;
2586 VM_Warning("VM_drawpic: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
2590 if(pos[2] || size[2])
2591 Con_Printf("VM_drawpic: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
2593 DrawQ_Pic(pos[0], pos[1], Draw_CachePic(picname, true), size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
2594 PRVM_G_FLOAT(OFS_RETURN) = 1;
2601 float drawfill(vector position, vector size, vector rgb, float alpha, float flag)
2604 void VM_drawfill(void)
2606 float *size, *pos, *rgb;
2609 VM_SAFEPARMCOUNT(5,VM_drawfill);
2612 pos = PRVM_G_VECTOR(OFS_PARM0);
2613 size = PRVM_G_VECTOR(OFS_PARM1);
2614 rgb = PRVM_G_VECTOR(OFS_PARM2);
2615 flag = (int) PRVM_G_FLOAT(OFS_PARM4);
2617 if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
2619 PRVM_G_FLOAT(OFS_RETURN) = -2;
2620 VM_Warning("VM_drawfill: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
2624 if(pos[2] || size[2])
2625 Con_Printf("VM_drawfill: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
2627 DrawQ_Pic(pos[0], pos[1], NULL, size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM3), flag);
2628 PRVM_G_FLOAT(OFS_RETURN) = 1;
2635 drawsetcliparea(float x, float y, float width, float height)
2638 void VM_drawsetcliparea(void)
2641 VM_SAFEPARMCOUNT(4,VM_drawsetcliparea);
2643 x = bound(0, PRVM_G_FLOAT(OFS_PARM0), vid_conwidth.integer);
2644 y = bound(0, PRVM_G_FLOAT(OFS_PARM1), vid_conheight.integer);
2645 w = bound(0, PRVM_G_FLOAT(OFS_PARM2) + PRVM_G_FLOAT(OFS_PARM0) - x, (vid_conwidth.integer - x));
2646 h = bound(0, PRVM_G_FLOAT(OFS_PARM3) + PRVM_G_FLOAT(OFS_PARM1) - y, (vid_conheight.integer - y));
2648 DrawQ_SetClipArea(x, y, w, h);
2653 VM_drawresetcliparea
2658 void VM_drawresetcliparea(void)
2660 VM_SAFEPARMCOUNT(0,VM_drawresetcliparea);
2662 DrawQ_ResetClipArea();
2669 vector getimagesize(string pic)
2672 void VM_getimagesize(void)
2677 VM_SAFEPARMCOUNT(1,VM_getimagesize);
2679 p = PRVM_G_STRING(OFS_PARM0);
2680 VM_CheckEmptyString (p);
2682 pic = Draw_CachePic (p, false);
2684 PRVM_G_VECTOR(OFS_RETURN)[0] = pic->width;
2685 PRVM_G_VECTOR(OFS_RETURN)[1] = pic->height;
2686 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
2693 string keynumtostring(float keynum)
2696 void VM_keynumtostring (void)
2698 VM_SAFEPARMCOUNT(1, VM_keynumtostring);
2700 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Key_KeynumToString((int)PRVM_G_FLOAT(OFS_PARM0)));
2707 float stringtokeynum(string key)
2710 void VM_stringtokeynum (void)
2712 VM_SAFEPARMCOUNT( 1, VM_keynumtostring );
2714 PRVM_G_INT(OFS_RETURN) = Key_StringToKeynum(PRVM_G_STRING(OFS_PARM0));
2717 // CL_Video interface functions
2720 ========================
2723 float cin_open(string file, string name)
2724 ========================
2726 void VM_cin_open( void )
2731 VM_SAFEPARMCOUNT( 2, VM_cin_open );
2733 file = PRVM_G_STRING( OFS_PARM0 );
2734 name = PRVM_G_STRING( OFS_PARM1 );
2736 VM_CheckEmptyString( file );
2737 VM_CheckEmptyString( name );
2739 if( CL_OpenVideo( file, name, MENUOWNER ) )
2740 PRVM_G_FLOAT( OFS_RETURN ) = 1;
2742 PRVM_G_FLOAT( OFS_RETURN ) = 0;
2746 ========================
2749 void cin_close(string name)
2750 ========================
2752 void VM_cin_close( void )
2756 VM_SAFEPARMCOUNT( 1, VM_cin_close );
2758 name = PRVM_G_STRING( OFS_PARM0 );
2759 VM_CheckEmptyString( name );
2761 CL_CloseVideo( CL_GetVideoByName( name ) );
2765 ========================
2767 void cin_setstate(string name, float type)
2768 ========================
2770 void VM_cin_setstate( void )
2773 clvideostate_t state;
2776 VM_SAFEPARMCOUNT( 2, VM_cin_netstate );
2778 name = PRVM_G_STRING( OFS_PARM0 );
2779 VM_CheckEmptyString( name );
2781 state = (clvideostate_t)((int)PRVM_G_FLOAT( OFS_PARM1 ));
2783 video = CL_GetVideoByName( name );
2784 if( video && state > CLVIDEO_UNUSED && state < CLVIDEO_STATECOUNT )
2785 CL_SetVideoState( video, state );
2789 ========================
2792 float cin_getstate(string name)
2793 ========================
2795 void VM_cin_getstate( void )
2800 VM_SAFEPARMCOUNT( 1, VM_cin_getstate );
2802 name = PRVM_G_STRING( OFS_PARM0 );
2803 VM_CheckEmptyString( name );
2805 video = CL_GetVideoByName( name );
2807 PRVM_G_FLOAT( OFS_RETURN ) = (int)video->state;
2809 PRVM_G_FLOAT( OFS_RETURN ) = 0;
2813 ========================
2816 void cin_restart(string name)
2817 ========================
2819 void VM_cin_restart( void )
2824 VM_SAFEPARMCOUNT( 1, VM_cin_restart );
2826 name = PRVM_G_STRING( OFS_PARM0 );
2827 VM_CheckEmptyString( name );
2829 video = CL_GetVideoByName( name );
2831 CL_RestartVideo( video );
2838 Writes new values for v_forward, v_up, and v_right based on the given forward vector
2839 vectorvectors(vector, vector)
2842 void VM_vectorvectors (void)
2844 VectorNormalize2(PRVM_G_VECTOR(OFS_PARM0), prog->globals.server->v_forward);
2845 VectorVectors(prog->globals.server->v_forward, prog->globals.server->v_right, prog->globals.server->v_up);
2849 ========================
2852 void drawline(float width, vector pos1, vector pos2, vector rgb, float alpha, float flags)
2853 ========================
2855 void VM_drawline (void)
2857 float *c1, *c2, *rgb;
2859 unsigned char flags;
2861 VM_SAFEPARMCOUNT(6, VM_drawline);
2862 width = PRVM_G_FLOAT(OFS_PARM0);
2863 c1 = PRVM_G_VECTOR(OFS_PARM1);
2864 c2 = PRVM_G_VECTOR(OFS_PARM2);
2865 rgb = PRVM_G_VECTOR(OFS_PARM3);
2866 alpha = PRVM_G_FLOAT(OFS_PARM4);
2867 flags = (int)PRVM_G_FLOAT(OFS_PARM5);
2868 DrawQ_Line(width, c1[0], c1[1], c2[0], c2[1], rgb[0], rgb[1], rgb[2], alpha, flags);
2871 //====================
2872 //QC POLYGON functions
2873 //====================
2878 float data[36]; //[515]: enough for polygons
2879 unsigned char flags; //[515]: + VM_POLYGON_2D and VM_POLYGON_FL4V flags
2882 //static float vm_polygon_linewidth = 1;
2883 static mempool_t *vm_polygons_pool = NULL;
2884 static unsigned char vm_current_vertices = 0;
2885 static qboolean vm_polygons_initialized = false;
2886 static vm_polygon_t *vm_polygons = NULL;
2887 static unsigned long vm_polygons_num = 0, vm_drawpolygons_num = 0; //[515]: ok long on 64bit ?
2888 static qboolean vm_polygonbegin = false; //[515]: for "no-crap-on-the-screen" check
2889 #define VM_DEFPOLYNUM 64 //[515]: enough for default ?
2891 #define VM_POLYGON_FL3V 16 //more than 2 vertices (used only for lines)
2892 #define VM_POLYGON_FLLINES 32
2893 #define VM_POLYGON_FL2D 64
2894 #define VM_POLYGON_FL4V 128 //4 vertices
2896 void VM_InitPolygons (void)
2898 vm_polygons_pool = Mem_AllocPool("VMPOLY", 0, NULL);
2899 vm_polygons = (vm_polygon_t *)Mem_Alloc(vm_polygons_pool, VM_DEFPOLYNUM*sizeof(vm_polygon_t));
2900 memset(vm_polygons, 0, VM_DEFPOLYNUM*sizeof(vm_polygon_t));
2901 vm_polygons_num = VM_DEFPOLYNUM;
2902 vm_drawpolygons_num = 0;
2903 vm_polygonbegin = false;
2904 vm_polygons_initialized = true;
2907 void VM_DrawPolygonCallback (const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
2909 int surfacelistindex;
2910 // LordHavoc: FIXME: this is stupid code
2911 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
2913 const vm_polygon_t *p = &vm_polygons[surfacelist[surfacelistindex]];
2914 int flags = p->flags & 0x0f;
2916 if(flags == DRAWFLAG_ADDITIVE)
2917 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
2918 else if(flags == DRAWFLAG_MODULATE)
2919 GL_BlendFunc(GL_DST_COLOR, GL_ZERO);
2920 else if(flags == DRAWFLAG_2XMODULATE)
2921 GL_BlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
2923 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2925 R_Mesh_TexBind(0, R_GetTexture(p->tex));
2928 //[515]: is speed is max ?
2929 if(p->flags & VM_POLYGON_FLLINES) //[515]: lines
2931 qglLineWidth(p->data[13]);CHECKGLERROR
2932 qglBegin(GL_LINE_LOOP);
2933 qglTexCoord1f (p->data[12]);
2934 qglColor4f (p->data[20], p->data[21], p->data[22], p->data[23]);
2935 qglVertex3f (p->data[0] , p->data[1], p->data[2]);
2937 qglTexCoord1f (p->data[14]);
2938 qglColor4f (p->data[24], p->data[25], p->data[26], p->data[27]);
2939 qglVertex3f (p->data[3] , p->data[4], p->data[5]);
2941 if(p->flags & VM_POLYGON_FL3V)
2943 qglTexCoord1f (p->data[16]);
2944 qglColor4f (p->data[28], p->data[29], p->data[30], p->data[31]);
2945 qglVertex3f (p->data[6] , p->data[7], p->data[8]);
2947 if(p->flags & VM_POLYGON_FL4V)
2949 qglTexCoord1f (p->data[18]);
2950 qglColor4f (p->data[32], p->data[33], p->data[34], p->data[35]);
2951 qglVertex3f (p->data[9] , p->data[10], p->data[11]);
2959 qglBegin(GL_POLYGON);
2960 qglTexCoord2f (p->data[12], p->data[13]);
2961 qglColor4f (p->data[20], p->data[21], p->data[22], p->data[23]);
2962 qglVertex3f (p->data[0] , p->data[1], p->data[2]);
2964 qglTexCoord2f (p->data[14], p->data[15]);
2965 qglColor4f (p->data[24], p->data[25], p->data[26], p->data[27]);
2966 qglVertex3f (p->data[3] , p->data[4], p->data[5]);
2968 qglTexCoord2f (p->data[16], p->data[17]);
2969 qglColor4f (p->data[28], p->data[29], p->data[30], p->data[31]);
2970 qglVertex3f (p->data[6] , p->data[7], p->data[8]);
2972 if(p->flags & VM_POLYGON_FL4V)
2974 qglTexCoord2f (p->data[18], p->data[19]);
2975 qglColor4f (p->data[32], p->data[33], p->data[34], p->data[35]);
2976 qglVertex3f (p->data[9] , p->data[10], p->data[11]);
2984 void VM_AddPolygonTo2DScene (vm_polygon_t *p)
2986 drawqueuemesh_t mesh;
2987 static int picelements[6] = {0, 1, 2, 0, 2, 3};
2989 mesh.texture = p->tex;
2990 mesh.data_element3i = picelements;
2991 mesh.data_vertex3f = p->data;
2992 mesh.data_texcoord2f = p->data + 12;
2993 mesh.data_color4f = p->data + 20;
2994 if(p->flags & VM_POLYGON_FL4V)
2996 mesh.num_vertices = 4;
2997 mesh.num_triangles = 2;
3001 mesh.num_vertices = 3;
3002 mesh.num_triangles = 1;
3004 if(p->flags & VM_POLYGON_FLLINES) //[515]: lines
3005 DrawQ_LineLoop (&mesh, (p->flags&0x0f));
3007 DrawQ_Mesh (&mesh, (p->flags&0x0f));
3010 //void(string texturename, float flag, float 2d, float lines) R_BeginPolygon
3011 void VM_R_PolygonBegin (void)
3014 const char *picname;
3016 VM_SAFEPARMCOUNT(2, VM_R_PolygonBegin);
3018 if(!vm_polygons_initialized)
3022 VM_Warning("VM_R_PolygonBegin: called twice without VM_R_PolygonEnd after first\n");
3025 if(vm_drawpolygons_num >= vm_polygons_num)
3027 p = (vm_polygon_t *)Mem_Alloc(vm_polygons_pool, 2 * vm_polygons_num * sizeof(vm_polygon_t));
3028 memset(p, 0, 2 * vm_polygons_num * sizeof(vm_polygon_t));
3029 memcpy(p, vm_polygons, vm_polygons_num * sizeof(vm_polygon_t));
3030 Mem_Free(vm_polygons);
3032 vm_polygons_num *= 2;
3034 p = &vm_polygons[vm_drawpolygons_num];
3035 picname = PRVM_G_STRING(OFS_PARM0);
3037 p->tex = Draw_CachePic(picname, true)->tex;
3039 p->tex = r_texture_white;
3040 p->flags = (unsigned char)PRVM_G_FLOAT(OFS_PARM1);
3041 vm_current_vertices = 0;
3042 vm_polygonbegin = true;
3045 if(PRVM_G_FLOAT(OFS_PARM2))
3046 p->flags |= VM_POLYGON_FL2D;
3047 if(prog->argc >= 4 && PRVM_G_FLOAT(OFS_PARM3))
3049 p->data[13] = PRVM_G_FLOAT(OFS_PARM3); //[515]: linewidth
3050 p->flags |= VM_POLYGON_FLLINES;
3055 //void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex
3056 void VM_R_PolygonVertex (void)
3058 float *coords, *tx, *rgb, alpha;
3060 VM_SAFEPARMCOUNT(4, VM_R_PolygonVertex);
3062 if(!vm_polygonbegin)
3064 VM_Warning("VM_R_PolygonVertex: VM_R_PolygonBegin wasn't called\n");
3067 coords = PRVM_G_VECTOR(OFS_PARM0);
3068 tx = PRVM_G_VECTOR(OFS_PARM1);
3069 rgb = PRVM_G_VECTOR(OFS_PARM2);
3070 alpha = PRVM_G_FLOAT(OFS_PARM3);
3072 p = &vm_polygons[vm_drawpolygons_num];
3073 if(vm_current_vertices > 4)
3075 VM_Warning("VM_R_PolygonVertex: may have 4 vertices max\n");
3079 p->data[vm_current_vertices*3] = coords[0];
3080 p->data[1+vm_current_vertices*3] = coords[1];
3081 p->data[2+vm_current_vertices*3] = coords[2];
3083 p->data[12+vm_current_vertices*2] = tx[0];
3084 if(!(p->flags & VM_POLYGON_FLLINES))
3085 p->data[13+vm_current_vertices*2] = tx[1];
3087 p->data[20+vm_current_vertices*4] = rgb[0];
3088 p->data[21+vm_current_vertices*4] = rgb[1];
3089 p->data[22+vm_current_vertices*4] = rgb[2];
3090 p->data[23+vm_current_vertices*4] = alpha;
3092 vm_current_vertices++;
3093 if(vm_current_vertices == 4)
3094 p->flags |= VM_POLYGON_FL4V;
3096 if(vm_current_vertices == 3)
3097 p->flags |= VM_POLYGON_FL3V;
3100 //void() R_EndPolygon
3101 void VM_R_PolygonEnd (void)
3103 if(!vm_polygonbegin)
3105 VM_Warning("VM_R_PolygonEnd: VM_R_PolygonBegin wasn't called\n");
3108 vm_polygonbegin = false;
3109 if(vm_current_vertices > 2 || (vm_current_vertices >= 2 && vm_polygons[vm_drawpolygons_num].flags & VM_POLYGON_FLLINES))
3111 if(vm_polygons[vm_drawpolygons_num].flags & VM_POLYGON_FL2D) //[515]: don't use qcpolygons memory if 2D
3112 VM_AddPolygonTo2DScene(&vm_polygons[vm_drawpolygons_num]);
3114 vm_drawpolygons_num++;
3117 VM_Warning("VM_R_PolygonEnd: %i vertices isn't a good choice\n", vm_current_vertices);
3120 void VM_AddPolygonsToMeshQueue (void)
3123 if(!vm_drawpolygons_num)
3125 R_Mesh_Matrix(&identitymatrix);
3126 GL_CullFace(GL_NONE);
3127 for(i = 0;i < (int)vm_drawpolygons_num;i++)
3128 VM_DrawPolygonCallback(NULL, NULL, 1, &i);
3129 vm_drawpolygons_num = 0;
3132 void Debug_PolygonBegin(const char *picname, int flags, qboolean draw2d, float linewidth)
3136 if(!vm_polygons_initialized)
3140 Con_Printf("Debug_PolygonBegin: called twice without Debug_PolygonEnd after first\n");
3143 // limit polygons to a vaguely sane amount, beyond this each one just
3144 // replaces the last one
3145 vm_drawpolygons_num = min(vm_drawpolygons_num, (1<<20)-1);
3146 if(vm_drawpolygons_num >= vm_polygons_num)
3148 p = (vm_polygon_t *)Mem_Alloc(vm_polygons_pool, 2 * vm_polygons_num * sizeof(vm_polygon_t));
3149 memset(p, 0, 2 * vm_polygons_num * sizeof(vm_polygon_t));
3150 memcpy(p, vm_polygons, vm_polygons_num * sizeof(vm_polygon_t));
3151 Mem_Free(vm_polygons);
3153 vm_polygons_num *= 2;
3155 p = &vm_polygons[vm_drawpolygons_num];
3156 if(picname && picname[0])
3157 p->tex = Draw_CachePic(picname, true)->tex;
3159 p->tex = r_texture_white;
3161 vm_current_vertices = 0;
3162 vm_polygonbegin = true;
3164 p->flags |= VM_POLYGON_FL2D;
3167 p->data[13] = linewidth; //[515]: linewidth
3168 p->flags |= VM_POLYGON_FLLINES;
3172 void Debug_PolygonVertex(float x, float y, float z, float s, float t, float r, float g, float b, float a)
3176 if(!vm_polygonbegin)
3178 Con_Printf("Debug_PolygonVertex: Debug_PolygonBegin wasn't called\n");
3182 p = &vm_polygons[vm_drawpolygons_num];
3183 if(vm_current_vertices > 4)
3185 Con_Printf("Debug_PolygonVertex: may have 4 vertices max\n");
3189 p->data[vm_current_vertices*3] = x;
3190 p->data[1+vm_current_vertices*3] = y;
3191 p->data[2+vm_current_vertices*3] = z;
3193 p->data[12+vm_current_vertices*2] = s;
3194 if(!(p->flags & VM_POLYGON_FLLINES))
3195 p->data[13+vm_current_vertices*2] = t;
3197 p->data[20+vm_current_vertices*4] = r;
3198 p->data[21+vm_current_vertices*4] = g;
3199 p->data[22+vm_current_vertices*4] = b;
3200 p->data[23+vm_current_vertices*4] = a;
3202 vm_current_vertices++;
3203 if(vm_current_vertices == 4)
3204 p->flags |= VM_POLYGON_FL4V;
3206 if(vm_current_vertices == 3)
3207 p->flags |= VM_POLYGON_FL3V;
3210 void Debug_PolygonEnd(void)
3212 if(!vm_polygonbegin)
3214 Con_Printf("Debug_PolygonEnd: Debug_PolygonBegin wasn't called\n");
3217 vm_polygonbegin = false;
3218 if(vm_current_vertices > 2 || (vm_current_vertices >= 2 && vm_polygons[vm_drawpolygons_num].flags & VM_POLYGON_FLLINES))
3220 if(vm_polygons[vm_drawpolygons_num].flags & VM_POLYGON_FL2D) //[515]: don't use qcpolygons memory if 2D
3221 VM_AddPolygonTo2DScene(&vm_polygons[vm_drawpolygons_num]);
3223 vm_drawpolygons_num++;
3226 Con_Printf("Debug_PolygonEnd: %i vertices isn't a good choice\n", vm_current_vertices);
3233 // float(float number, float quantity) bitshift (EXT_BITSHIFT)
3234 void VM_bitshift (void)
3237 VM_SAFEPARMCOUNT(2, VM_bitshift);
3239 n1 = (int)fabs((int)PRVM_G_FLOAT(OFS_PARM0));
3240 n2 = (int)PRVM_G_FLOAT(OFS_PARM1);
3242 PRVM_G_FLOAT(OFS_RETURN) = n1;
3245 PRVM_G_FLOAT(OFS_RETURN) = (n1 >> -n2);
3247 PRVM_G_FLOAT(OFS_RETURN) = (n1 << n2);
3250 ////////////////////////////////////////
3251 // AltString functions
3252 ////////////////////////////////////////
3255 ========================
3258 float altstr_count(string)
3259 ========================
3261 void VM_altstr_count( void )
3263 const char *altstr, *pos;
3266 VM_SAFEPARMCOUNT( 1, VM_altstr_count );
3268 altstr = PRVM_G_STRING( OFS_PARM0 );
3269 //VM_CheckEmptyString( altstr );
3271 for( count = 0, pos = altstr ; *pos ; pos++ ) {
3272 if( *pos == '\\' ) {
3276 } else if( *pos == '\'' ) {
3281 PRVM_G_FLOAT( OFS_RETURN ) = (float) (count / 2);
3285 ========================
3288 string altstr_prepare(string)
3289 ========================
3291 void VM_altstr_prepare( void )
3294 const char *instr, *in;
3296 char outstr[VM_STRINGTEMP_LENGTH];
3298 VM_SAFEPARMCOUNT( 1, VM_altstr_prepare );
3300 instr = PRVM_G_STRING( OFS_PARM0 );
3302 for( out = outstr, in = instr, size = sizeof(outstr) - 1 ; size && *in ; size--, in++, out++ )
3311 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( outstr );
3315 ========================
3318 string altstr_get(string, float)
3319 ========================
3321 void VM_altstr_get( void )
3323 const char *altstr, *pos;
3326 char outstr[VM_STRINGTEMP_LENGTH];
3328 VM_SAFEPARMCOUNT( 2, VM_altstr_get );
3330 altstr = PRVM_G_STRING( OFS_PARM0 );
3332 count = (int)PRVM_G_FLOAT( OFS_PARM1 );
3333 count = count * 2 + 1;
3335 for( pos = altstr ; *pos && count ; pos++ )
3336 if( *pos == '\\' ) {
3339 } else if( *pos == '\'' )
3343 PRVM_G_INT( OFS_RETURN ) = 0;
3347 for( out = outstr, size = sizeof(outstr) - 1 ; size && *pos ; size--, pos++, out++ )
3348 if( *pos == '\\' ) {
3353 } else if( *pos == '\'' )
3359 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( outstr );
3363 ========================
3366 string altstr_set(string altstr, float num, string set)
3367 ========================
3369 void VM_altstr_set( void )
3372 const char *altstr, *str;
3375 char outstr[VM_STRINGTEMP_LENGTH];
3377 VM_SAFEPARMCOUNT( 3, VM_altstr_set );
3379 altstr = PRVM_G_STRING( OFS_PARM0 );
3381 num = (int)PRVM_G_FLOAT( OFS_PARM1 );
3383 str = PRVM_G_STRING( OFS_PARM2 );
3386 for( num = num * 2 + 1, in = altstr; *in && num; *out++ = *in++ )
3391 } else if( *in == '\'' ) {
3396 for( ; *str; *out++ = *str++ );
3397 // now jump over the old content
3399 if( *in == '\'' || (*in == '\\' && !*++in) )
3402 strlcpy(out, in, outstr + sizeof(outstr) - out);
3403 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( outstr );
3407 ========================
3410 string altstr_ins(string altstr, float num, string set)
3411 ========================
3413 void VM_altstr_ins(void)
3421 char outstr[VM_STRINGTEMP_LENGTH];
3423 in = instr = PRVM_G_STRING( OFS_PARM0 );
3424 num = (int)PRVM_G_FLOAT( OFS_PARM1 );
3425 set = setstr = PRVM_G_STRING( OFS_PARM2 );
3428 for( num = num * 2 + 2 ; *in && num > 0 ; *out++ = *in++ )
3433 } else if( *in == '\'' ) {
3438 for( ; *set ; *out++ = *set++ );
3441 strlcpy(out, in, outstr + sizeof(outstr) - out);
3442 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( outstr );
3446 ////////////////////////////////////////
3447 // BufString functions
3448 ////////////////////////////////////////
3449 //[515]: string buffers support
3450 #define MAX_QCSTR_BUFFERS 128
3451 #define MAX_QCSTR_STRINGS 1024
3456 char *strings[MAX_QCSTR_STRINGS];
3459 static qcstrbuffer_t *qcstringbuffers[MAX_QCSTR_BUFFERS];
3460 static int num_qcstringbuffers;
3461 static int buf_sortpower;
3463 #define BUFSTR_BUFFER(a) (a>=MAX_QCSTR_BUFFERS) ? NULL : (qcstringbuffers[a])
3464 #define BUFSTR_ISFREE(a) (a<MAX_QCSTR_BUFFERS&&qcstringbuffers[a]&&qcstringbuffers[a]->num_strings<=0) ? 1 : 0
3466 static int BufStr_FindFreeBuffer (void)
3469 if(num_qcstringbuffers == MAX_QCSTR_BUFFERS)
3471 for(i=0;i<MAX_QCSTR_BUFFERS;i++)
3472 if(!qcstringbuffers[i])
3474 qcstringbuffers[i] = (qcstrbuffer_t *)Z_Malloc(sizeof(qcstrbuffer_t));
3475 memset(qcstringbuffers[i], 0, sizeof(qcstrbuffer_t));
3481 static void BufStr_ClearBuffer (int index)
3483 qcstrbuffer_t *b = qcstringbuffers[index];
3488 if(b->num_strings > 0)
3490 for(i=0;i<b->num_strings;i++)
3492 Z_Free(b->strings[i]);
3493 num_qcstringbuffers--;
3495 Z_Free(qcstringbuffers[index]);
3496 qcstringbuffers[index] = NULL;
3500 static int BufStr_FindFreeString (qcstrbuffer_t *b)
3503 for(i=0;i<b->num_strings;i++)
3504 if(!b->strings[i] || !b->strings[i][0])
3506 if(i == MAX_QCSTR_STRINGS) return -1;
3510 static int BufStr_SortStringsUP (const void *in1, const void *in2)
3513 a = *((const char **) in1);
3514 b = *((const char **) in2);
3516 if(!b[0]) return -1;
3517 return strncmp(a, b, buf_sortpower);
3520 static int BufStr_SortStringsDOWN (const void *in1, const void *in2)
3523 a = *((const char **) in1);
3524 b = *((const char **) in2);
3526 if(!b[0]) return -1;
3527 return strncmp(b, a, buf_sortpower);
3531 static void VM_BufStr_Init (void)
3533 memset(qcstringbuffers, 0, sizeof(qcstringbuffers));
3534 num_qcstringbuffers = 0;
3537 static void VM_BufStr_ShutDown (void)
3540 for(i=0;i<MAX_QCSTR_BUFFERS && num_qcstringbuffers;i++)
3541 BufStr_ClearBuffer(i);
3546 ========================
3548 creates new buffer, and returns it's index, returns -1 if failed
3549 float buf_create(void) = #460;
3550 ========================
3552 void VM_buf_create (void)
3555 VM_SAFEPARMCOUNT(0, VM_buf_create);
3556 i = BufStr_FindFreeBuffer();
3558 num_qcstringbuffers++;
3560 //Con_Printf("VM_buf_create: buffers overflow in %s\n", PRVM_NAME);
3561 PRVM_G_FLOAT(OFS_RETURN) = i;
3565 ========================
3567 deletes buffer and all strings in it
3568 void buf_del(float bufhandle) = #461;
3569 ========================
3571 void VM_buf_del (void)
3573 VM_SAFEPARMCOUNT(1, VM_buf_del);
3574 if(BUFSTR_BUFFER((int)PRVM_G_FLOAT(OFS_PARM0)))
3575 BufStr_ClearBuffer((int)PRVM_G_FLOAT(OFS_PARM0));
3578 VM_Warning("VM_buf_del: invalid buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
3584 ========================
3586 how many strings are stored in buffer
3587 float buf_getsize(float bufhandle) = #462;
3588 ========================
3590 void VM_buf_getsize (void)
3593 VM_SAFEPARMCOUNT(1, VM_buf_getsize);
3595 b = BUFSTR_BUFFER((int)PRVM_G_FLOAT(OFS_PARM0));
3598 PRVM_G_FLOAT(OFS_RETURN) = -1;
3599 VM_Warning("VM_buf_getsize: invalid buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
3603 PRVM_G_FLOAT(OFS_RETURN) = b->num_strings;
3607 ========================
3609 copy all content from one buffer to another, make sure it exists
3610 void buf_copy(float bufhandle_from, float bufhandle_to) = #463;
3611 ========================
3613 void VM_buf_copy (void)
3615 qcstrbuffer_t *b1, *b2;
3617 VM_SAFEPARMCOUNT(2, VM_buf_copy);
3619 b1 = BUFSTR_BUFFER((int)PRVM_G_FLOAT(OFS_PARM0));
3622 VM_Warning("VM_buf_copy: invalid source buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
3625 i = (int)PRVM_G_FLOAT(OFS_PARM1);
3626 if(i == (int)PRVM_G_FLOAT(OFS_PARM0))
3628 VM_Warning("VM_buf_copy: source == destination (%i) in %s\n", i, PRVM_NAME);
3631 b2 = BUFSTR_BUFFER(i);
3634 VM_Warning("VM_buf_copy: invalid destination buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM1), PRVM_NAME);
3638 BufStr_ClearBuffer(i);
3639 qcstringbuffers[i] = (qcstrbuffer_t *)Z_Malloc(sizeof(qcstrbuffer_t));
3640 memset(qcstringbuffers[i], 0, sizeof(qcstrbuffer_t));
3641 b2->num_strings = b1->num_strings;
3643 for(i=0;i<b1->num_strings;i++)
3644 if(b1->strings[i] && b1->strings[i][0])
3647 stringlen = strlen(b1->strings[i]) + 1;
3648 b2->strings[i] = (char *)Z_Malloc(stringlen);
3651 VM_Warning("VM_buf_copy: not enough memory for buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM1), PRVM_NAME);
3654 memcpy(b2->strings[i], b1->strings[i], stringlen);
3659 ========================
3661 sort buffer by beginnings of strings (sortpower defaults it's lenght)
3662 "backward == TRUE" means that sorting goes upside-down
3663 void buf_sort(float bufhandle, float sortpower, float backward) = #464;
3664 ========================
3666 void VM_buf_sort (void)
3670 VM_SAFEPARMCOUNT(3, VM_buf_sort);
3672 b = BUFSTR_BUFFER((int)PRVM_G_FLOAT(OFS_PARM0));
3675 VM_Warning("VM_buf_sort: invalid buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
3678 if(b->num_strings <= 0)
3680 VM_Warning("VM_buf_sort: tried to sort empty buffer %i in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
3683 buf_sortpower = (int)PRVM_G_FLOAT(OFS_PARM1);
3684 if(buf_sortpower <= 0)
3685 buf_sortpower = 99999999;
3687 if(!PRVM_G_FLOAT(OFS_PARM2))
3688 qsort(b->strings, b->num_strings, sizeof(char*), BufStr_SortStringsUP);
3690 qsort(b->strings, b->num_strings, sizeof(char*), BufStr_SortStringsDOWN);
3692 for(i=b->num_strings-1;i>=0;i--) //[515]: delete empty lines
3695 if(b->strings[i][0])
3699 Z_Free(b->strings[i]);
3701 b->strings[i] = NULL;
3709 ========================
3711 concantenates all buffer string into one with "glue" separator and returns it as tempstring
3712 string buf_implode(float bufhandle, string glue) = #465;
3713 ========================
3715 void VM_buf_implode (void)
3718 char k[VM_STRINGTEMP_LENGTH];
3722 VM_SAFEPARMCOUNT(2, VM_buf_implode);
3724 b = BUFSTR_BUFFER((int)PRVM_G_FLOAT(OFS_PARM0));
3725 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
3728 VM_Warning("VM_buf_implode: invalid buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
3733 sep = PRVM_G_STRING(OFS_PARM1);
3735 for(l=i=0;i<b->num_strings;i++)
3738 l += (i > 0 ? strlen(sep) : 0) + strlen(b->strings[i]);
3739 if (l >= sizeof(k) - 1)
3741 strlcat(k, sep, sizeof(k));
3742 strlcat(k, b->strings[i], sizeof(k));
3744 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(k);
3748 ========================
3750 get a string from buffer, returns tempstring, dont str_unzone it!
3751 string bufstr_get(float bufhandle, float string_index) = #465;
3752 ========================
3754 void VM_bufstr_get (void)
3758 VM_SAFEPARMCOUNT(2, VM_bufstr_get);
3760 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
3761 b = BUFSTR_BUFFER((int)PRVM_G_FLOAT(OFS_PARM0));
3764 VM_Warning("VM_bufstr_get: invalid buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
3767 strindex = (int)PRVM_G_FLOAT(OFS_PARM1);
3768 if(strindex < 0 || strindex > MAX_QCSTR_STRINGS)
3770 VM_Warning("VM_bufstr_get: invalid string index %i used in %s\n", strindex, PRVM_NAME);
3773 if(b->num_strings <= strindex)
3775 if(b->strings[strindex])
3776 PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(b->strings[strindex]);
3780 ========================
3782 copies a string into selected slot of buffer
3783 void bufstr_set(float bufhandle, float string_index, string str) = #466;
3784 ========================
3786 void VM_bufstr_set (void)
3788 int bufindex, strindex;
3793 VM_SAFEPARMCOUNT(3, VM_bufstr_set);
3795 bufindex = (int)PRVM_G_FLOAT(OFS_PARM0);
3796 b = BUFSTR_BUFFER(bufindex);
3799 VM_Warning("VM_bufstr_set: invalid buffer %i used in %s\n", bufindex, PRVM_NAME);
3802 strindex = (int)PRVM_G_FLOAT(OFS_PARM1);
3803 if(strindex < 0 || strindex > MAX_QCSTR_STRINGS)
3805 VM_Warning("VM_bufstr_set: invalid string index %i used in %s\n", strindex, PRVM_NAME);
3808 news = PRVM_G_STRING(OFS_PARM2);
3809 if(b->strings[strindex])
3810 Z_Free(b->strings[strindex]);
3811 alloclen = strlen(news) + 1;
3812 b->strings[strindex] = (char *)Z_Malloc(alloclen);
3813 memcpy(b->strings[strindex], news, alloclen);
3817 ========================
3819 adds string to buffer in nearest free slot and returns it
3820 "order == TRUE" means that string will be added after last "full" slot
3821 float bufstr_add(float bufhandle, string str, float order) = #467;
3822 ========================
3824 void VM_bufstr_add (void)
3826 int bufindex, order, strindex;
3831 VM_SAFEPARMCOUNT(3, VM_bufstr_add);
3833 bufindex = (int)PRVM_G_FLOAT(OFS_PARM0);
3834 b = BUFSTR_BUFFER(bufindex);
3835 PRVM_G_FLOAT(OFS_RETURN) = -1;
3838 VM_Warning("VM_bufstr_add: invalid buffer %i used in %s\n", bufindex, PRVM_NAME);
3841 string = PRVM_G_STRING(OFS_PARM1);
3842 order = (int)PRVM_G_FLOAT(OFS_PARM2);
3844 strindex = b->num_strings;
3847 strindex = BufStr_FindFreeString(b);
3850 VM_Warning("VM_bufstr_add: buffer %i has no free string slots in %s\n", bufindex, PRVM_NAME);
3855 while(b->num_strings <= strindex)
3857 if(b->num_strings == MAX_QCSTR_STRINGS)
3859 VM_Warning("VM_bufstr_add: buffer %i has no free string slots in %s\n", bufindex, PRVM_NAME);
3862 b->strings[b->num_strings] = NULL;
3865 if(b->strings[strindex])
3866 Z_Free(b->strings[strindex]);
3867 alloclen = strlen(string) + 1;
3868 b->strings[strindex] = (char *)Z_Malloc(alloclen);
3869 memcpy(b->strings[strindex], string, alloclen);
3870 PRVM_G_FLOAT(OFS_RETURN) = strindex;
3874 ========================
3876 delete string from buffer
3877 void bufstr_free(float bufhandle, float string_index) = #468;
3878 ========================
3880 void VM_bufstr_free (void)
3884 VM_SAFEPARMCOUNT(2, VM_bufstr_free);
3886 b = BUFSTR_BUFFER((int)PRVM_G_FLOAT(OFS_PARM0));
3889 VM_Warning("VM_bufstr_free: invalid buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
3892 i = (int)PRVM_G_FLOAT(OFS_PARM1);
3893 if(i < 0 || i > MAX_QCSTR_STRINGS)
3895 VM_Warning("VM_bufstr_free: invalid string index %i used in %s\n", i, PRVM_NAME);
3899 Z_Free(b->strings[i]);
3900 b->strings[i] = NULL;
3901 if(i+1 == b->num_strings)
3911 This was a major timewaster in progs, so it was converted to C
3914 void VM_changeyaw (void)
3917 float ideal, current, move, speed;
3919 ent = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
3920 if (ent == prog->edicts)
3922 VM_Warning("changeyaw: can not modify world entity\n");
3925 if (ent->priv.server->free)
3927 VM_Warning("changeyaw: can not modify free entity\n");
3930 if (prog->fieldoffsets.angles < 0 || prog->fieldoffsets.ideal_yaw < 0 || prog->fieldoffsets.yaw_speed < 0)
3932 VM_Warning("changeyaw: angles, ideal_yaw, or yaw_speed field(s) not found\n");
3935 current = ANGLEMOD(PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.angles)->vector[1]);
3936 ideal = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.ideal_yaw)->_float;
3937 speed = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.yaw_speed)->_float;
3939 if (current == ideal)
3941 move = ideal - current;
3942 if (ideal > current)
3963 PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.angles)->vector[1] = ANGLEMOD (current + move);
3971 void VM_changepitch (void)
3974 float ideal, current, move, speed;
3976 ent = PRVM_G_EDICT(OFS_PARM0);
3977 if (ent == prog->edicts)
3979 VM_Warning("changepitch: can not modify world entity\n");
3982 if (ent->priv.server->free)
3984 VM_Warning("changepitch: can not modify free entity\n");
3987 if (prog->fieldoffsets.angles < 0 || prog->fieldoffsets.idealpitch < 0 || prog->fieldoffsets.pitch_speed < 0)
3989 VM_Warning("changepitch: angles, idealpitch, or pitch_speed field(s) not found\n");
3992 current = ANGLEMOD(PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.angles)->vector[0]);
3993 ideal = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.idealpitch)->_float;
3994 speed = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.pitch_speed)->_float;
3996 if (current == ideal)
3998 move = ideal - current;
3999 if (ideal > current)
4020 PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.angles)->vector[0] = ANGLEMOD (current + move);
4025 void VM_Cmd_Init(void)
4027 // only init the stuff for the current prog
4030 // VM_BufStr_Init();
4031 if(vm_polygons_initialized)
4033 Mem_FreePool(&vm_polygons_pool);
4034 vm_polygons_initialized = false;
4038 void VM_Cmd_Reset(void)
4040 CL_PurgeOwner( MENUOWNER );
4042 VM_Files_CloseAll();
4043 // VM_BufStr_ShutDown();
4044 if(vm_polygons_initialized)
4046 Mem_FreePool(&vm_polygons_pool);
4047 vm_polygons_initialized = false;