Trying to do a few things

Started by Hammerhead, January 13, 2017, 07:15:51 PM

Previous topic - Next topic

Hammerhead

So, in the race xml files, there is a parameter called "baseBodySize." It is my understanding that this parameter controls several things, including carrying capacity, filth rate, and optimal meat returns on slaughter. I was wondering if there were a way to control these things individually, so that a creature could be made which generates a lot of filth but isn't very large, or has a large carrying capacity but also is very clean.

Also, I'm thinking about making a creature which explodes on death, like a boomalope, but which does so after about a one hour delay. What would be involved in making this happen?

Last, supposing I wanted to make a creature which is hermaphroditic, or which reproduces through mitosis. Could this be achieved purely through xml files?

RawCode

well, popular question, i will explain a bit more:

1) Each thing including pawns instead of shallow or deep copy of thingdef, store reference to singular thingdef stored inside database.
Altering any data "by reference" cause global modification and alter stats of all pawns of same type, forever, ever saving and loading won't fix, loading other savegame will keep modifications to database also.
2) When code ask for some data, there is no caching or buffering of any kind, pawn return reference to his thingdef no more no less.
3) If you want some specific value to be pawn related, two issues araise, first issue is callchain that must be altered to provide support of custom per pawn values, it's can be done with code injection.
But still painful, some routines ask pawn for thingdef and then required data directly from thingdef, in worst cases read fields directly.
It's possible to perform code injection into accessor, but hooking field IO is complicated task, mostly because all such actions are jitted into mov eax,ds:offsetoffield that cannot be hooked by itself.
Hooking large number of internal routines is possible but very hard to support.

Second issue is loading and saving of custom data, due to complexity of saving and loading routine, it's royal pain.

For this reason, if you want "custom versions" of some pawns, you will need to create (or generate at runtime) "fatmuffalo,redmuffalo,slimmuffalo" and so on, it will take less time and there is no risk of suicide after game update.

Hammerhead

Oh, perhaps I should have actually stated what I'm trying to do overall.

I'm attempting to make a mod which adds a few species to the game. Giant snails and a kind of giant cobra that breathes fire, for example.  ;D

I'm still learning all the ins and outs of Rimworld's xml file structure, and so I'm not certain where the xml stops and the C# takes over. I'm still learning C# on the side, so I'd like to avoid getting into the nitty gritty of that for the time being, if possible.

So, to clarify, I'm trying to make a pawn type, specifically the giant snails, generate a very large amount of filth, but I also don't want to give stupendous amounts of leather or meat. Is this possible without getting into C#? If so, how?

Same with the other two options. I want to make an entire type of pawn which, should one of them die, an hour timer begins, and then the corpse explodes (The reason for this is because the explosion will be very large, and I want to give nearby pawns a chance to escape). I was also curious as to whether the female/male dichotomy of pawns is in the C# or the xml.

Also, while I'm here, would it be possible to have a type of pawn which lowers the temperature in the cells close to it by a few degrees?

Hammerhead

Bumping this thread, because I really could use the information.

I have about half of the pawns designed, with art and everything. It's just the specifics bits I stated above that are unfinished.

genet13

Filth definitions are in:
Mods/core/Defs/ThingDefs_Misc/Filth_Various.xml

Insect definitions are in:
Mods/core/Defs/ThingDefs_Races/Races_Animal_Insect.xml

The base animal definition is in:
Mods/core/Defs/ThingDefs_Races/Races_Animal_Base.xml

You want to make a filth-leaving snail that wanders around in the open. Your best bet is to make your custom xml file and copy in an animal that's similar to what you want. Change the texture paths in the file. Add any desired characteristics from other critters that you like. I would look at deer for an example animal that wanders around in the open, and at insects as examples of filth-leaving animals.

I cannot tell exactly what makes insects generate their fluid spatters. If I find it later I'll update. But hopefully this gets you started.

monkhouse

You can set <LeatherAmount> and <MeatAmount> in the <statBases> part of the animal thingdef, if that helps. Control of the filth rate itself seems to be secreted away in the arcane world of bool and curly brackets, so other than changing the body size or wildness I don't think there's much way to control it. You could give your snail its own type of filth tho, and make it uglier or dirtier or harder to clean.

