Ludeon Forums

RimWorld => Mods => Help => Topic started by: thewho666 on May 04, 2021, 10:58:15 AM

Title: Stop/nerf insect digging speed
Post by: thewho666 on May 04, 2021, 10:58:15 AM
Hello everyone!
I'd like to slow down the insane speed that the insects mine with. I'm currently doing a prison labor playthrough with only two colonists and I don't even have time to react before my "insect protection system" breaks through my walls..
I'm not here to discuss how I should play so please stick to the topic of writing mods  :)
Soo, I've not written any mods or programmed anything like this before, but I poked around a bit and think I got the basics.

My first thought was to change the "mining speed" of the insects, but they do not "mine" do they? So changing the attack stats would make them almost harmless?
So my second idea was to change their "AI" so that their chance of attacking/mining rock/walls etc. is much lower.
But my veery limited knowledge says that this can't be done through a simple xml mod?

So is this something a beginner like me could do?
I tried searching for similar topics but could not find anything directly helpful 🤔

Plan B is to try adding doors to this mod 😅
https://steamcommunity.com/sharedfiles/filedetails/?id=2422894878
Title: Re: Stop/nerf insect digging speed
Post by: m1st4x on May 04, 2021, 11:28:53 AM
Grab a tool like ILSpy or JetBrains dot peek
Then open Rimworlds main library
<path-to-the-rim>\RimWorldWin64_Data\Managed\Assembly-CSharp.dll
and search for 'insect'. You'll find a class named
ThinkNode_ChancePerHour_InsectDigChance
To change the default behavior you have patch the method inside.
See https://harmony.pardeike.net/articles/patching.html

If you're able to understand code (in c#) you can do it  ;)
Title: Re: Stop/nerf insect digging speed
Post by: thewho666 on May 05, 2021, 06:11:39 AM
Thanks for helping me 👍
I found it and sort of understand what's happening.
The insects dig more often if the room is smaller?

public class ThinkNode_ChancePerHour_InsectDigChance : ThinkNode_ChancePerHour
{
private const float BaseMtbHours = 18f;

protected override float MtbHours(Pawn pawn)
{
Room room = pawn.GetRoom();
if (room == null)
{
return 18f;
}
int num = (room.IsHuge ? 9999 : room.CellCount);
float num2 = GenMath.LerpDoubleClamped(2f, 25f, 6f, 1f, num);
return 18f / num2;
}
}


So maybe this would work?
48h between "digs" regardless of the roomsize?

public class ThinkNode_ChancePerHour_InsectDigChance : ThinkNode_ChancePerHour
{
private const float BaseMtbHours = 18f;

protected override float MtbHours(Pawn pawn)
{
return 48f;
}
}


I also read through the harmony patching instructions but it seems way to advanced for the amount of free time I have at the moment.
Maybe I'll try to add doors to the mod I linked in the first post instead.
Title: Re: Stop/nerf insect digging speed
Post by: m1st4x on May 05, 2021, 07:04:12 AM
Yes, depending on your computer skills, it may be advanced and time consuming...
But in theory: Go and look after mods that do patching - a lot of them do; source code and project files are often included (Visual Studio).
Open it - try to understand what's going on - and adapt it to your needs.