Пример #1
0
        public Map(string fname, RpgController rpgController)
        {
            scriptHandler = new MapScriptHandler(fname, this, rpgController);
            Stream s = ResourceManager.Open(fname);
            BinaryReader br = new BinaryReader(s);

            //signature
            string str = StringBufferReader.read(s,6);
            if(str != "V3MAP")
            throw new NotAMapFileException(fname);

            //version
            int version = br.ReadInt32();
            if(version != 2) throw new MapFileBrokenException("Wrong version; expected 2; received " + version.ToString(),fname);

            try
            {

            //vc offset (skipped)
            br.ReadInt32();

            //mapname,vspname,musicname,renderstring,startupscript
            name = StringBufferReader.read(s,256);
            vspfile = StringBufferReader.read(s,256);
            musicfile = StringBufferReader.read(s,256);
            rstring = StringBufferReader.read(s,256);
            initscript = StringBufferReader.read(s,256);

            //startloc
            start.X = br.ReadInt16();
            start.Y = br.ReadInt16();

            //layers
            int numLayers = br.ReadInt32();
            layers = new TileLayer[numLayers];
            for(int i=0;i<numLayers;i++)
            {
                TileLayer tl = layers[i] = new TileLayer();
                tl.loadFromv32stream(br);
            }

            width = layers[0].width;
            height = layers[0].height;

            //special layers
            logicalLayer = new LogicalLayer(width,height);
            logicalLayer.obs = new Layer(); logicalLayer.obs.loadSpecialFromv32stream(8,width,height,br);
            logicalLayer.zone = new Layer(); logicalLayer.zone.loadSpecialFromv32stream(16,width,height,br);

            //zones
            int numZonedefs = br.ReadInt32();
            zonedefs = new Zonedef[numZonedefs];
            for(int i=0;i<numZonedefs;i++)
            {
                zonedefs[i] = new Zonedef();
                zonedefs[i].name = StringBufferReader.read(s,256);
                zonedefs[i].script = StringBufferReader.read(s,256);
                zonedefs[i].percent = br.ReadByte();
                zonedefs[i].delay = br.ReadByte();
                zonedefs[i].method = br.ReadByte();
            }

            //entities

            int numEntdefs = br.ReadInt32();
            entdefs = new Entdef[numEntdefs];
            for(int i=0;i<numEntdefs;i++)
            {
                entdefs[i] = new Entdef();
                entdefs[i].index = i;
                entdefs[i].x = br.ReadInt16();
                entdefs[i].y = br.ReadInt16();
                entdefs[i].facing = (Directions)br.ReadByte();
                if(entdefs[i].facing == Directions.None) entdefs[i].facing = Directions.s;
                entdefs[i].obstructable = br.ReadByte()==1;
                entdefs[i].obstruction = br.ReadByte()==1;
                entdefs[i].autoface = br.ReadByte()==1;
                entdefs[i].speed = br.ReadInt16(); //convert this to carot ticks?
                br.ReadByte();//activation mode
                entdefs[i].mode = br.ReadByte();
                entdefs[i].x1 = br.ReadInt16();
                entdefs[i].y1 = br.ReadInt16();
                entdefs[i].x2 = br.ReadInt16();
                entdefs[i].y2 = br.ReadInt16();
                entdefs[i].wanderDelay = br.ReadInt16();//convert this to carot ticks?
                br.ReadInt32();//wtf?
                entdefs[i].moveScript = StringBufferReader.read(s,256);
                entdefs[i].chrname = StringBufferReader.read(s,256);
                entdefs[i].descr = StringBufferReader.read(s,256);
                entdefs[i].script = StringBufferReader.read(s,256);
            }
            }
            catch(Exception e)
            {
            throw new MapFileBrokenException("Something is wrong with the mapfile.  Here's what happened:\n" + e.Message,fname);
            }

            //load up the vsp
            try
            {
            vsp = new VSP(Lib.GetAccompanyingFilePath(fname,vspfile));
            }
            catch(FileNotFoundException e) {throw new VspFileNotFoundException(e.Message); }

            br.Close();
        }
Пример #2
0
 public ScriptCallack(String scriptName, MapScriptHandler scriptHandler)
 {
     this.scriptHandler = scriptHandler;
     this.scriptName = scriptName;
 }