public CannonUpgrade(CannonUpgrade reference, VehiclePawn parent) : base(reference, parent) { cannonUpgrades = reference.cannonUpgrades; foreach (KeyValuePair <VehicleTurret, VehicleRole> cu in cannonUpgrades) { VehicleTurret newTurret = CompCannons.CreateTurret(parent, cu.Key); VehicleHandler handler = new VehicleHandler(parent, cu.Value); cannonsUnlocked.Add(newTurret, handler); } }
public static Toil PutPawnOnShip(Pawn pawnToBoard, VehiclePawn vehicle) { Toil toil = new Toil(); toil.initAction = delegate() { VehicleHandler handler = vehicle.handlers.Find(x => x.role.handlingTypes.NullOrEmpty()); vehicle.GiveLoadJob(pawnToBoard, handler); vehicle.Notify_Boarded(pawnToBoard); }; toil.defaultCompleteMode = ToilCompleteMode.Instant; return(toil); }
public VehicleRole(VehicleHandler group) { if (string.IsNullOrEmpty(group.role.key)) { Log.Error($"Missing Key on VehicleRole {group.role.label}"); } key = group.role.key; label = group.role.label; handlingTypes = new List <HandlingTypeFlags>(); if (group.role.handlingTypes != null) { handlingTypes.AddRange(group.role.handlingTypes); } slots = group.role.slots; slotsToOperate = group.role.slotsToOperate; cannonIds = new List <string>(); cannonIds.AddRange(group.role.cannonIds); }
protected override Job TryGiveJob(Pawn pawn) { if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { return(null); } Pawn pawn2 = FindPrisoner(pawn); if (pawn2 is null) { return(null); } VehiclePawn vehicle = FindShipToDeposit(pawn, pawn2); VehicleHandler handler = vehicle.handlers.Find(x => x.role.handlingTypes.NullOrEmpty()); return(new Job(JobDefOf.PrepareCaravan_GatherPawns, pawn2) { count = 1 }); }
public static Toil BoardVehicle(Pawn pawnBoarding) { Toil toil = new Toil(); toil.initAction = delegate() { VehiclePawn vehicle = toil.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing as VehiclePawn; Pair <VehiclePawn, VehicleHandler> assignedSeat; if (pawnBoarding.GetLord()?.LordJob is LordJob_FormAndSendVehicles lordJob) { assignedSeat = lordJob.GetVehicleAssigned(pawnBoarding); } else { VehicleHandler handler = vehicle.bills.FirstOrDefault(b => b.pawnToBoard == pawnBoarding)?.handler; if (handler is null) { handler = vehicle.Map.GetCachedMapComponent <VehicleReservationManager>().GetReservation <VehicleHandlerReservation>(vehicle)?.ReservedHandler(pawnBoarding); if (handler is null) { Log.Error("Could not find assigned spot for " + pawnBoarding.LabelShort + " to board."); return; } } assignedSeat = new Pair <VehiclePawn, VehicleHandler>(vehicle, handler); } //REDO - place nonhumanlike in cargo area if (assignedSeat.Second is null) { Log.Error($"{VehicleHarmony.LogLabel} VehicleHandler is null. This should never happen as assigned seating either handles arrangements or instructs pawns to follow rather than board."); } assignedSeat.First.GiveLoadJob(pawnBoarding, assignedSeat.Second); assignedSeat.First.Notify_Boarded(pawnBoarding); }; toil.defaultCompleteMode = ToilCompleteMode.Instant; return(toil); }
protected override Job TryGiveJob(Pawn pawn) { if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { return(null); } if (!(pawn.GetLord().LordJob is LordJob_FormAndSendVehicles)) { return(null); } Pawn pawn2 = FindDownedPawn(pawn); if (pawn2 is null) { return(null); } VehiclePawn vehicle = FindShipToDeposit(pawn, pawn2); VehicleHandler handler = vehicle.handlers.Find(x => x.role.handlingTypes.NullOrEmpty()); return(new Job(JobDefOf_Vehicles.CarryPawnToVehicle, pawn2, vehicle) { count = 1 }); }
public bool Equals(VehicleHandler obj2) { return(obj2?.role.key == role.key); }
private void DrawVehicleMenu(Rect rect) { Rect assignedRect = new Rect(rect.width * .6666f, 10f, rect.width / 3, rect.height - ButtonHeight * 3); Rect pawnsRect = new Rect(rect.width * .3333f, 10f, rect.width / 3, rect.height - ButtonHeight * 3); Rect assignedMenu = new Rect(assignedRect.x - 1, assignedRect.y + 25f, assignedRect.width, assignedRect.height); Rect pawnsMenu = new Rect(pawnsRect.x - 1, pawnsRect.y + 25f, pawnsRect.width, pawnsRect.height); Widgets.DrawMenuSection(assignedMenu); Widgets.DrawMenuSection(pawnsMenu); assignedRect.x += 1; pawnsRect.x += 1; Widgets.Label(assignedRect, "Assigned".Translate()); foreach (VehicleHandler handler in vehicle.handlers) { assignedRect.y += 30f; //TODO - Color for required seats int seatsOccupied = assignedSeats.Where(r => r.Value.Second.role == handler.role).Select(p => p.Key).Count(); Color countColor = handler.role.RequiredForCaravan ? seatsOccupied < handler.role.slotsToOperate ? Color.red : seatsOccupied == handler.role.slots ? Color.grey : Color.white : seatsOccupied == handler.role.slots ? Color.grey : Color.white; UIElements.LabelUnderlined(assignedRect, handler.role.label, $"({handler.role.slots - assignedSeats.Where(r => r.Value.Second.role == handler.role).Select(p => p.Key).Count()})", Color.white, countColor, Color.white); Rect assignedPawnIconRect = new Rect(assignedRect.x, assignedRect.y, 30f, 30f); Rect assignedPawnRect = new Rect(assignedPawnIconRect.x + 30f, assignedRect.y, pawnsRect.width, 30f); assignedRect.y += 30f; assignedPawnRect.y += 30f; assignedPawnIconRect.y += 35f; Rect roleRect = new Rect(assignedRect.x, assignedRect.y, assignedRect.width, 30f + 30f * assignedSeats.Where(r => r.Value.Second.role == handler.role).Select(p => p.Key).Count()); //Widgets.DrawBoxSolid(roleRect, Color.red); //Draw drop area bool slotsAvailable = assignedSeats.Where(r => r.Value.Second.role == handler.role).Select(p => p.Key).Count() < handler.role.slots; if (slotsAvailable && Mouse.IsOver(roleRect) && draggedPawn != null) { if (Event.current.type == EventType.MouseUp && Event.current.button == 0) { if (!handler.role.handlingTypes.NullOrEmpty() && (!draggedPawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || draggedPawn.Downed || draggedPawn.Dead)) { Messages.Message("IncapableStatusForRole".Translate(draggedPawn.LabelShortCap), MessageTypeDefOf.RejectInput); } else { assignedSeats.Add(draggedPawn, new Pair <VehiclePawn, VehicleHandler>(vehicle, handler)); } } } var removalList = new List <Pawn>(); foreach (KeyValuePair <Pawn, Pair <VehiclePawn, VehicleHandler> > assignedKVP in assignedSeats.Where(r => r.Value.Second.role == handler.role)) { Widgets.Label(assignedPawnRect, assignedKVP.Key.LabelCap); Widgets.ThingIcon(assignedPawnIconRect, assignedKVP.Key); Rect removalButtonRect = new Rect(roleRect.x + roleRect.width - 100f, assignedPawnRect.y, 90f, 20f); if (!assignedKVP.Value.First.AllPawnsAboard.Contains(assignedKVP.Key) && Widgets.ButtonText(removalButtonRect, "RemoveFromRole".Translate())) { removalList.Add(assignedKVP.Key); } assignedRect.y += 30f; assignedPawnRect.y += 30f; assignedPawnIconRect.y += 30f; } foreach (Pawn p in removalList) { assignedSeats.Remove(p); } if (!slotsAvailable) { assignedRect.y -= 15f; } } if (Event.current.type == EventType.MouseUp && Event.current.button == 0) { draggedPawn = null; } Widgets.Label(pawnsRect, "Colonists".Translate()); Rect colonistIconRect = new Rect(pawnsRect.x, pawnsRect.y + 30f, 30f, 30f); Rect colonistRect = new Rect(colonistIconRect.x + 30f, pawnsRect.y + 35f, pawnsRect.width, 30f); foreach (Pawn pawn in pawns.Select(p => p.AnyThing as Pawn).Where(a => !assignedSeats.ContainsKey(a))) { Rect entryButtonRect = new Rect(colonistIconRect.x + colonistRect.width - 100f, colonistRect.y, 90f, 20f); if (Mouse.IsOver(colonistRect) && !Mouse.IsOver(entryButtonRect)) { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { draggedPawn = pawn; draggedItemPosOffset = Event.current.mousePosition - colonistRect.position; draggedIconPosOffset = Event.current.mousePosition - colonistIconRect.position; Event.current.Use(); SoundDefOf.Click.PlayOneShotOnCamera(null); } } if (draggedPawn == pawn) { Rect draggedRect = new Rect(Event.current.mousePosition.x - draggedItemPosOffset.x, Event.current.mousePosition.y - draggedItemPosOffset.y, colonistRect.width, colonistRect.height); Rect draggedIconRect = new Rect(Event.current.mousePosition.x - draggedIconPosOffset.x, Event.current.mousePosition.y - draggedIconPosOffset.y, colonistIconRect.width, colonistIconRect.height); Widgets.Label(draggedRect, pawn.LabelCap); Widgets.ThingIcon(draggedIconRect, pawn); } else { if (Widgets.ButtonText(entryButtonRect, "AddToRole".Translate())) { VehicleHandler firstHandler = vehicle.handlers.FirstOrDefault(x => assignedSeats.Where(r => r.Value.Second.role == x.role).Select(p => p.Key).Count() < x.role.slots); if (!(firstHandler is null)) { assignedSeats.Add(pawn, new Pair <VehiclePawn, VehicleHandler>(vehicle, firstHandler)); } } Widgets.Label(colonistRect, pawn.LabelCap); Widgets.ThingIcon(colonistIconRect, pawn); } colonistIconRect.y += 35f; colonistRect.y += 35f; } }
public Bill_BoardShip(Pawn newBoard, VehicleHandler newHandler) { pawnToBoard = newBoard; handler = newHandler; }