The general idea I going for in my suggestion was something like:
Java:
if(this.isPlayer() || (this.getCell() == Main.game.getPlayer().getCell() )
{
for(AppliedStatusEffect appliedSe : new ArrayList<>(statusEffects))
{
[code]
}
}
Gotcha! The approach I took was a bit different, but accomplished a similar goal:
Java:
for(NPC npc : Main.game.getCharactersPresent()) {
npc.statusUpdateOnDemand();
}
I put this in
endTurn()
, in Game.java.
With my branch I introduced status priorities: ALWAYS and ONDEMAND, with priorities of ALWAYS updating regardless of the player's position in the world and ONDEMAND only updating when players share a tile with that NPC (or the lastUpdated field gets close to overflowing). The priority defaults to ONDEMAND, but can be freely overridden both in hardcoded and XML status effects.
One of the main drawbacks is that it's still looping through all of the statuses every. single. turn. but with the main difference being that it doesn't act on the ONDEMAND ones.
There's always going to inevitably be some sort of issue. Like, I just realized that using a scheduler won't necessarily work in all cases, since it's possible that some global (or ALWAYS priority) statuses are going to need to update every turn. Pregnancy doesn't, but that doesn't mean that something won't come along later that does.
Here's kind of what I currently have in mind: a status priority system, a scheduler, and your zone-based system to limit the loaded NPC count. The status priority would allow for ONDEMAND statuses (which only fire off when the player shares a tile with the NPC) and ALWAYS statuses (the NPC remains loaded, with the status event firing off every turn). Statuses like pregnancy would be reimplemented as scheduled events. This would allow the NPC to be unloaded as normal and reloaded on-demand when the event is resolved (if the player impregnates an NPC in Dominion, then travels to Elis, the NPC would be unloaded until their due date). Finally, the zone-based system would ensure that only the NPCs in the same general region as the player were active and in memory, to reduce the overall memory cost.
Rather than storing the amount of time that passed since an NPC was last updated like my current implementation does (that won't be possible if the object is unloaded, after all) we would save the
time that they were last updated, then work out what the numeric delta is from that point.
One idea might be to ditch the scheduler system and just use global events for everything. I kind of see the scheduler as being more of a long term goal. I'll also have to see if one already exists (I haven't looked into how the game tracks events like arcane storms, holidays, etc) that could be extended.