Skip to content

SlavRim/RimTerritory

Repository files navigation

How to use

  1. Clone this repo to your project.
  2. Add RimTerritory.csproj as reference.

Before adding new features to your project, update repo(fetch and pull).

Example of usage(May be outdated):

  1. Create/use Thing Class.
public class MyThing : Thing
{
    public Territory Territory
    {
        get;
        protected set;
    }
    public Territory.Locator<Pawn>? PawnLocator;
}
  1. Add handlers.
protected void PawnEnter(Pawn pawn)
{
    // Pawn enter
}

protected void PawnExit(Pawn pawn)
{
    // Pawn exit
}

protected void PawnStay(Pawn pawn)
{
    // Pawn stay
}
  1. Add initialization of territory.
public override void SpawnSetup(Map map, bool respawningAfterLoad)
{
    base.SpawnSetup(map, respawningAfterLoad);

    // Initialization of territory
    Territory ??= new Territory.Radial(this, Radius);
    var events = Territory.PawnEvents;
    events.OnEnter += PawnEnter;
    events.OnExit += PawnExit;
    events.OnStay += PawnStay;
    PawnLocator = new(Territory, ThingRequest.ForGroup(ThingRequestGroup.Pawn))
    {
        Predicate = pawn => !pawn.health.Dead
    };
}
  1. Add finalization of territory.
public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
{
    base.DeSpawn(mode);

    Territory = null;
    PawnLocator = null;
}
  1. Add ticking of locator.
public override void Tick()
{
    base.Tick();
    PawnLocator?.Tick();
}
  1. Add ExposeData.
public override void ExposeData()
{
    base.ExposeData();
    Territory?.ExposeData();
}

Code is still in testing stage, consider report issues if you find any!

About

Territories implementation for modding.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages