Changeset - r28702:1f79991b026a
[Not reviewed]
master
0 6 0
Loïc Guilloux - 5 months ago 2024-02-06 19:22:18
glx22@users.noreply.github.com
Add: [Script] ScriptTileList_StationCoverage (#12015)
6 files changed with 192 insertions and 4 deletions:
0 comments (0 inline, 0 general)
regression/regression/main.nut
Show inline comments
 
@@ -1265,192 +1265,207 @@ function Regression::Road()
 
	print("    IsRoadTile():                  " + AIRoad.IsRoadTile(33415));
 
}
 

	
 
function Regression::Sign()
 
{
 
	local j = 0;
 

	
 
	print("");
 
	print("--Sign--");
 
	print("  BuildSign(33410, 'Some Sign'):       " + AISign.BuildSign(33410, "Some Sign"));
 
	print("  BuildSign(33411, 'Test'):            " + AISign.BuildSign(33411, "Test"));
 
	print("  SetName(1, 'Test2'):                 " + AISign.SetName(1, "Test2"));
 
	local sign_id = AISign.BuildSign(33409, "Some other Sign");
 
	print("  BuildSign(33409, 'Some other Sign'): " + sign_id);
 
	print("  RemoveSign(" + sign_id + "):                       " + AISign.RemoveSign(sign_id));
 
	print("");
 
	local list = AISignList();
 
	list.Sort(AIList.SORT_BY_ITEM, AIList.SORT_ASCENDING);
 
	for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
 
		j++;
 
		print("  Sign " + i);
 
		print("    IsValidSign():   " + AISign.IsValidSign(i));
 
		print("    GetName():       " + AISign.GetName(i));
 
		print("    GetLocation():   " + AISign.GetLocation(i));
 
	}
 
	print("  Valid Signs:       " + j);
 
}
 

	
 
function Regression::Station()
 
{
 
	print("");
 
	print("--Station--");
 
	print("  IsValidStation(0):        " + AIStation.IsValidStation(0));
 
	print("  IsValidStation(1000):     " + AIStation.IsValidStation(1000));
 
	print("  GetName(0):               " + AIStation.GetName(0));
 
	print("  SetName(0):               " + AIStation.SetName(0, "Look, a station"));
 
	print("  GetName(0):               " + AIStation.GetName(0));
 
	print("  GetLocation(1):           " + AIStation.GetLocation(1));
 
	print("  GetLocation(1000):        " + AIStation.GetLocation(1000));
 
	print("  GetStationID(33411):      " + AIStation.GetStationID(33411));
 
	print("  GetStationID(34411):      " + AIStation.GetStationID(34411));
 
	print("  GetStationID(33411):      " + AIStation.GetStationID(33411));
 
	print("  HasRoadType(3, TRAM):     " + AIStation.HasRoadType(3, AIRoad.ROADTYPE_TRAM));
 
	print("  HasRoadType(3, ROAD):     " + AIStation.HasRoadType(3, AIRoad.ROADTYPE_ROAD));
 
	print("  HasRoadType(33411, TRAM): " + AIRoad.HasRoadType(33411, AIRoad.ROADTYPE_TRAM));
 
	print("  HasRoadType(33411, ROAD): " + AIRoad.HasRoadType(33411, AIRoad.ROADTYPE_ROAD));
 
	print("  HasStationType(3, BUS):   " + AIStation.HasStationType(3, AIStation.STATION_BUS_STOP));
 
	print("  HasStationType(3, TRAIN): " + AIStation.HasStationType(3, AIStation.STATION_TRAIN));
 

	
 
	print("  GetCoverageRadius(BUS):   " + AIStation.GetCoverageRadius(AIStation.STATION_BUS_STOP));
 
	print("  GetCoverageRadius(TRUCK): " + AIStation.GetCoverageRadius(AIStation.STATION_TRUCK_STOP));
 
	print("  GetCoverageRadius(TRAIN): " + AIStation.GetCoverageRadius(AIStation.STATION_TRAIN));
 

	
 
	print("  GetNearestTown():         " + AIStation.GetNearestTown(0));
 
	print("  GetNearestTown():         " + AIStation.GetNearestTown(10000));
 
	print("  GetNearestTown():         " + AIStation.GetNearestTown(3));
 

	
 
	print("");
 
	print("--CargoWaiting--");
 
	for (local cargo = 0; cargo <= 1000; cargo += 1000) {
 
		for (local station0 = 0; station0 <= 1000; station0 += 1000) {
 
			print("  GetCargoWaiting(" + station0 + ", " + cargo + "): " +
 
					AIStation.GetCargoWaiting(station0, cargo));
 
			for (local station1 = 0; station1 <= 1000; station1 += 1000) {
 
				print("  GetCargoWaitingFrom(" + station0 + ", " + station1 + ", " + cargo + "): " +
 
						AIStation.GetCargoWaitingFrom(station0, station1, cargo));
 
				print("  GetCargoWaitingVia(" + station0 + ", " + station1 + ", " + cargo + "): " +
 
						AIStation.GetCargoWaitingFrom(station0, station1, cargo));
 
				for (local station2 = 0; station2 <= 1000; station2 += 1000) {
 
					print("  GetCargoWaitingFromVia(" + station0 + ", " + station1 + ", " + station2 + ", " + cargo + "): " +
 
							AIStation.GetCargoWaitingFromVia(station0, station1, station2, cargo));
 
				}
 
			}
 
		}
 
	}
 

	
 
	print("");
 
	print("--CargoPlanned--");
 
	for (local cargo = 0; cargo <= 1000; cargo += 1000) {
 
		for (local station0 = 0; station0 <= 1000; station0 += 1000) {
 
			print("  GetCargoPlanned(" + station0 + ", " + cargo + "): " +
 
					AIStation.GetCargoPlanned(station0, cargo));
 
			for (local station1 = 0; station1 <= 1000; station1 += 1000) {
 
				print("  GetCargoPlannedFrom(" + station0 + ", " + station1 + ", " + cargo + "): " +
 
						AIStation.GetCargoPlannedFrom(station0, station1, cargo));
 
				print("  GetCargoPlannedVia(" + station0 + ", " + station1 + ", " + cargo + "): " +
 
						AIStation.GetCargoPlannedFrom(station0, station1, cargo));
 
				for (local station2 = 0; station2 <= 1000; station2 += 1000) {
 
					print("  GetCargoPlannedFromVia(" + station0 + ", " + station1 + ", " + station2 + ", " + cargo + "): " +
 
							AIStation.GetCargoPlannedFromVia(station0, station1, station2, cargo));
 
				}
 
			}
 
		}
 
	}
 
}
 

	
 
function Regression::StationList()
 
{
 
	print("");
 
	print("--StationList--");
 
	local road_stations = AIStationList(AIStation.STATION_TRUCK_STOP);
 
	for (local st = road_stations.Begin(); !road_stations.IsEnd(); st = road_stations.Next()) {
 
		print("  GetName(): " + AIStation.GetName(st));
 
		print("  TileList_StationCoverage:");
 
		local coverage = AITileList_StationCoverage(st);
 
		for (local i = coverage.Begin(); !coverage.IsEnd(); i = coverage.Next()) {
 
			print("    " + i);
 
		}
 
	}
 
}
 

	
 
