Skip to content

Commit 8b36c8b

Browse files
authored
Replace job instantiation that does not use JobMaker (#338)
* Replace job instantiation that does not use JobMaker * Fix the missing return statement for the created job * Fixed an errror that occurred when attempting to set out on a caravan while out of fuel (#336) * Fixed an errror that occurred when attempting to set out on a caravan while out of fuel * Added draft check within LoadToilTick to LordToil_PrepareCaravan_LeaveWithVehicles
1 parent 40db5a2 commit 8b36c8b

12 files changed

Lines changed: 37 additions & 41 deletions

Source/Vehicles/AI/JobGivers/JobGiver_AwaitOrders.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ protected override Job TryGiveJob(Pawn pawn)
2424
{
2525
vehicle.vehiclePather.EngageBrakes();
2626
}
27-
Job job = new(JobDefOf_Vehicles.IdleVehicle, vehicle)
28-
{
29-
checkOverrideOnExpire = true,
30-
expiryInterval = overrideExpiryInterval > 0 ? overrideExpiryInterval : 180
31-
};
27+
28+
Job job = JobMaker.MakeJob(JobDefOf_Vehicles.IdleVehicle, vehicle);
29+
job.checkOverrideOnExpire = true;
30+
job.expiryInterval = overrideExpiryInterval > 0 ? overrideExpiryInterval : 180;
3231
return job;
3332
}
3433
}

Source/Vehicles/AI/JobGivers/JobGiver_BoardVehicle.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ protected override Job TryGiveJob(Pawn pawn)
2727
if (!JobDriver_FollowClose.FarEnoughAndPossibleToStartJob(pawn, assignedSeat.Vehicle,
2828
FollowRadius))
2929
return null;
30-
return new Job(JobDefOf.FollowClose, assignedSeat.Vehicle)
31-
{
32-
lord = pawn.GetLord(),
33-
expiryInterval = 140,
34-
checkOverrideOnExpire = true,
35-
followRadius = FollowRadius
36-
};
30+
Job job = JobMaker.MakeJob(JobDefOf.FollowClose, assignedSeat.Vehicle);
31+
job.lord = pawn.GetLord();
32+
job.expiryInterval = 140;
33+
job.checkOverrideOnExpire = true;
34+
job.followRadius = FollowRadius;
35+
return job;
3736
}
38-
return new Job(JobDefOf_Vehicles.Board, assignedSeat.Vehicle);
37+
return JobMaker.MakeJob(JobDefOf_Vehicles.Board, assignedSeat.Vehicle);
3938
}
4039
return null;
4140
}

Source/Vehicles/AI/JobGivers/JobGiver_GotoTravelDestinationVehicle.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ protected override Job TryGiveJob(Pawn pawn)
3838
{
3939
return null;
4040
}
41-
Job job = new(JobDefOf.Goto, cell)
42-
{
43-
locomotionUrgency = LocomotionUrgency.Jog,
44-
expiryInterval = jobMaxDuration
45-
};
41+
Job job = JobMaker.MakeJob(JobDefOf.Goto, cell);
42+
job.locomotionUrgency = LocomotionUrgency.Jog;
43+
job.expiryInterval = jobMaxDuration;
4644
if (vehicle.InhabitedCellsProjected(cell, Rot8.Invalid)
4745
.Any(projCell => pawn.Map.exitMapGrid.IsExitCell(projCell)))
4846
{

Source/Vehicles/AI/JobGivers/JobGiver_PrepareVehicleCaravan_GatheringItems.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ protected override Job TryGiveJob(Pawn pawn)
2222
if (thing is null)
2323
return null;
2424

25-
return new Job(JobDef, thing)
26-
{
27-
lord = lord
28-
};
29-
}
25+
Job job = JobMaker.MakeJob(JobDef, thing);
26+
job.lord = lord;
27+
return job;
28+
}
3029
}

