Skip to content

Commit

Permalink
1.0.9.14 - Overlays Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jecrell committed Jun 9, 2018
1 parent 6a814ce commit a7d2752
Show file tree
Hide file tree
Showing 9 changed files with 857 additions and 121 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>https://discord.gg/AaVFA7V</url>
<targetVersion>0.18.0</targetVersion>
<description>
[1.0.9.12] (June 2018)
[1.0.9.14] (June 2018)
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/0JecsTools.dll
Binary file not shown.
Binary file modified Assemblies/AbilityUser.dll
Binary file not shown.
Binary file modified Assemblies/AbilityUserAI.dll
Binary file not shown.
Binary file modified Assemblies/CompOverlays.dll
Binary file not shown.
894 changes: 803 additions & 91 deletions Source/.idea/.idea.JecsTools/.idea/workspace.xml

Large diffs are not rendered by default.

74 changes: 45 additions & 29 deletions Source/AllModdingComponents/CompAbilityUser/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,31 @@ public AbilityUserMod(ModContentPack content) : base(content)

harmony.Patch(AccessTools.Method(typeof(ShortHashGiver), "GiveShortHash"),
new HarmonyMethod(typeof(AbilityUserMod), nameof(GiveShortHash_PrePatch)), null);
harmony.Patch(AccessTools.Method(typeof(PawnGroupKindWorker), "GeneratePawns",
new Type[]{typeof(PawnGroupMakerParms), typeof(PawnGroupMaker), typeof(bool)}), null,

harmony.Patch(AccessTools.Method(typeof(PawnGroupKindWorker), "GeneratePawns",
new Type[] {typeof(PawnGroupMakerParms), typeof(PawnGroupMaker), typeof(bool)}), null,
new HarmonyMethod(typeof(AbilityUserMod), nameof(GeneratePawns_PostFix)));
}

// RimWorld.PawnGroupKindWorker_Normal
public static void GeneratePawns_PostFix(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, bool errorOnZeroResults, ref List<Pawn> __result)
public static void GeneratePawns_PostFix(PawnGroupMakerParms parms, PawnGroupMaker groupMaker,
bool errorOnZeroResults, ref List<Pawn> __result)
{
//Anyone special?
if (__result.Any() && __result.FindAll(x => x.TryGetComp<CompAbilityUser>() is CompAbilityUser cu && cu.CombatPoints() > 0) is List<Pawn> specialPawns)
if (__result?.Count > 0 &&
__result.FindAll(x => x.TryGetComp<CompAbilityUser>() is CompAbilityUser cu && cu.CombatPoints() > 0) is
List<Pawn> specialPawns && specialPawns?.Count > 0)
{
//Log.Message("Special Pawns Detected");
//Log.Message("------------------");

//Points
var previousPoints = parms.points;
//Log.Message("Points: " + previousPoints);

//Log.Message("Average Characters");
//Log.Message("------------------");

//Anyone average?
int avgPawns = 0;
var avgCombatPoints = new Dictionary<Pawn, float>();
Expand All @@ -77,13 +80,12 @@ public static void GeneratePawns_PostFix(PawnGroupMakerParms parms, PawnGroupMak
avgCombatPoints.Add(x, x.kindDef.combatPower);
//Log.Message(x.LabelShort + " : " + x.kindDef.combatPower);
});

}

//Log.Message("------------------");
//Log.Message("Special Characters");
//Log.Message("------------------");

//What's your powers?
var specCombatPoints = new Dictionary<Pawn, float>();
specialPawns.ForEach(x =>
Expand All @@ -99,7 +101,6 @@ public static void GeneratePawns_PostFix(PawnGroupMakerParms parms, PawnGroupMak
//Log.Message(x.LabelShort + " : " + combatValue);
});


