Skip to content

Commit

Permalink
Wounded Combatants
Browse files Browse the repository at this point in the history
and tweaks I should've committed ages ago ;)
  • Loading branch information
Mehni committed Aug 1, 2018
1 parent 854b519 commit f93c99b
Show file tree
Hide file tree
Showing 21 changed files with 489 additions and 137 deletions.
Binary file modified Assemblies/0Harmony.dll
Binary file not shown.
Binary file modified Assemblies/MoreFactionInteraction.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions Defs/IncidentCategoryDef/MFI_IncidentCategoryDef.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>

<!-- Dear translators: there's nothing here to translate. -->
<IncidentCategoryDef>
<defName>MFI_FactionWar</defName>
<needsParmsPoints>true</needsParmsPoints>
</IncidentCategoryDef>

</Defs>
19 changes: 16 additions & 3 deletions Defs/Incidents/Incidents_Map_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<defName>MFI_PirateExtortion</defName>
<label>pirate extortion</label>
<category>Misc</category>
<targetTags>
<li>Map_PlayerHome</li>
</targetTags>
<targetTags>
<li>Map_PlayerHome</li>
</targetTags>
<workerClass>MoreFactionInteraction.IncidentWorker_Extortion</workerClass>
<letterLabel>Pirate fee demand</letterLabel>
<letterDef>ExtortionDemand</letterDef>
Expand All @@ -22,6 +22,19 @@
</chanceFactorByPopulationCurve>
</IncidentDef>

<IncidentDef>
<defName>MFI_WoundedCombatants</defName>
<label>wounded combatants</label>
<category>Misc</category>
<targetTags>
<li>Map_PlayerHome</li>
</targetTags>
<workerClass>MoreFactionInteraction.MoreFactionWar.IncidentWorker_WoundedCombatants</workerClass>
<baseChance>0.5</baseChance>
<minRefireDays>8</minRefireDays>
<earliestDay>30</earliestDay>
</IncidentDef>

<!-- <IncidentDef>
<defName>MFI_WeddingGuestsArrival</defName>
<label>wedding guests arrived</label>
Expand Down
9 changes: 1 addition & 8 deletions Defs/Incidents/Incidents_World_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
<baseChance>0.8</baseChance>
<earliestDay>15</earliestDay>
<minRefireDays>30</minRefireDays>
<chanceFactorByPopulationCurve>
<points>
<li>(1,0)</li>
<li>(5,0)</li>
<li>(12,1)</li>
<li>(20,2)</li>
</points>
</chanceFactorByPopulationCurve>
</IncidentDef>

<IncidentDef>
Expand Down Expand Up @@ -49,6 +41,7 @@
<workerClass>MoreFactionInteraction.World_Incidents.IncidentWorker_HuntersLodge</workerClass>
<letterLabel>Hunter's lodge</letterLabel>
<letterDef>PositiveEvent</letterDef>
<!-- You are invited to {FACTIONNAME}'s {FACTION.DEF.LEADERTITLE} summer retreat. {SITEPARTDEF MFI_HUNTERSLODGEDESCRIPTIONDIALOGUE}. There is an outpost at the site with all the required facilities to make meals, and they've extended their hospitality to you. This offer expires in {AMOUNT} days. -->
<letterText>You are invited to {0}'s {1} summer retreat. {2}. There is an outpost at the site with all the required facilities to make meals, and they've extended their hospitality to you. This offer expires in {3} days.</letterText>
<baseChance>0.8</baseChance>
<earliestDay>15</earliestDay>
Expand Down
1 change: 1 addition & 0 deletions Defs/Incidents/Incidents_World_Quests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
</targetTags>
<workerClass>MoreFactionInteraction.MoreFactionWar.IncidentWorker_FactionPeaceTalks</workerClass>
<letterLabel>Faction unrest</letterLabel>
<!-- Translation notes: leans heavily on PeaceTalks description. {0} = FACTION.DEF.LEADERTITLE {1} = WARRING FACTION NAME {2} = ENEMY IN FACTION WAR FACTION NAME -->
<letterText>You've received a message from [PAWN_nameDef], {0} of {1}. Their faction recently had diplomatic troubles with another faction and call upon you to negotiate between them and {2}. They've picked a neutral nearby location and invite you to come negotiate.\n\nIt could be a great opportunity to improve relations with their faction, but beware - a poor negotiator can cause more harm than good and even anger them.\n\nThe offer will expire after {3} days, after which [PAWN_nameDef] fears the worst.</letterText>
<letterDef>NeutralEvent</letterDef>
<baseChance>0.51</baseChance>
Expand Down
7 changes: 7 additions & 0 deletions Languages/English/Keyed/Incidents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@
<MFI_MysticalShamanFoundNoSickPawn>The Shaman emerges from his polyester teepee just before your caravan announces their presence. He judges your group silently, passing one quivering eye over your decidedly healthy group, the other eye crossed in apparent meditation. Visibly sweating, he orders you to wait a respectable distance while he retreats back in his teepee. Moments later you hear the rustling of fabric and the sound of a muffalo being spurred on.\n\nIt seems the mystical shaman packed up and left.</MFI_MysticalShamanFoundNoSickPawn>
<MFI_MysticalShamanDoesHisMagic>The Shaman seems to have been expecting you, and with great practice regales you the tale of his &quot;healer's hands&quot;. Once finished, he invites {0} into his teepee. There is a brief shake of the screen before {0} re-emerges, feeling much better.</MFI_MysticalShamanDoesHisMagic>

<MFI_WoundedCombatant>A high-ranking military official from {0} sends a distress signal. Multiple of his combatants have sustained serious injuries and require immediate medical attention. They're loaded in a transport pod but the nearest medical outpost is too far away to save the lives of these men and women, so he calls upon you as their ally to help them. Will you respond to his plea for help and nurture his troops back to health?</MFI_WoundedCombatant>
<MFI_WoundedCombatantRejected>It's amazing how well you can hear the commander's expletives over the sound of heavy mortar fire, as he wishes bad things upon your colony and holds you responsible for the death of his men.\n\n Relations with {0} have deteriorated by {1}.</MFI_WoundedCombatantRejected>
<MFI_WoundedCombatantTitle>Ally distress signal at {0}</MFI_WoundedCombatantTitle>
<MFI_WoundedCombatantAmbush>It's a trap! {0}'s enemy has somehow managed to hack your communication and abused it to get ahead in the war. {1}</MFI_WoundedCombatantAmbush>
<MFI_WoundedCombatantGratitude>The commander gives you an earnest and heartfelt salute. It loses a lot of its impact and meaning as you can't see the gesture through the radio, so you hang up.</MFI_WoundedCombatantGratitude>
<MFI_WoundedCombatantAmbushAvoided>You hear a voice in the background yell, asking if &quot;they've taken the bait yet&quot;. You quickly hang up, confused and somewhat relieved you escaped potential disaster.</MFI_WoundedCombatantAmbushAvoided>

</LanguageData>
42 changes: 21 additions & 21 deletions MoreFactionInteraction/General/Dialog_MFIDebugActionMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ protected override void DoListingItems()
DoLabel("Tools - MFI");

base.DebugToolWorld("Spawn pirate base", delegate
{
int tile = GenWorld.MouseTile(false);
{
int tile = GenWorld.MouseTile(false);

if (tile < 0 || Find.World.Impassable(tile))
Messages.Message("Impassable", MessageTypeDefOf.RejectInput, false);
if (tile < 0 || Find.World.Impassable(tile))
Messages.Message("Impassable", MessageTypeDefOf.RejectInput, false);

else
{
Faction faction = (from x in Find.FactionManager.AllFactions
where !x.def.hidden
&& !x.defeated
&& !x.IsPlayer
&& x.HostileTo(other: Faction.OfPlayer)
&& x.def.permanentEnemy
select x).First();
else
{
Faction faction = (from x in Find.FactionManager.AllFactions
where !x.def.hidden
&& !x.defeated
&& !x.IsPlayer
&& x.HostileTo(other: Faction.OfPlayer)
&& x.def.permanentEnemy
select x).First();

Settlement factionBase = (Settlement) WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.Settlement);
factionBase.SetFaction(newFaction: faction);
factionBase.Tile = tile;
factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase: factionBase);
Find.WorldObjects.Add(o: factionBase);
}
}
);
Settlement factionBase = (Settlement) WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.Settlement);
factionBase.SetFaction(newFaction: faction);
factionBase.Tile = tile;
factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase: factionBase);
Find.WorldObjects.Add(o: factionBase);
}
}
);
}
}
}
Expand Down
102 changes: 70 additions & 32 deletions MoreFactionInteraction/General/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
using UnityEngine;
using RimWorld.Planet;
using System.Reflection;
using System.Reflection.Emit;

namespace MoreFactionInteraction
{
using System.Reflection.Emit;

[StaticConstructorOnStartup]
public static class HarmonyPatches
{
Expand All @@ -32,47 +31,70 @@ static HarmonyPatches()

harmony.Patch(original: AccessTools.Method(type: typeof(ThingSetMaker), name: nameof(ThingSetMaker.Generate), parameters: new Type[] { typeof(ThingSetMakerParams) }), prefix: null,
postfix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(TraderStocker_OverStockerPostFix)));
#endregion

#region WorldIncidents
harmony.Patch(original: AccessTools.Method(type: typeof(SettlementBase), name: nameof(SettlementBase.GetCaravanGizmos)), prefix: null,
harmony.Patch(original: AccessTools.Method(type: typeof(Tradeable), name: "InitPriceDataIfNeeded"), prefix: null, postfix: null,
transpiler: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(ErrorSuppressionSssh)));

#endregion

#region WorldIncidents
harmony.Patch(original: AccessTools.Method(type: typeof(SettlementBase), name: nameof(SettlementBase.GetCaravanGizmos)), prefix: null,
postfix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(SettlementBase_CaravanGizmos_Postfix)));

harmony.Patch(original: AccessTools.Method(type: typeof(WorldReachabilityUtility), name: nameof(WorldReachabilityUtility.CanReach)), prefix: null,
postfix: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(WorldReachUtility_PostFix)));
#endregion

//harmony.Patch(original: AccessTools.Method(type: typeof(DebugWindowsOpener), name: "ToggleDebugActionsMenu"), prefix: null, postfix: null,
// transpiler: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(DebugWindowsOpener_ToggleDebugActionsMenu_Patch)));
harmony.Patch(original: AccessTools.Method(type: typeof(DebugWindowsOpener), name: "ToggleDebugActionsMenu"), prefix: null, postfix: null,
transpiler: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(DebugWindowsOpener_ToggleDebugActionsMenu_Patch)));

harmony.Patch(original: AccessTools.Method(type: typeof(Tradeable), name: "InitPriceDataIfNeeded"), prefix: null, postfix: null,
transpiler: new HarmonyMethod(type: typeof(HarmonyPatches), name: nameof(ErrorSuppressionSssh)));
}

private static IEnumerable<CodeInstruction> ErrorSuppressionSssh(IEnumerable<CodeInstruction> instructions)
//[HarmonyPatch]
//public static class MyPatch
//{
// public static MethodInfo match = typeof(Plant).GetMethod("YieldNow");
// public static MethodInfo replaceWith = typeof(MyPatch).GetMethod("YieldNowPatch");
// public static MethodInfo TargetMethod()
// {
// Type mainType = typeof(JobDriver_PlantWork);
// Log.Message("TargetMethod: Main Type Found");
// Type iteratorType = mainType.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Instance).First(t => t.FullName.Contains("c_Iterator"));
// Log.Message("TargetMethod: Iterator Type Resolved");
// Type anonStoreyType = iteratorType.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Instance).First(t => t.FullName.Contains("c_AnonStorey"));
// Log.Message("TargetMethod: AnonStorey Type Resolved");
// return anonStoreyType.GetMethods().First(m => m.ReturnType == typeof(void));
// }
// public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instr)
// {
// foreach (CodeInstruction i in instr)
// {
// if (i.operand == match)
// {
// Log.Message("Instruction insertion complete!");
// yield return new CodeInstruction(OpCodes.Ldloc_0);
// yield return new CodeInstruction(OpCodes.Call, replaceWith);
// }
// else
// {
// yield return i;
// }
// }
// }
// public static int YieldNowPatch(Plant p, Pawn actor)
// {
// return GenMath.RoundRandom(p.YieldNow() * actor.GetStatValue(StatDefOf.PlantHarvestYield, true)); // Whatever you want to do here
// }
//}

//thx Brrainz
private static IEnumerable<CodeInstruction> DebugWindowsOpener_ToggleDebugActionsMenu_Patch(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> instructionList = instructions.ToList();
for (int i = 0; i < instructionList.Count; i++)
{
if (instructionList[i].opcode == OpCodes.Ldstr)
{
for (int j = 0; j < 7; j++)
{
instructionList[i + j].opcode = OpCodes.Nop;
}
}
yield return instructionList[i];
}
ConstructorInfo from = AccessTools.Constructor(type: typeof(Dialog_DebugActionsMenu));
ConstructorInfo to = AccessTools.Constructor(type: typeof(Dialog_MFIDebugActionMenu));
return instructions.MethodReplacer(from: from, to: to);
}

////thx Brrainz
//private static IEnumerable<CodeInstruction> DebugWindowsOpener_ToggleDebugActionsMenu_Patch(IEnumerable<CodeInstruction> instructions)
//{
// ConstructorInfo from = AccessTools.Constructor(type: typeof(Dialog_DebugActionsMenu));
// ConstructorInfo to = AccessTools.Constructor(type: typeof(Dialog_MFIDebugActionMenu));
// return instructions.MethodReplacer(from: from, to: to);
//}

#region MoreTraders
private static void TraderStocker_OverStockerPostFix(ref List<Thing> __result, ref ThingSetMakerParams parms)
{
Expand Down Expand Up @@ -157,8 +179,24 @@ private static QualityCategory FactionAndGoodWillDependantQuality(Faction factio
return QualityUtility.GenerateQualityTraderItem();
}

#region SimpleCurves
private static readonly SimpleCurve WealthQualityDeterminationCurve = new SimpleCurve
private static IEnumerable<CodeInstruction> ErrorSuppressionSssh(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> instructionList = instructions.ToList();
for (int i = 0; i < instructionList.Count; i++)
{
if (instructionList[i].opcode == OpCodes.Ldstr)
{
for (int j = 0; j < 7; j++)
{
instructionList[i + j].opcode = OpCodes.Nop;
}
}
yield return instructionList[i];
}
}

#region SimpleCurves
private static readonly SimpleCurve WealthQualityDeterminationCurve = new SimpleCurve
{
new CurvePoint(x: 0, y: 1),
new CurvePoint(x: 10000, y: 1.5f),
Expand Down
6 changes: 6 additions & 0 deletions MoreFactionInteraction/General/MFI_Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ public static Faction EnemyInFactionWar(this Faction faction)
//
// which is a nested ternary and just awful to read. Be happy I spared you.
}

public static bool IsPartOfFactionWar(this Faction faction)
{
return faction == Find.World.GetComponent<WorldComponent_MFI_FactionWar>().WarringFactionOne ||
faction == Find.World.GetComponent<WorldComponent_MFI_FactionWar>().WarringFactionTwo;
}
}
}
Loading

0 comments on commit f93c99b

Please sign in to comment.