Skip to content

Latest commit

 

History

History
4 lines (3 loc) · 1.56 KB

EnmIdIter.md

File metadata and controls

4 lines (3 loc) · 1.56 KB

Enemy IDs and enemy iterators

Enemy IDs are something that exists in the vanilla game, and can be accessed with the ID variable. There are also a few ECL instructions that allow interacting with the enemy of a given ID. However, there is an issue with IDs - they are stored in a linked list. This means that whenever you want to do something with enemy that has a given ID, the game iterates over the enemy list to find the enemy you want. Obviously, this can cause performance issues when there are a lot of enemies that interact with one another by using IDs.

Enemy iterators introduced in ECLplus aim to solve this issue to some extent. They are essentially just pointers to nodes of a linked list, which means that accessing the enemy associated with an iterator is fast. However, problems arise when the enemy that an iterator refers to is deleted - the iterator becomes invalid. Of course, this happens with IDs too, but there is a catch - checking whether the ID or an iterator is valid requires looking for it by iterating over the enemy list. For IDs this doesn't matter, since iterating over the list is a part of the process of finding the enemy that the ID refers to. However, in case of iterators, this would reintroduce the issue that they're trying to address. This is why iterators have no run-time checks. Using an invalid iterator is likely to crash the game or cause some unpredictable issues. This is why you should be extra careful with iterators and always ask yourself the question "am I sure that this iterator is guaranteed to be valid?" when you use one.