public TechnologyStats(Technology technology, List <Effect> effects) { Cost = technology.GetCost(effects); }
public Unit(YTY.AocDatLib.Unit unit, List <Technology> technologies) { Id = unit.Id; Name = new string(Encoding.ASCII.GetChars(unit.Name).Where(c => char.IsLetterOrDigit(c)).ToArray()); Type = unit.Type; Class = (UnitClass)unit.UnitClass; TrainTime = TimeSpan.FromSeconds(unit.TrainTime); BaseHitpoints = unit.HitPoints; BaseRange = Math.Max(1, (int)unit.MaxRange); BaseArmors = new List <ArmorValue>(); if (unit.Armors != null) { BaseArmors.AddRange(unit.Armors.Select(a => new ArmorValue(a.Id, a.Amount))); } BaseAttacks = new List <ArmorValue>(); if (unit.Attacks != null) { BaseAttacks.AddRange(unit.Attacks.Select(a => new ArmorValue(a.Id, a.Amount))); } BaseReloadTime = unit.ReloadTime; if (unit.TerrainRestriction == 4 || unit.TerrainRestriction == 7 || unit.TerrainRestriction == 20) { Land = true; } else { Land = false; } Available = false; if (unit.Enabled == 1) { Available = true; } TechRequired = false; foreach (var tech in technologies.Where(t => t.Effect != null)) { foreach (var command in tech.Effect.Commands) { if (command is EnableDisableUnitCommand ec) { if (ec.Enable && ec.UnitId == Id) { TechRequired = true; } } if (command is UpgradeUnitCommand uc) { if (uc.ToUnitId == Id) { TechRequired = true; } } } } if (unit.TechId > 0) { TechInitiated = technologies.Single(t => t.Id == unit.TechId); } else { TechInitiated = null; } if (unit.Cost1Used == 1) { switch (unit.Cost1Id) { case 0: FoodCost = unit.Cost1Amount; break; case 1: WoodCost = unit.Cost1Amount; break; case 2: StoneCost = unit.Cost1Amount; break; case 3: GoldCost = unit.Cost1Amount; break; } } if (unit.Cost2Used == 1) { switch (unit.Cost2Id) { case 0: FoodCost = unit.Cost2Amount; break; case 1: WoodCost = unit.Cost2Amount; break; case 2: StoneCost = unit.Cost2Amount; break; case 3: GoldCost = unit.Cost2Amount; break; } } if (unit.Cost3Used == 1) { switch (unit.Cost3Id) { case 0: FoodCost = unit.Cost3Amount; break; case 1: WoodCost = unit.Cost3Amount; break; case 2: StoneCost = unit.Cost3Amount; break; case 3: GoldCost = unit.Cost3Amount; break; } } }
private List <OldBuildElement> GetTech(Technology tech) { const int TRACK = -1; if (SearchingTechs.Contains(tech)) { return(null); } if (tech == Civilization.Age1Tech) { return(new List <OldBuildElement>()); } if (KnownTechnologies.ContainsKey(tech)) { return(KnownTechnologies[tech]); } if (tech.ResearchLocation != null) { SearchingTechs.Add(tech); } if (tech.Id == TRACK) { Debug.WriteLine("getting tech 1"); } var bo = new List <OldBuildElement>(); var prereqs = new List <Technology>(); foreach (var prereq in tech.Prerequisites) { if (tech.Id == TRACK) { Debug.WriteLine("getting tech preq " + prereq.Id); } var b = GetTech(prereq); if (b != null) { prereqs.Add(prereq); } } if (prereqs.Count < tech.MinPrerequisites) { if (tech.Id == TRACK) { Debug.WriteLine("getting tech 2"); } SearchingTechs.Remove(tech); return(null); } if (tech.MinPrerequisites > 0) { while (prereqs.Count > tech.MinPrerequisites) { prereqs.RemoveAt(Random.Next(prereqs.Count)); } foreach (var prereq in prereqs) { bo.AddRange(GetTech(prereq)); } } else { if (tech.Id == TRACK) { Debug.WriteLine("getting tech 3"); } List <OldBuildElement> b = null; foreach (var unit in AvailableUnits.Where(u => u.TechInitiated == tech)) { if (tech.Id == TRACK) { Debug.WriteLine("checking tech unit " + unit.Id); } b = GetUnit(unit); if (b != null) { bo.AddRange(b); break; } } if (b == null) { return(null); } } if (tech.ResearchLocation != null) { if (tech.Id == TRACK) { Debug.WriteLine("getting tech 4"); } var b = GetUnit(tech.ResearchLocation); if (b == null) { SearchingTechs.Remove(tech); return(null); } bo.AddRange(b); } bo.Add(new OldBuildElement(true, null, tech)); SearchingTechs.Remove(tech); KnownTechnologies.Add(tech, bo); if (tech.Id == TRACK) { Debug.WriteLine("getting tech 5"); } return(bo); }
public void Load(string file) { Effects.Clear(); Technologies.Clear(); Units.Clear(); Civilizations.Clear(); var dat = new DatFile(file); // get effects for (int id = 0; id < dat.Technologies.Count; id++) { var effect = new Effect(id); foreach (var ec in dat.Technologies[id].Effects) { var command = EffectCommand.Get(ec); if (command != null) { effect.Commands.Add(command); } } Effects.Add(effect); } // get techs for (int id = 0; id < dat.Researches.Count; id++) { var tech = new Technology(id, dat.Researches[id], Effects); Technologies.Add(tech); } foreach (var tech in Technologies) { var dattech = dat.Researches[tech.Id]; if (dattech.RequiredTech1 >= 0) { tech.Prerequisites.Add(Technologies.Single(t => t.Id == dattech.RequiredTech1)); } if (dattech.RequiredTech2 >= 0) { tech.Prerequisites.Add(Technologies.Single(t => t.Id == dattech.RequiredTech2)); } if (dattech.RequiredTech3 >= 0) { tech.Prerequisites.Add(Technologies.Single(t => t.Id == dattech.RequiredTech3)); } if (dattech.RequiredTech4 >= 0) { tech.Prerequisites.Add(Technologies.Single(t => t.Id == dattech.RequiredTech4)); } if (dattech.RequiredTech5 >= 0) { tech.Prerequisites.Add(Technologies.Single(t => t.Id == dattech.RequiredTech5)); } if (dattech.RequiredTech6 >= 0) { tech.Prerequisites.Add(Technologies.Single(t => t.Id == dattech.RequiredTech6)); } } // get units var datunits = new Dictionary <int, YTY.AocDatLib.Unit>(); var units = new Dictionary <int, Unit>(); foreach (var unit in dat.Civilizations.SelectMany(c => c.Units)) { datunits[unit.Id] = unit; units[unit.Id] = new Unit(unit, Technologies); } Units.AddRange(units.Values); // assign units to techs foreach (var tech in Technologies) { var dattech = dat.Researches[tech.Id]; if (dattech.ResearchLocation > 0) { tech.ResearchLocation = units[dattech.ResearchLocation]; } } Units.Sort((a, b) => a.Id.CompareTo(b.Id)); foreach (var unit in Units) { unit.Commands.AddRange(dat.UnitCommands[unit.Id]); } var upgrades = Technologies .Where(t => t.Effect != null) .SelectMany(t => t.Effect.Commands) .Where(c => c is UpgradeUnitCommand) .ToList(); foreach (var uc in upgrades.Cast <UpgradeUnitCommand>()) { if (units.TryGetValue(uc.FromUnitId, out Unit from)) { if (units.TryGetValue(uc.ToUnitId, out Unit to)) { from.UpgradesTo.Add(to); to.UpgradedFrom.Add(from); } } } // set unit refs foreach (var unit in Units) { var datunit = datunits[unit.Id]; if (datunit.TrainLocationId > 0) { unit.TrainLocation = units[datunit.TrainLocationId]; } if (datunit.StackUnitId > 0) { unit.StackUnit = units[datunit.StackUnitId]; } if (datunit.HeadUnitId > 0) { unit.HeadUnit = units[datunit.HeadUnitId]; } if (datunit.TransformUnitId > 0) { unit.TransformUnit = units[datunit.TransformUnitId]; } if (datunit.PileUnit > 0) { unit.PileUnit = units[datunit.PileUnit]; } if (unit.Land) { if (units.TryGetValue(datunit.DropSite0, out Unit d0)) { unit.DropSite = d0; } if (units.TryGetValue(datunit.DropSite1, out Unit d1)) { if (unit.DropSite == null) { unit.DropSite = d1; } else if (d1.GetCost(null).Total < unit.DropSite.GetCost(null).Total) { unit.DropSite = d1; } } } } // set tech resource improvements foreach (var tech in Technologies.Where(t => t.Effect != null)) { foreach (var command in tech.Effect.Commands) { if (command is AttributeModifierCommand ac) { if (ac.Attribute == Attribute.CarryCapacity) { if (ac.Class == UnitClass.Civilian) { tech.ResourceImproved = Resource.Food; break; } else if (units.TryGetValue(ac.UnitId, out Unit unit)) { if (unit.ResourceGathered != Resource.None) { tech.ResourceImproved = unit.ResourceGathered; break; } } } else if (ac.Attribute == Attribute.WorkRate) { if (units.TryGetValue(ac.UnitId, out Unit unit)) { if (unit.ResourceGathered != Resource.None) { tech.ResourceImproved = unit.ResourceGathered; break; } } } } } } // get civs for (int id = 0; id < dat.Civilizations.Count; id++) { var civ = new Civilization(id, dat.Civilizations[id], this); Civilizations.Add(civ); } }
public List <OldBuildElement> GetTechPartial(Technology tech) { return(KnownTechnologies[tech]); }