/// <summary> /// Generates all roads in the game /// We do this by first starting at each kingdom capital, and iterativly searching /// near grid points to find near by settlements and tactical locations. /// We then build roads to these locations, /// </summary> public void GenerateRoads() { Dictionary <int, Shell> kingdomCapitals = new Dictionary <int, Shell>(); //iterate each shell to find all kingdoms foreach (Shell s in SetAndTactShells) { Kingdom king = s.GetKingdom(); if (s is SettlementShell && (s as SettlementShell).Type == SettlementType.CAPITAL) { //Capitals are added to SetAndTacShells first, so should all be at start kingdomCapitals.Add(king.KingdomID, s); } } //Iterate each set of capitals and ensure there is a road conenction foreach (KeyValuePair <int, Shell> kvp1 in kingdomCapitals) { foreach (KeyValuePair <int, Shell> kvp2 in kingdomCapitals) { if (kvp1.Key == kvp2.Key) { continue; } BuildRoad(kvp1.Value.GridPoint, kvp2.Value.GridPoint); } } foreach (Shell s in SetAndTactShells) { int king = s.KingdomID; if (s is SettlementShell) { SettlementShell ss = s as SettlementShell; if (ss.Type == SettlementType.CAPITAL) { continue; } BuildRoad(ss.GridPoint, kingdomCapitals[king].GridPoint); } else if (s is TacticalLocationShell) { TacticalLocationShell tls = s as TacticalLocationShell; BuildRoad(tls.GridPoint, kingdomCapitals[king].GridPoint); } } }
public void SetPoint(GridPoint p) { bool isActive = false; this.p = p; Text = GetComponentInChildren <Text>(); if (p.Shell != null) { Button = GetComponent <Button>(); isActive = true; ColorBlock b = Button.colors; Color c = Color.black; if (p.Shell is SettlementShell) { SettlementShell ss = p.Shell as SettlementShell; if (ss.Type == SettlementType.CAPITAL) { c = Color.yellow; Text.text = "CA"; } else if (ss.Type == SettlementType.CITY) { c = Color.magenta; Text.text = "CI"; } else if (ss.Type == SettlementType.TOWN) { c = Color.blue; Text.text = "TO"; } else if (ss.Type == SettlementType.VILLAGE) { c = Color.green; Text.text = "VI"; } } else if (p.Shell is TacticalLocationShell) { TacticalLocationShell ss = p.Shell as TacticalLocationShell; if (ss.Type == TacLocType.fort) { c = Color.red; Text.text = "FO"; } else if (ss.Type == TacLocType.tower) { c = Color.cyan; Text.text = "TO"; } } else if (p.Shell is ChunkStructureShell) { ChunkStructureShell css = p.Shell as ChunkStructureShell; if (css.Type == ChunkStructureType.banditCamp) { c = Color.red; Text.text = "BA"; } else if (css.Type == ChunkStructureType.vampireNest) { c = new Color(0.5f, 0, 0.5f); Text.text = "VA"; } else if (css.Type == ChunkStructureType.kithenaCatacomb) { c = new Color(0, 0.5f, 0.5f); Text.text = "KI"; } else if (css.Type == ChunkStructureType.ancientTemple) { c = new Color(0, 0.5f, 0.5f); Text.text = "AT"; } else { c = Color.red; Text.text = "DA"; } } b.normalColor = c; Button.colors = b; } this.gameObject.SetActive(isActive); }
/// <summary> /// Decides the placement of all tactical locations /// </summary> /// <param name="ktl"></param> private Dictionary <int, Dictionary <TacLocType, List <TacticalLocationShell> > > DecideAllTacticalLocationPlacements(Dictionary <int, KingdomTotalTactialLocations> ktl) { Dictionary <int, Dictionary <TacLocType, List <TacticalLocationShell> > > tactPlace = new Dictionary <int, Dictionary <TacLocType, List <TacticalLocationShell> > >(); //Create data structure to hold tactical locations foreach (Kingdom k in GameGen.KingdomGen.Kingdoms) { tactPlace.Add(k.KingdomID, new Dictionary <TacLocType, List <TacticalLocationShell> >()); tactPlace[k.KingdomID].Add(TacLocType.fort, new List <TacticalLocationShell>()); tactPlace[k.KingdomID].Add(TacLocType.tower, new List <TacticalLocationShell>()); } bool shouldContinue = true; while (shouldContinue) { //if no points remain, we break if (DesireWeightedGridpoints.Count == 0) { shouldContinue = false; break; } //We a random point GridPoint gp = DesireWeightedGridpoints.GetRandom(true); ChunkBase2 cb = GameGen.TerGen.ChunkBases[gp.ChunkPos.x, gp.ChunkPos.z]; int kingdomID = cb.KingdomID; if (kingdomID == -1) { continue; } //We have now got to a valid settlement point so we check what type of settlement we need; TacLocType tactType = TacLocType.fort; if (tactPlace[kingdomID][TacLocType.fort].Count < ktl[kingdomID].FortCount) { tactType = TacLocType.fort; } else if (tactPlace[kingdomID][TacLocType.tower].Count < ktl[kingdomID].TowerCount) { tactType = TacLocType.tower; } else { Debug.Log("Already completed set placement for " + kingdomID); continue; } //Find the shorest distance int distSqr = FindShortestSquareDistance(tactPlace[kingdomID], gp); //the maximum distance int minDistSqr = GridPlacement.GridPointSize * GridPlacement.GridPointSize * 4; if (distSqr >= minDistSqr || distSqr < 0) { gp.HasTacLoc = true; gp.TACTYPE = tactType; TacticalLocationShell tls = new TacticalLocationShell(gp, kingdomID, tactType); gp.Shell = tls; tactPlace[kingdomID][tactType].Add(tls); } } return(tactPlace); }
private TacticalLocation GenerateTactLoc(TacticalLocationShell tls) { return(null); }