|
- using System;
- using System.Collections.Generic;
- using SUISS.Storage;
- using SUISSEngine;
- using UnityEngine;
-
- public class CIGIslandState : IslandState
- {
- protected override void Awake()
- {
- base.Awake();
- }
-
- protected override void Start()
- {
- base.Start();
- }
-
- protected override void OnNewGameState()
- {
- base.OnNewGameState();
- this.SetValue("Propagate", this.propagate);
- this.Happiness = 0;
- this.Population = 0;
- this.Housing = 0;
- this.Employees = 0;
- this.Jobs = 0;
- this.Transport = this.baseTransport;
- if (this.baseHappiness != 0)
- {
- this.AddHappiness(this.baseHappiness);
- }
- }
-
- public int Happiness
- {
- get
- {
- return this.GetValue<int>("Happiness", 0);
- }
- private set
- {
- this.SetValue("Happiness", value);
- }
- }
-
- public int AvailableHappiness
- {
- get
- {
- if (this.infiniteTransport)
- {
- return this._gameState.reference.GlobalHappiness;
- }
- int num = this.Happiness;
- int transport = this.Transport;
- if (transport > 0)
- {
- int num2 = this._gameState.reference.GlobalHappiness - this._gameState.reference.GlobalHousing - (this.Happiness - this.Housing);
- if (num2 > 0)
- {
- num += Mathf.Min(num2, transport);
- }
- }
- return num;
- }
- }
-
- public int Population
- {
- get
- {
- return this.GetValue<int>("Population", 0);
- }
- private set
- {
- this.SetValue("Population", value);
- }
- }
-
- public int AvailablePopulation
- {
- get
- {
- if (this.infiniteTransport)
- {
- return this._gameState.reference.GlobalPopulation;
- }
- int num = this.Population;
- int transport = this.Transport;
- if (transport > 0)
- {
- int num2 = this._gameState.reference.GlobalPopulation - this._gameState.reference.GlobalJobs - (this.Population - this.Jobs);
- if (num2 > 0)
- {
- num += Mathf.Min(num2, transport);
- }
- }
- return num;
- }
- }
-
- public int Housing
- {
- get
- {
- return this.GetValue<int>("Housing", 0);
- }
- private set
- {
- this.SetValue("Housing", value);
- }
- }
-
- public int Employees
- {
- get
- {
- return this.GetValue<int>("Employees", 0);
- }
- private set
- {
- this.SetValue("Employees", value);
- }
- }
-
- public int Jobs
- {
- get
- {
- return this.GetValue<int>("Jobs", 0);
- }
- private set
- {
- this.SetValue("Jobs", value);
- }
- }
-
- public int Transport
- {
- get
- {
- return this.GetValue<int>("Transport", 0);
- }
- private set
- {
- this.SetValue("Transport", value);
- }
- }
-
- public bool Propagate
- {
- get
- {
- return this.GetValue<bool>("Propagate", false);
- }
- set
- {
- bool flag = this.Propagate;
- this.SetValue("Propagate", value);
- if (flag != this.Propagate)
- {
- this.AddGlobalValues((!value) ? -1 : 1);
- }
- }
- }
-
- protected void AddGlobalValues(int factor)
- {
- this._gameState.reference.AddGlobalPopulation(factor * this.Population);
- this._gameState.reference.AddGlobalHousing(factor * this.Housing);
- this._gameState.reference.AddGlobalHappiness(factor * this.Happiness);
- this._gameState.reference.AddGlobalEmployees(factor * this.Employees);
- this._gameState.reference.AddGlobalJobs(factor * this.Jobs);
- }
-
- public void AddPopulation(int pop)
- {
- this.Population += pop;
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalPopulation(pop);
- }
- }
-
- public void AddHousing(int room)
- {
- this.Housing += room;
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalHousing(room);
- }
- }
-
- public void AddHappiness(int smiles)
- {
- this.Happiness += smiles;
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalHappiness(smiles);
- }
- }
-
- public void AddEmployees(int emp)
- {
- this.Employees += emp;
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalEmployees(emp);
- }
- }
-
- public void AddJobs(int jobs)
- {
- this.Jobs += jobs;
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalJobs(jobs);
- }
- }
-
- public void AddTransport(int x)
- {
- this.Transport += x;
- }
-
- public Currencies CalculateProfitPerHour()
- {
- Currencies currencies = Currencies.Zero;
- foreach (GridTile gridTile in IsometricIsland.Current.grid.Tiles)
- {
- CIGCommercialBuilding component = gridTile.GetComponent<CIGCommercialBuilding>();
- if (component != null)
- {
- currencies += component.ProfitPerHour;
- }
- }
- return currencies;
- }
-
- public static Dictionary<string, object> GetDictionary(Island island)
- {
- Storage storage = Storage.Get(StorageLifecycle.Game);
- string key = island.ToString() + "State";
- if (storage.Root.ContainsKey(key))
- {
- return (Dictionary<string, object>)storage.Root[key];
- }
- return new Dictionary<string, object>();
- }
-
- public void LoadValuesFromBuildings()
- {
- bool flag = false;
- int num = 0;
- int num2 = 0;
- foreach (CIGCommercialBuilding cigcommercialBuilding in UnityEngine.Object.FindObjectsOfType<CIGCommercialBuilding>())
- {
- num += cigcommercialBuilding.Employees;
- num2 += cigcommercialBuilding.MaxEmployees;
- }
- if (num != this.Employees || num2 != this.Jobs)
- {
- UnityEngine.Debug.LogWarning(string.Format("Employees gamestate values changed from {2}/{3} to {0}/{1}.", new object[]
- {
- num,
- num2,
- this.Employees,
- this.Jobs
- }));
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalJobs(num2 - this.Jobs);
- }
- this.Jobs = num2;
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalEmployees(num - this.Employees);
- }
- this.Employees = num;
- flag = true;
- }
- int num3 = 0;
- int num4 = 0;
- foreach (CIGResidentialBuilding cigresidentialBuilding in UnityEngine.Object.FindObjectsOfType<CIGResidentialBuilding>())
- {
- num3 += cigresidentialBuilding.People;
- num4 += cigresidentialBuilding.MaxPeople;
- }
- if (num3 != this.Population || num4 != this.Housing)
- {
- UnityEngine.Debug.LogWarning(string.Format("Employees gamestate values changed from {2}/{3} to {0}/{1}.", new object[]
- {
- num3,
- num4,
- this.Population,
- this.Housing
- }));
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalHousing(num4 - this.Housing);
- }
- this.Housing = num4;
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalPopulation(num3 - this.Population);
- }
- this.Population = num3;
- flag = true;
- }
- int num5 = this.baseHappiness;
- foreach (CIGBuilding cigbuilding in UnityEngine.Object.FindObjectsOfType<CIGBuilding>())
- {
- num5 += cigbuilding.Happiness;
- }
- foreach (CIGScenery cigscenery in UnityEngine.Object.FindObjectsOfType<CIGScenery>())
- {
- num5 += cigscenery.happiness;
- }
- if (num5 != this.Happiness)
- {
- UnityEngine.Debug.LogWarning(string.Format("Happiness gamestate value changed from {1} to {0}.", num5, this.Happiness));
- if (this.Propagate)
- {
- this._gameState.reference.AddGlobalHappiness(num5 - this.Happiness);
- }
- this.Happiness = num5;
- flag = true;
- }
- if (flag)
- {
- StorageController.SaveAll();
- }
- }
-
- public const string HappinessKey = "Happiness";
-
- public const string PopulationKey = "Population";
-
- public const string HousingKey = "Housing";
-
- public const string EmployeesKey = "Employees";
-
- public const string JobsKey = "Jobs";
-
- public const string TransportKey = "Transport";
-
- public const string PropagateKey = "Propagate";
-
- public int baseTransport = 1000000;
-
- public int baseHappiness;
-
- public bool infiniteTransport = true;
-
- public bool propagate = true;
-
- protected MagicalReference<CIGGameState> _gameState = new MagicalReference<CIGGameState>();
- }
|