예제 #1
0
        private IMapInfo GetMap(ref int cellX, ref int cellY)
        {
            var p = new Point(cellX, cellY);

            IMapInfo mi = null;

            for (var i = mapInfo.Count - 1; i >= 0; i--)
            {
                if (mapInfo[i].TileLocation.Contains(p))
                {
                    mi = mapInfo[i];
                    break;
                }
            }
            if (mi == null)
            {
                return(null);
            }

            cellX -= mi.TileLocation.X;
            cellY -= mi.TileLocation.Y;
            return(mi);
        }
예제 #2
0
        // -------------------- Constructor --------------------
        public Person(Point location, IMapInfo mapInfo, int speed = 1, int panic = 0)
        {
            rng = new Random();

            this.location    = location;
            this.mapInfo     = mapInfo;
            this.orientation = Orientation.South;
            this.speed       = speed;
            this.health      = 100; // Full health by default
            jumped           = false;

            if (panic != 0)
            {
                this.panic = panic;
            }
            else
            {
                panic = rng.Next(1, 41);
            }

            shouldFindNewPath = true;
            targetReached     = false;
            escaped           = false;
        }
예제 #3
0
 public MapCreationData(IMapInfo mapInfo, IReadOnlyCollection <ICellContent> userContents)
 {
     this.MapInfo      = mapInfo;
     this.UserContents = userContents;
 }
예제 #4
0
 // -------------------- Constructor --------------------
 public Teacher(Point location, IMapInfo room, int speed = 1, int panic = 0) : base(location, room, speed, panic)
 {
     goingForWindow = true;
     foundWindow    = null;
 }
예제 #5
0
        private void GenerateGeneralContents(Point location, IMapInfo parentMap)
        {
            bool northExit = location.Y < 0;
            bool southExit = location.Y > 0;
            bool westExit  = location.X < 0;
            bool eastExit  = location.X > 0;


            if (northExit)
            {
                GenerateSouthernTownEntrance(location, parentMap);
                GenerateEasternRiver(location, parentMap);
                GenerateWesternFence(location, parentMap);
                GenerateNorthernFence(location, parentMap);
            }
            FillCenterArea(location, parentMap);
            GeneratePointsOfInterests(location, parentMap);

            #region old code
            //for (var y = 0; y < levelDetail.SizeY; y += 8)
            //{
            //    for (var x = 0; x < levelDetail.SizeX; x += 8)
            //    {
            //        var px = location.X + x;
            //        var py = location.Y + y;

            //        if ((x == 0) && (y == 0)) // North West
            //        {
            //            gameState.InsertSubMap((int)eWildBorder.NorthWest, 2, new Point(px, py), parentMap, 0);
            //        }
            //        else if ((x == levelDetail.SizeX - 8) && (y == 0)) // North East
            //        {
            //            gameState.InsertSubMap((int)eWildBorder.NorthEast, 2, new Point(px, py), parentMap, 0);
            //        }
            //        else if ((x == levelDetail.SizeX - 8) && (y == levelDetail.SizeY - 8)) // South East
            //        {
            //            if (northExit)
            //            {
            //                gameState.InsertSubMap((int)eWildBorder.RiverUpper, 2, new Point(location.X + x, location.Y + y), parentMap, 0);
            //            }
            //            else gameState.InsertSubMap((int)eWildBorder.SouthEast, 2, new Point(px, py), parentMap, 0);
            //        }
            //        else if ((x == 0) && (y == levelDetail.SizeY - 8)) // South West
            //        {
            //            if (northExit)
            //            {
            //                gameState.InsertSubMap((int)eWildBorder.West, 2, new Point(px, py), parentMap, 0);
            //            }
            //            else gameState.InsertSubMap((int)eWildBorder.SouthWest, 2, new Point(px, py), parentMap, 0);
            //        }
            //        else if ((x == 0) && ((y % 8) == 0)) // West
            //        {
            //            if (westExit)
            //            {
            //                gameState.InsertSubMap((int)eWildBorder.RiverUpper, 2, new Point(px, py), parentMap, 3);
            //            }
            //            else if (eastExit)
            //            {
            //                // TODO: Transition to town
            //            }
            //            else gameState.InsertSubMap((int)eWildBorder.West, 2, new Point(px, py), parentMap, 0);
            //        }
            //        else if ((x == levelDetail.SizeX - 8) && ((y % 8) == 0)) // East
            //        {
            //            if (westExit)
            //            {
            //                // TODO: Transition to town
            //            }
            //            if (northExit || eastExit)
            //            {
            //                gameState.InsertSubMap((int)eWildBorder.RiverUpper, 2, new Point(px, py), parentMap, 3);
            //            }
            //            else gameState.InsertSubMap((int)eWildBorder.East, 2, new Point(px, py), parentMap, 0);
            //        }
            //        else if (((x % 8) == 0) && (y == 0)) // North
            //        {
            //            if (southExit)
            //            {

            //            }
            //            else gameState.InsertSubMap((int)eWildBorder.North, 2, new Point(px, py), parentMap, 0);
            //        }
            //        else if (((x % 8) == 0) && (y == (levelDetail.SizeY - 8))) // South
            //        {
            //            if (northExit)
            //            {
            //                //var tileIdx = 31; // 8x8 fill
            //                //gameState.InsertSubMap(tileIdx, new Point(bloodMooreRect.Left + x, bloodMooreRect.Top + y), townMap);
            //            }
            //            else gameState.InsertSubMap((int)eWildBorder.South, 2, new Point(px, py), parentMap, 0);
            //        }
            //        else
            //        {

            //            //if (((x % 8) == 0) && ((y % 8)) == 0)
            //            //{
            //            //    var tileIdx = 31; // 8x8 fill
            //            //    gameState.InsertSubMap(tileIdx, 2, new Point(px, py), parentMap, 0);
            //            //}

            //        }
            //    }
            //}
            #endregion
        }
