How can I add affordances?

Started by Dr. Z, September 16, 2014, 11:49:48 AM

Previous topic - Next topic

Dr. Z

I want to create a floor you can build on mud to make it useable, but there isn't an affordance unique to mud, does anyone know how and where to add one?
Prasie the Squirrel!

Rikiki

#1
Adding an affordance would probably require to modify the core code. So this is just not possible I think.

I don't know if it works for floors (works for building at least) but you could just write your own placement_restricter like that:


public class PlacementRestricter_OnMud : PlacementRestricter
{
   if (Find.TerrainGrid.TerrainAt(loc).defName == "Mud")
   {
      return (true);
   }
   else
   {
      return (false);
   }
}


You can find some other examples here: http://ludeon.com/forums/index.php?topic=5930
and here: http://ludeon.com/forums/index.php?topic=3449

Dr. Z

Unfortunately I'm a modding newbie, so I was hoping that it would be done with adding a line somewhere in a dll :/
Prasie the Squirrel!

Rikiki

 ??? euh... this a piece of code for a dll.

You maybe mean "in an XML file" ? ;)

Dr. Z

No, I meant dll, your original post just sounded like I had to write one on my own instead of just adding something (for my understanding, a dll is like a huge wall of hieroglyphics at the moment).
Prasie the Squirrel!

ItchyFlea

This should work:
<affordances>
         <li>Any</li>
</affordances>

These are the terrain affordances currently in the game: (Thanks to ILSpy)
Any
Light
Heavy
GrowSoil
Diggable
SmoothHard
SmoothableStone
All my mods are licensed under a Attribution-NonCommercial-ShareAlike 4.0 International
Ask for permission before using in ModPacks

Click here for a list of the mods I've created

Dr. Z

That's actually a good idea for now, I will do this till I can realise Rikikis suggestion so you can build them only on mud. Thanks for your answeres :)
Prasie the Squirrel!

Dr. Z

@ Rikiki

Where would I have to add your code?
Prasie the Squirrel!

Rikiki

Mmh, to get started, I suggest you to follow the instructions of the Dark-matter generator tutorial.

Then you have to create a class that expands Placement_Restricter (get the Deepdriller mod for a complete/working example).

And finally, don't forget to set your custom placement restricter within your xml floor def:

<placementRestricters>
   <li>Deepdriller.PlacementRestricter_Deepdriller</li>
</placementRestricters>


Ask away if you are lost at some step :)