EventListItem

Overview

The EventListItem extension defines a new EventListItem class (along with appropriate modifications to various EventList classes to enable it to work). At a first approximation, an EventListItem combines the functionanlity of AgendaItems and EventList. An EventListItem can be included amongst other items in an EventList, but will only be used when its isReady condition is true, and will cease to be used once its isDone condition becomes true. It can be defined to become isDone after being used a certain number of uses, and a minimum interval can be set between successive uses of any given EventListItem.

EventListItems can be used with any class of EventList, but are probably most useful in conjunction with ShuffledEventLists.

Usage

Include the eventListItem.t file after the library files but before your game source files.

EventListItems are added to the eventList property (usually) of the EventList defined in the EventListItem's myListObj property. Instead of defining the myListObj property explicitly, we can simply locate EventListItems in their associated EventList using the + syntax. For example, suppose we have a ShuffledEventList that displays a list of atmospheric strings for a room. We could add an EventListItem to it thus:

startroom: Room, ShuffledEventList 'The Starting Location'
	"This is the starting location, blah, blah, blah. "
	
	eventList =     
    [
        'This room has quite an atmosphere. ',
        'What an atmospheric room! ',
        'You can\'t help noticing the atmosphere here. ',
        'Okay, so what else do you expect to happen here? '
    ]
;

+ EventListItem
	invokeItem = "The key may help you escape the atmosphere here. " 
	
	isReady = silverKey.moved
	
	minInterval = 5
	
	maxFireCt = 2
;   
 

This defines an EventListItem that won't be used until the silverKey has been moved, and which will then display the text "The key may help you escape the atmosphere here. ", but only twice in all with at least five turns in between occurrences.

Using the abbreviated alias ELI for the EventListItem class together with the EventListItem template defined in advLite.h, we could abbreviate the definition of EventListIem here to:

+ ELI ~(silverKey.moved) +5 *2 "The key may help you escape the atmosphere here. ";

This illustrates the basic usage; we move next to some of the detail.


Properties and Methods of EventListItem

The following are the properties and methods of EventListItem that are intended for direct use by game authors(there are some others which are primarily intended to for the internal use of the extension to support the implementation of this class, but we won't include them here):

There are all a number of EventListItem properties that game code may wish to query but should change only with great care, if at all (since they are meant to be maintained by the code in this extension):


Customising EventLists for Use with EventListItem

This extension makes a number of minor modifications to EventList and some of its subclasses to faciliate the use of the EventListItem class. To a large extent curious users can be left to inspect these in the eventListItem.t source file (perhaps via the Library Reference File), but there is one method and one property that should be mentioned here.

The resetList() method can be called on an EventList to remove any spent (isDone = true) EventListItems from its eventList. This is probably only ever necessary in an EventList that contains so many EventListItems that the presence of spent ones (through which code may nevertheless have to iterate) is slowing things down too much.

The resetEachCycle property (which defaults to nil) can be overridden to true on an EventList so that it calls resetList() at appropriate intervals (roughly speaking, each time the EventList has iterated through every item in its eventList). Whether this is advantageous can only be determined by experimentation in any given game, since the reduced overhead resulting from clearing out spent EventListItems may be counteracted by the increased overhead of clearing them out. If in doubt, this is probably best left at nil.


Convenient Shorthand

To save typing, EventListItem can be abbreviated to ELI (the extensions defines class ELI: EventListItem;).

The clase ELI1 can be used as a shorthand way of defining an EventListItem with a maxFireCt of 1.

EventListItems can be defined using the following template (itself defined in advlite.h):

EventListItem template @myListObj? ~isReady? +minInterval? *maxFireCt? "invokeItem"? ;

This covers most of what you need to know to use this extension. For additional information see the source code and comments in the eventListItem.t file.