[Solved] Extending Placement Restricter

Started by lub4095, May 04, 2014, 10:29:07 AM

Previous topic - Next topic

lub4095

So what I am trying to do is add Oil as a new resource and make an Oil Refinery which can only be placed on oil tiles.
EntityType.cp - I added Oil at the bottom

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine; // Always needed
using AI;        // Needed when you do something with the AI
using Sound;     // Needed when you do something with the Sound
using UI;        // Needed when you do something with the GUI


namespace SpaceOdyssey
{
    public enum EntityType
    {
        Undefined,
        Pawn,
        Item,
        Apparel,
        Equipment,
        Filth,
        Fire,
        Corpse,
        Debris,
        Puddle,
        DropPod,
        Plant,
        Floor,
        Roof,
        Mote,
        Blueprint,
        Projectile,
        ItemSkyFalling,
        Rock,
        SteamGeyser,
        BuildingComplex,
        BuildingInert,
        Frame,
        Wall,
        Door,
        Bed,
        Building_WorkTable,
        Building_Table,
        Building_PowerPlantGeothermal,
        Building_PowerConduit,
        Building_Battery,
        Building_CommsConsole,
        Building_ResearchBench,
        Building_Turret,
        Building_Chair,
        Oil
    }
}


PlacementRestricter_OnOil.cp - I edited PlacementRestricter_OnSteamGeyser to fit the oil resource

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine; // Always needed
using AI;        // Needed when you do something with the AI
using Sound;     // Needed when you do something with the Sound
using UI;        // Needed when you do something with the GUI

namespace SpaceOdyssey
{
    public class PlacementRestricter_OnOil : PlacementRestricter
    {
        public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
        {
            Thing thing = Find.Grids.ThingAt(loc, EntityType.Oil);
            if (thing == null || thing.Position != loc)
            {
                return "Must be placed directly on Oil.";
            }
            return true;
        }
    }
}


So when I try to compile it I get these errors:
The best overloaded method match for 'ThingGrid.ThingAt(IntVec3, EntityType)' has some invalid arguments

Argument 2: cannot convert from 'SpaceOdyssey.EntityType' to 'EntityType' in PlacementRestricter_OnOil.cp line 16. What am I doing wrong? Please note that I am a complete newbie at these stuff and it is my first attempt to make an assembly.




WorldOfIllusion

Firstly, you will need to actually make an XML defined thing that is the oil (similar to how a steam geyser works).
Secondly, I don't believe the game will use your extended version of EntityType, it will just use the default version (and thus any calls you make to it won't work). This is what's causing your error (you are passing your version of EntityType which is different to the games EntityType).
Artistically challenged modder seeking artistically talented texturer's help. Please, please, PM me :)

lub4095

Quote from: WorldOfIllusion on May 04, 2014, 10:33:30 AM
Firstly, you will need to actually make an XML defined thing that is the oil (similar to how a steam geyser works).
Secondly, I don't believe the game will use your extended version of EntityType, it will just use the default version (and thus any calls you make to it won't work). This is what's causing your error (you are passing your version of EntityType which is different to the games EntityType).

So how do I add a new entity type since I cannot overwrite the existing one from the game?

WorldOfIllusion

at this point I don't think you can, but I don't see why you need to?
If you make an XML defined 'oil well' or something like that and add it to worldgen you can check for it being present using its defName for example.
Artistically challenged modder seeking artistically talented texturer's help. Please, please, PM me :)

lub4095

Quote from: WorldOfIllusion on May 04, 2014, 07:49:11 PM
at this point I don't think you can, but I don't see why you need to?
If you make an XML defined 'oil well' or something like that and add it to worldgen you can check for it being present using its defName for example.

How is that possible? The only XML tag that I found which checks where you can build was:

<placementRestricters>
      <li>PlacementRestricter_OnSteamGeyser</li>
</placementRestricters>

WorldOfIllusion

That XML tag is defining a DLL with the same name. You can implement your own placement restricter (just as you were trying to originally), that doesn't check based on EntityType (for example look at the next to hopper accepter).
Artistically challenged modder seeking artistically talented texturer's help. Please, please, PM me :)

Cala13er

public class PlacementRestricter_OnOil : PlacementRestricter
{
    public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
    {
        ThingDef thingDef = ThingDef.Named("Oil");
        Thing thing = Find.Grids.ThingAt(loc, thingDef);
        if (thing == null || thing.Position != loc)
        {
            return "Must be placed directly on a steam geyser.";
        }
        return true;
    }
}


I quickly changed it for you, this should work.

lub4095

Quote from: Cala13er on May 05, 2014, 05:47:06 AM
public class PlacementRestricter_OnOil : PlacementRestricter
{
    public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
    {
        ThingDef thingDef = ThingDef.Named("Oil");
        Thing thing = Find.Grids.ThingAt(loc, thingDef);
        if (thing == null || thing.Position != loc)
        {
            return "Must be placed directly on a steam geyser.";
        }
        return true;
    }
}


I quickly changed it for you, this should work.

Haha it worked! And I thought I had to overwrite BuildingProperties (to add public bool wantsOilAdjacent;) and create a new Building_Oil class... I thank you! I am really new to this so it's really hard for me at the moment.

Architect

you might want to change what it returns first though :P Otherwise you're gonna get spammed with messages about steam geysers when you try to place it not on oil.
Check out BetterPower+ and all its derivatives by clicking the picture below.

It adds many new methods of power generation and uses for it, as well as other things such as incidents.


Cala13er

Quote from: Architect on May 05, 2014, 08:03:24 AM
you might want to change what it returns first though :P Otherwise you're gonna get spammed with messages about steam geysers when you try to place it not on oil.

What? :P

WorldOfIllusion

Quote from: Architect on May 05, 2014, 08:03:24 AM
you might want to change what it returns first though :P Otherwise you're gonna get spammed with messages about steam geysers when you try to place it not on oil.

Wait, steam geysers don't produce oil? *updates mod*
Artistically challenged modder seeking artistically talented texturer's help. Please, please, PM me :)

Architect

return "Must be placed directly on a steam geyser.";

should that not have something more to do with oil?
Check out BetterPower+ and all its derivatives by clicking the picture below.

It adds many new methods of power generation and uses for it, as well as other things such as incidents.


lub4095

Quote from: Architect on May 05, 2014, 08:03:24 AM
you might want to change what it returns first though :P Otherwise you're gonna get spammed with messages about steam geysers when you try to place it not on oil.

Don't worry I changed that.