Beispiel #1
0
        public ItemArrayList GetNeeds()
        {
            ItemArrayList needs = new ItemArrayList();

            foreach (Item itm in Type.Materials)
            {
                Item installed = Installed.GetByType(itm.Type);
                if (installed == null)
                {
                    needs.Add(new Item(itm.Type, itm.Amount));
                }
                else if (installed.Amount < itm.Amount)
                {
                    needs.Add(new Item(itm.Type, itm.Amount - installed.Amount));
                }
            }
            return(needs);
        }
Beispiel #2
0
 private static void LoadItems(ItemArrayList items, XmlNodeList nodeList)
 {
     foreach (XmlElement elItem in nodeList)
     {
         ItemType t   = ItemType.Get(elItem.GetAttribute("type"));
         Item     itm = new Item(t);
         items.Add(itm);
         itm.Amount = Convert.ToInt32(elItem.GetAttribute("amount"));
     }
 }
Beispiel #3
0
        public void CalcTurnResources()
        {
            // Get resources from region list
            ItemArrayList res = new ItemArrayList();

            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;
        }
Beispiel #4
0
        public void CalcTurnJunk()
        {
            // Add new junk
            // Get dying resources from region list
            ItemArrayList res = new ItemArrayList();

            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);
                }
            }
        }
Beispiel #5
0
        public Soldier(Battle btl, Person p, Side side)
        {
            Person = p;
            Side   = side;

            if (btl != null)
            {
                p.Faction.BattleRegions.Add(btl.region);
            }

            Flee = p.Avoiding;
            if (p.Building != null && p.Building.Type.HP > 0 &&
                p.Building.IsPersonInside(p))
            {
                Building = p.Building;
                if (btl != null)
                {
                    btl.Hits[p.Building] = p.Building.Type.HP;
                }
            }

            Skill reflexes = p.Skills.GetByType(Constants.ReflexesSkill);

            if (reflexes != null)
            {
                Reflexes = reflexes.Level;
            }

            // Look for weapons and armor in person inventory
            ItemArrayList equipment = new ItemArrayList();

            foreach (Item itm in p.Items)
            {
                if ((itm.Type.IsWeapon && !itm.Type.Heavy) ||
                    itm.Type.IsArmor)
                {
                    equipment.Add(itm);
                }
            }

            // Look for heavy weapon installed in building
            if (p.Building != null)
            {
                foreach (Item itm in p.Building.Installed)
                {
                    if (itm.Type.IsWeapon && (btl == null || btl.TakenHwpn[itm] == null ||
                                              (int)btl.TakenHwpn[itm] < itm.Amount))
                    {
                        equipment.Add(itm);
                    }
                }
            }

            // Take items by predefined priority
            foreach (ItemType it in p.Equipment)
            {
                TakeItem(btl, this, equipment, it);
            }

            // Take items by default
            if (Weapon == null || Armor == null)
            {
                for (int i = ItemType.List.Count - 1; i >= 0; i--)
                {
                    TakeItem(btl, this, equipment, ItemType.List[i]);
                }
            }
        }
Beispiel #6
0
        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();

                    // Get random items from spoils (as much as soldier can carry)
                    int attempt = 0;
                    while (attempt < 2)
                    {
                        if (spoil_lists.Count == 0)
                        {
                            break;
                        }
                        int           list_idx = Constants.Random(spoil_lists.Count);
                        ItemArrayList givable  = new ItemArrayList();
                        foreach (Item itm in (ItemArrayList)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);
                            ((ItemArrayList)spoil_lists[list_idx]).RemoveItems(item.Type, amt);
                        }
                        attempt++;
                    }
                }
            }

            // Add untaken spoils to Junk
            for (int i = Spoils.Count - 1; i >= 0; i--)
            {
                r.Junk.AddItems(Spoils[i].Type, Spoils[i].Amount);
            }
        }
