+/*
+=========
+VM_drawcharacter
+
+float drawcharacter(vector position, float character, vector scale, vector rgb, float alpha, float flag)
+=========
+*/
+void VM_drawcharacter(void)
+{
+ float *pos,*scale,*rgb;
+ char character;
+ int flag;
+ VM_SAFEPARMCOUNT(6,VM_drawcharacter);
+
+ character = (char) PRVM_G_FLOAT(OFS_PARM1);
+ if(character == 0)
+ {
+ Con_Printf("VM_drawcharacter: %s passed null character !\n",PRVM_NAME);
+ PRVM_G_FLOAT(OFS_RETURN) = -1;
+ return;
+ }
+
+ pos = PRVM_G_VECTOR(OFS_PARM0);
+ scale = 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)
+ {
+ Con_Printf("VM_drawcharacter: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+ PRVM_G_FLOAT(OFS_RETURN) = -2;
+ return;
+ }
+
+ if(pos[2] || scale[2])
+ 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")));
+
+ if(!scale[0] || !scale[1])
+ {
+ Con_Printf("VM_drawcharacter: scale %s is null !\n", (scale[0] == 0) ? ((scale[1] == 0) ? "x and y" : "x") : "y");
+ PRVM_G_FLOAT(OFS_RETURN) = -3;
+ return;
+ }
+
+ DrawQ_String (pos[0], pos[1], &character, 1, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
+
+/*
+=========
+VM_drawstring
+
+float drawstring(vector position, string text, vector scale, vector rgb, float alpha, float flag)
+=========
+*/
+void VM_drawstring(void)
+{
+ float *pos,*scale,*rgb;
+ const char *string;
+ int flag;
+ VM_SAFEPARMCOUNT(6,VM_drawstring);
+
+ string = PRVM_G_STRING(OFS_PARM1);
+ if(!string)
+ {
+ Con_Printf("VM_drawstring: %s passed null string !\n",PRVM_NAME);
+ PRVM_G_FLOAT(OFS_RETURN) = -1;
+ return;
+ }
+
+ //VM_CheckEmptyString(string); Why should it be checked - perhaps the menu wants to support the precolored letters, too?
+
+ pos = PRVM_G_VECTOR(OFS_PARM0);
+ scale = 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)
+ {
+ Con_Printf("VM_drawstring: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+ PRVM_G_FLOAT(OFS_RETURN) = -2;
+ return;
+ }
+
+ if(!scale[0] || !scale[1])
+ {
+ Con_Printf("VM_drawstring: scale %s is null !\n", (scale[0] == 0) ? ((scale[1] == 0) ? "x and y" : "x") : "y");
+ PRVM_G_FLOAT(OFS_RETURN) = -3;
+ return;
+ }
+
+ if(pos[2] || scale[2])
+ Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && scale[2]) ? 's' : 0,((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
+
+ DrawQ_String (pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
+/*
+=========
+VM_drawpic
+
+float drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag)
+=========
+*/
+void VM_drawpic(void)
+{
+ const char *pic;
+ float *size, *pos, *rgb;
+ int flag;
+
+ VM_SAFEPARMCOUNT(6,VM_drawpic);
+
+ pic = PRVM_G_STRING(OFS_PARM1);
+
+ if(!pic)
+ {
+ Con_Printf("VM_drawpic: %s passed null picture name !\n", PRVM_NAME);
+ PRVM_G_FLOAT(OFS_RETURN) = -1;
+ return;
+ }
+
+ VM_CheckEmptyString (pic);
+
+ // is pic cached ? no function yet for that
+ if(!1)
+ {
+ Con_Printf("VM_drawpic: %s: %s not cached !\n", PRVM_NAME, pic);
+ PRVM_G_FLOAT(OFS_RETURN) = -4;
+ 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)
+ {
+ Con_Printf("VM_drawstring: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+ PRVM_G_FLOAT(OFS_RETURN) = -2;
+ return;
+ }
+
+ if(pos[2] || size[2])
+ Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && size[2]) ? 's' : 0,((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
+
+ DrawQ_Pic(pos[0], pos[1], pic, size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), 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)
+ {
+ Con_Printf("VM_drawstring: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+ PRVM_G_FLOAT(OFS_RETURN) = -2;
+ return;
+ }
+
+ if(pos[2] || size[2])
+ Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && size[2]) ? 's' : 0,((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
+
+ DrawQ_Pic(pos[0], pos[1], 0, 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);
+
+ if(!p)
+ PRVM_ERROR("VM_getimagepos: %s passed null picture name !\n", PRVM_NAME);
+
+ VM_CheckEmptyString (p);
+
+ pic = Draw_CachePic (p, false);
+
+ PRVM_G_VECTOR(OFS_RETURN)[0] = pic->width;
+ PRVM_G_VECTOR(OFS_RETURN)[1] = pic->height;
+ PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+}
+
+// CL_Video interface functions
+
+/*
+========================
+VM_cin_open
+
+float cin_open(string file, string name)
+========================
+*/
+void VM_cin_open( void )
+{
+ const char *file;
+ const char *name;
+
+ VM_SAFEPARMCOUNT( 2, VM_cin_open );
+
+ file = PRVM_G_STRING( OFS_PARM0 );
+ name = PRVM_G_STRING( OFS_PARM1 );
+
+ VM_CheckEmptyString( file );
+ VM_CheckEmptyString( name );
+
+ if( CL_OpenVideo( file, name, MENUOWNER ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = 1;
+ else
+ PRVM_G_FLOAT( OFS_RETURN ) = 0;
+}
+
+/*
+========================
+VM_cin_close
+
+void cin_close(string name)
+========================
+*/
+void VM_cin_close( void )
+{
+ const char *name;
+
+ VM_SAFEPARMCOUNT( 1, VM_cin_close );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ CL_CloseVideo( CL_GetVideo( name ) );
+}
+
+/*
+========================
+VM_cin_setstate
+void cin_setstate(string name, float type)
+========================
+*/
+void VM_cin_setstate( void )
+{
+ const char *name;
+ clvideostate_t state;
+ clvideo_t *video;
+
+ VM_SAFEPARMCOUNT( 2, VM_cin_netstate );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ state = PRVM_G_FLOAT( OFS_PARM1 );
+
+ video = CL_GetVideo( name );
+ if( video && state > CLVIDEO_UNUSED && state < CLVIDEO_STATECOUNT )
+ CL_SetVideoState( video, state );
+}
+
+/*
+========================
+VM_cin_getstate
+
+float cin_getstate(string name)
+========================
+*/
+void VM_cin_getstate( void )
+{
+ const char *name;
+ clvideo_t *video;
+
+ VM_SAFEPARMCOUNT( 1, VM_cin_getstate );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ video = CL_GetVideo( name );
+ if( video )
+ PRVM_G_FLOAT( OFS_RETURN ) = (int)video->state;
+ else
+ PRVM_G_FLOAT( OFS_RETURN ) = 0;
+}
+
+/*
+========================
+VM_cin_restart
+
+void cin_restart(string name)
+========================
+*/
+void VM_cin_restart( void )
+{
+ const char *name;
+ clvideo_t *video;
+
+ VM_SAFEPARMCOUNT( 1, VM_cin_restart );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ video = CL_GetVideo( name );
+ if( video )
+ CL_RestartVideo( video );
+}
+
+////////////////////////////////////////
+// AltString functions
+////////////////////////////////////////
+
+/*
+========================
+VM_altstr_count
+
+float altstr_count(string)
+========================
+*/
+void VM_altstr_count( void )
+{
+ const char *altstr, *pos;
+ int count;
+
+ VM_SAFEPARMCOUNT( 1, VM_altstr_count );
+
+ altstr = PRVM_G_STRING( OFS_PARM0 );
+ //VM_CheckEmptyString( altstr );
+
+ for( count = 0, pos = altstr ; *pos ; pos++ ) {
+ if( *pos == '\\' ) {
+ if( !*++pos ) {
+ break;
+ }
+ } else if( *pos == '\'' ) {
+ count++;
+ }
+ }
+
+ PRVM_G_FLOAT( OFS_RETURN ) = (float) (count / 2);
+}
+
+/*
+========================
+VM_altstr_prepare
+
+string altstr_prepare(string)
+========================
+*/
+void VM_altstr_prepare( void )
+{
+ char *outstr, *out;
+ const char *instr, *in;
+ int size;
+
+ VM_SAFEPARMCOUNT( 1, VM_altstr_prepare );
+
+ instr = PRVM_G_STRING( OFS_PARM0 );
+ //VM_CheckEmptyString( instr );
+ outstr = VM_GetTempString();
+
+ for( out = outstr, in = instr, size = VM_STRINGTEMP_LENGTH - 1 ; size && *in ; size--, in++, out++ )
+ if( *in == '\'' ) {
+ *out++ = '\\';
+ *out = '\'';
+ size--;
+ } else
+ *out = *in;
+ *out = 0;
+
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( outstr );
+}
+
+/*
+========================
+VM_altstr_get
+
+string altstr_get(string, float)
+========================
+*/
+void VM_altstr_get( void )
+{
+ const char *altstr, *pos;
+ char *outstr, *out;
+ int count, size;
+
+ VM_SAFEPARMCOUNT( 2, VM_altstr_get );
+
+ altstr = PRVM_G_STRING( OFS_PARM0 );
+ //VM_CheckEmptyString( altstr );
+
+ count = PRVM_G_FLOAT( OFS_PARM1 );
+ count = count * 2 + 1;
+
+ for( pos = altstr ; *pos && count ; pos++ )
+ if( *pos == '\\' ) {
+ if( !*++pos )
+ break;
+ } else if( *pos == '\'' )
+ count--;
+
+ if( !*pos ) {
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( NULL );
+ return;
+ }
+
+ outstr = VM_GetTempString();
+ for( out = outstr, size = VM_STRINGTEMP_LENGTH - 1 ; size && *pos ; size--, pos++, out++ )
+ if( *pos == '\\' ) {
+ if( !*++pos )
+ break;
+ *out = *pos;
+ size--;
+ } else if( *pos == '\'' )
+ break;
+ else
+ *out = *pos;
+
+ *out = 0;
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( outstr );
+}
+
+/*
+========================
+VM_altstr_set
+
+string altstr_set(string altstr, float num, string set)
+========================
+*/
+void VM_altstr_set( void )
+{
+ int num;
+ const char *altstr, *str;
+ const char *in;
+ char *outstr, *out;
+
+ VM_SAFEPARMCOUNT( 3, VM_altstr_set );
+
+ altstr = PRVM_G_STRING( OFS_PARM0 );
+ //VM_CheckEmptyString( altstr );
+
+ num = PRVM_G_FLOAT( OFS_PARM1 );
+
+ str = PRVM_G_STRING( OFS_PARM2 );
+ //VM_CheckEmptyString( str );
+
+ outstr = out = VM_GetTempString();
+ for( num = num * 2 + 1, in = altstr; *in && num; *out++ = *in++ )
+ if( *in == '\\' ) {
+ if( !*++in ) {
+ break;
+ }
+ } else if( *in == '\'' ) {
+ num--;
+ }
+
+ if( !in ) {
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( altstr );
+ return;
+ }
+ // copy set in
+ for( ; *str; *out++ = *str++ );
+ // now jump over the old content
+ for( ; *in ; in++ )
+ if( *in == '\'' || (*in == '\\' && !*++in) )
+ break;
+
+ if( !in ) {
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( NULL );
+ return;
+ }
+
+ strcpy( out, in );
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( outstr );
+}
+
+/*
+========================
+VM_altstr_ins
+insert after num
+string altstr_ins(string altstr, float num, string set)
+========================
+*/
+void VM_altstr_ins(void)
+{
+ int num;
+ const char *setstr;
+ const char *set;
+ const char *instr;
+ const char *in;
+ char *outstr;
+ char *out;
+
+ in = instr = PRVM_G_STRING( OFS_PARM0 );
+ num = PRVM_G_FLOAT( OFS_PARM1 );
+ set = setstr = PRVM_G_STRING( OFS_PARM2 );
+
+ out = outstr = VM_GetTempString();
+ for( num = num * 2 + 2 ; *in && num > 0 ; *out++ = *in++ )
+ if( *in == '\\' ) {
+ if( !*++in ) {
+ break;
+ }
+ } else if( *in == '\'' ) {
+ num--;
+ }
+
+ *out++ = '\'';
+ for( ; *set ; *out++ = *set++ );
+ *out++ = '\'';
+
+ strcpy( out, in );
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( outstr );
+}
+
+void VM_Cmd_Init(void)
+{
+ // only init the stuff for the current prog
+ VM_Files_Init();
+ VM_Search_Init();
+}
+
+void VM_Cmd_Reset(void)
+{
+ CL_PurgeOwner( MENUOWNER );
+ VM_Search_Reset();
+ VM_Files_CloseAll();
+}
+
+