Ludeon Forums

RimWorld => Mods => Help => Topic started by: BookBurner on August 24, 2017, 03:21:15 AM

Title: [A17] C# help - prisoners, infestations and traps
Post by: BookBurner on August 24, 2017, 03:21:15 AM
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... :)
Title: Re: [A17] C# help - prisoners, infestations and traps
Post by: BookBurner on August 25, 2017, 04:26:57 AM
pretty please? :D

or is there a link to some sort of documentation about RimWorld object types?
Title: Re: [A17] C# help - prisoners, infestations and traps
Post by: CannibarRechter on August 25, 2017, 08:19:05 AM
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?
Title: Re: [A17] C# help - prisoners, infestations and traps
Post by: mrofa on August 25, 2017, 08:22:33 AM
p.isprisoner
Title: Re: [A17] C# help - prisoners, infestations and traps
Post by: Fereal on August 26, 2017, 02:44:21 PM
GenHostility.HostileTo()