Implementing logical puzzles for Stendhal
Stendhal code design
This page describes a concept for implementing logical puzzles in Stendhal.
This article describes a future concept. It may still have some open issues and it was not decided, yet, whether to implement it in this way.
Basic Objectives
- It should be easy for content creators to define logical puzzles.
- Puzzles should consists of basic building blocks (such as switches, doors)
Entities
Entities are basic building blocks that can be used by puzzle creators.
General properties
All entities have these general properties:
- active
- values: true, false
- default: false
- An entity may be activated. For example a player activate a pressure plate by stepping on it, which in turn activates (opens) a door.
- enabled
- values: true, false
- default: true
- An entity only reacts to input, if it is enabled. For example a switch will ignore all player actions, if it is disabled. A door will ignore the state of its associated switches, if it is disabled. Entities should indicate disabled state visibly and/or audibly.
Timer
- time
- datatype: integer
- required
- The number of seconds until an action occurs.
- target
- datatype: entity reference
- required
- The target entity to modify
- propname
- datatype: string
- required
- The name of the property of the target entity that will be changed
- propvalue
- datatype: string
- required
- The new value of the property of the target entity
Switches
- Different kinds of switches and objects which contain a switch mechanism.
Pressure plate
A pressure plate is a tile with a switch, that gets active when a player steps on it.
Weight plate
A weight plate is a tile with a switch that only gets active when the exact weight is put on it.
Weights
Weights are objects with a special weight. They exist in different sizes with different weight and have to be put on weight plates to activate them.
Wall switch
A wall switch is an entity with a switch mechanism, assembled to a wall. It can have different forms, such as a huge lever or a pushbutton.
Moveable block
A moveable block can be pushed or dragged on the floor and fits to a moveable block receiver.
Moveable block receiver
A movable block receiver is an entity set on the floor with a switch mechanism that gets active when a moveable block is pushed on it.
Passive Entities
- These entities don't contain a switch mechanism itself, but are affected by one.
Door
A door is a barrier that prevents players from crossing unless the switch for opening it is active.
Switch Mechanisms
- These are different mechanisms for switches. Pushing is to understand as triggering, as the mechanisms work with different kind of switches, not only with Push-Buttons.
Tap-On Switch
Tap-Switch, which is active when pushed continuously and inactive when released.
Toggle Switch
On/Off-Switch, which is active when pushed and stays active after releasing. Gets inactive when pushed again.
Linked-Toggle Switch
On/Off-Mechanism, works like a Toggle Switch, but has two seperated but linked switches which affects each other. One of the linked switches (the On-Switch) is inactive, the other one (the Off-Switch) active by default. When switching the On-Switch to active, the Off-Switch switches automatically to inactive. Only the inactive switch can be pushed, pushing the active switch again has no effect.
Multi Switch
More-way-switch, is inactive in the default setting and can be pushed in different directions to change the output number.
Incremental Switch
More-way-switch, is inactive in the default setting and increases the output number by 1, every time when pushed. After reaching the maximum output number it switches to inactive again.
Delay-On Switch
Time-delayed switch, delays the time before switching to active after pushing.
Delay-Off Switch
Time-delayed switch, switches immediately to active when pushed, but switches back to inactive after the delay.
Backend implementation
- Although most puzzles will be confined to one zone each, the backend must support multi zone puzzles.
- Entity references default to entities in the same zone, unless an optional zone name was specified.
- Event bus or listeners
- Events are fired on change of a property (setting a property to the value, which it already had, must not fire an event)
- Limit number of nested events to prevent infinite loops