Ludeon Forums

RimWorld => Mods => Help => Topic started by: jamieg on April 25, 2014, 09:26:50 PM

Title: HELP PLEASE Restricting building areas [solved]
Post by: jamieg on April 25, 2014, 09:26:50 PM
I'm having the hardest time with a sand pit... I have it working but not how i want, at the moment my people can create 10 bags of sand but it cost 1 metal and about 20-30 seconds, and you can place the sandpit anywhere.

I would like it so it can only be built on sand and so that it does not require anything to make except the time it take them to dig if you get me, I've been playing around with this loads, tried the whole restriction like with a geothermal on a steam geyser ect but im all out of ideas

SOMEONE PLEASE GET BACK TO ME ASAP WHILST MY INSPIRATION IS RUNNING WILD :D
Title: Re: HELP PLEASE Restricting building areas
Post by: ItchyFlea on April 25, 2014, 09:44:58 PM
<SurfaceNeeded> and <SurfacesSupported> are the tags you'll need to work with to restrict placement to just sand and nothing else. Unfortunately there isn't a surface type just for sand that isn't shared by the other terrain types. You'll need to create a separate one, probably with a .dll, and use that.

As for taking time but for free, keep the <WorkToBuild> tag but remove the <CostList> one.
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 25, 2014, 09:49:41 PM
Thank you once again Itchy!! I ow ya! Although i may need to hold for a few days or so on this as i am too nooby for dll at the moment and will need Zelldot to teach me
Title: Re: HELP PLEASE Restricting building areas
Post by: Kirid on April 26, 2014, 02:27:05 AM
I think your best bet would be <SurfaceNeeded> <li>Diggable</li> </SurfaceNeeded> That includes only sand, soil, rich soil, and gravel. Light includes alot more things like floors and stone.
I'm pretty nooby at dll editing atm also, but this idea doesn't seem too hard.
Title: Re: HELP PLEASE Restricting building areas
Post by: WorldOfIllusion on April 26, 2014, 07:17:23 AM
You could try making a custom PlacementRestricter for it.

And then explain to me why mine don't work :P
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 26, 2014, 10:58:39 AM
Quote from: ItchyFlea on April 25, 2014, 09:44:58 PM

As for taking time but for free, keep the <WorkToBuild> tag but remove the <CostList> one.

I ment in the BagOfSand recipe when removing the resources required to make it, it causes the game to get very vibrant in colour when my pawns try to use it, then it crashes so i had to set it to cost 1 wood to make which bugs me :(
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 26, 2014, 11:01:21 AM
Quote from: Kirid on April 26, 2014, 02:27:05 AM
I think your best bet would be <SurfaceNeeded> <li>Diggable</li> </SurfaceNeeded> That includes only sand, soil, rich soil, and gravel. Light includes alot more things like floors and stone.
I'm pretty nooby at dll editing atm also, but this idea doesn't seem too hard.

Does ANYONE know of a replacment for Diggable in this that is for sand only? because this is almost spot on
Title: Re: HELP PLEASE Restricting building areas
Post by: Kirid on April 26, 2014, 11:09:10 AM
Not unless you define a new Surface Type.  Any, Light, Heavy, GrowSoil, Diggable, SmoothHard, SmoothableStone are the only types currently.
I'm looking at the SurfaceType dll right now trying to figure out how define a new one  ;) I'm not sure how to build class files into a dll.
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 26, 2014, 11:12:41 AM
Quote from: Kirid on April 26, 2014, 11:09:10 AM
Not unless you define a new Surface Type.  Any, Light, Heavy, GrowSoil, Diggable, SmoothHard, SmoothableStone are the only types currently.
I'm looking at the SurfaceType dll right now trying to figure out how define a new one  ;) I'm not sure how to build class files into a dll.

I think (as this is for our full conversions) that i will change steam geysers to something like Sink holes as an example and set the restrictions probs be the easier way.
Title: Re: HELP PLEASE Restricting building areas
Post by: ItchyFlea on April 27, 2014, 12:29:41 AM
Quote from: jamieg on April 26, 2014, 10:58:39 AM
I ment in the BagOfSand recipe when removing the resources required to make it, it causes the game to get very vibrant in colour when my pawns try to use it, then it crashes so i had to set it to cost 1 wood to make which bugs me :(
Ahh, I see.
A workaround would be to make it cost 1 of something, and have the recipe result include that something as well as the bag of sand.
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 27, 2014, 06:44:05 AM
so it could cost 1 wood but you get it back with the bag of sand.... why didnt i think of this! ITCHY you genius :p
Title: Re: HELP PLEASE Restricting building areas
Post by: pawnstorm on April 27, 2014, 03:48:38 PM
Quote from: WorldOfIllusion on April 26, 2014, 07:17:23 AM
You could try making a custom PlacementRestricter for it.

And then explain to me why mine don't work :P
Show me yours, I'll show you mine :P

    public class PlacementRestricter_OnlyOne : PlacementRestricter
    {
        public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
        {
            if (Find.ListerBuildings.ColonistsHaveBuilding((ThingDef) checkingDef))
            {
                return new AcceptanceReport("Can only build one of those.");
            }
            return true;
        }
    }


You could probably make something like that which checks for sand too. Maybe using TerrainGrid.TerrainAt?
Title: Re: HELP PLEASE Restricting building areas
Post by: Cala13er on April 27, 2014, 04:16:53 PM
Since we're exposing Placement Restrictors, here's mine for the hydro plants of Industrial RIM. Just so people can learn from it :).


public class PlacementRestricter_NextToHydroAccepter : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
{
foreach (IntVec3 current in GenAdj.AdjacentSquares8Way(loc))
{
foreach (Thing current2 in Find.get_Grids().ThingsAt(current))
{
ThingDef thingDef = ThingDef.Named("HydroPowerPlant");
ThingDef thingDef2 = ThingDef.Named("HydroPool");
ThingDef thingDef3 = ThingDef.Named("HydroAccelerator");
ThingDef thingDef4 = ThingDef.Named("HydroAdvancedTurbine");
if (current2.def == thingDef)
{
AcceptanceReport result = true;
return result;
}
if (current2.def == thingDef2)
{
AcceptanceReport result = true;
return result;
}
if (current2.def == thingDef3)
{
AcceptanceReport result = true;
return result;
}
if (current2.def == thingDef4)
{
AcceptanceReport result = true;
return result;
}
}
}
return "Must be placed next to a hydroplant, hydropool, hydroaccelerator or advancedhydroturbines";
}
}
Title: Re: HELP PLEASE Restricting building areas
Post by: Tynan on April 27, 2014, 05:25:41 PM
Not tested, but this should work.


