HEAD: sfllaw/jim's patch for xplc detection broke xplc detection in
[wvapps.git] / twc / src / twcevent.h
blob539be340b6ff9f5402572655376b7d74782bfcd9
1 /* -*- Mode: C++ -*- */
2 #ifndef __TWCEVENT_H
3 #define __TWCEVENT_H
5 #include <time.h>
6 #include <wvcallback.h>
7 #include <wvlinklist.h>
8 #include <wvlog.h>
9 #include <wvtimestream.h>
11 enum TWCEventType {
12 Event = 0,
13 DemandSurrender,
14 WarpInto,
15 WarpOutOf,
16 ShipDestroyed,
17 ShipCaptured,
18 LaunchEscapePod,
19 PodDestroyed,
20 ShipAttackHit,
21 ShipAttackMissed,
22 ShieldsRaised,
23 ShieldsDropped,
24 ShipDocked,
25 ShipUndocked,
26 TractorBeamEngaged,
27 TractorBeamDropped,
28 CargoBeamedFrom,
29 CargoBeamedTo
32 // int parameter is the id of whatever we're talking about in the callback:
33 // ship, player, planet, etc.
34 typedef WvCallback<void, int> TWCEventCallback;
36 struct TWCEvent
38 int idx;
39 time_t interval;
40 bool single;
41 time_t next;
42 TWCEventCallback cb;
43 int id;
46 DeclareWvList(TWCEvent);
48 int event_sorter(const TWCEvent *a, const TWCEvent *b);
50 class TWCEventHandler : public WvTimeStream
52 TWCEventList events;
53 WvLog log;
54 public:
55 // use set_timer() to start the handler.
56 TWCEventHandler();
57 virtual ~TWCEventHandler();
59 // Returns index of event.
60 int add_event(TWCEventCallback _cb, int _id, time_t _interval,
61 bool _single);
63 // Remove event by index.
64 void remove_event(int event_idx);
66 virtual void execute();
69 #endif // __TWCEVENT_H