36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 * POSSIBILITY OF SUCH DAMAGE. |
38 * POSSIBILITY OF SUCH DAMAGE. |
39 */ |
39 */ |
40 |
40 |
41 #define __EVENTS_CXX__ |
|
42 #include <stdlib.h> |
41 #include <stdlib.h> |
43 #include <stdio.h> |
42 #include <stdio.h> |
44 #include "common.h" |
43 #include "main.h" |
45 #include "scriptreader.h" |
44 #include "scriptreader.h" |
46 #include "str.h" |
45 #include "str.h" |
47 #include "events.h" |
46 #include "events.h" |
48 |
47 |
49 EventDef* g_EventDef; |
48 EventDef* g_EventDef; |
50 |
49 |
51 // ============================================================================ |
50 // ============================================================================ |
52 // Read event definitions from file |
51 // Read event definitions from file |
53 void ReadEvents () { |
52 void ReadEvents () { |
54 ScriptReader* r = new ScriptReader ("events.def"); |
53 ScriptReader* r = new ScriptReader ("events.def"); |
55 g_EventDef = NULL; |
54 g_EventDef = null; |
56 EventDef* curdef = g_EventDef; |
55 EventDef* curdef = g_EventDef; |
57 unsigned int numEventDefs = 0; |
56 unsigned int numEventDefs = 0; |
58 while (r->Next()) { |
57 while (r->Next()) { |
59 EventDef* e = new EventDef; |
58 EventDef* e = new EventDef; |
60 e->name = r->token; |
59 e->name = r->token; |
61 e->number = numEventDefs; |
60 e->number = numEventDefs; |
62 e->next = NULL; |
61 e->next = null; |
63 |
62 |
64 // g_EventDef becomes the first eventdef |
63 // g_EventDef becomes the first eventdef |
65 if (!g_EventDef) |
64 if (!g_EventDef) |
66 g_EventDef = e; |
65 g_EventDef = e; |
67 |
66 |
90 // Finds an event definition by index |
89 // Finds an event definition by index |
91 EventDef* FindEventByIdx (unsigned int idx) { |
90 EventDef* FindEventByIdx (unsigned int idx) { |
92 EventDef* e = g_EventDef; |
91 EventDef* e = g_EventDef; |
93 while (idx > 0) { |
92 while (idx > 0) { |
94 if (!e->next) |
93 if (!e->next) |
95 return NULL; |
94 return null; |
96 e = e->next; |
95 e = e->next; |
97 idx--; |
96 idx--; |
98 } |
97 } |
99 return e; |
98 return e; |
100 } |
99 } |
101 |
100 |
102 // ============================================================================ |
101 // ============================================================================ |
103 // Finds an event definition by name |
102 // Finds an event definition by name |
104 EventDef* FindEventByName (str a) { |
103 EventDef* FindEventByName (string a) { |
105 EventDef* e; |
104 EventDef* e; |
106 for (e = g_EventDef; e->next != NULL; e = e->next) { |
105 for (e = g_EventDef; e->next != null; e = e->next) { |
107 if (!a.icompare (e->name)) |
106 if (a.to_uppercase() == e->name.to_uppercase()) |
108 return e; |
107 return e; |
109 } |
108 } |
110 |
109 |
111 return NULL; |
110 return null; |
112 } |
111 } |