Ludeon Forums

RimWorld => Mods => Help => Topic started by: Evul on June 03, 2014, 08:54:16 PM

Title: [C#] Help! How do i restrict something against a wall?
Post by: Evul on June 03, 2014, 08:54:16 PM
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!!!
}
{
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: StorymasterQ on June 03, 2014, 10:26:26 PM
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?
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Justin C on June 03, 2014, 10:26:41 PM
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.
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Evul on June 04, 2014, 06:25:05 AM
How do I do that? I'm kiiiind a new to C# coding.
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Cala13er on June 04, 2014, 07:17:17 AM
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.
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Evul on June 04, 2014, 07:43:50 AM
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. :)
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Cala13er on June 04, 2014, 07:47:45 AM
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.
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Cala13er on June 04, 2014, 08:07:44 AM
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 ;))
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Evul on June 04, 2014, 08:19:06 AM
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
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Cala13er on June 04, 2014, 08:21:10 AM
Wow, I'm worse than I thought. Give me a second Grrrr.
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Evul on June 04, 2014, 08:36:08 AM
Quote from: Cala13er on June 04, 2014, 08:21:10 AM
Wow, I'm worse than I thought. Give me a second Grrrr.

hehe
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Cala13er on June 04, 2014, 08:37:02 AM
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!
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: 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?
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: 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.
Title: Re: [C#] Help! How do i restrict something against a wall?
Post by: Evul on June 04, 2014, 09:08:56 AM
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 ^^