I've been going through the decompiled code, and I've come up with a few things to share. I'll post it here in the form of a commented version of some files, starting with the Incident_MiracleHeal example mod.
This code has been updated slightly, just according to some small suggestions from Visual Studio 2013.
So, would a game-wide commenting project like this of any use to anyone? Please let me know if you can clear up a few things I don't understand about the incident system, like how the storyteller picks incidents from the list of defined incidents.
Code Select
// Include basic system functionality for .NET
using System;
using System.Linq;
// Include required libraries for Rimworld
using UI;
using UnityEngine;
// Create the namespace for your mod classes to reside in
namespace RimWorldTestMod
{
/// <summary>
/// The Incident_MiracleHeal class inherits from the generic IncidentDef class.
/// The IncidentDef class has these inheritable values:
/// public float chance;
/// Effects the odds of this incident actually occuring when the Storyteller finds this incident in the queue.
/// public bool global;
/// Not sure what this does; the only two incidents I have found that do not set this to true are TraderArrivalGeneral and TraderArrivalSlaver.
/// public IncidentFavorability favorability = IncidentFavorability.Neutral;
/// This sets whether this incident is considered good, bad, or neutral for the colony. Probably used by the Storyteller to pick what type of incident to use.
/// public IncidentThreatLevel threatLevel;
/// This sets whether this incident is considered a big threat, small threat, or no threat to the colony. Probably used by the Storyteller to pick incidents.
/// public IncidentPopulationEffect populationEffect = IncidentPopulationEffect.None;
/// This tells the game whether this incident will increase, reduce or have no effect on the population of the colony. Probably used by the Storyteller.
/// public int minRefireInterval;
/// This sets the minimum length of time between this incident being allowed to repeat. Not sure of the units of time though.
/// public bool pointsScaleable;
/// Not sure what points are for and what making them scalable would do.
/// public int uniqueSaveKey;
/// A unique integer defining this incident, so that the incident will still exist between save/load cycles. Prevents incidents that stay active for a time
/// from being cleared cheatily by quiting and reloading.
/// </summary>
public class Incident_MiracleHeal : IncidentDef
{
// TryExecute is the main method of any incident. When the incident is excecuted, this is the method called to do so.
// Arguments: IncidentParms parms
// IncidentParms is an object defined as:
//
//public class IncidentParms : Saveable
//{
// public Thing target;
// public float points = -1f;
// public float maxSquadCost = 99999f;
// public bool forceIncap;
// public void ExposeData()
// public override string ToString()
//}
//
// TryExecute returns TRUE under any non-error outcome. Returning FALSE would indicate an error state.
public override bool TryExecute(IncidentParms parms)
{
// Writes a line to the debugging log, visible ingame in developer mode.
Debug.Log("Test log");
Debug.Log("Map size is " + Find.get_Map().get_Size());
bool flag;
// Uses a Linq (SQL-like) statement to find a random incapacitated Colonist Pawn.
// The 'out flag' argument means that 'flag' will be set to TRUE if a colonist matching those conditions is found.
Pawn pawn = GenLinq.TryRandomElement<Pawn>(
from col in Find.get_ListerPawns().get_Colonists()
where col.get_Incapacitated()
select col, out flag);
// If a random incapped pawn is selected:
if (flag)
{
// Get the amount of missing health from the target, less between 2 and 10.
int num = pawn.healthTracker.get_MaxHealth() - pawn.healthTracker.get_Health() - UnityEngine.Random.Range(2, 10);
// Heal the pawn by the determined amount.
pawn.TakeDamage(new DamageInfo(DamageType.Healing, num));
// Create a letter to be displayed to the player.
Letter letter = new Letter(pawn.get_Name().nick + " has experienced a miraculous recovery!", 1, pawn);
// Deliver the newly created letter.
Find.get_LetterStack().ReceiveLetter(letter);
return true;
}
return true;
}
}
}
This code has been updated slightly, just according to some small suggestions from Visual Studio 2013.
So, would a game-wide commenting project like this of any use to anyone? Please let me know if you can clear up a few things I don't understand about the incident system, like how the storyteller picks incidents from the list of defined incidents.