Help with terrain and Community Library

Started by hoochy, April 18, 2016, 08:38:43 AM

Previous topic - Next topic

hoochy

Hi everyone, I am basically just after some details which will speed up my mod development. Basically I want a callback to be called after the map has been created. I then want to store some extra info for each tile on the map that I will use for a production building and maybe a task. I also want to add some extra "ground" types. So any info you can give to speed up my learning process on that would be fantastic! :)

Is it best to just override the relevant functions as I find them and then call the base one, or is there a better way to do this with the community library? I'm assuming there is some issue with order of loading and hooking into things which that library/mod solves but I haven't been able to find much info about it.

RemingtonRyder

With CCL, you can use a post load injector. That's every time you load game, by the way.

So as a very simple example (but not something which is exactly covered by the examples):

    <ModHelperDef>
        <defName>GravelInfertilityInjector</defName>

        <ModName>Gravel Infertility Injector</ModName>

        <minCCLVersion>0.13.0</minCCLVersion>

        <PostLoadInjectors>
            <li>NoGravelFertility.FertilityInjector</li>
        </PostLoadInjectors>

    </ModHelperDef>


That will execute the mentioned class (in the list tags) if it's a PostLoadInjector.

using Verse;
using CommunityCoreLibrary;

namespace NoGravelFertility
{
public class FertilityInjector : SpecialInjector
{
public override bool Inject ()
{

TerrainDef.Named ("Gravel").fertility = 0.0f;
return true;

}
}
}


This is the code which is actually executed. Which, very basically, finds the TerrainDef named Gravel and assigns 0.0 to its fertility.

hoochy

Thanks for that, it is good to have some examples to do such things. I will need my mod to be there when the actual map is created, probably from the seed  if the specific map you  select isn't random genned the first time you run it. Basically whenever the actual tiles for the map are "created" I need to be there after that to then add my own data there for each tile, whether it is directly in the tiles or just my own data structure I'm not sure what the best method is for this game.

1000101

Yes, the C# API isn't terribly well documented for CCL.  It's kind of "download the source and poke through it."  We do plan (one day) to have some C# examples for how to do some things.

The above example posted by MarvinKosh is accurate, however for SpecialInjectors and PostLoadInjectors (which are exactly the same except for when they happen).
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

hoochy

Quote from: 1000101 on April 18, 2016, 12:53:31 PM
Yes, the C# API isn't terribly well documented for CCL.  It's kind of "download the source and poke through it."  We do plan (one day) to have some C# examples for how to do some things.

The above example posted by MarvinKosh is accurate, however for SpecialInjectors and PostLoadInjectors (which are exactly the same except for when they happen).

How do most people decide to use your mod? I don't mean to offend you, your mod seems to be used by some pretty big mods but the information on your mod seems extremely limited. I can learn from some of the example mods that use yours, just reading the source, but it seems a mod like yours would do itself a world of good if it was more advertised and marketed, in turn, with better tutorials. :)

I am a "Real programmer" so the only need I have is information about the best way to do things so I don't waste time relearning everything you or others have already done.

1000101

There are examples and "def descriptions" for the xml stuffs (download the "modders release"), but I just haven't had time to write C# examples.  Mostly people decide to use it if there is something they find useful in it.  Of course "useful" is a matter of perspective.  For example, mods which add lights can benefit from CompColoredLight as they can create one game object which with the aforementioned ThingComp which allows for the color of the light to be changed by the user without having to destroy the light and build a new specifically colored light.

That is one example, but there are others.  I have been told *cough*alistaire*cough* that my documentation sucks.  While my documentation "covers the basics" it's far from optimal, to be sure.

A lot of CCL is "done by request" and implemented in a manner which would be useful to the community and mods at large.  If there was a tech writer lurking on the forums, I'd love to get some help writing better docs and examples.  I've been using the excuse of, "I'm a programmer, not tech writer," but that is "weak sauce" and some people *cough*alistaire*cough* like to call BS on me for that.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

hoochy

#6
Quote from: 1000101 on April 18, 2016, 04:45:59 PM
There are examples and "def descriptions" for the xml stuffs (download the "modders release"), but I just haven't had time to write C# examples.  Mostly people decide to use it if there is something they find useful in it.  Of course "useful" is a matter of perspective.  For example, mods which add lights can benefit from CompColoredLight as they can create one game object which with the aforementioned ThingComp which allows for the color of the light to be changed by the user without having to destroy the light and build a new specifically colored light.

That is one example, but there are others.  I have been told *cough*alistaire*cough* that my documentation sucks.  While my documentation "covers the basics" it's far from optimal, to be sure.

A lot of CCL is "done by request" and implemented in a manner which would be useful to the community and mods at large.  If there was a tech writer lurking on the forums, I'd love to get some help writing better docs and examples.  I've been using the excuse of, "I'm a programmer, not tech writer," but that is "weak sauce" and some people *cough*alistaire*cough* like to call BS on me for that.

