12 #include "../stdafx.h" 
   13 #include "../settings_type.h" 
   20 #include "../safeguards.h" 
   22 ScriptInfo::~ScriptInfo()
 
   27     free((*it).description);
 
   28     if (it->labels != NULL) {
 
   53     seprintf(error, 
lastof(error), 
"your info.nut/library.nut doesn't have the method '%s'", name);
 
   72   static const char * 
const required_functions[] = {
 
   81   for (
size_t i = 0; i < 
lengthof(required_functions); i++) {
 
   82     if (!info->
CheckMethod(required_functions[i])) 
return SQ_ERROR;
 
  120   memset(&config, 0, 
sizeof(config));
 
  127   while (SQ_SUCCEEDED(sq_next(vm, -2))) {
 
  129     if (SQ_FAILED(sq_getstring(vm, -2, &key))) 
return SQ_ERROR;
 
  132     if (strcmp(key, 
"name") == 0) {
 
  133       const SQChar *sqvalue;
 
  134       if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) 
return SQ_ERROR;
 
  141       while ((s = strchr(name, 
'=')) != NULL) *s = 
'_';
 
  142       while ((s = strchr(name, 
',')) != NULL) *s = 
'_';
 
  145     } 
else if (strcmp(key, 
"description") == 0) {
 
  146       const SQChar *sqdescription;
 
  147       if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription))) 
return SQ_ERROR;
 
  151     } 
else if (strcmp(key, 
"min_value") == 0) {
 
  153       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  156     } 
else if (strcmp(key, 
"max_value") == 0) {
 
  158       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  161     } 
else if (strcmp(key, 
"easy_value") == 0) {
 
  163       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  166     } 
else if (strcmp(key, 
"medium_value") == 0) {
 
  168       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  171     } 
else if (strcmp(key, 
"hard_value") == 0) {
 
  173       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  176     } 
else if (strcmp(key, 
"random_deviation") == 0) {
 
  178       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  181     } 
else if (strcmp(key, 
"custom_value") == 0) {
 
  183       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  186     } 
else if (strcmp(key, 
"step_size") == 0) {
 
  188       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  190     } 
else if (strcmp(key, 
"flags") == 0) {
 
  192       if (SQ_FAILED(sq_getinteger(vm, -1, &res))) 
return SQ_ERROR;
 
  197       seprintf(error, 
lastof(error), 
"unknown setting property '%s'", key);
 
  210     seprintf(error, 
lastof(error), 
"Setting both random_deviation and SCRIPTCONFIG_RANDOM is not allowed");
 
  221     seprintf(error, 
lastof(error), 
"please define all properties of a setting (min/max not allowed for booleans)");
 
  232   const SQChar *setting_name;
 
  233   if (SQ_FAILED(sq_getstring(vm, -2, &setting_name))) 
return SQ_ERROR;
 
  237   for (ScriptConfigItemList::iterator it = this->
config_list.begin(); it != this->
config_list.end(); it++) {
 
  238     if (strcmp((*it).name, setting_name) == 0) config = &(*it);
 
  241   if (config == NULL) {
 
  243     seprintf(error, 
lastof(error), 
"Trying to add labels for non-defined setting '%s'", setting_name);
 
  247   if (config->
labels != NULL) 
return SQ_ERROR;
 
  253   while (SQ_SUCCEEDED(sq_next(vm, -2))) {
 
  254     const SQChar *key_string;
 
  256     if (SQ_FAILED(sq_getstring(vm, -2, &key_string))) 
return SQ_ERROR;
 
  257     if (SQ_FAILED(sq_getstring(vm, -1, &label))) 
return SQ_ERROR;
 
  260     int key = atoi(key_string + 1);
 
  272   for (
int value = config->
min_value; value <= config->max_value; value++) {
 
  289   for (ScriptConfigItemList::const_iterator it = this->
config_list.begin(); it != this->
config_list.end(); it++) {
 
  290     if (strcmp((*it).name, name) == 0) 
return &(*it);
 
  297   for (ScriptConfigItemList::const_iterator it = this->
config_list.begin(); it != this->
config_list.end(); it++) {
 
  298     if (strcmp((*it).name, name) != 0) 
continue;
 
  301       case SP_EASY:   
return (*it).easy_value;
 
  302       case SP_MEDIUM: return (*it).medium_value;
 
  303       case SP_HARD:   return (*it).hard_value;
 
  304       case SP_CUSTOM: return (*it).custom_value;
 
  305       default: NOT_REACHED();