Adonthell  0.4
time_event Class Reference

The time event executes the attached script or callback at a certain point in game-time. More...

#include <time_event.h>

Inheritance diagram for time_event:
Collaboration diagram for time_event:

Public Member Functions

u_int32 time () const
 Get the event's "alarm" time, i.e. More...
 
Initialization
 time_event (const string &time, bool absolute=false)
 Create a new time event. More...
 
 time_event ()
 Standard constructor. More...
 
 time_event (const u_int32 &time)
 Create a new time event. More...
 
void set_repeat (const string &interval, s_int32 count=-1)
 Set whether the event should be raised at fixed intervals. More...
 
Event Handling
bool equals (const event *evnt)
 Compare two time events for equality. More...
 
s_int32 execute (const event *evnt)
 Executes the script associated with this time event. More...
 
Loading / Saving
void put_state (ogzstream &out) const
 Saves the basic event data (such as the type or script data) to a file. More...
 
bool get_state (igzstream &in)
 Loads the basic event date from a file. More...
 
Pausing / Resuming execution
void pause ()
 Disable the event temporarily. More...
 
void resume ()
 Re-enable an event that has been paused. More...
 
- Public Member Functions inherited from event
 event ()
 Constructor. More...
 
virtual ~event ()
 Destructor. More...
 
void clear ()
 Cleanup. More...
 
void set_script (string filename, PyObject *args=NULL)
 Sets a script to be executed whenever the event occurs. More...
 
void set_callback (PyObject *callback, PyObject *args=NULL)
 Sets a python function/method to be executed whenever the event occurs. More...
 
void set_callback (const Functor0 &callback)
 Sets a C function/C++ method to be executed whenever the event occurs. More...
 
u_int8 type () const
 Get the event's type. More...
 
const string & id () const
 Get the event's id. More...
 
void set_id (const string &id)
 Assign an id to the event, so it may be retrieved from an event_list later on, without having a pointer to it. More...
 
bool registered () const
 Test whether the event is registered with the event handler. More...
 
void set_registered (bool reg)
 Set whether the event is registered with the event handler. More...
 
void set_list (event_list *list)
 Tell the whether it is kept in an event_list. More...
 
s_int32 repeat () const
 Return whether this event should be repeated. More...
 
void set_repeat (s_int32 count)
 Set whether this event should be repeated. More...
 
bool is_paused () const
 Check whether the event is temporarily disabled or not. More...
 

Additional Inherited Members

- Protected Member Functions inherited from event
s_int32 do_repeat ()
 Decrease the event's repeat count and return the number of repeats left. More...
 
- Protected Attributes inherited from event
u_int8 Type
 Event type - see enum above. More...
 
string Id
 (Optional) Id of the event More...
 
u_int8 Action
 What happens if the event occurs - see enum above. More...
 
bool Registered
 Whether the event is registered with the event handler. More...
 
bool Paused
 Whether the event temporarily disabled or not. More...
 
s_int32 Repeat
 Defines how often the event should be repeated. More...
 
py_objectScript
 The Python script accociated with this event. More...
 
PyObject * Args
 The arguments passed to the script. More...
 
py_callbackPyFunc
 Python callback that may be executed instead of the script. More...
 
Functor0 Callback
 C++ callback that may be executed when the event gets triggered. More...
 
event_listList
 The event_list this event is kept in. More...
 

Detailed Description

The time event executes the attached script or callback at a certain point in game-time.

This point can either be relative to the current time, or absolute in time. In any case, this point should be in the future. Time event with an alarm time in the past will be triggered at once.

Definition at line 38 of file time_event.h.

Constructor & Destructor Documentation

◆ time_event() [1/3]

time_event::time_event ( const string &  time,
bool  absolute = false 
)

Create a new time event.

Parameters
timeThe time when the event should be raised. The string specifies week, day, hour, minute and 1/10 minute in the format "<number>w<number>d<number>h<number>m<number>t". If a number is 0, it can be omitted.
absoluteDecides whether the given time is relative from now on, or an absolute time

Definition at line 30 of file time_event.cc.

◆ time_event() [2/3]

time_event::time_event ( )
inline

Standard constructor.

Definition at line 62 of file time_event.h.

◆ time_event() [3/3]

time_event::time_event ( const u_int32 time)
inline

Create a new time event.

This constructor is primarily used for raising time events.

Parameters
timeThe "alarm" time in gametime minutes.

Definition at line 74 of file time_event.h.

Member Function Documentation

◆ set_repeat()

void time_event::set_repeat ( const string &  interval,
s_int32  count = -1 
)

Set whether the event should be raised at fixed intervals.

Parameters
intervalThe time between two occurences of the event.
countThe number of times the event shall be repeated. Specify -1 to repeat it an unlimited number of times.

Definition at line 40 of file time_event.cc.

◆ equals()

bool time_event::equals ( const event evnt)
inlinevirtual

Compare two time events for equality.

Parameters
evntThe time event to compare this to.
Returns
True if the two events equal, false otherwise.

Implements event.

Definition at line 103 of file time_event.h.

◆ execute()

s_int32 time_event::execute ( const event evnt)
virtual

Executes the script associated with this time event.

If the event repeats it is re-registered with the event handler.

Parameters
evntThe event that triggered this time event.
Returns
The number of times the event needs to be repeated.

Implements event.

Definition at line 47 of file time_event.cc.

◆ put_state()

void time_event::put_state ( ogzstream out) const
virtual

Saves the basic event data (such as the type or script data) to a file.

Parameters
outfile where to save the event.

Reimplemented from event.

Definition at line 99 of file time_event.cc.

◆ get_state()

bool time_event::get_state ( igzstream in)
virtual

Loads the basic event date from a file.

Parameters
infile to load the event from.
Returns
true if the event could be loaded, false otherwise

Reimplemented from event.

Definition at line 111 of file time_event.cc.

◆ pause()

void time_event::pause ( )
virtual

Disable the event temporarily.

As long as it in this state, the event will neither be executed, nor will its repeat-count change.

The alarm time of relative time events will be prolongued be the time the event was paused. Absolute events will only be deferred until they are resumed.

Reimplemented from event.

Definition at line 81 of file time_event.cc.

◆ resume()

void time_event::resume ( )
virtual

Re-enable an event that has been paused.

Absolute events that are past their alarm time are executed at once.

Reimplemented from event.

Definition at line 90 of file time_event.cc.

◆ time()

u_int32 time_event::time ( ) const
inline

Get the event's "alarm" time, i.e.

the time when it needs to be executed.

Returns
the "alarm" time in 1/10 gametime minutes.

Definition at line 173 of file time_event.h.


The documentation for this class was generated from the following files: