public void MakeBuildingWithStoreysTest() { // arrange var buildingHeight = 10; var storeys = new List <Storey>(); storeys.Add(new Storey() { From = 0, To = 5, Color = "#ff0000" }); storeys.Add(new Storey() { From = 5, To = 10, Color = "#D3D3D3" }); var bs = new BuildingStyle() { FloorColor = "#D3D3D3", RoofColor = "#ff0000", WallsColor = "#00ff00" }; bs.Storeys = storeys; // act var res = TesselateBuilding.MakeBuilding(footprint, 0, buildingHeight, bs); // assert var footprintTriangles = TesselateBuilding.Tesselate(footprint, height).Count; Assert.IsTrue(res.polygons.Count == footprintTriangles * 2 + (footprint.ExteriorRing.Points.Count - 1) * 2 * storeys.Count); }
public static House GenerateHouse(Building building, BuildingStyle style, WorldObject wallType = null, Tile tileType = null) { int width = building.Width; int height = building.Height; Vec2i entr = GenerateWallsFloorAndEntrance(width, height, building.BuildingObjects, building.BuildingTiles, 0, BuildingStyle.stone, tileType: Tile.TEST_RED); //AddObject(building.BuildingObjects, WorldObject.BED, 2, 3); building.SetEntrancePoint(entr); return(building as House); }
public void TriangulateBuildingTest() { var bs = new BuildingStyle() { FloorColor = "#D3D3D3", RoofColor = "#ff0000", WallsColor = "#00ff00" }; var res = TesselateBuilding.MakeBuilding(footprint, 0, height, bs); var footprintTriangles = TesselateBuilding.Tesselate(footprint, height).Count; Assert.IsTrue(res.polygons.Count == footprintTriangles * 2 + (footprint.ExteriorRing.Points.Count - 1) * 2); }
public void MakePolyHedralTest() { var bs = new BuildingStyle() { FloorColor = "#D3D3D3", RoofColor = "#ff0000", WallsColor = "#00ff00" }; var res = TesselateBuilding.MakePolyHedral(footprint, 0, height, bs); var wkt = res.polyhedral.SerializeString <WktSerializer>(); Assert.IsTrue(wkt != null); }
public void GetByID_OneItem_ReturnsBuildingStyle() { // Arrange BuildingStyle entity = new BuildingStyle { ID = 1 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <BuildingStyle>(entity)); // Assert Assert.AreNotSame(entity, _cache.GetByID(1)); }
public void TestId12() { var wktFootprint = "POLYGON((-75.554412769 39.1634003080001, -75.554480102 39.163362636, -75.554508552 39.1633934610001, -75.554552455 39.163368898, -75.554609356 39.1634305470001, -75.554505101 39.163488876, -75.554412769 39.1634003080001))"; footprint = (Polygon)Geometry.Deserialize <WktSerializer>(wktFootprint); var height = 9.92000000000; var bs = new BuildingStyle() { FloorColor = "#D3D3D3", RoofColor = "#ff0000", WallsColor = "#00ff00" }; var res = TesselateBuilding.MakePolyHedral(footprint, 0, height, bs); Assert.IsTrue(res.polyhedral.Geometries.Count == 20); Assert.IsTrue(res.colors.Count == 20); }
public static MarketPlace GenerateMarket(MarketPlace building, BuildingStyle style = BuildingStyle.stone) { int width = building.Width; int height = building.Height; Vec2i entr = GenerateWallsFloorAndEntrance(width, height, building.BuildingObjects, building.BuildingTiles, 0, style, tileType: Tile.TEST_YELLOW); building.SetEntrancePoint(entr); MarketStall s1 = new MarketStall(new Vec2i(3, 3)); MarketStall s2 = new MarketStall(new Vec2i(building.Width - 3, building.Height - 3)); AddObject(building, s1, 3, 3); AddObject(building, s2, building.Width - 3, building.Height - 3); NPCJob[] jobs = new NPCJob[] { new NPCJobMarketStall("Market runner", building, s1), new NPCJobMarketStall("Market runner", building, s2) }; building.SetWorkBuildingData(new WorkBuildingData(jobs)); return(building); }
public void GetByID_TwoItems_ReturnsCorrectObject() { // Arrange BuildingStyle entity1 = new BuildingStyle { ID = 1 }; BuildingStyle entity2 = new BuildingStyle { ID = 2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <BuildingStyle>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <BuildingStyle>(entity2)); // Assert Assert.AreNotSame(entity1, _cache.GetByID(1)); Assert.AreNotSame(entity2, _cache.GetByID(2)); }
public Building CreateBuilding(Blueprint blueprint) { GameObject building = new GameObject("Building"); // TODO Give name that can even be displayed in game Mesh mesh = building.AddComponent <MeshFilter> ().mesh; MeshRenderer renderer = building.AddComponent <MeshRenderer> (); this.heightGrowth = blueprint.heightGrowth; this.buildingStyle = blueprint.buildingStyle; Vector3 dimension = new Vector3( Random.Range(blueprint.minBuildingWidth, blueprint.maxBuildingWidth), Random.Range(blueprint.minBuildingHeight, blueprint.maxBuildingHeight), Random.Range(blueprint.minBuildingWidth, blueprint.maxBuildingWidth)); CreateMesh(ref mesh, dimension, Random.Range(1, blueprint.maxStack + 1)); renderer.material = blueprint.defaultMaterial; return(new Building(dimension, building)); }
public void GetByID_RemovedItem_ReturnsCorrectObject() { // Arrange BuildingStyle entity1 = new BuildingStyle { ID = 1 }; BuildingStyle entity2 = new BuildingStyle { ID = 2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <BuildingStyle>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <BuildingStyle>(entity2)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <BuildingStyle>(entity1)); // Assert Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(1); }); Assert.AreNotSame(entity2, _cache.GetByID(2)); }
public void GetByID_NoItems_ThrowsKeyNotFoundException() { // Arrange BuildingStyle entity1 = new BuildingStyle { ID = 1 }; BuildingStyle entity2 = new BuildingStyle { ID = 2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <BuildingStyle>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <BuildingStyle>(entity2)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <BuildingStyle>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <BuildingStyle>(entity2)); // Assert Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(1); }); Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(2); }); }
public static Baracks GenerateBaracks(Baracks building, BuildingStyle style = BuildingStyle.stone) { int width = building.Width; int height = building.Height; Vec2i entr = GenerateWallsFloorAndEntrance(width, height, building.BuildingObjects, building.BuildingTiles, 0, style, tileType: Tile.TEST_PURPLE); building.SetEntrancePoint(entr); List <NPCJob> jobs = new List <NPCJob>(); for (int x = 2; x < building.Width; x += 3) { AddObject(building, new Bed(new Vec2i(2, 2)), x, 2); jobs.Add(new NPCJobSoldier(building)); } NPCJob[] jobs_ = jobs.ToArray(); building.SetWorkBuildingData(new WorkBuildingData(jobs_)); return(building); }
public static Blacksmith GenerateBlacksmith(Blacksmith building, BuildingStyle style = BuildingStyle.stone) { int width = building.Width; int height = building.Height; Vec2i entr = GenerateWallsFloorAndEntrance(width, height, building.BuildingObjects, building.BuildingTiles, 0, style, tileType: Tile.TEST_MAGENTA); building.SetEntrancePoint(entr); WorkEquiptmentData anvil = new Anvil(new Vec2i(1, 3)); WorkEquiptmentData forge = new Anvil(new Vec2i(4, 4)); AddObject(building, anvil, 1, 3); AddObject(building, forge, 4, 4); NPCJob[] jobs = new NPCJob[] { new NPCJobBlackSmith(building), new NPCJobBlackSmith(building), new NPCJobBlackSmith(building) }; building.SetWorkBuildingData(new WorkBuildingData(jobs)); AddEntrance(building, 0); //building.WorkEquiptment.Add(new WorkEquiptmentPlacement(anvil, new Vec2i(1, 3))); //building.WorkEquiptment.Add(new WorkEquiptmentPlacement(forge, new Vec2i(4, 4))); return(building); }
/// <summary> /// Generates the basic walls, floor, and entrance for any building. /// Picks the exact position of entrance, and returns it /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="buildingObjects">Building objects to be filled with walls</param> /// <param name="buildTiles"></param> /// <param name="entranceID"></param> /// <param name="style"></param> /// <returns></returns> public static Vec2i GenerateWallsFloorAndEntrance(int width, int height, WorldObjectData[,] buildingObjects, Tile[,] buildTiles, int entranceID, BuildingStyle style, int entraceDis = -1, WorldObjectData wallType = null, Tile tileType = null) { int entWidth = 2; if (entraceDis == -1) { if (entranceID == NORTH_ENTRANCE || entranceID == SOUTH_ENTRANCE) { entraceDis = MiscMaths.RandomRange(1, width - 1); } else { entraceDis = MiscMaths.RandomRange(1, height - 1); } } //Decide the position of the entrance Vec2i entrance = null; if (entranceID == NORTH_ENTRANCE) { entrance = new Vec2i(entraceDis, height - 1); } else if (entranceID == SOUTH_ENTRANCE) { entrance = new Vec2i(entraceDis, 0); } else if (entranceID == EAST_ENTRANCE) { entrance = new Vec2i(width - 1, entraceDis); } else if (entranceID == WEST_ENTRANCE) { entrance = new Vec2i(0, entraceDis); } //Assign correct wall type if none given if (wallType == null) { switch (style) { case BuildingStyle.stone: wallType = new BrickWall(new Vec2i(0, 0)); break; case BuildingStyle.wood: //TODO - Add wallType = new BrickWall(new Vec2i(0, 0)); break; } }//Asign correct tile type if none given if (tileType == null) { switch (style) { case BuildingStyle.stone: tileType = Tile.STONE_FLOOR; break; case BuildingStyle.wood: tileType = Tile.WOOD_FLOOR; break; } } //Iterate all points for (int x = 0; x < width; x++) { for (int z = 0; z < height; z++) { //Asign tile buildTiles[x, z] = tileType; if (x == 0 || x == width - 1 || z == 0 || z == height - 1) { //Asign wall if no entrance if (!(entrance.x == x & entrance.z == z)) { if (x == 3) { buildingObjects[x, z] = new BuildingWall(new Vec2i(0, 0), "brick", 5, new GlassWindow(new Vec2i(0, 0), new Vec2i(0, 1)), 2); } else { buildingObjects[x, z] = new BuildingWall(new Vec2i(0, -1), "brick", 5); } } } } } //(buildingObjects[0, 0] as BuildingWall).AddRoof(new Roof(new Vec2i(0, 0), new Vec2i(width, height))); return(entrance); }