public override void CompTick() { base.CompTick(); ticker++; if (ticker >= Props.scuttlePollInTicks) { ticker = 0; if (compRefuelable == null) { compRefuelable = parent.TryGetComp <CompRefuelable>(); } if (compRefuelable == null || !BlackFuelUtil.CarbonThingsExist || compRefuelable.IsFull) { return; } if (parent.IsForbidden(parent.Faction)) { return; } CompFlickable compFlickable = parent.GetComp <CompFlickable>(); if (compFlickable != null && !compFlickable.SwitchIsOn) { return; } if (!compRefuelable.ShouldAutoRefuelNow) { return; } Thing fuelThing = FindFuelInAnyScuttle(); if (fuelThing != null) { // should I check if the item is forbidden first? Core hopper logic doesn't seem to... int fuelNeeded = compRefuelable.GetFuelCountToFullyRefuel(); int fuelThingValue = fuelThing.stackCount; if (BlackFuelUtil.IsCarbonThing(fuelThing)) { fuelNeeded /= 3; fuelThingValue *= 3; } if (fuelThingValue <= fuelNeeded) { compRefuelable.Refuel(fuelThingValue); fuelThing.Destroy(); } else { compRefuelable.Refuel(fuelThingValue); fuelThing.stackCount -= fuelNeeded; } } } }
public override void PostMake() { base.PostMake(); refuelableComp = GetComp <CompRefuelable>(); refuelableComp.Refuel(extension.GetDronesOnSpawn(refuelableComp)); }
private void DoDestroyDestroyable() { foreach (var itemPos in destroyableItems) { List <Thing> items = itemPos.GetThingList(Site.Map); foreach (var item in items) { CompRefuelable compRefuelable = item.TryGetComp <CompRefuelable>(); if (compRefuelable != null) { float refuelInt = Mathf.Clamp(compRefuelable.Fuel - compRefuelable.Props.fuelCapacity, 0, compRefuelable.Props.fuelCapacity); compRefuelable.Refuel(refuelInt); } CompBreakdownable compBreakdownable = item.TryGetComp <CompBreakdownable>(); if (compBreakdownable != null) { compBreakdownable.DoBreakdown(); } if (item.def.CanHaveFaction) { item.SetFaction(Faction.OfPlayer); } } } }
private void UnburrowTurret() { SoundDefOf.DropPod_Open.PlayOneShot(new TargetInfo(this.Position, this.Map, false)); Map map = base.Map; IntVec3 loc = this.Position; float HPp = (float)this.HitPoints / (float)this.MaxHitPoints; if (insideStuff) { Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named(insideman), this.Stuff), loc, map, WipeMode.Vanish); thing.SetFaction(Faction.OfPlayer, null); thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp); if (insidefuel >= 0) { CompRefuelable refuelableComp = ((ThingWithComps)thing).GetComp <CompRefuelable>(); refuelableComp.ConsumeFuel(9999); refuelableComp.Refuel((insidefuel / refuelableComp.Props.FuelMultiplierCurrentDifficulty)); } } else { Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named(insideman), null), loc, map, WipeMode.Vanish); thing.SetFaction(Faction.OfPlayer, null); thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp); if (insidefuel >= 0) { CompRefuelable refuelableComp = ((ThingWithComps)thing).GetComp <CompRefuelable>(); refuelableComp.ConsumeFuel(9999); refuelableComp.Refuel((insidefuel / refuelableComp.Props.FuelMultiplierCurrentDifficulty)); } } }
public override void DoEffect(Pawn usedBy) { base.DoEffect(usedBy); CompRefuelable refuelable = usedBy.equipment.Primary.GetComp <CompRefuelable>(); int needAmount = (int)(refuelable.Props.fuelCapacity - refuelable.Fuel); if (parent.stackCount > needAmount) { refuelable.Refuel(needAmount); parent.SplitOff(needAmount).Destroy(DestroyMode.Vanish); } else { refuelable.Refuel(parent.stackCount); parent.Destroy(DestroyMode.Vanish); } }
public override void CompTick() { base.CompTick(); if (this.parent.Spawned && this.parent.Map.weatherManager.RainRate > 0.4f && !this.parent.Map.roofGrid.Roofed(this.parent.Position)) { refuelableComp.Refuel(0.03f); } }
public override void CompTick() { //null map check if (this.parent.Map != null && (!Props.mustBeTamed || (this.parent.Faction != null && this.parent.Faction.IsPlayer))) { tickCounter++; //Only do every fuelingRate ticks if (tickCounter >= Props.fuelingRate) { Pawn pawn = this.parent as Pawn; CellRect rect = GenAdj.OccupiedRect(pawn.Position, pawn.Rotation, IntVec2.One); rect = rect.ExpandedBy(Props.fuelingRadius); List <Building> buildingsInRange = new List <Building>(); foreach (IntVec3 current in rect.Cells) { if (current.InBounds(pawn.Map)) { Building edifice = current.GetEdifice(pawn.Map); //If any buildings were found in the requested area if (edifice != null) { foreach (string defNameOfBuilding in Props.buildingsToAffect) { if (edifice.def.defName == defNameOfBuilding) { buildingsInRange.Add(edifice); } } } } } //If any building was found if (buildingsInRange.Count > 0) { //Affect a random one if more than one was found Building buildingToAffect = buildingsInRange.RandomElement(); CompRefuelable comp = buildingToAffect.TryGetComp <CompRefuelable>(); if (comp != null) { comp.Refuel(1); } } tickCounter = 0; } } }
public static void PlaceBuildingsAndItems(List <MapObject> mapObjects, Map map, Faction forceFaction, bool refuel) { foreach (var thing in mapObjects) { ThingData data = thing.key; if (data.Thing != null) { foreach (var pos in thing.value) { Thing newThing = ThingMaker.MakeThing(data.Thing, data.Stuff); var comp = newThing.TryGetComp <CompQuality>(); if (comp != null) { comp.SetQuality(data.Quality, ArtGenerationContext.Colony); } if (newThing.def.stackLimit != 1) { newThing.stackCount = data.Count; } newThing = GenSpawn.Spawn(newThing, pos, map, data.Rotate); CompGatherSpot compGathering = newThing.TryGetComp <CompGatherSpot>(); if (compGathering != null) { compGathering.Active = false; } if (newThing.def.CanHaveFaction && forceFaction != null) { newThing.SetFaction(forceFaction); } CompRefuelable compRefuelable = newThing.TryGetComp <CompRefuelable>(); if (compRefuelable != null && refuel) { compRefuelable.Refuel(compRefuelable.Props.fuelCapacity); } } } } }
public virtual void Histolysis() { if (HasAnyContents) { Pawn pawn = ContainedThing as Pawn; if (pawn != null) { compRefuelable.Refuel(35); DamageInfo d = new DamageInfo(); d.Def = DamageDefOf.Burn; d.SetAmount(1000); pawn.Kill(d); try { CompRottable compRottable = ContainedThing.TryGetComp <CompRottable>(); if (compRottable != null) { compRottable.RotProgress += 600000f; } MakeFuel(); } catch (Exception ee) { Log.Message("Rot Error" + ee); } if (pawn.RaceProps.Humanlike) { foreach (Pawn p in this.Map.mapPawns.SpawnedPawnsInFaction(Faction)) { if (p.needs != null && p.needs.mood != null && p.needs.mood.thoughts != null) { p.needs.mood.thoughts.memories.TryGainMemory(BioReactorThoughtDef.KnowHistolysisHumanlike, null); p.needs.mood.thoughts.memories.TryGainMemory(BioReactorThoughtDef.KnowHistolysisHumanlikeCannibal, null); p.needs.mood.thoughts.memories.TryGainMemory(BioReactorThoughtDef.KnowHistolysisHumanlikePsychopath, null); } } } } } }
public override void Tick() { base.Tick(); if (this.IsHashIntervalTick(10) && GetComp <CompPowerTrader>().PowerOn) { foreach (IntVec3 cell in GenAdj.CellsAdjacent8Way(this)) { Thing item = cell.GetFirstItem(Map); if (item != null) { CompRefuelable refuelableComp = FuelableCell.GetFirstBuilding(Map)?.GetComp <CompRefuelable>(); if (refuelableComp != null && refuelableComp.Fuel + 1 < refuelableComp.TargetFuelLevel && refuelableComp.Props.fuelFilter.Allows(item)) { int num = Mathf.Min(item.stackCount, Mathf.CeilToInt(refuelableComp.TargetFuelLevel - refuelableComp.Fuel)); if (num > 0) { refuelableComp.Refuel(num); item.SplitOff(num).Destroy(); } } } } } }
// Fill the cell with Thing (Building) private static void TrySetCell_2_SetThing(IntVec3 c, Map map, Faction faction, ThingData thingData, Rot4 thingRot, ThingDef stuffDef = null) { if (thingData == null) { return; } if (!Rand.Chance(thingData.Chance)) { return; } //Note: Here is no functionality to clear the cell by design, because it is possible to place items that are larger than 1x1 // 2nd step - work with the Thing (Buildings) if (thingData.Thing != null) { ThingDef thingDef = thingData.Thing; ThingDef stuffDef1 = null; if (thingData.Stuff.Count > 0) { float value = Rand.Value; foreach (var pair in thingData.Stuff.OrderBy(pair => pair.Value)) { if (value < pair.Value) { stuffDef1 = pair.Key; break; } } } if (stuffDef1 == null) { stuffDef1 = stuffDef; } if (!thingDef.MadeFromStuff) { stuffDef1 = null; } Thing newThing = ThingMaker.MakeThing(thingDef, stuffDef1); if (thingData.Quality.Count > 0) { var comp = newThing.TryGetComp <CompQuality>(); if (comp != null) { float value = Rand.Value; foreach (var pair in thingData.Quality.OrderBy(pair => pair.Value)) { if (value < pair.Value) { comp.SetQuality(pair.Key, ArtGenerationContext.Outsider); break; } } } } if (thingRot == null || thingRot == Rot4.Invalid) { newThing = GenSpawn.Spawn(newThing, c, map); } else { newThing = GenSpawn.Spawn(newThing, c, map, thingRot); } // Set it to the current faction newThing.SetFactionDirect(faction); // If CompGatherSpot -> disable it! CompGatherSpot compGathering = newThing.TryGetComp <CompGatherSpot>(); if (compGathering != null) { compGathering.Active = false; } CompRefuelable compRefuelable = newThing.TryGetComp <CompRefuelable>(); if (compRefuelable != null) { compRefuelable.Refuel(compRefuelable.Props.fuelCapacity); } } }
public void Refuel() { if (!GetComp <CompPowerTrader>().PowerOn) { return; } // Get what we are supposed to refuel: // (only refuel one thing - if you need to adjust this to fuel more // than one thing, make the loop here and put some breaking logic // instead of all the "return;"s below) CompRefuelable refuelableComp = null; var thingsOnRefuelCell = Map.thingGrid.ThingsListAt(FuelableCell); // Refuel action might cause thing to to be added to that cell, this ensures no list modification while iterating. var clonedThingsOnRefuelCell = new List <Thing>(thingsOnRefuelCell); foreach (Thing tmpThing in clonedThingsOnRefuelCell) { if (tmpThing is Building) { refuelableComp = (tmpThing as Building).GetComp <CompRefuelable>(); // Check if there is already enough fuel: // (because Fuel is a float, we check the current fuel + .99, so it // only refuels when Fuel drops at least one full unit below taret level) if (refuelableComp != null && refuelableComp.Fuel + 0.9999f < refuelableComp.TargetFuelLevel) { foreach (Thing item in this.AllThingsForFueling) { if (refuelableComp.Props.fuelFilter.Allows(item)) { // round down to not waste fuel: int num = Mathf.Min(item.stackCount, Mathf.FloorToInt(refuelableComp.TargetFuelLevel - refuelableComp.Fuel)); if (num > 0) { refuelableComp.Refuel(num); item.SplitOff(num).Destroy(); } else { // It's not quite 1 below TargetFuelLevel // but we KNOW we are at least .9999f below TargetFuelLevel (see test above) // So we call it close enough to 1: refuelableComp.Refuel(1); item.SplitOff(1).Destroy(); } // check fuel as float (as above) if (refuelableComp.Fuel + 0.9999f >= refuelableComp.TargetFuelLevel) { goto Fueled; // fully fueled } } } } } // end if is Building Fueled: //This is a generalized system for mod compatibility - mostlyfor Mortar like buildings foreach (var rr in registeredRefuelables) { // basically, if (tmpThing is Building_From_rr) if (rr.buildingType.IsAssignableFrom(tmpThing.GetType())) { object o = rr.objectThatNeedsFueling(tmpThing as Building); if (o != null) { // it needs "refueling" - or ammo loaded foreach (Thing t in AllThingsForFueling) { int count = rr.fuelTest(o, t); if (count > 0) { // it wants some of this for fuel/ammo! Thing fuel = t.SplitOff(count); rr.refuelAction(o, fuel); goto Fueled; // jump back to beginning to make sure it's fully fueled. } } } } } } // end loop checking for things that need fuel }
private void UnburrowTurret() { SoundDefOf.DropPod_Open.PlayOneShot(new TargetInfo(this.Position, this.Map, false)); Map map = base.Map; IntVec3 loc = this.Position; float HPp = (float)this.HitPoints / (float)this.MaxHitPoints; Thing thing; if (insideStuff) { thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named(insideman), this.Stuff), loc, map, WipeMode.Vanish); } else { thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named(insideman), null), loc, map, WipeMode.Vanish); } thing.SetFaction(Faction.OfPlayer, null); thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp); if (thing.HitPoints < thing.MaxHitPoints) { thing.Map.listerBuildingsRepairable.Notify_BuildingTookDamage((Building)thing); } if (insidefuel >= 0) { CompRefuelable refuelableComp = ((ThingWithComps)thing).GetComp <CompRefuelable>(); refuelableComp.ConsumeFuel(9999); refuelableComp.Refuel((insidefuel / refuelableComp.Props.FuelMultiplierCurrentDifficulty)); } try { ((Action)(() => { if (upgradedbyturretextensions) { TurretExtensions.CompUpgradable compUP = ((ThingWithComps)thing).GetComp <TurretExtensions.CompUpgradable>(); thing.HitPoints = (int)(Math.Ceiling((thing.MaxHitPoints + TE_HP_Offset) * TE_HP_Factor * HPp)); compUP.upgraded = true; } }))(); } catch (TypeLoadException ex) { //Log.Message("error in unburrowTurret XP"); } /*if (insideStuff) * { * * Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named(insideman), this.Stuff), loc, map, WipeMode.Vanish); * thing.SetFaction(Faction.OfPlayer, null); * thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp); * if (thing.HitPoints < thing.MaxHitPoints) * { * thing.Map.listerBuildingsRepairable.Notify_BuildingTookDamage((Building)thing); * } * if (insidefuel >= 0) * { * CompRefuelable refuelableComp = ((ThingWithComps)thing).GetComp<CompRefuelable>(); * refuelableComp.ConsumeFuel(9999); * refuelableComp.Refuel((insidefuel / refuelableComp.Props.FuelMultiplierCurrentDifficulty)); * } * try * { * ((Action)(() => * { * if (upgradedbyturretextensions) * { * TurretExtensions.CompUpgradable compUP = ((ThingWithComps)thing).GetComp<TurretExtensions.CompUpgradable>(); * thing.HitPoints = (int)(Math.Ceiling((thing.MaxHitPoints + TE_HP_Offset) * TE_HP_Factor * HPp)); * compUP.upgraded = true; * * } * }))(); * } * catch (TypeLoadException ex) * { * //Log.Message("error in unburrowTurret XP"); * } * * } * else * { * Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named(insideman), null), loc, map, WipeMode.Vanish); * thing.SetFaction(Faction.OfPlayer, null); * thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp); * if (thing.HitPoints < thing.MaxHitPoints) * { * thing.Map.listerBuildingsRepairable.Notify_BuildingTookDamage((Building)thing); * } * if (insidefuel >= 0) * { * CompRefuelable refuelableComp = ((ThingWithComps)thing).GetComp<CompRefuelable>(); * refuelableComp.ConsumeFuel(9999); * refuelableComp.Refuel((insidefuel / refuelableComp.Props.FuelMultiplierCurrentDifficulty)); * } * try * { * ((Action)(() => * { * if (upgradedbyturretextensions) * { * TurretExtensions.CompUpgradable compUP = ((ThingWithComps)thing).GetComp<TurretExtensions.CompUpgradable>(); * thing.HitPoints = (int)(Math.Ceiling((thing.MaxHitPoints + TE_HP_Offset) * TE_HP_Factor * HPp)); * compUP.upgraded = true; * * } * }))(); * } * catch (TypeLoadException ex) * { * Log.Message("error in unburrowTurret XP"); * } * * } * */ }
private void CentaurAlphaShipPostProcess(Map spaceMap) { spaceMap.fogGrid.ClearAllFog(); /*foreach (Letter letter in Find.LetterStack.LettersListForReading) * { * Find.LetterStack.RemoveLetter(letter); * }*/ List <Thing> things = spaceMap.listerThings.AllThings; Thing targetTorpedo = null; IntVec3 torpedoToLocation = new IntVec3(0, 0, 0); IntVec3? sunLampLocation = null; foreach (Thing thing in things) { try { if (thing.def == ThingDefOf.MinifiedThing) { Thing thingInside = ((MinifiedThing)thing).InnerThing; if (thingInside.TryGetComp <CompPowerBattery>() != null) { thingInside?.TryGetComp <CompPowerBattery>()?.AddEnergy(float.PositiveInfinity); } } if (sunLampLocation == null && thing.def == DefDatabase <ThingDef> .GetNamed("SunLamp")) { sunLampLocation = thing.Position; } if (thing?.TryGetComp <CompForbiddable>() != null) { thing.TryGetComp <CompForbiddable>().Forbidden = false; } if (thing?.TryGetComp <CompQuality>() != null) { thing.TryGetComp <CompQuality>().SetQuality(QualityCategory.Legendary, ArtGenerationContext.Colony); } if (thing?.TryGetComp <CompArt>() != null) { thing.TryGetComp <CompArt>().JustCreatedBy(spaceMap.mapPawns.AllPawns.RandomElement()); } if (thing?.TryGetComp <CompRefuelable>() != null) { //thing.def == DefDatabase<ThingDef>.GetNamed("Ship_Engine_Small") || //thing.def == DefDatabase<ThingDef>.GetNamed("Ship_Engine") || //thing.def == DefDatabase<ThingDef>.GetNamed("Ship_Engine_Large") CompRefuelable fuelTarget = thing?.TryGetComp <CompRefuelable>(); fuelTarget?.Refuel(fuelTarget.Props.fuelCapacity); } if (thing?.TryGetComp <CompTempControl>() != null) { thing.TryGetComp <CompTempControl>().targetTemperature = 19f; } if (thing?.TryGetComp <CompBreakdownable>() != null) { } if (thing?.TryGetComp <CompPower>() != null) { } if ( thing?.def?.building?.buildingTags?.Contains("Production") == true && thing?.TryGetComp <CompFlickable>() != null && thing.def != DefDatabase <ThingDef> .GetNamed("HydroponicsBasin") ) { thing.TryGetComp <CompFlickable>().SwitchIsOn = false; } if (thing.def == DefDatabase <ThingDef> .GetNamed("HydroponicsBasin")) { ((Building_PlantGrower)thing)?.SetPlantDefToGrow(ThingDefOf.Plant_Potato); thing.TryGetComp <CompForbiddable>().Forbidden = true; } if (thing.def == ThingDefOf.Blight) { ((Blight)thing).Severity = 0.05f; } if (thing.def == DefDatabase <ThingDef> .GetNamed("ShipCombatShieldGenerator")) { thing.TryGetComp <CompFlickable>().SwitchIsOn = false; thing.TryGetComp <CompBreakdownable>()?.DoBreakdown(); } if (thing.def == DefDatabase <ThingDef> .GetNamed("ShipTurret_Laser")) { ((Building_ShipTurret)thing).PointDefenseMode = true; } if (thing.def == DefDatabase <ThingDef> .GetNamed("Plant_Potato")) { ((Plant)thing).Growth = 0.85f; } /*if (thing.def == DefDatabase<ThingDef>.GetNamed("ShipTorpedoOne")) * { * foreach (Thing thingInside in ((Building_ShipTurretTorpedo)thing).Contents.innerContainer) * { * if (thing.def == DefDatabase<ThingDef>.GetNamed("ShipTorpedo_HighExplosive")) * { * thing.def = DefDatabase<ThingDef>.GetNamed("ShipTorpedo_EMP"); * } * } * }*/ if ( thing.def == DefDatabase <ThingDef> .GetNamed("ComponentIndustrial") || thing.def == DefDatabase <ThingDef> .GetNamed("ShipTorpedo_HighExplosive") || thing.def == DefDatabase <ThingDef> .GetNamed("ShipTorpedo_EMP") || thing.def == DefDatabase <ThingDef> .GetNamed("Chemfuel") || thing.def == DefDatabase <ThingDef> .GetNamed("ShuttleFuelPods") || thing.def == DefDatabase <ThingDef> .GetNamed("WoodLog") || thing.def == DefDatabase <ThingDef> .GetNamed("Shell_EMP") ) { //Log.Message("[Explorite]Patching stack."); thing.stackCount = thing.def.stackLimit; foreach (Thing thingInGrid in spaceMap.thingGrid.ThingsAt(thing.Position)) { if (thingInGrid.def == DefDatabase <ThingDef> .GetNamed("Shelf")) { ((Building_Storage)thingInGrid).settings.filter.SetDisallowAll(); ((Building_Storage)thingInGrid).settings.filter.SetAllow(thing.def, true); } } } /*if (thing.def == DefDatabase<ThingDef>.GetNamed("ShipTorpedo_HighExplosive")) * { * //Log.Message("[Explorite]Patching HE."); * thing.stackCount = 1; * //thing.def = DefDatabase<ThingDef>.GetNamed("ShipTorpedo_EMP"); * }*/ if (thing.def == DefDatabase <ThingDef> .GetNamed("Shelf")) { torpedoToLocation.z = Math.Max(thing.Position.z, torpedoToLocation.z); } if (thing.def == DefDatabase <ThingDef> .GetNamed("ShipTorpedo_HighExplosive")) { torpedoToLocation.x = Math.Max(thing.Position.x, torpedoToLocation.x); if (targetTorpedo == null) { targetTorpedo = thing; } else if (thing.Position.z > targetTorpedo.Position.z) { targetTorpedo = thing; } } for (int i = -4; i < 5; i++) { for (int j = -4; j < 5; j++) { spaceMap.areaManager.Home[new IntVec3(i, 0, j) + thing.Position] = true; } } } catch { } } targetTorpedo.Position = torpedoToLocation; /* * Thing InterplanetaryEngineL = ThingMaker.MakeThing(ThingDef.Named("Ship_Engine_Interplanetary")); * InterplanetaryEngineL.SetFaction(Faction.OfPlayer); * GenSpawn.Spawn(InterplanetaryEngineL, new IntVec3(-18,0,-28), spaceMap); * Thing InterplanetaryEngineR = ThingMaker.MakeThing(ThingDef.Named("Ship_Engine_Interplanetary")); * InterplanetaryEngineR.SetFaction(Faction.OfPlayer); * GenSpawn.Spawn(InterplanetaryEngineR, new IntVec3(18,0,-28), spaceMap); * //((Blueprint_Build)InterplanetaryEngineL).; */ if (false && sunLampLocation.HasValue) { IntVec3 leftEngine = new IntVec3(sunLampLocation.Value.ToVector3()); leftEngine.x -= 18; leftEngine.z -= 17; IntVec3 rightEngine = new IntVec3(sunLampLocation.Value.ToVector3()); leftEngine.x += 18; rightEngine.z -= 17; Thing InterplanetaryEngineL = ThingMaker.MakeThing(ThingDef.Named("Blueprint_Ship_Engine_Interplanetary")); InterplanetaryEngineL.SetFaction(Faction.OfPlayer); GenSpawn.Spawn(InterplanetaryEngineL, leftEngine, spaceMap); Thing InterplanetaryEngineR = ThingMaker.MakeThing(ThingDef.Named("Blueprint_Ship_Engine_Interplanetary")); InterplanetaryEngineR.SetFaction(Faction.OfPlayer); GenSpawn.Spawn(InterplanetaryEngineR, rightEngine, spaceMap); } /* * List<Building> thingsRocket = spaceMap.listerBuildings.allBuildingsColonist; * foreach (Building thing in thingsBatteryIn) * { * try * { * if ( * thing?.TryGetComp<CompRefuelable>() != null * //thing.def == DefDatabase<ThingDef>.GetNamed("Ship_Engine_Small") || * //thing.def == DefDatabase<ThingDef>.GetNamed("Ship_Engine") || * //thing.def == DefDatabase<ThingDef>.GetNamed("Ship_Engine_Large") * ) * { * CompRefuelable fuelTarget = thing?.TryGetComp<CompRefuelable>(); * fuelTarget.ConsumeFuel( * fuelTarget.Fuel - * fuelTarget.Props.fuelCapacity * ); * } * } * catch { } * }*/ }
public override void Notify_ConstructGained() { refeulableComp.Refuel(1); }
public override void Notify_DroneGained() { refuelableComp.Refuel(1); }
public void Refuel() { if (GetComp <CompPowerTrader>().PowerOn) { // Get what we are supposed to refuel: // (only refuel one thing - if you need to adjust this to fuel more // than one thing, make the loop here and put some breaking logic // instead of all the "return;"s below) CompRefuelable refuelableComp = null; foreach (Thing tmpThing in Map.thingGrid.ThingsListAt(FuelableCell)) { if (tmpThing is Building) { refuelableComp = (tmpThing as Building).GetComp <CompRefuelable>(); } if (refuelableComp != null) { break; } } if (refuelableComp != null) { // Check if there is already enough fuel: // (because Fuel is a float, we check the current fuel + .99, so it // only refuels when Fuel drops at least one full unit below taret level) if (refuelableComp.Fuel + 0.9999f >= refuelableComp.TargetFuelLevel) { return; // fully fueled } foreach (IntVec3 cell in GenAdj.CellsAdjacent8Way(this)) { List <Thing> l = Map.thingGrid.ThingsListAt(cell); for (int i = l.Count - 1; i >= 0; i--) // count down because items may be destroyed { Thing item = l[i]; // Without this check, if there is something that is fueled by // minified Power Conduits (weird, but ...possible?), then // our FuelingMachine will happily rip conduits out of the // ground to fuel it. I'm okay with this behavior. // Feature. Not a bug. // But if it ever causes a problem, uncomment this check: // if (item.def.category != ThingCategory.Item) continue; if (refuelableComp.Props.fuelFilter.Allows(item)) { // round down to not waste fuel: int num = Mathf.Min(item.stackCount, Mathf.FloorToInt(refuelableComp.TargetFuelLevel - refuelableComp.Fuel)); if (num > 0) { refuelableComp.Refuel(num); item.SplitOff(num).Destroy(); } else // It's not quite 1 below TargetFuelLevel // but we KNOW we are at least .9999f below TargetFuelLevel (see test above) // So we call it close enough to 1: { refuelableComp.Refuel(1); item.SplitOff(1).Destroy(); } // check fuel as float (as above) if (refuelableComp.Fuel + 0.9999f >= refuelableComp.TargetFuelLevel) { return; // fully fueled } } } } } } }
// ================================== /// <summary> /// /// </summary> public override void Tick() { if (!instantiated) { //foreach (Thing thing in GetContainer()) //{ // thing.holder.owner = this; //} currentDriverSpeed = VehicleSpeed; instantiated = true; } base.Tick(); #region Headlights #if Headlights { if (Find.GlowGrid.GameGlowAt(Position - Rotation.FacingCell - Rotation.FacingCell) < 0.4f) { // TODO Add headlights to xml & move the flooder initialization to mountableComp if (mountableComp.Driver != null && !compVehicles.AnimalsCanDrive() && flooder == null) { flooder = new HeadLights(Position, Rotation, this); CustomGlowFloodManager.RegisterFlooder(flooder); CustomGlowFloodManager.RefreshGlowFlooders(); } if (mountableComp.Driver == null && flooder != null) { flooder.Clear(); CustomGlowFloodManager.DeRegisterGlower(flooder); CustomGlowFloodManager.RefreshGlowFlooders(); flooder = null; } // TODO optimized performance, lights only at night and when driver is mounted => light switch gizmo? if (flooder != null) { flooder.Position = Position + Rotation.FacingCell + Rotation.FacingCell; flooder.Orientation = Rotation; flooder.Clear(); flooder.CalculateGlowFlood(); } } if (mountableComp.Driver == null && flooder != null || flooder != null) { CustomGlowFloodManager.DeRegisterGlower(flooder); CustomGlowFloodManager.RefreshGlowFlooders(); flooder = null; } } #endif #endregion if (mountableComp.IsMounted) { if (refuelableComp != null) { if (mountableComp.Driver.Faction != Faction.OfPlayer) { if (!fueledByAI) { if (refuelableComp.FuelPercent < 0.550000011920929) { refuelableComp.Refuel( ThingMaker.MakeThing(refuelableComp.Props.fuelFilter.AllowedThingDefs.FirstOrDefault())); } else { fueledByAI = true; } } } } if (mountableComp.Driver.pather.Moving) // || mountableComp.Driver.drafter.pawn.pather.Moving) { if (!mountableComp.Driver.stances.FullBodyBusy && axlesComp.HasAxles()) { wheelRotation += currentDriverSpeed / 3f; tick_time += 0.01f * currentDriverSpeed / 5f; } if (mountableComp.Driver.Position.AdjacentTo8WayOrInside(mountableComp.Driver.pather.Destination.Cell) && axlesComp.HasAxles()) { // Make the breaks sound once and throw some dust if Driver comes to his destination if (!soundPlayed) { SoundDef.Named("VehicleATV_Ambience_Break").PlayOneShot(mountableComp.Driver.Position); MoteMaker.ThrowDustPuff(DrawPos, 0.8f); soundPlayed = true; } } else { soundPlayed = false; } // TODO move all variables like smoke amount and break sound to xml etc. if (Find.TerrainGrid.TerrainAt(DrawPos.ToIntVec3()).takeFootprints || Find.SnowGrid.GetDepth(DrawPos.ToIntVec3()) > 0.2f) { if (vehicleComp.LeaveTrail()) { Vector3 normalized = (DrawPos - _lastFootprintPlacePos).normalized; float rot = normalized.AngleFlat(); Vector3 loc = DrawPos + TrailOffset; if ((loc - _lastFootprintPlacePos).MagnitudeHorizontalSquared() > FootprintIntervalDist) { if (loc.ShouldSpawnMotesAt() && !MoteCounter.SaturatedLowPriority) { MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDef.Named("Mote_Trail_ATV")); moteThrown.exactRotation = rot; moteThrown.exactPosition = loc; GenSpawn.Spawn(moteThrown, loc.ToIntVec3()); _lastFootprintPlacePos = DrawPos; } } } if (axlesComp.HasAxles()) { MoteMaker.ThrowDustPuff(DrawPos + DustOffset, 0.15f + Mathf.InverseLerp(0, 50, currentDriverSpeed) * 0.6f); } else { MoteMaker.ThrowDustPuff(DrawPos + DustOffset, 0.15f + Mathf.InverseLerp(0, 50, VehicleSpeed) * 0.6f); } } } //Exhaustion fumes - basic // only fumes on vehicles with combustion and no animals driving if (!vehicleComp.MotorizedWithoutFuel() && !vehicleComp.AnimalsCanDrive()) { MoteMaker.ThrowSmoke(DrawPos + FumesOffset, 0.05f + currentDriverSpeed * 0.01f); } if (Find.TickManager.TicksGame - tickCheck >= tickCooldown) { if (mountableComp.Driver.pather.Moving) { if (!mountableComp.Driver.stances.FullBodyBusy) { if (refuelableComp != null) { refuelableComp.Notify_UsedThisTick(); } damagetick -= 1; if (axlesComp.HasAxles()) { currentDriverSpeed = ToolsForHaulUtility.GetMoveSpeed(mountableComp.Driver); } } if (breakdownableComp != null && breakdownableComp.BrokenDown || refuelableComp != null && !refuelableComp.HasFuel) { VehicleSpeed = 0.75f; } else { VehicleSpeed = DesiredSpeed; } tickCheck = Find.TickManager.TicksGame; } if (Position.InNoBuildEdgeArea() && despawnAtEdge && Spawned && (mountableComp.Driver.Faction != Faction.OfPlayer || mountableComp.Driver.MentalState.def == MentalStateDefOf.PanicFlee)) { DeSpawn(); } } } //if (Find.TickManager.TicksGame >= damagetick) //{ // TakeDamage(new DamageInfo(DamageDefOf.Deterioration, 1, null, null, null)); // damagetick = Find.TickManager.TicksGame + 3600; //} if (vehicleComp.tankLeaking) { if (Find.TickManager.TicksGame > _tankSpillTick) { if (refuelableComp.FuelPercent > _tankHitPos) { refuelableComp.ConsumeFuel(0.15f); FilthMaker.MakeFilth(Position, fuelDefName, LabelCap); _tankSpillTick = Find.TickManager.TicksGame + 15; } } } }
public static void GenerateRoomFromLayout(List <string> layoutList, CellRect roomRect, Map map, StructureLayoutDef rld, bool generateConduit = true) { bool parentFaction = map.ParentFaction != null; if (rld.roofGrid != null) { GenerateRoofGrid(rld.roofGrid, roomRect, map); } List <string> allSymbList = new List <string>(); foreach (string str in layoutList) { allSymbList.AddRange(str.Split(',')); } int l = 0; foreach (IntVec3 cell in roomRect) { if (l < allSymbList.Count && allSymbList[l] != ".") { SymbolDef temp = DefDatabase <SymbolDef> .GetNamedSilentFail(allSymbList[l]); Thing thing; if (temp != null) { if (temp.isTerrain && temp.terrainDef != null) { GenerateTerrainAt(map, cell, temp.terrainDef); } else if (temp.pawnKindDefNS != null && CGO.factionSettlement?.shouldRuin == false) { if (temp.lordJob != null) { Lord lord = CreateNewLord(temp.lordJob, map, cell); for (int i = 0; i < temp.numberToSpawn; i++) { Pawn pawn = temp.spawnPartOfFaction ? PawnGenerator.GeneratePawn(temp.pawnKindDefNS, map.ParentFaction) : PawnGenerator.GeneratePawn(temp.pawnKindDefNS); if (pawn != null) { if (temp.isSlave && parentFaction) { pawn.guest.SetGuestStatus(map.ParentFaction, GuestStatus.Prisoner); } GenSpawn.Spawn(pawn, cell, map, WipeMode.FullRefund); lord.AddPawn(pawn); } } } else { for (int i = 0; i < temp.numberToSpawn; i++) { Pawn pawn = temp.spawnPartOfFaction ? PawnGenerator.GeneratePawn(temp.pawnKindDefNS, map.ParentFaction) : PawnGenerator.GeneratePawn(temp.pawnKindDefNS); if (pawn != null) { if (temp.isSlave && parentFaction) { pawn.guest.SetGuestStatus(map.ParentFaction, GuestStatus.Prisoner); } GenSpawn.Spawn(pawn, cell, map, WipeMode.FullRefund); } } } } else if (temp.thingDef?.category == ThingCategory.Item && cell.Walkable(map)) { thing = ThingMaker.MakeThing(temp.thingDef, temp.stuffDef ?? (temp.thingDef.stuffCategories?.Count > 0 ? GenStuff.RandomStuffFor(temp.thingDef) : null)); thing.stackCount = Mathf.Clamp(Rand.RangeInclusive(1, temp.thingDef.stackLimit), 1, 75); CompQuality quality = thing.TryGetComp <CompQuality>(); quality?.SetQuality(QualityUtility.GenerateQualityBaseGen(), ArtGenerationContext.Outsider); GenSpawn.Spawn(thing, cell, map, WipeMode.FullRefund); thing.SetForbidden(true, false); } else if (temp.thingDef != null) { thing = ThingMaker.MakeThing(temp.thingDef, temp.thingDef.CostStuffCount > 0 ? (temp.stuffDef ?? temp.thingDef.defaultStuff ?? ThingDefOf.WoodLog) : null); CompRefuelable refuelable = thing.TryGetComp <CompRefuelable>(); refuelable?.Refuel(refuelable.Props.fuelCapacity); CompPowerBattery battery = thing.TryGetComp <CompPowerBattery>(); battery?.AddEnergy(battery.Props.storedEnergyMax); if (thing is Building_CryptosleepCasket cryptosleepCasket && Rand.Value < temp.chanceToContainPawn) { Pawn pawn = GeneratePawnForContainer(temp, map); if (!cryptosleepCasket.TryAcceptThing(pawn)) { pawn.Destroy(); } } else if (thing is Building_CorpseCasket corpseCasket && Rand.Value < temp.chanceToContainPawn) { Pawn pawn = GeneratePawnForContainer(temp, map); if (!corpseCasket.TryAcceptThing(pawn)) { pawn.Destroy(); } } else if (thing is Building_Crate crate) { List <Thing> thingList = new List <Thing>(); if (map.ParentFaction == Faction.OfPlayer && temp.thingSetMakerDefForPlayer != null) { thingList = temp.thingSetMakerDefForPlayer.root.Generate(new ThingSetMakerParams()); } else if (temp.thingSetMakerDef != null) { thingList = temp.thingSetMakerDef.root.Generate(new ThingSetMakerParams()); } foreach (Thing t in thingList) { t.stackCount = Math.Min((int)(t.stackCount * temp.crateStackMultiplier), t.def.stackLimit); } thingList.ForEach(t => { if (!crate.TryAcceptThing(t, false)) { t.Destroy(); } }); } if (thing.def.category == ThingCategory.Pawn && CGO.factionSettlement?.shouldRuin == true) { l++; continue; } else if (cell.GetFirstMineable(map) is Mineable m && thing.def.designationCategory == DesignationCategoryDefOf.Security) { l++; continue; } else if (thing.def.category == ThingCategory.Plant && cell.GetTerrain(map).fertility > 0.5 && cell.Walkable(map)) // If it's a plant { Plant plant = thing as Plant; plant.Growth = temp.plantGrowth; // apply the growth GenSpawn.Spawn(plant, cell, map, WipeMode.VanishOrMoveAside); } else if (thing.def.category == ThingCategory.Building) { if (!cell.GetTerrain(map).affordances.Contains(TerrainAffordanceDefOf.Heavy)) { if (thing.def.building.isNaturalRock) { TerrainDef t = DefDatabase <TerrainDef> .GetNamedSilentFail($"{thing.def.defName}_Rough"); map.terrainGrid.SetTerrain(cell, t ?? TerrainDefOf.Soil); foreach (IntVec3 intVec3 in CellRect.CenteredOn(cell, 1)) { if (!intVec3.GetTerrain(map).BuildableByPlayer) { map.terrainGrid.SetTerrain(intVec3, t ?? TerrainDefOf.Soil); } } } else { map.terrainGrid.SetTerrain(cell, TerrainDefOf.Bridge); } } if (thing.def.rotatable) { GenSpawn.Spawn(thing, cell, map, new Rot4(temp.rotation.AsInt), WipeMode.VanishOrMoveAside); } else { GenSpawn.Spawn(thing, cell, map, WipeMode.VanishOrMoveAside); } if (parentFaction) { thing.SetFactionDirect(map.ParentFaction); } } if (generateConduit && rld.spawnConduits && !thing.def.mineable && (thing.def.passability == Traversability.Impassable || thing.def.IsDoor) && map.ParentFaction?.def.techLevel >= TechLevel.Industrial) // Add power cable under all impassable { Thing c = ThingMaker.MakeThing(ThingDefOf.PowerConduit); if (parentFaction) { c.SetFactionDirect(map.ParentFaction); } GenSpawn.Spawn(c, cell, map, WipeMode.FullRefund); } // Handle mortar and mortar pawns if (thing?.def?.building?.buildingTags?.Count > 0) { if (thing.def.building.IsMortar && thing.def.category == ThingCategory.Building && thing.def.building.buildingTags.Contains("Artillery_MannedMortar") && thing.def.HasComp(typeof(CompMannable)) && parentFaction) { // Spawn pawn Lord singlePawnLord = LordMaker.MakeNewLord(map.ParentFaction, new LordJob_ManTurrets(), map, null); PawnGenerationRequest value = new PawnGenerationRequest(map.ParentFaction.RandomPawnKind(), map.ParentFaction, PawnGenerationContext.NonPlayer, map.Tile, mustBeCapableOfViolence: true, inhabitant: true); ResolveParams rpPawn = new ResolveParams { faction = map.ParentFaction, singlePawnGenerationRequest = new PawnGenerationRequest?(value), rect = CellRect.SingleCell(thing.InteractionCell), singlePawnLord = singlePawnLord }; BaseGen.symbolStack.Push("pawn", rpPawn); // Spawn shells ThingDef shellDef = TurretGunUtility.TryFindRandomShellDef(thing.def, false, true, map.ParentFaction.def.techLevel, false, 250f); if (shellDef != null) { ResolveParams rpShell = new ResolveParams { faction = map.ParentFaction, singleThingDef = shellDef, singleThingStackCount = Rand.RangeInclusive(8, Math.Min(12, shellDef.stackLimit)) }; BaseGen.symbolStack.Push("thing", rpShell); } } } }