function Regression::Tile()
 
{
 
	print("");
 
	print("--Tile--");
 
	print("  HasTreeOnTile():      " + AITile.HasTreeOnTile(33148));
 
	print("  IsFarmTile():         " + AITile.IsFarmTile(32892));
 
	print("  IsRockTile():         " + AITile.IsRockTile(31606));
 
	print("  IsRoughTile():        " + AITile.IsRoughTile(33674));
 
	print("  HasTreeOnTile():      " + AITile.HasTreeOnTile(33404));
 
	print("  IsFarmTile():         " + AITile.IsFarmTile(33404));
 
	print("  IsRockTile():         " + AITile.IsRockTile(33404));
 
	print("  IsRoughTile():        " + AITile.IsRoughTile(33404));
 
	print("  IsSnowTile():         " + AITile.IsSnowTile(33404));
 
	print("  IsDesertTile():       " + AITile.IsDesertTile(33404));
 
	print("  PlantTree():          " + AITile.PlantTree(33404));
 
	print("  HasTreeOnTile():      " + AITile.HasTreeOnTile(33404));
 
	print("  PlantTree():          " + AITile.PlantTree(33404));
 
	print("  HasTreeOnTile():      " + AITile.HasTreeOnTile(33661));
 
	print("  PlantTreeRectangle(): " + AITile.PlantTreeRectangle(33404, 2, 2));
 
	print("  HasTreeOnTile():      " + AITile.HasTreeOnTile(33661));
 
}
 

	
 
function Regression::TileList()
 
{
 
	local list = AITileList();
 

	
 
	print("");
 
	print("--TileList--");
 
	print("  Count():             " + list.Count());
 
	list.AddRectangle(27631 - 256 * 1, 256 * 1 + 27631 + 2);
 
	print("  Count():             " + list.Count());
 

	
 
	list.Valuate(AITile.GetSlope);
 
	print("  Slope():             done");
 
	print("  Count():             " + list.Count());
 
	print("  ListDump:");
 
	for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
 
		print("    " + i + " => " + list.GetValue(i));
 
		print("    " + i + " => " + AITile.GetComplementSlope(list.GetValue(i)));
 
		print("    " + i + " => " + AITile.IsSteepSlope(list.GetValue(i)));
 
		print("    " + i + " => " + AITile.IsHalftileSlope(list.GetValue(i)));
 
	}
 
	list.Clear();
 

	
 
	print("");
 
	print("--TileList--");
 
	print("  Count():             " + list.Count());
 
	list.AddRectangle(34436, 256 * 2 + 34436 + 8);
 
	print("  Count():             " + list.Count());
 

	
 
	list.Valuate(AITile.GetCornerHeight, AITile.CORNER_N);
 
	print("  Height():            done");
 
	print("  Count():             " + list.Count());
 
	print("  ListDump:");
 
	for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
 
		print("    " + i + " => " + list.GetValue(i));
 
	}
 

	
 
	list.Valuate(AITile.GetCornerHeight, AITile.CORNER_N);
 
	print("  CornerHeight(North): done");
 
	print("  Count():             " + list.Count());
 
	print("  ListDump:");
 
	for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
 
		print("    " + i + " => " + list.GetValue(i));
 
	}
 

	
 
	list.Valuate(AITile.GetMinHeight);
 
	print("  MinHeight():         done");
 
	print("  Count():             " + list.Count());
 
	print("  ListDump:");
 
	for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
 
		print("    " + i + " => " + list.GetValue(i));
 
	}
 

	
 
	list.Valuate(AITile.GetMaxHeight);
 
	print("  MaxHeight():         done");
 
	print("  Count():             " + list.Count());
 
	print("  ListDump:");
 
	for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
 
		print("    " + i + " => " + list.GetValue(i));
 
	}
 

	
 
	list.Valuate(AITile.GetSlope);
 
	list.KeepValue(0);
 
	print("  Slope():             done");
 
	print("  KeepValue(0):        done");
 
	print("  Count():             " + list.Count());
 
	print("  ListDump:");
 
	for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
 
		print("    " + i + " => " + list.GetValue(i));
 
	}
 

	
 
	list.Clear();
 
	list.AddRectangle(41895 - 256 * 2, 256 * 2 + 41895 + 8);
 
	list.Valuate(AITile.IsBuildable);
 
	list.KeepValue(1);
 
@@ -1896,142 +1911,143 @@ function Regression::Vehicle()
 
		print("    " + i + " => " + list.GetValue(i));
 
	}
 
	list.Valuate(AIVehicle.GetCargoLoad, 10);
 
	print("  VehicleType ListDump:");
 
	for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) {
 
		print("    " + i + " => " + list.GetValue(i));
 
	}
 
}
 

	
 
function Regression::PrintSubsidy(subsidy_id)
 
{
 
	print("      --Subsidy (" + subsidy_id + ") --");
 
	print("        IsValidSubsidy():      " + AISubsidy.IsValidSubsidy(subsidy_id));
 
	print("        IsAwarded():           " + AISubsidy.IsAwarded(subsidy_id));
 
	print("        GetAwardedTo():        " + AISubsidy.GetAwardedTo(subsidy_id));
 
	print("        GetExpireDate():       " + AISubsidy.GetExpireDate(subsidy_id));
 
	print("        GetSourceType():       " + AISubsidy.GetSourceType(subsidy_id));
 
	print("        GetSourceIndex():      " + AISubsidy.GetSourceIndex(subsidy_id));
 
	print("        GetDestinationType():  " + AISubsidy.GetDestinationType(subsidy_id));
 
	print("        GetDestinationIndex(): " + AISubsidy.GetDestinationIndex(subsidy_id));
 
	print("        GetCargoType():        " + AISubsidy.GetCargoType(subsidy_id));
 
}
 

	
 
function Regression::Math()
 
