Stop/nerf insect digging speed

Started by thewho666, May 04, 2021, 10:58:15 AM

Previous topic - Next topic

thewho666

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

m1st4x

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  ;)

thewho666

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.

m1st4x

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.