diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut index 8b77879bd2..82154c9dbe 100644 --- a/bin/ai/regression/regression.nut +++ b/bin/ai/regression/regression.nut @@ -220,6 +220,7 @@ function Regression::Airport() } print(" GetBankBalance(): " + AICompany.GetBankBalance(AICompany.COMPANY_SELF)); + print(" GetPrice(): " + AIAirport.GetPrice(0)); print(" BuildAirport(): " + AIAirport.BuildAirport(32116, 0, AIStation.STATION_JOIN_ADJACENT)); print(" IsHangarTile(): " + AIAirport.IsHangarTile(32116)); print(" IsAirportTile(): " + AIAirport.IsAirportTile(32116)); diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index 5a7c96d2a5..2f5613f3b4 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -620,6 +620,7 @@ GetAirportHeight(9): -1 GetAirportCoverageRadius(9): -1 GetBankBalance(): 100000 + GetPrice(): 84 BuildAirport(): true IsHangarTile(): false IsAirportTile(): true @@ -7328,7 +7329,7 @@ Count(): 9 ListDump: 27631 => 29 - 27631 => 255 + 27631 => 65535 27631 => true 27631 => false 27888 => 13 diff --git a/src/ai/api/ai_airport.cpp b/src/ai/api/ai_airport.cpp index ed58701c33..819880f97a 100644 --- a/src/ai/api/ai_airport.cpp +++ b/src/ai/api/ai_airport.cpp @@ -8,12 +8,21 @@ #include "../../company_func.h" #include "../../command_type.h" #include "../../town.h" +#include "../../economy_func.h" /* static */ bool AIAirport::IsValidAirportType(AirportType type) { return type >= AT_SMALL && type <= AT_HELISTATION && HasBit(::GetValidAirports(), type); } +/* static */ Money AIAirport::GetPrice(AirportType type) +{ + if (!IsValidAirportType(type)) return -1; + + const AirportFTAClass *afc = ::GetAirport(type); + return _price.build_airport * afc->size_x * afc->size_y; +} + /* static */ bool AIAirport::IsHangarTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; diff --git a/src/ai/api/ai_airport.hpp b/src/ai/api/ai_airport.hpp index 2456613643..e4541edf63 100644 --- a/src/ai/api/ai_airport.hpp +++ b/src/ai/api/ai_airport.hpp @@ -53,6 +53,13 @@ public: */ static bool IsValidAirportType(AirportType type); + /** + * Get the cost to build this AirportType. + * @param type The AirportType to check. + * @return The cost of building this AirportType. + */ + static Money GetPrice(AirportType type); + /** * Checks whether the given tile is actually a tile with a hangar. * @param tile The tile to check. diff --git a/src/ai/api/ai_airport.hpp.sq b/src/ai/api/ai_airport.hpp.sq index 0a42aa2d78..3825c29ae2 100644 --- a/src/ai/api/ai_airport.hpp.sq +++ b/src/ai/api/ai_airport.hpp.sq @@ -39,6 +39,7 @@ void SQAIAirport_Register(Squirrel *engine) { SQAIAirport.DefSQConst(engine, AIAirport::PT_INVALID, "PT_INVALID"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsValidAirportType, "IsValidAirportType", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetPrice, "GetPrice", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsHangarTile, "IsHangarTile", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsAirportTile, "IsAirportTile", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportWidth, "GetAirportWidth", 2, ".i"); diff --git a/src/ai/api/ai_controller.cpp b/src/ai/api/ai_controller.cpp index f783bbabb9..f9ef2ab166 100644 --- a/src/ai/api/ai_controller.cpp +++ b/src/ai/api/ai_controller.cpp @@ -5,6 +5,7 @@ #include "../../stdafx.h" #include "../../string_func.h" #include "../../company_base.h" +#include "../../rev.h" #include "table/strings.h" #include "../ai.hpp" @@ -66,6 +67,11 @@ AIController::~AIController() return AIConfig::GetConfig(_current_company)->GetSetting(name); } +/* static */ uint AIController::GetVersion() +{ + return _openttd_newgrf_version; +} + bool AIController::LoadedLibrary(const char *library_name, int *next_number, char *fake_class_name, int fake_class_name_len) { LoadedLibraryList::iterator iter = this->loaded_library.find(library_name); diff --git a/src/ai/api/ai_controller.hpp b/src/ai/api/ai_controller.hpp index 5304039c2d..a0d4c8bef4 100644 --- a/src/ai/api/ai_controller.hpp +++ b/src/ai/api/ai_controller.hpp @@ -50,6 +50,18 @@ public: */ static int GetSetting(const char *name); + /** + * Get the OpenTTD version of this executable. The version is formatted + * with the bits having the following meaning: + * 28-31 major version + * 24-27 minor version + * 20-23 build + * 19 1 if it is a release, 0 if it is not. + * 0-18 revision number; 0 when the revision is unknown. + * @return The version in newgrf format. + */ + static uint GetVersion(); + /** * Change the minimum amount of time the AI should be put in suspend mode * when you execute a command. Normally in SP this is 1, and in MP it is diff --git a/src/ai/api/ai_controller.hpp.sq b/src/ai/api/ai_controller.hpp.sq index 911fe42b6d..02212061b4 100644 --- a/src/ai/api/ai_controller.hpp.sq +++ b/src/ai/api/ai_controller.hpp.sq @@ -5,10 +5,11 @@ void SQAIController_Register(Squirrel *engine) { DefSQClass SQAIController("AIController"); SQAIController.PreRegister(engine); - SQAIController.DefSQStaticMethod(engine, &AIController::GetTick, "GetTick", 1, "?"); - SQAIController.DefSQStaticMethod(engine, &AIController::SetCommandDelay, "SetCommandDelay", 2, "?i"); - SQAIController.DefSQStaticMethod(engine, &AIController::Sleep, "Sleep", 2, "?i"); - SQAIController.DefSQStaticMethod(engine, &AIController::GetSetting, "GetSetting", 2, "?s"); - SQAIController.DefSQStaticMethod(engine, &AIController::Print, "Print", 3, "?bs"); + SQAIController.DefSQStaticMethod(engine, &AIController::GetTick, "GetTick", 1, "."); + SQAIController.DefSQStaticMethod(engine, &AIController::SetCommandDelay, "SetCommandDelay", 2, ".i"); + SQAIController.DefSQStaticMethod(engine, &AIController::Sleep, "Sleep", 2, ".i"); + SQAIController.DefSQStaticMethod(engine, &AIController::GetSetting, "GetSetting", 2, ".s"); + SQAIController.DefSQStaticMethod(engine, &AIController::GetVersion, "GetVersion", 1, "."); + SQAIController.DefSQStaticMethod(engine, &AIController::Print, "Print", 3, ".bs"); SQAIController.PostRegister(engine); } diff --git a/src/ai/api/ai_tile.cpp b/src/ai/api/ai_tile.cpp index f5bf96f1a8..70bb1fb835 100644 --- a/src/ai/api/ai_tile.cpp +++ b/src/ai/api/ai_tile.cpp @@ -73,14 +73,14 @@ /* static */ bool AITile::IsSteepSlope(Slope slope) { - if (slope == SLOPE_INVALID) return false; + if ((slope & ~(SLOPE_ELEVATED | SLOPE_STEEP | SLOPE_HALFTILE_MASK)) != 0) return false; return ::IsSteepSlope((::Slope)slope); } /* static */ bool AITile::IsHalftileSlope(Slope slope) { - if (slope == SLOPE_INVALID) return false; + if ((slope & ~(SLOPE_ELEVATED | SLOPE_STEEP | SLOPE_HALFTILE_MASK)) != 0) return false; return ::IsHalftileSlope((::Slope)slope); } @@ -124,9 +124,7 @@ /* static */ AITile::Slope AITile::GetComplementSlope(Slope slope) { - if (slope == SLOPE_INVALID) return SLOPE_INVALID; - if (IsSteepSlope(slope)) return SLOPE_INVALID; - if (IsHalftileSlope(slope)) return SLOPE_INVALID; + if ((slope & ~SLOPE_ELEVATED) != 0) return SLOPE_INVALID; return (Slope)::ComplementSlope((::Slope)slope); } diff --git a/src/ai/api/ai_tile.hpp b/src/ai/api/ai_tile.hpp index e1e20d5fa6..d50fb54eea 100644 --- a/src/ai/api/ai_tile.hpp +++ b/src/ai/api/ai_tile.hpp @@ -80,7 +80,7 @@ public: SLOPE_STEEP_E = SLOPE_STEEP | SLOPE_SEN, //!< A steep slope falling to west (from east) SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW, //!< A steep slope falling to south (from north) - SLOPE_INVALID = 0xFF, //!< An invalid slope + SLOPE_INVALID = 0xFFFF, //!< An invalid slope }; /** diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 398cf3b0f2..d034c8fcbe 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -535,8 +535,8 @@ public: ShowQueryString( STR_JUST_RAW_STRING, STR_NETWORK_ENTER_IP, - 31, // maximum number of characters - 250, // characters up to this width pixels, whichever is satisfied first + NETWORK_HOSTNAME_LENGTH, // maximum number of characters including '\0' + 0, // no limit in pixels this, CS_ALPHANUMERAL, QSF_ACCEPT_UNCHANGED); break; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 32c8691212..40c247e6cc 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1356,9 +1356,12 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, byte BridgeSpec *bridge = &_bridge[brid + i]; switch (prop) { - case 0x08: // Year of availability - bridge->avail_year = ORIGINAL_BASE_YEAR + grf_load_byte(&buf); + case 0x08: { // Year of availability + /* We treat '0' as always available */ + byte year = grf_load_byte(&buf); + bridge->avail_year = (year > 0 ? ORIGINAL_BASE_YEAR + year : 0); break; + } case 0x09: // Minimum length bridge->min_length = grf_load_byte(&buf);