{
 
	print("");
 
	print("--Math--");
 
	print("  -2147483648 < -2147483647:   " + (-2147483648 < -2147483647));
 
	print("  -2147483648 < -1         :   " + (-2147483648 < -1         ));
 
	print("  -2147483648 <  0         :   " + (-2147483648 <  0         ));
 
	print("  -2147483648 <  1         :   " + (-2147483648 <  1         ));
 
	print("  -2147483648 <  2147483647:   " + (-2147483648 <  2147483647));
 

	
 
	print("  -2147483647 < -2147483648:   " + (-2147483647 < -2147483648));
 
	print("  -1          < -2147483648:   " + (-1          < -2147483648));
 
	print("   0          < -2147483648:   " + ( 0          < -2147483648));
 
	print("   1          < -2147483648:   " + ( 1          < -2147483648));
 
	print("   2147483647 < -2147483648:   " + ( 2147483647 < -2147483648));
 

	
 
	print("  -1          >  2147483647:   " + (-1          >  2147483647));
 
	print("  -1          >  1         :   " + (-1          >  1         ));
 
	print("  -1          >  0         :   " + (-1          >  0         ));
 
	print("  -1          > -1         :   " + (-1          > -1         ));
 
	print("  -1          > -2147483648:   " + (-1          > -2147483648));
 

	
 
	print("   1          >  2147483647:   " + ( 1          >  2147483647));
 
	print("   1          >  1         :   " + ( 1          >  1         ));
 
	print("   1          >  0         :   " + ( 1          >  0         ));
 
	print("   1          > -1         :   " + ( 1          > -1         ));
 
	print("   1          > -2147483648:   " + ( 1          > -2147483648));
 

	
 
	print("   2147483647 >  2147483646:   " + ( 2147483647 >  2147483646));
 
	print("   2147483647 >  1         :   " + ( 2147483647 >  1         ));
 
	print("   2147483647 >  0         :   " + ( 2147483647 >  0         ));
 
	print("   2147483647 > -1         :   " + ( 2147483647 > -1         ));
 
	print("   2147483647 > -2147483648:   " + ( 2147483647 > -2147483648));
 

	
 
	print("   2147483646 >  2147483647:   " + ( 2147483646 >  2147483647));
 
	print("   1          >  2147483647:   " + ( 1          >  2147483647));
 
	print("   0          >  2147483647:   " + ( 0          >  2147483647));
 
	print("  -1          >  2147483647:   " + (-1          >  2147483647));
 
	print("  -2147483648 >  2147483647:   " + (-2147483648 >  2147483647));
 

	
 
	print("   13725      > -2147483648:   " + ( 13725      > -2147483648));
 
}
 

	
 
function Regression::Start()
 
{
 
	this.TestInit();
 
	this.Std();
 
	this.Base();
 
	this.List();
 

	
 
	/* Do this first as it gains maximum loan (which is faked to quite a lot). */
 
	this.Company();
 

	
 
	this.Commands();
 
	this.Airport();
 
	this.Bridge();
 
	this.BridgeList();
 
	this.Cargo();
 
	this.CargoList();
 
	this.Engine();
 
	this.EngineList();
 
	this.Group();
 
	this.Industry();
 
	this.IndustryList();
 
	this.IndustryTypeList();
 
	this.Map();
 
	this.Marine();
 
	this.Prices();
 
	this.Rail();
 
	this.RailTypeList();
 
	this.Road();
 
	this.Sign();
 
	this.Station();
 
	this.StationList();
 
	this.Tile();
 
	this.TileList();
 
	this.Town();
 
	this.TownList();
 
	this.Tunnel();
 
	this.Vehicle();
 
	/* Order has to be after Vehicle */
 
	this.Order();
 
	print("");
 
	print("  First Subsidy Test");
 
	PrintSubsidy(0);
 

	
 
	while (AIEventController.IsEventWaiting()) {
 
		local e = AIEventController.GetNextEvent();
 
		print("  GetNextEvent:          " + (e == null ? "null" : "instance"));
 
		print("    GetEventType:        " + e.GetEventType());
 
		switch (e.GetEventType()) {
 
			case AIEvent.ET_SUBSIDY_OFFER: {
 
				local c = AIEventSubsidyOffer.Convert(e);
 
				print("      EventName:         SubsidyOffer");
 
				PrintSubsidy(c.GetSubsidyID());
 
			} break;
 

	
 
			case AIEvent.ET_VEHICLE_WAITING_IN_DEPOT: {
 
				local c = AIEventVehicleWaitingInDepot.Convert(e);
 
				print("      EventName:         VehicleWaitingInDepot");
 
				print("      VehicleID:         " + c.GetVehicleID());
 
			} break;
 

	
 
			default:
 
				print("      Unknown Event");
 
				break;
 
		}
 
	}
 
	print("  IsEventWaiting:        false");
 

	
 
	this.Math();
 

	
 
	/* Check Valuate() is actually limited, MUST BE THE LAST TEST. */
 
	print("--Valuate() with excessive CPU usage--")
 
	local list = AIList();
 
	list.AddItem(0, 0);
 
	local Infinite = function(id) { while(true); }
 
	list.Valuate(Infinite);
 
}
 

	
regression/regression/result.txt
Show inline comments
 
@@ -7668,192 +7668,339 @@ ERROR: IsEnd() is invalid as Begin() is 
 
  SetName(0):               true
 
  GetName(0):               Look, a station
 
  GetLocation(1):           29253
 
  GetLocation(1000):        -1
 
  GetStationID(33411):      6
 
  GetStationID(34411):      65535
 
  GetStationID(33411):      6
 
  HasRoadType(3, TRAM):     false
 
  HasRoadType(3, ROAD):     false
 
  HasRoadType(33411, TRAM): false
 
  HasRoadType(33411, ROAD): true
 
  HasStationType(3, BUS):   false
 
  HasStationType(3, TRAIN): false
 
  GetCoverageRadius(BUS):   3
 
  GetCoverageRadius(TRUCK): 3
 
  GetCoverageRadius(TRAIN): 4
 
  GetNearestTown():         15
 
  GetNearestTown():         65535
 
  GetNearestTown():         10
 

	
 
--CargoWaiting--
 
  GetCargoWaiting(0, 0): 0
 
  GetCargoWaitingFrom(0, 0, 0): 0
 
  GetCargoWaitingVia(0, 0, 0): 0
 
  GetCargoWaitingFromVia(0, 0, 0, 0): 0
 
  GetCargoWaitingFromVia(0, 0, 1000, 0): -1
 
  GetCargoWaitingFrom(0, 1000, 0): -1
 
  GetCargoWaitingVia(0, 1000, 0): -1
 
  GetCargoWaitingFromVia(0, 1000, 0, 0): -1
 
  GetCargoWaitingFromVia(0, 1000, 1000, 0): -1
 
  GetCargoWaiting(1000, 0): -1
 
  GetCargoWaitingFrom(1000, 0, 0): -1
 
  GetCargoWaitingVia(1000, 0, 0): -1
 
  GetCargoWaitingFromVia(1000, 0, 0, 0): -1
 
  GetCargoWaitingFromVia(1000, 0, 1000, 0): -1
 
  GetCargoWaitingFrom(1000, 1000, 0): -1
 
  GetCargoWaitingVia(1000, 1000, 0): -1
 
  GetCargoWaitingFromVia(1000, 1000, 0, 0): -1
 
  GetCargoWaitingFromVia(1000, 1000, 1000, 0): -1
 
  GetCargoWaiting(0, 1000): -1
 
  GetCargoWaitingFrom(0, 0, 1000): -1
 
  GetCargoWaitingVia(0, 0, 1000): -1
 
  GetCargoWaitingFromVia(0, 0, 0, 1000): -1
 
  GetCargoWaitingFromVia(0, 0, 1000, 1000): -1
 
  GetCargoWaitingFrom(0, 1000, 1000): -1
 
  GetCargoWaitingVia(0, 1000, 1000): -1
 
  GetCargoWaitingFromVia(0, 1000, 0, 1000): -1
 
  GetCargoWaitingFromVia(0, 1000, 1000, 1000): -1
 
  GetCargoWaiting(1000, 1000): -1
 
  GetCargoWaitingFrom(1000, 0, 1000): -1
 
  GetCargoWaitingVia(1000, 0, 1000): -1
 
  GetCargoWaitingFromVia(1000, 0, 0, 1000): -1
 
  GetCargoWaitingFromVia(1000, 0, 1000, 1000): -1
 
  GetCargoWaitingFrom(1000, 1000, 1000): -1
 
  GetCargoWaitingVia(1000, 1000, 1000): -1
 
  GetCargoWaitingFromVia(1000, 1000, 0, 1000): -1
 
  GetCargoWaitingFromVia(1000, 1000, 1000, 1000): -1
 

	
 
