public static Toil FindAdjacentEatSurface(TargetIndex eatSurfaceInd, TargetIndex foodInd) { Toil toil = new Toil(); toil.initAction = delegate() { Pawn actor = toil.actor; IntVec3 position = actor.Position; Map map = actor.Map; for (int i = 0; i < 4; i++) { Rot4 rot = new Rot4(i); IntVec3 intVec = position + rot.FacingCell; if (intVec.HasEatSurface(map)) { toil.actor.CurJob.SetTarget(eatSurfaceInd, intVec); toil.actor.jobs.curDriver.rotateToFace = eatSurfaceInd; Thing thing = toil.actor.CurJob.GetTarget(foodInd).Thing; if (thing.def.rotatable) { thing.Rotation = Rot4.FromIntVec3(intVec - toil.actor.Position); } break; } } }; toil.defaultCompleteMode = ToilCompleteMode.Instant; return(toil); }
public static Toil FindAdjacentEatSurface(TargetIndex eatSurfaceInd, TargetIndex foodInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; IntVec3 position = actor.Position; Map map = actor.Map; int num = 0; IntVec3 intVec; while (true) { if (num >= 4) { return; } intVec = position + new Rot4(num).FacingCell; if (intVec.HasEatSurface(map)) { break; } num++; } toil.actor.CurJob.SetTarget(eatSurfaceInd, intVec); toil.actor.jobs.curDriver.rotateToFace = eatSurfaceInd; Thing thing = toil.actor.CurJob.GetTarget(foodInd).Thing; if (thing.def.rotatable) { thing.Rotation = Rot4.FromIntVec3(intVec - toil.actor.Position); } }; toil.defaultCompleteMode = ToilCompleteMode.Instant; return(toil); }
public override void SpawnSetup(Map map) { base.SpawnSetup(map); var tiles = AdjacentConveyorTiles.ToArray(); // make adjacent nodes that point at nothing point at this foreach (var adjacent in tiles) { if (Map.thingGrid.ThingAt <Building_ConveyorBase>(adjacent.NextCell) == null) { adjacent.Rotation = Rot4.FromIntVec3(Position - adjacent.Position); } } // if this points at nothing, point at first thing that doesn't point at this var pointsAt = Map.thingGrid.ThingAt <Building_ConveyorBase>(NextCell); if (pointsAt == null || tiles.Contains(pointsAt)) { var next = tiles.FirstOrDefault(x => x.NextCell != Position); if (next != null) { Rotation = Rot4.FromIntVec3(next.Position - Position); } } }
public override void Print(SectionLayer layer, Thing thing) { base.Print(layer, thing); // Similar to Graphic_LinkedConveyor, we need to not print this // if it's underground (unless something is selected, etc etc) if (thing is Building_BeltSplitter splitter) { if (splitter.IsUnderground && !(layer is SectionLayer_UGConveyor)) { return; } // We want to draw the open door only if something is using the S // facing wall, so either an output link to the S or an incoming link: if ((splitter.OutputLinks.TryGetValue(Rot4.South, out var link) && link.Active) || splitter.IncomingLinks.Any(o => splitter.Position + Rot4.South.FacingCell == o.Position)) { // Draw open door var mat = splitterBuildingDoorOpen.Graphic.MatSingleFor(thing); Printer_Plane.PrintPlane(layer, thing.TrueCenter() + BuildingOffset, Vector2.one, mat); } else { // Draw closed door var mat = splitterBuildingDoorClosed.Graphic.MatSingleFor(thing); Printer_Plane.PrintPlane(layer, thing.TrueCenter() + BuildingOffset, Vector2.one, mat); } // Print the splitter version of the tiny yellow arrow showing input direction: // Note: these arrows texPaths should probably be exposed to XML via IHaveExtraGrahicData or something foreach (var i in splitter.IncomingLinks) { if (i.Position.IsNextTo(splitter.Position)) // otherwise need new logic // splitter.Position + offset = i.Position, so // offset = i.Position - splitter.Position { var r = Rot4.FromIntVec3(i.Position - splitter.Position); Printer_Plane.PrintPlane(layer, thing.TrueCenter() + ArrowOffset(r), this.drawSize, arrow00b, r.Opposite.AsAngle); } } // print tiny brown arrows pointing in output directions: // Note: the texPaths for these should probably be exposed to XML too. foreach (var d in splitter.ActiveOutputDirections) { Printer_Plane.PrintPlane(layer, thing.TrueCenter() + ArrowOffset(d), this.drawSize, arrow01, d.AsAngle); } }
public static Toil TurnToEatSurface(TargetIndex eatSurfaceInd, TargetIndex foodInd = TargetIndex.None) { var toil = new Toil(); toil.initAction = delegate { toil.actor.jobs.curDriver.rotateToFace = eatSurfaceInd; if (foodInd != TargetIndex.None) { var thing = toil.actor.CurJob.GetTarget(foodInd).Thing; if (thing?.def.rotatable == true) { thing.Rotation = Rot4.FromIntVec3(toil.actor.CurJob.GetTarget(eatSurfaceInd).Cell - toil.actor.Position); } } }; toil.defaultCompleteMode = ToilCompleteMode.Instant; return(toil); }
public Toil PlaceItemToRead(TargetIndex bookInd) { Toil placeItem = new Toil(); placeItem.initAction = delegate { Pawn actor = placeItem.actor; Thing carriedThing = actor.carrier.CarriedThing; ThingDef_Readables clutterThingDefs = (ThingDef_Readables)carriedThing.def; if (!clutterThingDefs.IsABook) { Log.Message(actor + " tried to place book for reading but was carrying " + actor.carrier.CarriedThing); actor.jobs.EndCurrentJob(JobCondition.Incompletable); } else { if (carriedThing.Destroyed) { actor.jobs.EndCurrentJob(JobCondition.Incompletable); } else { IntVec3 position; if (!TryFindAdjacentReadPlaceSpot(actor.Position, carriedThing.def, out position)) { Log.Error(string.Concat(new object[] { actor, " could not read: found no place spot near ", actor.Position, ". Correcting." })); position = actor.Position; } if (!position.InBounds()) { Log.Error(string.Concat(new object[] { actor, " tried to place book out of bounds at ", position, ". Correcting." })); position = actor.Position; } if (!actor.carrier.TryDropCarriedThing(position, ThingPlaceMode.Direct, out carriedThing)) { Log.Error(string.Concat(new object[] { actor, " could not read: book vanished when placed at ", position, "." })); actor.jobs.EndCurrentJob(JobCondition.Errored); } else { actor.jobs.curJob.SetTarget(bookInd, carriedThing); IntVec3 intVec = position - actor.Position; if (carriedThing.def.rotatable && intVec != IntVec3.Zero) { carriedThing.Rotation = Rot4.FromIntVec3(intVec); } } } } }; placeItem.defaultCompleteMode = ToilCompleteMode.Instant; return(placeItem); }