Exemplo n.º 1
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     this.powerComp         = base.GetComp <CompPowerTrader>();
     this.refuelableComp    = base.GetComp <CompRefuelable>();
     this.breakdownableComp = base.GetComp <CompBreakdownable>();
 }
Exemplo n.º 2
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     this.powerComp = base.GetComp <CompPowerTrader>();
     LessonAutoActivator.TeachOpportunity(ConceptDefOf.BuildOrbitalTradeBeacon, OpportunityType.GoodToKnow);
     LessonAutoActivator.TeachOpportunity(ConceptDefOf.OpeningComms, OpportunityType.GoodToKnow);
 }
        protected virtual bool CanInteractWith(Pawn pawn, Thing t, bool inBed)
        {
            if (!pawn.CanReserve(t, base.def.jobDef.joyMaxParticipants, -1, null, false))
            {
                return(false);
            }
            if (t.IsForbidden(pawn))
            {
                return(false);
            }
            if (!t.IsSociallyProper(pawn))
            {
                return(false);
            }
            if (!t.IsPoliticallyProper(pawn))
            {
                return(false);
            }
            CompPowerTrader compPowerTrader = t.TryGetComp <CompPowerTrader>();

            if (compPowerTrader != null && !compPowerTrader.PowerOn)
            {
                return(false);
            }
            if (base.def.unroofedOnly && t.Position.Roofed(t.Map))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        public static IntVec3 TradeDropSpot(Map map)
        {
            IEnumerable <Building> collection = from b in map.listerBuildings.allBuildingsColonist
                                                where b.def.IsCommsConsole
                                                select b;
            IEnumerable <Building> enumerable = from b in map.listerBuildings.allBuildingsColonist
                                                where b.def.IsOrbitalTradeBeacon
                                                select b;
            Building building = enumerable.FirstOrDefault((Building b) => !map.roofGrid.Roofed(b.Position) && AnyAdjacentGoodDropSpot(b.Position, map, allowFogged: false, canRoofPunch: false));
            IntVec3  result;

            if (building == null)
            {
                List <Building> list = new List <Building>();
                list.AddRange(enumerable);
                list.AddRange(collection);
                list.RemoveAll(delegate(Building b)
                {
                    CompPowerTrader compPowerTrader = b.TryGetComp <CompPowerTrader>();
                    return(compPowerTrader != null && !compPowerTrader.PowerOn);
                });
                Predicate <IntVec3> validator = (IntVec3 c) => IsGoodDropSpot(c, map, allowFogged: false, canRoofPunch: false);
                if (!list.Any())
                {
                    list.AddRange(map.listerBuildings.allBuildingsColonist);
                    list.Shuffle();
                    if (!list.Any())
                    {
                        return(CellFinderLoose.RandomCellWith(validator, map));
                    }
                }
                int     num = 8;
                int     num2;
                IntVec3 size;
                do
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        IntVec3 position = list[i].Position;
                        if (CellFinder.TryFindRandomCellNear(position, map, num, validator, out result))
                        {
                            return(result);
                        }
                    }
                    num  = Mathf.RoundToInt((float)num * 1.1f);
                    num2 = num;
                    size = map.Size;
                }while (num2 <= size.x);
                Log.Error("Failed to generate trade drop center. Giving random.");
                return(CellFinderLoose.RandomCellWith(validator, map));
            }
            result = building.Position;
            if (!TryFindDropSpotNear(result, map, out IntVec3 result2, allowFogged: false, canRoofPunch: false))
            {
                Log.Error("Could find no good TradeDropSpot near dropCenter " + result + ". Using a random standable unfogged cell.");
                return(CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(map) && !c.Fogged(map), map));
            }
            return(result2);
        }
