diff --git a/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml b/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml index 297e28e..0bf9f68 100644 --- a/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml +++ b/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml @@ -3,37 +3,40 @@ TestGroupAnimation1 2 - -
  • +
  • 200 - +
  • Pawn1_Stage1_TestAnimation1
  • Pawn2_Stage1_TestAnimation2
  • - +
  • - 10 - + 10 +
  • 3 -
  • Pawn1_Stage2_Variant1
  • -
  • Pawn2_Stage2_Variant1
  • + +
  • Pawn1_Stage2_Variant1
  • +
  • Pawn2_Stage2_Variant1
  • +
    + -
  • 1 -
  • Pawn1_Stage2_Variant2
  • -
  • Pawn2_Stage2_Variant2
  • + +
  • Pawn1_Stage2_Variant2
  • +
  • Pawn2_Stage2_Variant2
  • +
    - + -
  • - +
  • +
  • 10 - +
  • 3
  • Pawn1_Stage2_Variant1
  • @@ -45,12 +48,12 @@
  • Pawn1_Stage2_Variant2
  • Pawn2_Stage2_Variant2
  • - +
  • 10 - +
  • 3
  • Pawn1_Stage2_Variant1
  • @@ -62,10 +65,10 @@
  • Pawn1_Stage2_Variant2
  • Pawn2_Stage2_Variant2
  • - + - +
    @@ -82,6 +85,26 @@ 1 +
  • + +
  • Sex
  • + + +
  • Human
  • +
  • Dog
  • +
    + 0 + +
  • + +
  • Sex_Reverse
  • + + +
  • Dog
  • +
  • Human
  • +
    + 1 +
    diff --git a/1.5/Source/GroupAnimationStages/AnimationStage.cs b/1.5/Source/GroupAnimationStages/AnimationStage.cs index f8a22e0..58e86ab 100644 --- a/1.5/Source/GroupAnimationStages/AnimationStage.cs +++ b/1.5/Source/GroupAnimationStages/AnimationStage.cs @@ -3,11 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Verse; namespace Rimworld_Animations { public abstract class AnimationStage { - //single stage containing group of animations + + //Return a list containing a tuple; int for how long the animation should play for + public abstract List> GetAnimations(int actor, int seed); + } } diff --git a/1.5/Source/GroupAnimationStages/AnimationStage_Branch.cs b/1.5/Source/GroupAnimationStages/AnimationStage_Branch.cs new file mode 100644 index 0000000..deb7751 --- /dev/null +++ b/1.5/Source/GroupAnimationStages/AnimationStage_Branch.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace Rimworld_Animations +{ + public class AnimationStage_Branch : AnimationStage + { + List paths; + public override List> GetAnimations(int actor, int seed) + { + return paths[(seed * 59) % paths.Count].GetAnimations(actor, seed); + } + } +} diff --git a/1.5/Source/GroupAnimationStages/AnimationStage_LoopRandomSelectChance.cs b/1.5/Source/GroupAnimationStages/AnimationStage_LoopRandomSelectChance.cs new file mode 100644 index 0000000..6ef1ad4 --- /dev/null +++ b/1.5/Source/GroupAnimationStages/AnimationStage_LoopRandomSelectChance.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace Rimworld_Animations +{ + public class AnimationStage_LoopRandomSelectChance : AnimationStage + { + public int loops; + public List animationOptions; + + public override List> GetAnimations(int actor, int seed) + { + int numberOfActors = animationOptions[0].animationDefs.Count; + List> animations = new List>(); + + for (int i = 0; i < loops; i++) + { + + AnimationLoopOption option = getAnimationLoopOptionByWeight(seed + i, out int longestAnimLength); + Tuple animation = Tuple.Create(longestAnimLength, option.animationDefs[actor]); + animations.Append(animation); + } + + return animations; + } + + public class AnimationLoopOption + { + public int probability; + public List animationDefs; + } + + //select random element from loop options by weight; also calculate the longest anim length + public AnimationLoopOption getAnimationLoopOptionByWeight(int seed, out int longestAnimLength) + { + int totalWeight = animationOptions.Sum(x => x.probability); + int randomNumber = (seed * 56) % totalWeight; + + int cumulativeWeight = 0; + foreach(AnimationLoopOption option in animationOptions) { + cumulativeWeight += option.probability; + if (randomNumber <= cumulativeWeight) + { + longestAnimLength = option.animationDefs.Max(x => x.durationTicks); + return option; + } + } + + longestAnimLength = animationOptions[0].animationDefs.Max(x => x.durationTicks); + return animationOptions[0]; + } + + + } +} diff --git a/1.5/Source/GroupAnimationStages/AnimationStage_TicksDuration.cs b/1.5/Source/GroupAnimationStages/AnimationStage_TicksDuration.cs new file mode 100644 index 0000000..e502596 --- /dev/null +++ b/1.5/Source/GroupAnimationStages/AnimationStage_TicksDuration.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace Rimworld_Animations +{ + public class AnimationStage_TicksDuration : AnimationStage + { + int ticks; + List animationDefs; + + public override List> GetAnimations(int actor, int seed) + { + return new List>() { Tuple.Create(ticks, animationDefs[actor]) }; + } + } +} diff --git a/1.5/Source/Keyframes/ExtendedKeyframe.cs b/1.5/Source/Keyframes/ExtendedKeyframe.cs index ff23cab..e5e6701 100644 --- a/1.5/Source/Keyframes/ExtendedKeyframe.cs +++ b/1.5/Source/Keyframes/ExtendedKeyframe.cs @@ -12,6 +12,7 @@ namespace Rimworld_Animations { public Rot4 rotation; + public SoundDef sound = null; public bool visible; } diff --git a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs index fe6c81a..8855f47 100644 --- a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs +++ b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs @@ -19,6 +19,7 @@ namespace Rimworld_Animations if (__instance.AnimationWorker is AnimationWorker_KeyframesExtended extendedAnimWorker) { //INVIS IF ANIM CALLS FOR IT + //replace maybe? if (!extendedAnimWorker.visibleAtTick(__instance.tree.AnimationTick)) { __instance.requestRecache = true; @@ -27,6 +28,7 @@ namespace Rimworld_Animations // HEAD ROTATION ADJUST FACING + Rot4 animFacing = extendedAnimWorker.facingAtTick(__instance.tree.AnimationTick); if (parms.facing != animFacing) diff --git a/Rimworld-Animations.csproj b/Rimworld-Animations.csproj index 398d8a9..4aff51e 100644 --- a/Rimworld-Animations.csproj +++ b/Rimworld-Animations.csproj @@ -77,6 +77,9 @@ + + +