Source/Vehicles/AI/JobGivers/JobGiver_SendSlavesToVehicle.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ protected override Job TryGiveJob(Pawn pawn)
1818
return null;
1919
VehiclePawn vehicle = FindShipToDeposit(pawn, pawn2);
2020
VehicleRoleHandler handler = vehicle.handlers.Find(x => x.role.HandlingTypes == HandlingType.None);
21-
return new Job(JobDefOf.PrepareCaravan_GatherDownedPawns, pawn2)
22-
{
23-
count = 1
24-
};
25-
}
21+
Job job = JobMaker.MakeJob(JobDefOf.PrepareCaravan_GatherDownedPawns, pawn2);
22+
job.count = 1;
23+
return job;
24+
}
2625

2726
private Pawn FindPrisoner(Pawn pawn)
2827
{

Source/Vehicles/AI/JobGivers/NPC/JobGiver_SabotageVehicle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override Job TryGiveJob(Pawn pawn)
4141
IntVec3 jobCell = vehicle.SurroundingCells.RandomOrFallback(cell =>
4242
resMgr.CanReserve<LocalTargetInfo, VehicleTargetReservation>(vehicle, pawn, cell),
4343
IntVec3.Invalid);
44-
return new Job(JobDefOf_Vehicles.SabotageVehicle, vehicle, jobCell);
44+
return JobMaker.MakeJob(JobDefOf_Vehicles.SabotageVehicle, vehicle, jobCell);
4545
}
4646
}
4747
}

Source/Vehicles/Components/Vehicles/FloatOptionProviders/FloatMenuOptionProvider_OrderVehicle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ internal static void PawnGotoAction(IntVec3 clickCell, VehiclePawn vehicle, IntV
119119

120120
if (!IsFeatureEnabled(PathFinderV2))
121121
{
122-
Job job = new(JobDefOf.Goto, gotoLoc);
122+
Job job = JobMaker.MakeJob(JobDefOf.Goto, gotoLoc);
123123
vehicle.jobs.TryTakeOrderedJob(job, JobTag.Misc);
124124
return;
125125
}

Source/Vehicles/Components/Vehicles/VehiclePathFollower.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,8 @@ public bool TryOrderMoveTo(in PathOrderData data)
413413
return true;
414414
}
415415

416-
Job job = new(JobDefOf.Goto, new LocalTargetInfo(data.destination))
417-
{
418-
exitMapOnArrival = data.exitMapOnArrival
419-
};
416+
Job job = JobMaker.MakeJob(JobDefOf.Goto, new LocalTargetInfo(data.destination));
417+
job.exitMapOnArrival = data.exitMapOnArrival;
420418
if (vehicle.jobs.TryTakeOrderedJob(job, JobTag.Misc))
421419
{
422420
endRot = data.endRotation;

Source/Vehicles/Components/Vehicles/VehiclePawn/VehiclePawn_Rendering.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ public void PromptToBoardVehicle(Pawn pawn, VehicleRoleHandler handler)
991991
return;
992992
}
993993

994-
Job job = new(JobDefOf_Vehicles.Board, this);
994+
Job job = JobMaker.MakeJob(JobDefOf_Vehicles.Board, this);
995995
GiveLoadJob(pawn, handler);
996996
pawn.jobs.TryTakeOrderedJob(job, JobTag.DraftedOrder);
997997
if (!pawn.Spawned)

Source/Vehicles/Comps/FueledTravel/CompFueledTravel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public override IEnumerable<FloatMenuOption> CompFloatMenuOptions(Pawn selPawn)
483483
yield return new FloatMenuOption("Refuel".Translate().ToString(),
484484
delegate
485485
{
486-
Job job = new(JobDefOf_Vehicles.RefuelVehicle, parent, ClosestFuelAvailable(selPawn));
486+
Job job = JobMaker.MakeJob(JobDefOf_Vehicles.RefuelVehicle, parent, ClosestFuelAvailable(selPawn));
487487
selPawn.jobs.TryTakeOrderedJob(job, JobTag.DraftedOrder);
488488
});
489489
}

0 commit comments

Comments
 (0)