public void CalculateDevelopment(StaticsDB statics, StatesDB states, IList <ColonyProcessor> colonyProcessors) { double developmentPoints = 0; foreach (var colonyProc in colonyProcessors) { developmentPoints += colonyProc.Development; } var focus = statics.DevelopmentFocusOptions[Player.Orders.DevelopmentFocusIndex]; var techLevels = states.DevelopmentAdvances.Of[Player].ToDictionary(x => x.Topic.IdCode, x => (double)x.Level); var advanceOrder = this.DevelopmentOrder(states.DevelopmentAdvances, states.ResearchAdvances, statics).ToList(); var results = new List <DevelopmentResult>(); for (int i = 0; i < advanceOrder.Count && i < focus.Weights.Length; i++) { results.Add(advanceOrder[i].SimulateInvestment( developmentPoints * focus.Weights[i], techLevels )); } this.DevelopmentPlan = results; }
private void advanceTechnologies(StatesDB states, StaticsDB statics) { foreach (var techProgress in this.DevelopmentPlan) { techProgress.Item.Progress(techProgress); if (techProgress.CompletedCount > 0) { states.Reports.Add(new DevelopmentReport(techProgress)); } } foreach (var techProgress in this.ResearchPlan) { techProgress.Item.Progress(techProgress); if (techProgress.CompletedCount > 0) { states.Reports.Add(new ResearchReport(techProgress)); } } this.Calculate(states.DevelopmentAdvances.Of[Player]); var researchLevels = states.ResearchAdvances.Of[Player].ToDictionary(x => x.Topic.IdCode, x => (double)x.Level); var validTechs = new HashSet <string>( states.DevelopmentAdvances .Where(x => x.CanProgress(researchLevels, statics)) .Select(x => x.Topic.IdCode) ); Player.Orders.DevelopmentQueue = updateTechQueue(Player.Orders.DevelopmentQueue, validTechs); }
private Design makeDesign(StaticsDB statics, StatesDB states, PredefinedDesign predefDesign, Dictionary <string, double> techLevels, bool isVirtual) { var hull = statics.Hulls[predefDesign.HullCode].MakeHull(techLevels); var specials = predefDesign.SpecialEquipment.OrderBy(x => x.Key).Select( x => statics.SpecialEquipment[x.Key].MakeBest(techLevels, x.Value) ).ToList(); var armor = AComponentType.MakeBest(statics.Armors.Values, techLevels); var reactor = ReactorType.MakeBest(techLevels, hull, specials, statics); var isDrive = predefDesign.HasIsDrive ? IsDriveType.MakeBest(techLevels, hull, reactor, specials, statics) : null; var sensor = AComponentType.MakeBest(statics.Sensors.Values, techLevels); var shield = predefDesign.ShieldCode != null ? statics.Shields[predefDesign.ShieldCode].MakeBest(techLevels) : null; var equipment = predefDesign.MissionEquipment.Select( x => statics.MissionEquipment[x.Key].MakeBest(techLevels, x.Value) ).ToList(); var thruster = AComponentType.MakeBest(statics.Thrusters.Values, techLevels); var design = new Design( states.MakeDesignId(), Player, false, isVirtual, predefDesign.Name, predefDesign.HullImageIndex, armor, hull, isDrive, reactor, sensor, shield, equipment, specials, thruster ); design.CalcHash(statics); if (!states.Designs.Contains(design)) { states.Designs.Add(design); this.Analyze(design, statics); return(design); } return(states.Designs.First(x => x == design)); }
public Design DesignUpgrade(Design oldDesign, StaticsDB statics, StatesDB states) { var techLevels = states.DevelopmentAdvances.Of[Player].ToDictionary(x => x.Topic.IdCode, x => (double)x.Level); var hull = statics.Hulls[oldDesign.Hull.TypeInfo.IdCode].MakeHull(techLevels); var specials = oldDesign.SpecialEquipment.Select( x => statics.SpecialEquipment[x.TypeInfo.IdCode].MakeBest(techLevels, x.Quantity) ).ToList(); var armor = AComponentType.MakeBest(statics.Armors.Values, techLevels); var reactor = ReactorType.MakeBest(techLevels, hull, specials, statics); var isDrive = oldDesign.IsDrive != null?IsDriveType.MakeBest(techLevels, hull, reactor, specials, statics) : null; var sensor = AComponentType.MakeBest(statics.Sensors.Values, techLevels); var shield = oldDesign.Shield != null ? statics.Shields[oldDesign.Shield.TypeInfo.IdCode].MakeBest(techLevels) : null; var equipment = oldDesign.MissionEquipment.Select( x => statics.MissionEquipment[x.TypeInfo.IdCode].MakeBest(techLevels, x.Quantity) ).ToList(); var thruster = AComponentType.MakeBest(statics.Thrusters.Values, techLevels); var design = new Design( states.MakeDesignId(), Player, false, oldDesign.IsVirtual, oldDesign.Name, oldDesign.ImageIndex, armor, hull, isDrive, reactor, sensor, shield, equipment, specials, thruster ); design.CalcHash(statics); return(design); }
private void makeDesign(StaticsDB statics, StatesDB states, DesignTemplate predefDesign, Dictionary <string, double> techLevels) { var hull = statics.Hulls[predefDesign.HullCode].MakeHull(techLevels); var specials = predefDesign.SpecialEquipment.OrderBy(x => x.Key).Select( x => statics.SpecialEquipment[x.Key].MakeBest(techLevels, x.Value) ).ToList(); var equipment = predefDesign.MissionEquipment.Select( x => statics.MissionEquipment[x.Key].MakeBest(techLevels, x.Value) ).ToList(); var armor = AComponentType.MakeBest(statics.Armors.Values, techLevels); var reactor = ReactorType.MakeBest(techLevels, hull, specials, equipment, statics); var isDrive = predefDesign.HasIsDrive ? IsDriveType.MakeBest(techLevels, hull, reactor, specials, equipment, statics) : null; var sensor = AComponentType.MakeBest(statics.Sensors.Values, techLevels); var shield = predefDesign.ShieldCode != null ? statics.Shields[predefDesign.ShieldCode].MakeBest(techLevels) : null; var thruster = AComponentType.MakeBest(statics.Thrusters.Values, techLevels); var design = new Design( this.Player, predefDesign.Name, predefDesign.HullImageIndex, true, armor, hull, isDrive, reactor, sensor, thruster, shield, equipment, specials ); if (!states.Designs.Contains(design)) { states.Designs.Add(design); this.Analyze(design, statics); } }
private void makeDesign(StaticsDB statics, StatesDB states, string id, PredefinedDesign designData, PlayerProcessor playerProc) { var design = states.Designs.FirstOrDefault(x => x.IdCode == id); if (design == null) { var armor = new Component <ArmorType>(statics.Armors[designData.Armor.IdCode], designData.Armor.Level); var hull = new Component <HullType>(statics.Hulls[designData.Hull.IdCode], designData.Hull.Level); var reactor = new Component <ReactorType>(statics.Reactors[designData.Reactor.IdCode], designData.Reactor.Level); var sensor = new Component <SensorType>(statics.Sensors[designData.Sensors.IdCode], designData.Sensors.Level); var thruster = new Component <ThrusterType>(statics.Thrusters[designData.Thrusters.IdCode], designData.Thrusters.Level); var isDrive = designData.IsDrive != null ? new Component <IsDriveType>(statics.IsDrives[designData.IsDrive.IdCode], designData.IsDrive.Level) : null; var shield = designData.Shield != null ? new Component <ShieldType>(statics.Shields[designData.Shield.IdCode], designData.Shield.Level) : null; var equipment = designData.MissionEquipment.Select( x => new Component <MissionEquipmentType>(statics.MissionEquipment[x.IdCode], x.Level, x.Amount) ).ToList(); var specials = designData.SpecialEquipment.Select( x => new Component <SpecialEquipmentType>(statics.SpecialEquipment[x.IdCode], x.Level, x.Amount) ).ToList(); design = new Design( id, playerProc.Player, false, designData.Name, designData.HullImageIndex, designData.UsesFuel, armor, hull, isDrive, reactor, sensor, thruster, shield, equipment, specials ); design.CalcHash(statics); states.Designs.Add(design); } playerProc.Analyze(design, statics); }
public void CalculateResearch(StaticsDB statics, StatesDB states, IList <ColonyProcessor> colonyProcessors) { var techLevels = states.DevelopmentAdvances.Of[Player].ToDictionary(x => x.Topic.IdCode, x => (double)x.Level); var advanceOrder = this.ResearchOrder(states.ResearchAdvances).ToList(); string focused = Player.Orders.ResearchFocus; if (advanceOrder.Count > 0 && advanceOrder.All(x => x.Topic.IdCode != focused)) { focused = advanceOrder[0].Topic.IdCode; } double focusWeight = statics.PlayerFormulas.FocusedResearchWeight; var results = new List <ResearchResult>(); for (int i = 0; i < advanceOrder.Count; i++) { double weight = advanceOrder[i].Topic.IdCode == focused ? focusWeight : 1; weight /= advanceOrder.Count + focusWeight - 1; results.Add(advanceOrder[i].SimulateInvestment(weight)); } this.ResearchPlan = results; }
public void ProcessPostcombat(StaticsDB statics, StatesDB states, TemporaryDB derivates) { this.advanceTechnologies(states, statics); this.checkColonizationValidity(states); this.doConstruction(statics, states, derivates); this.unlockPredefinedDesigns(statics, states); this.updateDesigns(statics, states, derivates); }
public void Initialize(StatesDB states) { this.starKnowledge.Clear(); foreach (var star in states.Stars) { starKnowledge.Add(star, new StarIntelligence(states.Planets.At[star])); } }
public void BreakthroughReviewed(IList <string> selectedPriorities, StatesDB states) { for (int priority = 0; priority < selectedPriorities.Count; priority++) { var progress = states.DevelopmentAdvances.Of[this.Player].First(x => x.Topic.IdCode == selectedPriorities[priority]); progress.Priority = priority; } }
public void ProcessPrecombat(StaticsDB statics, StatesDB states, TemporaryDB derivates) { var catalizers = states.Fleets.OwnedBy[this.OrganellePlayer].SelectMany(x => x.Ships).Where(x => x.Design.IdCode == CatalyzerId).Sum(x => x.Quantity); if (catalizers < MaxCatalyzers) { var nativeDesign = states.Designs.OwnedBy[this.OrganellePlayer].First(x => x.IdCode == CatalyzerId); derivates[this.OrganellePlayer].SpawnShip(states.StareaterBrain, nativeDesign, 1, 0, new AMission[0], states); } }
public MainGame(Player[] players, Player organellePlayer, StaticsDB statics, StatesDB states, TemporaryDB derivates) { this.Turn = 0; this.StareaterOrganelles = organellePlayer; this.MainPlayers = players; this.IsReadOnly = false; this.Statics = statics; this.States = states; this.Derivates = derivates; this.Processor = new GameProcessor(this); }
public void Initialize(StatesDB states, StaticsDB statics, TemporaryDB derivates) { this.OrganellePlayer.Intelligence.Initialize(states); foreach (var star in states.Stars) { this.OrganellePlayer.Intelligence.StarFullyVisited(star, 0); } foreach (var designData in statics.NativeDesigns) { makeDesign(statics, states, designData.Key, designData.Value, derivates[this.OrganellePlayer]); } }
public void Initialize(StatesDB states, StaticsDB statics, TemporaryDB derivates) { this.OrganellePlayer.Intelligence.Initialize(states.Stars.Select( star => new Stareater.Galaxy.Builders.StarSystem(star, states.Planets.At[star].ToArray()) )); foreach (var star in states.Stars) { this.OrganellePlayer.Intelligence.StarFullyVisited(star, 0); } foreach (var template in statics.NativeDesigns) { makeDesign(statics, states, template.Key, template.Value, derivates.Of(this.OrganellePlayer)); } }
private Design updateVirtualDesign(Design oldDesign, StaticsDB statics, StatesDB states, IEnumerable <PredefinedDesign> predefDesigns, Dictionary <string, double> techLevels) { var newDesign = makeDesign( statics, states, predefDesigns.Last(x => Prerequisite.AreSatisfied(x.Prerequisites(statics), 0, techLevels)), techLevels, true); if (newDesign != oldDesign && oldDesign != null) { oldDesign.IsObsolete = true; oldDesign.Owner.Orders.RefitOrders[oldDesign] = null; } return(newDesign); }
private void checkColonizationValidity(StatesDB states) { var occupiedTargets = new HashSet <Planet>(); foreach (var order in this.Player.Orders.ColonizationOrders) { if (states.Colonies.AtPlanet.Contains(order.Key)) //TODO(later) use intelligence instead { occupiedTargets.Add(order.Key); } } foreach (var planet in occupiedTargets) { this.Player.Orders.ColonizationOrders.Remove(planet); } }
public void Apply(StatesDB states, TemporaryDB derivates, AConstructionSite site, long quantity) { //TODO(v0.5) report new building construction var vars = new Var("quantity", quantity); quantity = (long)this.quantity.Evaluate(vars.Get); if (!site.Buildings.ContainsKey(buildingCode)) { site.Buildings.Add(buildingCode, quantity); } else { site.Buildings[buildingCode] += quantity; } }
private void unlockPredefinedDesigns(StaticsDB statics, StatesDB states) { var playerTechs = states.DevelopmentAdvances.Of[Player]; var techLevels = playerTechs.ToDictionary(x => x.Topic.IdCode, x => (double)x.Level); foreach (var predefDesign in statics.PredeginedDesigns) { if (!Player.UnlockedDesigns.Contains(predefDesign) && Prerequisite.AreSatisfied(predefDesign.Prerequisites(statics), 0, techLevels)) { Player.UnlockedDesigns.Add(predefDesign); makeDesign(statics, states, predefDesign, techLevels, false); } } this.ColonyShipDesign = updateVirtualDesign(this.ColonyShipDesign, statics, states, statics.ColonyShipDesigns, techLevels); this.SystemColonizerDesign = updateVirtualDesign(this.SystemColonizerDesign, statics, states, statics.SystemColonizerDesigns, techLevels); }
public void Initialize(StatesDB states, StaticsDB statics, TemporaryDB derivates) { this.OrganellePlayer.Intelligence.Initialize(states); foreach (var star in states.Stars) { this.OrganellePlayer.Intelligence.StarFullyVisited(star, 0); } foreach (var designData in statics.NativeDesigns) { var design = makeDesign(statics, designData.Value, this.OrganellePlayer); this.nativeDesigns[designData.Key] = design; states.Designs.Add(design); derivates[this.OrganellePlayer].Analyze(design, statics); } }
private void doConstruction(StaticsDB statics, StatesDB states, TemporaryDB derivates) { var oldPlans = Player.Orders.ConstructionPlans; Player.Orders.ConstructionPlans = new Dictionary <AConstructionSite, ConstructionOrders>(); foreach (var colony in states.Colonies.OwnedBy[Player]) { if (oldPlans.ContainsKey(colony)) { var updatedPlans = updateConstructionPlans( statics, oldPlans[colony], derivates.Of(colony), this.TechLevels ); Player.Orders.ConstructionPlans.Add(colony, updatedPlans); } else { Player.Orders.ConstructionPlans.Add(colony, new ConstructionOrders(PlayerOrders.DefaultSiteSpendingRatio)); } } foreach (var stellaris in states.Stellarises.OwnedBy[Player]) { if (oldPlans.ContainsKey(stellaris)) { var updatedPlans = updateConstructionPlans( statics, oldPlans[stellaris], derivates.Of(stellaris), this.TechLevels ); Player.Orders.ConstructionPlans.Add(stellaris, updatedPlans); } else { Player.Orders.ConstructionPlans.Add(stellaris, new ConstructionOrders(PlayerOrders.DefaultSiteSpendingRatio)); } } }
public MainGame(Player[] players, Player organellePlayer, StaticsDB statics, StatesDB states, TemporaryDB derivates) { this.Turn = 0; this.StareaterOrganelles = organellePlayer; this.MainPlayers = players; this.IsReadOnly = false; this.Statics = statics; this.States = states; this.Derivates = derivates; this.Processor = new GameProcessor(this); this.Orders = new Dictionary <Player, PlayerOrders>(); foreach (var player in this.AllPlayers) { this.Orders[player] = new PlayerOrders(); } }
private void updateColonizationOrders(StatesDB states) { foreach (var project in states.ColonizationProjects.OwnedBy[this.Player]) { if (!this.Player.Orders.ColonizationOrders.ContainsKey(project.Destination)) { states.ColonizationProjects.PendRemove(project); } } foreach (var order in this.Player.Orders.ColonizationOrders) { if (states.ColonizationProjects.Of[order.Key].All(x => x.Owner != this.Player)) { states.ColonizationProjects.PendAdd(new ColonizationProject(this.Player, order.Value.Destination)); } } states.ColonizationProjects.ApplyPending(); }
public void PostcombatApply(StatesDB states, StaticsDB statics) { if (this.duration <= 0) { this.star.Traits.PendRemove(this.parentTrait); return; } var trait = statics.Traits[this.type.afflictionId]; foreach (var planet in states.Planets.At[this.star]) { if (planet.Traits.All(x => x.Type.IdCode != this.type.afflictionId)) { planet.Traits.Add(trait.Instantiate(planet)); } } this.duration--; }
public void ProcessPrecombat(StaticsDB statics, StatesDB states, TemporaryDB derivates) { this.updateColonizationOrders(states); foreach (var colonyProc in derivates.Colonies.OwnedBy[this.Player]) { colonyProc.ProcessPrecombat(states, derivates); } foreach (var stellarisProc in derivates.Stellarises.OwnedBy[this.Player]) { stellarisProc.ProcessPrecombat(states, derivates); } this.breakthroughs = new Queue <ResearchResult>(this.ResearchPlan.Where(x => x.CompletedCount > 0)); /* * TODO(later): * - Perform migration */ }
public void Apply(StatesDB states, TemporaryDB derivates, AConstructionSite site, long quantity) { var project = states.ColonizationProjects.Of[Destination].FirstOrDefault(x => x.Owner == this.ColonizerDesign.Owner); var missions = new LinkedList <AMission>(); missions.AddLast(new SkipTurnMission()); //TODO(later) check shortest path if (site.Location.Star != Destination.Star) { var lastStar = site.Location.Star; var nextStar = Destination.Star; var wormhole = states.Wormholes.At[lastStar].FirstOrDefault(x => x.FromStar == nextStar || x.ToStar == nextStar); missions.AddLast(new MoveMission(Destination.Star, wormhole)); } missions.AddLast(new ColonizationMission(Destination)); //TODO(v0.6) report new ship construction derivates.Of(site.Owner).SpawnShip(site.Location.Star, this.ColonizerDesign, quantity, missions, states); }
private void makeDesign(StaticsDB statics, StatesDB states, string id, PredefinedDesign predefDesign, PlayerProcessor playerProc) { var design = states.Designs.FirstOrDefault(x => x.IdCode == id); if (design == null) { var techLevels = new Var(). Init(statics.DevelopmentTopics.Select(x => x.IdCode), false). Init(statics.ResearchTopics.Select(x => x.IdCode), false).Get; var hull = statics.Hulls[predefDesign.HullCode].MakeHull(techLevels); var specials = predefDesign.SpecialEquipment.OrderBy(x => x.Key).Select( x => statics.SpecialEquipment[x.Key].MakeBest(techLevels, x.Value) ).ToList(); var armor = AComponentType.MakeBest(statics.Armors.Values, techLevels); //TODO(0.5) get id from template var reactor = ReactorType.MakeBest(techLevels, hull, specials, statics); //TODO(0.5) get id from template var isDrive = predefDesign.HasIsDrive ? IsDriveType.MakeBest(techLevels, hull, reactor, specials, statics) : null; //TODO(0.5) get id from template var sensor = AComponentType.MakeBest(statics.Sensors.Values, techLevels); //TODO(0.5) get id from template var shield = predefDesign.ShieldCode != null ? statics.Shields[predefDesign.ShieldCode].MakeBest(techLevels) : null; var equipment = predefDesign.MissionEquipment.Select( x => statics.MissionEquipment[x.Key].MakeBest(techLevels, x.Value) ).ToList(); var thruster = AComponentType.MakeBest(statics.Thrusters.Values, techLevels); //TODO(0.5) get id from template design = new Design( id, playerProc.Player, false, true, predefDesign.Name, predefDesign.HullImageIndex, armor, hull, isDrive, reactor, sensor, shield, equipment, specials, thruster ); design.CalcHash(statics); states.Designs.Add(design); } playerProc.Analyze(design, statics); }
public virtual void ProcessPrecombat(StatesDB states, TemporaryDB derivates) { foreach (var construction in this.SpendingPlan) { if (construction.CompletedCount >= 1) { foreach (var effect in construction.Type.Effects) { effect.Apply(states, derivates, this.Site, construction.CompletedCount); } } var stockpileKey = construction.Type.StockpileGroup; if (construction.FromStockpile > 0 && this.Site.Stockpile.ContainsKey(stockpileKey)) { this.Site.Stockpile[stockpileKey] -= construction.FromStockpile; } if (construction.LeftoverPoints > 0) { if (!this.Site.Stockpile.ContainsKey(stockpileKey)) { this.Site.Stockpile.Add(stockpileKey, construction.LeftoverPoints); } else { this.Site.Stockpile[stockpileKey] += construction.LeftoverPoints; } } if (this.Site.Stockpile.ContainsKey(stockpileKey) && this.Site.Stockpile[stockpileKey] <= 0) { this.Site.Stockpile.Remove(stockpileKey); } } }
public override void ProcessPrecombat(StatesDB states, TemporaryDB derivates) { base.ProcessPrecombat(states, derivates); Colony.Population = Methods.Clamp(Colony.Population + PopulationGrowth, 0, MaxPopulation); }
public void Apply(StatesDB states, TemporaryDB derivates, AConstructionSite site, long quantity) { //TODO(v0.6) report new ship construction derivates.Of(site.Owner).SpawnShip(site.Location.Star, this.Design, quantity, new AMission[0], states); }
public void Initialize(StaticsDB statics, StatesDB states) { this.Calculate(states.DevelopmentAdvances.Of[this.Player]); this.unlockPredefinedDesigns(statics, states); }