예제 #6
0
 public void Generate(IMapInfo parentMap, Point location)
 {
     // Generate the area inside of the borders
     GenerateGeneralContents(location, parentMap);
 }
예제 #7
0
        private MapCellInfo GetMapCellInfo(IMapInfo map, int cellX, int cellY, MPQDS1TileProps props, eRenderCellType cellType, byte orientation)
        {
            if (props.Prop1 == 0)
            {
                return(null);
            }

            if (!map.CellInfo.ContainsKey(cellType))
            {
                map.CellInfo[cellType] = new MapCellInfo[map.FileData.Width * map.FileData.Height];
            }

            var cellInfo = map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)];

            if (cellInfo != null && (cellInfo.Ignore || !cellInfo.Tile.Animated))
            {
                return(cellInfo.Ignore ? null : cellInfo);
            }

            var mainIndex = (props.Prop3 >> 4) + ((props.Prop4 & 0x03) << 4);
            var subIndex  = props.Prop2;

            if (orientation == 0)
            {
                // Floor or Shadow
                if (cellType != eRenderCellType.Floor && cellType != eRenderCellType.Shadow)
                {
                    map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                        Ignore = true
                    };
                    return(null);
                }
            }
            else if (orientation == 10 || orientation == 11)
            {
                if (cellType != eRenderCellType.WallNormal)
                {
                    // Special tile
                    map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                        Ignore = true
                    };
                    return(null);
                }
            }
            else if (orientation == 14)
            {
                // Walls (objects?) with precedent shadows
                if (cellType != eRenderCellType.WallNormal)
                {
                    map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                        Ignore = true
                    };
                    return(null);
                }
            }
            else if (orientation < 15)
            {
                // Upper walls
                if (cellType != eRenderCellType.WallNormal)
                {
                    map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                        Ignore = true
                    };
                    return(null);
                }
            }
            else if (orientation == 15)
            {
                // Roof
                if (cellType != eRenderCellType.Roof)
                {
                    map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                        Ignore = true
                    };
                    return(null);
                }
            }
            else
            {
                // Lower Walls
                if (cellType != eRenderCellType.WallLower)
                {
                    map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                        Ignore = true
                    };
                    return(null);
                }
            }

            IEnumerable <MPQDT1Tile> tiles = Enumerable.Empty <MPQDT1Tile>();

            tiles = map.FileData.LookupTable
                    .Where(x => x.MainIndex == mainIndex && x.SubIndex == subIndex && x.Orientation == orientation)
                    .Select(x => x.TileRef);

            if (tiles == null || !tiles.Any())
            {
                log.Error($"Could not find tile [{mainIndex}:{subIndex}:{orientation}]!");
                map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                    Ignore = true
                };
                return(null);
            }

            MPQDT1Tile tile = null;

            if (tiles.First().Animated)
            {
#if DEBUG
                if (!tiles.All(x => x.Animated))
                {
                    throw new OpenDiablo2Exception("Some tiles are animated and some aren't...");
                }
#endif
                var frameIndex = (int)Math.Floor(tiles.Count() * animationTime);
                tile = tiles.ElementAt(frameIndex);
            }
            else
            {
                if (tiles.Any())
                {
                    var totalRarity = tiles.Sum(q => q.RarityOrFrameIndex);
                    var random      = new Random(Seed + cellX + (map.FileData.Width * cellY));
                    var x           = random.Next(totalRarity);
                    var z           = 0;
                    foreach (var t in tiles)
                    {
                        z += t.RarityOrFrameIndex;
                        if (x <= z)
                        {
                            tile = t;
                            break;
                        }
                    }

                    if (tile.Animated)
                    {
                        throw new OpenDiablo2Exception("Why are we randomly finding an animated tile? Something's wrong here.");
                    }
                }
                else
                {
                    tile = tiles.First();
                }
            }


            // This WILL happen to you
            if (tile.Width == 0 || tile.Height == 0)
            {
                map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                    Ignore = true
                };
                return(null);
            }


            if (tile.BlockDataLength == 0)
            {
                map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = new MapCellInfo {
                    Ignore = true
                };
                return(null); // Why is this a thing?
            }


            var mapCellInfo = mapDataLookup.FirstOrDefault(x => x.Tile.Id == tile.Id);
            if (mapCellInfo == null)
            {
                mapCellInfo = renderWindow.CacheMapCell(tile, cellType);
                mapDataLookup.Add(mapCellInfo);
            }

            map.CellInfo[cellType][cellX + (cellY * map.FileData.Width)] = mapCellInfo;
            return(mapCellInfo);
        }
