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