Skip to content

Commit

Permalink
Caravan Enter Fixes
Browse files Browse the repository at this point in the history
Fixed issues with entering somewhere with a caravan.
  • Loading branch information
jecrell committed Jul 23, 2017
1 parent 6cf3f75 commit 0192a74
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 83 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<url></url>
<targetVersion>0.17.0</targetVersion>
<description>
[1.0.4.15] Adds modding components to RimWorld: vehicles, spell casting, weapon slots, oversized weapons, and more!
[1.0.4.16] Adds modding components to RimWorld: vehicles, spell casting, weapon slots, oversized weapons, and more!

Note to players: This mod will not change your game, but rather it lets modders do more, so you can have an even more amazing RimWorld experience.

Expand Down
Binary file modified Assemblies/AbilityUser.dll
Binary file not shown.
Binary file modified Assemblies/CompVehicle.dll
Binary file not shown.
Binary file modified Source/.vs/JecsTools/v15/.suo
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ public Toil GotoCastPosition(TargetIndex targetInd, bool closeIfDowned = false)
}




protected override IEnumerable<Toil> MakeNewToils()
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public enum HandlingType : int

public class CompProperties_Vehicle : CompProperties
{
//Added 7/23/17
public float cargoCapacity = 385.554f; // Cargo capacity for your vehicle in kilograms.

public VehicleType vehicleType = VehicleType.LandWheeled; // Defaults to wheeled land vehicles.
public HandlingType movementHandling = HandlingType.HandlerRequired; // Is the movement automatic?
public HandlingType weaponHandling = HandlingType.HandlerRequired; // Are the weapons automatic?
Expand Down
128 changes: 61 additions & 67 deletions Source/AllModdingComponents/CompVehicle/CompVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class CompVehicle : ThingComp
public List<ThingCountClass> repairCostList = new List<ThingCountClass>();
private Sustainer movingSustainer;

#region SwenzisCode
//------ Additions By Swenzi -------
//Purpose: Control the boolean warnedOnNoFuel
//Logic: Needed to prevent spamming of the warning message
Expand All @@ -67,6 +68,7 @@ public List<VehicleHandlerGroup> PawnsInVehicle
set => this.vehicleContents = value;
}
//------ Additions By Swenzi -------
#endregion SwenzisCode

