+ memset(f->fallbacks, 0, sizeof(f->fallbacks));
+ memset(f->fallback_faces, 0, sizeof(f->fallback_faces));
+
+ // first font is handled "normally"
+ c = strchr(filelist, ':');
+ cm = strchr(filelist, ',');
+ if(c && (!cm || c < cm))
+ f->req_face = atoi(c+1);
+ else
+ {
+ f->req_face = 0;
+ c = cm;
+ }
+ if(!c || (c - filelist) > MAX_QPATH)
+ strlcpy(mainfont, filelist, sizeof(mainfont));
+ else
+ {
+ memcpy(mainfont, filelist, c - filelist);
+ mainfont[c - filelist] = 0;
+ }
+
+ // handle fallbacks
+ for(i = 0; i < MAX_FONT_FALLBACKS; ++i)
+ {
+ c = strchr(filelist, ',');
+ if(!c)
+ break;
+ filelist = c + 1;
+ if(!*filelist)
+ break;
+ c = strchr(filelist, ':');
+ cm = strchr(filelist, ',');
+ if(c && (!cm || c < cm))
+ f->fallback_faces[i] = atoi(c+1);
+ else
+ {
+ f->fallback_faces[i] = 0; // f->req_face; could make it stick to the default-font's face index
+ c = cm;
+ }
+ if(!c || (c-filelist) > MAX_QPATH)
+ {
+ strlcpy(f->fallbacks[i], filelist, sizeof(mainfont));
+ }
+ else
+ {
+ memcpy(f->fallbacks[i], filelist, c - filelist);
+ f->fallbacks[i][c - filelist] = 0;
+ }
+ }
+
+ // handle sizes
+ for(i = 0; i < MAX_FONT_SIZES; ++i)
+ f->req_sizes[i] = -1;
+ for (numsizes = 0,c = sizes;;)
+ {
+ if (!COM_ParseToken_VM_Tokenize(&c, 0))
+ break;
+ sz = atof(com_token);
+ // detect crap size
+ if (sz < 0.001f || sz > 1000.0f)
+ {
+ VM_Warning("VM_loadfont: crap size %s", com_token);
+ continue;
+ }
+ // check overflow
+ if (numsizes == MAX_FONT_SIZES)
+ {
+ VM_Warning("VM_loadfont: MAX_FONT_SIZES = %i exceeded", MAX_FONT_SIZES);
+ break;
+ }
+ f->req_sizes[numsizes] = sz;
+ numsizes++;
+ }
+
+ // additional scale/hoffset parms
+ scale = 1;
+ voffset = 0;
+ if (prog->argc >= 5)
+ {
+ scale = PRVM_G_FLOAT(OFS_PARM4);
+ if (scale <= 0)
+ scale = 1;
+ }
+ if (prog->argc >= 6)
+ voffset = PRVM_G_FLOAT(OFS_PARM5);
+
+ // load
+ LoadFont(true, mainfont, f, scale, voffset);
+
+ // return index of loaded font
+ PRVM_G_FLOAT(OFS_RETURN) = (f - dp_fonts.f);
+}
+
+/*
+=========
+VM_drawpic
+
+float drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag)
+=========
+*/
+void VM_drawpic(void)
+{
+ const char *picname;
+ float *size, *pos, *rgb;
+ int flag;
+
+ VM_SAFEPARMCOUNT(6,VM_drawpic);
+
+ picname = PRVM_G_STRING(OFS_PARM1);
+ VM_CheckEmptyString (picname);
+
+ // is pic cached ? no function yet for that
+ if(!1)
+ {
+ PRVM_G_FLOAT(OFS_RETURN) = -4;
+ VM_Warning("VM_drawpic: %s: %s not cached !\n", PRVM_NAME, picname);
+ return;
+ }
+
+ pos = PRVM_G_VECTOR(OFS_PARM0);
+ size = PRVM_G_VECTOR(OFS_PARM2);
+ rgb = PRVM_G_VECTOR(OFS_PARM3);
+ flag = (int) PRVM_G_FLOAT(OFS_PARM5);
+
+ if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
+ {
+ PRVM_G_FLOAT(OFS_RETURN) = -2;
+ VM_Warning("VM_drawpic: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+ return;
+ }
+
+ if(pos[2] || size[2])
+ 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")));
+
+ DrawQ_Pic(pos[0], pos[1], Draw_CachePic_Flags (picname, CACHEPICFLAG_NOTPERSISTENT), size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
+/*
+=========
+VM_drawrotpic
+
+float drawrotpic(vector position, string pic, vector size, vector org, float angle, vector rgb, float alpha, float flag)
+=========
+*/
+void VM_drawrotpic(void)
+{
+ const char *picname;
+ float *size, *pos, *org, *rgb;
+ int flag;
+
+ VM_SAFEPARMCOUNT(8,VM_drawrotpic);
+
+ picname = PRVM_G_STRING(OFS_PARM1);
+ VM_CheckEmptyString (picname);
+
+ // is pic cached ? no function yet for that
+ if(!1)
+ {
+ PRVM_G_FLOAT(OFS_RETURN) = -4;
+ VM_Warning("VM_drawrotpic: %s: %s not cached !\n", PRVM_NAME, picname);
+ return;
+ }
+
+ pos = PRVM_G_VECTOR(OFS_PARM0);
+ size = PRVM_G_VECTOR(OFS_PARM2);
+ org = PRVM_G_VECTOR(OFS_PARM3);
+ rgb = PRVM_G_VECTOR(OFS_PARM5);
+ flag = (int) PRVM_G_FLOAT(OFS_PARM7);
+
+ if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
+ {
+ PRVM_G_FLOAT(OFS_RETURN) = -2;
+ VM_Warning("VM_drawrotpic: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+ return;
+ }
+
+ if(pos[2] || size[2] || org[2])
+ Con_Printf("VM_drawrotpic: z value from pos/size/org discarded\n");
+
+ DrawQ_RotPic(pos[0], pos[1], Draw_CachePic_Flags(picname, CACHEPICFLAG_NOTPERSISTENT), size[0], size[1], org[0], org[1], PRVM_G_FLOAT(OFS_PARM4), rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM6), flag);
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
+/*
+=========
+VM_drawsubpic
+
+float drawsubpic(vector position, vector size, string pic, vector srcPos, vector srcSize, vector rgb, float alpha, float flag)
+
+=========
+*/
+void VM_drawsubpic(void)
+{
+ const char *picname;
+ float *size, *pos, *rgb, *srcPos, *srcSize, alpha;
+ int flag;
+
+ VM_SAFEPARMCOUNT(8,VM_drawsubpic);
+
+ picname = PRVM_G_STRING(OFS_PARM2);
+ VM_CheckEmptyString (picname);
+
+ // is pic cached ? no function yet for that
+ if(!1)
+ {
+ PRVM_G_FLOAT(OFS_RETURN) = -4;
+ VM_Warning("VM_drawsubpic: %s: %s not cached !\n", PRVM_NAME, picname);
+ return;
+ }
+
+ pos = PRVM_G_VECTOR(OFS_PARM0);
+ size = PRVM_G_VECTOR(OFS_PARM1);
+ srcPos = PRVM_G_VECTOR(OFS_PARM3);
+ srcSize = PRVM_G_VECTOR(OFS_PARM4);
+ rgb = PRVM_G_VECTOR(OFS_PARM5);
+ alpha = PRVM_G_FLOAT(OFS_PARM6);
+ flag = (int) PRVM_G_FLOAT(OFS_PARM7);
+
+ if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
+ {
+ PRVM_G_FLOAT(OFS_RETURN) = -2;
+ VM_Warning("VM_drawsubpic: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+ return;
+ }
+
+ if(pos[2] || size[2])
+ Con_Printf("VM_drawsubpic: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
+
+ DrawQ_SuperPic(pos[0], pos[1], Draw_CachePic_Flags (picname, CACHEPICFLAG_NOTPERSISTENT),
+ size[0], size[1],
+ srcPos[0], srcPos[1], rgb[0], rgb[1], rgb[2], alpha,
+ srcPos[0] + srcSize[0], srcPos[1], rgb[0], rgb[1], rgb[2], alpha,
+ srcPos[0], srcPos[1] + srcSize[1], rgb[0], rgb[1], rgb[2], alpha,
+ srcPos[0] + srcSize[0], srcPos[1] + srcSize[1], rgb[0], rgb[1], rgb[2], alpha,
+ flag);
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
+
+/*
+=========
+VM_drawfill
+
+float drawfill(vector position, vector size, vector rgb, float alpha, float flag)
+=========
+*/
+void VM_drawfill(void)
+{
+ float *size, *pos, *rgb;
+ int flag;
+
+ VM_SAFEPARMCOUNT(5,VM_drawfill);
+
+
+ pos = PRVM_G_VECTOR(OFS_PARM0);
+ size = PRVM_G_VECTOR(OFS_PARM1);
+ rgb = PRVM_G_VECTOR(OFS_PARM2);
+ flag = (int) PRVM_G_FLOAT(OFS_PARM4);
+
+ if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
+ {
+ PRVM_G_FLOAT(OFS_RETURN) = -2;
+ VM_Warning("VM_drawfill: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+ return;
+ }
+
+ if(pos[2] || size[2])
+ 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")));
+
+ DrawQ_Fill(pos[0], pos[1], size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM3), flag);
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
+
+/*
+=========
+VM_drawsetcliparea
+
+drawsetcliparea(float x, float y, float width, float height)
+=========
+*/
+void VM_drawsetcliparea(void)
+{
+ float x,y,w,h;
+ VM_SAFEPARMCOUNT(4,VM_drawsetcliparea);
+
+ x = bound(0, PRVM_G_FLOAT(OFS_PARM0), vid_conwidth.integer);
+ y = bound(0, PRVM_G_FLOAT(OFS_PARM1), vid_conheight.integer);
+ w = bound(0, PRVM_G_FLOAT(OFS_PARM2) + PRVM_G_FLOAT(OFS_PARM0) - x, (vid_conwidth.integer - x));
+ h = bound(0, PRVM_G_FLOAT(OFS_PARM3) + PRVM_G_FLOAT(OFS_PARM1) - y, (vid_conheight.integer - y));
+
+ DrawQ_SetClipArea(x, y, w, h);
+}
+
+/*
+=========
+VM_drawresetcliparea
+
+drawresetcliparea()
+=========
+*/
+void VM_drawresetcliparea(void)
+{
+ VM_SAFEPARMCOUNT(0,VM_drawresetcliparea);
+
+ DrawQ_ResetClipArea();
+}
+
+/*
+=========
+VM_getimagesize
+
+vector getimagesize(string pic)
+=========
+*/
+void VM_getimagesize(void)
+{
+ const char *p;
+ cachepic_t *pic;
+
+ VM_SAFEPARMCOUNT(1,VM_getimagesize);
+
+ p = PRVM_G_STRING(OFS_PARM0);
+ VM_CheckEmptyString (p);
+
+ pic = Draw_CachePic_Flags (p, CACHEPICFLAG_NOTPERSISTENT);
+
+ PRVM_G_VECTOR(OFS_RETURN)[0] = pic->width;
+ PRVM_G_VECTOR(OFS_RETURN)[1] = pic->height;
+ PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+}
+
+/*
+=========
+VM_keynumtostring
+
+string keynumtostring(float keynum)
+=========
+*/
+void VM_keynumtostring (void)
+{
+ VM_SAFEPARMCOUNT(1, VM_keynumtostring);
+
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Key_KeynumToString((int)PRVM_G_FLOAT(OFS_PARM0)));
+}
+
+/*
+=========
+VM_findkeysforcommand
+
+string findkeysforcommand(string command, float bindmap)
+
+the returned string is an altstring
+=========
+*/
+#define FKFC_NUMKEYS 5
+void M_FindKeysForCommand(const char *command, int *keys);
+void VM_findkeysforcommand(void)
+{
+ const char *cmd;
+ char ret[VM_STRINGTEMP_LENGTH];
+ int keys[FKFC_NUMKEYS];
+ int i;
+ int bindmap;
+
+ VM_SAFEPARMCOUNTRANGE(1, 2, VM_findkeysforcommand);
+
+ cmd = PRVM_G_STRING(OFS_PARM0);
+ if(prog->argc == 2)
+ bindmap = bound(-1, PRVM_G_FLOAT(OFS_PARM1), MAX_BINDMAPS-1);
+ else
+ bindmap = 0; // consistent to "bind"
+
+ VM_CheckEmptyString(cmd);
+
+ Key_FindKeysForCommand(cmd, keys, FKFC_NUMKEYS, bindmap);
+
+ ret[0] = 0;
+ for(i = 0; i < FKFC_NUMKEYS; i++)
+ strlcat(ret, va(" \'%i\'", keys[i]), sizeof(ret));
+
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(ret);
+}
+
+/*
+=========
+VM_stringtokeynum
+
+float stringtokeynum(string key)
+=========
+*/
+void VM_stringtokeynum (void)
+{
+ VM_SAFEPARMCOUNT( 1, VM_keynumtostring );
+
+ PRVM_G_FLOAT(OFS_RETURN) = Key_StringToKeynum(PRVM_G_STRING(OFS_PARM0));
+}
+
+/*
+=========
+VM_getkeybind
+
+string getkeybind(float key, float bindmap)
+=========
+*/
+void VM_getkeybind (void)
+{
+ int bindmap;
+ VM_SAFEPARMCOUNTRANGE(1, 2, VM_CL_getkeybind);
+ if(prog->argc == 2)
+ bindmap = bound(-1, PRVM_G_FLOAT(OFS_PARM1), MAX_BINDMAPS-1);
+ else
+ bindmap = 0; // consistent to "bind"
+
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Key_GetBind((int)PRVM_G_FLOAT(OFS_PARM0), bindmap));
+}
+
+/*
+=========
+VM_setkeybind
+
+float setkeybind(float key, string cmd, float bindmap)
+=========
+*/
+void VM_setkeybind (void)
+{
+ int bindmap;
+ VM_SAFEPARMCOUNTRANGE(2, 3, VM_CL_setkeybind);
+ if(prog->argc == 3)
+ bindmap = bound(-1, PRVM_G_FLOAT(OFS_PARM2), MAX_BINDMAPS-1);
+ else
+ bindmap = 0; // consistent to "bind"
+
+ PRVM_G_FLOAT(OFS_RETURN) = 0;
+ if(Key_SetBinding((int)PRVM_G_FLOAT(OFS_PARM0), bindmap, PRVM_G_STRING(OFS_PARM1)))
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
+
+/*
+=========
+VM_getbindmap
+
+vector getbindmaps()
+=========
+*/
+void VM_getbindmaps (void)
+{
+ int fg, bg;
+ VM_SAFEPARMCOUNT(0, VM_CL_getbindmap);
+ Key_GetBindMap(&fg, &bg);
+ PRVM_G_VECTOR(OFS_RETURN)[0] = fg;
+ PRVM_G_VECTOR(OFS_RETURN)[1] = bg;
+ PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+}
+
+/*
+=========
+VM_setbindmap
+
+float setbindmaps(vector bindmap)
+=========
+*/
+void VM_setbindmaps (void)
+{
+ VM_SAFEPARMCOUNT(1, VM_CL_setbindmap);
+ PRVM_G_FLOAT(OFS_RETURN) = 0;
+ if(PRVM_G_VECTOR(OFS_PARM0)[2] == 0)
+ if(Key_SetBindMap((int)PRVM_G_VECTOR(OFS_PARM0)[0], (int)PRVM_G_VECTOR(OFS_PARM0)[1]))
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
+
+// CL_Video interface functions
+
+/*
+========================
+VM_cin_open