Need some help with finding appropriate squares

Started by bslinger, June 06, 2014, 10:16:02 AM

Previous topic - Next topic

bslinger

Hey there,

I'm trying to write the AI for a creature that will hide in the darkness, so my first step is to find the closest cell that is dark. So far I've written it using GenRadial to just search a radius, which works OK, but I'd prefer to use the new Region system if possible to get better paths. Unfortunately there only seems to be a way to search for Things in a square using that system, but not other aspects of a cell.

The other issue I have is that I would prefer to find a path that doesn't require going through a closed door - this is supposed to be an escape mechanism, and if the creature needs to fight it's way through a door it will take too long.

Here is my code so far, any help would be greatly appreciated!


class JobGiver_FindDarkness : ThinkNode_JobGiver
    {
        protected override Job TryGiveTerminalJob(Pawn pawn)
        {
            // find closest point that is dark
            foreach (IntVec3 current in GenRadial.RadialPatternInRadius(20))
            {
                IntVec3 testPos = pawn.Position + current;
                Log.Message("Looking for darkness at   " + current.ToString());
                if (Find.GlowGrid.PsychGlowAt(testPos) == PsychGlow.Dark)
                {
                    if (testPos.Standable() && pawn.CanReach(testPos, PathMode.OnSquare))
                    {
                        Log.Message("Found darkness at : " + current.ToString());
                        return new Job(JobDefOf.Goto, new TargetPack(testPos))
                        {
                            moveSpeed = MoveSpeed.Walk
                        };
                    }
                }
            }
            return null;
        }
    }

bslinger

Another question: is there a way to conditionally make a Pawn render transparent or invisible? I've been trying to figure out the drawing routines but I can't get access to everything through ILSpy and I'm not familiar enough with the Unity Engine to fully understand how its Material class works.

mrofa

All i do is clutter all around.

bslinger

Is there a simple way to just change the texture of a pawn? I couldn't seem to figure it out without having to deal with multiple overlaying meshes, etc.

mrofa

I use

this.cleanMat = MaterialPool.MatFrom("Things/Building/2x1TableClean", true);
this.clutterMat = MaterialPool.MatFrom("Things/Building/2x1Table", true);



public override Material DrawMat
{
get
{
return (!this.TClean) ? this.clutterMat : this.cleanMat;
}
}


To change the texture of a object, not sure if this work on pawns thrugh didnt play with them
All i do is clutter all around.