mirror of https://github.com/OpenTTD/OpenTTD
(svn r16272) [0.7] -Backport from trunk:
- Fix: [NoAI] Check slopes passed to the API better for validity (r16264, r16262) - Fix: [NewGRF] Interpret setting bridge property 08 to 0 as always available (r16263) - Add: [NoAI] AIController::GetVersion, this returns the version of OpenTTD in the same way as for NewGRFs (r16253) - Add: [NoAI] AIAirport::GetPrice, returning the building cost of an airport (r16252) - Fix: [NoAI] Enable parameter checking for AIController::* functions again (r16249)release/0.7
parent
2db7e3a0a8
commit
9676072298
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
void SQAIController_Register(Squirrel *engine) {
|
||||
DefSQClass <AIController> 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue