diff --git a/About/DiscordURL.txt b/About/DiscordURL.txt new file mode 100644 index 0000000..7e2a087 --- /dev/null +++ b/About/DiscordURL.txt @@ -0,0 +1 @@ +https://discord.gg/AaVFA7V diff --git a/About/LudeonURL.txt b/About/LudeonURL.txt new file mode 100644 index 0000000..0f104b0 --- /dev/null +++ b/About/LudeonURL.txt @@ -0,0 +1 @@ +https://ludeon.com/forums/index.php?topic=39264.0 diff --git a/About/PatreonURL.txt b/About/PatreonURL.txt new file mode 100644 index 0000000..5325a38 --- /dev/null +++ b/About/PatreonURL.txt @@ -0,0 +1 @@ +https://www.patreon.com/posts/doors-expanded-0-21060058 diff --git a/Assemblies/0Harmony.dll b/Assemblies/0Harmony.dll new file mode 100644 index 0000000..5078dad Binary files /dev/null and b/Assemblies/0Harmony.dll differ diff --git a/Assemblies/DoorsExpanded.dll b/Assemblies/DoorsExpanded.dll index 180833f..7eeeec9 100644 Binary files a/Assemblies/DoorsExpanded.dll and b/Assemblies/DoorsExpanded.dll differ diff --git a/Source/.idea/.idea.ProjectHeron/.idea/contentModel.xml b/Source/.idea/.idea.ProjectHeron/.idea/contentModel.xml index 91ce6f3..beaaa89 100644 --- a/Source/.idea/.idea.ProjectHeron/.idea/contentModel.xml +++ b/Source/.idea/.idea.ProjectHeron/.idea/contentModel.xml @@ -1,8 +1,8 @@ - - + + @@ -19,6 +19,7 @@ - + + \ No newline at end of file diff --git a/Source/.idea/.idea.ProjectHeron/.idea/indexLayout.xml b/Source/.idea/.idea.ProjectHeron/.idea/indexLayout.xml index f1feadf..27ba142 100644 --- a/Source/.idea/.idea.ProjectHeron/.idea/indexLayout.xml +++ b/Source/.idea/.idea.ProjectHeron/.idea/indexLayout.xml @@ -1,6 +1,7 @@ + diff --git a/Source/.idea/.idea.ProjectHeron/.idea/vcs.xml b/Source/.idea/.idea.ProjectHeron/.idea/vcs.xml index 21a4bc5..6c0b863 100644 --- a/Source/.idea/.idea.ProjectHeron/.idea/vcs.xml +++ b/Source/.idea/.idea.ProjectHeron/.idea/vcs.xml @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/Source/Building_DoorExpanded.cs b/Source/Building_DoorExpanded.cs index ffabe53..a966202 100644 --- a/Source/Building_DoorExpanded.cs +++ b/Source/Building_DoorExpanded.cs @@ -388,9 +388,11 @@ public bool SlowsPawns public virtual bool PawnCanOpen(Pawn p) { Lord lord = p.GetLord(); - return !forbiddenComp.Forbidden && Def.doorType == DoorType.FreePassage || (lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(p)) || + var result = !forbiddenComp.Forbidden || Def.doorType == DoorType.FreePassage || (lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(p)) || (p.IsWildMan() && !p.mindState.WildManEverReachedOutside) || base.Faction == null || (p.guest != null && p.guest.Released) || GenAI.MachinesLike(base.Faction, p); + if (!result && p.AnimalOrWildMan()) Console.WriteLine(p.def.ToString() + " cannot open " + this.def.ToString()); + return result; } diff --git a/Source/Building_DoorRegionHandler.cs b/Source/Building_DoorRegionHandler.cs index 57c59f1..cd69096 100644 --- a/Source/Building_DoorRegionHandler.cs +++ b/Source/Building_DoorRegionHandler.cs @@ -6,6 +6,7 @@ using RimWorld; using Verse; using Verse.AI; +using Verse.AI.Group; using Verse.Sound; namespace DoorsExpanded @@ -23,19 +24,12 @@ namespace DoorsExpanded /// public class Building_DoorRegionHandler : Building_Door { - - private Building_DoorExpanded parentDoor; + public Building_DoorExpanded ParentDoor { - get - { - return parentDoor; - } - set - { - parentDoor = value; - } + get { return parentDoor; } + set { parentDoor = value; } } public override string LabelMouseover => ""; @@ -53,7 +47,12 @@ public int TicksUntilClose public override bool PawnCanOpen(Pawn p) { - return base.PawnCanOpen(p) && ((p.Faction == this.Faction || !p.Faction.HostileTo(this.Faction)) && !this.IsForbidden(p)); + Lord lord = p.GetLord(); + if (lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(p) || + (WildManUtility.WildManShouldReachOutsideNow(p) || this.Faction == null || + p.guest != null && p.guest.Released) || p.AnimalOrWildMan() && p.playerSettings != null) + return true; + return GenAI.MachinesLike(this.Faction, p); } public override void Tick() @@ -102,7 +101,7 @@ public bool OpenValue get => Traverse.Create(this).Field("openInt").GetValue(); set => Traverse.Create(this).Field("openInt").SetValue(value); } - + public void OpenMe(int ticks) { this.ticksUntilClose = ticks; @@ -126,7 +125,7 @@ public void OpenMe(int ticks) } } } - + public override void ExposeData() { base.ExposeData(); @@ -137,4 +136,4 @@ public override void ExposeData() }*/ } } -} +} \ No newline at end of file diff --git a/Source/DiscordWebhookToken.txt b/Source/DiscordWebhookToken.txt new file mode 100644 index 0000000..9ea85d0 --- /dev/null +++ b/Source/DiscordWebhookToken.txt @@ -0,0 +1 @@ +https://discordapp.com/api/webhooks/487657430256451586/fQfntEHnahggdYmE4db0c0S_xc2MFgzHNyN7nUwIf91LSHqKPKhVi6ixUhkmL7oZf-BJ diff --git a/Source/HarmonyPatches.cs b/Source/HarmonyPatches.cs index 461e03b..6e6d946 100644 --- a/Source/HarmonyPatches.cs +++ b/Source/HarmonyPatches.cs @@ -14,57 +14,75 @@ namespace DoorsExpanded [StaticConstructorOnStartup] static class HarmonyPatches { - static HarmonyPatches() { //Log.Message("This is working!"); HarmonyInstance harmony = HarmonyInstance.Create(id: "rimworld.jecrell.doorsexpanded"); - - harmony.Patch(original: AccessTools.Method(type: typeof(EdificeGrid), name: "Register"), prefix: new HarmonyMethod( - type: typeof(HarmonyPatches), - name: nameof(RegisterDoorExpanded)), postfix: null); - harmony.Patch(original: AccessTools.Method(type: typeof(Building_Door), name: "DoorOpen"), prefix: new HarmonyMethod( - type: typeof(HarmonyPatches), - name: nameof(InvisDoorOpen)), postfix: null); - harmony.Patch(original: AccessTools.Method(type: typeof(Building_Door), name: "DoorTryClose"), prefix: new HarmonyMethod( - type: typeof(HarmonyPatches), - name: nameof(InvisDoorTryClose)), postfix: null); - harmony.Patch(original: AccessTools.Method(type: typeof(Building_Door), name: "Notify_PawnApproaching"), prefix: null, postfix: new HarmonyMethod( - type: typeof(HarmonyPatches), - name: nameof(InvisDoorNotifyApproaching)), transpiler: null); - harmony.Patch(original: AccessTools.Method(type: typeof(Building_Door), name: nameof(Building_Door.StartManualCloseBy)), + + harmony.Patch(original: AccessTools.Method(type: typeof(EdificeGrid), name: "Register"), + prefix: new HarmonyMethod( + type: typeof(HarmonyPatches), + name: nameof(RegisterDoorExpanded)), postfix: null); + harmony.Patch(original: AccessTools.Method(type: typeof(Building_Door), name: "DoorOpen"), + prefix: new HarmonyMethod( + type: typeof(HarmonyPatches), + name: nameof(InvisDoorOpen)), postfix: null); + harmony.Patch(original: AccessTools.Method(type: typeof(Building_Door), name: "DoorTryClose"), + prefix: new HarmonyMethod( + type: typeof(HarmonyPatches), + name: nameof(InvisDoorTryClose)), postfix: null); + harmony.Patch(original: AccessTools.Method(type: typeof(Building_Door), name: "Notify_PawnApproaching"), + prefix: null, postfix: new HarmonyMethod( + type: typeof(HarmonyPatches), + name: nameof(InvisDoorNotifyApproaching)), transpiler: null); + harmony.Patch( + original: AccessTools.Method(type: typeof(Building_Door), + name: nameof(Building_Door.StartManualCloseBy)), prefix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(InvisDoorManualClose)), postfix: null); - harmony.Patch(original: AccessTools.Method(type: typeof(Building_Door), name: nameof(Building_Door.StartManualOpenBy)), prefix: null, + harmony.Patch( + original: AccessTools.Method(type: typeof(Building_Door), + name: nameof(Building_Door.StartManualOpenBy)), prefix: null, postfix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(InvisDoorManualOpen)), transpiler: null); - harmony.Patch(original: AccessTools.Property(type: typeof(Building_Door), name: nameof(Building_Door.FreePassage)).GetGetMethod(), + harmony.Patch( + original: AccessTools.Property(type: typeof(Building_Door), name: nameof(Building_Door.FreePassage)) + .GetGetMethod(), prefix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(get_FreePassage)), postfix: null); - harmony.Patch(original: AccessTools.Method(type: typeof(GhostDrawer), name: nameof(GhostDrawer.DrawGhostThing)), + harmony.Patch( + original: AccessTools.Method(type: typeof(GhostDrawer), name: nameof(GhostDrawer.DrawGhostThing)), prefix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(HeronDoorGhostHandler)), postfix: null); - harmony.Patch(original: AccessTools.Method(type: typeof(GenSpawn), name: nameof(GenSpawn.SpawnBuildingAsPossible)), + harmony.Patch( + original: AccessTools.Method(type: typeof(GenSpawn), name: nameof(GenSpawn.SpawnBuildingAsPossible)), prefix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(HeronSpawnBuildingAsPossible)), postfix: null); - harmony.Patch(original: AccessTools.Method(type: typeof(GenSpawn), name: nameof(GenSpawn.WipeExistingThings)), prefix: new HarmonyMethod( - type: typeof(HarmonyPatches), - name: nameof(WipeExistingThings)), postfix: null); - harmony.Patch(original: AccessTools.Method(type: typeof(GenSpawn), name: nameof(GenSpawn.SpawningWipes)), prefix: null, postfix: new HarmonyMethod( - type: typeof(HarmonyPatches), - name: nameof(InvisDoorsDontWipe)), transpiler: null); - harmony.Patch(original: AccessTools.Method(type: typeof(GenPath), name: "ShouldNotEnterCell"), prefix: null, postfix: new HarmonyMethod( - type: typeof(HarmonyPatches), - name: nameof(ShouldNotEnterCellInvisDoors)), transpiler: null); - harmony.Patch(original: AccessTools.Method(type: typeof(CompForbiddable), name: nameof(CompForbiddable.PostDraw)), + harmony.Patch( + original: AccessTools.Method(type: typeof(GenSpawn), name: nameof(GenSpawn.WipeExistingThings)), + prefix: new HarmonyMethod( + type: typeof(HarmonyPatches), + name: nameof(WipeExistingThings)), postfix: null); + harmony.Patch(original: AccessTools.Method(type: typeof(GenSpawn), name: nameof(GenSpawn.SpawningWipes)), + prefix: null, postfix: new HarmonyMethod( + type: typeof(HarmonyPatches), + name: nameof(InvisDoorsDontWipe)), transpiler: null); + harmony.Patch(original: AccessTools.Method(type: typeof(GenPath), name: "ShouldNotEnterCell"), prefix: null, + postfix: new HarmonyMethod( + type: typeof(HarmonyPatches), + name: nameof(ShouldNotEnterCellInvisDoors)), transpiler: null); + harmony.Patch( + original: AccessTools.Method(type: typeof(CompForbiddable), name: nameof(CompForbiddable.PostDraw)), prefix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(DontDrawInvisDoorForbiddenIcons)), postfix: null); harmony.Patch( - original: AccessTools.Method(type: typeof(PawnPathUtility), name: nameof(PawnPathUtility.TryFindLastCellBeforeBlockingDoor)), + original: AccessTools.Method(type: typeof(PawnPathUtility), + name: nameof(PawnPathUtility.TryFindLastCellBeforeBlockingDoor)), prefix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(ManhunterJobGiverFix)), postfix: null); harmony.Patch( - original: AccessTools.Method(type: typeof(ForbidUtility), name: nameof(ForbidUtility.IsForbiddenToPass)), + original: AccessTools.Method(type: typeof(ForbidUtility), + name: nameof(ForbidUtility.IsForbiddenToPass)), prefix: null, postfix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(IsForbiddenToPass_PostFix))); harmony.Patch( @@ -72,16 +90,119 @@ static HarmonyPatches() prefix: null, postfix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(GetBuildingCost_PostFix))); harmony.Patch( - original: AccessTools.Method(type: typeof(PawnPathUtility), name: nameof(PawnPathUtility.FirstBlockingBuilding)), + original: AccessTools.Method(type: typeof(PawnPathUtility), + name: nameof(PawnPathUtility.FirstBlockingBuilding)), prefix: null, postfix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(FirstBlockingBuilding_PostFix))); harmony.Patch( - original: AccessTools.Method(typeof(GenGrid), "CanBeSeenOver", new []{typeof(Building)} ), + original: AccessTools.Method(typeof(GenGrid), "CanBeSeenOver", new[] {typeof(Building)}), prefix: null, postfix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(CanBeSeenOver))); - + harmony.Patch( + AccessTools.Method(typeof(JobGiver_SeekAllowedArea), "TryGiveJob"), + new HarmonyMethod(type: typeof(HarmonyPatches), + name: nameof(SeekAllowedArea_TryGiveJob)), null); + harmony.Patch( + AccessTools.Method(typeof(Building_Door), "CanPhysicallyPass"), + new HarmonyMethod(type: typeof(HarmonyPatches), + name: nameof(CanPhysicallyPass)), null); + //harmony.Patch( + // original: AccessTools.Method(typeof(Region), "Allows"), + // prefix: null, postfix: new HarmonyMethod(type: typeof(HarmonyPatches), + // name: nameof(RegionAllows))); + } + + public static bool CanPhysicallyPass(Building_Door __instance, Pawn p, ref bool __result) + { + if (!p.AnimalOrWildMan()) return true; + if (p.playerSettings == null) return true; + StringBuilder s = new StringBuilder(); + s.AppendLine(p.LabelShort + " - FreePassage: " + __instance.FreePassage); + var pawnCanOpen = (__instance is Building_DoorRegionHandler reg) ? reg.PawnCanOpen(p) : __instance.PawnCanOpen(p); + s.AppendLine(p.LabelShort + " - PawnCanOpen: " + pawnCanOpen); + s.AppendLine((p.LabelShort + " - Open: " + __instance.Open)); + s.AppendLine((p.LabelShort + " - Hostile: " + p.HostileTo(__instance))); + //Log.Message(s.ToString()); + __result = __instance.FreePassage || pawnCanOpen || (__instance.Open && p.HostileTo(__instance)); + return false; + } + + //public class JobGiver_SeekAllowedArea : ThinkNode_JobGiver + public static bool SeekAllowedArea_TryGiveJob(JobGiver_SeekAllowedArea __instance, Pawn pawn, ref Job __result) + { + if (!pawn.AnimalOrWildMan()) return true; + if (pawn.playerSettings == null) return true; + if (!pawn.Position.IsForbidden(pawn)) + { + __result = null; + return false; + } + + if (Traverse.Create(__instance).Method("HasJobWithSpawnedAllowedTarget", pawn).GetValue()) + { + __result = null; + return false; + } + + Region region = pawn.GetRegion(RegionType.Set_Passable); + if (region == null) + { + __result = null; + return false; + } + + var allows = false; + TraverseParms traverseParms = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); + RegionEntryPredicate entryCondition = (Region from, Region r) => + { + allows = r.Allows(traverseParms, false); + if (allows) return true; + return false; + }; + Region reg = null; + RegionProcessor regionProcessor = delegate(Region r) + { + if (r.IsDoorway && r?.ListerThings?.AllThings?.Any(x => x is Building_DoorRegionHandler) == false) + { + //Log.Message("Doorway disallowed"); + return false; + } + + if (!r.IsForbiddenEntirely(pawn)) + { + reg = r; + return true; + } + + return false; + }; + RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 9999, + RegionType.Set_Passable); + if (reg == null) + { + //Log.Message(pawn.LabelShort + " No region found"); + __result = null; + return false; + } + + IntVec3 c; + if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, null, out c)) + { + //Log.Message(pawn.LabelShort + " Failed to find random cell in region unforbidden"); + __result = null; + return false; + } + + __result = new Job(JobDefOf.Goto, c); + return false; } + //Region + //public bool RegionAllows(TraverseParms tp, bool isDestination) + //{ + // + //} + //GenGrid public static void CanBeSeenOver(Building b, ref bool __result) { @@ -92,27 +213,31 @@ public static void CanBeSeenOver(Building b, ref bool __result) __result = building_DoorEx != null && building_DoorEx.Open; } } - + //public static class PawnPathUtility - public static void FirstBlockingBuilding_PostFix(this PawnPath path, ref IntVec3 cellBefore, Pawn pawn, ref Thing __result) + public static void FirstBlockingBuilding_PostFix(this PawnPath path, ref IntVec3 cellBefore, Pawn pawn, + ref Thing __result) { if (!path.Found) { cellBefore = IntVec3.Invalid; __result = null; } + List nodesReversed = path.NodesReversed; if (nodesReversed.NullOrEmpty() || nodesReversed.Count <= 1) { return; } + Building building = null; IntVec3 intVec = IntVec3.Invalid; for (int i = nodesReversed.Count - 2; i >= 0; i--) { //Building edifice = nodesReversed[i].GetEdifice(pawn.Map); - var edifice = nodesReversed[index: i].GetThingList(pawn.Map).FirstOrDefault(x => x.def.thingClass == typeof(Building_DoorExpanded) || - x.def.thingClass == typeof(Building_DoorRegionHandler)); + var edifice = nodesReversed[index: i].GetThingList(pawn.Map).FirstOrDefault(x => + x.def.thingClass == typeof(Building_DoorExpanded) || + x.def.thingClass == typeof(Building_DoorRegionHandler)); if (edifice != null) { if ((edifice is Building_DoorExpanded building_Door && !building_Door.FreePassage && @@ -122,6 +247,7 @@ public static void FirstBlockingBuilding_PostFix(this PawnPath path, ref IntVec3 cellBefore = nodesReversed[i + 1]; __result = edifice; } + var building_DoorReg = edifice as Building_DoorRegionHandler; if (building_DoorReg == null || building_DoorReg.ParentDoor == null) continue; if ((!building_DoorReg.FreePassage && @@ -138,14 +264,24 @@ public static void FirstBlockingBuilding_PostFix(this PawnPath path, ref IntVec3 //PathFinder public static void GetBuildingCost_PostFix(Building b, TraverseParms traverseParms, Pawn pawn, ref int __result) { - if (__result >= int.MaxValue) return; + // if (__result >= int.MaxValue) return; if (b is Building_DoorRegionHandler reg) { switch (traverseParms.mode) { case TraverseMode.ByPawn: { - if (!traverseParms.canBash && reg.IsForbiddenToPass(pawn)) + if (reg.PawnCanOpen(pawn) && !reg.FreePassage) + { + __result = reg.TicksToOpenNow; + return; + } + if (reg.CanPhysicallyPass(pawn)) + { + __result = 0; + return; + } + if (!traverseParms.canBash && reg.IsForbidden(pawn)) { if (DebugViewSettings.drawPaths) { @@ -153,8 +289,10 @@ public static void GetBuildingCost_PostFix(Building b, TraverseParms traversePar new object[] {b.Position, b.Map, 0.77f, "forbid"}); //PathFinder.DebugFlash(b.Position, b.Map, 0.77f, "forbid"); } + __result = int.MaxValue; } + break; } } @@ -165,6 +303,11 @@ public static void GetBuildingCost_PostFix(Building b, TraverseParms traversePar { case TraverseMode.ByPawn: { + if (ex.PawnCanOpen(pawn) && !ex.FreePassage) + { + __result = ex.TicksToOpenNow; + return; + } if (!traverseParms.canBash && ex.IsForbidden(pawn)) { if (DebugViewSettings.drawPaths) @@ -172,11 +315,13 @@ public static void GetBuildingCost_PostFix(Building b, TraverseParms traversePar Traverse.Create(typeof(PathFinder)).Method("DebugFlash", new object[] {b.Position, b.Map, 0.77f, "forbid"}); } + __result = int.MaxValue; } + break; } - } + } } } @@ -186,18 +331,22 @@ public static void IsForbiddenToPass_PostFix(this Thing t, Pawn pawn, ref bool _ if (t is Building_DoorRegionHandler reg) { //Log.Message("reg called"); - __result = __result && ((t.Spawned && t.Position.IsForbidden(pawn) && !(t is Building_DoorRegionHandler)) || t.IsForbidden(pawn.Faction)); + //__result = __result && ((t.Spawned && t.Position.IsForbidden(pawn) && !(t is Building_DoorRegionHandler)) || t.IsForbidden(pawn.Faction)); + //ForbidUtility.CaresAboutForbidden(pawn, false) && t.IsForbidden(pawn.Faction); + __result = __result && ((t.Spawned && t.Position.IsForbidden(pawn)) || t.IsForbidden(pawn.Faction)); + //if (__result == false && pawn.AnimalOrWildMan()) Log.Message(pawn.LabelShort + " rejected from expanded door"); //Log.Message("Result is " + __result.ToString()); } - if (t is Building_DoorExpanded ex) - { - //Log.Message("ex called"); - __result = __result && ((t.Spawned && t.Position.IsForbidden(pawn) && !(t is Building_DoorExpanded)) || t.IsForbidden(pawn.Faction)); - //Log.Message("Result is " + __result.ToString()); - } - + +// if (t is Building_DoorExpanded ex) +// { +// Log.Message("ex called"); +// //__result = __result && ((t.Spawned && t.Position.IsForbidden(pawn) && !(t is Building_DoorExpanded)) || t.IsForbidden(pawn.Faction)); +// __result = __result && ((t.Spawned && t.Position.IsForbidden(pawn) && !(t is Building_DoorExpanded)) || t.IsForbidden(pawn.Faction)); +// //Log.Message("Result is " + __result.ToString()); +// } } - + //PawnPathUtility //Adds an extra check. public static bool ManhunterJobGiverFix(PawnPath path, Pawn pawn, ref IntVec3 result, ref bool __result) @@ -206,9 +355,10 @@ public static bool ManhunterJobGiverFix(PawnPath path, Pawn pawn, ref IntVec3 re { result = path.NodesReversed[index: 0]; __result = false; - Log.Message("Nodes less or equal to 1"); + //Log.Message("Nodes less or equal to 1"); return false; } + List nodesReversed = path.NodesReversed; if (nodesReversed != null) { @@ -216,7 +366,9 @@ public static bool ManhunterJobGiverFix(PawnPath path, Pawn pawn, ref IntVec3 re { //pawn.Map.debugDrawer.FlashCell(nodesReversed[i]); var edifice = nodesReversed[index: i].GetThingList(pawn.Map) - .FirstOrDefault(x => x.def.thingClass == typeof(Building_DoorExpanded) || x.def.thingClass == typeof(Building_DoorRegionHandler)); //GetEdifice(map: pawn.Map); + .FirstOrDefault(x => + x.def.thingClass == typeof(Building_DoorExpanded) || + x.def.thingClass == typeof(Building_DoorRegionHandler)); //GetEdifice(map: pawn.Map); //var edifice = nodesReversed[i].GetEdifice(pawn.Map); if (edifice is Building_DoorExpanded building_DoorExpanded) { @@ -229,8 +381,9 @@ public static bool ManhunterJobGiverFix(PawnPath path, Pawn pawn, ref IntVec3 re return false; } } + if (edifice is Building_DoorRegionHandler building_DoorReg && - (!building_DoorReg.CanPhysicallyPass(pawn))) + (!building_DoorReg.CanPhysicallyPass(pawn))) { //Log.Message(text: "DoorsExpanded :: Manhunter Check Passed"); result = nodesReversed[index: i + 1]; @@ -238,13 +391,15 @@ public static bool ManhunterJobGiverFix(PawnPath path, Pawn pawn, ref IntVec3 re return false; } } + //Log.Message("No objects detected in path"); result = nodesReversed[index: 0]; } + __result = false; return true; } - + //Building_Door public static bool get_FreePassage(Building_Door __instance, ref bool __result) { @@ -253,6 +408,7 @@ public static bool get_FreePassage(Building_Door __instance, ref bool __result) __result = b.ParentDoor.FreePassage && !b.ParentDoor.Forbidden; return false; } + return true; } @@ -264,7 +420,7 @@ public static bool DontDrawInvisDoorForbiddenIcons(CompForbiddable __instance) return true; } - public static void ShouldNotEnterCellInvisDoors(Pawn pawn, Map map, IntVec3 dest, ref bool __result ) + public static void ShouldNotEnterCellInvisDoors(Pawn pawn, Map map, IntVec3 dest, ref bool __result) { if (__result || pawn == null) return; @@ -273,17 +429,20 @@ public static void ShouldNotEnterCellInvisDoors(Pawn pawn, Map map, IntVec3 dest __result = true; return; } + if (!dest.Walkable(map)) { __result = true; return; } + Building edifice = dest.GetEdifice(map: map); if (edifice == null) { //Log.Message("No edifice. So let's go!"); return; } + if (edifice is Building_DoorExpanded building_doorEx) { if (building_doorEx.IsForbidden(pawn)) @@ -291,12 +450,14 @@ public static void ShouldNotEnterCellInvisDoors(Pawn pawn, Map map, IntVec3 dest __result = true; return; } + if (!building_doorEx.PawnCanOpen(pawn)) { __result = true; return; } } + if (edifice is Building_DoorRegionHandler building_doorReg) { if (building_doorReg.IsForbidden(pawn)) @@ -304,14 +465,16 @@ public static void ShouldNotEnterCellInvisDoors(Pawn pawn, Map map, IntVec3 dest __result = true; return; } + if (!building_doorReg.PawnCanOpen(p: pawn)) { __result = true; } } } - - public static bool WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, BuildableDef thingDef, Map map, DestroyMode mode) + + public static bool WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, BuildableDef thingDef, Map map, + DestroyMode mode) { //Log.Message("1"); var trueDef = DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == thingDef.defName); @@ -322,38 +485,45 @@ public static bool WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, Buildable { return false; } - return true; + + return true; } //GenSpawn public static void InvisDoorsDontWipe(BuildableDef newEntDef, BuildableDef oldEntDef, ref bool __result) { - var oldTrueDef = DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == oldEntDef.defName); - var newTrueDef = DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == newEntDef.defName); + var oldTrueDef = + DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == oldEntDef.defName); + var newTrueDef = + DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == newEntDef.defName); if (newEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName && oldEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName) { - __result = true; //false, meaning, don't wipe the old thing when you spawn + __result = true; //false, meaning, don't wipe the old thing when you spawn return; } - if (newEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName || oldEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName) + + if (newEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName || + oldEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName) { - __result = false; //false, meaning, don't wipe the old thing when you spawn + __result = false; //false, meaning, don't wipe the old thing when you spawn return; } - + if (newTrueDef != null && newTrueDef.thingClass == typeof(Building_DoorExpanded) && oldTrueDef != null && oldTrueDef.thingClass == typeof(Building_DoorExpanded)) { __result = true; return; } + if (oldTrueDef != null && oldTrueDef.thingClass == typeof(Building_DoorExpanded) && newEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName) { __result = false; return; } + if (newTrueDef != null && newTrueDef.thingClass == typeof(Building_DoorExpanded) && oldEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName) { @@ -369,11 +539,13 @@ public static bool HeronSpawnBuildingAsPossible(Building building, Map map, bool if (building is Building_DoorExpanded || building is Building_DoorRegionHandler || building.def == HeronDefOf.HeronInvisibleDoor || - building.def.thingClass == typeof(Building_DoorRegionHandler)) + building.def.thingClass == typeof(Building_DoorRegionHandler)) { - GenSpawn.Spawn(newThing: building, loc: building.Position, map: map, rot: building.Rotation, wipeMode: WipeMode.Vanish, respawningAfterLoad: respawningAfterLoad); + GenSpawn.Spawn(newThing: building, loc: building.Position, map: map, rot: building.Rotation, + wipeMode: WipeMode.Vanish, respawningAfterLoad: respawningAfterLoad); return false; } + return true; } @@ -384,10 +556,12 @@ public static Quaternion QuatFromRot(Graphic __instance, Rot4 rot) { return Quaternion.identity; } + if (__instance.ShouldDrawRotated) { return rot.AsQuat; } + return Quaternion.identity; } @@ -398,7 +572,7 @@ public static bool isExceptionForEdificeRegistration(Building ed) ed.def.thingClass == typeof(Building_DoorRegionHandler) || ed.def.thingClass == typeof(Building_DoorExpanded); } - + //EdificeGrid //TODO Make transpiler public static bool RegisterDoorExpanded(EdificeGrid __instance, Building ed) @@ -417,7 +591,8 @@ public static bool RegisterDoorExpanded(EdificeGrid __instance, Building ed) { IntVec3 intVec = new IntVec3(j, 0, i); var oldBuilding = __instance[intVec]; - if (UnityData.isDebugBuild && oldBuilding != null && !oldBuilding.Destroyed && !isExceptionForEdificeRegistration(oldBuilding)) + if (UnityData.isDebugBuild && oldBuilding != null && !oldBuilding.Destroyed && + !isExceptionForEdificeRegistration(oldBuilding)) { Log.Error(string.Concat(new object[] { @@ -432,45 +607,55 @@ public static bool RegisterDoorExpanded(EdificeGrid __instance, Building ed) oldBuilding.Destroy(DestroyMode.Vanish); return false; } - Traverse.Create(__instance).Field("innerArray").GetValue()[cellIndices.CellToIndex(intVec)] = ed; + + Traverse.Create(__instance).Field("innerArray").GetValue()[ + cellIndices.CellToIndex(intVec)] = ed; } } + // return false; } + return true; } // Verse.GhostDrawer - public static bool HeronDoorGhostHandler(IntVec3 center, Rot4 rot, ThingDef thingDef, Graphic baseGraphic, Color ghostCol, AltitudeLayer drawAltitude) + public static bool HeronDoorGhostHandler(IntVec3 center, Rot4 rot, ThingDef thingDef, Graphic baseGraphic, + Color ghostCol, AltitudeLayer drawAltitude) { if (thingDef is DoorExpandedDef def && def.fixedPerspective) { - Graphic graphic = GhostUtility.GhostGraphicFor(baseGraphic, thingDef, ghostCol); - //Graphic graphic = Traverse.Create(typeof(GhostDrawer)).Method("GhostGraphicFor", new object[] { thingDef.graphic, thingDef, ghostCol }).GetValue(); - Vector3 loc = GenThing.TrueCenter(center, rot, thingDef.Size, drawAltitude.AltitudeFor()); - - for (int i = 0; i < 2; i++) - { - bool flipped = (i != 0) ? true : false; - Building_DoorExpanded.DrawParams(def, loc, rot, out var mesh, out var matrix, mod: 0, flipped: flipped); - Graphics.DrawMesh(mesh: mesh, matrix: matrix, material: graphic.MatAt(rot: rot, thing: null), layer: 0); - } - if (thingDef?.PlaceWorkers?.Count > 0) + Graphic graphic = GhostUtility.GhostGraphicFor(baseGraphic, thingDef, ghostCol); + //Graphic graphic = Traverse.Create(typeof(GhostDrawer)).Method("GhostGraphicFor", new object[] { thingDef.graphic, thingDef, ghostCol }).GetValue(); + Vector3 loc = GenThing.TrueCenter(center, rot, thingDef.Size, drawAltitude.AltitudeFor()); + + for (int i = 0; i < 2; i++) + { + bool flipped = (i != 0) ? true : false; + Building_DoorExpanded.DrawParams(def, loc, rot, out var mesh, out var matrix, mod: 0, + flipped: flipped); + Graphics.DrawMesh(mesh: mesh, matrix: matrix, material: graphic.MatAt(rot: rot, thing: null), + layer: 0); + } + + if (thingDef?.PlaceWorkers?.Count > 0) + { + for (int i = 0; i < thingDef.PlaceWorkers.Count; i++) { - for (int i = 0; i < thingDef.PlaceWorkers.Count; i++) - { - thingDef.PlaceWorkers[index: i].DrawGhost(def: thingDef, center: center, rot: rot, ghostCol: ghostCol); - } + thingDef.PlaceWorkers[index: i] + .DrawGhost(def: thingDef, center: center, rot: rot, ghostCol: ghostCol); } + } + return false; } + return true; } - //// Verse.ThingDef //public static void HeronDoorIsDoor(ThingDef __instance, ref bool __result) //{ @@ -518,8 +703,8 @@ public static bool InvisDoorManualClose(Building_Door __instance, Pawn closer) //w.ParentDoor.StartManualCloseBy(closer); return false; } - return true; + return true; } // RimWorld.Building_Door @@ -530,20 +715,22 @@ public static void InvisDoorManualOpen(Building_Door __instance, Pawn opener) if (w.ParentDoor.PawnCanOpen(p: opener)) { w.ParentDoor.StartManualOpenBy(opener: opener); - if (w.ParentDoor.InvisDoors.ToList().FindAll(match: x => x != __instance) is List otherDoors && !otherDoors.NullOrEmpty()) + if (w.ParentDoor.InvisDoors.ToList().FindAll(match: x => x != __instance) is + List otherDoors && !otherDoors.NullOrEmpty()) { foreach (Building_DoorRegionHandler door in otherDoors) { if (!door.Open) { - int math = (int)(1200 * Math.Max(val1: w.ParentDoor.Graphic.drawSize.x, val2: w.ParentDoor.Graphic.drawSize.y)); + int math = (int) (1200 * Math.Max(val1: w.ParentDoor.Graphic.drawSize.x, + val2: w.ParentDoor.Graphic.drawSize.y)); //this.ticksUntilClose = ticksToClose; Traverse.Create(root: door).Field(name: "ticksUntilClose").SetValue(value: math); //this.openInt = true; Traverse.Create(root: door).Field(name: "openInt").SetValue(value: true); } } - } + } } } } @@ -567,22 +754,25 @@ public static bool InvisDoorOpen(Building_Door __instance, int ticksToClose = 60 Traverse.Create(root: __instance).Field(name: "ticksUntilClose").SetValue(value: ticksToClose); if (!Traverse.Create(root: __instance).Field(name: "openInt").GetValue()) { - AccessTools.Field(type: typeof(Building_Door), name: "openInt").SetValue(obj: __instance, value: true); + AccessTools.Field(type: typeof(Building_Door), name: "openInt") + .SetValue(obj: __instance, value: true); //Traverse.Create(__instance).Field("openInt"). SetValue(true); } + w.ParentDoor.DoorOpen(ticksToClose: ticksToClose); return false; } + return true; } public static bool InvisDoorTryClose(Building_Door __instance) { - if (__instance is Building_DoorRegionHandler w) { //w.ParentDoor.DoorTryClose(); - if (!Traverse.Create(root: __instance).Field(name: "holdOpenInt").GetValue() || __instance.BlockedOpenMomentary || w.ParentDoor.Open) + if (!Traverse.Create(root: __instance).Field(name: "holdOpenInt").GetValue() || + __instance.BlockedOpenMomentary || w.ParentDoor.Open) { return false; } @@ -591,11 +781,11 @@ public static bool InvisDoorTryClose(Building_Door __instance) //Traverse.Create(__instance).Field("openInt").SetValue(false); return false; } + return true; } - // Verse.RegionTypeUtility public static void GetHeronRegionType(ref RegionType __result, IntVec3 c, Map map) { @@ -616,5 +806,4 @@ public static void GetHeronRegionType(ref RegionType __result, IntVec3 c, Map ma } } } -} - +} \ No newline at end of file diff --git a/Source/ProjectHeron.csproj b/Source/ProjectHeron.csproj index f673d76..a552836 100644 --- a/Source/ProjectHeron.csproj +++ b/Source/ProjectHeron.csproj @@ -45,7 +45,7 @@ - .\Dependencies\UnityEngine.dll + ..\..\..\RimWorldWin64_Data\Managed\UnityEngine.dll False diff --git a/Source/obj/Debug/DoorsExpanded.dll b/Source/obj/Debug/DoorsExpanded.dll index 180833f..7eeeec9 100644 Binary files a/Source/obj/Debug/DoorsExpanded.dll and b/Source/obj/Debug/DoorsExpanded.dll differ diff --git a/Source/obj/Debug/ProjectHeron.csproj.CoreCompileInputs.cache b/Source/obj/Debug/ProjectHeron.csproj.CoreCompileInputs.cache index d7ce60a..8fd2c15 100644 --- a/Source/obj/Debug/ProjectHeron.csproj.CoreCompileInputs.cache +++ b/Source/obj/Debug/ProjectHeron.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -9bcceca6af9907eb84f31f30e127157e25d77f28 +7643d5db6326961f2f7baa3252da99c66b5d6f3e diff --git a/Source/obj/Debug/ProjectHeron.csproj.FileListAbsolute.txt b/Source/obj/Debug/ProjectHeron.csproj.FileListAbsolute.txt index 0f876a4..e3f15d6 100644 --- a/Source/obj/Debug/ProjectHeron.csproj.FileListAbsolute.txt +++ b/Source/obj/Debug/ProjectHeron.csproj.FileListAbsolute.txt @@ -15,3 +15,8 @@ C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\Doors-Expan C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\Doors-Expanded\Source\obj\Debug\ProjectHeron.csprojAssemblyReference.cache C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\Doors-Expanded\Source\obj\Debug\ProjectHeron.csproj.CoreCompileInputs.cache C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\Doors-Expanded\Source\obj\Debug\ProjectHeron.csproj.CopyComplete +C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\DoorsExpanded\Assemblies\DoorsExpanded.dll +C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\DoorsExpanded\Source\obj\Debug\ProjectHeron.csprojAssemblyReference.cache +C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\DoorsExpanded\Source\obj\Debug\ProjectHeron.csproj.CoreCompileInputs.cache +C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\DoorsExpanded\Source\obj\Debug\ProjectHeron.csproj.CopyComplete +C:\Program Files (x86)\Steam\steamapps\common\RimWorld\ModsWorkspace\DoorsExpanded\Source\obj\Debug\DoorsExpanded.dll diff --git a/Source/obj/Debug/ProjectHeron.csprojAssemblyReference.cache b/Source/obj/Debug/ProjectHeron.csprojAssemblyReference.cache index 3546c7e..c893195 100644 Binary files a/Source/obj/Debug/ProjectHeron.csprojAssemblyReference.cache and b/Source/obj/Debug/ProjectHeron.csprojAssemblyReference.cache differ