private void HandleSelectedBuildingPlanChanged(BuildingPlan plan) { if (turretBuildingPannel != null) { turretBuildingPannel.Bind(plan); } }
public void ShowTurretBuildingPannel(BuildingPlan buildingPlan) { turretBuildingPannel.SetActive(true); imgTurret.sprite = buildingPlan.GetComponent <SpriteRenderer>().sprite; txtTurretBuildingDamage.text = "Damage: " + buildingPlan.TurretDamage; txtTurretBuildingSpeed.text = "Speed: " + buildingPlan.TurretSpeed; txtBuildersCount.text = buildingPlan.WorkersCount.ToString(); txtTimeLeft.text = "Time left: " + buildingPlan.TimeLeft; }
public override bool Equals(object obj) { if (obj == null) { return(false); } BuildingPlan bp = obj as BuildingPlan; if (bp == null) { return(false); } return(bp.Name == Name); }
/// <summary> /// Attempts to place generate a building based on <paramref name="bp"/> in the plot specified /// </summary> /// <param name="bp"></param> /// <param name="plot"></param> private bool GenBuildingInPlot(BuildingPlan bp, Plot plot) { Vec2i entrance = GenerationRandom.RandomFromArray(plot.EntranceSides); BuildingGenerationPlan bpPlan = new BuildingGenerationPlan() { BuildingPlan = bp, EntranceSide = entrance, MaxHeight = plot.Bounds.Height, MaxWidth = plot.Bounds.Width }; if (bp.MinSize > plot.Bounds.Width || bp.MinSize > plot.Bounds.Height) { return(false); } Building b = BuildingGenerator.CreateBuilding(GenerationRandom, out BuildingVoxels vox, bpPlan); Vec2i pos = new Vec2i(plot.Bounds.X, plot.Bounds.Y); if (entrance.x == -1) { pos = new Vec2i(plot.Bounds.X, plot.Bounds.Y + GenerationRandom.RandomIntFromSet(0, plot.Bounds.Height - b.Height)); } else if (entrance.x == 1) { pos = new Vec2i(plot.Bounds.X + (plot.Bounds.Width - b.Width), plot.Bounds.Y + GenerationRandom.RandomIntFromSet(0, plot.Bounds.Height - b.Height)); } else if (entrance.z == -1) { pos = new Vec2i(plot.Bounds.X + GenerationRandom.RandomIntFromSet(0, plot.Bounds.Width - b.Width), plot.Bounds.Y); } else if (entrance.z == 1) { pos = new Vec2i(plot.Bounds.X + GenerationRandom.RandomIntFromSet(0, plot.Bounds.Width - b.Width), plot.Bounds.Y + (plot.Bounds.Height - b.Height)); } Recti r = AddBuilding(b, vox, pos); if (r != null) { BuildingPlots.Add(r); return(true); } return(false); }
public void Bind(BuildingPlan buildingPlan) { if (buildingPlan != null) { buildingPlan.OnWorkersCountChanghed -= HandleWorkersChanged; buildingPlan.OnTimeOnBuildingChanged -= HandleTimeOnBuildingChanged; } boundPlan = buildingPlan; if (boundPlan != null) { boundPlan.OnWorkersCountChanghed += HandleWorkersChanged; buildingPlan.OnTimeOnBuildingChanged += HandleTimeOnBuildingChanged; HandleWorkersChanged(boundPlan.WorkersCount); HandleTimeOnBuildingChanged(boundPlan.TimeOnBuilding, boundPlan.TimeLeft); } }
public static void ChangeBuildingPlan(BuildingPlan plan) { OnSelectedBuildingPlanChanged?.Invoke(plan); }
/// <summary> /// Attempts to place multiple buildings inside this plot /// Works in order. i.e, if we can fit the first, we try to fit the second /// If we can't fit the second, we do no further checks /// If we can, we check the third.. and so on /// We return the number of buildings succesfully placed /// </summary> /// <param name="bps"></param> /// <param name="startIndex">The index of the first building to place</param> /// <param name="plot"></param> /// <returns>The number of buildings placed in this plot, between 0 and 4 (incusive)</returns> private int GenMultipleBuildingsInPlot(List <BuildingPlan> bps, int startIndex, Plot plot) { //Represents 4 points for 4 corners of plot bool[,] isCornerPossible = new bool[2, 2]; bool[] sideHasPath = new bool[4]; //Iterate all entrances foreach (Vec2i v in plot.EntranceSides) { if (v.x == -1) { sideHasPath[0] = true; isCornerPossible[0, 0] = true; isCornerPossible[0, 1] = true; } else if (v.x == 1) { sideHasPath[1] = true; isCornerPossible[1, 0] = true; isCornerPossible[1, 1] = true; } if (v.z == -1) { sideHasPath[2] = true; isCornerPossible[0, 0] = true; isCornerPossible[1, 0] = true; } else if (v.z == 1) { sideHasPath[3] = true; isCornerPossible[0, 1] = true; isCornerPossible[1, 1] = true; } } //Buildings sorted by the corner they have been placed in Recti[,] bounds = new Recti[2, 2]; int j = 0; for (int x = 0; x < 2; x++) { for (int z = 0; z < 2; z++) { //Index of adjacect x, and adjacent z int adjX = (x + 1) % 2; int adjZ = (x + 1) % 2; Recti adjacentX = bounds[adjX, z]; int adjacentXWidth = adjacentX == null ? 0 : adjacentX.Width; Recti adjacentZ = bounds[x, adjZ]; int adjacentZHeight = adjacentZ == null ? 0 : adjacentZ.Height; //check this corner is free if (isCornerPossible[x, z]) { if (startIndex + j >= bps.Count) { return(j); } BuildingPlan plan = bps[startIndex + j]; int maxWidth = plot.Bounds.Width - adjacentXWidth; int maxHeight = plot.Bounds.Height - adjacentZHeight; //If it won't fit, we continue if (maxWidth < plan.MinSize || maxHeight < plan.MinSize) { continue; } int desWidth = GenerationRandom.RandomInt(plan.MinSize, Mathf.Min(plan.MaxSize, maxWidth)); int desHeight = GenerationRandom.RandomInt(plan.MinSize, Mathf.Min(plan.MaxSize, maxHeight)); List <Vec2i> posSides = new List <Vec2i>(); Vec2i entranceSide = null; Vec2i pos = null; //We calculate the entrance side and position of each building if (x == 0 && z == 0) { if (sideHasPath[2]) { posSides.Add(new Vec2i(0, -1)); } if (sideHasPath[0]) { posSides.Add(new Vec2i(-1, 0)); } if (posSides.Count == 0) { continue; } entranceSide = GenerationRandom.RandomFromList(posSides); pos = new Vec2i(plot.Bounds.X, plot.Bounds.Y); } else if (x == 0 && z == 1) { if (sideHasPath[3]) { posSides.Add(new Vec2i(0, 1)); } if (sideHasPath[0]) { posSides.Add(new Vec2i(-1, 0)); } if (posSides.Count == 0) { continue; } entranceSide = GenerationRandom.RandomFromList(posSides); pos = new Vec2i(plot.Bounds.X + 2, plot.Bounds.Y + plot.Bounds.Height - desHeight); } else if (x == 1 && z == 1) { if (sideHasPath[3]) { posSides.Add(new Vec2i(0, 1)); } if (sideHasPath[1]) { posSides.Add(new Vec2i(1, 0)); } if (posSides.Count == 0) { continue; } entranceSide = GenerationRandom.RandomFromList(posSides); pos = new Vec2i(plot.Bounds.X + plot.Bounds.Width - desWidth, plot.Bounds.Y + plot.Bounds.Height - desHeight); } else if (x == 1 && z == 0) { if (sideHasPath[2]) { posSides.Add(new Vec2i(0, -1)); } if (sideHasPath[1]) { posSides.Add(new Vec2i(1, 0)); } if (posSides.Count == 0) { continue; } entranceSide = GenerationRandom.RandomFromList(posSides); pos = new Vec2i(plot.Bounds.X + plot.Bounds.Width - desWidth, plot.Bounds.Y); } Recti curBound = new Recti(pos.x, pos.z, desWidth, desHeight); bool intersect = false; foreach (Recti ri in bounds) { if (ri != null) { if (ri.Intersects(curBound)) { intersect = true; } } } if (intersect) { continue; } bounds[x, z] = curBound; BuildingGenerationPlan curCorn = new BuildingGenerationPlan() { BuildingPlan = bps[startIndex + j], MaxWidth = maxWidth, MaxHeight = maxHeight, EntranceSide = entranceSide, DesiredSize = new Vec2i(desWidth, desHeight) }; Building build = BuildingGenerator.CreateBuilding(GenerationRandom, out BuildingVoxels vox, curCorn); Recti r = AddBuilding(build, vox, pos); if (r != null) { BuildingPlots.Add(r); j++; } } } } return(j); }
/// <summary> /// Takes a building plan and generates a full building from it. /// TODO - Currently messy, fix /// </summary> /// <param name="plan"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="entrance"></param> /// <returns></returns> public static Building CreateBuilding(BuildingPlan plan, int width = -1, int height = -1, int entrance = 0) { if (width == -1) { width = MiscMaths.RandomRange(plan.MinSize, plan.MaxSize); } else if (width < plan.MinSize) { width = plan.MinSize; } else if (width > plan.MaxSize) { width = plan.MaxSize; } if (height == -1) { height = MiscMaths.RandomRange(plan.MinSize, plan.MaxSize); } else if (height < plan.MinSize) { height = plan.MinSize; } else if (height > plan.MaxSize) { height = plan.MaxSize; } Tile[,] buildingBase = new Tile[width, height]; WorldObjectData[,] buildingObjects = new WorldObjectData[width, height]; if (plan == Building.HOUSE) { House h = new House(width, height); h.SetBuilding(buildingBase, buildingObjects); return(GenerateHouse(h, BuildingStyle.stone)); } if (plan == Building.BLACKSMITH) { Blacksmith b = new Blacksmith(width, height); b.SetBuilding(buildingBase, buildingObjects); return(GenerateBlacksmith(b, BuildingStyle.stone)); } if (plan == Building.MARKET) { MarketPlace market = new MarketPlace(width, height); market.SetBuilding(buildingBase, buildingObjects); return(GenerateMarket(market, BuildingStyle.stone)); } if (plan == Building.BARACKS) { Baracks baracks = new Baracks(width, height); baracks.SetBuilding(buildingBase, buildingObjects); return(GenerateBaracks(baracks)); } /* * if(plan == Building.MARKET) * { * MarketPlace market = new MarketPlace(width, height); * market.SetBuilding(buildingBase, buildingObjects); * return GenerateMarket(market, BuildingStyle.stone); * } * if(plan == Building.BARACKSCITY) * { * Baracks bar = new Baracks(width, height); * bar.SetBuilding(buildingBase, buildingObjects); * return GenerateCityBaracks(bar); * } * if (plan == Building.BARACKSCITY || plan == Building.BARACKSTOWN) * { * * }*/ //Default for now House ht = new House(width, height); ht.SetBuilding(buildingBase, buildingObjects); return(GenerateHouse(ht, BuildingStyle.stone)); }
public void GenerateSettlement() { //ChooseRandomEntrancePoints(); AddInitPaths(); List <BuildingPlan> mustAdd = new List <BuildingPlan>(); BuildingPlan defaultRemaining = Building.HOUSE; switch (SettlementType) { case SettlementType.CAPITAL: AddMainBuilding(BuildingGenerator.GenerateCastle(48)); mustAdd.Add(Building.BLACKSMITH); mustAdd.Add(Building.MARKET); mustAdd.Add(Building.BARACKS); mustAdd.Add(Building.BLACKSMITH); mustAdd.Add(Building.BLACKSMITH); mustAdd.Add(Building.BLACKSMITH); mustAdd.Add(Building.BLACKSMITH); mustAdd.Add(Building.BLACKSMITH); /* * mustAdd.Add(Building.MARKET); * mustAdd.Add(Building.BARACKSCITY); * mustAdd.Add(Building.TAVERN); * mustAdd.Add(Building.BLACKSMITH); * mustAdd.Add(Building.ALCHEMISTS); * mustAdd.Add(Building.TAVERN); * mustAdd.Add(Building.BLACKSMITH); * mustAdd.Add(Building.TAVERN); * mustAdd.Add(Building.GENERALMERCHANT); * mustAdd.Add(Building.ARCHERYSTORE); * mustAdd.Add(Building.SWORDSELLER); */ for (int i = 0; i < 20; i++) { mustAdd.Add(Building.HOUSE); } defaultRemaining = Building.HOUSE; break; case SettlementType.CITY: AddMainBuilding(BuildingGenerator.GenerateCastle(32)); //mustAdd.Add(Building.BARACKSCITY); mustAdd.Add(Building.BLACKSMITH); /* * mustAdd.Add(Building.GENERALMERCHANT); * mustAdd.Add(Building.TAVERN); * mustAdd.Add(Building.MARKET); */ for (int i = 0; i < 15; i++) { mustAdd.Add(Building.HOUSE); } break; case SettlementType.TOWN: AddMainBuilding(BuildingGenerator.CreateBuilding(Building.HOLD)); //mustAdd.Add(Building.BARACKSTOWN); mustAdd.Add(Building.BLACKSMITH); /*mustAdd.Add(Building.GENERALMERCHANT); * mustAdd.Add(Building.TAVERN); * mustAdd.Add(Building.MARKET);*/ for (int i = 0; i < 10; i++) { mustAdd.Add(Building.HOUSE); } break; case SettlementType.VILLAGE: AddMainBuilding(BuildingGenerator.CreateBuilding(Building.VILLAGEHALL)); mustAdd.Add(Building.BLACKSMITH); /* * mustAdd.Add(Building.GENERALMERCHANT); * mustAdd.Add(Building.TAVERN); * mustAdd.Add(Building.MARKET);*/ for (int i = 0; i < 6; i++) { mustAdd.Add(Building.HOUSE); } break; } PlaceBuildings(mustAdd); CreatePathNodes(); foreach (Building b in Buildings) { } }