예제 #8
0
        public IMapInfo InsertMap(int levelId, Point origin, IMapInfo parentMap = null)
        {
            var levelDetails = engineDataManager.Levels.First(x => x.Id == levelId);

            if (levelDetails.LevelPreset == null)
            {
                // There is no preset level, so we must generate one
                var generator = getRandomizedMapGenerator(levelDetails.LevelName);

                if (generator == null)
                {
                    throw new OpenDiablo2Exception($"Could not locate a map generator for '{levelDetails.LevelName}'.");
                }

                generator.Generate(parentMap, origin);

                // There is no core map so we cannot return a value here. If anyone actually uses
                // this value on a generated map they are making a terrible mistake anyway...
                return(null);
            }

            // Some maps have variations, so lets pick a random one
            var mapNames = new List <string>();

            if (levelDetails.LevelPreset.File1 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File1);
            }
            if (levelDetails.LevelPreset.File2 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File2);
            }
            if (levelDetails.LevelPreset.File3 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File3);
            }
            if (levelDetails.LevelPreset.File4 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File4);
            }
            if (levelDetails.LevelPreset.File5 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File5);
            }
            if (levelDetails.LevelPreset.File6 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File6);
            }


            var random = new Random(Seed);
            // -------------------------------------------------------------------------------------
            // var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count)].Replace("/", "\\");
            // -------------------------------------------------------------------------------------
            // TODO: ***TEMP FOR TESTING
            var mapName = "data\\global\\tiles\\" + mapNames[0].Replace("/", "\\");

            // -------------------------------------------------------------------------------------
            MapName = levelDetails.LevelPreset.Name;
            Act     = levelDetails.LevelType.Act;

            var fileData = resourceManager.GetMPQDS1(mapName, levelDetails.LevelPreset, levelDetails.LevelType);

            var result = new MapInfo
            {
                LevelId      = levelId,
                FileData     = fileData,
                CellInfo     = new Dictionary <eRenderCellType, MapCellInfo[]>(),
                TileLocation = new Rectangle(origin, new Size(fileData.Width - 1, fileData.Height - 1))
            };

            mapInfo.Add(result);

            // Only change music if loading a 'core' map
            if (Enum.IsDefined(typeof(eLevelId), levelId))
            {
                soundProvider.StopSong();
                soundProvider.LoadSong(mpqProvider.GetStream(ResourcePaths.GetMusicPathForLevel((eLevelId)levelId)));
                soundProvider.PlaySong();
            }


            return(result);
        }
예제 #9
0
        public IMapInfo InsertSubMap(int levelPresetId, int levelTypeId, Point origin, IMapInfo primaryMap, int subTile = -1)
        {
            var result = GetSubMapInfo(levelPresetId, levelTypeId, primaryMap, origin, subTile);

            mapInfo.Add(result);

            return(result);
        }
예제 #10
0
 public IMapInfo InsertMap(eLevelId levelId, IMapInfo parentMap = null) => InsertMap((int)levelId, new Point(0, 0), parentMap);
예제 #11
0
 public void AddMap(IMapInfo map) => mapInfo.Add(map);
예제 #12
0
 public MessageDataGameMap(IMapInfo mapInfo)
 {
     _mapInfo = mapInfo;
 }
예제 #13
0
 public void SetToUpdateMap(IMapInfo mapInfo)
 {
     _mapInfo = mapInfo;
 }
예제 #14
0
 public Table(IMapInfo map)
 {
    _map = map;
 }
예제 #15
0
 // -------------------- Constructor --------------------
 public Staff(Point location, IMapInfo room, int speed = 1, int panic = 0) : base(location, room, speed, panic)
 {
     goingForExtinguisher    = true;
     fightingFire            = false;
     equipedFireExtinguisher = null;
 }