I am trying to implement a custom alert (relates to bug report https://ludeon.com/forums/index.php?topic=30217.0).
I realised I don't need to modify the existing alert but could just add an additional alert in that covers pawns in medical beds. I implemented a new alert with the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using UnityEngine;
using Verse;
namespace Medical_Alert
{
public class Alert_ColonistNeedsTendInBed : Alert
{
private IEnumerable<Pawn> NeedingColonists
{
get
{
return
from p in PawnsFinder.AllMaps_FreeColonistsAndPrisoners
where (HealthAIUtility.ShouldBeTendedNow(p) && RestUtility.InBed(p) && RestUtility.CurrentBed(p).Medical)
select p;
}
}
public Alert_ColonistNeedsTendInBed()
{
this.defaultLabel = "ColonistNeedsTreatment".Translate();
this.defaultPriority = AlertPriority.High;
}
public override string GetExplanation()
{
StringBuilder stringBuilder = new StringBuilder();
foreach (Pawn current in this.NeedingColonists)
{
stringBuilder.AppendLine(" " + current.NameStringShort);
}
return string.Format("ColonistNeedsTreatmentDesc".Translate(), stringBuilder.ToString());
}
public override AlertReport GetReport()
{
Pawn pawn = this.NeedingColonists.FirstOrDefault<Pawn>();
if (pawn == null)
{
return false;
}
return AlertReport.CulpritIs(pawn);
}
}
}
This does not work at all however. Not only does the alert not show up, I get a whole series of other issues:
- "<something> already has short hash" errors on start
- Unable to select a start region after world generation
- (On load save) all vanilla alerts are shown twice on the alert list
I looked around for mods implementing similar functionality to see if I had missed anything and found this one: https://github.com/Aeryl/TempGauge/blob/master/Source/TempGauge/Alert_TemperatureGauge.cs
I can not see any major differences. Yet my mod seems to trigger multiple parts of the game to be loaded twice.
Anyone know what is going on here?