--CargoPlanned--
 
  GetCargoPlanned(0, 0): 0
 
  GetCargoPlannedFrom(0, 0, 0): 0
 
  GetCargoPlannedVia(0, 0, 0): 0
 
  GetCargoPlannedFromVia(0, 0, 0, 0): 0
 
  GetCargoPlannedFromVia(0, 0, 1000, 0): -1
 
  GetCargoPlannedFrom(0, 1000, 0): -1
 
  GetCargoPlannedVia(0, 1000, 0): -1
 
  GetCargoPlannedFromVia(0, 1000, 0, 0): -1
 
  GetCargoPlannedFromVia(0, 1000, 1000, 0): -1
 
  GetCargoPlanned(1000, 0): -1
 
  GetCargoPlannedFrom(1000, 0, 0): -1
 
  GetCargoPlannedVia(1000, 0, 0): -1
 
  GetCargoPlannedFromVia(1000, 0, 0, 0): -1
 
  GetCargoPlannedFromVia(1000, 0, 1000, 0): -1
 
  GetCargoPlannedFrom(1000, 1000, 0): -1
 
  GetCargoPlannedVia(1000, 1000, 0): -1
 
  GetCargoPlannedFromVia(1000, 1000, 0, 0): -1
 
  GetCargoPlannedFromVia(1000, 1000, 1000, 0): -1
 
  GetCargoPlanned(0, 1000): -1
 
  GetCargoPlannedFrom(0, 0, 1000): -1
 
  GetCargoPlannedVia(0, 0, 1000): -1
 
  GetCargoPlannedFromVia(0, 0, 0, 1000): -1
 
  GetCargoPlannedFromVia(0, 0, 1000, 1000): -1
 
  GetCargoPlannedFrom(0, 1000, 1000): -1
 
  GetCargoPlannedVia(0, 1000, 1000): -1
 
  GetCargoPlannedFromVia(0, 1000, 0, 1000): -1
 
  GetCargoPlannedFromVia(0, 1000, 1000, 1000): -1
 
  GetCargoPlanned(1000, 1000): -1
 
  GetCargoPlannedFrom(1000, 0, 1000): -1
 
  GetCargoPlannedVia(1000, 0, 1000): -1
 
  GetCargoPlannedFromVia(1000, 0, 0, 1000): -1
 
  GetCargoPlannedFromVia(1000, 0, 1000, 1000): -1
 
  GetCargoPlannedFrom(1000, 1000, 1000): -1
 
  GetCargoPlannedVia(1000, 1000, 1000): -1
 
  GetCargoPlannedFromVia(1000, 1000, 0, 1000): -1
 
  GetCargoPlannedFromVia(1000, 1000, 1000, 1000): -1
 

	
 
--StationList--
 
  GetName(): Little Frutford Valley
 
  TileList_StationCoverage:
 
    34192
 
    34191
 
    34190
 
    34189
 
    34188
 
    34187
 
    34186
 
    33936
 
    33935
 
    33934
 
    33933
 
    33932
 
    33931
 
    33930
 
    33680
 
    33679
 
    33678
 
    33677
 
    33676
 
    33675
 
    33674
 
    33424
 
    33423
 
    33422
 
    33421
 
    33420
 
    33419
 
    33418
 
    33168
 
    33167
 
    33166
 
    33165
 
    33164
 
    33163
 
    33162
 
    32912
 
    32911
 
    32910
 
    32909
 
    32908
 
    32907
 
    32906
 
    32656
 
    32655
 
    32654
 
    32653
 
    32652
 
    32651
 
    32650
 
  GetName(): Little Frutford Woods
 
  TileList_StationCoverage:
 
    34439
 
    34438
 
    34437
 
    34436
 
    34435
 
    34434
 
    34433
 
    34432
 
    34187
 
    34186
 
    34185
 
    34184
 
    34183
 
    34182
 
    34181
 
    34180
 
    34179
 
    34178
 
    34177
 
    34176
 
    33931
 
    33930
 
    33929
 
    33928
 
    33927
 
    33926
 
    33925
 
    33924
 
    33923
 
    33922
 
    33921
 
    33920
 
    33675
 
    33674
 
    33673
 
    33672
 
    33671
 
    33670
 
    33669
 
    33668
 
    33667
 
    33666
 
    33665
 
    33664
 
    33419
 
    33418
 
    33417
 
    33416
 
    33415
 
    33414
 
    33413
 
    33412
 
    33411
 
    33410
 
    33409
 
    33408
 
    33163
 
    33162
 
    33161
 
    33160
 
    33159
 
    33158
 
    33157
 
    33156
 
    33155
 
    33154
 
    33153
 
    33152
 
    32907
 
    32906
 
    32905
 
    32904
 
    32903
 
    32902
 
    32901
 
    32900
 
    32899
 
    32898
 
    32897
 
    32896
 
    32651
 
    32650
 
    32649
 
    32648
 
    32647
 
    32646
 
    32645
 
    32644
 
    32643
 
    32642
 
    32641
 
    32640
 

	
 
--Tile--
 
  HasTreeOnTile():      false
 
  IsFarmTile():         true
 
  IsRockTile():         true
 
  IsRoughTile():        true
 
  HasTreeOnTile():      true
 
  IsFarmTile():         false
 
  IsRockTile():         false
 
  IsRoughTile():        false
 
  IsSnowTile():         false
 
  IsDesertTile():       false
 
  PlantTree():          true
 
  HasTreeOnTile():      true
 
  PlantTree():          false
 
  HasTreeOnTile():      false
 
  PlantTreeRectangle(): true
 
  HasTreeOnTile():      true
 

	
 
--TileList--
 
  Count():             0
 
  Count():             9
 
  Slope():             done
 
  Count():             9
 
  ListDump:
 
    27631 => 29
 
    27631 => 65535
 
    27631 => true
 
    27631 => false
 
    27888 => 13
 
    27888 => 2
 
    27888 => false
 
    27888 => false
 
    27376 => 12
 
    27376 => 3
 
    27376 => false
 
    27376 => false
 
    27375 => 12
 
    27375 => 3
 
    27375 => false
 
    27375 => false
 
    27889 => 9
 
    27889 => 6
 
    27889 => false
 
    27889 => false
 
    27887 => 8
 
    27887 => 7
 
    27887 => false
 
    27887 => false
 
    27632 => 8
 
    27632 => 7
 
    27632 => false
 
    27632 => false
 
    27633 => 0
 
    27633 => 15
 
    27633 => false
 
    27633 => false
 
    27377 => 0
 
    27377 => 15
 
    27377 => false
 
    27377 => false
 

	
 
--TileList--
 
  Count():             0
 
  Count():             27
 
  Height():            done
 
  Count():             27
 
  ListDump:
 
    34956 => 4
 
    34700 => 4
 
    34444 => 4
 
    34955 => 3
 
    34954 => 3
 
    34953 => 3
 
    34699 => 3
 
    34698 => 3
 
    34697 => 3
 
    34693 => 3
 
    34692 => 3
 
    34443 => 3
 
    34442 => 3
 
    34441 => 3
 
    34439 => 3
 
    34438 => 3
 
    34437 => 3
 
    34436 => 3
 
    34952 => 2
 
    34951 => 2
 
    34950 => 2
 
    34949 => 2
 
    34948 => 2
 
    34696 => 2
 
    34695 => 2
 
    34694 => 2
 
    34440 => 2
 
  CornerHeight(North): done
 
  Count():             27
 
@@ -9496,113 +9643,113 @@ ERROR: IsEnd() is invalid as Begin() is 
 
  IsValidConditionalOrder(): false
 
  IsValidConditionalOrder(): true
 
  IsValidConditionalOrder(): false
 
  IsValidVehicleOrder(): false
 
  IsGotoStationOrder():  false
 
  IsGotoDepotOrder():    false
 
  IsGotoWaypointOrder(): false
 
  IsConditionalOrder():  false
 
  IsCurrentOrderPartOfOrderList(): false
 
  GetOrderFlags():       65535
 
  AppendOrder():         true
 
  InsertOrder():         true
 
  GetOrderCount():       2
 
  IsValidVehicleOrder(): true
 
  IsGotoStationOrder():  true
 
  IsGotoDepotOrder():    false
 
  IsGotoWaypointOrder(): false
 
  IsConditionalOrder():  false
 
  IsCurrentOrderPartOfOrderList(): false
 
  GetOrderFlags():       8
 
  GetOrderFlags():       8
 
  GetOrderJumpTo():      -1
 
  RemoveOrder():         true
 
  SetOrderFlags():       true
 
  GetOrderFlags():       64
 
  GetOrderDestination(): 33411
 
  CopyOrders():          false
 
  CopyOrders():          true
 
  ShareOrders():         false
 
  ShareOrders():         true
 
  UnshareOrders():       true
 
  AppendOrder():         true
 
  GetStopLocation():     -1
 
  BuildVehicle():        20
 
  BuildRailStation():    true
 
  AppendOrder():         true
 
  GetOrderCount():       1
 
  GetStopLocation():     2
 
  SetStopLocation():     true
 
  GetStopLocation():     1
 

	
 
--VehicleList_Station--
 
  Count():             1
 
  Location ListDump:
 
    20 => 23596
 
  foreach():
 
    20 => 23596
 

	
 
  First Subsidy Test
 
      --Subsidy (0) --
 
        IsValidSubsidy():      true
 
        IsAwarded():           false
 
        GetAwardedTo():        -1
 
        GetExpireDate():       714080
 
        GetSourceType():       1
 
        GetSourceIndex():      15
 
        GetDestinationType():  1
 
        GetDestinationIndex(): 7
 
        GetCargoType():        0
 
  IsEventWaiting:        false
 

	
 
--Math--
 
  -2147483648 < -2147483647:   true
 
  -2147483648 < -1         :   true
 
  -2147483648 <  0         :   true
 
  -2147483648 <  1         :   true
 
  -2147483648 <  2147483647:   true
 
  -2147483647 < -2147483648:   false
 
  -1          < -2147483648:   false
 
   0          < -2147483648:   false
 
   1          < -2147483648:   false
 
   2147483647 < -2147483648:   false
 
  -1          >  2147483647:   false
 
  -1          >  1         :   false
 
  -1          >  0         :   false
 
  -1          > -1         :   false
 
  -1          > -2147483648:   true
 
   1          >  2147483647:   false
 
   1          >  1         :   false
 
   1          >  0         :   true
 
   1          > -1         :   true
 
   1          > -2147483648:   true
 
   2147483647 >  2147483646:   true
 
   2147483647 >  1         :   true
 
   2147483647 >  0         :   true
 
   2147483647 > -1         :   true
 
   2147483647 > -2147483648:   true
 
   2147483646 >  2147483647:   false
 
   1          >  2147483647:   false
 
   0          >  2147483647:   false
 
  -1          >  2147483647:   false
 
  -2147483648 >  2147483647:   false
 
   13725      > -2147483648:   true
 
--Valuate() with excessive CPU usage--
 
Your script made an error: excessive CPU usage in valuator function
 

	
 
*FUNCTION [unknown()] regression/main.nut line [2034]
 
*FUNCTION [unknown()] regression/main.nut line [2050]
 
*FUNCTION [Valuate()] NATIVE line [-1]
 
*FUNCTION [Start()] regression/main.nut line [2035]
 
*FUNCTION [Start()] regression/main.nut line [2051]
 

	
 
[id] 0
 
[this] TABLE
 
[Infinite] CLOSURE
 
[list] INSTANCE
 
[this] INSTANCE
 
Your script made an error: excessive CPU usage in valuator function
 

	
 
*FUNCTION [Start()] regression/main.nut line [2035]
 
*FUNCTION [Start()] regression/main.nut line [2051]
 

	
 
[Infinite] CLOSURE
 
[list] INSTANCE
 
[this] INSTANCE
 
