2.2 KiB
Attention Lock
Note: at this time, none of the following is implemented.
Attention lock is a new mechanism that is used when you want to force the player to give his undivided attention to a single activity. Attention lock is particularly relevant for turn-based combat. Let’s say you have a turn-based combat in progress. You don’t want the player to wander away and grow flax when it’s his turn to attack.
The attention lock mechanism can affect the following aspects of the game:
- Stops the player from walking around (or walking away).
- Stops the player from clicking on unrelated sprites.
- Hides the gui interfaces of unrelated sprites.
- Forces the gui of a sprite to appear even if the user didn’t click on that sprite.
- Directs the camera to point at a specific place, or a specific object.
Enabling Attention Lock
The mechanism is as follows: the player sprite has a single field, actor.attention, which is a pointer to a sprite that is trying to hold the player’s attention. There is a second field, actor.attentionID, which must be equal to place.attentionID of the attention-holding sprite. If attentionID doesn’t match, then actor.attention field is considered no longer valid, and the attention is considered to be not held. With that protocol, it is easy to implement these functions:
-
function attentionClear(place)
- Release the attention of all sprites paying attention to place.
- Implementation: set attentionID to a new unique ID.
-
function attentionHolder(actor)
- Return the ID of the sprite holding actor’s attention.
- Implementation: returns actor.attention after verifying attentionID match.
-
function attentionGrab(place, actor):
- Cause place to grab the attention of actor.
- Implementation: sets actor.attention to place, copies attentionID to actor.
This is designed to be resilient to bugs: let’s say a battleground is holding the attention of some actor. If the battleground gets bulldozed, attention is implicitly released. Or if the battleground starts a new battle, attention of previous combatants would be implicitly released. In short, it should be pretty easy to clean up messes caused by buggy sprites grabbing attention.