void SGalaxy::writeGalaxy(VSFile &f) const
{
	f.Fprintf ("<galaxy>\n<systems>\n");
	writeSector(f,1,"sector",NULL);
	f.Fprintf ("</systems>\n");
	f.Fprintf("</galaxy>\n");
}
void GameCockpit::LoadXML( const char *filename )
{

    VSFile    f;
    if (filename[0] != '\0')
        if(f.OpenReadOnly( filename, CockpitFile ))
            LoadXML(f);
}
void GameCockpit::LoadXML (const char * filename) {
  const int chunk_size = 16384;

  VSFile f;
  VSError err = Unspecified;

  if (filename[0]!='\0') {
  	VSError err = f.OpenReadOnly( filename, CockpitFile);
  }
  LoadXML( f);
}
void Galaxy::writeGalaxy(VSFile &f) const
{
  f.Fprintf ("<galaxy>\n<systems>\n");
  writeSector(f,1,"sector",planet_types);
  f.Fprintf ("</systems>\n");
  if (planet_types) {
    f.Fprintf("<planets>\n");
    planet_types->writeSector(f,1,"planet",NULL);
    f.Fprintf("</planets>\n");
  }
  f.Fprintf("</galaxy>\n");
}
Ejemplo n.º 5
0
Mesh::Mesh( const char *filename,
            const Vector &scale,
            int faction,
            Flightgroup *fg,
            bool orig,
            const vector< string > &textureOverride ) : hash_name( filename )
{
    this->convex = false;
    this->orig   = NULL;
    InitUnit();
    Mesh   *oldmesh;
    if ( LoadExistant( filename, scale, faction ) )
        return;
    bool    shared = false;
    VSFile  f;
    VSError err    = Unspecified;
    err = f.OpenReadOnly( filename, MeshFile );
    if (err > Ok) {
        VSFileSystem::vs_fprintf( stderr, "Cannot Open Mesh File %s\n", filename );
//cleanexit=1;
//winsys_exit(1);
        return;
    }
    shared = (err == Shared);

    bool xml = true;
    if (xml) {
        //LoadXML(filename,scale,faction,fg,orig);
        LoadXML( f, scale, faction, fg, orig, textureOverride );
        oldmesh = this->orig;
    } else {
        //This must be changed someday
        LoadBinary( shared ? ( VSFileSystem::sharedmeshes+"/"+(filename) ).c_str() : filename, faction );
        oldmesh = new Mesh[1];
    }
    if (err <= Ok)
        f.Close();
    draw_queue = new vector< MeshDrawContext >[NUM_ZBUF_SEQ+1];
    if (!orig) {
        hash_name = shared ? VSFileSystem::GetSharedMeshHashName( filename, scale, faction ) : VSFileSystem::GetHashName(
            filename,
            scale,
            faction );
        meshHashTable.Put( hash_name, oldmesh );
        //oldmesh[0]=*this;
        *oldmesh = *this;
        oldmesh->orig = NULL;
        oldmesh->refcount++;
    } else {
        this->orig = NULL;
    }
}
string GetElMeshName( string name, string faction, char direction )
{
    using namespace VSFileSystem;
    char    strdir[2]     = {direction, 0};
    string  elxmesh       = string( strdir )+"_elevator.bfxm";
    string  elevator_mesh = name+"_"+faction+elxmesh;
    VSFile  f;
    VSError err = f.OpenReadOnly( elevator_mesh, MeshFile );
    if (err > Ok)
        f.Close();
    else elevator_mesh = name+elxmesh;
    return elevator_mesh;
}
void Universe::Generate1( const char *file, const char *jumpback )
{
    int count = 0;
    if (game_options.while_loading_starsystem)
        ss_generating( true );
    VSFile  f;
    VSError err = f.OpenReadOnly( file, SystemFile );
    //If the file is not found we generate a system
    if (err > Ok)
        MakeStarSystem( file, galaxy.get(), RemoveDotSystem( jumpback ), count );
    if (SERVER) {
        string filestr( file );
        UniverseUtil::ComputeSystemSerials( filestr );
    }
}
void FSM::LoadXML( const char *filename )
{
    using namespace CommXML;
    using namespace VSFileSystem;
    unitlevel = 0;
    VSFile  f;
    VSError err = f.OpenReadOnly( filename, CommFile );
    if (err > Ok) {
        fprintf( stderr, "Failed to open Communications file '%s' -- aborting!\n", filename );
        assert( 0 );
        return;
    }
    XML_Parser parser = XML_ParserCreate( NULL );
    XML_SetUserData( parser, this );
    XML_SetElementHandler( parser, &FSM::beginElement, &FSM::endElement );

    XML_Parse( parser, ( f.ReadFull() ).c_str(), f.Size(), 1 );
    f.Close();
    XML_ParserFree( parser );
}
SGalaxy::SGalaxy(const char *configfile)
{
  using namespace VSFileSystem;
  subheirarchy=NULL;
  VSFile f;
  VSError err = f.OpenReadOnly(configfile,UniverseFile);
  if (err<=Ok) {
	  GalaxyXML::XML x;
	  x.g=this;
	  
	  XML_Parser parser = XML_ParserCreate(NULL);
	  XML_SetUserData(parser,&x);
	  XML_SetElementHandler (parser,&GalaxyXML::beginElement,&GalaxyXML::endElement);
	  XML_Parse(parser,(f.ReadFull()).c_str(),f.Size(),1);
	  /*
	  do {
		  const int chunk_size = 65536;
		  char buf[chunk_size];
		  int length;
		  length = VSFileSystem::vs_read (buf,1,chunk_size,fp);
		  XML_Parse(parser,buf,length,VSFileSystem::vs_feof(fp));
	  }while (!VSFileSystem::vs_feof(fp));
	  VSFileSystem::vs_close (fp);
	  */
	  f.Close();

	  XML_ParserFree(parser);

  }
  else
  {
  	if(SERVER)
	{
		std::cerr<<"!!! ERROR : couldn't find galaxy file : "<<configfile<<std::endl;
		exit(1);
	}
  }
}
void    GameStarSystem::createBackground( StarSystem::StarXML * xml)
{
#ifdef NV_CUBE_MAP
	printf("using NV_CUBE_MAP\n");
	LightMap[0]=new Texture ((xml->backgroundname+"_light.cube").c_str(),1,BILINEAR,CUBEMAP,CUBEMAP_POSITIVE_X);
	if (lightMap[0]->LoadSuccess() && LightMap[0]->isCube()) {
	    LightMap[1] = LightMap[2] = LightMap[3] =
	    LightMap[4] = LightMap[5] = 0;
    } else {
        delete LightMap[0];
        LightMap[0]=new Texture ((xml->backgroundname+"_right_light.image").c_str(),1,BILINEAR,CUBEMAP,CUBEMAP_POSITIVE_X);
        LightMap[1]=new Texture ((xml->backgroundname+"_left_light.image").c_str(),1,BILINEAR,CUBEMAP,CUBEMAP_NEGATIVE_X);
        LightMap[2]=new Texture ((xml->backgroundname+"_up_light.image").c_str(),1,BILINEAR,CUBEMAP,CUBEMAP_POSITIVE_Y);
        LightMap[3]=new Texture ((xml->backgroundname+"_down_light.image").c_str(),1,BILINEAR,CUBEMAP,CUBEMAP_NEGATIVE_Y);
        LightMap[4]=new Texture ((xml->backgroundname+"_front_light.image").c_str(),1,BILINEAR,CUBEMAP,CUBEMAP_POSITIVE_Z);
        LightMap[5]=new Texture ((xml->backgroundname+"_back_light.image").c_str(),1,BILINEAR,CUBEMAP,CUBEMAP_NEGATIVE_Z);
    }
#else
	//string bglight= VSFileSystem::sharedtextures+"/"+xml->backgroundname+"_light.image";
	string bglight= xml->backgroundname+"_light.image";
	string bgfile = xml->backgroundname+"_light.image";
	VSFile f;
	VSError err = f.OpenReadOnly(bgfile,TextureFile);
	if (err>Ok) {
		EnvironmentMapGeneratorMain (xml->backgroundname.c_str(),bglight.c_str(), 0,xml->reflectivity,1);
	}
	else {
		f.Close();
	}
	LightMap[0] = new Texture(bgfile.c_str(), 1,MIPMAP,TEXTURE2D,TEXTURE_2D,GFXTRUE);
#endif

	bg = new Background(xml->backgroundname.c_str(),xml->numstars,g_game.zfar*.9,filename);
	stars = new Stars (xml->numnearstars, xml->starsp);
	stars->SetBlend (game_options.starblend, game_options.starblend);
}
Ejemplo n.º 11
0
void Cockpit::Init( const char *file, bool isDisabled )
{
    retry_dock     = 0;
    shakin         = 0;
    autopilot_time = 0;
    bool f404 = false;
    //case no file was given
    if (file == NULL || strlen( file ) == 0) 
    {
        if (isDisabled)
            file = "cockpit.cpt";
        else
            file = "disabled-cockpit.cpt";
        f404 = true;
    }
    if (isDisabled == true) 
    {
        std::string disname = std::string( "disabled-" )+file;
        Init( disname.c_str() );//call again to retrieve the good filename
        return;
    }
    VSFile  f;
    VSError err = f.OpenReadOnly( file, CockpitFile );
    if (err > Ok) 
    {
        //File not found...
        if ( isDisabled == false && (string( file ).find( "disabled-" ) == string::npos) )
            Init( file, true );
        else if (!f404)
            Init( NULL );
        return;
    }
    Delete();
    LoadXML( f );
    f.Close();
}
Ejemplo n.º 12
0
bool Music::LoadMusic( const char *file )
{
    using namespace VSFileSystem;
    if (!g_game.music_enabled)
        return true;
    //Loads a playlist so try to open a file in datadir or homedir
    VSFile  f;
    VSError err = f.OpenReadOnly( file, UnknownFile );
    if (err > Ok)
        err = f.OpenReadOnly( VSFileSystem::HOMESUBDIR+"/"+file, UnknownFile );
    char    songname[1024];
    this->playlist.push_back( PlayList() );
    if (err <= Ok) {
        while ( !f.Eof() ) {
            songname[0] = '\0';
            f.ReadLine( songname, 1022 );
            int size = strlen( songname );
            if (size >= 1)
                if (songname[size-1] == '\n')
                    songname[size-1] = '\0';
            if (size > 1)
                if (songname[size-2] == '\r' || songname[size-2] == '\n')
                    songname[size-2] = '\0';
            if (songname[0] == '\0')
                continue;
            if (songname[0] == '#') {
                if (strncmp( songname, "#pragma ", 8 ) == 0) {
                    char *sep = strchr( songname+8, ' ' );
                    if (sep) {
                        *sep = 0;
                        this->playlist.back().pragmas[songname+8] = sep+1;
                    } else if (songname[8]) {
                        this->playlist.back().pragmas[songname+8] = "1";
                    }
                }
                continue;
            }
            this->playlist.back().songs.push_back( std::string( songname ) );
        }
        f.Close();
    } else {
        return false;
    }
    return true;
}
void EnvironmentMapGeneratorMain(const char * inpt, const char *outpt, float a, float m, float p, bool w)
{

    affine=a;
    multiplicitive=m;
    power=p;
    pushdown =w;
	int size = sizeof(char)*strlen(inpt)+40;
    char * tmp = (char *) malloc (size);
    strcpy (tmp,inpt);
	VSFile f;
	VSError err = f.OpenReadOnly( strcat (tmp,"_sphere.image"), TextureFile);
    if (err>Ok)
	{
	  err = f.OpenReadOnly( strcat (tmp,"_sphere.bmp"), TextureFile);
	  if (err>Ok) {
	    memset( tmp, 0, size);
	    strcpy( tmp, inpt);
	    err = f.OpenReadOnly( strcat (tmp,"_up.image"), TextureFile);
	    if (err>Ok) {
	      err = f.OpenReadOnly( strcat (tmp,"_up.bmp"), TextureFile);
	    }
	  }
	}
    //bool share = false;
    std::string s;
    if (err>Ok) {
      //s = VSFileSystem::GetSharedTexturePath (std::string (inpt));
      s = VSFileSystem::sharedtextures+"/"+string(inpt);
      InputName = (char *) malloc (sizeof (char)*(s.length()+2));
      strcpy (InputName,s.c_str());
    } else {
      f.Close();
      InputName = (char *) malloc (sizeof (char)*(strlen(inpt)+2));
      strcpy (InputName,inpt);
    }
    OutputName=strdup (outpt);
    free(tmp);
    tmp=NULL;
  VSFileSystem::vs_fprintf (stderr, "input name %s, output name %s\nAffine %f Mult %f Pow %f\n",InputName, OutputName, affine, multiplicitive, power);
  GenerateSphereMap();
  free (InputName);
  free (OutputName);
}
void Texture::Load (const char * FileNameRGB, const char *FileNameA, int stage, enum FILTER  mipmap, enum TEXTURE_TARGET target, enum TEXTURE_IMAGE_TARGET imagetarget, float alpha, int zeroval, GFXBOOL force_load, int maxdimension,GFXBOOL detailtexture,GFXBOOL nocache,enum ADDRESSMODE address_mode)
{
    if (data) free(data);
    if (palette) free(palette);
    data = NULL;
    palette = NULL;
    ismipmapped  = mipmap;

    this->stage = stage;
    this->address_mode = address_mode;
    texture_target=target;
    image_target=imagetarget;
    string texfn = string(FileNameRGB) + string("|") + string(FileNameA);
    if (!nocache) {
        string tempstr;
        if (  checkold(texfn,false,tempstr)
                ||checkold(texfn,true,tempstr)  ) {
            texfilename = tempstr;
            return;
        }
    }
    //VSFileSystem::vs_fprintf (stderr,"2.Loading bmp file %s alp %s ",FileNameRGB,FileNameA);
    //this->texfilename = texfilename;
    //strcpy (filename,texfilename.c_str());
    VSFile f;
    VSError err = Unspecified;
    err = f.OpenReadOnly(FileNameRGB, TextureFile);
    if (!nocache) {
        bool shared = (err==Shared);
        string tempstr;
        modold (texfn,shared,tempstr);
        texfilename = tempstr;
    }
    if (err<=Ok&&g_game.use_textures==0&&!force_load) {
        f.Close();
        err = Unspecified;
    }
    if (err>Ok)
    {
        FileNotFound(texfilename);
        return;
    }
    VSFile f1;
    VSError err1=Unspecified;
    bool shared1;
    if (FileNameA)
    {
        static bool use_alphamap
            = parse_bool(vs_config->getVariable("graphics",
                                                "bitmap_alphamap",
                                                "true"));
        if (use_alphamap) {
            std::string tmp;
            f1.OpenReadOnly( FileNameA, TextureFile);

            shared1 = (err1==Shared);
            if (err1>Ok)
            {
                data = NULL;
                FileNameA = NULL;
            }
        } else FileNameA=0;
    }
    if( err1>Ok)
        data = this->ReadImage( &f, NULL, true, NULL);
    else
        data = this->ReadImage( &f, NULL, true, &f1);
    if (data)
    {
        if(mode >= _DXT1 && mode <= _DXT5) {
            if((int)data[0] == 0) {
                detailtexture = NEAREST;
                ismipmapped = NEAREST;
            }
        }
        Bind(maxdimension,detailtexture);
        free(data);
        data = NULL;
        if (!nocache) setold();
    }
    else
        FileNotFound( texfilename);
    f.Close();
    if (err1<=Ok) {
        f1.Close();
    }
    //VSFileSystem::vs_fprintf (stderr,"Load Success\n");
}
Ejemplo n.º 15
0
VSSprite::VSSprite( const char *file, enum FILTER texturefilter, GFXBOOL force )
{
    VSCONSTRUCT2( 'S' )
    xcenter     = ycenter = 0;
    widtho2     = heighto2 = 0;
    rotation    = 0;
    surface     = NULL;
    maxs        = maxt = 0;
    isAnimation = false;

    //Check cache
    {
        std::pair< bool, VSSprite* >lkup = cacheLookup( file );
        if (lkup.first) {
            if (lkup.second) {
                *this = *lkup.second;
                if (surface != NULL)
                    surface = surface->Clone();
            } else {
                return;
            }
        }
    }

    VSFile  f;
    VSError err = Unspecified;
    if (file[0] != '\0')
        err = f.OpenReadOnly( file, VSSpriteFile );
    if (err <= Ok) {
        char texture[127]  = {0};
        char texturea[127] = {0};
        f.Fscanf( "%126s %126s", texture, texturea );
        f.Fscanf( "%f %f", &widtho2, &heighto2 );
        f.Fscanf( "%f %f", &xcenter, &ycenter );
        texture[sizeof (texture)-sizeof (*texture)-1]    = 0;
        texturea[sizeof (texturea)-sizeof (*texturea)-1] = 0;

        widtho2  /= 2;
        heighto2 /= -2;
        surface   = NULL;
        if (g_game.use_sprites || force == GFXTRUE) {
            int len = strlen( texture );
            if (len > 4 && texture[len-1] == 'i' && texture[len-2] == 'n' && texture[len-3] == 'a' && texture[len-4] == '.') {
                surface     = new AnimatedTexture( f, 0, texturefilter, GFXFALSE );
                isAnimation = true;
            } else if (texturea[0] == '0') {
                surface     = new Texture( texture, 0, texturefilter, TEXTURE2D, TEXTURE_2D, GFXTRUE, 65536, GFXFALSE );
                isAnimation = false;
            } else {
                surface = new Texture( texture,
                                       texturea,
                                       0,
                                       texturefilter,
                                       TEXTURE2D,
                                       TEXTURE_2D,
                                       1,
                                       0,
                                       GFXTRUE,
                                       65536,
                                       GFXFALSE );
                isAnimation = false;
            }
            if ( !surface->LoadSuccess() ) {
                delete surface;
                surface = NULL;
                VSSprite *newspr = new VSSprite();
                *newspr = *this;
                newspr->surface = NULL;
                cacheInsert( file, newspr );
            } else {
                //Update cache
                VSSprite *newspr = new VSSprite();
                *newspr = *this;
                newspr->surface = this->surface->Clone();
                cacheInsert( file, newspr );
            }
        }
        //Finally close file
        f.Close();
    } else {
        cacheInsert( file, 0 );         //Mark bad file
        widtho2 = heighto2 = 0;
        xcenter = ycenter = 0;
    }
}
static bool LoadTex(char * FileName, unsigned char scdata [lmwid][lmwid][3]){
using namespace VSFileSystem;

  unsigned char ctemp;
  VSFile f;
  VSError err = f.OpenReadOnly( FileName, TextureFile);
	if (err>Ok)
	{
		return false;
	}
	Texture tex;
	unsigned char * data = tex.ReadImage( &f, texTransform, true);
	int bpp = tex.Depth();
	int format = tex.Format();

	unsigned char *buffer= NULL;
	bpp/=8;	
	// 999 is the code for DDS file, we must decompress them.
	if(format == 999){
		unsigned char *tmpbuffer = data + 2;
		TEXTUREFORMAT internformat;
		bpp = 1;
		// Make sure we are reading a DXT1 file. All backgrounds 
		// should be DXT1
		switch(tex.mode){
			case ::VSImage::_DXT1:
				internformat = DXT1;
				break;
			default:
				return(false);
		}
		// we could hardware decompress, but that involves more
		// pollution of gl in gfx. 
		ddsDecompress(tmpbuffer,buffer,internformat, tex.sizeY,tex.sizeX);
		// We are done with the DDS file data.  Remove it. 
		free(data);
		data = buffer;
		
		// stride and row_pointers are used for the texTransform 
		unsigned long stride = 4 * sizeof(unsigned char);
		unsigned char **row_pointers = (unsigned char**)malloc(sizeof(unsigned char*)*tex.sizeY);
		for(unsigned int i = 0;i < tex.sizeY;++i){
			row_pointers[i] = &data[i*stride*tex.sizeX];
		}
		// texTransform demands that the first argument (bpp) be 8. So we abide
		int tmp = 8;
		int tmp2 = PNG_HAS_COLOR + PNG_HAS_ALPHA;
		buffer = texTransform(tmp,tmp2,tex.sizeX,tex.sizeY,row_pointers);
		// We're done with row_pointers, free it
		free(row_pointers);
		row_pointers = NULL;
		// We're done with the decompressed dds data, free it
		free(data);
		// We set data to the transformed image data 
		data = buffer;
		buffer = NULL;
		// it's 3 because 24/8
		bpp =  4;
	} else if (format&PNG_HAS_ALPHA) {
	  bpp*=4;
	}else {
	  bpp*=3;
	}
	if (data) {
	  int ii;
	  int jj;
	  for (int i=0;i<lmwid;i++) {
	    ii=(i*tex.sizeY)/lmwid;
	    for (int j=0;j<lmwid;j++) {
	      jj= (j*tex.sizeX)/lmwid;
	      scdata[i][j][0]=data[(ii*tex.sizeX+jj)*bpp];
	      scdata[i][j][1]=data[(ii*tex.sizeX+jj)*bpp+1];
	      scdata[i][j][2]=data[(ii*tex.sizeX+jj)*bpp+2];
	    }
	  }
	  free(data);
	}
	else
		return false;

 	f.Close();
	return true;
}
Ejemplo n.º 17
0
void AIScript::LoadXML()
{
    static int aidebug = XMLSupport::parse_int( vs_config->getVariable( "AI", "debug_level", "0" ) );
    using namespace AiXml;
    using namespace VSFileSystem;
    string     full_filename = filename;
    bool doroll = false;
    HardCodedMap::const_iterator iter = hard_coded_scripts.find( full_filename );
    if (iter==hard_coded_scripts.end() && full_filename.length() > 5 && full_filename[0] == 'r' && full_filename[1] == 'o' && full_filename[2] == 'l'
        && full_filename[3] == 'l' && full_filename[4] == ' ') {
        doroll = true;
        full_filename = full_filename.substr( 5 );
        iter = hard_coded_scripts.find( full_filename );
    }
    if ( iter != hard_coded_scripts.end() ) {
        CCScript *myscript = (*iter).second;
        (*myscript)(this, parent);
        if (doroll) {
            unsigned int val = rand();
            if (val < RAND_MAX/4)
                RollRightHard( this, parent );
            else if (val < RAND_MAX/2)
                RollLeftHard( this, parent );
            else
                RollLeft( this, parent );
        }
        if (aidebug > 1) {
            VSFileSystem::vs_fprintf( stderr, "%f using hcs %s for %s threat %f\n",
                                      mission->getGametime(), filename, parent->name.get().c_str(),
                                      parent->GetComputerData().threatlevel );
        }
        if ( _Universe->isPlayerStarship( parent->Target() ) ) {
            float value;
            static float game_speed = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
            static float game_accel = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_accel", "1" ) );
            {
                Unit *targ = parent->Target();
                if (targ) {
                    Vector PosDifference = ( targ->Position()-parent->Position() ).Cast();
                    float  pdmag = PosDifference.Magnitude();
                    value = ( pdmag-parent->rSize()-targ->rSize() );
                    float  myvel = pdmag > 0 ? PosDifference.Dot( parent->GetVelocity()-targ->GetVelocity() )/pdmag : 0;
                    if (myvel > 0)
                        value -= myvel*myvel/( 2*( parent->Limits().retro/parent->GetMass() ) );
                } else {
                    value = 10000;
                }
                value /= game_speed*game_accel;
            }
            if (aidebug > 0) {
                UniverseUtil::IOmessage( 0, parent->name, "all", string( "using script " )+string(
                                            filename )+" threat "+XMLSupport::tostring(
                                            parent->GetComputerData().threatlevel )+" dis "
                                        +XMLSupport::tostring( value ) );
            }
        }
        return;
    } else {
        if (aidebug > 1)
            VSFileSystem::vs_fprintf( stderr, "using soft coded script %s", filename );
        if (aidebug > 0)
            UniverseUtil::IOmessage( 0, parent->name, "all", string( "FAILED(or missile) script " )+string(
                                        filename )+" threat "+XMLSupport::tostring( parent->GetComputerData().threatlevel ) );
    }
#ifdef AIDBG
    VSFileSystem::vs_fprintf( stderr, "chd" );
#endif

#ifdef AIDBG
    VSFileSystem::vs_fprintf( stderr, "echd" );
#endif
    VSFile    f;
    VSError   err = f.OpenReadOnly( filename, AiFile );
#ifdef AIDBG
    VSFileSystem::vs_fprintf( stderr, "backup " );
#endif
    if (err > Ok) {
        VSFileSystem::vs_fprintf( stderr, "cannot find AI script %s\n", filename );
        if (hard_coded_scripts.find(filename)!=hard_coded_scripts.end()) {
            assert(0);
        }
        return;
    }
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "nxml" );
#endif
    xml = new AIScriptXML;
    xml->unitlevel  = 0;
    xml->terminate  = true;
    xml->afterburn  = true;
    xml->acc = 2;
    xml->defaultvec = QVector( 0, 0, 0 );
    xml->defaultf   = 0;
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "parscrea" );
#endif
    XML_Parser parser = XML_ParserCreate( NULL );
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "usdat %x", parser );
#endif
    XML_SetUserData( parser, this );
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "elha" );
#endif
    XML_SetElementHandler( parser, &AIScript::beginElement, &AIScript::endElement );
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "do" );
#endif
    XML_Parse( parser, ( f.ReadFull() ).c_str(), f.Size(), 1 );
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "%xxml_free", parser );
    fflush( stderr );