public class PlacementRestricter_OnlyOnSand : PlacementRestricter
{
        public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
        {
            if( Find.TerrainGrid.TerrainAt( loc ) != TerrainDef.Named("Sand") )
               return "Can only place on sand."
            else
                return true;
        }
    }
Title: Re: HELP PLEASE Restricting building areas
Post by: Cala13er on April 27, 2014, 05:29:28 PM
Quote from: Tynan on April 27, 2014, 05:25:41 PM
Not tested, but this should work.


public class PlacementRestricter_OnlyOnSand : PlacementRestricter
{
        public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
        {
            if( Find.TerrainGrid.TerrainAt( loc ) != TerrainDef.Named("Sand") )
               return "Can only place on sand."
            else
                return true;
        }
    }


Oh, I thought someone had already resolved his problem.

Apart from that, +1 that code. Works fine.
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 27, 2014, 06:02:44 PM
Just seen all the replies and thanks, im working on it now :)
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 28, 2014, 12:08:27 PM
Quote from: Tynan on April 27, 2014, 05:25:41 PM
Not tested, but this should work.


public class PlacementRestricter_OnlyOnSand : PlacementRestricter
{
        public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
        {
            if( Find.TerrainGrid.TerrainAt( loc ) != TerrainDef.Named("Sand") )
               return "Can only place on sand."
            else
                return true;
        }
    }


worked like a charm, thx Ty!
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 28, 2014, 03:13:32 PM
Can anyone tell me where i can find some referencing to this code, so that i do not need to ask again when creating DLL's, thanks :)
Title: Re: HELP PLEASE Restricting building areas
Post by: Tynan on April 28, 2014, 03:18:36 PM
Quote from: jamieg on April 28, 2014, 03:13:32 PM
Can anyone tell me where i can find some referencing to this code, so that i do not need to ask again when creating DLL's, thanks :)

I don't understand "find some referencing to this code".
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 28, 2014, 03:22:23 PM
I mean for example the answer you gave me work fine(after putting in the missing semicolon  :P) but where would I look to have found this out myself rather than having to ask? hope thats a better question.
Title: Re: HELP PLEASE Restricting building areas
Post by: zelldot on April 28, 2014, 03:37:06 PM
I think what jamie means is that he is looking for some sort of reference index for in game procedures when it comes to modding this game e.g. CanPlaceWithRestriction() I am sure is created by yourself. He is not asking for the basics of programming as has me to guide him with that.
Title: Re: HELP PLEASE Restricting building areas
Post by: Tynan on April 28, 2014, 03:49:03 PM
Ah yes. He's asking for documentation on the game code.

I'm sorry to say there isn't any. It's still changing. And I just don't have time to write documentation when I'm busy writing the code itself. I was hoping people would build up that knowledge base on rimworldwiki.com.
Title: Re: HELP PLEASE Restricting building areas
Post by: Cala13er on April 28, 2014, 03:53:07 PM
Quote from: Tynan on April 28, 2014, 03:49:03 PM
Ah yes. He's asking for documentation on the game code.

I'm sorry to say there isn't any. It's still changing. And I just don't have time to write documentation when I'm busy writing the code itself. I was hoping people would build up that knowledge base on rimworldwiki.com.

Hey Tynan, I have some spare time, I could do it. What knowledge base are you on about? http://rimworldwiki.com/Modding ? I plan on making some significant changes to the RimWorld Wiki, listing every single Mod available in rimWorld, including unfinished and outdated. Aswell as change some of the current pages :)
Title: Re: HELP PLEASE Restricting building areas
Post by: jamieg on April 28, 2014, 04:09:23 PM
Cheers Ty no worrys, and call, I like my wiki page :P
Title: Re: HELP PLEASE Restricting building areas
Post by: Tynan on April 28, 2014, 04:19:55 PM
I'd much appreciate it Calum!

I think the most useful thing to do would be to create:

0. Create a good "Modding" root page with a centralized set of links to all content available on modding. Integrate info from http://rimworldwiki.com/Modding_Tutorials

1. A set of basic tutorials on how to do various things. First, some basic XML modding. Then some with code.

2. A documentation reference on some of the core classes in the RW code base and how they're structured. How defs work, how items are spawned and moved around, and so on.

You may want to coordinate a bit through this thread: http://ludeon.com/forums/index.php?topic=3283.0

If you have any questions for me while writing please feel free to ask them. I can also go look at what you wrote and check that nothing is missing if you like.

I actually don't think listing existing mods is the best use of your time. The future is much bigger than the present when it comes to RW mods and community in general. I think the most optimal move is to amplify the future by providing good how-to modding info to upcoming modders. If people want to see existing mods, they can look in the forums. If the forums aren't enough, there are other ways to track this kind of content on the Internet, and a wiki is not the most appropriate one. We'd need something closer to YouTube with latest/categories/search function, etc.