/// <summary> /// Needs to be called when deserialized to get the references of non-serialized fields /// </summary> public void InitReferences(ElectionTacticsGame game) { District = game.Districts.First(x => x.Key.Id == DistrictId).Value; PartyPoints = PartyPointsById.ToDictionary(x => game.Parties.First(p => p.Id == x.Key), x => x.Value); Votes = VotesById.ToDictionary(x => game.Parties.First(p => p.Id == x.Key), x => x.Value); VoteShare = VoteShareById.ToDictionary(x => game.Parties.First(p => p.Id == x.Key), x => x.Value); Winner = game.Parties.First(x => x.Id == WinnerPartyId); }
private Language GetLanguageForNewRegion() // Languages can spread over land borders { List <Language> languageChances = new List <Language>(); languageChances.Add(ElectionTacticsGame.GetRandomLanguage()); foreach (Region r in Region.LandNeighbours) { if (Game.VisibleDistricts.ContainsKey(r)) { languageChances.Add(Game.VisibleDistricts[r].Language); } } return(languageChances[Random.Range(0, languageChances.Count)]); }
public void Init(ElectionTacticsGame game) { Game = game; if (Game.GameType == GameType.Singleplayer) { CountdownOverlay.gameObject.SetActive(false); CountdownText.gameObject.SetActive(false); EndTurnButtonText.text = "End Turn"; } else { CountdownOverlay.gameObject.SetActive(true); CountdownText.gameObject.SetActive(true); } }
/// <summary> /// Applies the district result to the game, meaning that it will get added to the districts history and victory points will be awarded. /// </summary> public void Apply(ElectionTacticsGame game) { // Add result to district District.ElectionResults.Add(this); District.CurrentWinnerParty = VoteShare.First(x => x.Value == VoteShare.Max(y => y.Value)).Key; District.CurrentWinnerShare = VoteShare.First(x => x.Value == VoteShare.Max(y => y.Value)).Value; // Award victory points Winner.Seats += Seats; Winner.TotalSeatsWon += Seats; Winner.TotalDistrictsWon++; foreach (Party p in game.Parties) { p.TotalVotes += Votes[p]; } }
public void Init(ElectionTacticsGame game) { Game = game; // Listeners TabPanels.Add(Tab.DistrictList, DistrictList.gameObject); TabButtons.Add(Tab.DistrictList, DistrictTabButton); DistrictTabButton.Button.onClick.AddListener(() => SelectTab(Tab.DistrictList)); TabPanels.Add(Tab.DistrictInfo, DistrictInfo.gameObject); TabButtons.Add(Tab.DistrictInfo, DistrictTabButton); TabPanels.Add(Tab.Parliament, Parliament.gameObject); TabButtons.Add(Tab.Parliament, ParliamentTabButton); ParliamentTabButton.Button.onClick.AddListener(() => SelectTab(Tab.Parliament)); TabPanels.Add(Tab.Constitution, Constitution.gameObject); TabButtons.Add(Tab.Constitution, ConstitutionTabButton); ConstitutionTabButton.Button.onClick.AddListener(() => SelectTab(Tab.Constitution)); TabPanels.Add(Tab.Events, Events.gameObject); TabButtons.Add(Tab.Events, EventsTabButton); EventsTabButton.Button.onClick.AddListener(() => SelectTab(Tab.Events)); TabPanels.Add(Tab.Policies, PolicySelection.gameObject); TabButtons.Add(Tab.Policies, PoliciesTabButton); PoliciesTabButton.Button.onClick.AddListener(() => SelectTab(Tab.Policies)); TabPanels.Add(Tab.Campaigns, Campaigns.gameObject); TabButtons.Add(Tab.Campaigns, CampaignsTabButton); CampaignsTabButton.Button.onClick.AddListener(() => SelectTab(Tab.Campaigns)); TabPanels.Add(Tab.Voting, Voting.gameObject); TabButtons.Add(Tab.Voting, VotingTabButton); VotingTabButton.Button.onClick.AddListener(() => SelectTab(Tab.Voting)); TabPanels.Add(Tab.Settings, Settings.gameObject); TabButtons.Add(Tab.Settings, SettingsTabButton); SettingsTabButton.Button.onClick.AddListener(() => SelectTab(Tab.Settings)); // Element initialization ElectionControls.Init(Game); }
/// <summary> /// Applies the result to the game, meaning that it will be added to the history and victory points will be awarded accordingly. /// </summary> public void Apply(ElectionTacticsGame game) { // Add result to the game game.AddGeneralElectionResult(this); // Apply district election results foreach (DistrictElectionResult result in DistrictResults) { result.Apply(game); } // Award total election victory points List <Party> winnerParties = game.Parties.Where(x => x.Seats == game.Parties.Max(y => y.Seats)).ToList(); foreach (Party p in winnerParties) { p.TotalElectionsWon++; } }
public Party(ElectionTacticsGame game, int id, string name, Color c, bool isAi) { Id = id; Game = game; Name = name; Acronym = ""; string[] words = name.Split(' '); foreach (string w in words) { Acronym += (w[0] + "").ToUpper(); } Color = c; IsHuman = !isAi; if (isAi) { AI = new PartyAI(this); IsReady = true; } }
private Religion GetReligionForNewRegion() // Religion can spread over land and water { List <Religion> religionChances = new List <Religion>(); foreach (Region r in Region.Neighbours) { Religion religion; if (Game.VisibleDistricts.ContainsKey(r)) { religion = Game.VisibleDistricts[r].Religion; } else { religion = ElectionTacticsGame.GetRandomReligion(); } religionChances.Add(religion); } return(religionChances[UnityEngine.Random.Range(0, religionChances.Count)]); }
public void Init(ElectionTacticsGame game, List <Party> parties) { // Parlialment party list Parties = parties; Dictionary <Party, int> listValues = new Dictionary <Party, int>(); foreach (Party p in parties.OrderByDescending(x => x.Seats)) { listValues.Add(p, p.Seats); } ParliamentPartyList.Init(listValues, dynamic: true); // Standings party list StandingsContainer.SetActive(true); if (game.Constitution == null) { StandingsDropdown.value = STANDINGS_ELECTIONS; } else if (game.Constitution.WinCondition.Type == WinConditionType.TotalElectionsWon) { StandingsDropdown.value = STANDINGS_ELECTIONS; } else if (game.Constitution.WinCondition.Type == WinConditionType.TotalSeatsWon) { StandingsDropdown.value = STANDINGS_SEATS; } else if (game.Constitution.WinCondition.Type == WinConditionType.TotalDistrictsWon) { StandingsDropdown.value = STANDINGS_DISTRICTS; } else if (game.Constitution.WinCondition.Type == WinConditionType.TotalVotes) { StandingsDropdown.value = STANDINGS_VOTES; } UpdateList(StandingsDropdown.value); }
public ElectionAnimationHandler(ElectionTacticsGame game) { Game = game; State = AnimationState.Inactive; }
private AgeGroup GetAgeGroupForNewRegion() // Age group is fully random { return(ElectionTacticsGame.GetRandomAgeGroup()); }
public void Init(ElectionTacticsGame game, MapDisplayMode mode) { Game = game; Map = game.Map; SetMapDisplayMode(mode); }
public DistrictSeatDistribution(ElectionTacticsGame game) : base(game) { ChapterTitle = "District Seat Distribution"; }
public void UpdateValues(ElectionTacticsGame game) { YearText.text = game.Year.ToString(); PPText.text = game.LocalPlayerParty.PolicyPoints.ToString(); CPText.text = game.LocalPlayerParty.CampaignPoints.ToString(); }
public void Init(ElectionTacticsGame game) { Game = game; }
public WinCondition(ElectionTacticsGame game) : base(game) { ChapterTitle = "Win Condition"; }
public Constitution(ElectionTacticsGame game) { Game = game; WinCondition = new WinCondition(game); Chapters.Add(WinCondition); }
public District(Random.State seed, ElectionTacticsGame game, Region r, string name) { Seed = seed; Game = game; Region = r; Name = name; Random.state = seed; SetGeographyTraits(); Density = GetDensityForNewRegion(); AgeGroup = GetAgeGroupForNewRegion(); Language = GetLanguageForNewRegion(); Religion = GetReligionForNewRegion(); Economy1 = ElectionTacticsGame.GetRandomEconomyTrait(); Economy2 = ElectionTacticsGame.GetRandomEconomyTrait(); while (Economy2 == Economy1) { Economy2 = ElectionTacticsGame.GetRandomEconomyTrait(); } Economy3 = ElectionTacticsGame.GetRandomEconomyTrait(); while (Economy3 == Economy2 || Economy3 == Economy1) { Economy3 = ElectionTacticsGame.GetRandomEconomyTrait(); } int numMentalities = Random.Range(1, 4); while (Mentalities.Count < numMentalities) { Mentality m = Game.GetRandomAdoptableMentality(this); Mentalities.Add(m); MentalityTypes.Add(m.Type); } // Population calculation Population = (int)(Region.Area * 1000000); float populationModifier = 0f; if (Density == Density.Urban) { populationModifier = Random.Range(1.2f, 1.6f); } if (Density == Density.Mixed) { populationModifier = Random.Range(0.8f, 1.2f); } if (Density == Density.Rural) { populationModifier = Random.Range(0.4f, 0.8f); } Population = (int)(Population * populationModifier); Population = (Population / 1000) * 1000; // Seat calculation int tmpPop = Population; int tmpSeatRequirement = RequiredPopulationPerSeat; int tmpSeats = 0; while (tmpPop >= tmpSeatRequirement) { tmpSeats++; tmpPop -= tmpSeatRequirement; tmpSeatRequirement += RequirementIncreasePerSeat; } Seats = Mathf.Max(MinSeats, tmpSeats); // Voter calculation if (MentalityTypes.Contains(MentalityType.Predictable)) { Voters = Random.Range(NumVotersPredictableMin, NumVotersPredictableMax + 1); } else if (MentalityTypes.Contains(MentalityType.Unpredictable)) { Voters = Random.Range(NumVotersUnpredictableMin, NumVotersUnpredictableMax + 1); } else { Voters = Random.Range(NumVotersDefaultMin, NumVotersDefaultMax + 1); } // Voter turnour if (MentalityTypes.Contains(MentalityType.LowVoterTurnout)) { VoterTurnout = Random.Range(VoterTurnoutLowMin, VoterTurnoutLowMax); } else if (MentalityTypes.Contains(MentalityType.HighVoterTurnout)) { VoterTurnout = Random.Range(VoterTurnoutHighMin, VoterTurnoutHighMax); } else { VoterTurnout = Random.Range(VoterTurnoutDefaultMin, VoterTurnoutDefaultMax); } }
public ConstitutionChapter(ElectionTacticsGame game) { Game = game; SetInitialRandomValues(); }