ERROR: The script died unexpectedly.
src/script/api/ai_changelog.hpp
Show inline comments
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/**
 
 * @file ai_changelog.hpp Lists all changes / additions to the API.
 
 *
 
 * Only new / renamed / deleted api functions will be listed here. A list of
 
 * bug fixes can be found in the normal changelog. Note that removed API
 
 * functions may still be available if you return an older API version
 
 * in GetAPIVersion() in info.nut.
 
 *
 
 * \b 14.0
 
 *
 
 * This version is not yet released. The following changes are not set in stone yet.
 
 *
 
 * API additions:
 
 * \li AITimeMode
 
 * \li AITown::ROAD_LAYOUT_RANDOM
 
 * \li AIVehicle::IsPrimaryVehicle
 
 * \li AITileList_StationCoverage
 
 *
 
 * API removals:
 
 * \li AIError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
 
 * \li AIInfo::CONFIG_RANDOM, no longer used.
 
 *
 
 * Other changes:
 
 * \li AIGroupList accepts an optional filter function
 
 * \li AIIndustryList accepts an optional filter function
 
 * \li AISignList accepts an optional filter function
 
 * \li AISubsidyList accepts an optional filter function
 
 * \li AITownList accepts an optional filter function
 
 * \li AIVehicleList accepts an optional filter function
 
 * \li AIInfo::AddSettings easy_value / medium_value / hard_value are replaced with default_value
 
 *
 
 * \b 13.0
 
 *
 
 * API additions:
 
 * \li AICargo::GetWeight
 
 * \li AIIndustryType::ResolveNewGRFID
 
 * \li AIObjectType::ResolveNewGRFID
 
 *
 
 * Other changes:
 
 * \li AIRoad::HasRoadType now correctly checks RoadType against RoadType
 
 *
 
 * \b 12.0
 
 *
 
 * API additions:
 
 * \li AINewGRF
 
 * \li AINewGRFList
 
 * \li AIGroup::GetNumVehicles
 
 * \li AIMarine::BT_LOCK
 
 * \li AIMarine::BT_CANAL
 
 * \li AITile::IsSeaTile
 
 * \li AITile::IsRiverTile
 
 * \li AITile::BT_CLEAR_WATER
 
 * \li AIObjectTypeList
 
 * \li AIObjectType
 
 *
 
 * \b 1.11.0
 
 *
 
 * API additions:
 
 * \li AICargo::GetName
 
 * \li AIPriorityQueue
 
 *
 
 * Other changes:
 
 * \li AIVehicle::CloneVehicle now correctly returns estimate when short on cash
 
 *
 
 * \b 1.10.0
 
 *
 
 * API additions:
 
 * \li AIGroup::SetPrimaryColour
 
 * \li AIGroup::SetSecondaryColour
 
 * \li AIGroup::GetPrimaryColour
 
 * \li AIGroup::GetSecondaryColour
 
 * \li AIVehicle::BuildVehicleWithRefit
 
 * \li AIVehicle::GetBuildWithRefitCapacity
 
 * \li AIRoad::GetName
 
 * \li AIRoad::RoadVehCanRunOnRoad
 
 * \li AIRoad::RoadVehHasPowerOnRoad
 
 * \li AIRoad::ConvertRoadType
 
 * \li AIRoad::GetMaxSpeed
 
 * \li AIEngine::CanRunOnRoad
 
 * \li AIEngine::HasPowerOnRoad
 
 * \li AIRoadTypeList::RoadTypeList
 
 * \li AIEventVehicleAutoReplaced
 
 *
 
 * Other changes:
 
 * \li AITile::DemolishTile works without a selected company
 
 *
 
 * \b 1.9.0
 
 *
 
 * API additions:
 
 * \li AIAirport::GetMonthlyMaintenanceCost
 
 * \li AIGroup::SetParent
 
 * \li AIGroup::GetParent
 
 * \li AICompany::SetPrimaryLiveryColour
 
 * \li AICompany::SetSecondaryLiveryColour
 
 * \li AICompany::GetPrimaryLiveryColour
 
 * \li AICompany::GetSecondaryLiveryColour
 
 *
 
 * Other changes:
 
 * \li AIBridge::GetName takes one extra parameter to refer the vehicle type
 
 * \li AIGroup::CreateGroup gains parent_group_id parameter
 
 *
 
 * \b 1.8.0
 
 *
 
 * No changes
 
 *
 
 * API additions:
 
 * \li AIRoad::ERR_ROADTYPE_DISALLOWS_CROSSING
 
 *
 
 * \b 1.7.0 - 1.7.2
 
 *
 
 * No changes
 
 *
 
 * \b 1.6.1 - 1.6.0
src/script/api/game_changelog.hpp
Show inline comments
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/**
 
 * @file game_changelog.hpp Lists all changes / additions to the API.
 
 *
 
 * Only new / renamed / deleted api functions will be listed here. A list of
 
 * bug fixes can be found in the normal changelog. Note that removed API
 
 * functions may still be available if you return an older API version
 
 * in GetAPIVersion() in info.nut.
 
 *
 
 * \b 14.0
 
 *
 
 * This version is not yet released. The following changes are not set in stone yet.
 
 *
 
 * API additions:
 
 * \li GSIndustry::GetConstructionDate
 
 * \li GSAsyncMode
 
 * \li GSCompanyMode::IsValid
 
 * \li GSCompanyMode::IsDeity
 
 * \li GSTimeMode
 
 * \li GSTown::ROAD_LAYOUT_RANDOM
 
 * \li GSVehicle::IsPrimaryVehicle
 
 * \li GSOrder::SetOrderJumpTo
 
 * \li GSOrder::SetOrderCondition
 
 * \li GSOrder::SetOrderCompareFunction
 
 * \li GSOrder::SetOrderCompareValue
 
 * \li GSOrder::SetStopLocation
 
 * \li GSOrder::SetOrderRefit
 
 * \li GSOrder::AppendOrder
 
 * \li GSOrder::AppendConditionalOrder
 
 * \li GSOrder::InsertOrder
 
 * \li GSOrder::InsertConditionalOrder
 
 * \li GSOrder::RemoveOrder
 
 * \li GSOrder::SetOrderFlags
 
 * \li GSOrder::MoveOrder
 
 * \li GSOrder::SkipToOrder
 
 * \li GSOrder::CopyOrders
 
 * \li GSOrder::ShareOrders
 
 * \li GSOrder::UnshareOrders
 
 * \li GSCompany::IsMine
 
 * \li GSCompany::SetPresidentGender
 
 * \li GSCompany::SetAutoRenewStatus
 
 * \li GSCompany::SetAutoRenewMonths
 
 * \li GSCompany::SetAutoRenewMoney
 
 * \li GSCompany::SetMaxLoanAmountForCompany
 
 * \li GSCompany::ResetMaxLoanAmountForCompany
 
 * \li GSGameSettings::IsDisabledVehicleType
 
 * \li GSGroup::GroupID
 
 * \li GSGroup::IsValidGroup
 
 * \li GSGroup::CreateGroup
 
 * \li GSGroup::DeleteGroup
 
 * \li GSGroup::GetVehicleType
 
 * \li GSGroup::SetName
 
 * \li GSGroup::GetName
 
 * \li GSGroup::SetParent
 
 * \li GSGroup::GetParent
 
 * \li GSGroup::EnableAutoReplaceProtection
 
 * \li GSGroup::GetAutoReplaceProtection
 
 * \li GSGroup::GetNumEngines
 
 * \li GSGroup::GetNumVehicles
 
 * \li GSGroup::MoveVehicle
 
 * \li GSGroup::EnableWagonRemoval
 
 * \li GSGroup::HasWagonRemoval
 
 * \li GSGroup::SetAutoReplace
 
 * \li GSGroup::GetEngineReplacement
 
 * \li GSGroup::StopAutoReplace
 
 * \li GSGroup::GetProfitThisYear
 
 * \li GSGroup::GetProfitLastYear
 
 * \li GSGroup::GetCurrentUsage
 
 * \li GSGroup::SetPrimaryColour
 
 * \li GSGroup::SetSecondaryColour
 
 * \li GSGroup::GetPrimaryColour
 
 * \li GSGroup::GetSecondaryColour
 
 * \li GSGroupList
 
 * \li GSVehicleList_Group
 
 * \li GSVehicleList_DefaultGroup
 
 * \li GSGoal::IsValidGoalDestination
 
 * \li GSGoal::SetDestination
 
 * \li GSIndustry::GetProductionLevel
 
 * \li GSIndustry::SetProductionLevel
 
 * \li GSStoryPage::IsValidStoryPageElementType
 
 * \li GSStoryPage::IsValidStoryPageButtonColour
 
 * \li GSStoryPage::IsValidStoryPageButtonFlags
 
 * \li GSStoryPage::IsValidStoryPageButtonCursor
 
 * \li GSTileList_StationCoverage
 
 *
 
 * API removals:
 
 * \li GSError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
 
 * \li AIInfo::CONFIG_RANDOM, no longer used.
 
 * \li GSInfo::CONFIG_RANDOM, no longer used.
 
 *
 
 * Other changes:
 
 * \li GSGroupList accepts an optional filter function
 
 * \li GSIndustryList accepts an optional filter function
 
 * \li GSSignList accepts an optional filter function
 
 * \li GSSubsidyList accepts an optional filter function
 
 * \li GSTownList accepts an optional filter function
 
 * \li GSVehicleList accepts an optional filter function
 
 * \li GSInfo::AddSettings easy_value / medium_value / hard_value are replaced with default_value
 
 *
 
 * \b 13.0
 
 *
 
 * API additions:
 
 * \li GSCargo::GetWeight
 
 * \li GSIndustryType::ResolveNewGRFID
 
 * \li GSObjectType::ResolveNewGRFID
 
 * \li GSLeagueTable
 
 *
 
 * Other changes:
 
 * \li GSRoad::HasRoadType now correctly checks RoadType against RoadType
 
 *
 
 * \b 12.0
 
 *
 
 * API additions:
 
 * \li GSNewGRF
 
 * \li GSNewGRFList
 
 * \li GSMarine::BT_LOCK
 
 * \li GSMarine::BT_CANAL
 
 * \li GSTile::IsSeaTile
 
 * \li GSTile::IsRiverTile
 
 * \li GSTile::BT_CLEAR_WATER
 
 * \li GSObjectTypeList
 
 * \li GSObjectType
 
 *
 
 * \b 1.11.0
 
 *
 
 * API additions:
 
 * \li GSCargo::GetName
 
 * \li GSEventStoryPageButtonClick
 
 * \li GSEventStoryPageTileSelect
 
 * \li GSEventStoryPageVehicleSelect
 
 * \li GSIndustry::GetCargoLastAcceptedDate
 
 * \li GSIndustry::GetControlFlags
 
 * \li GSIndustry::GetExclusiveConsumer
 
 * \li GSIndustry::GetExclusiveSupplier
 
 * \li GSIndustry::GetLastProductionYear
 
 * \li GSIndustry::SetControlFlags
 
 * \li GSIndustry::SetExclusiveConsumer
 
 * \li GSIndustry::SetExclusiveSupplier
 
 * \li GSIndustry::SetText
 
 * \li GSStoryPage::MakePushButtonReference
 
 * \li GSStoryPage::MakeTileButtonReference
 
 * \li GSStoryPage::MakeVehicleButtonReference
 
 * \li GSPriorityQueue
 
 *
 
 * Other changes:
 
 * \li GSCompany::ChangeBankBalance takes one extra parameter to refer to a location to show text effect on
 
 * \li GSGoal::Question and GSGoal::QuestionClient no longer require to have any buttons except for the window type GSGoal.QT_QUESTION
 
 *
 
 * \b 1.10.0
 
 *
 
 * API additions:
 
 * \li GSVehicle::BuildVehicleWithRefit
 
 * \li GSVehicle::GetBuildWithRefitCapacity
 
 * \li GSRoad::GetName
 
 * \li GSRoad::RoadVehCanRunOnRoad
 
 * \li GSRoad::RoadVehHasPowerOnRoad
 
 * \li GSRoad::ConvertRoadType
 
 * \li GSRoad::GetMaxSpeed
 
 * \li GSEngine::EnableForCompany
 
 * \li GSEngine::DisableForCompany
 
 *
 
 * \b 1.9.0
 
 *
 
 * API additions:
 
 * \li GSAirport::GetMonthlyMaintenanceCost
 
 * \li GSClient
 
 * \li GSClientList
 
 * \li GSClientList_Company
 
 * \li GSViewport::ScrollEveryoneTo
 
 * \li GSViewport::ScrollCompanyClientsTo
 
 * \li GSViewport::ScrollClientTo
 
 * \li GSGoal::QuestionClient
 
 *
 
 * Other changes:
 
 * \li GSBridge::GetName takes one extra parameter to refer the vehicle type
 
 *
 
 * \b 1.8.0
 
 *
 
 * No changes
 
 *
 
 * API additions:
 
 * \li GSRoad::ERR_ROADTYPE_DISALLOWS_CROSSING
 
 *
 
 * \b 1.7.0 - 1.7.2
 
 *
src/script/api/script_tilelist.cpp
Show inline comments
 
@@ -54,96 +54,106 @@ void ScriptTileList::RemoveTile(TileInde
 
 * @param bta BitmapTileArea to fill
 
 */
 
