Help with Things and Pawns and Corpses

Started by smoq2, February 03, 2015, 08:02:37 AM

Previous topic - Next topic

smoq2

Will the code below work?

            var homeCells = Find.HomeRegionGrid.ActiveCells;
            if (homeCells == null)
                return;

            var haulables = Find.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableEver);

            if (haulables == null)
            {
                return;
            }


var thingsInStockpiles = from stockpile in Find.ZoneManager.ZonesOfType<Zone_Stockpile>()
where stockpile.GetSlotGroup() != null
from thing in stockpile.GetSlotGroup().HeldThings
select thing;

            var forbiddenHaulablesInHomeZone = from thing in haulables
                                               join cell in homeCells on thing.Position equals cell
                                               where thing.IsForbidden(Faction.OfColony) == true
                                               select thing;

//forbiddenHaulablesInHomeZone = forbiddenHaulablesInHomeZone.Except(thingsInStockpiles);    
   
   
            foreach (Thing thing in forbiddenHaulablesInHomeZone)
            {
                GenThing.TrySetForbidden(thing, false);
            }


My 1st question is: Are the things in thingsInStockpiles the same things as in forbiddenHaulablesInHomeZone so that the (commented out) except() method can compare them?

The aim of the code is to ignore items that are in a Stockpile zone as well as Home zone.

My 2nd question is: How do I get a Pawn or a Corpse from a Thing? I know I have to check if the said Thing even has a Pawn or Corpse - how to do that too?

Thanks to anyone willing to help. :)

mipen

I could be wrong, but I don't think pawns are things, so searching for things won't let you find any pawns. To check if a thing is a corpse, you can try

if(thing is Corpse)
//whatever code you want to do for a corpse goes here

You'll have to double check that corpses even have their own class and what it is called, but I'm pretty sure they do. The 'is'  keyword will return true if the object you are testing inherits from the corpse class anywhere in its inheritance cycle.

I'm not sure I understand your first question. Do you want to get a list of all haulable items that are not in either a stockpile or the home zone?