public bool CanManipulate => this.Props.manipulationHandling > HandlingType.HandlerRequired || ManipulationHandlerAvailable;
public bool ManipulationHandlerAvailable
Expand Down Expand Up @@ -265,93 +267,85 @@ public void ResolveFactionPilots()
}
public void ResolveEjection()
{
//----Additions Made By Swenzi-----
//----Additions Made By Swenzi-----
//Purpose: Ejects pawns if the need of that pawn is below the threshold set by ejectIfBelowNeedPercent
//Logic: Prevents pawns from starving to death or other need related issues i.e. moral from poor management of pawns in vehicles
//Improvements: Have pawns remember the vehicle they left, so they return after needs are satisfied?

CompRefuelable refuelable = this.Pawn.GetComp<CompRefuelable>();
if (refuelable != null)
//CompRefuelable refuelable = this.Pawn.GetComp<CompRefuelable>();
//if (refuelable != null)
//{
if (this.parent is Pawn vehicle && vehicle.Spawned && this.handlers != null && this.handlers.Count > 0)
{
if (this.handlers != null && this.handlers.Count > 0)
//Find and remove all spawned characters from the vehicle list.
foreach (VehicleHandlerGroup group in this.handlers)
{
foreach (VehicleHandlerGroup group in this.handlers)
Pawn toRemove = group?.handlers?.InnerListForReading?.FirstOrDefault(x => x.Spawned);
if (toRemove != null)
{
if ((group?.handlers?.Count ?? 0) > 0)
{
for (int i = 0; i < group.handlers.Count; i++)
{
Pawn pawn = group.handlers[i];
List<Need> pawnNeeds = pawn.needs.AllNeeds;
for (int j = 0; j < pawnNeeds.Count; j++)
{
if (pawnNeeds[j].CurLevelPercentage < this.Props.ejectIfBelowNeedPercent)
{
//Prevents annoying issues where the pawn leaves the vehicle due to needs when forming a caravan
//since they can wait till world map, world needs are handled seperately by the game
if (!this.Pawn.IsCaravanMember() && !((this.Pawn.GetLord()?.LordJob?.ToString()) == "RimWorld.LordJob_FormAndSendCaravan"))
{
//Prevents annoying issues where the pawn leaves the vehicle despite the player wanting
//the pawn to enter the vehicle. I.e. Life and death situation? Ignore Needs. Live!!!!
if (!this.Pawn.IsFighting() && !pawn.IsFighting())
{
//Notify the player that "Johnny" has left the vehicle so the pawn can be punished as appropriate
Messages.Message("MessagePawnLeftVehicle".Translate(new object[] { pawn.Label, this.Pawn.Label, pawnNeeds[j].def.defName }), this.Pawn, MessageSound.SeriousAlert);
Eject(pawn, group.handlers);
group.handlers.Remove(pawn);
break;
}
}
}
}


}
}
//Log.Message("x");
group.handlers.InnerListForReading.Remove(toRemove);
//return;
}
}

//Find and eject all characters who need to have their needs met.
foreach (VehicleHandlerGroup group in this.handlers)
{
Pawn toEject = group?.handlers?.InnerListForReading?.FirstOrDefault(x => !x.Spawned && x?.needs?.AllNeeds?.FirstOrDefault(y => y.CurLevelPercentage < this.Props.ejectIfBelowNeedPercent) != null);
if (toEject != null)
{
Messages.Message("MessagePawnLeftVehicle".Translate(new object[] { toEject.Label, this.Pawn.Label, "low" }), this.Pawn, MessageSound.SeriousAlert);
//Eject(p, ref group.handlers);
Pawn b;
//Log.Message("1");
group.handlers.TryDrop(toEject, this.Pawn.PositionHeld, this.Pawn.MapHeld, ThingPlaceMode.Near, out b);
//Log.Message("2");
//return;
}
}
}
//}

//----Additions Made By Swenzi-----
//----Additions Made By Swenzi-----

//Every 250 ticks
if (this.Props.ejectIfBelowHealthPercent > 0.0f)
{
if (Find.TickManager.TicksGame % 250 == 0)
//Every 250 ticks
if (this.Props.ejectIfBelowHealthPercent > 0.0f)
{
if (this.Pawn.Dead || this.Pawn.Downed)
if (Find.TickManager.TicksGame % 250 == 0)
{
if (this.handlers != null && this.handlers.Count > 0)
if (this.Pawn.Dead || this.Pawn.Downed)
{
foreach (VehicleHandlerGroup group in this.handlers)
if (this.handlers != null && this.handlers.Count > 0)
{
EjectAll(group.handlers);
foreach (VehicleHandlerGroup group in this.handlers)
{
EjectAll(ref group.handlers);
}
this.weaponStatus = WeaponState.frozen;
this.movingStatus = MovingState.frozen;
if (this.Pawn.Downed && this.Pawn.Faction != Faction.OfPlayerSilentFail) this.Pawn.SetFaction(Faction.OfPlayerSilentFail);
return;
}
this.weaponStatus = WeaponState.frozen;
this.movingStatus = MovingState.frozen;
if (this.Pawn.Downed && this.Pawn.Faction != Faction.OfPlayerSilentFail) this.Pawn.SetFaction(Faction.OfPlayerSilentFail);
return;
}
}

if (this.Pawn.health != null)
{
if (this.Pawn.health.summaryHealth != null)
if (this.Pawn.health != null)
{
float currentHealthPercentage = this.Pawn.health.summaryHealth.SummaryHealthPercent;
if (currentHealthPercentage < this.Props.ejectIfBelowHealthPercent)
if (this.Pawn.health.summaryHealth != null)
{
if (this.handlers != null && this.handlers.Count > 0)
float currentHealthPercentage = this.Pawn.health.summaryHealth.SummaryHealthPercent;
if (currentHealthPercentage < this.Props.ejectIfBelowHealthPercent)
{
foreach (VehicleHandlerGroup group in this.handlers)
if (this.handlers != null && this.handlers.Count > 0)
{
EjectAll(group.handlers);
foreach (VehicleHandlerGroup group in this.handlers)
{
EjectAll(ref group.handlers);
}
this.weaponStatus = WeaponState.frozen;
this.movingStatus = MovingState.frozen;
if (this.Pawn.Downed) this.Pawn.SetFaction(Faction.OfPlayerSilentFail);
return;
}
this.weaponStatus = WeaponState.frozen;
this.movingStatus = MovingState.frozen;
if (this.Pawn.Downed) this.Pawn.SetFaction(Faction.OfPlayerSilentFail);
return;
}
}
}
Expand Down Expand Up @@ -497,22 +491,22 @@ public void ResolveNeeds(){
}
// ------ Additions made by Swenzi ------

public void Eject(Pawn pawn, ThingOwner<Pawn> list)
public void Eject(Pawn pawn, ref ThingOwner<Pawn> list)
{
if (!pawn.Spawned)
{
GenSpawn.Spawn(pawn, this.Pawn.PositionHeld.RandomAdjacentCell8Way(), this.Pawn.MapHeld);
}
list.Remove(pawn);
}
public void EjectAll(ThingOwner<Pawn> pawns)
public void EjectAll(ref ThingOwner<Pawn> pawns)
{
List<Pawn> pawnsToEject = new List<Pawn>(pawns);
if (pawnsToEject != null && pawnsToEject.Count > 0)
{
foreach (Pawn p in pawnsToEject)
{
Eject(p, pawns);
Eject(p, ref pawns);
}
}
}
Expand Down Expand Up @@ -614,7 +608,7 @@ public void GetVehicleButtonFloatMenu(VehicleHandlerGroup group, bool canLoad)
Func<Rect, bool> extraPartOnGUI = (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, handler);
list.Add(new FloatMenuOption(text, delegate
{
Eject(handler, group.handlers);
Eject(handler, ref group.handlers);
}, MenuOptionPriority.Default, null, null, 29f, extraPartOnGUI, null));
}
}
Expand Down
Loading

0 comments on commit 0192a74

Please sign in to comment.