static void FillIndustryCatchment(const Industry *i, SQInteger radius, BitmapTileArea &bta)
 
{
 
	for (TileIndex cur_tile : i->location) {
 
		if (!::IsTileType(cur_tile, MP_INDUSTRY) || ::GetIndustryIndex(cur_tile) != i->index) continue;
 

	
 
		int tx = TileX(cur_tile);
 
		int ty = TileY(cur_tile);
 
		for (int y = -radius; y <= radius; y++) {
 
			if (ty + y < 0 || ty + y > (int)Map::MaxY()) continue;
 
			for (int x = -radius; x <= radius; x++) {
 
				if (tx + x < 0 || tx + x > (int)Map::MaxX()) continue;
 
				TileIndex tile = TileXY(tx + x, ty + y);
 
				if (!IsValidTile(tile)) continue;
 
				if (::IsTileType(tile, MP_INDUSTRY) && ::GetIndustryIndex(tile) == i->index) continue;
 
				bta.SetTile(tile);
 
			}
 
		}
 
	}
 
}
 

	
 
ScriptTileList_IndustryAccepting::ScriptTileList_IndustryAccepting(IndustryID industry_id, SQInteger radius)
 
{
 
	if (!ScriptIndustry::IsValidIndustry(industry_id) || radius <= 0) return;
 

	
 
	const Industry *i = ::Industry::Get(industry_id);
 

	
 
	/* Check if this industry is only served by its neutral station */
 
	if (i->neutral_station != nullptr && !_settings_game.station.serve_neutral_industries) return;
 

	
 
	/* Check if this industry accepts anything */
 
	if (!i->IsCargoAccepted()) return;
 

	
 
	if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
 

	
 
	BitmapTileArea bta(TileArea(i->location).Expand(radius));
 
	FillIndustryCatchment(i, radius, bta);
 

	
 
	BitmapTileIterator it(bta);
 
	for (TileIndex cur_tile = it; cur_tile != INVALID_TILE; cur_tile = ++it) {
 
		/* Only add the tile if it accepts the cargo (sometimes just 1 tile of an
 
		 *  industry triggers the acceptance). */
 
		CargoArray acceptance = ::GetAcceptanceAroundTiles(cur_tile, 1, 1, radius);
 
		if (std::none_of(std::begin(i->accepted), std::end(i->accepted), [&acceptance](const auto &a) { return ::IsValidCargoID(a.cargo) && acceptance[a.cargo] != 0; })) continue;
 

	
 
		this->AddTile(cur_tile);
 
	}
 
}
 

	
 
ScriptTileList_IndustryProducing::ScriptTileList_IndustryProducing(IndustryID industry_id, SQInteger radius)
 