Exemplo n.º 5
0
 private void EnsurePowerUsersConnected(Map map)
 {
     this.tmpThings.Clear();
     this.tmpThings.AddRange(map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial));
     for (int i = 0; i < this.tmpThings.Count; i++)
     {
         if (this.IsPowerUser(this.tmpThings[i]))
         {
             CompPowerTrader powerComp = this.tmpThings[i].TryGetComp <CompPowerTrader>();
             PowerNet        powerNet  = powerComp.PowerNet;
             if (powerNet != null && powerNet.hasPowerSource)
             {
                 this.TryTurnOnImmediately(powerComp, map);
             }
             else
             {
                 map.powerNetManager.UpdatePowerNetsAndConnections_First();
                 PowerNet powerNet2;
                 IntVec3  dest;
                 if (this.TryFindClosestReachableNet(powerComp.parent.Position, (PowerNet x) => x.CurrentEnergyGainRate() - powerComp.Props.basePowerConsumption * CompPower.WattsToWattDaysPerTick > 1E-07f, map, out powerNet2, out dest))
                 {
                     map.floodFiller.ReconstructLastFloodFillPath(dest, this.tmpCells);
                     bool flag = false;
                     if (this.canSpawnPowerGenerators && this.tmpThings[i] is Building_Turret && this.tmpCells.Count > 13)
                     {
                         flag = this.TrySpawnPowerGeneratorAndBatteryIfCanAndConnect(this.tmpThings[i], map);
                     }
                     if (!flag)
                     {
                         this.SpawnTransmitters(this.tmpCells, map, this.tmpThings[i].Faction);
                     }
                     this.TryTurnOnImmediately(powerComp, map);
                 }
                 else if (this.canSpawnPowerGenerators && this.TrySpawnPowerGeneratorAndBatteryIfCanAndConnect(this.tmpThings[i], map))
                 {
                     this.TryTurnOnImmediately(powerComp, map);
                 }
                 else if (this.TryFindClosestReachableNet(powerComp.parent.Position, (PowerNet x) => x.CurrentStoredEnergy() > 1E-07f, map, out powerNet2, out dest))
                 {
                     map.floodFiller.ReconstructLastFloodFillPath(dest, this.tmpCells);
                     this.SpawnTransmitters(this.tmpCells, map, this.tmpThings[i].Faction);
                 }
                 else if (this.canSpawnBatteries)
                 {
                     Building building;
                     if (this.TrySpawnBatteryNear(this.tmpThings[i].Position, map, this.tmpThings[i].Faction, out building))
                     {
                         this.SpawnTransmitters(this.tmpThings[i].Position, building.Position, map, this.tmpThings[i].Faction);
                         if (building.GetComp <CompPowerBattery>().StoredEnergy > 0f)
                         {
                             this.TryTurnOnImmediately(powerComp, map);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        public static bool Applies(Thing th)
        {
            if (th.def.building.unpoweredWorkTableWorkSpeedFactor == 0f)
            {
                return(false);
            }
            CompPowerTrader compPowerTrader = th.TryGetComp <CompPowerTrader>();

            return(compPowerTrader != null && !compPowerTrader.PowerOn);
        }
Exemplo n.º 7
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     this.powerComp = base.GetComp <CompPowerTrader>();
     this.ClearReachabilityCache(map);
     if (this.BlockedOpenMomentary)
     {
         this.DoorOpen(60);
     }
 }
Exemplo n.º 8
0
        private bool IsPowerGenerator(Thing thing)
        {
            if (thing.TryGetComp <CompPowerPlant>() != null)
            {
                return(true);
            }
            CompPowerTrader compPowerTrader = thing.TryGetComp <CompPowerTrader>();

            return(compPowerTrader != null && (compPowerTrader.PowerOutput > 0f || (!compPowerTrader.PowerOn && compPowerTrader.Props.basePowerConsumption < 0f)));
        }
 public static IEnumerable <Building_OrbitalTradeBeacon> AllPowered(Map map)
 {
     foreach (Building_OrbitalTradeBeacon item in map.listerBuildings.AllBuildingsColonistOfClass <Building_OrbitalTradeBeacon>())
     {
         CompPowerTrader comp = item.GetComp <CompPowerTrader>();
         if (comp == null || comp.PowerOn)
         {
             yield return(item);
         }
     }
 }
Exemplo n.º 10
0
 private void TryTurnOnImmediately(CompPowerTrader powerComp, Map map)
 {
     if (!powerComp.PowerOn)
     {
         map.powerNetManager.UpdatePowerNetsAndConnections_First();
         if (powerComp.PowerNet != null && powerComp.PowerNet.CurrentEnergyGainRate() > 1E-07f)
         {
             powerComp.PowerOn = true;
         }
     }
 }
Exemplo n.º 11
0
 public static IEnumerable <Building_OrbitalTradeBeacon> AllPowered(Map map)
 {
     foreach (Building_OrbitalTradeBeacon b in map.listerBuildings.AllBuildingsColonistOfClass <Building_OrbitalTradeBeacon>())
     {
         CompPowerTrader power = b.GetComp <CompPowerTrader>();
         if (power == null || power.PowerOn)
         {
             yield return(b);
         }
     }
 }
Exemplo n.º 12
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     powerComp         = GetComp <CompPowerTrader>();
     refuelableComp    = GetComp <CompRefuelable>();
     breakdownableComp = GetComp <CompBreakdownable>();
     foreach (Bill item in billStack)
     {
         item.ValidateSettings();
     }
 }
Exemplo n.º 13
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     this.powerComp         = base.GetComp <CompPowerTrader>();
     this.refuelableComp    = base.GetComp <CompRefuelable>();
     this.breakdownableComp = base.GetComp <CompBreakdownable>();
     foreach (Bill bill in this.billStack)
     {
         bill.ValidateSettings();
     }
 }
Exemplo n.º 14
0
        public bool ThreatDisabled(IAttackTargetSearcher disabledFor)
        {
            CompPowerTrader comp = base.GetComp <CompPowerTrader>();

            if (comp != null && !comp.PowerOn)
            {
                return(true);
            }
            CompMannable comp2 = base.GetComp <CompMannable>();

            return(comp2 != null && !comp2.MannedNow);
        }
Exemplo n.º 15
0
        private bool IsActivePowerSource(CompPower cp)
        {
            CompPowerBattery compPowerBattery = cp as CompPowerBattery;

            if (compPowerBattery != null && compPowerBattery.StoredEnergy > 0f)
            {
                return(true);
            }
            CompPowerTrader compPowerTrader = cp as CompPowerTrader;

            return(compPowerTrader != null && compPowerTrader.PowerOutput > 0f);
        }
Exemplo n.º 16
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     dormantComp     = GetComp <CompCanBeDormant>();
     initiatableComp = GetComp <CompInitiatable>();
     powerComp       = GetComp <CompPowerTrader>();
     mannableComp    = GetComp <CompMannable>();
     if (!respawningAfterLoad)
     {
         top.SetRotationFromOrientation();
         burstCooldownTicksLeft = def.building.turretInitialCooldownTime.SecondsToTicks();
     }
 }
Exemplo n.º 17
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);

            powerComp = GetComp <CompPowerTrader>();
            ClearReachabilityCache(map);

            // Open the door if we're spawning on top of something
            if (BlockedOpenMomentary)
            {
                DoorOpen();
            }
        }
		public bool ThreatDisabled()
		{
			CompPowerTrader comp = base.GetComp<CompPowerTrader>();
			if (comp != null && !comp.PowerOn)
			{
				return true;
			}
			CompMannable comp2 = base.GetComp<CompMannable>();
			if (comp2 != null && !comp2.MannedNow)
			{
				return true;
			}
			return false;
		}
