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);
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;
}
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;
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], "<="))
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';
* 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;
* 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;
+ }
}
}