--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
with Scripting; use Scripting;
private with Scripting.Evaluators;
package Entities.Triggers is
-- A Trigger is an entity that executes a script when a condition is met at
-- a configurable time. For example, when a player collides with a trigger,
-- a new level may be loaded.
type Trigger is abstract new Entity and Evaluation_Node with private;
type A_Trigger is access all Trigger'Class;
-- A class pattern that matches all trigger class ids registered in the
-- entity factory.
CLASS_PATTERN : constant String := "Entities.Triggers.*";
private
use Scripting.Evaluators;
-- Valid values for the "When" attribute are:
-- OnActivate - The player manually activated a trigger
-- OnLoad - The world was loaded
-- OnTouch - The player touched the trigger (once per collision)
ATTR_WHEN : constant String := "When"; -- when the trigger may trip
ATTR_CONDITION : constant String := "Condition"; -- the necessary condition
ATTR_ACTION : constant String := "Action"; -- what the trigger will do (a script)
type Trigger is abstract new Entity and Evaluation_Node with
record
activatable : Boolean := True;
-- ** the following fields are not streamed **
evaluator : A_Evaluator := Create_Evaluator;
activator : A_Entity; -- entity that activated the
-- trigger (if any); set only
-- while executing the action
end record;
-- Raises an exception if 'icon' can't be found in library 'libName'.
procedure Construct( this : access Trigger;
libName : String;
icon : String );
procedure Delete( this : in out Trigger );
-- This is called when the trigger's action script is evaluated, to
-- implement the behavior of any script functions the map designer wrote.
-- It evaluates function 'name' (as a script function), given 'arguments'.
-- If the trigger doesn't recognize the function, it will ask its World to
-- evaluate it. If function 'name' isn't recognized at all, then Null will
-- be returned. The default implementation of this doesn't implement any
-- functions.
--
-- Override this function as necessary to allow triggers to do things when
-- they're activated. Call this function from the overriding implementation
-- if 'name' is not recognized.
function Evaluate_Function( this : access Trigger;
name : String;
arguments : Value_Array ) return Value_Ptr;
-- Evaluates the symbol 'symbol' (as a script variable), resolving its value
-- and returning it. If the trigger doesn't recognize 'symbol', it will ask
-- the world to resolve the symbol. If the symbol can't be resolved, Null
-- will be returned.
function Evaluate_Symbol( this : access Trigger;
symbol : String ) return Value_Ptr;
procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Trigger );
for Trigger'Read use Object_Read;
procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Trigger );
for Trigger'Write use Object_Write;
-- Called when the trigger is manually activated by entity 'activator'.
-- Don't override this procedure.
procedure On_Activate( this : access Trigger;
activator : not null A_Entity );
-- Called when the trigger is touched by an entity. Don't override this
-- procedure.
procedure On_Collide( this : access Trigger; e : not null A_Entity );
-- Called when the triggers's world is loaded from disk. Don't override this
-- procedure.
procedure On_Load( this : access Trigger );
end Entities.Triggers;