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 __VARIABLES_CXX__ |
|
42 #include <stdio.h> |
41 #include <stdio.h> |
43 #include <stdlib.h> |
42 #include <stdlib.h> |
44 #include <string.h> |
43 #include <string.h> |
45 #include "common.h" |
44 #include "main.h" |
46 #include "array.h" |
45 #include "containers.h" |
47 #include "bots.h" |
46 #include "bots.h" |
48 #include "botcommands.h" |
47 #include "botcommands.h" |
49 #include "objwriter.h" |
48 #include "objwriter.h" |
50 #include "stringtable.h" |
49 #include "stringtable.h" |
51 #include "variables.h" |
50 #include "variables.h" |
52 #include "scriptreader.h" |
51 #include "scriptreader.h" |
53 |
52 |
54 array<ScriptVar> g_GlobalVariables; |
53 list<ScriptVar> g_GlobalVariables; |
55 array<ScriptVar> g_LocalVariables; |
54 list<ScriptVar> g_LocalVariables; |
56 |
55 |
57 // ============================================================================ |
56 // ============================================================================ |
58 // Tries to declare a new global-scope variable. Returns pointer |
57 // Tries to declare a new global-scope variable. Returns pointer |
59 // to new global variable, NULL if declaration failed. |
58 // to new global variable, null if declaration failed. |
60 ScriptVar* DeclareGlobalVariable (ScriptReader* r, type_e type, str name) { |
59 ScriptVar* DeclareGlobalVariable (ScriptReader* r, type_e type, string name) { |
61 // Unfortunately the VM does not support string variables so yeah. |
60 // Unfortunately the VM does not support string variables so yeah. |
62 if (type == TYPE_STRING) |
61 if (type == TYPE_STRING) |
63 r->ParserError ("variables cannot be string\n"); |
62 r->ParserError ("variables cannot be string\n"); |
64 |
63 |
65 // Check that the variable is valid |
64 // Check that the variable is valid |
87 return &g_GlobalVariables[g.index]; |
86 return &g_GlobalVariables[g.index]; |
88 } |
87 } |
89 |
88 |
90 // ============================================================================ |
89 // ============================================================================ |
91 // Find a global variable by name |
90 // Find a global variable by name |
92 ScriptVar* FindGlobalVariable (str name) { |
91 ScriptVar* FindGlobalVariable (string name) { |
93 for (uint i = 0; i < g_GlobalVariables.size(); i++) { |
92 for (uint i = 0; i < g_GlobalVariables.size(); i++) { |
94 ScriptVar* g = &g_GlobalVariables[i]; |
93 ScriptVar* g = &g_GlobalVariables[i]; |
95 if (g->name == name) |
94 if (g->name == name) |
96 return g; |
95 return g; |
97 } |
96 } |
98 |
97 |
99 return NULL; |
98 return null; |
100 } |
99 } |
101 |
100 |
102 // ============================================================================ |
101 // ============================================================================ |
103 // Count all declared global variables |
102 // Count all declared global variables |
104 uint CountGlobalVars () { |
103 uint CountGlobalVars () { |