[C#] Help! How do i restrict something against a wall?

Started by Evul, June 03, 2014, 08:54:16 PM

Previous topic - Next topic

Evul

I need some help making a C# code for restricting a item against a wall? How do i do this?

using System;
using Verse;
public class PlacementRestricter_NextToWall : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
{
WHAT SHOULD I WRITE HERE!!!
}
{

StorymasterQ

I don't know much about C# programming, much less with RimWorld's, but perhaps you can check for a Wall tile adjacent to the location?
I like how this game can result in quotes that would be quite unnerving when said in public, out of context. - Myself

The dubious quotes list is now public. See it here

Justin C

I'd find the closest walls to the location you are trying to place the object, and see if any of them are in the squares right next to where the object is being placed.

Evul

How do I do that? I'm kiiiind a new to C# coding.

Cala13er

Try this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using Verse.Sound;

public class PlacementRestricter_NextToWall : PlacementRestricter
{
    public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
    {
        foreach (IntVec3 current in loc.AdjacentSquares8Way())
        {
            foreach (Thing current2 in Find.ThingGrid.ThingsAt(current))
            {
                if (current2.def.linkFlags == LinkFlags.WallBrick)
                {
                    return "Can not be placed next to a wall";
                }
                else if (current2.def.linkFlags == LinkFlags.WallLog)
                {
                    return "Can not be placed next to a wall";
                }
                else if (current2.def.linkFlags == LinkFlags.WallMetal)
                {
                    return "Can not be placed next to a wall";
                }
                else if (current2.def.linkFlags == LinkFlags.WallMud)
                {
                    return "Can not be placed next to a wall";
                }
                else if (current2.def.linkFlags == LinkFlags.WallStone)
                {
                    return "Can not be placed next to a wall";
                }
                else if (current2.def.linkFlags == LinkFlags.WallWood)
                {
                    return "Can not be placed next to a wall";
                }
                else if (current2.def.linkFlags == LinkFlags.Rock)
                {
                    return "Can not be placed next to a wall";
                }
                else
                {
                    return true;
                }
            }
        }
        return "Can not be placed next to a wall";
    }
}


If this does not work, I will get right on to making one that works, I just made this quickly hoping it would work.

Evul

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using Verse.Sound;

public class PlacementRestricter_NextToWall : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
{
foreach (IntVec3 current in loc.AdjacentSquares8Way())
{
foreach (Thing current2 in Find.ThingGrid.ThingsAt(current))
{
if (current2.def.linkFlags == LinkFlags.WallBrick)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallLog)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallMetal)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallMud)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallStone)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallWood)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.Rock)
{
return "Can only be placed next to a powered wall";
}
else
{
return true;
}
}
}
return "Can only be placed next to a powered wall";
}
}


It almost worked
It calculated all kind of objects 1 tile away so filth and rocks was also calculated.

But to clarify i want it to only be able to be located next to a powered wall. :)

Cala13er

Oh you want it so it can only be placed next to powered walls? Right I get it now. Will get on it in a second.

Cala13er

Right here you go! This should will work.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using Verse.Sound;

public class PlacementRestricter_NextToWall : PlacementRestricter
{
    public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
    {
        foreach (IntVec3 current in loc.AdjacentSquares8Way())
        {
            foreach (Thing current2 in Find.ThingGrid.ThingsAt(current))
            {
                if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallMetal)
                {
                    return true;
                }
                else if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallWood)
                {
                    return true;
                }
                else if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallStone)
                {
                    return true;
                }
                else if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallWood)
                {
                    return true;
                }
                else if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallBrick)
                {
                    return true;
                }
            }
        }
        return "Must be placed next to wall that transmits power";
    }
}


This is also makes it compatible with Industrial RIM v1.2.0 as it has Wood and Stone walls that transmit power.
(Also compatible with other mods that use the linkflags of course ;))

Evul

Did not work :3
Even when it have power.
It should tho be able to be placed even tho the wall do not have power at the moment. :P

Cala13er

Wow, I'm worse than I thought. Give me a second Grrrr.

Evul


Cala13er

FINALLY GOT IT!!! GAWDERR.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using Verse.Sound;

public class PlacementRestricter_NextToWall : PlacementRestricter
{
    public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
    {
        foreach (IntVec3 current in loc.AdjacentSquares8Way())
        {
            foreach (Thing current2 in Find.ThingGrid.ThingsAt(current))
            {
                if (current2.def.transmitsPower == true)
                {
                    if (current2.def.eType == EntityType.Wall)
                    {
                        return true;
                    }
                }
            }
        }
        return "Must be placed next to wall that transmits power";
    }
}


This DOES work.

At least I know why It wasn't working!

Evul

Now it works! Awesome!

One thing how do i make it so so Xamarin don't build all the assembly dll files?

Cala13er

Quote from: Evul on June 04, 2014, 08:41:30 AM
Now it works! Awesome!

One thing how do i make it so so Xamarin don't build all the assembly dll files?

I don't use Xamarin.

Evul

Quote from: Cala13er on June 04, 2014, 08:45:21 AM
Quote from: Evul on June 04, 2014, 08:41:30 AM
Now it works! Awesome!

One thing how do i make it so so Xamarin don't build all the assembly dll files?

I don't use Xamarin.

Damit ^^