Ejemplo n.º 1
0
        public static bool DropThing(Thing toDrop, Building_WeaponStorage from, Map map, bool makeForbidden = false)
        {
            if (toDrop.stackCount == 0)
            {
                Log.Warning("To Drop Thing " + toDrop.Label + " had stack count of 0");
                return(false);
            }

            try
            {
                from.AllowAdds = false;
                if (toDrop.stackCount <= toDrop.def.stackLimit)
                {
                    return(DropSingleThing(toDrop, from, map, makeForbidden));
                }
                return(DropThing(toDrop, toDrop.stackCount, from, map, null, makeForbidden));
            }
            catch (Exception e)
            {
                Log.Warning($"failed to drop {toDrop?.def?.defName}\n{e.Message}");
                return(true);
            }
            finally
            {
                from.AllowAdds = true;
            }
        }
Ejemplo n.º 2
0
 public void Add(Building_WeaponStorage s)
 {
     if (!this.AttachedWeaponStorages.Contains(s))
     {
         this.AttachedWeaponStorages.AddLast(s);
     }
 }
 public static void EmptyAmmo(Building_WeaponStorage ws)
 {
     foreach (var kv in Ammo)
     {
         DropAllNoUpate(kv.Key, kv.Value, ws);
     }
     Ammo.Clear();
 }
Ejemplo n.º 4
0
        public static bool DropThing(Thing toDrop, int amountToDrop, Building_WeaponStorage from, Map map, List <Thing> droppedThings = null, bool makeForbidden = false)
        {
            if (toDrop.stackCount == 0)
            {
                Log.Warning("To Drop Thing " + toDrop.Label + " had stack count of 0");
                return(false);
            }

            bool anyDropped = false;

            try
            {
                from.AllowAdds = false;

                Thing t;
                bool  done = false;
                while (!done)
                {
                    int toTake = toDrop.def.stackLimit;
                    if (toTake > amountToDrop)
                    {
                        toTake = amountToDrop;
                        done   = true;
                    }
                    if (toTake >= toDrop.stackCount)
                    {
                        if (amountToDrop > toTake)
                        {
                            Log.Error("        ThingStorage: Unable to drop " + (amountToDrop - toTake).ToString() + " of " + toDrop.def.label);
                        }
                        toTake = toDrop.stackCount;
                        done   = true;
                    }
                    if (toTake > 0)
                    {
                        amountToDrop -= toTake;
                        t             = toDrop.SplitOff(toTake);
                        if (droppedThings != null)
                        {
                            droppedThings.Add(t);
                        }
                        if (DropSingleThing(t, from, map, makeForbidden))
                        {
                            anyDropped = true;
                        }
                    }
                }
            }
            finally
            {
                from.AllowAdds = true;
            }
            return(anyDropped);
        }
Ejemplo n.º 5
0
        public static void Add(Building_WeaponStorage ws)
        {
            if (ws == null || ws.Map == null)
            {
                Log.Error("Cannot add WeaponStorage that is either null or has a null map.");
                return;
            }

            if (!WeaponStoragesToUse.Contains(ws))
            {
                WeaponStoragesToUse.Add(ws);
            }
        }
 private static void DropAllNoUpate(ThingDef def, int count, Building_WeaponStorage ws)
 {
     while (count > 0)
     {
         int toDrop = Math.Max(def.stackLimit, 1);
         if (toDrop > count)
         {
             toDrop = count;
         }
         BuildingUtil.DropThing(MakeAmmo(def, toDrop), ws, ws.Map);
         count -= toDrop;
     }
 }
