[A17] C# help - prisoners, infestations and traps

Started by BookBurner, August 24, 2017, 03:21:15 AM

Previous topic - Next topic

BookBurner

Hi, I am writing a trap mod which has several kinds of traps and one generic function for deciding which pawn can be hit by it or not. I have issues with method which decides this. Function is as follows.

public static bool CoreKnowsOfTrap (Pawn p, Faction f)
{
    Lord lord = p.GetLord ();
    if (p != null && p.def.race.Animal && p.Faction == Faction.OfPlayer && !p.InAggroMentalState) { // tamed animals
        return true;
    } else if (p != null && p.def.race.Animal && lord != null) { // caravan animals
        return true;
    } else if (p != null && p.def.race.Animal) {
        return false;
    }
    if (p.guest != null && lord != null && (lord.LordJob is LordJob_FormAndSendCaravan || lord.LordJob is LordJob_AssistColony || lord.LordJob is LordJob_VisitColony)) { // caravans, friendlies, visitors
        return true;
    }
    if (p.guest != null && p.guest.released) { // released prisoners
        return true;
    }
    if (p.guest != null && p.guest.IsPrisoner && !p.guest.PrisonerIsSecure && !p.guest.released) { // escaping prisoners
        return false;
    }
    if (p.Faction != null && !p.Faction.HostileTo (f)) { // non hostiles
        return true;
    }
    if (p.Faction.IsPlayer && p.RaceProps.Humanlike) { // player humanlike pawns
        return true;
    }

    return false;
}


and usage is here:

private bool KnowsOfTrapFence (Pawn p)
{
    return fenceCore.CoreKnowsOfTrap (p, base.Faction);
}



pawn is the pawn thet is on the trap, base.faction is a faction of trap (basically player faction)

I have a problem with released prisoners, they are not hostile but they are still hit by the trap and I can't wrap my head around how to differenciate released prisoner from escaped prisoner. So escaped prisoner is killed by trap but released prisoner isn't.

same thing with animals from infestations, I wasn't able to designate those as hostiles for the trap either.

Anyone solved something like this? Google is unfortunately silent... :)

BookBurner

pretty please? :D

or is there a link to some sort of documentation about RimWorld object types?

CannibarRechter

I can't really help with your problem, but since you are asking about rimworld object types, I'm surely assuming you know how to open/decompile rimworld and explore all the code with ILSpy, yeah?
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

mrofa

All i do is clutter all around.

Fereal