public void CalcTurnResources() { // Get resources from region list ItemList res = new ItemList(); foreach (Item itm in Resources) { res.Add(new Item(itm.Type, itm.Amount)); } // Apply temperature factor int tempr = this.Temperature; for (int i = res.Count - 1; i >= 0; i--) { Item itm = res[i]; int danger = (itm.Type.TemperatureFrom - tempr) * itm.Type.TemperatureEffect; if (danger > 0) { int died = itm.Amount * Math.Min(100, danger) / 100; res.RemoveItems(itm.Type, died); } } // Add resources added by production buildings foreach (Building b in Buildings) { if (b.Type.Resource != null && b.IsComplete) { res.AddItems(b.Type.Resource.Type, b.Type.Resource.Amount); } } // Apply radiation factor int radiation = this.Radiation; for (int i = res.Count - 1; i >= 0; i--) { Item itm = res[i]; int danger = (radiation - itm.Type.RadiationTo) * itm.Type.RadiationEffect; if (danger > 0) { // Mutate some resource int amt = itm.Amount * Math.Min(100, danger) / 100; res.RemoveItems(itm.Type, amt); int amt_mutated = amt * itm.Type.MutatePercent / 100; if (itm.Type.MutateTo != null && amt_mutated > 0) { res.AddItems(itm.Type.MutateTo, amt_mutated); } } } TurnResources = res; }
public void Damage() { // Destroy random component int total = 0; foreach (Item itm in Installed) { total += itm.Amount; } if (total == 0) { return; } int idx = Constants.Random(total); for (int i = 0; i < Installed.Count; i++) { idx -= Installed[i].Amount; if (idx > 0) { continue; } Installed.RemoveItems(Installed[i].Type, 1); break; } // If first components spent, collapse if (Installed.Count == 0 || (Type.Materials.Count > 0 && Installed.GetByType(Type.Materials[0].Type) == null)) { Collapse(); } }
public void CalcTurnJunk() { // Add new junk // Get dying resources from region list ItemList res = new ItemList(); foreach (Item itm in Resources) { if (itm.Type.Dead != null) { res.Add(new Item(itm.Type, itm.Amount)); } } // Apply temperature factor int tempr = this.Temperature; for (int i = res.Count - 1; i >= 0; i--) { Item itm = res[i]; int danger = (itm.Type.TemperatureFrom - tempr) * itm.Type.TemperatureEffect; if (danger > 0) { int died = itm.Amount * Math.Min(100, danger) / 100; res.RemoveItems(itm.Type, died); Junk.AddItems(itm.Type.Dead, died); } } // Add resources added by production buildings foreach (Building b in Buildings) { if (b.Type.Resource != null && b.Type.Resource.Type.Dead != null && b.IsComplete) { res.AddItems(b.Type.Resource.Type, b.Type.Resource.Amount); } } // Apply radiation factor int radiation = this.Radiation; for (int i = res.Count - 1; i >= 0; i--) { Item itm = res[i]; int danger = Math.Max(radiation - itm.Type.RadiationTo, itm.Type.RadiationFrom - radiation) * itm.Type.RadiationEffect; if (danger > 0) { int amt = itm.Amount * Math.Min(100, danger) / 100; int amt_mutated = amt * itm.Type.MutatePercent / 100; int amt_dead = amt - amt_mutated; if (amt_dead > 0) { Junk.AddItems(itm.Type.Dead, amt_dead); } } } // Decompose junk for (int i = Junk.Count - 1; i >= 0; i--) { Item itm = Junk[i]; if (itm.Type.DecomposeChance > 0) { int decomposed = itm.Amount * itm.Type.DecomposeChance / 100; if (decomposed == 0 && Constants.Random(100) < itm.Type.DecomposeChance * itm.Amount) { decomposed = 1; } Junk.RemoveItems(itm.Type, decomposed); } } }
private void CollectSpoils(Region r, bool draw, Side winner) { ArrayList spoil_lists = new ArrayList(); spoil_lists.Add(Spoils); foreach (Soldier s in Soldiers) { if (s.OutOfAction && !s.FleedAway) { if (s.Person.Killed) { // If person killed, add items to Spoils for (int i = s.Person.Items.Count - 1; i >= 0; i--) { Item itm = s.Person.Items[i]; if (!itm.Type.NoGive) { s.Person.Items.RemoveAt(i); Spoils.AddItems(itm.Type, itm.Amount); } } } else if (!draw && s.Side != winner) { // If person stunned, allow to marauder givable items from it spoil_lists.Add(s.Person.Items); } } // If person killed, drop "drops" to Spoils if (s.OutOfAction && s.Person.Killed && s.Person.Man.Drops.Count > 0) { foreach (Item itm in s.Person.Man.Drops) { Spoils.AddItems(itm.Type, itm.Amount); } } } if (!draw) { foreach (Soldier s in Soldiers) { if (s.OutOfAction) { continue; } int space = s.Person.GetCapacity(Movement.Walk) - s.Person.GetWeight(); ItemList taken = new ItemList(); // Get item requested in spoils if (s.Person.Spoils.Count > 0) { foreach (ItemType wanted in s.Person.Spoils) { if (wanted.NoGive) { continue; } for (int i = spoil_lists.Count - 1; i >= 0; i--) { ItemList list = (ItemList)spoil_lists[i]; Item item = list.GetByType(wanted); if (item == null) { continue; } int amt; if (item.Type.Weight == 0) { amt = Math.Min(item.Amount, Constants.Random(20)); } else { amt = Math.Min(item.Type.Weight * item.Amount, space) / item.Type.Weight; } if (amt == 0) { continue; } s.Person.Items.AddItems(item.Type, amt); space -= item.Type.Weight * amt; list.RemoveItems(item.Type, amt); if (list.Count == 0) { spoil_lists.Remove(list); } taken.AddItems(item.Type, amt); } if (taken.Count > 0) { break; } } } // Get random items from spoils (as much as soldier can carry) if (taken.Count == 0) { int attempt = 0; while (attempt < 2) { if (spoil_lists.Count == 0) { break; } int list_idx = Constants.Random(spoil_lists.Count); ItemList givable = new ItemList(); foreach (Item itm in (ItemList)spoil_lists[list_idx]) { if (!itm.Type.NoGive) { givable.Add(itm); } } if (givable.Count == 0) { spoil_lists.RemoveAt(list_idx); continue; } int item_idx = Constants.Random(givable.Count); Item item = givable[item_idx]; int amt; if (item.Type.Weight == 0) { amt = Math.Min(item.Amount, Constants.Random(20)); } else { amt = Math.Min(item.Type.Weight * item.Amount, space) / item.Type.Weight; } if (amt > 0) { s.Person.Items.AddItems(item.Type, amt); space -= item.Type.Weight * amt; ((ItemList)spoil_lists[list_idx]).RemoveItems(item.Type, amt); taken.AddItems(item.Type, amt); } attempt++; } } if (taken.Count > 0) { BattleReport.Add(String.Format("{0} takes {1}|{2} берёт: {3}", s.Person.ToString(Lang.En), taken.ToString(Lang.En), s.Person.ToString(Lang.Ru), taken.ToString(Lang.Ru))); } } } // Add untaken spoils to Junk for (int i = Spoils.Count - 1; i >= 0; i--) { r.Junk.AddItems(Spoils[i].Type, Spoils[i].Amount); } }