mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-19 15:25:39 +00:00
(svn r15343) -Add [NoAI]: Add AITown::GetRoadLayout so AIs can get the road layout per town.
This commit is contained in:
parent
e80255c4ae
commit
70a38e8a60
@ -192,3 +192,10 @@
|
|||||||
}
|
}
|
||||||
return max(0, 2 - num);
|
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);
|
||||||
|
}
|
||||||
|
@ -84,6 +84,18 @@ public:
|
|||||||
TOWN_RATING_INVALID = -1, ///< The town rating for invalid towns/companies.
|
TOWN_RATING_INVALID = -1, ///< The town rating for invalid towns/companies.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Gets the maximum town index; there are no valid towns with a higher index.
|
||||||
* @return The maximum town index.
|
* @return The maximum town index.
|
||||||
@ -279,6 +291,13 @@ public:
|
|||||||
* @return The noise that still can be added.
|
* @return The noise that still can be added.
|
||||||
*/
|
*/
|
||||||
static int GetAllowedNoise(TownID town_id);
|
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 */
|
#endif /* AI_TOWN_HPP */
|
||||||
|
@ -9,6 +9,8 @@ namespace SQConvert {
|
|||||||
template <> int Return<AITown::TownAction>(HSQUIRRELVM vm, AITown::TownAction res) { sq_pushinteger(vm, (int32)res); return 1; }
|
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 <> 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 <> 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 */
|
/* 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; }
|
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_EXCELLENT, "TOWN_RATING_EXCELLENT");
|
||||||
SQAITown.DefSQConst(engine, AITown::TOWN_RATING_OUTSTANDING, "TOWN_RATING_OUTSTANDING");
|
SQAITown.DefSQConst(engine, AITown::TOWN_RATING_OUTSTANDING, "TOWN_RATING_OUTSTANDING");
|
||||||
SQAITown.DefSQConst(engine, AITown::TOWN_RATING_INVALID, "TOWN_RATING_INVALID");
|
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::GetClassName, "GetClassName", 1, "x");
|
||||||
SQAITown.DefSQStaticMethod(engine, &AITown::GetMaxTownID, "GetMaxTownID", 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::PerformTownAction, "PerformTownAction", 3, "xii");
|
||||||
SQAITown.DefSQStaticMethod(engine, &AITown::GetRating, "GetRating", 3, "xii");
|
SQAITown.DefSQStaticMethod(engine, &AITown::GetRating, "GetRating", 3, "xii");
|
||||||
SQAITown.DefSQStaticMethod(engine, &AITown::GetAllowedNoise, "GetAllowedNoise", 2, "xi");
|
SQAITown.DefSQStaticMethod(engine, &AITown::GetAllowedNoise, "GetAllowedNoise", 2, "xi");
|
||||||
|
SQAITown.DefSQStaticMethod(engine, &AITown::GetRoadLayout, "GetRoadLayout", 2, "xi");
|
||||||
|
|
||||||
SQAITown.PostRegister(engine);
|
SQAITown.PostRegister(engine);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user