Пример #1
0
 /// <summary>
 /// Creates a search tree for map objects with the size of the map of this scenario.
 /// </summary>
 /// <returns>The created search tree.</returns>
 private ISearchTree <MapObject> CreateSearchTree()
 {
     return(new BspSearchTree <MapObject>(
                new RCNumRectangle(-(RCNumber)1 / (RCNumber)2,
                                   -(RCNumber)1 / (RCNumber)2,
                                   this.map.CellSize.X,
                                   this.map.CellSize.Y),
                ConstantsTable.Get <int>("RC.Engine.Maps.BspNodeCapacity"),
                ConstantsTable.Get <int>("RC.Engine.Maps.BspMinNodeSize")));
 }
Пример #2
0
        /// <summary>
        /// Creates the header package of the given map.
        /// </summary>
        /// <param name="map">Reference to the map.</param>
        /// <returns>The data package that contains the header of the given map.</returns>
        private RCPackage CreateMapHeaderPackage(IMapAccess map)
        {
            RCPackage mapHeader  = RCPackage.CreateCustomDataPackage(MapFileFormat.MAP_HEADER);
            Version   appVersion = new Version(ConstantsTable.Get <string>("RC.App.Version"));

            mapHeader.WriteInt(0, appVersion.Major);
            mapHeader.WriteInt(1, appVersion.Minor);
            mapHeader.WriteInt(2, appVersion.Build);
            mapHeader.WriteInt(3, appVersion.Revision);
            mapHeader.WriteString(4, map.MapName);
            mapHeader.WriteString(5, map.Tileset.Name);
            mapHeader.WriteShort(6, (short)map.Size.X);
            mapHeader.WriteShort(7, (short)map.Size.Y);
            mapHeader.WriteByte(8, (byte)8); // TODO: get the maximum number of players
            mapHeader.WriteIntArray(9, new int[0] {
            });                              // TODO: get checksum values of the map
            return(mapHeader);
        }
Пример #3
0
        static DssRoot()
        {
            APPLICATION_VERSION = new Version(ConstantsTable.Get <string>("RC.App.Version"));

            DSS_CTRL_CONN_REQUEST        = RCPackageFormatMap.Get("RC.DssServices.DssCtrlConnectionRequest");
            DSS_CTRL_CONN_ACK            = RCPackageFormatMap.Get("RC.DssServices.DssCtrlConnectionAcknowledge");
            DSS_CTRL_CONN_REJECT         = RCPackageFormatMap.Get("RC.DssServices.DssCtrlConnectionReject");
            DSS_CTRL_SETUP_STEP_RQ_BEGIN = RCPackageFormatMap.Get("RC.DssServices.DssCtrlSetupStepRqBegin");
            DSS_CTRL_SETUP_STEP_AW_BEGIN = RCPackageFormatMap.Get("RC.DssServices.DssCtrlSetupStepAwBegin");
            DSS_CTRL_SETUP_STEP_MSG_END  = RCPackageFormatMap.Get("RC.DssServices.DssCtrlSetupStepMsgEnd");
            DSS_CTRL_START_SIMULATION    = RCPackageFormatMap.Get("RC.DssServices.DssCtrlStartSimulation");
            DSS_SIM_ERROR       = RCPackageFormatMap.Get("RC.DssServices.DssSimulationError");
            DSS_COMMIT          = RCPackageFormatMap.Get("RC.DssServices.DssCommit");
            DSS_COMMIT_ANSWER   = RCPackageFormatMap.Get("RC.DssServices.DssCommitAnswer");
            DSS_CTRL_DROP_GUEST = RCPackageFormatMap.Get("RC.DssServices.DssCtrlDropGuest");
            DSS_LEAVE           = RCPackageFormatMap.Get("RC.DssServices.DssLeave");
            DSS_COMMAND         = RCPackageFormatMap.Get("RC.DssServices.DssCommand");
        }
Пример #4
0
        public CommandResult Execute(ConstantDeclaration declaration)
        {
            var constantSymbol = (Constant)declaration.Symbols.Single(s => s is Constant);

            if (ConstantsTable.ContainsKey(constantSymbol))
            {
                throw new Exception("Already defined");
            }

            var romanSymbol = (Roman)declaration.Symbols.Single(s => s is Roman);

            ConstantsTable.Add(constantSymbol, romanSymbol);

            return(new CommandResult
            {
                ResultText = String.Format("Information Registred: \"{0}\"", declaration),
                Sucess = true
            });
        }
Пример #5
0
        /// <see cref="IMapLoader.LoadMap"/>
        public IMapAccess LoadMap(ITileSet tileset, byte[] data)
        {
            if (!this.initThreadStarted)
            {
                throw new InvalidOperationException("Component has not yet been started!");
            }
            this.initThread.Join();

            if (tileset == null)
            {
                throw new ArgumentNullException("tileset");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            /// Load the packages from the byte array.
            RCPackage mapHeaderPackage      = null;
            RCPackage isotileListPackage    = null;
            RCPackage terrainObjListPackage = null;
            int       offset = 0;

            while (offset < data.Length)
            {
                int       parsedBytes;
                RCPackage package = RCPackage.Parse(data, offset, data.Length - offset, out parsedBytes);
                if (package == null || !package.IsCommitted)
                {
                    throw new MapException("Syntax error!");
                }
                offset += parsedBytes;
                if (package.PackageFormat.ID == MapFileFormat.MAP_HEADER)
                {
                    mapHeaderPackage = package;
                }
                else if (package.PackageFormat.ID == MapFileFormat.ISOTILE_LIST)
                {
                    isotileListPackage = package;
                }
                else if (package.PackageFormat.ID == MapFileFormat.TERRAINOBJ_LIST)
                {
                    terrainObjListPackage = package;
                }
            }

            /// Validate the packages.
            if (mapHeaderPackage == null)
            {
                throw new MapException("Syntax error: map header is missing!");
            }
            if (isotileListPackage == null)
            {
                throw new MapException("Syntax error: isometric-tile-list is missing!");
            }
            if (terrainObjListPackage == null)
            {
                throw new MapException("Syntax error: terrain-object-list is missing!");
            }

            /// Validate the map header.
            MapHeader mapHeader = MapHeader.FromPackage(mapHeaderPackage);

            if (mapHeader.AppVersion > new Version(ConstantsTable.Get <string>("RC.App.Version")))
            {
                throw new MapException(string.Format("Incompatible map version: {0}!", mapHeader.AppVersion));
            }
            if (mapHeader.TilesetName != tileset.Name)
            {
                throw new ArgumentException(string.Format("The given tileset '{0}' has to equal with the map tileset '{1}'!", tileset.Name, mapHeader.TilesetName), "tileset");
            }
            if (mapHeader.MapSize.X > MapStructure.MAX_MAPSIZE || mapHeader.MapSize.Y > MapStructure.MAX_MAPSIZE)
            {
                throw new MapException(string.Format("Map size exceeds the limits: {0}x{0}!", MapStructure.MAX_MAPSIZE));
            }

            MapAccess retObj = new MapAccess(mapHeader.MapName, this.mapStructure);

            this.mapStructure.BeginOpen(tileset, mapHeader.MapSize);
            this.LoadIsoTiles(isotileListPackage);
            this.mapStructure.EndOpen();

            this.LoadTerrainObjects(terrainObjListPackage, retObj);

            // TODO: validate MapHeader.MaxPlayers!
            // TODO: validate the MapHeader checksums!
            return(retObj);
        }
Пример #6
0
 public void SaveToConstantTable(Expression constant, Expression roman)
 {
     ConstantsTable.Add(constant, roman);
 }