]> Chaos Git - vn/vndc.git/commitdiff
Guess what? setvar var = anothervar is now allowed syntax. Isn't that cool?
authorchaoskagami <chaos.kagami@gmail.com>
Mon, 25 Aug 2014 02:52:32 +0000 (22:52 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Mon, 25 Aug 2014 02:52:32 +0000 (22:52 -0400)
bin/vndc.x86_64 [deleted file]
vndc/include/Funcs.hpp
vndc/src/Data.cpp
vndc/src/Parse.cpp
vndc/src/op_goto.cpp
vndc/src/op_gsetvar.cpp
vndc/src/op_setvar.cpp

diff --git a/bin/vndc.x86_64 b/bin/vndc.x86_64
deleted file mode 100755 (executable)
index 0f8601b..0000000
Binary files a/bin/vndc.x86_64 and /dev/null differ
index 21b54522b333a584d2fa9852755a3ea49dc924f2..3a08b262fe9a05f165d9fac95c98fa57f1c6bc8b 100644 (file)
@@ -23,12 +23,12 @@ void op_bgload(char* file, int* fadetime);
 void op_cleartext();
 void op_delay(int* frames);
 void op_fi();
-void op_gsetvar(char* var, int *modifier, int *value);
+void op_gsetvar(char* var, int *modifier, char *value);
 void op_if(char* var, int* op, int* val);
 void op_music(char* file);
 void op_random(char* var, int* low, int* high);
 void op_setimg(char* file, int* x, int* y);
-void op_setvar(char* var, int *modifier, int *value);
+void op_setvar(char* var, int *modifier, char *value);
 void op_sound(char* file, int* times);
 void op_text(char* string);
 void op_jump(char* file, int* lineTo, bool isSave);
index 67ec5678e7aaf18099a53a4eb422b372b4b6068a..6b83638d3696713bea8a3fdde255b1c7dac11de7 100644 (file)
@@ -39,7 +39,8 @@ void DumpSave(char* fname) {
        if(!data_vals.empty()) {
                std::map<std::string, int>::iterator item = data_vals.begin();
                while(item != data_vals.end()) {
-                       fprintf(save_to, "setvar %s = %d\n", item->first.c_str(), item->second);
+                       if(strcmp(item->first.c_str(), "selected"))
+                               fprintf(save_to, "setvar %s = %d\n", item->first.c_str(), item->second);
 
                        ++item;
                }
index 3a550bcd6d332492f13c4086cc55c340ea236583..e46e09dbedccf23c580bb904fa2ed04a061140ce 100644 (file)
@@ -86,7 +86,7 @@ void ParseCmd(char* line) {
 
 
                        sscanf(tokens[3], "%d", &value_2);
-                       op_setvar(tokens[1], &value_1, &value_2);
+                       op_setvar(tokens[1], &value_1, tokens[3]);
                }
                else {
                        value_1 = -2;
@@ -101,8 +101,7 @@ void ParseCmd(char* line) {
                else if(!strcmp(tokens[2], "-"))
                        value_1 = -1;
 
-               sscanf(tokens[3], "%d", &value_2);
-               op_gsetvar(tokens[1], &value_1, &value_2);
+               op_gsetvar(tokens[1], &value_1, tokens[3]);
        }
        else if(!strcmp(tokens[0], "if")) {
                if(!strcmp(tokens[2], "<="))
index 4f2615c7310ee6e020fd7e0f7e9d8773ff21f040..f3b5e076247ececdadd884f0a6fdf7877a1daa47 100644 (file)
@@ -23,7 +23,7 @@ void op_goto(char* label) {
                line_to++;
                fgets(line, 400, *infile);
 
-       // Remove all '\n' from this string
+               // Remove all '\n' from this string
                for(int i=0; i < 400; i++) {
                        if (line[i] == '\n')
                                line[i] = '\0';
index ceec62f502e8b939b8da2ae108e2923efd0f729b..f128b021b171c1bf55aa0405d255462f25269f0f 100644 (file)
  * Also, for now I simply redirect to setvar. Global values are only set
  * by definition on an end-game event for replays, so when the interpreter hits
  * 'the end' it loops back to the title.
- * So setting local vars is okay, since they'll be reloaded across playthrus.
+ *
+ * As an exception, setvar ~ ~ will ignore all vars prefixed with g
+ * because these are globals.
+ *
+ * You can set global vars with setvar because my implementation just
+ * works different here, but still.
+ *
+ * Any local vars will obviously be nuked by setvar ~ ~.
  */
 
-void op_gsetvar(char* var, int *modifier, int *value) {
+void op_gsetvar(char* var, int *modifier, char *value) {
        if (GetData()->if_fail != 0)
                return;
 
index 045309d43d4ee51f41c98285cefd9b74e56f360d..f22b1d753b185a0b6a66c53d74f6236aa6a6ae4f 100644 (file)
@@ -9,29 +9,58 @@
  * MAY need to be UTF8 friendly
  */
 
-void op_setvar(char* var, int* modifier, int* value) {
+void op_setvar(char* var, int* modifier, char* value) {
        if (GetData()->if_fail != 0)
                return;
 
-       if(*modifier == 0) {
-               GetData()->s_flags[0][std::string(var)] = value[0];
-       }
-       else if (*modifier == -1) {
-               GetData()->s_flags[0][std::string(var)] -= value[0];
-       }
-       else if (*modifier == 1) {
-               GetData()->s_flags[0][std::string(var)] += value[0];
-       }
-       else if (*modifier == -2) {
-               // There's a rare case on program start where a resetall
-               // happens.
+       int value_r = 0, ret;
+       if(value == NULL)
+               ret = 0;
+       else
+               ret = sscanf(value, "%d", &value_r);
 
-               if(!strcmp(var, "~")) {
-                       // We'll handle it by doing a delete & new on s_local
-                       GetData()->s_flags[0].clear();
-                       return;
+       if(ret == 0) { // value is a variable not a number
+               if(*modifier == 0) {
+                       GetData()->s_flags[0][std::string(var)] = GetData()->s_flags[0][std::string(value)];
                }
+               else if (*modifier == -1) {
+                       GetData()->s_flags[0][std::string(var)] -= GetData()->s_flags[0][std::string(value)];
+               }
+               else if (*modifier == 1) {
+                       GetData()->s_flags[0][std::string(var)] += GetData()->s_flags[0][std::string(value)];
+               }
+       }
+       else {
+               if(*modifier == 0) {
+                       GetData()->s_flags[0][std::string(var)] = value_r;
+               }
+               else if (*modifier == -1) {
+                       GetData()->s_flags[0][std::string(var)] -= value_r;
+               }
+               else if (*modifier == 1) {
+                       GetData()->s_flags[0][std::string(var)] += value_r;
+               }
+               else if (*modifier == -2) {
+                       // There's a rare case on program start where a resetall
+                       // happens.
 
-               GetData()->s_flags[0][std::string(var)] = 0;
+                       if(!strcmp(var, "~")) {
+                               // We'll handle it by searching through and deleting all non-G values.
+                               // g values are global, so they by definition survive this.
+       
+                               if(!GetData()->s_flags[0].empty()) {
+                                       std::map<std::string, int>::iterator item = GetData()->s_flags[0].begin();
+                                       while(item != GetData()->s_flags[0].end()) {
+                                               if(item->first.c_str()[0] != 'g')
+                                                       GetData()->s_flags[0].erase(item++);
+                                               else
+                                                       item++;
+                                       }
+                               }
+                               return;
+                       }
+
+                       GetData()->s_flags[0][std::string(var)] = 0;
+               }
        }
 }