Skip to content

Commit

Permalink
Fix head rendering in wrong map, adjust auto processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru committed Feb 16, 2024
1 parent 19f6f23 commit db6db53
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 31 deletions.
40 changes: 20 additions & 20 deletions Source/Animations/UserSettings/Layouts/default-2022.dwlt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 100}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 93
controlID: 17
--- !u!114 &3
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -128,7 +128,7 @@ MonoBehaviour:
- {fileID: 14}
- {fileID: 13}
m_Selected: 2
m_LastSelected: 0
m_LastSelected: 1
--- !u!114 &6
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -224,7 +224,7 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 100}
m_MaxSize: {x: 16192, y: 16192}
vertical: 1
controlID: 184
controlID: 18
--- !u!114 &10
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -249,7 +249,7 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 50}
m_MaxSize: {x: 16192, y: 8096}
vertical: 0
controlID: 49
controlID: 19
--- !u!114 &11
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -469,7 +469,7 @@ MonoBehaviour:
m_OverlaysVisible: 1
m_LockTracker:
m_IsLocked: 0
m_LastSelectedObjectID: 20046
m_LastSelectedObjectID: 20044
--- !u!114 &14
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -530,9 +530,9 @@ MonoBehaviour:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 60580000
m_LastClickedID: 22624
m_ExpandedIDs: 0000000006500000
m_SelectedIDs: 4a5a0000
m_LastClickedID: 23114
m_ExpandedIDs: 0000000004500000365a000000ca9a3bffffff7f
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -560,7 +560,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 0000000006500000
m_ExpandedIDs: 0000000004500000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand All @@ -585,9 +585,9 @@ MonoBehaviour:
m_Icon: {fileID: 0}
m_ResourceFile:
m_ListAreaState:
m_SelectedInstanceIDs:
m_LastClickedInstanceID: 0
m_HadKeyboardFocusLastEvent: 1
m_SelectedInstanceIDs: 784e0000
m_LastClickedInstanceID: 20088
m_HadKeyboardFocusLastEvent: 0
m_ExpandedInstanceIDs: c6230000
m_RenameOverlay:
m_UserAcceptedRename: 0
Expand Down Expand Up @@ -700,9 +700,9 @@ MonoBehaviour:
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 4e4e0000
m_LastClickedID: 20046
m_ExpandedIDs: 24fbffff
m_SelectedIDs: 4c4e0000
m_LastClickedID: 20044
m_ExpandedIDs: 30fbffff044c0000c04c0000844d00004c4e0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -1043,9 +1043,9 @@ MonoBehaviour:
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: 1.0091436, y: -0.012789965, z: 0.16064566}
m_Target: {x: 0.68495107, y: -0.14878297, z: 0.14938828}
speed: 2
m_Value: {x: 1.0091436, y: -0.012789965, z: 0.16064566}
m_Value: {x: 0.68495107, y: -0.14878297, z: 0.14938828}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
Expand Down Expand Up @@ -1095,9 +1095,9 @@ MonoBehaviour:
speed: 2
m_Value: {x: -0.7071068, y: 0, z: -0, w: -0.7071068}
m_Size:
m_Target: 1.3983847
m_Target: 1.0008484
speed: 2
m_Value: 1.3983847
m_Value: 1.0008484
m_Ortho:
m_Target: 1
speed: 2
Expand Down Expand Up @@ -1189,7 +1189,7 @@ MonoBehaviour:
m_HSlider: 0
m_VSlider: 0
m_IgnoreScrollWheelUntilClicked: 0
m_EnableMouseInput: 0
m_EnableMouseInput: 1
m_EnableSliderZoomHorizontal: 0
m_EnableSliderZoomVertical: 0
m_UniformScale: 1
Expand Down
7 changes: 2 additions & 5 deletions Source/ThingGenerator/AnimDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,8 @@ where chance > 0
// Chance to promote at all:
// Needs to be thought out... A future task.
float promotionChanceForAny = Mathf.Min(possibleCount * 0.5f, 0.65f);
if (!Rand.Chance(promotionChanceForAny))
{
Core.Log($"Did not promote from {input.OriginalAnim} ({input.Outcome}), {promotionChanceForAny:P1} chance failed.");
return null;
}
if (!Rand.Chance(promotionChanceForAny))
return null;

var selected = allPossibles.RandomElementByWeightWithFallback(pair => pair.chance);

Expand Down
11 changes: 6 additions & 5 deletions Source/ThingGenerator/AnimationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public void AddDroppedHeadFor(Pawn pawn, AnimRenderer animRenderer)
Direction = bodySS.GetWorldDirection(),
Position = headSS.GetWorldPosition(),
Rotation = headSS.GetWorldRotation(),
TimeToLive = 120
TimeToLive = 120,
Map = pawn.Map ?? pawn.Corpse?.Map
};

heads.Add(instance);
Expand All @@ -140,20 +141,21 @@ private void RenderHeads()
{
for (int i = 0; i < heads.Count; i++)
{
var head = heads[i];
bool stayAlive;
try
{
stayAlive = heads[i].Render();
stayAlive = head.Render();
}
catch (Exception e)
{
Core.Error($"Exception rendering dropped head of {heads[i].Pawn}. Head will be deleted.", e);
Core.Error($"Exception rendering dropped head of {head.Pawn}. Head will be deleted.", e);
stayAlive = false;
}

if (!stayAlive)
{
PawnToHeadInstance.Remove(heads[i].Pawn);
PawnToHeadInstance.Remove(head.Pawn);
// Remove at swap back, for speed reasons:
heads[i] = heads[^1];
heads.RemoveAt(heads.Count - 1);
Expand Down Expand Up @@ -203,7 +205,6 @@ private static void DoEvent(AnimRenderer r, EventBase ev)
try
{
EventHelper.Handle(ev, r);
Core.Log($"Did event {ev} for {r}");
}
catch (Exception e)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/ThingGenerator/Heads/HeadInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace AM.Heads;
public sealed class HeadInstance
{
public Pawn Pawn { get; set; }
public Map Map { get; set; }
public Vector3 Position { get; set; }
public float Rotation { get; set; }
public float TimeToLive { get; set; }
Expand All @@ -27,6 +28,10 @@ public bool Render()
if (TimeToLive <= 0f)
return false;

// Do not actually render if the map is not currently visible.
if (Map != Find.CurrentMap)
return true;

//Render pawn in custom position using patches.
Patch_PawnRenderer_RenderPawnInternal.NextDrawMode = Patch_PawnRenderer_RenderPawnInternal.DrawMode.HeadStandalone;
Patch_PawnRenderer_RenderPawnInternal.HeadRotation = Direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static bool Prefix(Pawn pawn, ref bool createdNew, ref bool __result)
var isBeheaded = AnimationManager.PawnToHeadInstance.TryGetValue(pawn, out _);
if (!isBeheaded)
return true;
}
}

createdNew = false;
__result = false;
Expand Down
4 changes: 4 additions & 0 deletions Source/ThingGenerator/Processing/MapPawnProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ bool FormalGrappleCheck(Pawn pawn)
if (pawn.IsInAnimation() || GrabUtility.IsBeingTargetedForGrapple(pawn))
continue;

// If fire at will is disabled, don't process them. They should not be attacking or lassoing.
if (pawn.drafter?.FireAtWill == false)
continue;

// Should this pawn even be scanned?
GetSecondsMTB(pawn, out float execMTB, out float lassoMTB);
bool execRandom = Rand.MTBEventOccurs(execMTB, 60f, Core.Settings.ScanTickInterval);
Expand Down

0 comments on commit db6db53

Please sign in to comment.