//Special case -- single raider/character should not be special to avoid problems (e.g. Werewolf raid destroys everyone).
if (avgPawns == 0 && specCombatPoints.Sum(x => x.Value) > 0 && specialPawns.Count == 1)
{
Expand All @@ -108,6 +109,10 @@ public static void GeneratePawns_PostFix(PawnGroupMakerParms parms, PawnGroupMak
return;
}

//Special case -- no special characters.
if (specialPawns?.Count <= 0)
return;

//Should we rebalance?
int tryLimit = avgPawns + specialPawns.Count + 1;
int initTryLimit = tryLimit;
Expand All @@ -116,48 +121,58 @@ public static void GeneratePawns_PostFix(PawnGroupMakerParms parms, PawnGroupMak
var removedCharacters = new List<Pawn>();
while (previousPoints < tempAvgCombatPoints.Sum(x => x.Value) + tempSpecCombatPoints.Sum(x => x.Value))
{

//Log.Message("------------------");
//Log.Message("Rebalance Attempt # " + (initTryLimit - tryLimit + 1));
//Log.Message("------------------");
//Log.Message("Scenario Points: " + previousPoints + ". Total Points: " + tempAvgCombatPoints.Sum(x => x.Value) + tempSpecCombatPoints.Sum(x => x.Value));

//In-case some stupid stuff occurs
--tryLimit;
if (tryLimit < 0)
break;

//If special characters outnumber the avg characters, try removing some of the special characters instead.
if (tempSpecCombatPoints.Count >= tempAvgCombatPoints.Count)
{
var toRemove = tempSpecCombatPoints.Keys.RandomElement();
//Log.Message("Removed: " + toRemove.LabelShort + " : " + tempSpecCombatPoints[toRemove]);
removedCharacters.Add(toRemove);
tempSpecCombatPoints.Remove(toRemove);
var toRemove = tempSpecCombatPoints?.Keys?.RandomElement();
if (toRemove != null)
{
//Log.Message("Removed: " + toRemove.LabelShort + " : " + tempSpecCombatPoints[toRemove]);
removedCharacters.Add(toRemove);
tempSpecCombatPoints.Remove(toRemove);
}
}
//If average characters outnumber special characters, then check if the combat value of avg is greater.
else if (tempSpecCombatPoints.Count < tempAvgCombatPoints.Count)
{
//Remove a random average character if the average characters have more combat points for a score
if (tempAvgCombatPoints.Sum(x => x.Value) > tempSpecCombatPoints.Sum(x => x.Value))
{
var toRemove = tempAvgCombatPoints.Keys.RandomElement();
//Log.Message("Removed: " + toRemove.LabelShort + " : " + tempSpecCombatPoints[toRemove]);
removedCharacters.Add(toRemove);
tempAvgCombatPoints.Remove(toRemove);
var toRemove = tempAvgCombatPoints?.Keys?.RandomElement();
if (toRemove != null)
{
//Log.Message("Removed: " + toRemove.LabelShort + " : " + tempSpecCombatPoints[toRemove]);
removedCharacters.Add(toRemove);
tempAvgCombatPoints.Remove(toRemove);
}

}
else
{
var toRemove = tempSpecCombatPoints.Keys.RandomElement();
var toRemove = tempSpecCombatPoints?.Keys?.RandomElement();
//Log.Message("Removed: " + toRemove.LabelShort + " : " + tempSpecCombatPoints[toRemove]);
removedCharacters.Add(toRemove);
tempSpecCombatPoints.Remove(toRemove);
if (toRemove != null)
{
removedCharacters.Add(toRemove);
tempSpecCombatPoints.Remove(toRemove);
}

}
}
}
avgCombatPoints = tempAvgCombatPoints;
specCombatPoints = tempSpecCombatPoints;

// Log.Message("------------");
// Log.Message("Final Report");
// Log.Message("------------");
Expand All @@ -172,7 +187,8 @@ public static void GeneratePawns_PostFix(PawnGroupMakerParms parms, PawnGroupMak
});
foreach (var x in removedCharacters)
{
if (x.TryGetComp<CompAbilityUser>() is CompAbilityUser cu && cu.CombatPoints() > 0) cu.DisableAbilityUser();
if (x.TryGetComp<CompAbilityUser>() is CompAbilityUser cu && cu.CombatPoints() > 0)
cu.DisableAbilityUser();
else x.DestroyOrPassToWorld();
}
removedCharacters.Clear();
Expand Down
5 changes: 5 additions & 0 deletions Source/AllModdingComponents/CompOverlays/CompOverlays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public override void PostDraw()
{
var o = Props.overlays[i];
var vec3 = drawPos + o.offset;
if (o.usesStuff)
{
o.graphicData.GraphicColoredFor(this.parent).Draw(vec3, parent.Rotation, parent, 0f);
continue;
}
o.graphicData.Graphic.Draw(vec3, parent.Rotation, parent, 0f);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ namespace CompOverlays
public class GraphicOverlay
{
public GraphicData graphicData;

public bool usesStuff = false;
public Vector3 offset = Vector3.zero;

}

public class CompProperties_Overlays : CompProperties
Expand Down

0 comments on commit a7d2752

Please sign in to comment.