The rest of the stuff seems a bit impossible, tbh, at least from what I know (which isn't much). Temperature control seems strictly linked to buildings, and once things are dead there's not much you can make them do. Asexual reproduction, maybe? You could give the creature its own thinktree to stop it trying to mate, and make it pregnant anyway with a hediff. Tho I'm not sure how you could apply it at appropriate times. Birthday hediffgiver, maybe? Maybe.

In general, I've found it's best to look at what the xmls do first, then think about what's possible. You'll run into a lot of brick walls coming at it from the other direction. I know I have ;)

Hammerhead

genect13: I already have made most of the .xml files as well. I had to make custom body parts for the snail shell, the 'foot,' snail lung/kidney (snails only have one of each), and the eye-tentacles, as well as a Body xml to fit it all together correctly (since no insect in the game is put together in the same way as a snail), but yeah, all of that is done. Also, it's my understanding that all animals leave filth, except for those that don't spawn in the wild at all.

I found that, at the top of Races_Animal_Insect, there is a little part which gives them insect blood. Maybe that will help?

monkhouse: Well, filth rate is apparently proportional to body size (at least, it's listed as an update from a12 here) so if I can control meat amount and leather amount separately from body size, then I can just get body size really high and get the same effect, right?

Also, I had the idea of giving the animal a status effect which ticks up towards 100% over the course of an hour upon their death, triggering the explosion when it reaches 100%. Would this not work because the creature is dead?

Also, too bad on the temperature control. I guess I'll have to hold back on the Yeti until I have a firmer grasp on C#.

genet13

I think you could use the the insect blood tag you mentioned, and instead link it to the slime that the snails make. If you made the snails constantly "bleeding" they would generate slime. They'd need some custom element in Hediff_giver so that they would constantly regenerate blood and not bleed out.

Your post-death ticker thing also involves a rate or time measurement and that's not something I know much about unfortunately. I see boomalopes have

          <deathActionWorkerClass>DeathActionWorker_BigExplosion</deathActionWorkerClass>

but I can't find anything that tells me how many ticks there are between death and the explosion.

IEDs have

            <startWickHitPointsPercent>0.2</startWickHitPointsPercent>

but I don't know what would happen if you put that into an animal's xml. It might just blow up after spawning.

genet13

To control the rate of slime generation it looks like you'd need to use C#, with which I cannot help you. See this guy who is trying to make smoke come out of smokestacks:

https://ludeon.com/forums/index.php?topic=8563.0

monkhouse

> Well, filth rate is apparently proportional to body size (at least, it's listed as an update from a12 here) so if I can control meat amount and leather amount separately from body size, then I can just get body size really high and get the same effect, right?

Yeah, should be, although there may be some unexpected side effects from having huge body size other than leather and meat amounts, you'll have to test it.

Here's the bit of the spooky code that seems to correspond:

public static float AnimalFilthChancePerCell(ThingDef def, float bodySize)
{
float num = bodySize * 0.00125f;
return num * (1f - def.race.petness);
}


So increasing bodysize or decreasing petness (which is presumably the inverse of wildness) seem to be the only ways to alter the filth rate without getting into overrides and detours and all of that complex stuff.

Hammerhead

genect13: Do you know if the different potential values for deathActionWorkerClass are defined in another xml file? If they are, I might be able to make a custom one for my purposes. It will take some extra research on my part, but it will give me a place to begin.

monkhouse: I need to attain a coding program that will allow me to sift through the game's code myself. In the meantime, would it be possible to get a quick search of instances of "bodySize" in the code? It would help in predicting potential side effects of a massive body size, I think.

monkhouse

You can use Ilspy to look at the code (use it to open RimWorld\RimWorldWin_Data\Managed\Assembly-CSharp.dll), although all I usually get out of it are feelings of confusion and stupidity. For the xmls the auto-documentation from this thread is a godsend, lets you search through all of the xmls and see what links to what, and which files different tags show up in.

Hammerhead

Bit of an issue: How does one use ILspy? I seem to keep bumping into visual studios with it, instead of the interface I see on the ILspy website.

Also, I've already looked through the auto-documentation. They tell you potential values, and under what tags other tags are used, but I don't believe they tell you the names of the xml files they are located in. (If they do, then tell me where to find this information because I need it.)

Jamestec

Use this version of ILSpy: https://github.com/Zhentar/ILSpy/releases/
Extract and run ILSpy.exe

I also use Notepad++ with it's "Folder as Workspace" function to search through the XML or through saved decompiled C#.