Beispiel #7
0
        private static void WritePerson(Person p, Faction f, int indent)
        {
            Lang lng = faction.Options.Lang;

            string s = "";

            if (p.Faction == f)
            {
                s = "* ";
            }
            else
            {
                s = "- ";
            }
            for (int i = 0; i < indent; i++)
            {
                s = "  " + s;
            }
            s += p.ToString(lng);

            if (p.Faction == f || !p.HideFaction)
            {
                s += ", " + p.Faction.ToString(lng);

                //if (!p.Faction.Description.Equals(""))
                //	s += ", " + p.Faction.Description.ToString();
            }

            if (p.Insanity >= Constants.DangerousInsanity)
            {
                s += (lng == Lang.En ? ", insane" : ", безумен");
            }
            if (p.Chosen)
            {
                s += (lng == Lang.En ? ", chosen one" : ", избранный");
            }
            if (p.Patrolling)
            {
                s += (lng == Lang.En ? ", patrolling" : ", патрулирует");
            }
            if (p.Age <= Constants.ChildTurns)
            {
                s += (lng == Lang.En ? ", child" : ", ребёнок");
            }

            if (p.Faction == f)
            {
                if (p.Avoiding)
                {
                    s += (lng == Lang.En ? ", avoiding" : ", избегает боя");
                }
                if (p.Hide)
                {
                    s += (lng == Lang.En ? ", hiding" : ", скрывается");
                }
                else if (p.HideFaction)
                {
                    s += (lng == Lang.En ? ", hiding faction" : ", скрывает фракцию");
                }
            }

            if (p.Faction == faction)
            {
                s += ", " + p.Items.ToString(lng);
            }
            else
            {
                ItemArrayList items = new ItemArrayList();
                foreach (Item itm in p.Items)
                {
                    if (itm.Type.Weight > 0)
                    {
                        items.Add(itm);
                    }
                }
                s += ", " + items.ToString(lng);
            }

            if (p.Faction == f)
            {
                int weight = p.GetWeight();
                if (p.Man != null)
                {
                    weight -= p.Man.Weight;
                }

                s += (lng == Lang.En ? " Load: " : " Груз: ") +
                     weight.ToString() + ((lng == Lang.En) ? " kg." : " кг.");
                s += (lng == Lang.En ? " Skills: " : " Навыки: ") +
                     p.Skills.ToString(lng);

                if (p.Consume.Count > 0)
                {
                    s += (lng == Lang.En ? " Consuming: " : " Еда: ") +
                         p.Consume.ToString(lng);
                }
                if (p.Burn.Count > 0)
                {
                    s += (lng == Lang.En ? " Burning: " : " Топливо: ") +
                         p.Burn.ToString(lng);
                }
                if (p.Equipment.Count > 0)
                {
                    s += (lng == Lang.En ? " Equipment: " : " Снаряжение: ") +
                         p.Equipment.ToString(lng);
                }

                s += (lng == Lang.En ? " Insanity: " : " Безумие: ") +
                     p.Insanity.ToString() + ".";

                int hire = p.GetHireAmount();
                if (hire == 1)
                {
                    s += (lng == Lang.En ? " Hire demand: day ration." : " Найм: дневной рацион.");
                }
                else if (hire > 1)
                {
                    s += String.Format((lng == Lang.En ? " Hire demand: {0} day rations." :
                                        " Найм: {0} рационов."), hire);
                }

                int rad_danger   = Math.Abs(p.RadiationDanger(true));
                int tempr_danger = p.TemperatureDanger(true);

                if (rad_danger > 0 || tempr_danger > 0)
                {
                    s += (lng == Lang.En ? " Danger:" : " Опасность:");
                    if (rad_danger > 0)
                    {
                        s += " " + rad_danger.ToString() + (lng == Lang.En ? " mR/h" : " мР/ч");
                    }
                    if (tempr_danger > 0)
                    {
                        if (rad_danger > 0)
                        {
                            s += ",";
                        }
                        s += " " + tempr_danger.ToString() + (lng == Lang.En ? "°C" : "°C");
                    }
                    s += ".";
                }

                if (!p.Description.Equals(""))
                {
                    s += " " + p.Description.ToString() + ".";
                }
            }

            if (p.TradeOrder != null)
            {
                Person receiver = null;
                if (p.TradeOrder.PersonNum != 0)
                {
                    receiver = p.Region.Persons.GetByNumber(p.TradeOrder.PersonNum);
                }
                if (p.TradeOrder.PersonNum == 0 || (receiver != null && receiver.Faction == f))
                {
                    s += " Trade: sells " + p.TradeOrder.SellWhat.ToString(p.TradeOrder.SellAmount, Lang.En) +
                         " for " + p.TradeOrder.BuyWhat.ToString(p.TradeOrder.BuyAmount, Lang.En);
                    if (receiver != null)
                    {
                        s += " to " + receiver.ToString(Lang.En);
                    }
                    s += ".";
                }
            }

            Write(s);
        }