protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; Building_AquacultureBasin aquacultureBasin = null; foreach (Building building in map.listerBuildings.AllBuildingsColonistOfDef(Util_FishIndustry.AquacultureBasinDef)) { aquacultureBasin = building as Building_AquacultureBasin; int infestationDuration = (int)(GenDate.TicksPerDay * this.def.durationDays.min * Rand.Range(0.8f, 1.2f)); Room room = aquacultureBasin.InteractionCell.GetRoom(map); if ((room == null) || room.PsychologicallyOutdoors) { // Maximum infestation duration. infestationDuration = (int)(GenDate.TicksPerDay * this.def.durationDays.max * Rand.Range(0.8f, 1.2f)); } else { // Adjust infestation duration according to cleanliness. float dirtyness = -room.GetStat(RoomStatDefOf.Cleanliness); if (dirtyness > 0) { infestationDuration += (int)(GenDate.TicksPerDay * this.def.durationDays.min * dirtyness); } } aquacultureBasin.StartMicroFungusInfestation(infestationDuration); } if (aquacultureBasin != null) { Find.LetterStack.ReceiveLetter("FishIndustry.LetterLabelMicroFungus".Translate(), "FishIndustry.MicroFungus".Translate(), LetterDefOf.NegativeEvent, aquacultureBasin); } return(true); }
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { if ((t is Building_AquacultureBasin) == false) { return(false); } Building_AquacultureBasin aquacultureBasin = t as Building_AquacultureBasin; if (pawn.Dead || pawn.Downed || pawn.IsBurning()) { return(false); } if (pawn.CanReserveAndReach(aquacultureBasin, this.PathEndMode, Danger.Some) == false) { return(false); } if (aquacultureBasin.fishIsHarvestable || aquacultureBasin.speciesShouldBeChanged || aquacultureBasin.shouldBeMaintained) { return(true); } return(false); }
public override Job JobOnThing(Pawn pawn, Thing thing) { ISlotGroupParent slotGroupParent = thing as ISlotGroupParent; if (slotGroupParent == null) { return(null); } if (!pawn.CanReserve(thing.Position, 1)) { return(null); } int num = 0; List <Thing> list = pawn.MapHeld.thingGrid.ThingsListAt(thing.Position); for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (Building_AquacultureBasin.IsAcceptableFeedstock(thing2.def)) { num += thing2.stackCount; } } if (num > 25) { JobFailReason.Is("AlreadyFilledLower".Translate()); return(null); } return(WorkGiver_FillAquacultureHopper.HopperFillFoodJob(pawn, slotGroupParent)); }
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { if ((t is Building_AquacultureBasin) == false) { return(false); } Building_AquacultureBasin aquacultureBasin = t as Building_AquacultureBasin; if (pawn.Dead || pawn.Downed || pawn.IsBurning()) { return(false); } if (pawn.CanReserveAndReach(aquacultureBasin, this.PathEndMode, Danger.Some) == false) { return(false); } if (aquacultureBasin.breedingIsFinished) { return(true); } return(false); }
public override bool TryExecute(IncidentParms parms) { Map map = (Map)parms.target; Building_AquacultureBasin aquacultureBasin = null; foreach (Building building in map.listerBuildings.AllBuildingsColonistOfDef(Util_FishIndustry.AquacultureBasinDef)) { aquacultureBasin = building as Building_AquacultureBasin; int infestationDuration = (int)(GenDate.TicksPerDay * this.def.durationDays.min * Rand.Range(0.8f, 1.2f)); Room room = aquacultureBasin.InteractionCell.GetRoom(map); if ((room == null) || room.PsychologicallyOutdoors) { // Maximum infestation duration. infestationDuration = (int)(GenDate.TicksPerDay * this.def.durationDays.max * Rand.Range(0.8f, 1.2f)); } else { // Adjust infestation duration according to cleanliness. float dirtyness = -room.GetStat(RoomStatDefOf.Cleanliness); if (dirtyness > 0) { infestationDuration += (int)(GenDate.TicksPerDay * this.def.durationDays.min * dirtyness); } } aquacultureBasin.StartMicroFungusInfestation(infestationDuration); } if (aquacultureBasin != null) { Find.LetterStack.ReceiveLetter("Micro fungus", "Some of your aquaculture basins have been infected by a strange aquatic fungus.\nIt seems to consume all the water's oxygen.\nLet's hope the fishes will survive this deprivation.", LetterType.BadNonUrgent, aquacultureBasin); } return(true); }
protected override IEnumerable <Toil> MakeNewToils() { Building_AquacultureBasin aquacultureBasin = this.TargetThingA as Building_AquacultureBasin; yield return(Toils_Goto.GotoThing(aquacultureBasinIndex, PathEndMode.InteractionCell)); yield return(Toils_General.Wait(120).WithProgressBarToilDelay(aquacultureBasinIndex)); Toil getAquacultureBasinProduction = new Toil() { initAction = () => { Job curJob = this.pawn.jobs.curJob; Thing product = aquacultureBasin.GetProduction(); if (product == null) { this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded); } else { while (product.stackCount > product.def.stackLimit) { Thing meatStack = ThingMaker.MakeThing(product.def); meatStack.stackCount = product.def.stackLimit; GenPlace.TryPlaceThing(meatStack, this.GetActor().Position, this.Map, ThingPlaceMode.Near); product.stackCount -= product.def.stackLimit; } GenSpawn.Spawn(product, aquacultureBasin.InteractionCell, this.Map); IntVec3 storageCell; if (StoreUtility.TryFindBestBetterStoreCellFor(product, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true)) { this.pawn.Reserve(product, this.job); this.pawn.Reserve(storageCell, this.job, 1); this.pawn.CurJob.SetTarget(TargetIndex.B, storageCell); this.pawn.CurJob.SetTarget(TargetIndex.A, product); this.pawn.CurJob.count = 99999; this.pawn.CurJob.haulMode = HaulMode.ToCellStorage; } else { this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded); } } } }; yield return(getAquacultureBasinProduction); yield return(Toils_Reserve.Release(aquacultureBasinIndex)); yield return(Toils_Haul.StartCarryThing(TargetIndex.A)); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true)); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { Job job = new Job(); Building_AquacultureBasin aquacultureBasin = t as Building_AquacultureBasin; job = new Job(Util_FishIndustry.HarvestAquacultureBasinProductionJobDef, aquacultureBasin); return(job); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { Job job = new Job(); Building_AquacultureBasin aquacultureBasin = t as Building_AquacultureBasin; job = new Job(DefDatabase <JobDef> .GetNamed(Util_FishIndustry.JobDefName_HarvestAquacultureBasinProduction), aquacultureBasin); return(job); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Reserve.Reserve(aquacultureBasinIndex)); Building_AquacultureBasin aquacultureBasin = this.TargetThingA as Building_AquacultureBasin; yield return(Toils_Goto.GotoThing(aquacultureBasinIndex, PathEndMode.InteractionCell)); yield return(Toils_General.Wait(120).WithProgressBarToilDelay(aquacultureBasinIndex)); Toil getAquacultureBasinProduction = new Toil() { initAction = () => { Job curJob = this.pawn.jobs.curJob; Thing product = aquacultureBasin.GetProduction(); if (product == null) { this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded); } else { GenSpawn.Spawn(product, aquacultureBasin.InteractionCell, this.Map); IntVec3 storageCell; if (StoreUtility.TryFindBestBetterStoreCellFor(product, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true)) { this.pawn.carryTracker.TryStartCarry(product); curJob.targetB = storageCell; curJob.targetC = product; curJob.count = 99999; } else { this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded); } } } }; yield return(getAquacultureBasinProduction); // Reserve the product and storage cell. yield return(Toils_Reserve.Reserve(TargetIndex.B)); yield return(Toils_Reserve.Reserve(TargetIndex.C)); yield return(Toils_Reserve.Release(aquacultureBasinIndex)); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true)); }
public override void Notify_IterationCompleted(Pawn billDoer, List <Thing> ingredients) { base.Notify_IterationCompleted(billDoer, ingredients); Building_AquacultureBasin aquacultureBasin = this.billStack.billGiver as Building_AquacultureBasin; if (aquacultureBasin != null) { // Get the supplied species def and start a new breed cycle in the aquaculture basin. ThingDef speciesSuppliedDef = this.recipe.products.First().thingDef; aquacultureBasin.StartNewBreedCycle(speciesSuppliedDef); } }
public override bool TryExecute(IncidentParms parms) { Building_AquacultureBasin aquacultureBasin = null; foreach (Building building in Find.ListerBuildings.AllBuildingsColonistOfDef(Util_FishIndustry.AquacultureBasinDef)) { aquacultureBasin = building as Building_AquacultureBasin; aquacultureBasin.StartMicroFungusInfestation((int)(60000f * Rand.Range(this.def.durationDays.min, this.def.durationDays.max))); } if (aquacultureBasin != null) { Find.LetterStack.ReceiveLetter("Micro fungus", "Some of your aquaculture basins have been infected by a strange aquatic fungus.\nIt seems to consume all the water's oxygen.\nLet's hope the fishes will survive this deprivation.", LetterType.BadNonUrgent, aquacultureBasin); } return(true); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { Job job = null; Building_AquacultureBasin aquacultureBasin = t as Building_AquacultureBasin; if (aquacultureBasin.fishIsHarvestable) { job = new Job(Util_FishIndustry.AquacultureBasinHarvestJobDef, aquacultureBasin); } else if (aquacultureBasin.speciesShouldBeChanged) { job = new Job(Util_FishIndustry.AquacultureBasinChangeSpeciesJobDef, aquacultureBasin); } else if (aquacultureBasin.shouldBeMaintained) { job = new Job(Util_FishIndustry.AquacultureBasinMaintainJobDef, aquacultureBasin); } return(job); }
protected override IEnumerable <Toil> MakeNewToils() { Building_AquacultureBasin aquacultureBasin = this.TargetThingA as Building_AquacultureBasin; yield return(Toils_Goto.GotoThing(aquacultureBasinIndex, PathEndMode.InteractionCell).FailOn(() => aquacultureBasin.powerComp.PowerOn == false)); yield return(Toils_General.Wait(600).WithProgressBarToilDelay(aquacultureBasinIndex).FailOn(() => aquacultureBasin.powerComp.PowerOn == false)); Toil maintainAquacultureBasin = new Toil() { initAction = () => { aquacultureBasin.Notify_MaintenanceDone(); }, defaultCompleteMode = ToilCompleteMode.Instant }; yield return(maintainAquacultureBasin); }
public override void Notify_IterationCompleted(Pawn billDoer, List <Thing> ingredients) { base.Notify_IterationCompleted(billDoer, ingredients); Building_AquacultureBasin aquacultureBasin = this.billStack.billGiver as Building_AquacultureBasin; if (aquacultureBasin != null) { if ((aquacultureBasin.BillStack.Count == 0) || (aquacultureBasin.BillStack.Bills.First().recipe != this.recipe)) { return; } // Get the supplied species def and start a new breed cycle in the aquaculture basin. Thing fishCorpse = ingredients.First(); if (fishCorpse != null) { PawnKindDef fishKind = null; string fishCorpseAsString = fishCorpse.ToString(); if (fishCorpseAsString.Contains("Mashgon")) { fishKind = Util_FishIndustry.MashgonPawnKindDef; } else if (fishCorpseAsString.Contains("Blueblade")) { fishKind = Util_FishIndustry.BluebladePawnKindDef; } else if (fishCorpseAsString.Contains("Tailteeth")) { fishKind = Util_FishIndustry.TailteethPawnKindDef; } if (fishKind != null) { aquacultureBasin.StartNewBreedingCycle(fishKind); } else { Log.Warning("FishIndustry: this fish is not handled for breeding (" + fishCorpseAsString + ")."); } } } }
protected override IEnumerable <Toil> MakeNewToils() { Building_AquacultureBasin aquacultureBasin = this.TargetThingA as Building_AquacultureBasin; yield return(Toils_Goto.GotoThing(aquacultureBasinIndex, PathEndMode.InteractionCell).FailOn(() => (aquacultureBasin.powerComp.PowerOn == false) || (aquacultureBasin.desiredSpeciesDef == null))); yield return(Toils_General.Wait(600).WithProgressBarToilDelay(aquacultureBasinIndex).FailOn(() => (aquacultureBasin.powerComp.PowerOn == false) || (aquacultureBasin.desiredSpeciesDef == null))); Toil changeAquacultureBasinBredSpecies = new Toil() { initAction = () => { aquacultureBasin.StartNewBreedingCycle(); }, defaultCompleteMode = ToilCompleteMode.Instant }; yield return(changeAquacultureBasinBredSpecies); }
public static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp) { Building building = hopperSgp as Building; if (!pawn.CanReserveAndReach(building.Position, PathEndMode.Touch, pawn.NormalMaxDanger(), 1)) { return(null); } ThingDef thingDef = null; Thing firstItem = building.Position.GetFirstItem(pawn.MapHeld); if (firstItem != null) { if (Building_AquacultureBasin.IsAcceptableFeedstock(firstItem.def)) { thingDef = firstItem.def; } else { if (firstItem.IsForbidden(pawn)) { return(null); } return(HaulAIUtility.HaulAsideJobFor(pawn, firstItem)); } } List <Thing> list; if (thingDef == null) { list = pawn.MapHeld.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree); } else { list = pawn.MapHeld.listerThings.ThingsOfDef(thingDef); } for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing.def.IsNutritionGivingIngestible) { if (thing.def.ingestible.preferability == FoodPreferability.RawBad || thing.def.ingestible.preferability == FoodPreferability.RawTasty) { if (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, thing)) { if (pawn.MapHeld.slotGroupManager.SlotGroupAt(building.Position).Settings.AllowedToAccept(thing)) { StoragePriority storagePriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing); if (storagePriority < hopperSgp.GetSlotGroup().Settings.Priority) { Job job = HaulAIUtility.HaulMaxNumToCellJob(pawn, thing, building.Position, true); if (job != null) { return(job); } } } } } } } return(null); }