Best way to call debug function in code

Started by Senyaak, June 16, 2019, 03:11:10 AM

Previous topic - Next topic

Senyaak

I'm making mode which triggers different events(e.g. drop pod, kill pawn, call raid etc). This all events are listen in debugging panel . But I can't found how should trigger them from code.
Can anyone help with that?

jetharius

All the debug events are triggered with worker classes for each specific event for example an infestation:
       public class IncidentWorker_Infestation : IncidentWorker
which is checked with a evaluation:
      protected override bool CanFireNowSub(IncidentParms parms)
      {
         Map map = (Map)parms.target;
         IntVec3 intVec;
         return base.CanFireNowSub(parms) && HiveUtility.TotalSpawnedHivesCount(map) < 30 && InfestationCellFinder.TryFindCell(out intVec, map);
      }
then executed:
            protected override bool TryExecuteWorker(IncidentParms parms)
      {
         Map map = (Map)parms.target;
         int hiveCount = Mathf.Max(GenMath.RoundRandom(parms.points / 220f), 1);
         Thing t = this.SpawnTunnels(hiveCount, map);
         base.SendStandardLetter(t, null, new string[0]);
         Find.TickManager.slower.SignalForceNormalSpeedShort();
         return true;
      }

Depending on how you want to execute the events, manually running the IncidentWorker_Infestation.TryExecuteWorker() would manually spawn a infestation.  I'm pretty sure all the other events run off the same classes and methods to some degree.  I hope this gives you some direction.


Senyaak


Mehni

Those are protected methods, so you'll run into some issues there. The correct way of triggering an event is through the Worker in the Def.


//IncidentDef def = IncidentDefOf.RaidEnemy;
// or
//IncidentDef def = DefDatabase<IncidentDef>.GetNamed("MyDefName");

def.Worker.TryExecute();