diff --git a/src/3rdparty/squirrel/include/squirrel.h b/src/3rdparty/squirrel/include/squirrel.h index 7bce8f5a92..b3864b975c 100644 --- a/src/3rdparty/squirrel/include/squirrel.h +++ b/src/3rdparty/squirrel/include/squirrel.h @@ -54,6 +54,10 @@ extern "C" { typedef __int64 SQInteger; typedef unsigned __int64 SQUnsignedInteger; typedef unsigned __int64 SQHash; /*should be the same size of a pointer*/ +#elif defined(_WIN32) +typedef long long SQInteger; +typedef unsigned long long SQUnsignedInteger; +typedef unsigned long long SQHash; /*should be the same size of a pointer*/ #else typedef long SQInteger; typedef unsigned long SQUnsignedInteger; @@ -77,6 +81,8 @@ typedef float SQFloat; #if defined(SQUSEDOUBLE) && !defined(_SQ64) #ifdef _MSC_VER typedef __int64 SQRawObjectVal; //must be 64bits +#elif defined(_WIN32) +typedef long long SQRawObjectVal; //must be 64bits #else typedef long SQRawObjectVal; //must be 64bits #endif diff --git a/src/ai/ai_config.cpp b/src/ai/ai_config.cpp index 8ec213cd8f..a00cf48677 100644 --- a/src/ai/ai_config.cpp +++ b/src/ai/ai_config.cpp @@ -75,9 +75,9 @@ AIInfo *AIConfig::GetInfo() const return this->info; } -bool AIConfig::ResetInfo() +bool AIConfig::ResetInfo(bool force_exact_match) { - this->info = AI::FindInfo(this->name, -1, false); + this->info = AI::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match); return this->info != NULL; } diff --git a/src/ai/ai_config.hpp b/src/ai/ai_config.hpp index ee6f8b4165..3ed06d346c 100644 --- a/src/ai/ai_config.hpp +++ b/src/ai/ai_config.hpp @@ -57,10 +57,12 @@ public: /** * When ever the AI Scanner is reloaded, all infos become invalid. This * function tells AIConfig about this. + * @param force_exact_match If true try to find the exact same version + * as specified. If false any version is ok. * @return \c true if the reset was successful, \c false if the AI was no longer * found. */ - bool ResetInfo(); + bool ResetInfo(bool force_exact_match); /** * Get the AIInfo linked to this AIConfig. diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index 1c7005b74a..f92d511c21 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -170,13 +170,24 @@ * a random new AI on reload). */ for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { if (_settings_game.ai_config[c] != NULL && _settings_game.ai_config[c]->HasAI()) { - if (!_settings_game.ai_config[c]->ResetInfo()) { + if (!_settings_game.ai_config[c]->ResetInfo(true)) { DEBUG(ai, 0, "After a reload, the AI by the name '%s' was no longer found, and removed from the list.", _settings_game.ai_config[c]->GetName()); _settings_game.ai_config[c]->ChangeAI(NULL); + if (Company::IsValidAiID(c)) { + /* The code belonging to an already running AI was deleted. We can only do + * one thing here to keep everything sane and that is kill the AI. After + * killing the offending AI we start a random other one in it's place, just + * like what would happen if the AI was missing during loading. */ + AI::Stop(c); + AI::StartNew(c, false); + } + } else if (Company::IsValidAiID(c)) { + /* Update the reference in the Company struct. */ + Company::Get(c)->ai_info = _settings_game.ai_config[c]->GetInfo(); } } if (_settings_newgame.ai_config[c] != NULL && _settings_newgame.ai_config[c]->HasAI()) { - if (!_settings_newgame.ai_config[c]->ResetInfo()) { + if (!_settings_newgame.ai_config[c]->ResetInfo(false)) { DEBUG(ai, 0, "After a reload, the AI by the name '%s' was no longer found, and removed from the list.", _settings_newgame.ai_config[c]->GetName()); _settings_newgame.ai_config[c]->ChangeAI(NULL); } diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 75f222306a..78ec9cc1f9 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -575,7 +575,7 @@ static const NWidgetPart _nested_build_airport_widgets[] = { static const WindowDesc _build_airport_desc( WDP_AUTO, 0, 0, WC_BUILD_STATION, WC_BUILD_TOOLBAR, - WDF_CONSTRUCTION, + WDF_CONSTRUCTION | WDF_UNCLICK_BUTTONS, _nested_build_airport_widgets, lengthof(_nested_build_airport_widgets) ); diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index a975603dd5..087a23122d 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -243,11 +243,11 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod) buffer += seprintf(buffer, last, "Registers:\n"); #ifdef _M_AMD64 buffer += seprintf(buffer, last, - " RAX: %.16llX RBX: %.16llX RCX: %.16llX RDX: %.16llX\n" - " RSI: %.16llX RDI: %.16llX RBP: %.16llX RSP: %.16llX\n" - " R8: %.16llX R9: %.16llX R10: %.16llX R11: %.16llX\n" - " R12: %.16llX R13: %.16llX R14: %.16llX R15: %.16llX\n" - " RIP: %.16llX EFLAGS: %.8X\n", + " RAX: %.16I64X RBX: %.16I64X RCX: %.16I64X RDX: %.16I64X\n" + " RSI: %.16I64X RDI: %.16I64X RBP: %.16I64X RSP: %.16I64X\n" + " R8: %.16I64X R9: %.16I64X R10: %.16I64X R11: %.16I64X\n" + " R12: %.16I64X R13: %.16I64X R14: %.16I64X R15: %.16I64X\n" + " RIP: %.16I64X EFLAGS: %.8lX\n", ep->ContextRecord->Rax, ep->ContextRecord->Rbx, ep->ContextRecord->Rcx, @@ -548,7 +548,6 @@ static void CDECL CustomAbort(int signal) /* static */ void CrashLog::InitialiseCrashLog() { -#if defined(_MSC_VER) #ifdef _M_AMD64 CONTEXT ctx; RtlCaptureContext(&ctx); @@ -559,12 +558,13 @@ static void CDECL CustomAbort(int signal) * alignment would be wrong in the called function. */ _safe_esp = (void *)(ctx.Rsp - 8); #else +#if defined(_MSC_VER) _asm { mov _safe_esp, esp } -#endif #else asm("movl %esp, __safe_esp"); +#endif #endif /* SIGABRT is not an unhandled exception, so we need to intercept it. */ diff --git a/src/settings.cpp b/src/settings.cpp index dc7ae6e5bf..7084a41d4c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -97,10 +97,10 @@ static const char * const _list_group_names[] = { * @param onelen force calculation of the *one parameter * @return the integer index of the full-list, or -1 if not found */ -static int LookupOneOfMany(const char *many, const char *one, size_t onelen = 0) +static size_t LookupOneOfMany(const char *many, const char *one, size_t onelen = 0) { const char *s; - int idx; + size_t idx; if (onelen == 0) onelen = strlen(one); @@ -113,7 +113,7 @@ static int LookupOneOfMany(const char *many, const char *one, size_t onelen = 0) s = many; while (*s != '|' && *s != 0) s++; if ((size_t)(s - many) == onelen && !memcmp(one, many, onelen)) return idx; - if (*s == 0) return -1; + if (*s == 0) return (size_t)-1; many = s + 1; idx++; } @@ -126,11 +126,11 @@ static int LookupOneOfMany(const char *many, const char *one, size_t onelen = 0) * of seperated by a whitespace,tab or | character * @return the 'fully' set integer, or -1 if a set is not found */ -static uint32 LookupManyOfMany(const char *many, const char *str) +static size_t LookupManyOfMany(const char *many, const char *str) { const char *s; - int r; - uint32 res = 0; + size_t r; + size_t res = 0; for (;;) { /* skip "whitespace" */ @@ -141,7 +141,7 @@ static uint32 LookupManyOfMany(const char *many, const char *str) while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++; r = LookupOneOfMany(many, str, s - str); - if (r == -1) return (uint32)-1; + if (r == (size_t)-1) return r; SetBit(res, r); // value found, set it if (*s == 0) break; @@ -339,24 +339,24 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str switch (desc->cmd) { case SDT_NUMX: { char *end; - unsigned long val = strtoul(str, &end, 0); + size_t val = strtoul(str, &end, 0); if (*end != '\0') ShowInfoF("ini: trailing characters at end of setting '%s'", desc->name); return (void*)val; } case SDT_ONEOFMANY: { - long r = LookupOneOfMany(desc->many, str); + size_t r = LookupOneOfMany(desc->many, str); /* if the first attempt of conversion from string to the appropriate value fails, * look if we have defined a converter from old value to new value. */ - if (r == -1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str); - if (r != -1) return (void*)r; // and here goes converted value + if (r == (size_t)-1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str); + if (r != (size_t)-1) return (void*)r; // and here goes converted value ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name); // sorry, we failed return 0; } case SDT_MANYOFMANY: { - unsigned long r = LookupManyOfMany(desc->many, str); - if (r != (unsigned long)-1) return (void*)r; + size_t r = LookupManyOfMany(desc->many, str); + if (r != (size_t)-1) return (void*)r; ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name); - return 0; + return NULL; } case SDT_BOOLX: if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return (void*)true; @@ -571,15 +571,15 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp break; case SLE_VAR_I8: case SLE_VAR_U8: - if (*(byte*)ptr == (byte)(unsigned long)p) continue; + if (*(byte*)ptr == (byte)(size_t)p) continue; break; case SLE_VAR_I16: case SLE_VAR_U16: - if (*(uint16*)ptr == (uint16)(unsigned long)p) continue; + if (*(uint16*)ptr == (uint16)(size_t)p) continue; break; case SLE_VAR_I32: case SLE_VAR_U32: - if (*(uint32*)ptr == (uint32)(unsigned long)p) continue; + if (*(uint32*)ptr == (uint32)(size_t)p) continue; break; default: NOT_REACHED(); } @@ -1059,7 +1059,7 @@ static bool CheckRoadSide(int p1) * @param value that was read from config file * @return the "hopefully" converted value */ -static int32 ConvertLandscape(const char *value) +static size_t ConvertLandscape(const char *value) { /* try with the old values */ return LookupOneOfMany("normal|hilly|desert|candy", value); diff --git a/src/settings_internal.h b/src/settings_internal.h index 7dca0332f3..035b636f76 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -56,7 +56,7 @@ typedef SimpleTinyEnumT SettingGuiFlag; typedef bool OnChange(int32 var); ///< callback prototype on data modification -typedef int32 OnConvert(const char *value); ///< callback prototype for convertion error +typedef size_t OnConvert(const char *value); ///< callback prototype for convertion error /** Properties of config file settings. */ struct SettingDescBase { diff --git a/src/table/settings.h b/src/table/settings.h index 58fe09d3d1..ccdbf98a10 100644 --- a/src/table/settings.h +++ b/src/table/settings.h @@ -34,7 +34,7 @@ static bool DifficultyChange(int32); static bool DifficultyNoiseChange(int32 i); static bool MaxNoAIsChange(int32 i); static bool CheckRoadSide(int p1); -static int32 ConvertLandscape(const char *value); +static size_t ConvertLandscape(const char *value); static bool CheckFreeformEdges(int32 p1); static bool ChangeDynamicEngines(int32 p1); static bool StationCatchmentChanged(int32 p1); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 3551c4d64e..58246a6b09 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1865,7 +1865,7 @@ void Vehicle::BeginLoading() in_list->GetDestination() != this->last_station_visited)) { bool suppress_implicit_orders = HasBit(this->GetGroundVehicleFlags(), GVF_SUPPRESS_IMPLICIT_ORDERS); /* Do not create consecutive duplicates of implicit orders */ - Order *prev_order = this->cur_implicit_order_index > 0 ? this->GetOrder(this->cur_implicit_order_index - 1) : NULL; + Order *prev_order = this->cur_implicit_order_index > 0 ? this->GetOrder(this->cur_implicit_order_index - 1) : (this->GetNumOrders() > 1 ? this->GetLastOrder() : NULL); if (prev_order == NULL || (!prev_order->IsType(OT_IMPLICIT) && !prev_order->IsType(OT_GOTO_STATION)) || prev_order->GetDestination() != this->last_station_visited) {