this.Position and buildings

Started by JuliaEllie, November 14, 2014, 01:21:32 PM

Previous topic - Next topic

JuliaEllie

Hey guys,

I have a quick question: I need to read out the contents of a storage building which is 2x1. At the moment I use

public IntVec3 slot1
        {
            get
            {
                return this.Position;
            }
        }

        public IntVec3 slot2
        {
            get
            {
                IntVec3 toreturn = this.Position;
                toreturn.x += 1;
                return toreturn;
            }
        }

        public bool slot1Full
        {
            get
            {
                foreach (Thing thing in Find.ThingGrid.ThingsAt(this.slot1))
                {
                    if (thing.def.defName.Equals("genome"))
                    {

                        this.genome1 = (genome)thing;


                        return true;


                    }
                }
                return false;
            }
       
       
        }


        public bool slot2Full
        {
            get
            {
                foreach (Thing thing in Find.ThingGrid.ThingsAt(this.slot2))
                {
                    if (thing.def.defName.Equals("genome"))
                    {

                        this.genome2 = (genome)thing;


                        return true;


                    }
                }
                return false;
            }


        }     


but then I noticed that this might be a problem if someone rotates the building :D Is there a way to return a List<IntVec3> of all cells occupied by that building no matter what rotation or do I have to write it myself using the rotation property of the building?

Rikiki

Write it yourself! ;)
You have some examples in M&Co. Deepdriller (placement restrictor and other, look for "Rotation").

JuliaEllie

#2
Ok Ill write it myself :D thanks

and why the fing hell I need a fing monobehaviour if I only want to draw a simple box when a thing is selected?!

JuliaEllie

Hey we are both stupid :D there is Building_Storage.AllSlotCellsListFast() which returns List<IntVec3> cachedOccupiedSquares. Next time we only have to return this list and we are fine ;)

oh and I found this out AFTER I wrote my own :D

mipen

Another way you can do this is by using GenAdj ->
GenAdj.CellsOccupiedBy(this).ToList<IntVec3>();
It returns an IEnumerable<IntVec3> that you can easily cast as a list using .ToList() :)

JuliaEllie

Looks like we the modders need to write a documentation for all this.