Exemplo n.º 19
0
        private void DeregisterAllComponentsOf(ThingWithComps parentThing)
        {
            CompPowerTrader comp = parentThing.GetComp <CompPowerTrader>();

            if (comp != null)
            {
                this.powerComps.Remove(comp);
            }
            CompPowerBattery comp2 = parentThing.GetComp <CompPowerBattery>();

            if (comp2 != null)
            {
                this.batteryComps.Remove(comp2);
            }
        }
 public static bool PlayerHasPoweredCommsConsole(Map map)
 {
     foreach (Building_CommsConsole item in map.listerBuildings.AllBuildingsColonistOfClass <Building_CommsConsole>())
     {
         if (item.Faction == Faction.OfPlayer)
         {
             CompPowerTrader compPowerTrader = item.TryGetComp <CompPowerTrader>();
             if (compPowerTrader == null || compPowerTrader.PowerOn)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 21
0
        private bool IsPowerGenerator(Thing thing)
        {
            bool result;

            if (thing.TryGetComp <CompPowerPlant>() != null)
            {
                result = true;
            }
            else
            {
                CompPowerTrader compPowerTrader = thing.TryGetComp <CompPowerTrader>();
                result = (compPowerTrader != null && (compPowerTrader.PowerOutput > 0f || (!compPowerTrader.PowerOn && compPowerTrader.Props.basePowerConsumption < 0f)));
            }
            return(result);
        }
Exemplo n.º 22
0
        public static bool Applies(Thing th)
        {
            bool result;

            if (th.def.building.unpoweredWorkTableWorkSpeedFactor == 0f)
            {
                result = false;
            }
            else
            {
                CompPowerTrader compPowerTrader = th.TryGetComp <CompPowerTrader>();
                result = (compPowerTrader != null && !compPowerTrader.PowerOn);
            }
            return(result);
        }
Exemplo n.º 23
0
        private bool IsActivePowerSource(CompPower cp)
        {
            CompPowerBattery compPowerBattery = cp as CompPowerBattery;
            bool             result;

            if (compPowerBattery != null && compPowerBattery.StoredEnergy > 0f)
            {
                result = true;
            }
            else
            {
                CompPowerTrader compPowerTrader = cp as CompPowerTrader;
                result = (compPowerTrader != null && compPowerTrader.PowerOutput > 0f);
            }
            return(result);
        }
Exemplo n.º 24
0
        public static IEnumerable <Building_OrbitalTradeBeacon> AllPowered(Map map)
        {
            foreach (Building_OrbitalTradeBeacon item in map.listerBuildings.AllBuildingsColonistOfClass <Building_OrbitalTradeBeacon>())
            {
                CompPowerTrader power = item.GetComp <CompPowerTrader>();
                if (power == null || power.PowerOn)
                {
                    yield return(item);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield break;
IL_00ef:
            /*Error near IL_00f0: Unexpected return in MoveNext()*/;
        }
Exemplo n.º 25
0
        public bool ThreatDisabled(IAttackTargetSearcher disabledFor)
        {
            CompPowerTrader comp = base.GetComp <CompPowerTrader>();
            bool            result;

            if (comp != null && !comp.PowerOn)
            {
                result = true;
            }
            else
            {
                CompMannable comp2 = base.GetComp <CompMannable>();
                result = (comp2 != null && !comp2.MannedNow);
            }
            return(result);
        }
Exemplo n.º 26
0
        public override bool ShouldSkip(Pawn pawn, bool forced = false)
        {
            List <Building> allBuildingsColonist = pawn.Map.listerBuildings.allBuildingsColonist;

            for (int i = 0; i < allBuildingsColonist.Count; i++)
            {
                if (allBuildingsColonist[i].def == ThingDefOf.DeepDrill)
                {
                    CompPowerTrader comp = allBuildingsColonist[i].GetComp <CompPowerTrader>();
                    if (comp == null || comp.PowerOn)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 27
0
        public static bool PlayerHasPoweredCommsConsole(Map map)
        {
            List <Thing> list = map.listerThings.ThingsMatching(ThingRequest.ForDef(ThingDefOf.CommsConsole));

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Faction == Faction.OfPlayer)
                {
                    CompPowerTrader compPowerTrader = list[i].TryGetComp <CompPowerTrader>();
                    if (compPowerTrader == null || compPowerTrader.PowerOn)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
 public static void DisconnectAllFromTransmitterAndSetWantConnect(CompPower deadPc, Map map)
 {
     if (deadPc.connectChildren != null)
     {
         for (int i = 0; i < deadPc.connectChildren.Count; i++)
         {
             CompPower compPower = deadPc.connectChildren[i];
             compPower.connectParent = null;
             CompPowerTrader compPowerTrader = compPower as CompPowerTrader;
             if (compPowerTrader != null)
             {
                 compPowerTrader.PowerOn = false;
             }
             map.powerNetManager.Notify_ConnectorWantsConnect(compPower);
         }
     }
 }
Exemplo n.º 29
0
        protected override ThoughtState CurrentStateInternal(Pawn p)
        {
            if (!p.Spawned)
            {
                return(false);
            }
            List <Thing> list = p.Map.listerThings.ThingsOfDef(ThingDefOf.PsychicEmanator);

            for (int i = 0; i < list.Count; i++)
            {
                CompPowerTrader compPowerTrader = list[i].TryGetComp <CompPowerTrader>();
                if ((compPowerTrader == null || compPowerTrader.PowerOn) && p.Position.InHorDistOf(list[i].Position, 15f))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 30
0
        public override bool ShouldSkip(Pawn pawn, bool forced = false)
        {
            List <Building> allBuildingsColonist = pawn.Map.listerBuildings.allBuildingsColonist;

            for (int i = 0; i < allBuildingsColonist.Count; i++)
            {
                Building building = allBuildingsColonist[i];
                if (building.def == ThingDefOf.DeepDrill)
                {
                    CompPowerTrader comp = building.GetComp <CompPowerTrader>();
                    if ((comp == null || comp.PowerOn) && building.Map.designationManager.DesignationOn(building, DesignationDefOf.Uninstall) == null)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }