Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Large update, adding a timer to camps and abandoned camps blocking the tile after leaving. Configurable. Also camps now generate a new seed when being created, meaning you won't always get the same map anymore.
  • Loading branch information
Syrchalis authored Aug 12, 2018
1 parent c0901e1 commit 89cf1de
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 161 deletions.
15 changes: 15 additions & 0 deletions About.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetaData>
<name>[SYR] Set Up Camp</name>
<author>Syrchalis</author>
<url>https://ludeon.com/forums/index.php?topic=43172.0</url>
<targetVersion>0.19.1987</targetVersion>
<description>Set up camp, once again! For all your caravan managing needs, you can now set up camp anywhere. You can customize the possible size of the map, the duration you are allowed to stay, the time the tile is blocked after abandoning a camp and turn events on the camp map on/off.

It is recommended to use settings close to the default and not turn the map timer or the tile blocking off, as this makes the mod severely game-breaking in terms of balance. However, what you do is your choice - the option to turn these settings off is there for a reason.

Originally by Nandonalt
Re-coded and improved by Syrchalis
Assistance provided by spd, potatoclip</description>

</ModMetaData>
Binary file modified About/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assemblies/SetUpCamp.dll
Binary file not shown.
12 changes: 12 additions & 0 deletions Defs/WorldObjectDefs/WorldObjects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@
<expandingIconPriority>8</expandingIconPriority>
<comps>
<li Class="WorldObjectCompProperties_FormCaravan" />
<li Class="WorldObjectCompProperties_TimedForcedExit" />
<li Class="WorldObjectCompProperties_EnterCooldown" />
</comps>
<IncidentTargetTags>
</IncidentTargetTags>
</WorldObjectDef>

<WorldObjectDef>
<defName>AbandonedCamp</defName>
<label>abandoned camp</label>
<description>An abandoned camp.</description>
<texture>World/WorldObjects/Camp</texture>
<comps>
<li Class="WorldObjectCompProperties_Timeout" />
</comps>
</WorldObjectDef>


</Defs>
10 changes: 9 additions & 1 deletion Languages/English/Keyed/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
<SetUpCampDesc>Set up a camp, enabling you to forage, mine and hunt as well as reorganize your caravan.</SetUpCampDesc>
<SetUpCampFormedCamp>The caravan successfully set up a camp.</SetUpCampFormedCamp>
<SetUpCampSettingsCategoryLabel>Set Up Camp</SetUpCampSettingsCategoryLabel>
<SetUpCampSettingMapSize>Camp map size range</SetUpCampSettingMapSize>
<SetUpCampSettingMapSize>Camp map size range (Default: 75-125)</SetUpCampSettingMapSize>
<SetUpCampSettingsMapTimerDays>Camp leaving timer (Default: 5)</SetUpCampSettingsMapTimerDays>
<SetUpCampSettingsMapTimerDaysTooltip>Days until caravan is forced to leave camp</SetUpCampSettingsMapTimerDaysTooltip>
<SetUpCampSettingsTimeout>Abandoned camp vanish timer (Default: 60)</SetUpCampSettingsTimeout>
<SetUpCampSettingsTimeoutTooltip>Days until abandoned camps vanish (15-120)</SetUpCampSettingsTimeoutTooltip>
<SetUpCampSettingMinCampSize>Minimum size for camps</SetUpCampSettingMinCampSize>
<SetUpCampSettingMaxCampSize>Maximum size for camps</SetUpCampSettingMaxCampSize>
<SetUpCampSettingsPermanentCamps>Enable permanent camps (disabling this will permanently delete all empty camps currently on the map)</SetUpCampSettingsPermanentCamps>
<SetUpCampSettingsHomeEvents>Enable "normal map" events on camps</SetUpCampSettingsHomeEvents>
<SetUpCampSettingsCaravanEvents>Enable "caravan" events on camps</SetUpCampSettingsCaravanEvents>
<SetUpCampDestroyCamp>Abandon camp</SetUpCampDestroyCamp>
<SetUpCampDestroyCampDesc>Abandons this camp permanently.</SetUpCampDestroyCampDesc>
<SetUpCampAbandonDialogue>Are you sure you wish to permanently and irreversibly destroy this camp?</SetUpCampAbandonDialogue>
<SetUpCampAbandoned>Camp abandoned.</SetUpCampAbandoned>
<SetUpCampStillInUse>There are still colonists in the camp. You must form a caravan before abandoning the camp.</SetUpCampStillInUse>
<SetUpCampOccupied>You need to wait before setting up a camp at the same spot.</SetUpCampOccupied>



</LanguageData>
44 changes: 42 additions & 2 deletions Source/SetupCamp/CaravanCamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,35 @@ public override void ExposeData()
base.ExposeData();
}

public override void Tick()
{
base.Tick();
if (HasMap)
{
CheckStartForceExitAndRemoveMapCountdown();
}
}

private bool startedCountdown;
public float forceExitAndRemoveMapCountdownDurationDays = SetUpCampSettings.mapTimerDays;
private void CheckStartForceExitAndRemoveMapCountdown()
{
if (!startedCountdown && SetUpCampSettings.mapTimerDays != SetUpCampSettings.mapTimerDaysmin && SetUpCampSettings.mapTimerDays != SetUpCampSettings.mapTimerDaysmax)
{
if (!GenHostility.AnyHostileActiveThreatToPlayer(Map))
{
startedCountdown = true;
int num = Mathf.RoundToInt(forceExitAndRemoveMapCountdownDurationDays * 60000f);
string text = "MessageSiteCountdownBecauseNoEnemiesInitially".Translate(new object[]
{
TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(num)
});
Messages.Message(text, this, MessageTypeDefOf.PositiveEvent, true);
GetComponent<TimedForcedExit>().StartForceExitAndRemoveMapCountdown(num);
}
}
}
public bool shouldBeDeleted = false;
public override bool ShouldRemoveMapNow(out bool alsoRemoveWorldObject)
{
bool result;
Expand All @@ -30,6 +59,10 @@ public override bool ShouldRemoveMapNow(out bool alsoRemoveWorldObject)
{
alsoRemoveWorldObject = true;
result = true;
if (SetUpCampSettings.timeout != SetUpCampSettings.timeoutmin && SetUpCampSettings.timeout != SetUpCampSettings.timeoutmax)
{
AddAbandonedCamp(this);
}
}
}
else
Expand All @@ -40,6 +73,15 @@ public override bool ShouldRemoveMapNow(out bool alsoRemoveWorldObject)
return result;
}

private static void AddAbandonedCamp(CaravanCamp Camp)
{
WorldObject worldObject = WorldObjectMaker.MakeWorldObject(SetUpCampDefOf.AbandonedCamp);
worldObject.GetComponent<TimeoutComp>().StartTimeout(SetUpCampSettings.timeout * 60000);
worldObject.Tile = Camp.Tile;
worldObject.SetFaction(Camp.Faction);
Find.WorldObjects.Add(worldObject);
}

public override IEnumerable<Gizmo> GetGizmos()
{
SetUpCampSettings settings = LoadedModManager.GetMod<SetUpCamp>().GetSettings<SetUpCampSettings>();
Expand Down Expand Up @@ -80,7 +122,5 @@ public override IEnumerable<Gizmo> GetGizmos()
}
yield break;
}

public bool shouldBeDeleted = false;
}
}
25 changes: 25 additions & 0 deletions Source/SetupCamp/DefOfs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Harmony;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
using System.Reflection;
using RimWorld.Planet;
using Verse.Sound;
using UnityEngine;

namespace Syrchalis_SetUpCamp
{
[DefOf]
public static class SetUpCampDefOf
{
static SetUpCampDefOf()
{
DefOfHelper.EnsureInitializedInCtor(typeof(SetUpCampDefOf));
}
public static WorldObjectDef CaravanCamp;
public static WorldObjectDef AbandonedCamp;
}
}
150 changes: 8 additions & 142 deletions Source/SetupCamp/ModSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public class SetUpCampSettings : ModSettings
{
private const int MinSizeDefault = 75;
private const int MaxSizeDefault = 125;
public static int mapTimerDays = 7;
public static int mapTimerDaysmin = 0;
public static int mapTimerDaysmax = 31;
public static int timeout = 60;
public static int timeoutmin = 0;
public static int timeoutmax = 181;
public static bool permanentCamps = false;
public static bool homeEvents = false;
public static bool caravanEvents = false;
Expand All @@ -25,151 +31,11 @@ public override void ExposeData()
{
base.ExposeData();
Scribe_Values.Look<IntRange>(ref allowedSizeRange, "allowedSizeRange", new IntRange(75, 125), true);
Scribe_Values.Look<int>(ref mapTimerDays, "mapTimerDays", 7, true);
Scribe_Values.Look<int>(ref timeout, "Timeout", 60, true);
Scribe_Values.Look<bool>(ref permanentCamps, "permanentCamps", false, true);
Scribe_Values.Look<bool>(ref homeEvents, "homeEvents", false, true);
Scribe_Values.Look<bool>(ref caravanEvents, "caravanEvents", false, true);
}
}

[DefOf]
public static class SetUpCampDefOf
{
static SetUpCampDefOf()
{
DefOfHelper.EnsureInitializedInCtor(typeof(SetUpCampDefOf));
}
public static WorldObjectDef CaravanCamp;
}

public class SetUpCamp : Mod
{
public static SetUpCampSettings settings;

public SetUpCamp(ModContentPack content) : base(content)
{
settings = GetSettings<SetUpCampSettings>();
var harmony = HarmonyInstance.Create("Syrchalis.Rimworld.SetUpCamp");
MethodInfo method = typeof(Caravan).GetMethod("GetGizmos");
HarmonyMethod prefix = null;
HarmonyMethod postfix = new HarmonyMethod(typeof(SetUpCamp).GetMethod("GetGizmosPostfix")); ;
harmony.Patch(method, prefix, postfix, null);
#if DEBUG
Log.Message("[SetUpCamp] loaded...");
#endif
}

public override string SettingsCategory() => "SetUpCampSettingsCategoryLabel".Translate();

public override void DoSettingsWindowContents(Rect inRect)
{
Listing_Standard listing_Standard = new Listing_Standard();
listing_Standard.Begin(inRect);
listing_Standard.Label("SetUpCampSettingMapSize".Translate());
listing_Standard.IntRange(ref SetUpCampSettings.allowedSizeRange, 50, 300);
listing_Standard.AddLabeledCheckbox("SetUpCampSettingsPermanentCamps".Translate() + ": ", ref SetUpCampSettings.permanentCamps);
listing_Standard.AddLabeledCheckbox("SetUpCampSettingsHomeEvents".Translate() + ": ", ref SetUpCampSettings.homeEvents);
listing_Standard.AddLabeledCheckbox("SetUpCampSettingsCaravanEvents".Translate() + ": ", ref SetUpCampSettings.caravanEvents);
listing_Standard.End();
settings.Write();
}

public static void ApplySettings()
{
if (SetUpCampSettings.homeEvents)
{
SetUpCampDefOf.CaravanCamp.IncidentTargetTags.Add(IncidentTargetTagDefOf.Map_PlayerHome);
}
else
{
SetUpCampDefOf.CaravanCamp.IncidentTargetTags.Remove(IncidentTargetTagDefOf.Map_PlayerHome);
}
if (SetUpCampSettings.caravanEvents)
{
SetUpCampDefOf.CaravanCamp.IncidentTargetTags.Add(IncidentTargetTagDefOf.Caravan);
}
else
{
SetUpCampDefOf.CaravanCamp.IncidentTargetTags.Remove(IncidentTargetTagDefOf.Caravan);
}
SetUpCampDefOf.CaravanCamp.ResolveReferences();
}

public override void WriteSettings()
{
base.WriteSettings();
ApplySettings();
}

public static void GetGizmosPostfix(ref IEnumerable<Gizmo> __result, Caravan __instance)
{
__result = __result.Concat(new Gizmo[] { SetUpCampCommand(__instance) });
ApplySettings();
}

private static StringBuilder tmpSettleFailReason = new StringBuilder();
public static Command SetUpCampCommand(Caravan caravan)
{
Command_Action command_Action = new Command_Action();
command_Action.defaultLabel = "SetUpCamp".Translate();
command_Action.defaultDesc = "SetUpCampDesc".Translate();
command_Action.icon = ContentFinder<Texture2D>.Get("UI/Commands/SetUpCamp", true);
command_Action.action = delegate ()
{
SoundStarter.PlayOneShotOnCamera(SoundDefOf.Tick_High, null);
Camp(caravan);
};

if (!TileFinder.IsValidTileForNewSettlement(caravan.Tile, tmpSettleFailReason))
{
command_Action.Disable(tmpSettleFailReason.ToString());
}
return command_Action;
}

private static List<Pawn> tmpCaravanPawns = new List<Pawn>();
public static void Camp(Caravan caravan)
{
float PawnScore = CaravanPawnsCountScore(caravan);
//int num2 = Mathf.RoundToInt(PawnScore * 900f);
int CampSize = new System.Random().Next(SetUpCampSettings.allowedSizeRange.min, SetUpCampSettings.allowedSizeRange.max);
//float num4 = Mathf.Max(PawnScore * EnemyPointsPerCaravanPawnsScoreRange.RandomInRange, 45f);
Pawn pawn = caravan.PawnsListForReading[0];
tmpCaravanPawns.Clear();
tmpCaravanPawns.AddRange(caravan.PawnsListForReading);
Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(caravan, new IntVec3(CampSize, 1, CampSize), DefDatabase<WorldObjectDef>.GetNamed("CaravanCamp", true));
MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out IntVec3 playerStartingSpot, out IntVec3 intVec);
CaravanEnterMapUtility.Enter(caravan, map, (Pawn x) => CellFinder.RandomSpawnCellForPawnNear(playerStartingSpot, map, 4), 0, true);
tmpCaravanPawns.Clear();
CameraJumper.TryJumpAndSelect(pawn);
Find.TickManager.CurTimeSpeed = 0;
Messages.Message("SetUpCampFormedCamp".Translate(), MessageTypeDefOf.PositiveEvent);
}

private static float CaravanPawnsCountScore(Caravan caravan)
{
float num = 0f;
List<Pawn> pawnsListForReading = caravan.PawnsListForReading;
for (int i = 0; i < pawnsListForReading.Count; i++)
{
bool isColonist = pawnsListForReading[i].IsColonist;
if (isColonist)
{
num += (pawnsListForReading[i].Downed ? 0.35f : 1f);
}
else
{
bool humanlike = pawnsListForReading[i].RaceProps.Humanlike;
if (humanlike)
{
num += 0.35f;
}
else
{
num += 0.2f * pawnsListForReading[i].BodySize;
}
}
}
return num;
}
}
}
Loading

0 comments on commit 89cf1de

Please sign in to comment.