#endif
    XML_ParserFree( parser );
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "xml_freed" );
#endif
    f.Close();
    for (unsigned int i = 0; i < xml->orders.size(); i++) {
#ifdef BIDBG
        VSFileSystem::vs_fprintf( stderr, "parset" );
#endif
        xml->orders[i]->SetParent( parent );
        EnqueueOrder( xml->orders[i] );
#ifdef BIDBG
        VSFileSystem::vs_fprintf( stderr, "cachunkx" );
#endif
    }
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "xml%x", xml );
    fflush( stderr );
#endif
    delete xml;
#ifdef BIDBG
    VSFileSystem::vs_fprintf( stderr, "\\xml\n" );
    fflush( stderr );
#endif
}
void Texture::Load(const char * FileName, int stage, enum FILTER mipmap, enum TEXTURE_TARGET target, enum TEXTURE_IMAGE_TARGET imagetarget, GFXBOOL force_load, int maxdimension,GFXBOOL detailtexture,GFXBOOL nocache,enum ADDRESSMODE address_mode)
{
    if (data) free(data);
    if (palette) free(palette);
    data = NULL;
    palette = NULL;
    ismipmapped  = mipmap;
    texture_target =target;
    image_target=imagetarget;
    this->stage = stage;
    this->address_mode = address_mode;
    string texfn = string(FileName);
    if(checkbad(texfn))
        return;
    if (!nocache) {
        string tempstr;
        if (  checkold(texfn,false,tempstr)
                ||checkold(texfn,true,tempstr)  ) {
            texfilename = tempstr;
            return;
        }
    }

    //VSFileSystem::vs_fprintf (stderr,"1.Loading bmp file %s ",FileName);
    char *t= strdup (FileName);
    int tmp = strlen(FileName);
    if (tmp>3) {
        t[tmp-3] = 'a';
        t[tmp-2] = 'l';
        t[tmp-1] = 'p';
    }
    VSFile f2;
    VSError err2=VSFileSystem::FileNotFound;
    if (t) {
        if (t[0]!='\0') {
            static bool use_alphamap              = parse_bool(vs_config->getVariable("graphics",
                                                    "bitmap_alphamap",
                                                    "true"));
            if (use_alphamap)
                err2 = f2.OpenReadOnly(t, TextureFile);
        }
    }


    if(err2<=Ok) {
        //texfilename += string(t);
    }
    //	this->texfilename = texfilename;
    //strcpy (filename,texfilename.c_str());
    VSFile f;
    VSError err;
    if (FileName)
        if (FileName[0])
            err = f.OpenReadOnly (FileName, TextureFile);
    bool shared = (err==Shared);
    free ( t);
    if (err<=Ok&&g_game.use_textures==0&&!force_load) {
        f.Close();
        err = Unspecified;
    }
    if (err>Ok)
    {
        FileNotFound(texfn);
//		VSFileSystem::vs_fprintf (stderr, "\n%s, not found\n",FileName);
        if (err2<=Ok) {
            f2.Close();
        }
        return;
    }
    if (!nocache) {
        string tempstr;
        modold (texfn,shared,tempstr);
        texfilename = tempstr;
    }
    if (texfn.find("white")==string::npos)
        bootstrap_draw("Loading "+string(FileName));

    //	strcpy(filename, FileName);
    if( err2>Ok)
        data = this->ReadImage( &f, NULL, true, NULL);
    else
        data = this->ReadImage( &f, NULL, true, &f2);
    if (data)
    {
        if(mode >= _DXT1 && mode <= _DXT5) {
            if((int)data[0] == 0) {
                detailtexture = NEAREST;
                ismipmapped = NEAREST;
            }
        }
        Bind(maxdimension,detailtexture);
        free(data);
        data = NULL;
        if (!nocache) setold();
    }
    else
        FileNotFound(texfilename);
    f.Close();
    if( f2.Valid())
        f2.Close();
    //VSFileSystem::vs_fprintf (stderr," Load Success\n");
}