events.cxx

changeset 2
bb2c45522eb6
child 3
08cab2b67dce
equal deleted inserted replaced
1:f0c61c204bc8 2:bb2c45522eb6
1 /*
2 * botc source code
3 * Copyright (C) 2012 Santeri `Dusk` Piippo
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * 3. Neither the name of the Skulltag Development Team nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 * 4. Redistributions in any form must be accompanied by information on how to
18 * obtain complete source code for the software and any accompanying
19 * software that uses the software. The source code must either be included
20 * in the distribution or be available for no more than the cost of
21 * distribution plus a nominal fee, and must be freely redistributable
22 * under reasonable conditions. For an executable file, complete source
23 * code means the source code for all modules it contains. It does not
24 * include source code for modules or files that typically accompany the
25 * major components of the operating system on which the executable file
26 * runs.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
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
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 #include <stdlib.h>
42 #include <stdio.h>
43 #include "common.h"
44 #include "scriptreader.h"
45 #include "str.h"
46 #include "events.h"
47
48 EventDef* g_EventDef;
49 void ReadEvents () {
50 ScriptReader* r = new ScriptReader ((char*)"events.def");
51 g_EventDef = NULL;
52 EventDef* curdef = g_EventDef;
53 unsigned int numEventDefs = 0;
54 while (r->Next()) {
55 EventDef* e = new EventDef;
56 e->name = r->token;
57 e->number = numEventDefs;
58 e->next = NULL;
59
60 // g_EventDef becomes the first eventdef
61 if (!g_EventDef)
62 g_EventDef = e;
63
64 if (!curdef) {
65 curdef = e;
66 } else {
67 curdef->next = e;
68 curdef = e;
69 }
70 numEventDefs++;
71 }
72
73 delete r;
74 printf ("%d event definitions read.\n", numEventDefs);
75 }
76
77 void UnlinkEvents (EventDef* e) {
78 if (e->next)
79 UnlinkEvents (e->next);
80 delete e;
81 }
82
83 EventDef* FindEventByIdx (unsigned int idx) {
84 EventDef* e = g_EventDef;
85 while (idx > 0) {
86 if (!e->next)
87 return NULL;
88 e = e->next;
89 idx--;
90 }
91 return e;
92 }
93
94 EventDef* FindEventByName (str a) {
95 a.tolower();
96
97 EventDef* e;
98 for (e = g_EventDef; e->next != NULL; e = e->next) {
99 str b = e->name;
100 b.tolower();
101
102 if (!a.compare (b))
103 return e;
104 }
105
106 return NULL;
107 }

mercurial