Well I feel like your mod could be that "compatibility layer" that helps other mods more effortlessly migrate to newer versions. Maybe you can work a deal out with the moderators here or whatever to get your project stickied if you can make that next step documentation and project wise.

In regards to what I want to do, do you have any advice to where I should be looking? I basically want to have some "per tile" definitions myself in my mod, that are only created once, when the map is. I could also just "random gen" the same information if the mod is applied to an active game - but again that will only have to be done once per game, so a postload injector would work ok for that but I'm not sure about the first. If I use my own data structure in this "Special terrain class" will it be saved by the game or do I need to something special for that?

Since I also want to be working with the terrain, it seems your mods "Terrain With Comps" feature will be helpful for me.

1000101

From your first post, I would probably suggest using a MapComponent.  The first call to the tick method, you can scan the map and cache the data you need.  The MapComponent also has an ExposeData() method which you can use to save and load your persistent data.

As to TerrainWithComps, it currently only supports using CompRestrictedPlacement.  The rules for that could be relaxed, but it doesn't support ticking or ExposeData.  Currently there is no need for it however, the library constantly evolves based on modders needs and it can be expanded to support more "relaxed features."  The big issue with TerrainWithComps ticking is that unlike Things in the game, every cell of the map has terrain and ticking terrain could cause serious lag so it must be implemented with care and caution.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

hoochy

The ability to allow mining based on terrain would be very helpful. Otherwise I have to place fake buildings, a bit like the current mining in the game. A rock wall is a fake building.

1000101

I'm not sure what you mean by "allow mining by terrain."  Rock walls always have the same type of "rough stone" floor under the rock wall as the rock wall itself.  ie, a granite rock wall always has a rough granite floor underneath it.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

RemingtonRyder

I think he wants to be able to actually mine a terraindef for resources. I'm not sure if that's even possible.

hoochy

#11
Yes that is what I want, so a "comp" for that on a terraindef guess. I'm not sure what "comp" stands for exactly but it seems to be the thing ;)

Looking at how the existing game does it, ie treats mineable rocks as buildings, it would probably be more than a simple tweak to do this. I am adding "rocky outcrops" and things like this which basically I want pawns to be able to mine, and also eventually buildings can be placed in these areas too.

The reason I can't really use the existing mining system is it looks much uglier. The "Terrain" system uses a large texture in a repeating way which isn't "as obvious" and makes it look ok-ish. I basically have the terrain looking in a way I want, but just no way to interact with it. If I was to use "buildings" like the current game does, I would be quite limited in the "Look" of the terrain which could be mined.



So it seems the only thing the game really allows with terrain atm is building on it and "floors", so I'm not really sure how to go about adding mining to terrain except adding new code to do it, somehow linking in with the existing "can this be mined" check the game does. It seems something perfect for CCL because it would be useful not just for my mining mod. But adding possibilities to do more with the terrain itself seems  a worthy goal for the game itself, but since the game isn't doing it seems great for CCL. ;)

RemingtonRyder

You could still use Building as your base. The reason why terrain textures don't have obvious repeating patterns is because they're fairly large. Not sure how big exactly.

The trick, I guess, would be to make your buildings look and behave like terrain - it should be possible to pass over it, for example. The texturing would be the difficult bit.

1000101

#13
You don't even need a comp (which is short for "ThingComp" (class name) or "Thing Component") to do this.  (Image RimWorld modding like lego, Things and Terrain are like the large base pieces and "comps" are the blocks you add to make your base piece that much cooler).

Just replace the mining designator to check terrain type and allow the cell to be designated if it's the appropriate type.  You will also need to modify the mining job and then probably change the terrain once the cell is "mined out".

This can all be done with just the RimWorld core, no CCL required.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

hoochy

Quote from: 1000101 on April 21, 2016, 12:43:33 PM
You don't even need a comp (which is short for "ThingComp" (class name) or "Thing Component") to do this.  (Image RimWorld modding like lego, Things and Terrain are like the large base pieces and "comps" are the blocks you add to make your base piece that much cooler).

Just replace the mining designator to check terrain type and allow the cell to be designated if it's the appropriate type.  You will also need to modify the mining job and then probably change the terrain once the cell is "mined out".

This can all be done with just the RimWorld core, no CCL required.

I'm not sure I follow you. The rocks which are mineable are "ThingDefs" which seem to add this :-

<thingClass>Mineable</thingClass>

If you add that to terraindef it says it is not a valid thing. When you said you can do that all in core did you mean by overriding core C# Functions or just with XML mods? If you meant the former then yeah I am aware that you can alter the game to do what you want, I was basically just saying if CCL had that it would simplify this mod and other uses of the terrain. ;)