first mod. how to change a stat of a thing through a researchprogect?

Started by toric, December 10, 2015, 02:07:29 PM

Previous topic - Next topic

toric

essentially, i want to add a research that will change one stat or another of a certain thing upon completion. I've been looking through the files, specifically at the nutrient paste dispenser and the gun turret, to try to figure out how to do this. the nutrient paste dispenser, nor its research has nothing that seems like it would decrease the amount of food needed for a nutrient paste meal. in gun turret cooling, the only thing i could find was  <specialAction>ResearchModsSpecial.GunTurretCooling</specialAction> in the researchedef, and i could not find where it pointed to. any help?

Fluffy (l2032)

You can't really do this with XML only, the specialAction points to a C# 'worker' method that is executed once the project is complete, and makes some changes. In this case, it changes the first and only verb on the turret def;

public static void GunTurretCooling()
{
(from x in DefDatabase<ThingDef>.GetNamed("Gun_TurretImprovised", true).Verbs
where x.isPrimary
select x).First<VerbProperties>().burstShotCount = 4;
}


As for the nutrient paste dispenser, I suspect a check for the research might be hardcoded - the entire nutrientpaste dispenser is a hardcoded modding nightmare.

I would say messing with C# is not a great idea for a first mod, but it depends a bit on how familiar you are with programming. Making changes to defs like this is fairly simple as well.

toric

ok. ill have to find something else. i know basic java stuff, but I've never done c#. i suspected that there was something somewhere that changed the burstshotcount verb int he def, but could not for the life of me find it. i was intending to make a research that removed the beauty penalty from conduits, (think running them under the floor or on the ceiling) but if its not doable with xml, probably won't do it until i learn more. however, consider this a mod request, if tynan sees this, to be able to change xml stats with research. (imagine getting research that made the hydroponics grow faster, or increased the output of solar panels, or coolers use less power, etc. would really open the door in terms of research, IMO)

Fluffy (l2032)

If you know java, C# should look familiar. I have trouble distinguishing source code from the two sometimes when looking for unity examples (unity has C# and/or java scripting, examples are given in one or both, and not always clearly marked.)

Compiling a C# dll really is fairly simple, get Visual Studio (the community edition is plenty good enough and free) or something like monodevelop (I only have experience with VS). There's a few tricks to setting things up right (references, build targets, etc.) but thats all described in the wiki. The actual code for changing a def really is fairly easy, and almost a carbon copy of the above example for turrets.

As for allowing to do this from XML, it'd be a fairly massive amount of code to provide this functionality, I'd say it's easier to do it with a small C# worker that just does what you want. All your examples are pretty much one-liner pieces of code, following the same template.

Finally, don't give up so easily! :D

toric

wasn't planning on giving up, just thinking about doing something purely xml for a first mod. as for changing it via xml, i was just thinking maybe you could define a new thingdef within the research, with properties inherited from the old thingdef. would probably still take a lot of code, though.

are there any editors out there that are for mac/linux? text wangler will probably work, but what about compiling? also, is it possible to decompile a dll to look at what other modders have done?

Fluffy (l2032)

I only really use linux for work (Fortran), but I'm told MonoDevelop works on win/mac/linux. Decompiling is also definitely possible, I personally use ILSpy for searching the entire code base, and the in-IDE decompiler that ReSharper adds for quick references. Again, not sure what is available for linux/mac, but a quick google search should help you there.

95% of the code can be decompiled without issue, the major exception being Enumerator blocks, which turn into a bit of a mess (but can usually still be deconstructed manually.)

milon

Toric, you might be able to accomplish your mod via XML in a roundabout way. Instead of the research changing a stat, you could have two things defined that are the same except for the stat and the name (ie. Basic Thing and Advanced Thing). Then just have the research as a prerequisite for unlocking the advanced thing.

Fluffy (l2032)

Quote from: milon on December 12, 2015, 06:41:41 AM
Toric, you might be able to accomplish your mod via XML in a roundabout way. Instead of the research changing a stat, you could have two things defined that are the same except for the stat and the name (ie. Basic Thing and Advanced Thing). Then just have the research as a prerequisite for unlocking the advanced thing.
That won't upgrade existing things though, you'ld have to create new ones. But yeah, that'd work.

toric

yup. already a mod that does that. i think ill be learning some c# just for it.

Fluffy (l2032)

Happy hunting!

Some pointers in setting the environment up right that I ran into on my first mods (and sometimes still do);
- disable debug files (.dbg), they crash rimworld. If you get unexplained crashes on boot, check your assemblies folder and delete all the junk.
- disable local copies of the references (i.e. the rimworld and unity .dll's). If you don't, they get put in your mods assembly folder, and the game loads the assemblies twice, leading to some weirdness.
- make sure to set the target to version 3.5