diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/api/ai_town.cpp | 7 | ||||
-rw-r--r-- | src/ai/api/ai_town.hpp | 19 | ||||
-rw-r--r-- | src/ai/api/ai_town.hpp.sq | 8 |
3 files changed, 34 insertions, 0 deletions
diff --git a/src/ai/api/ai_town.cpp b/src/ai/api/ai_town.cpp index 60fbdb799..117c35f39 100644 --- a/src/ai/api/ai_town.cpp +++ b/src/ai/api/ai_town.cpp @@ -192,3 +192,10 @@ } return max(0, 2 - num); } + +/* static */ AITown::RoadLayout AITown::GetRoadLayout(TownID town_id) +{ + if (!IsValidTown(town_id)) return ROAD_LAYOUT_INVALID; + + return (AITown::RoadLayout)((TownLayout)::GetTown(town_id)->layout); +} diff --git a/src/ai/api/ai_town.hpp b/src/ai/api/ai_town.hpp index a4516f94b..02b806b4c 100644 --- a/src/ai/api/ai_town.hpp +++ b/src/ai/api/ai_town.hpp @@ -85,6 +85,18 @@ public: }; /** + * Possible layouts for the roads in a town. + */ + enum RoadLayout { + /* Order IS important, as it matches an in-game value */ + ROAD_LAYOUT_ORIGINAL, ///< Original algorithm (min. 1 distance between roads). + ROAD_LAYOUT_BETTER_ROADS, ///< Extended original algorithm (min. 2 distance between roads). + ROAD_LAYOUT_2x2, ///< Geometric 2x2 grid algorithm + ROAD_LAYOUT_3x3, ///< Geometric 3x3 grid algorithm + ROAD_LAYOUT_INVALID = -1, ///< The layout for invalid towns. + }; + + /** * Gets the maximum town index; there are no valid towns with a higher index. * @return The maximum town index. * @post Return value is always non-negative. @@ -279,6 +291,13 @@ public: * @return The noise that still can be added. */ static int GetAllowedNoise(TownID town_id); + + /** + * Get the road layout for a town. + * @param town_id The town to get the road layout from. + * @return The RoadLayout for the town. + */ + static RoadLayout GetRoadLayout(TownID town_id); }; #endif /* AI_TOWN_HPP */ diff --git a/src/ai/api/ai_town.hpp.sq b/src/ai/api/ai_town.hpp.sq index 164f0ffa5..abc789fbc 100644 --- a/src/ai/api/ai_town.hpp.sq +++ b/src/ai/api/ai_town.hpp.sq @@ -9,6 +9,8 @@ namespace SQConvert { template <> int Return<AITown::TownAction>(HSQUIRRELVM vm, AITown::TownAction res) { sq_pushinteger(vm, (int32)res); return 1; } template <> AITown::TownRating GetParam(ForceType<AITown::TownRating>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AITown::TownRating)tmp; } template <> int Return<AITown::TownRating>(HSQUIRRELVM vm, AITown::TownRating res) { sq_pushinteger(vm, (int32)res); return 1; } + template <> AITown::RoadLayout GetParam(ForceType<AITown::RoadLayout>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AITown::RoadLayout)tmp; } + template <> int Return<AITown::RoadLayout>(HSQUIRRELVM vm, AITown::RoadLayout res) { sq_pushinteger(vm, (int32)res); return 1; } /* Allow AITown to be used as Squirrel parameter */ template <> AITown *GetParam(ForceType<AITown *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITown *)instance; } @@ -41,6 +43,11 @@ void SQAITown_Register(Squirrel *engine) { SQAITown.DefSQConst(engine, AITown::TOWN_RATING_EXCELLENT, "TOWN_RATING_EXCELLENT"); SQAITown.DefSQConst(engine, AITown::TOWN_RATING_OUTSTANDING, "TOWN_RATING_OUTSTANDING"); SQAITown.DefSQConst(engine, AITown::TOWN_RATING_INVALID, "TOWN_RATING_INVALID"); + SQAITown.DefSQConst(engine, AITown::ROAD_LAYOUT_ORIGINAL, "ROAD_LAYOUT_ORIGINAL"); + SQAITown.DefSQConst(engine, AITown::ROAD_LAYOUT_BETTER_ROADS, "ROAD_LAYOUT_BETTER_ROADS"); + SQAITown.DefSQConst(engine, AITown::ROAD_LAYOUT_2x2, "ROAD_LAYOUT_2x2"); + SQAITown.DefSQConst(engine, AITown::ROAD_LAYOUT_3x3, "ROAD_LAYOUT_3x3"); + SQAITown.DefSQConst(engine, AITown::ROAD_LAYOUT_INVALID, "ROAD_LAYOUT_INVALID"); SQAITown.DefSQStaticMethod(engine, &AITown::GetClassName, "GetClassName", 1, "x"); SQAITown.DefSQStaticMethod(engine, &AITown::GetMaxTownID, "GetMaxTownID", 1, "x"); @@ -64,6 +71,7 @@ void SQAITown_Register(Squirrel *engine) { SQAITown.DefSQStaticMethod(engine, &AITown::PerformTownAction, "PerformTownAction", 3, "xii"); SQAITown.DefSQStaticMethod(engine, &AITown::GetRating, "GetRating", 3, "xii"); SQAITown.DefSQStaticMethod(engine, &AITown::GetAllowedNoise, "GetAllowedNoise", 2, "xi"); + SQAITown.DefSQStaticMethod(engine, &AITown::GetRoadLayout, "GetRoadLayout", 2, "xi"); SQAITown.PostRegister(engine); } |