Plan for raising NPC-per-map limits
NPC definitions[edit]
-
Store NPC pictures in an array of memory buffers, rather than an allmodex screen page(done) -
Optimize NPC picture array to behave as a cache, only storing each set once, and automatically adding new entries when alter NPC changes an NPC's picture(done) -
Update the N lump.(done)-
store record size in BINSIZE.BIN(done) -
get rid of 1920 wasted bytes in each record(done)
-
-
Update all code that assumes that exactly 36 NPCs exist-
take special care that accessing non-existent NPC IDs <= 35 from a plotscript fails gracefully (why was this a problem?) (Not sure, since accessing a non-existent NPC ID <= 35 does nothing anyway)(N/A)
-
-
Increase the NPC limit(done) -
Increase the limit even more!(done)
NPC locations[edit]
-
Convert custom to use NPCInst objects instead of an array(done) - Replace the L lump with a RELOAD lump. See L
- Update all code that assumes that exactly 300 NPC instances exist, including RSAV saving/loading
-
Update code that saves/loads temporary map state(not needed) - Deal with scripting back compat issues (see below)
- Raise NPC instance limit (into at least the thousands range) or ideally remove it completely
Too many extra NPCs will have a performance impact, on display, collision-checking, and other things like NPC zone triggers. In order to support huge numbers of NPCs on a map some optimisation might be needed.
Scripting back-compatibility[edit]
Unfortunately scripts sometimes make the following assumptions:
- All NPC references are integers in the range -1 to -300
- NPCs with lower references are drawn on top (example: npc above). This only happens in the Walkabout Layering option is not the new "Together"
- "Create NPC" assigns references starting from -300, while NPCs placed on the map editor start from -1
It's going to be tricky to preserve these assumptions while increasing the limit. One option is to use the old scheme for assigning references when there are less than 300 NPCs on a map, and switch to simple first-unused-reference counting down from -300 when there are more.
Another option is to only allow more than 300 NPCs when the walkabout sort order is set to "Together".
Ultimately we want to make NPC references objects which can be converted to integers rather than plain integers.
Raising the NPC instance limit may also fix game bugs. SoJ uses over 300 NPCs on one map. There is a special kludge in "create npc" for this case which overwrites a tag-disabled NPC when there are no free NPC references left. (This kludge was added because "create npc" historically worked that way)