From 91078be657b2ce0d31fa3d2f38cea6c55c74ae77 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 20 Aug 2009 12:22:31 +0000 Subject: [PATCH] (svn r17235) [0.7] -Backport from trunk: - Fix: [NoAI] IsRoadTypeAvailable(GetCurrentRoadType()) was not a precondition for several AIRoad::* functions (r17203) - Fix: [NoAI] Do not say you are building a depot when you are actually building a station (API docs typo) (r17201) - Change: [NoAI] When the API requests a string as parameter allow every squirrel type and convert to a string [FS#3101] (r17221) --- src/ai/api/ai_company.hpp.sq | 4 ++-- src/ai/api/ai_gamesettings.hpp.sq | 4 ++-- src/ai/api/ai_group.hpp.sq | 2 +- src/ai/api/ai_log.hpp.sq | 6 +++--- src/ai/api/ai_road.cpp | 7 +++++++ src/ai/api/ai_road.hpp | 11 ++++++++++- src/ai/api/ai_sign.hpp.sq | 4 ++-- src/ai/api/ai_station.hpp.sq | 2 +- src/ai/api/ai_vehicle.hpp.sq | 2 +- src/ai/api/ai_waypoint.hpp.sq | 2 +- src/ai/api/squirrel_export.awk | 2 +- src/script/squirrel_helper.hpp | 12 +++++++++++- 12 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/ai/api/ai_company.hpp.sq b/src/ai/api/ai_company.hpp.sq index 9441fb317b..1c23906175 100644 --- a/src/ai/api/ai_company.hpp.sq +++ b/src/ai/api/ai_company.hpp.sq @@ -33,9 +33,9 @@ void SQAICompany_Register(Squirrel *engine) { SQAICompany.DefSQStaticMethod(engine, &AICompany::ResolveCompanyID, "ResolveCompanyID", 2, ".i"); SQAICompany.DefSQStaticMethod(engine, &AICompany::IsMine, "IsMine", 2, ".i"); - SQAICompany.DefSQStaticMethod(engine, &AICompany::SetName, "SetName", 2, ".s"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::SetName, "SetName", 2, ".."); SQAICompany.DefSQStaticMethod(engine, &AICompany::GetName, "GetName", 2, ".i"); - SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentName, "SetPresidentName", 2, ".s"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentName, "SetPresidentName", 2, ".."); SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentName, "GetPresidentName", 2, ".i"); SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentGender, "SetPresidentGender", 2, ".i"); SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentGender, "GetPresidentGender", 2, ".i"); diff --git a/src/ai/api/ai_gamesettings.hpp.sq b/src/ai/api/ai_gamesettings.hpp.sq index 7ffb63ff2c..d0df6d71bc 100644 --- a/src/ai/api/ai_gamesettings.hpp.sq +++ b/src/ai/api/ai_gamesettings.hpp.sq @@ -17,8 +17,8 @@ void SQAIGameSettings_Register(Squirrel *engine) { SQAIGameSettings.PreRegister(engine); SQAIGameSettings.AddConstructor(engine, "x"); - SQAIGameSettings.DefSQStaticMethod(engine, &AIGameSettings::IsValid, "IsValid", 2, ".s"); - SQAIGameSettings.DefSQStaticMethod(engine, &AIGameSettings::GetValue, "GetValue", 2, ".s"); + SQAIGameSettings.DefSQStaticMethod(engine, &AIGameSettings::IsValid, "IsValid", 2, ".."); + SQAIGameSettings.DefSQStaticMethod(engine, &AIGameSettings::GetValue, "GetValue", 2, ".."); SQAIGameSettings.DefSQStaticMethod(engine, &AIGameSettings::IsDisabledVehicleType, "IsDisabledVehicleType", 2, ".i"); SQAIGameSettings.PostRegister(engine); diff --git a/src/ai/api/ai_group.hpp.sq b/src/ai/api/ai_group.hpp.sq index f54b984f53..c6ebdbdbcf 100644 --- a/src/ai/api/ai_group.hpp.sq +++ b/src/ai/api/ai_group.hpp.sq @@ -29,7 +29,7 @@ void SQAIGroup_Register(Squirrel *engine) { SQAIGroup.DefSQStaticMethod(engine, &AIGroup::CreateGroup, "CreateGroup", 2, ".i"); SQAIGroup.DefSQStaticMethod(engine, &AIGroup::DeleteGroup, "DeleteGroup", 2, ".i"); SQAIGroup.DefSQStaticMethod(engine, &AIGroup::GetVehicleType, "GetVehicleType", 2, ".i"); - SQAIGroup.DefSQStaticMethod(engine, &AIGroup::SetName, "SetName", 3, ".is"); + SQAIGroup.DefSQStaticMethod(engine, &AIGroup::SetName, "SetName", 3, ".i."); SQAIGroup.DefSQStaticMethod(engine, &AIGroup::GetName, "GetName", 2, ".i"); SQAIGroup.DefSQStaticMethod(engine, &AIGroup::EnableAutoReplaceProtection, "EnableAutoReplaceProtection", 3, ".ib"); SQAIGroup.DefSQStaticMethod(engine, &AIGroup::GetAutoReplaceProtection, "GetAutoReplaceProtection", 2, ".i"); diff --git a/src/ai/api/ai_log.hpp.sq b/src/ai/api/ai_log.hpp.sq index 8c432d4d9f..0db625fcca 100644 --- a/src/ai/api/ai_log.hpp.sq +++ b/src/ai/api/ai_log.hpp.sq @@ -17,9 +17,9 @@ void SQAILog_Register(Squirrel *engine) { SQAILog.PreRegister(engine); SQAILog.AddConstructor(engine, "x"); - SQAILog.DefSQStaticMethod(engine, &AILog::Info, "Info", 2, ".s"); - SQAILog.DefSQStaticMethod(engine, &AILog::Warning, "Warning", 2, ".s"); - SQAILog.DefSQStaticMethod(engine, &AILog::Error, "Error", 2, ".s"); + SQAILog.DefSQStaticMethod(engine, &AILog::Info, "Info", 2, ".."); + SQAILog.DefSQStaticMethod(engine, &AILog::Warning, "Warning", 2, ".."); + SQAILog.DefSQStaticMethod(engine, &AILog::Error, "Error", 2, ".."); SQAILog.PostRegister(engine); } diff --git a/src/ai/api/ai_road.cpp b/src/ai/api/ai_road.cpp index 4cbce4a689..0aa9c213b6 100644 --- a/src/ai/api/ai_road.cpp +++ b/src/ai/api/ai_road.cpp @@ -75,6 +75,7 @@ { if (!::IsValidTile(t1)) return false; if (!::IsValidTile(t2)) return false; + if (!IsRoadTypeAvailable(GetCurrentRoadType())) return false; /* Tiles not neighbouring */ if ((abs((int)::TileX(t1) - (int)::TileX(t2)) + abs((int)::TileY(t1) - (int)::TileY(t2))) != 1) return false; @@ -421,6 +422,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia /* static */ int32 AIRoad::GetNeighbourRoadCount(TileIndex tile) { if (!::IsValidTile(tile)) return false; + if (!IsRoadTypeAvailable(GetCurrentRoadType())) return false; ::RoadTypes rts = ::RoadTypeToRoadTypes((::RoadType)GetCurrentRoadType()); int32 neighbour = 0; @@ -461,6 +463,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia EnforcePrecondition(false, ::IsValidTile(end)); EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end)); EnforcePrecondition(false, !one_way || AIObject::GetRoadType() == ::ROADTYPE_ROAD); + EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); return AIObject::DoCommand(end, start, (::TileY(start) != ::TileY(end) ? 4 : 0) | (((start < end) == !full) ? 1 : 2) | (AIObject::GetRoadType() << 3) | ((one_way ? 1 : 0) << 5), CMD_BUILD_LONG_ROAD); } @@ -491,6 +494,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsValidTile(front)); EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front)); + EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0); @@ -505,6 +509,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front)); EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); EnforcePrecondition(false, road_veh_type == ROADVEHTYPE_BUS || road_veh_type == ROADVEHTYPE_TRUCK); + EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); uint entrance_dir; if (drive_through) { @@ -536,6 +541,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia EnforcePrecondition(false, ::IsValidTile(start)); EnforcePrecondition(false, ::IsValidTile(end)); EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end)); + EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); return AIObject::DoCommand(end, start, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD); } @@ -545,6 +551,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia EnforcePrecondition(false, ::IsValidTile(start)); EnforcePrecondition(false, ::IsValidTile(end)); EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end)); + EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); return AIObject::DoCommand(end, start, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD); } diff --git a/src/ai/api/ai_road.hpp b/src/ai/api/ai_road.hpp index 33af0f0119..c20186e073 100644 --- a/src/ai/api/ai_road.hpp +++ b/src/ai/api/ai_road.hpp @@ -134,6 +134,7 @@ public: * center of the second tile. * @param tile_from The source tile. * @param tile_to The destination tile. + * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @pre AIMap::IsValidTile(tile_from). * @pre AIMap::IsValidTile(tile_to). * @pre 'tile_from' and 'tile_to' are directly neighbouring tiles. @@ -197,6 +198,7 @@ public: * Count how many neighbours are road. * @param tile The tile to check on. * @pre AIMap::IsValidTile(tile). + * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @return 0 means no neighbour road; max value is 4. */ static int32 GetNeighbourRoadCount(TileIndex tile); @@ -237,6 +239,7 @@ public: * @pre 'start' and 'end' are in a straight line, i.e. * AIMap::GetTileX(start) == AIMap::GetTileX(end) or * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @exception AIError::ERR_ALREADY_BUILT * @exception AIError::ERR_LAND_SLOPED_WRONG * @exception AIError::ERR_AREA_NOT_CLEAR @@ -284,6 +287,7 @@ public: * @pre 'start' and 'end' are in a straight line, i.e. * AIMap::GetTileX(start) == AIMap::GetTileX(end) or * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @exception AIError::ERR_ALREADY_BUILT * @exception AIError::ERR_LAND_SLOPED_WRONG * @exception AIError::ERR_AREA_NOT_CLEAR @@ -328,6 +332,7 @@ public: * @pre AIMap::IsValidTile(tile). * @pre AIMap::IsValidTile(front). * @pre 'tile' is not equal to 'front', but in a straight line of it. + * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @exception AIError::ERR_FLAT_LAND_REQUIRED * @exception AIError::ERR_AREA_NOT_CLEAR * @return Whether the road depot has been/can be build or not. @@ -344,6 +349,7 @@ public: * @pre AIMap::IsValidTile(front). * @pre 'tile' is not equal to 'front', but in a straight line of it. * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). + * @pre GetCurrentRoadType() == ROADTYPE_ROAD. * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception AIError::ERR_AREA_NOT_CLEAR * @exception AIError::ERR_FLAT_LAND_REQUIRED @@ -359,7 +365,7 @@ public: /** * Builds a drive-through road bus or truck station. - * @param tile Place to build the depot. + * @param tile Place to build the station. * @param front A tile on the same axis with 'tile' as the station shall be oriented. * @param road_veh_type Whether to build a truck or bus station. * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. @@ -367,6 +373,7 @@ public: * @pre AIMap::IsValidTile(front). * @pre 'tile' is not equal to 'front', but in a straight line of it. * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). + * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception AIError::ERR_AREA_NOT_CLEAR * @exception AIError::ERR_FLAT_LAND_REQUIRED @@ -389,6 +396,7 @@ public: * @pre 'start' and 'end' are in a straight line, i.e. * AIMap::GetTileX(start) == AIMap::GetTileX(end) or * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception AIError::ERR_VEHICLE_IN_THE_WAY * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS @@ -406,6 +414,7 @@ public: * @pre 'start' and 'end' are in a straight line, i.e. * AIMap::GetTileX(start) == AIMap::GetTileX(end) or * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception AIError::ERR_VEHICLE_IN_THE_WAY * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS diff --git a/src/ai/api/ai_sign.hpp.sq b/src/ai/api/ai_sign.hpp.sq index f288c072c4..7e5c217879 100644 --- a/src/ai/api/ai_sign.hpp.sq +++ b/src/ai/api/ai_sign.hpp.sq @@ -30,10 +30,10 @@ void SQAISign_Register(Squirrel *engine) { SQAISign.DefSQStaticMethod(engine, &AISign::GetMaxSignID, "GetMaxSignID", 1, "."); SQAISign.DefSQStaticMethod(engine, &AISign::IsValidSign, "IsValidSign", 2, ".i"); - SQAISign.DefSQStaticMethod(engine, &AISign::SetName, "SetName", 3, ".is"); + SQAISign.DefSQStaticMethod(engine, &AISign::SetName, "SetName", 3, ".i."); SQAISign.DefSQStaticMethod(engine, &AISign::GetName, "GetName", 2, ".i"); SQAISign.DefSQStaticMethod(engine, &AISign::GetLocation, "GetLocation", 2, ".i"); - SQAISign.DefSQStaticMethod(engine, &AISign::BuildSign, "BuildSign", 3, ".is"); + SQAISign.DefSQStaticMethod(engine, &AISign::BuildSign, "BuildSign", 3, ".i."); SQAISign.DefSQStaticMethod(engine, &AISign::RemoveSign, "RemoveSign", 2, ".i"); SQAISign.PostRegister(engine); diff --git a/src/ai/api/ai_station.hpp.sq b/src/ai/api/ai_station.hpp.sq index 23c9fc6f73..72a239cbe3 100644 --- a/src/ai/api/ai_station.hpp.sq +++ b/src/ai/api/ai_station.hpp.sq @@ -57,7 +57,7 @@ void SQAIStation_Register(Squirrel *engine) { SQAIStation.DefSQStaticMethod(engine, &AIStation::IsValidStation, "IsValidStation", 2, ".i"); SQAIStation.DefSQStaticMethod(engine, &AIStation::GetStationID, "GetStationID", 2, ".i"); SQAIStation.DefSQStaticMethod(engine, &AIStation::GetName, "GetName", 2, ".i"); - SQAIStation.DefSQStaticMethod(engine, &AIStation::SetName, "SetName", 3, ".is"); + SQAIStation.DefSQStaticMethod(engine, &AIStation::SetName, "SetName", 3, ".i."); SQAIStation.DefSQStaticMethod(engine, &AIStation::GetLocation, "GetLocation", 2, ".i"); SQAIStation.DefSQStaticMethod(engine, &AIStation::GetConstructionDate, "GetConstructionDate", 2, ".i"); SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii"); diff --git a/src/ai/api/ai_vehicle.hpp.sq b/src/ai/api/ai_vehicle.hpp.sq index 16abc1367c..b5cc1ca646 100644 --- a/src/ai/api/ai_vehicle.hpp.sq +++ b/src/ai/api/ai_vehicle.hpp.sq @@ -102,7 +102,7 @@ void SQAIVehicle_Register(Squirrel *engine) { SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidVehicle, "IsValidVehicle", 2, ".i"); SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetNumWagons, "GetNumWagons", 2, ".i"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SetName, "SetName", 3, ".is"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SetName, "SetName", 3, ".i."); SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetName, "GetName", 2, ".i"); SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetLocation, "GetLocation", 2, ".i"); SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetEngineType, "GetEngineType", 2, ".i"); diff --git a/src/ai/api/ai_waypoint.hpp.sq b/src/ai/api/ai_waypoint.hpp.sq index ef17875ac9..8accbb6321 100644 --- a/src/ai/api/ai_waypoint.hpp.sq +++ b/src/ai/api/ai_waypoint.hpp.sq @@ -26,7 +26,7 @@ void SQAIWaypoint_Register(Squirrel *engine) { SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::IsValidWaypoint, "IsValidWaypoint", 2, ".i"); SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::GetWaypointID, "GetWaypointID", 2, ".i"); SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::GetName, "GetName", 2, ".i"); - SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::SetName, "SetName", 3, ".is"); + SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::SetName, "SetName", 3, ".i."); SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::GetLocation, "GetLocation", 2, ".i"); SQAIWaypoint.PostRegister(engine); diff --git a/src/ai/api/squirrel_export.awk b/src/ai/api/squirrel_export.awk index 37b1cdfa1f..b3b7b83ea6 100644 --- a/src/ai/api/squirrel_export.awk +++ b/src/ai/api/squirrel_export.awk @@ -375,7 +375,7 @@ BEGIN { sub("^[ ]*", "", params[len]) if (match(params[len], "\\*") || match(params[len], "&")) { if (match(params[len], "^char")) { - types = types "s" + types = types "." } else if (match(params[len], "^void")) { types = types "p" } else if (match(params[len], "^Array")) { diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp index 580f49cbd7..2310b70cb0 100644 --- a/src/script/squirrel_helper.hpp +++ b/src/script/squirrel_helper.hpp @@ -96,8 +96,18 @@ namespace SQConvert { template <> inline int16 GetParam(ForceType , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger (vm, index, &tmp); return tmp; } template <> inline int32 GetParam(ForceType , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger (vm, index, &tmp); return tmp; } template <> inline bool GetParam(ForceType , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQBool tmp; sq_getbool (vm, index, &tmp); return tmp != 0; } - template <> inline const char *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { const SQChar *tmp; sq_getstring (vm, index, &tmp); char *tmp_str = strdup(FS2OTTD(tmp)); *ptr->Append() = (void *)tmp_str; str_validate(tmp_str, tmp_str + strlen(tmp_str)); return tmp_str; } template <> inline void *GetParam(ForceType , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer tmp; sq_getuserpointer(vm, index, &tmp); return tmp; } + template <> inline const char *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) + { + sq_tostring(vm, index); + const SQChar *tmp; + sq_getstring(vm, -1, &tmp); + char *tmp_str = strdup(FS2OTTD(tmp)); + sq_poptop(vm); + *ptr->Append() = (void *)tmp_str; + str_validate(tmp_str, tmp_str + strlen(tmp_str)); + return tmp_str; + } template <> inline Array *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) {