상속: ContainerObject, IEnvironmentObject
예제 #1
0
        // does this living see location l in env
        public bool Sees(EnvironmentObject env, IntVector3 p)
        {
            if (env != this.Environment)
            {
                return(false);
            }

            IntVector3 dp = p - this.Location;

            switch (this.World.LivingVisionMode)
            {
            case LivingVisionMode.SquareFOV:
                return(dp.ComponentLength <= this.VisionRange);

            case LivingVisionMode.LOS:
                if (Math.Abs(dp.X) > this.VisionRange || Math.Abs(dp.Y) > this.VisionRange || Math.Abs(dp.Z) > this.VisionRange)
                {
                    return(false);
                }

                return(this.VisionMap[dp]);

            default:
                throw new Exception();
            }
        }
예제 #2
0
        public EnvObserver(EnvironmentObject env)
        {
            m_region = new Region();

            foreach (var ob in env.Inventory.OfType<ItemObject>().Where(item => item.ItemCategory == ItemCategory.Workbench))
                m_region.Add(new IntGrid2Z(ob.Location.ToIntPoint() - new IntVector2(2, 2), new IntSize2(5, 5), ob.Location.Z));
        }
예제 #3
0
        public VisionTrackerLOS(Player player, EnvironmentObject env)
        {
            Debug.Assert(env.VisibilityMode == VisibilityMode.LivingLOS);

            m_player = player;
            m_environment = env;
        }
        public VisionTrackerGlobalFOV(Player player, EnvironmentObject env)
        {
            Debug.Assert(env.VisibilityMode == VisibilityMode.GlobalFOV);

            m_player      = player;
            m_environment = env;
        }
예제 #5
0
        public AllVisibleVisionTracker(Player player, EnvironmentObject env)
        {
            Debug.Assert(env.VisibilityMode == VisibilityMode.AllVisible);

            m_player      = player;
            m_environment = env;
        }
예제 #6
0
        VisionTrackerBase GetVisionTrackerInternal(EnvironmentObject env)
        {
            if (m_seeAll)
            {
                return(AdminVisionTracker.Tracker);
            }

            VisionTrackerBase tracker;

            if (m_visionTrackers.TryGetValue(env, out tracker) == false)
            {
                switch (env.VisibilityMode)
                {
                case VisibilityMode.AllVisible:
                    tracker = new AllVisibleVisionTracker(this, env);
                    break;

                case VisibilityMode.GlobalFOV:
                    tracker = new VisionTrackerGlobalFOV(this, env);
                    break;

                case VisibilityMode.LivingLOS:
                    tracker = new VisionTrackerLOS(this, env);
                    break;

                default:
                    throw new NotImplementedException();
                }

                m_visionTrackers[env] = tracker;
            }

            return(tracker);
        }
예제 #7
0
        public AllVisibleVisionTracker(Player player, EnvironmentObject env)
        {
            Debug.Assert(env.VisibilityMode == VisibilityMode.AllVisible);

            m_player = player;
            m_environment = env;
        }
예제 #8
0
        public EnvTreeHandler(EnvironmentObject env, int targetNumTrees)
        {
            m_env            = env;
            m_targetNumTrees = targetNumTrees;

            m_numTrees = ParallelEnumerable.Range(0, m_env.Size.Depth).Sum(z =>
            {
                int sum = 0;
                for (int y = 0; y < m_env.Size.Height; ++y)
                {
                    for (int x = 0; x < m_env.Size.Width; ++x)
                    {
                        if (m_env.GetTileData(x, y, z).HasTree)
                        {
                            sum++;
                        }
                    }
                }

                return(sum);
            });

            m_env.TerrainOrInteriorChanged += OnTerrainOrInteriorChanged;

            m_env.World.TickEnding += OnTick;
        }
예제 #9
0
        public VisionTrackerGlobalFOV(Player player, EnvironmentObject env)
        {
            Debug.Assert(env.VisibilityMode == VisibilityMode.GlobalFOV);

            m_player = player;
            m_environment = env;
        }
예제 #10
0
        public VisionTrackerLOS(Player player, EnvironmentObject env)
        {
            Debug.Assert(env.VisibilityMode == VisibilityMode.LivingLOS);

            m_player      = player;
            m_environment = env;
        }
예제 #11
0
        public EnvWaterHandler(EnvironmentObject env)
        {
            m_env = env;

            ScanWaterTiles();

            m_env.World.TickEnding += OnTick;
        }
예제 #12
0
        public EnvWaterHandler(EnvironmentObject env)
        {
            m_env = env;

            ScanWaterTiles();

            m_env.World.TickEnding += OnTick;
        }
예제 #13
0
        public static EnvironmentObject Create(World world, Dwarrowdelf.TerrainGen.TerrainData terrain, VisibilityMode visMode,
                                               IntVector3 startLocation)
        {
            var ob = new EnvironmentObject(terrain, visMode, startLocation);

            ob.Initialize(world);
            return(ob);
        }
예제 #14
0
        public EnvWildlifeHandler(EnvironmentObject env)
        {
            m_env = env;
            /*
                        m_env.Contents
                            .OfType<LivingObject>()
                            .Where(o => o.LivingCategory == LivingCategory.Herbivore)
                            .Count();
             */

            //m_env.World.TickStarting += OnTickStarting;
        }
예제 #15
0
        public EnvWildlifeHandler(EnvironmentObject env)
        {
            m_env = env;

            /*
             *                      m_env.Contents
             *                              .OfType<LivingObject>()
             *                              .Where(o => o.LivingCategory == LivingCategory.Herbivore)
             *                              .Count();
             */

            //m_env.World.TickStarting += OnTickStarting;
        }
예제 #16
0
        public EnvTreeHandler(EnvironmentObject env, int targetNumTrees)
        {
            m_env = env;
            m_targetNumTrees = targetNumTrees;

            m_randomArray = new int[env.Width * env.Height];
            for (int i = 0; i < m_randomArray.Length; ++i)
                m_randomArray[i] = (ushort)i;

            MyMath.ShuffleArray(m_randomArray, m_env.World.Random);

            m_numTrees = m_env.Size.Range().Count(p => m_env.GetTileData(p).InteriorID.IsTree());

            m_env.TerrainOrInteriorChanged += OnTerrainOrInteriorChanged;
        }
예제 #17
0
        IntPoint3 GetRandomSurfaceLocation(Environment env, int zLevel)
        {
            IntPoint3 p;
            int       iter = 0;

            do
            {
                if (iter++ > 10000)
                {
                    throw new Exception();
                }

                p = new IntPoint3(m_random.Next(env.Width), m_random.Next(env.Height), zLevel);
            } while (!EnvironmentHelpers.CanEnter(env, p));

            return(p);
        }
예제 #18
0
        void CreateSheep(Environment env, int surfaceLevel)
        {
            var group = new Group();

            for (int i = 0; i < NUM_SHEEP; ++i)
            {
                var sheepBuilder = new LivingObjectBuilder(LivingID.Sheep)
                {
                    Color = this.GetRandomColor(),
                };
                var sheep = sheepBuilder.Create(env.World);
                var ai    = new HerbivoreAI(sheep);
                ai.Group = group;
                sheep.SetAI(ai);

                CreateItems(sheep, i);

                sheep.MoveTo(env, GetRandomSurfaceLocation(env, surfaceLevel));
            }
        }
예제 #19
0
        public EnvTreeHandler(EnvironmentObject env, int targetNumTrees)
        {
            m_env = env;
            m_targetNumTrees = targetNumTrees;

            m_numTrees = ParallelEnumerable.Range(0, m_env.Size.Depth).Sum(z =>
            {
                int sum = 0;
                for (int y = 0; y < m_env.Size.Height; ++y)
                    for (int x = 0; x < m_env.Size.Width; ++x)
                        if (m_env.GetTileData(x, y, z).HasTree)
                            sum++;

                return sum;
            });

            m_env.TerrainOrInteriorChanged += OnTerrainOrInteriorChanged;

            m_env.World.TickEnding += OnTick;
        }
예제 #20
0
        static void AddMonsters(EnvironmentObject env)
        {
            var world = env.World;

            for (int i = 0; i < NUM_ORCS; ++i)
            {
                var livingBuilder = new LivingObjectBuilder(LivingID.Orc)
                {
                    Color = GetRandomColor(),
                };

                var living = livingBuilder.Create(world);
                living.SetAI(new Dwarrowdelf.AI.MonsterAI(living, world.PlayerID));

                Helpers.AddGem(living);
                Helpers.AddBattleGear(living);

                living.MoveToMustSucceed(env, env.GetRandomEnterableSurfaceLocation());
            }
        }