Ejemplo n.º 7
0
        private void StartRepairing()
        {
#if AUTO_MENDER
            Log.Warning("Begin RepairChangeDresser.StartRepairing");
            Log.Message("    Currently Being Repaired:");
            foreach (Apparel a in AllApparelBeingRepaired)
            {
                Log.Message("        " + a.Label);
            }
#endif
            this.OrderAttachedWeaponStorages();
            foreach (AssignedWeaponContainer c in WorldComp.AssignedWeaponContainers)
            {
                foreach (ThingWithComps w in c.Weapons)
                {
                    if (w.HitPoints < w.MaxHitPoints &&
                        !AllWeaponsBeingRepaired.Contains(w))
                    {
                        this.beingRepaird = w;
                        this.container    = c;
                        AllWeaponsBeingRepaired.AddLast(w);
#if AUTO_MENDER
                        Log.Warning("End RepairChangeDresser.StartRepairing -- " + a.Label);
#endif
                        return;
                    }
                }
            }
            for (LinkedListNode <Building_WeaponStorage> n = this.AttachedWeaponStorages.First; n != null; n = n.Next)
            {
                Building_WeaponStorage ws = n.Value;
                foreach (ThingWithComps w in ws.GetWeapons(true))
                {
                    if (w.HitPoints < w.MaxHitPoints &&
                        !AllWeaponsBeingRepaired.Contains(w))
                    {
                        this.beingRepaird = w;
                        this.container    = null;
                        AllWeaponsBeingRepaired.AddLast(w);
#if AUTO_MENDER
                        Log.Warning("End RepairChangeDresser.StartRepairing -- " + a.Label);
#endif
                        return;
                    }
                }
            }
#if AUTO_MENDER
            Log.Warning("End RepairChangeDresser.StartRepairing -- No new repairs to start");
#endif
        }
Ejemplo n.º 8
0
        private void OrderAttachedWeaponStorages()
        {
            bool isSorted = true;
            LinkedListNode <Building_WeaponStorage> n = this.AttachedWeaponStorages.First;

            while (n != null)
            {
                var next = n.Next;
                if (!n.Value.Spawned)
                {
                    this.AttachedWeaponStorages.Remove(n);
                }
                else if (
                    n.Next != null &&
                    n.Value.settings.Priority < n.Next.Value.settings.Priority)
                {
                    isSorted = false;
                }
                n = next;
            }

            if (!isSorted)
            {
                LinkedList <Building_WeaponStorage> ordered = new LinkedList <Building_WeaponStorage>();
                for (n = this.AttachedWeaponStorages.First; n != null; n = n.Next)
                {
                    Building_WeaponStorage s = n.Value;
                    bool inserted            = false;
                    for (LinkedListNode <Building_WeaponStorage> o = ordered.First; o != null; o = o.Next)
                    {
                        if (s.settings.Priority > o.Value.settings.Priority)
                        {
                            ordered.AddBefore(o, s);
                            inserted = true;
                            break;
                        }
                    }
                    if (!inserted)
                    {
                        ordered.AddLast(s);
                    }
                }
                this.AttachedWeaponStorages.Clear();
                this.AttachedWeaponStorages = ordered;
            }
        }
Ejemplo n.º 9
0
        public static bool DropSingleThing(Thing toDrop, Building_WeaponStorage from, Map map, bool makeForbidden = false)
        {
            if (toDrop.stackCount == 0)
            {
                Log.Warning("To Drop Thing " + toDrop.Label + " had stack count of 0");
                return(false);
            }

            try
            {
                from.AllowAdds = false;
                return(DropSingleThing(toDrop, from.InteractionCell, map, makeForbidden));
            }
            finally
            {
                from.AllowAdds = true;
            }
        }
Ejemplo n.º 10
0
 public StoredWeapons(Building_WeaponStorage storage, ThingWithComps weapon)
 {
     this.Storage = storage;
     this.Weapon  = weapon;
 }
Ejemplo n.º 11
0
 public void Remove(Building_WeaponStorage s)
 {
     this.AttachedWeaponStorages.Remove(s);
 }
Ejemplo n.º 12
0
 public static void Remove(Building_WeaponStorage ws)
 {
     WeaponStoragesToUse.Remove(ws);
 }
 internal static void DropAmmo(ThingDef def, Building_WeaponStorage ws)
 {
     DropAllNoUpate(def, GetAmmoCount(def), ws);
     Ammo[def] = 0;
 }