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 AddItems(ItemType it, int amount) { Items.AddItems(it, amount); if (Faction != null) { Faction.ShowItem(it); } }
public void Kill(bool drop) { if (drop) { ItemList lst = Region.Junk; // Try to give possessions to other person in team, or drop in Junk if (this.Leader != null) { lst = this.Leader.Items; } else if (this.Team.Count > 0) { lst = this.Team[0].Items; } foreach (Item itm in Items) { if (!itm.Type.NoGive) { lst.AddItems(itm.Type, itm.Amount); } } // Drop drops to Junk foreach (Item itm in Man.Drops) { Region.Junk.AddItems(itm.Type, itm.Amount); } } foreach (Person p in Team) { p.InheritTurnOrder(this); } Leader = null; foreach (Person p in Team) { p.Leader = null; } Building = null; _faction.Persons.Remove(this); _faction = null; DiedIn = _region; _region.Persons.Remove(this); _region = null; }
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); } }
private void MoveSoldier(Soldier s, int round) { if (s.Weapon == null || s.SkillLevel == 0 || s.Person.Avoiding) { s.Flee = true; } if (s.Flee) { OOASoldier(s); s.FleedAway = true; BattleReport.Add(String.Format("{0} ran away from combat.|{1} убегает из боя.", s.Person.ToString(Lang.En), s.Person.ToString(Lang.Ru))); return; } // First turn is for ranged weapon only if shooters on field if (round == 1 && ShootersPresent() && !s.Weapon.Ranged) { return; } for (int i = 0; i < s.Weapon.Attacks; i++) { if (OutOfAmmo(s)) { break; } for (int j = 0; j < s.Weapon.Targets; j++) { MakeHit(s); if (BattleEnded()) { break; } } if (s.Ammo > 0) { s.Ammo--; } if (s.Weapon.Ammo != null) { if (s.Weapon.Ammo.Case != null) { Spoils.AddItems(s.Weapon.Ammo.Case, 1); } s.Person.Items.RemoveItems(s.Weapon.Ammo, 1); } if (OutOfAmmo(s)) { break; } if (BattleEnded()) { break; } } }