예제 #21
0
        static void ClearFloor(EnvironmentObject env, IntVector3 p)
        {
            var td = env.GetTileData(p);

            if (td.HasFloor == false)
            {
                env.SetTileData(p.Down, TileData.GetNaturalWall(MaterialID.Granite));
                td = env.GetTileData(p);
            }

            if (td.IsGreen)
            {
                td.ID = TileID.Grass;
                td.MaterialID = GetRandomMaterial(MaterialCategory.Grass);
            }

            if (!td.IsClearFloor)
                throw new Exception();

            env.SetTileData(p, td);
        }
예제 #22
0
        public static void FinalizeEnv(EnvironmentObject env)
        {
            // Add gems to random locs
            for (int i = 0; i < 6; ++i)
                CreateItem(env, ItemID.Gem, GetRandomMaterial(MaterialCategory.Gem), env.GetRandomEnterableSurfaceLocation());

            // Add rocks to random locs
            for (int i = 0; i < 6; ++i)
                CreateItem(env, ItemID.Rock, GetRandomMaterial(MaterialCategory.Rock), env.GetRandomEnterableSurfaceLocation());

            CreateWorkbenches(env);

            CreateStartItems(env);
            CreateDebugItems(env);

            {
                var gen = FoodGenerator.Create(env.World);
                gen.MoveToMustSucceed(env, env.GetSurfaceLocation(env.Width / 2 - 2, env.Height / 2 - 2));
            }

            AddMonsters(env);
        }
예제 #23
0
        static void CreateWorkbenches(EnvironmentObject env)
        {
            int posx = env.Width / 2 - 10;
            int posy = env.Height / 2 - 10;

            var surface = env.GetSurfaceLevel(new IntVector2(posx, posy));

            {
                var p = new IntVector3(posx, posy, surface);
                ClearFloor(env, p);
                var item = CreateItem(env, ItemID.SmithsWorkbench, MaterialID.Iron, p);
                item.IsInstalled = true;
            }

            posx += 4;

            {
                var p = new IntVector3(posx, posy, surface);
                ClearFloor(env, p);
                var item = CreateItem(env, ItemID.CarpentersWorkbench, MaterialID.Oak, p);
                item.IsInstalled = true;
            }

            posx += 4;

            {
                var p = new IntVector3(posx, posy, surface);
                ClearFloor(env, p);
                var item = CreateItem(env, ItemID.MasonsWorkbench, MaterialID.Iron, p);
                item.IsInstalled = true;
            }

            posx = env.Width / 2 - 10;

            posy += 4;

            {
                var p = new IntVector3(posx, posy, surface);
                ClearFloor(env, p);
                var item = CreateItem(env, ItemID.SmelterWorkbench, MaterialID.Iron, p);
                item.IsInstalled = true;
            }

            posx += 4;

            {
                var p = new IntVector3(posx, posy, surface);
                ClearFloor(env, p);
                var item = CreateItem(env, ItemID.GemcuttersWorkbench, MaterialID.Iron, p);
                item.IsInstalled = true;
            }
        }
예제 #24
0
        private static void CreateStartItems(EnvironmentObject env)
        {
            var p = env.GetSurfaceLocation(env.Width / 2 - 1, env.Height / 2 - 4);

            ClearFloor(env, p);

            CreateItem(env, ItemID.Log, GetRandomMaterial(MaterialCategory.Wood), p);
            CreateItem(env, ItemID.Log, GetRandomMaterial(MaterialCategory.Wood), p);
            CreateItem(env, ItemID.Log, GetRandomMaterial(MaterialCategory.Wood), p);

            CreateItem(env, ItemID.Bar, GetRandomMaterial(MaterialCategory.Metal), p);
            CreateItem(env, ItemID.Bar, GetRandomMaterial(MaterialCategory.Metal), p);
            CreateItem(env, ItemID.Bar, GetRandomMaterial(MaterialCategory.Metal), p);

            CreateItem(env, ItemID.CarpentersWorkbench, GetRandomMaterial(MaterialCategory.Wood), p);
            CreateItem(env, ItemID.MasonsWorkbench, GetRandomMaterial(MaterialCategory.Wood), p);
        }
예제 #25
0
 static ItemObject CreateItem(EnvironmentObject env, ItemID itemID, MaterialID materialID, IntVector3 p)
 {
     var builder = new ItemObjectBuilder(itemID, materialID);
     var item = builder.Create(env.World);
     item.MoveToMustSucceed(env, p);
     return item;
 }
예제 #26
0
 public IVisionTracker GetVisionTracker(EnvironmentObject env)
 {
     return(GetVisionTrackerInternal(env));
 }
예제 #27
0
 public EnvObserver(EnvironmentObject env)
 {
     m_region = new Region();
 }
예제 #28
0
        // does this living see location l in env
        public bool Sees(EnvironmentObject env, IntPoint3 l)
        {
            if (env != this.Environment)
                return false;

            IntVector3 dl = l - this.Location;

            // XXX livings don't currently see up or down
            if (dl.Z != 0)
                return false;

            // is the target outside range?
            if (Math.Abs(dl.X) > this.VisionRange || Math.Abs(dl.Y) > this.VisionRange)
                return false;

            switch (World.LivingVisionMode)
            {
                case LivingVisionMode.SquareFOV:
                    return true;

                case LivingVisionMode.LOS:
                    if (this.VisionMap[new IntPoint2(dl.X, dl.Y)] == false)
                        return false;

                    return true;

                default:
                    throw new Exception();
            }
        }
예제 #29
0
        // does this living see location l in env
        public bool Sees(EnvironmentObject env, IntVector3 p)
        {
            if (env != this.Environment)
                return false;

            IntVector3 dp = p - this.Location;

            switch (this.World.LivingVisionMode)
            {
                case LivingVisionMode.SquareFOV:
                    return dp.ComponentLength <= this.VisionRange;

                case LivingVisionMode.LOS:
                    if (Math.Abs(dp.X) > this.VisionRange || Math.Abs(dp.Y) > this.VisionRange || Math.Abs(dp.Z) > this.VisionRange)
                        return false;

                    return this.VisionMap[dp];

                default:
                    throw new Exception();
            }
        }
예제 #30
0
		static void CreateWaterTest(EnvironmentObject env)
		{
			var pos = env.GetSurfaceLocation(env.Width / 2 + 10, env.Height / 2 - 10);

			int surface = pos.Z;

			CreateWalls(env, new IntGrid2Z(pos.X, pos.Y, 5, 8, surface));
			CreateWater(env, new IntGrid2Z(pos.X + 1, pos.Y + 1, 3, 6, surface));
			CreateWalls(env, new IntGrid2Z(pos.X + 2, pos.Y + 2, 1, 4, surface));

			if (true)
			{
				int x = pos.X + 1;
				int y = pos.Y + 1;

				ClearTile(env, new IntVector3(x, y, surface - 0));
				ClearTile(env, new IntVector3(x, y, surface - 1));
				ClearTile(env, new IntVector3(x, y, surface - 2));
				ClearTile(env, new IntVector3(x, y, surface - 3));
				ClearTile(env, new IntVector3(x, y, surface - 4));
				ClearTile(env, new IntVector3(x + 0, y, surface - 5));
				ClearTile(env, new IntVector3(x + 1, y, surface - 5));
				ClearTile(env, new IntVector3(x + 2, y, surface - 5));
				ClearTile(env, new IntVector3(x + 3, y, surface - 5));
				ClearTile(env, new IntVector3(x + 4, y, surface - 5));
				ClearTile(env, new IntVector3(x + 4, y, surface - 4));
				ClearTile(env, new IntVector3(x + 4, y, surface - 3));
				ClearTile(env, new IntVector3(x + 4, y, surface - 2));
				ClearTile(env, new IntVector3(x + 4, y, surface - 1));
				ClearTile(env, new IntVector3(x + 4, y, surface - 0));
			}

			if (true)
			{
				// Add a water generator
				var item = WaterGenerator.Create(env.World);
				item.MoveToMustSucceed(env, new IntVector3(pos.X + 1, pos.Y + 2, surface));
			}
		}
예제 #31
0
 public MapChange(EnvironmentObject map, IntVector3 l, TileData tileData)
     : base(map)
 {
     this.Location = l;
     this.TileData = tileData;
 }