{
 
	if (!ScriptIndustry::IsValidIndustry(industry_id) || radius <= 0) return;
 

	
 
	const Industry *i = ::Industry::Get(industry_id);
 

	
 
	/* Check if this industry is only served by its neutral station */
 
	if (i->neutral_station != nullptr && !_settings_game.station.serve_neutral_industries) return;
 

	
 
	/* Check if this industry produces anything */
 
	if (!i->IsCargoProduced()) return;
 

	
 
	if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
 

	
 
	BitmapTileArea bta(TileArea(i->location).Expand(radius));
 
	FillIndustryCatchment(i, radius, bta);
 

	
 
	BitmapTileIterator it(bta);
 
	for (TileIndex cur_tile = it; cur_tile != INVALID_TILE; cur_tile = ++it) {
 
		this->AddTile(cur_tile);
 
	}
 
}
 

	
 
ScriptTileList_StationType::ScriptTileList_StationType(StationID station_id, ScriptStation::StationType station_type)
 
{
 
	if (!ScriptStation::IsValidStation(station_id)) return;
 

	
 
	const StationRect *rect = &::Station::Get(station_id)->rect;
 

	
 
	uint station_type_value = 0;
 
	/* Convert ScriptStation::StationType to ::StationType, but do it in a
 
	 *  bitmask, so we can scan for multiple entries at the same time. */
 
	if ((station_type & ScriptStation::STATION_TRAIN) != 0)      station_type_value |= (1 << ::STATION_RAIL);
 
	if ((station_type & ScriptStation::STATION_TRUCK_STOP) != 0) station_type_value |= (1 << ::STATION_TRUCK);
 
	if ((station_type & ScriptStation::STATION_BUS_STOP) != 0)   station_type_value |= (1 << ::STATION_BUS);
 
	if ((station_type & ScriptStation::STATION_AIRPORT) != 0)    station_type_value |= (1 << ::STATION_AIRPORT) | (1 << ::STATION_OILRIG);
 
	if ((station_type & ScriptStation::STATION_DOCK) != 0)       station_type_value |= (1 << ::STATION_DOCK)    | (1 << ::STATION_OILRIG);
 

	
 
	TileArea ta(::TileXY(rect->left, rect->top), rect->Width(), rect->Height());
 
	for (TileIndex cur_tile : ta) {
 
		if (!::IsTileType(cur_tile, MP_STATION)) continue;
 
		if (::GetStationIndex(cur_tile) != station_id) continue;
 
		if (!HasBit(station_type_value, ::GetStationType(cur_tile))) continue;
 
		this->AddTile(cur_tile);
 
	}
 
}
 

	
 
ScriptTileList_StationCoverage::ScriptTileList_StationCoverage(StationID station_id)
 
{
 
	if (!ScriptStation::IsValidStation(station_id)) return;
 

	
 
	BitmapTileIterator it(::Station::Get(station_id)->catchment_tiles);
 
	for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
 
		this->AddTile(tile);
 
	}
 
}
src/script/api/script_tilelist.hpp
Show inline comments
 
@@ -11,97 +11,110 @@
 
#define SCRIPT_TILELIST_HPP
 

	
 
#include "script_station.hpp"
 
#include "script_list.hpp"
 

	
 
/**
 
 * Creates an empty list, in which you can add tiles.
 
 * @api ai game
 
 * @ingroup ScriptList
 
 */
 
class ScriptTileList : public ScriptList {
 
public:
 
	/**
 
	 * Adds the rectangle between tile_from and tile_to to the to-be-evaluated tiles.
 
	 * @param tile_from One corner of the tiles to add.
 
	 * @param tile_to The other corner of the tiles to add.
 
	 * @pre ScriptMap::IsValidTile(tile_from).
 
	 * @pre ScriptMap::IsValidTile(tile_to).
 
	 */
 
	void AddRectangle(TileIndex tile_from, TileIndex tile_to);
 

	
 
	/**
 
	 * Add a tile to the to-be-evaluated tiles.
 
	 * @param tile The tile to add.
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 */
 
	void AddTile(TileIndex tile);
 

	
 
	/**
 
	 * Remove the tiles inside the rectangle between tile_from and tile_to from the list.
 
	 * @param tile_from One corner of the tiles to remove.
 
	 * @param tile_to The other corner of the files to remove.
 
	 * @pre ScriptMap::IsValidTile(tile_from).
 
	 * @pre ScriptMap::IsValidTile(tile_to).
 
	 */
 
	void RemoveRectangle(TileIndex tile_from, TileIndex tile_to);
 

	
 
	/**
 
	 * Remove a tile from the list.
 
	 * @param tile The tile to remove.
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 */
 
	void RemoveTile(TileIndex tile);
 
};
 

	
 
/**
 
 * Creates a list of tiles that will accept cargo for the given industry.
 
 * @note If a simular industry is close, it might happen that this industry receives the cargo.
 
 * @api ai game
 
 * @ingroup ScriptList
 
 */
 
class ScriptTileList_IndustryAccepting : public ScriptTileList {
 
public:
 
	/**
 
	 * @param industry_id The industry to create the ScriptTileList around.
 
	 * @param radius The coverage radius of the station type you will be using.
 
	 * @pre ScriptIndustry::IsValidIndustry(industry_id).
 
	 * @pre radius > 0.
 
	 * @note A station part built on any of the returned tiles will give you coverage.
 
	 */
 
	ScriptTileList_IndustryAccepting(IndustryID industry_id, SQInteger radius);
 
};
 

	
 
/**
 
 * Creates a list of tiles which the industry checks to see if a station is
 
 *  there to receive cargo produced by this industry.
 
 * @api ai game
 
 * @ingroup ScriptList
 
 */
 
class ScriptTileList_IndustryProducing : public ScriptTileList {
 
public:
 
	/**
 
	 * @param industry_id The industry to create the ScriptTileList around.
 
	 * @param radius The coverage radius of the station type you will be using.
 
	 * @pre ScriptIndustry::IsValidIndustry(industry_id).
 
	 * @pre radius > 0.
 
	 * @note A station part built on any of the returned tiles will give you acceptance.
 
	 */
 
	ScriptTileList_IndustryProducing(IndustryID industry_id, SQInteger radius);
 
};
 

	
 
/**
 
 * Creates a list of tiles which have the requested StationType of the
 
 *  StationID.
 
 * @api ai game
 
 * @ingroup ScriptList
 
 */
 
class ScriptTileList_StationType : public ScriptTileList {
 
public:
 
	/**
 
	 * @param station_id The station to create the ScriptTileList for.
 
	 * @param station_type The StationType to create the ScriptList for.
 
	 */
 
	ScriptTileList_StationType(StationID station_id, ScriptStation::StationType station_type);
 
};
 

	
 
/**
 
 * Creates a list of tiles in the catchment area of the StationID.
 
 * @api ai game
 
 * @ingroup ScriptList
 
 */
 
class ScriptTileList_StationCoverage : public ScriptTileList {
 
public:
 
	/**
 
	 * @param station_id The station to create the ScriptTileList for.
 
	 */
 
	ScriptTileList_StationCoverage(StationID station_id);
 
};
 

	
 
#endif /* SCRIPT_TILELIST_HPP */
0 comments (0 inline, 0 general)