(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
--- a/bin/ai/regression/regression.nut Fri Apr 25 15:34:04 2008 +0000
+++ b/bin/ai/regression/regression.nut Fri Apr 25 15:51:12 2008 +0000
@@ -667,6 +667,11 @@
for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
print(" " + i + " => " + list.GetValue(i));
}
+ list.Valuate(AIStation.IsWithinTownRadius, 0);
+ print(" IsWithinTownRadius(0) ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
list = AIVehicleList_Station(3);
@@ -878,6 +883,11 @@
for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
print(" " + i + " => " + list.GetValue(i));
}
+ list.Valuate(AITile.GetOwner);
+ print(" GetOwner() ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
list.Valuate(AITile.GetCargoAcceptance, 0, 1, 1, 3);
list.KeepAboveValue(10);
@@ -981,6 +991,11 @@
for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
print(" " + i + " => " + list.GetValue(i));
}
+ list.Valuate(AITown.IsWithinTownRadius, AITown.GetLocation(0));
+ print(" IsWithinTownRadius(" + AITown.GetLocation(0) + ") ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
list.Valuate(AITown.GetPopulation);
list.KeepAboveValue(500);
print(" KeepAboveValue(500): done");
@@ -1083,6 +1098,7 @@
print(" IsInDepot(): " + AIVehicle.IsInDepot(11));
print(" IsStoppedInDepot(): " + AIVehicle.IsStoppedInDepot(11));
+ print(" GetOwner(): " + AITile.GetOwner(32119));
print(" BuildVehicle(): " + AIVehicle.BuildVehicle(32119, 219));
print(" IsValidVehicle(13): " + AIVehicle.IsValidVehicle(13));
print(" IsInDepot(13): " + AIVehicle.IsInDepot(13));
--- a/bin/ai/regression/regression.txt Fri Apr 25 15:34:04 2008 +0000
+++ b/bin/ai/regression/regression.txt Fri Apr 25 15:51:12 2008 +0000
@@ -5697,6 +5697,40 @@
41895 => 16277
41639 => 16186
41383 => 16097
+ GetOwner() ListDump:
+ 42415 => 9
+ 42414 => 9
+ 42413 => 9
+ 42410 => 9
+ 42409 => 9
+ 42408 => 9
+ 42407 => 9
+ 42159 => 9
+ 42158 => 9
+ 42157 => 9
+ 42156 => 9
+ 42153 => 9
+ 42151 => 9
+ 41903 => 9
+ 41902 => 9
+ 41901 => 9
+ 41900 => 9
+ 41899 => 9
+ 41897 => 9
+ 41895 => 9
+ 41647 => 9
+ 41646 => 9
+ 41645 => 9
+ 41644 => 9
+ 41643 => 9
+ 41641 => 9
+ 41639 => 9
+ 41391 => 9
+ 41390 => 9
+ 41389 => 9
+ 41388 => 9
+ 41387 => 9
+ 41383 => 9
CargoAcceptance(): done
KeepAboveValue(10): done
Count(): 14
@@ -6186,6 +6220,35 @@
26 => 2458
6 => 1088
20 => 922
+ IsWithinTownRadius(15508) ListDump:
+ 0 => 1
+ 27 => 0
+ 26 => 0
+ 25 => 0
+ 24 => 0
+ 23 => 0
+ 22 => 0
+ 21 => 0
+ 20 => 0
+ 19 => 0
+ 18 => 0
+ 17 => 0
+ 16 => 0
+ 15 => 0
+ 14 => 0
+ 13 => 0
+ 12 => 0
+ 11 => 0
+ 10 => 0
+ 9 => 0
+ 8 => 0
+ 7 => 0
+ 6 => 0
+ 5 => 0
+ 4 => 0
+ 3 => 0
+ 2 => 0
+ 1 => 0
KeepAboveValue(500): done
Count(): 11
Population ListDump:
@@ -6263,6 +6326,7 @@
GetCargoLoad(): 0
IsInDepot(): false
IsStoppedInDepot(): false
+ GetOwner(): 1
BuildVehicle(): 13
IsValidVehicle(13): true
IsInDepot(13): true
@@ -6390,6 +6454,9 @@
DistanceSquareToTile(30000) ListDump:
3 => 8818
2 => 7058
+ IsWithinTownRadius(0) ListDump:
+ 3 => 0
+ 2 => 0
--VehicleList_Station--
Count(): 1
--- a/src/ai/api/ai_station.cpp Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_station.cpp Fri Apr 25 15:51:12 2008 +0000
@@ -5,6 +5,7 @@
#include "ai_station.hpp"
#include "ai_cargo.hpp"
#include "ai_map.hpp"
+#include "ai_town.hpp"
#include "../../openttd.h"
#include "../../debug.h"
#include "../../station_map.h"
@@ -87,3 +88,8 @@
{
return AIMap::DistanceSquare(tile, GetLocation(station_id));
}
+
+/* static */ bool AIStation::IsWithinTownRadius(StationID station_id, TownID town_id)
+{
+ return AITown::IsWithinTownRadius(town_id, GetLocation(station_id));
+}
--- a/src/ai/api/ai_station.hpp Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_station.hpp Fri Apr 25 15:51:12 2008 +0000
@@ -122,6 +122,14 @@
* @return The distance between station and tile.
*/
static int32 GetDistanceSquareToTile(StationID station_id, TileIndex tile);
+
+ /**
+ * Find out if this station is within the rating influence of a town.
+ * @param station_id The station to check.
+ * @param town_id The town to check.
+ * @return True if the tile is within the rating influence of the town.
+ */
+ static bool IsWithinTownRadius(StationID station_id, TownID town_id);
};
DECLARE_ENUM_AS_BIT_SET(AIStation::StationType);
--- a/src/ai/api/ai_station.hpp.sq Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_station.hpp.sq Fri Apr 25 15:51:12 2008 +0000
@@ -59,6 +59,7 @@
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCoverageRadius, "GetCoverageRadius", 2, "xi");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, "xii");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetDistanceSquareToTile, "GetDistanceSquareToTile", 3, "xii");
+ SQAIStation.DefSQStaticMethod(engine, &AIStation::IsWithinTownRadius, "IsWithinTownRadius", 3, "xii");
SQAIStation.PostRegister(engine);
}
--- a/src/ai/api/ai_tile.cpp Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_tile.cpp Fri Apr 25 15:51:12 2008 +0000
@@ -93,6 +93,15 @@
return ::TileHeight(tile);
}
+/* static */ AICompany::CompanyIndex AITile::GetOwner(TileIndex tile)
+{
+ if (!::IsValidTile(tile)) return AICompany::INVALID_COMPANY;
+ if (::IsTileType(tile, MP_HOUSE)) return AICompany::INVALID_COMPANY;
+ if (::IsTileType(tile, MP_INDUSTRY)) return AICompany::INVALID_COMPANY;
+
+ return AICompany::ResolveCompanyIndex((AICompany::CompanyIndex)(byte)::GetTileOwner(tile));
+}
+
/* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)
{
if (!::IsValidTile(tile)) return false;
--- a/src/ai/api/ai_tile.hpp Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_tile.hpp Fri Apr 25 15:51:12 2008 +0000
@@ -7,6 +7,7 @@
#include "ai_abstractlist.hpp"
#include "ai_error.hpp"
+#include "ai_company.hpp"
/**
* Class that handles all tile related functions.
@@ -137,6 +138,15 @@
static int32 GetHeight(TileIndex tile);
/**
+ * Get the owner of the tile.
+ * @param tile The tile to get the owner from.
+ * @pre AIMap::IsValidTile(tile).
+ * @return The CompanyIndex of the owner of the tile, or INVALID_COMPANY if
+ * there is no owner (grass/industry/water tiles, etc.).
+ */
+ static AICompany::CompanyIndex GetOwner(TileIndex tile);
+
+ /**
* Check how much cargo this tile accepts.
* It creates a radius around the tile, and adds up all acceptance of this
* cargo.
--- a/src/ai/api/ai_tile.hpp.sq Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_tile.hpp.sq Fri Apr 25 15:51:12 2008 +0000
@@ -64,6 +64,7 @@
SQAITile.DefSQStaticMethod(engine, &AITile::GetSlope, "GetSlope", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetComplementSlope, "GetComplementSlope", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetHeight, "GetHeight", 2, "xi");
+ SQAITile.DefSQStaticMethod(engine, &AITile::GetOwner, "GetOwner", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoAcceptance, "GetCargoAcceptance", 6, "xiiiii");
SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoProduction, "GetCargoProduction", 6, "xiiiii");
SQAITile.DefSQStaticMethod(engine, &AITile::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, "xii");
--- a/src/ai/api/ai_town.cpp Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_town.cpp Fri Apr 25 15:51:12 2008 +0000
@@ -60,3 +60,9 @@
{
return AIMap::DistanceSquare(tile, GetLocation(town_id));
}
+
+/* static */ bool AITown::IsWithinTownRadius(TownID town_id, TileIndex tile)
+{
+ const Town *t = ::GetTown(town_id);
+ return ((uint32)GetDistanceSquareToTile(town_id, tile) <= t->squared_town_zone_radius[0]);
+}
--- a/src/ai/api/ai_town.hpp Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_town.hpp Fri Apr 25 15:51:12 2008 +0000
@@ -80,6 +80,14 @@
* @return The distance between town and tile.
*/
static int32 GetDistanceSquareToTile(TownID town_id, TileIndex tile);
+
+ /**
+ * Find out if this tile is within the rating influence of a town.
+ * @param town_id The town to check.
+ * @param tile The tile to check.
+ * @return True if the tile is within the rating influence of the town.
+ */
+ static bool IsWithinTownRadius(TownID town_id, TileIndex tile);
};
#endif /* AI_TOWN_HPP */
--- a/src/ai/api/ai_town.hpp.sq Fri Apr 25 15:34:04 2008 +0000
+++ b/src/ai/api/ai_town.hpp.sq Fri Apr 25 15:51:12 2008 +0000
@@ -26,6 +26,7 @@
SQAITown.DefSQStaticMethod(engine, &AITown::GetLocation, "GetLocation", 2, "xi");
SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, "xii");
SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceSquareToTile, "GetDistanceSquareToTile", 3, "xii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::IsWithinTownRadius, "IsWithinTownRadius", 3, "xii");
SQAITown.PostRegister(engine);
}