Loading

Paste #plsfqqmcn

  1. Index: src/ai/ai_scanner.cpp
  2. ===================================================================
  3. --- src/ai/ai_scanner.cpp   (revision 27586)
  4. +++ src/ai/ai_scanner.cpp   (working copy)
  5. @@ -104,7 +104,7 @@
  6.     AIInfo *info = NULL;
  7.     int version = -1;
  8.  
  9. -   if (versionParam == -1) {
  10. +   if (versionParam <= -1) {
  11.         /* We want to load the latest version of this AI; so find it */
  12.         if (this->info_single_list.find(ai_name) != this->info_single_list.end()) return static_cast<AIInfo *>(this->info_single_list[ai_name]);
  13.  
  14. @@ -113,7 +113,8 @@
  15.         if (e == NULL) return NULL;
  16.         *e = '\0';
  17.         e++;
  18. -       versionParam = atoi(e);
  19. +       /* We may still want to load the latest available version of this AI */
  20. +       if (versionParam == -1) versionParam = atoi(e);
  21.         /* FALL THROUGH, like we were calling this function with a version. */
  22.     }
  23.  
  24. @@ -125,17 +126,46 @@
  25.         if (this->info_list.find(ai_name_tmp) != this->info_list.end()) return static_cast<AIInfo *>(this->info_list[ai_name_tmp]);
  26.     }
  27.  
  28. -   /* See if there is a compatible AI which goes by that name, with the highest
  29. -    *  version which allows loading the requested version */
  30. -   ScriptInfoList::iterator it = this->info_list.begin();
  31. -   for (; it != this->info_list.end(); it++) {
  32. -       AIInfo *i = static_cast<AIInfo *>((*it).second);
  33. -       if (strcasecmp(ai_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
  34. -           version = (*it).second->GetVersion();
  35. -           info = i;
  36. +   if (versionParam != -2) {
  37. +       /* See if there is a compatible AI which goes by that name, with the highest
  38. +        *  version which allows loading the requested version */
  39. +       ScriptInfoList::iterator it = this->info_list.begin();
  40. +       for (; it != this->info_list.end(); it++) {
  41. +           AIInfo *i = static_cast<AIInfo *>((*it).second);
  42. +           if (strcasecmp(ai_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
  43. +               version = (*it).second->GetVersion();
  44. +               info = i;
  45. +           }
  46.         }
  47.     }
  48.  
  49. +   if (info == NULL && !force_exact_match && versionParam != -1) {
  50. +       if (versionParam != -2) {
  51. +           /* If we didn't find a match AI, maybe the user included a version */
  52. +           char *e = strrchr(ai_name, '.');
  53. +           if (e == NULL) return NULL;
  54. +           *e = '\0';
  55. +           e++;
  56. +           versionParam = atoi(e);
  57. +           /* Try to find a direct 'name.version' match */
  58. +           char ai_name_tmp[1024];
  59. +           seprintf(ai_name_tmp, lastof(ai_name_tmp), "%s.%d", ai_name, versionParam);
  60. +           strtolower(ai_name_tmp);
  61. +           if (this->info_list.find(ai_name_tmp) != this->info_list.end()) return static_cast<AIInfo *>(this->info_list[ai_name_tmp]);
  62. +       }
  63. +       /* See if there is a compatible AI which goes by that name, with the highest
  64. +       *  version which allows loading the requested version */
  65. +       ScriptInfoList::iterator it = this->info_list.begin();
  66. +       if (versionParam == -2) versionParam = -1;
  67. +       for (; it != this->info_list.end(); it++) {
  68. +           AIInfo *i = static_cast<AIInfo *>((*it).second);
  69. +           if (strcasecmp(ai_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
  70. +               version = (*it).second->GetVersion();
  71. +               info = i;
  72. +           }
  73. +       }
  74. +   }
  75. +
  76.     return info;
  77.  }
  78.  
  79. Index: src/game/game_scanner.cpp
  80. ===================================================================
  81. --- src/game/game_scanner.cpp   (revision 27586)
  82. +++ src/game/game_scanner.cpp   (working copy)
  83. @@ -45,7 +45,7 @@
  84.     GameInfo *info = NULL;
  85.     int version = -1;
  86.  
  87. -   if (versionParam == -1) {
  88. +   if (versionParam <= -1) {
  89.         /* We want to load the latest version of this Game script; so find it */
  90.         if (this->info_single_list.find(game_name) != this->info_single_list.end()) return static_cast<GameInfo *>(this->info_single_list[game_name]);
  91.  
  92. @@ -54,7 +54,8 @@
  93.         if (e == NULL) return NULL;
  94.         *e = '\0';
  95.         e++;
  96. -       versionParam = atoi(e);
  97. +       /* We may still want to load the latest available version of this Game script */
  98. +       if (versionParam == -1) versionParam = atoi(e);
  99.         /* FALL THROUGH, like we were calling this function with a version. */
  100.     }
  101.  
  102. @@ -66,17 +67,46 @@
  103.         if (this->info_list.find(game_name_tmp) != this->info_list.end()) return static_cast<GameInfo *>(this->info_list[game_name_tmp]);
  104.     }
  105.  
  106. -   /* See if there is a compatible Game script which goes by that name, with the highest
  107. -    *  version which allows loading the requested version */
  108. -   ScriptInfoList::iterator it = this->info_list.begin();
  109. -   for (; it != this->info_list.end(); it++) {
  110. -       GameInfo *i = static_cast<GameInfo *>((*it).second);
  111. -       if (strcasecmp(game_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
  112. -           version = (*it).second->GetVersion();
  113. -           info = i;
  114. +   if (versionParam != -2) {
  115. +       /* See if there is a compatible Game script which goes by that name, with the highest
  116. +        *  version which allows loading the requested version */
  117. +       ScriptInfoList::iterator it = this->info_list.begin();
  118. +       for (; it != this->info_list.end(); it++) {
  119. +           GameInfo *i = static_cast<GameInfo *>((*it).second);
  120. +           if (strcasecmp(game_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
  121. +               version = (*it).second->GetVersion();
  122. +               info = i;
  123. +           }
  124.         }
  125.     }
  126.  
  127. +   if (info == NULL && !force_exact_match && versionParam != -1) {
  128. +       if (versionParam != -2) {
  129. +           /* If we didn't find a match Game script, maybe the user included a version */
  130. +           char *e = strrchr(game_name, '.');
  131. +           if (e == NULL) return NULL;
  132. +           *e = '\0';
  133. +           e++;
  134. +           versionParam = atoi(e);
  135. +           /* Try to find a direct 'name.version' match */
  136. +           char game_name_tmp[1024];
  137. +           seprintf(game_name_tmp, lastof(game_name_tmp), "%s.%d", game_name, versionParam);
  138. +           strtolower(game_name_tmp);
  139. +           if (this->info_list.find(game_name_tmp) != this->info_list.end()) return static_cast<GameInfo *>(this->info_list[game_name_tmp]);
  140. +       }
  141. +       /* See if there is a compatible Game script which goes by that name, with the highest
  142. +       *  version which allows loading the requested version */
  143. +       ScriptInfoList::iterator it = this->info_list.begin();
  144. +       if (versionParam == -2) versionParam = -1;
  145. +       for (; it != this->info_list.end(); it++) {
  146. +           GameInfo *i = static_cast<GameInfo *>((*it).second);
  147. +           if (strcasecmp(game_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
  148. +               version = (*it).second->GetVersion();
  149. +               info = i;
  150. +           }
  151. +       }
  152. +   }
  153. +
  154.     return info;
  155.  }
  156.  
  157. Index: src/saveload/ai_sl.cpp
  158. ===================================================================
  159. --- src/saveload/ai_sl.cpp  (revision 27586)
  160. +++ src/saveload/ai_sl.cpp  (working copy)
  161. @@ -87,7 +87,7 @@
  162.             if (!config->HasScript()) {
  163.                 /* No version of the AI available that can load the data. Try to load the
  164.                  * latest version of the AI instead. */
  165. -               config->Change(_ai_saveload_name, -1, false, _ai_saveload_is_random);
  166. +               config->Change(_ai_saveload_name, -2, false, _ai_saveload_is_random);
  167.                 if (!config->HasScript()) {
  168.                     if (strcmp(_ai_saveload_name, "%_dummy") != 0) {
  169.                         DEBUG(script, 0, "The savegame has an AI by the name '%s', version %d which is no longer available.", _ai_saveload_name, _ai_saveload_version);
  170. Index: src/saveload/game_sl.cpp
  171. ===================================================================
  172. --- src/saveload/game_sl.cpp    (revision 27586)
  173. +++ src/saveload/game_sl.cpp    (working copy)
  174. @@ -79,10 +79,10 @@
  175.         if (!config->HasScript()) {
  176.             /* No version of the GameScript available that can load the data. Try to load the
  177.              * latest version of the GameScript instead. */
  178. -           config->Change(_game_saveload_name, -1, false, _game_saveload_is_random);
  179. +           config->Change(_game_saveload_name, -2, false, _game_saveload_is_random);
  180.             if (!config->HasScript()) {
  181.                 if (strcmp(_game_saveload_name, "%_dummy") != 0) {
  182. -                   DEBUG(script, 0, "The savegame has an GameScript by the name '%s', version %d which is no longer available.", _game_saveload_name, _game_saveload_version);
  183. +                   DEBUG(script, 0, "The savegame has a GameScript by the name '%s', version %d which is no longer available.", _game_saveload_name, _game_saveload_version);
  184.                     DEBUG(script, 0, "This game will continue to run without GameScript.");
  185.                 } else {
  186.                     DEBUG(script, 0, "The savegame had no GameScript available at the time of saving.");
  187. @@ -89,7 +89,7 @@
  188.                     DEBUG(script, 0, "This game will continue to run without GameScript.");
  189.                 }
  190.             } else {
  191. -               DEBUG(script, 0, "The savegame has an GameScript by the name '%s', version %d which is no longer available.", _game_saveload_name, _game_saveload_version);
  192. +               DEBUG(script, 0, "The savegame has a GameScript by the name '%s', version %d which is no longer available.", _game_saveload_name, _game_saveload_version);
  193.                 DEBUG(script, 0, "The latest version of that GameScript has been loaded instead, but it'll not get the savegame data as it's incompatible.");
  194.             }
  195.             /* Make sure the GameScript doesn't get the saveload data, as he was not the
  196. Index: src/script/script_config.cpp
  197. ===================================================================
  198. --- src/script/script_config.cpp    (revision 27586)
  199. +++ src/script/script_config.cpp    (working copy)
  200. @@ -24,6 +24,18 @@
  201.     this->name = (name == NULL) ? NULL : stredup(name);
  202.     this->info = (name == NULL) ? NULL : this->FindInfo(this->name, version, force_exact_match);
  203.     this->version = (info == NULL) ? -1 : info->GetVersion();
  204. +   if (this->name != NULL && info != NULL && strcasecmp(this->name, this->info->GetName()) != 0 && this->version > -1) {
  205. +       char script_name[1024];
  206. +       strecpy(script_name, this->name, lastof(script_name));
  207. +       strtolower(script_name);
  208. +       char *e = strrchr(script_name, '.');
  209. +       if (e != NULL) {
  210. +           *e = '\0';
  211. +           e++;
  212. +           int versionParam = atoi(e);
  213. +           if (this->version != versionParam) this->name = stredup(GetInfo()->GetName());
  214. +       }
  215. +   }
  216.     this->is_random = is_random;
  217.     if (this->config_list != NULL) delete this->config_list;
  218.     this->config_list = (info == NULL) ? NULL : new ScriptConfigItemList();

Comments