Note that layer pointer in a pattern spec depends on which network the environment is being applied to. Thus, there is some checking that takes place when an event is being applied to the network to make sure that the layer pointers are up-to-date. Along these same lines, any time the events or patterns are edited, the layer pointers are reset, with the idea being that they might have changed where the patterns are being applied to.
The basic set of functions can be found in the `src/pdp/enviro.h' file. They are fairly straightforward.