summaryrefslogtreecommitdiff
path: root/src/ai/ai_scanner.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-01-29 00:03:31 +0000
committeryexo <yexo@openttd.org>2010-01-29 00:03:31 +0000
commitfae34ee719a90dc7b7d68b54b97fb5485387b356 (patch)
tree2f584e6bf3765b262d9ade84f32bcd222b5ca015 /src/ai/ai_scanner.cpp
parentd75b9f1642f24dd3336437d818b41c2a6d295905 (diff)
downloadopenttd-fae34ee719a90dc7b7d68b54b97fb5485387b356.tar.xz
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
Diffstat (limited to 'src/ai/ai_scanner.cpp')
-rw-r--r--src/ai/ai_scanner.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index 6ae8c2e77..a974b5fd4 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -274,7 +274,7 @@ AIInfo *AIScanner::SelectRandomAI() const
return (*it).second;
}
-AIInfo *AIScanner::FindInfo(const char *nameParam, int versionParam)
+AIInfo *AIScanner::FindInfo(const char *nameParam, int versionParam, bool force_exact_match)
{
if (this->info_list.size() == 0) return NULL;
if (nameParam == NULL) return NULL;
@@ -299,21 +299,19 @@ AIInfo *AIScanner::FindInfo(const char *nameParam, int versionParam)
/* Fall-through, like we were calling this function with a version */
}
- /* Try to find a direct 'name.version' match */
- char ai_name_tmp[1024];
- snprintf(ai_name_tmp, sizeof(ai_name_tmp), "%s.%d", ai_name, versionParam);
- strtolower(ai_name_tmp);
- if (this->info_list.find(ai_name_tmp) != this->info_list.end()) return this->info_list[ai_name_tmp];
+ if (force_exact_match) {
+ /* Try to find a direct 'name.version' match */
+ char ai_name_tmp[1024];
+ snprintf(ai_name_tmp, sizeof(ai_name_tmp), "%s.%d", ai_name, versionParam);
+ strtolower(ai_name_tmp);
+ if (this->info_list.find(ai_name_tmp) != this->info_list.end()) return this->info_list[ai_name_tmp];
+ }
/* See if there is a compatible AI which goes by that name, with the highest
* version which allows loading the requested version */
AIInfoList::iterator it = this->info_list.begin();
for (; it != this->info_list.end(); it++) {
- char ai_name_compare[1024];
- snprintf(ai_name_compare, sizeof(ai_name_compare), "%s", (*it).second->GetName());
- strtolower(ai_name_compare);
-
- if (strcasecmp(ai_name, ai_name_compare) == 0 && (*it).second->CanLoadFromVersion(versionParam) && (version == -1 || (*it).second->GetVersion() > version)) {
+ if (strcasecmp(ai_name, (*it).second->GetName()) == 0 && (*it).second->CanLoadFromVersion(versionParam) && (version == -1 || (*it).second->GetVersion() > version)) {
version = (*it).second->GetVersion();
info = (*it).second;
}