internal void ReclaimWeapons(bool force = false)
        {
            if (base.Map == null)
            {
                return;
            }

            List <ThingWithComps> l = BuildingUtil.FindThingsOfTypeNextTo <ThingWithComps>(base.Map, base.Position, 1);

            if (l.Count > 0)
            {
                foreach (ThingWithComps t in l)
                {
                    if (!this.AddWeapon(t) &&
                        force &&
                        t.Spawned &&
                        (t.def.IsWeapon || CombatExtendedUtil.IsAmmo(t)) &&
                        !t.def.defName.Equals("WoodLog"))
                    {
                        t.DeSpawn();
                        if (this.forceAddedWeapons == null)
                        {
                            forceAddedWeapons = new List <Thing>(l.Count);
                        }
                        this.forceAddedWeapons.Add(t);
                    }
                }
                l.Clear();
            }
        }
Пример #2
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.compPowerTrader             = base.GetComp <CompPowerTrader>();
            this.compPowerTrader.PowerOutput = -LOW_POWER_COST;

            this.CurrentMap = map;

            foreach (Building_WeaponStorage s in BuildingUtil.FindThingsOfTypeNextTo <Building_WeaponStorage>(base.Map, base.Position, Settings.RepairAttachmentDistance))
            {
                this.Add(s);
            }

#if DEBUG_REPAIR
            Log.Warning(this.Label + " adding attached dressers:");
            foreach (Building_Dresser d in this.AttachedDressers)
            {
                Log.Warning(" " + d.Label);
            }
#endif

            this.compPowerTrader.powerStartedAction = new Action(delegate()
            {
                this.compPowerTrader.PowerOutput = LOW_POWER_COST;
            });

            this.compPowerTrader.powerStoppedAction = new Action(delegate()
            {
                this.StopRepairing();
                this.compPowerTrader.PowerOutput = 0;
            });
        }
        private void Dispose()
        {
            try
            {
                if (this.StoredWeapons != null)
                {
                    foreach (LinkedList <ThingWithComps> l in this.StoredWeapons.Values)
                    {
                        foreach (ThingWithComps t in l)
                        {
                            this.DropThing(t);
                        }
                    }
                    this.StoredWeapons.Clear();
                }
                if (this.StoredBioEncodedWeapons != null)
                {
                    foreach (LinkedList <ThingWithComps> l in this.StoredBioEncodedWeapons.Values)
                    {
                        foreach (ThingWithComps t in l)
                        {
                            this.DropThing(t);
                        }
                    }
                    this.StoredBioEncodedWeapons.Clear();
                }
            }
            catch (Exception e)
            {
                Log.Error(
                    this.GetType().Name + ".Dispose\n" +
                    e.GetType().Name + " " + e.Message + "\n" +
                    e.StackTrace);
            }

            WorldComp.Remove(this);
            foreach (Building_RepairWeaponStorage r in BuildingUtil.FindThingsOfTypeNextTo <Building_RepairWeaponStorage>(base.Map, base.Position, Settings.RepairAttachmentDistance))
            {
#if DEBUG_REPAIR
                Log.Warning("Removing Dresser " + this.Label + " to " + r.Label);
#endif
                r.Remove(this);
            }
        }
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.CurrentMap = map;

            if (settings == null)
            {
                base.settings = new StorageSettings(this);
                base.settings.CopyFrom(this.def.building.defaultStorageSettings);
                base.settings.filter.SetDisallowAll();
            }
            this.UpdatePreviousStorageFilter();
            WorldComp.Add(this);

            foreach (Building_RepairWeaponStorage r in BuildingUtil.FindThingsOfTypeNextTo <Building_RepairWeaponStorage>(base.Map, base.Position, Settings.RepairAttachmentDistance))
            {
#if DEBUG_REPAIR
                Log.Warning("Adding Dresser " + this.Label + " to " + r.Label);
#endif
                r.Add(this);
            }

            WorldComp.InitializeAssignedWeapons();
        }