예제 #32
0
 public MapChange(EnvironmentObject map, IntPoint3 l, TileData tileData)
     : base(map)
 {
     this.Location = l;
     this.TileData = tileData;
 }
예제 #33
0
파일: Area.cs 프로젝트: tomba/dwarrowdelf
        IntPoint3 GetRandomSurfaceLocation(Environment env, int zLevel)
        {
            IntPoint3 p;
            int iter = 0;

            do
            {
                if (iter++ > 10000)
                    throw new Exception();

                p = new IntPoint3(m_random.Next(env.Width), m_random.Next(env.Height), zLevel);
            } while (!EnvironmentHelpers.CanEnter(env, p));

            return p;
        }
예제 #34
0
 static void SetArea(EnvironmentObject env, IntGrid3 area, TileData data)
 {
     foreach (var p in area.Range())
         env.SetTileData(p, data);
 }
예제 #35
0
		public static void CreateWater(EnvironmentObject env, IntGrid2Z area)
		{
			for (int x = area.X1; x <= area.X2; ++x)
			{
				for (int y = area.Y1; y <= area.Y2; ++y)
				{
					var p = new IntVector3(x, y, area.Z);

					ClearTile(env, p);

					env.SetWaterLevel(p, TileData.MaxWaterLevel);
				}
			}
		}
예제 #36
0
		public static void CreateWalls(EnvironmentObject env, IntGrid2Z area)
		{
			for (int x = area.X1; x <= area.X2; ++x)
			{
				for (int y = area.Y1; y <= area.Y2; ++y)
				{
					if (y != area.Y1 && y != area.Y2 && x != area.X1 && x != area.X2)
						continue;

					var p = new IntVector3(x, y, area.Z);

					env.SetTileData(p, TileData.GetNaturalWall(MaterialID.Granite));
				}
			}
		}
예제 #37
0
        private static void CreateDebugItems(EnvironmentObject env)
        {
            var p = env.GetSurfaceLocation(env.Width / 2 - 1, env.Height / 2 - 2);

            ClearFloor(env, p);

            CreateItem(env, ItemID.Ore, MaterialID.Tin, p);
            CreateItem(env, ItemID.Ore, MaterialID.Tin, p);
            CreateItem(env, ItemID.Ore, MaterialID.Lead, p);
            CreateItem(env, ItemID.Ore, MaterialID.Lead, p);
            CreateItem(env, ItemID.Ore, MaterialID.Iron, p);
            CreateItem(env, ItemID.Ore, MaterialID.Iron, p);

            CreateItem(env, ItemID.Door, GetRandomMaterial(MaterialCategory.Wood), p);
            CreateItem(env, ItemID.Door, GetRandomMaterial(MaterialCategory.Wood), p);
            CreateItem(env, ItemID.Table, GetRandomMaterial(MaterialCategory.Wood), p);
            CreateItem(env, ItemID.Bed, GetRandomMaterial(MaterialCategory.Wood), p);
            CreateItem(env, ItemID.Chair, GetRandomMaterial(MaterialCategory.Wood), p);

            CreateItem(env, ItemID.Barrel, GetRandomMaterial(MaterialCategory.Wood), p);
            CreateItem(env, ItemID.Bin, GetRandomMaterial(MaterialCategory.Wood), p);

            CreateItem(env, ItemID.Block, GetRandomMaterial(MaterialCategory.Rock), p);
            CreateItem(env, ItemID.Block, GetRandomMaterial(MaterialCategory.Rock), p);
            CreateItem(env, ItemID.Block, GetRandomMaterial(MaterialCategory.Rock), p);
            CreateItem(env, ItemID.Block, GetRandomMaterial(MaterialCategory.Rock), p);
            CreateItem(env, ItemID.Block, GetRandomMaterial(MaterialCategory.Rock), p);

            CreateItem(env, ItemID.UncutGem, GetRandomMaterial(MaterialCategory.Gem), p);
            CreateItem(env, ItemID.UncutGem, GetRandomMaterial(MaterialCategory.Gem), p);
            CreateItem(env, ItemID.UncutGem, GetRandomMaterial(MaterialCategory.Gem), p);

            CreateItem(env, ItemID.Rock, GetRandomMaterial(MaterialCategory.Rock), p);
            CreateItem(env, ItemID.Rock, GetRandomMaterial(MaterialCategory.Rock), p);
            CreateItem(env, ItemID.Rock, GetRandomMaterial(MaterialCategory.Rock), p);

            p = p + new IntVector3(8, 0, 0);

            ClearFloor(env, p);

            var bed = CreateItem(env, ItemID.Bed, GetRandomMaterial(MaterialCategory.Wood), p);
            bed.IsInstalled = true;
        }
예제 #38
0
        bool TestStartArea(EnvironmentObject env, IntGrid2Z r)
        {
            foreach (var p in r.Range())
            {
                var terrainID = env.GetTerrainID(p);
                var interiorID = env.GetInteriorID(p);

                if (terrainID == TerrainID.NaturalFloor)
                    continue;
                else
                    return false;
            }

            return true;
        }
예제 #39
0
파일: Area.cs 프로젝트: tomba/dwarrowdelf
        void CreateSheep(Environment env, int surfaceLevel)
        {
            var group = new Group();

            for (int i = 0; i < NUM_SHEEP; ++i)
            {
                var sheepBuilder = new LivingObjectBuilder(LivingID.Sheep)
                {
                    Color = this.GetRandomColor(),
                };
                var sheep = sheepBuilder.Create(env.World);
                var ai = new HerbivoreAI(sheep);
                ai.Group = group;
                sheep.SetAI(ai);

                CreateItems(sheep, i);

                sheep.MoveTo(env, GetRandomSurfaceLocation(env, surfaceLevel));
            }
        }
예제 #40
0
        Player CreatePlayer(int playerNum, EnvironmentObject env)
        {
            const int NUM_DWARVES = 7;

            var player = new FortressPlayer(2 + playerNum, this, env);

            IntVector3 pos;

            switch (playerNum)
            {
                case 0:
                    pos = env.StartLocation;
                    break;

                case 1:
                    pos = env.GetSurfaceLocation(env.Width / 4, env.Height / 4);
                    break;

                case 2:
                    pos = env.GetSurfaceLocation(env.Width / 4 * 3, env.Height / 4 * 3);
                    break;

                default:
                    throw new Exception();
            }

            var startRect = FindStartLocation(env, pos);

            if (!startRect.HasValue)
                throw new Exception();

            player.EnvObserver.Add(startRect.Value);

            var startLocs = startRect.Value.Range().ToArray();

            // clear trees
            foreach (var p in startLocs)
            {
                var td = env.GetTileData(p);
                if (td.HasTree)
                {
                    td.ID = TileID.Grass;
                    td.MaterialID = MaterialID.RyeGrass;
                    env.SetTileData(p, td);
                }
            }

            var list = new List<LivingObject>();

            for (int i = 0; i < NUM_DWARVES; ++i)
            {
                var p = startLocs[Helpers.GetRandomInt(startLocs.Length - 1)];

                var l = CreateDwarf(i);

                l.SetAI(new DwarfAI(l, player.EnvObserver, this.World.PlayerID));

                l.MoveToMustSucceed(env, p);

                list.Add(l);
            }

            player.AddControllables(list);

            return player;
        }
예제 #41
0
 protected EnvironmentChange(EnvironmentObject env)
 {
     this.Environment = env;
 }
예제 #42
0
        bool TestStartArea(EnvironmentObject env, IntGrid2Z r)
        {
            foreach (var p in r.Range())
            {
                var td = env.GetTileData(p);

                if (td.IsWalkable)
                    continue;
                else
                    return false;
            }

            return true;
        }
예제 #43
0
        IntGrid2Z? FindStartLocation(EnvironmentObject env, IntVector3 pos)
        {
            const int size = 3;

            var center = pos;

            foreach (var p in IntVector2.SquareSpiral(center.ToIntVector2(), env.Width / 2))
            {
                if (env.Size.Plane.Contains(p) == false)
                    continue;

                var z = env.GetSurfaceLevel(p);

                var r = new IntGrid2Z(p.X - size, p.Y - size, size * 2, size * 2, z);

                if (TestStartArea(env, r))
                    return r;
            }

            return null;
        }
예제 #44
0
 protected EnvironmentChange(EnvironmentObject env)
 {
     this.Environment = env;
 }