Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }