Events project
From OPU Wiki
Due to massive problems with the exported Outpost triggers and groups, i've decided to start on a new project called "Outpost 2 Events"
It'll be coding project, but i will put all documentation online on the wiki pages of the OPU.
The OP2Events use the IUnit library.
| Table of contents |
Introduction
In making the event system saveable, i have to write my own memory-management subsystem, that handles the creation of those event structures. Since OP2 MUST know upfront (when the mission starts) how many bytes are in the save-section, i have to create a large enough memory block that can support a lot of events, BUT it also makes this event-system less perfect, as you cannot create more events then the memoryblock-size permits.
For now, i've set the number of event pointers in the array to 512 (not that it will ever be reached), and the space allocated for event structures (and data) to 32kB (0x8000). This could fit 2048 events with 4 DWORDs of data (16 bytes) for each event. I am unsure at this point how much data an event will have, so i cannot yet give an estimate on the actual number of possible events. Memory will be allocated dynamically in blocks of 16 bytes: if an event is smaller, the left over bytes are unused; if it's larger, more than 1 block is used, decreasing the maximum number of events possible. The base class has 15 bytes of data, so most events will consist of 2 datablocks (32 bytes).
Using full source, the amount of allocateable memory can be changed by simply setting an other value to the #define in the _memory.h
When using headers (in combination with a static library), the user cannot change the size by editing. In this case i will supply seperate libraries with different memory-table sizes.
New files
The list below shows all files used to build OP2Events. The public package will only include the header files with the library. When using the OP2Events library, do NOT include the GetSaveRegions function in your own source: it is already included in the OP2Events library.
| source file | header file | Description |
| Events.h | main header, calls all necessary headers | |
| _memory.cpp | _memory.h | Memory handling routines |
| _compare.cpp | _compare.h | contains a function for using compare_mode |
| _save.cpp | _save.h | Contains GetSaveRegions function |
| OPEvent.cpp | OPEvent.h | OP2Event base class definition |
| CountEvent.cpp | CountEvent.h | A counting event simular to CountTrigger |
| DamagedEvent.cpp | DamagedEvent.h | Fires when a certain amount of units from a group have been destroyed (50,75 or 100%) |
| OperationalEvent.cpp | OperationalEvent.h | A counting event simular to OperationalTrigger |
| PointEvent.cpp | PointEvent.h | Fires when a unit is at a location |
| RectEvent.cpp | RectEvent.h | Fires as soon as a unit enters a rect |
| ResearchEvent.cpp | ResearchEvent.h | Fires when a research topic is done |
| ResourceEvent.cpp | ResourceEvent.h | Fires when a resource reaches a certain level |
| TimerEvent.cpp | TimerEvent.h | A timer event simular to TimeTrigger |
| MyEvent.cpp | MyEvent.h | Basic event descendent. Copy the file, and recode it to include custom event functionality |
| OP2extra.cpp | OP2extra.h | OP2 extra's, contains usefull functions |
| ImageHlp.dll | ImageHlp.lib | Is part of Windows (needed by _save) |
Events
Standard
| OP2Event | Base class for all events |
| TimerEvent | simular to TimeTrigger |
| CountEvent | simular to CountTrigger |
| OperationalEvent | simular to OperationalTrigger |
| RectEvent | simular to RectTrigger |
| PointEvent | simular to PointTrigger |
| DamagedEvent | simular to DamagedTrigger |
| ResearchEvent | simular to ResearchTrigger |
| ResourceEvent | simular to ResourceTrigger |
Additional
| GroupCountEvent | extention of the CountEvent |
| NotRectEvent | opposite of RectEvent |
| UnitDiedEvent | fires when the supplied unit dies |
| LightsEvent | fires when the first vehicle turns on its lights |
Limitations
- The memory segment used to store events can handle 2048 memory blocks. With an average size of 2 blocks, it should be able to store roughly 1000 events. See also next limitation!
- The library has a hard-limit for maximum number of events: 512 (could change in later versions)
- HasFired can count to 65535. Although the event can still continue to fire with no problems whatsoever, the counter will start again from 0
How to add your own event
See also: Category_talk:Events
