Codechange: Pass GRFConfig by reference where feasible. (#13388)
[openttd-github.git] / bin / ai / compat_0.7.nut
blob0b2fa1f243bd57c76f16900dcfe2b74dc7bac919
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 AILog.Info("0.7 API compatibility in effect:");
9 AILog.Info(" - AITown::GetLastMonthProduction's behaviour has slightly changed.");
10 AILog.Info(" - AISubsidy::GetDestination returns STATION_INVALID for awarded subsidies.");
11 AILog.Info(" - AISubsidy::GetSource returns STATION_INVALID for awarded subsidies.");
13 AISign.GetMaxSignID <- function()
15 local list = AISignList();
16 local max_id = 0;
17 foreach (id, d in list) {
18 if (id > max_id) max_id = id;
20 return max_id;
23 AITile.GetHeight <- function(tile)
25 if (!AIMap.IsValidTile(tile)) return -1;
27 return AITile.GetCornerHeight(tile, AITile.CORNER_N);
30 AIOrder.ChangeOrder <- function(vehicle_id, order_position, order_flags)
32 return AIOrder.SetOrderFlags(vehicle_id, order_position, order_flags);
35 AIWaypoint.WAYPOINT_INVALID <- 0xFFFF;
37 AISubsidy.SourceIsTown <- function(subsidy_id)
39 if (!AISubsidy.IsValidSubsidy(subsidy_id) || AISubsidy.IsAwarded(subsidy_id)) return false;
41 return AISubsidy.GetSourceType(subsidy_id) == AISubsidy.SPT_TOWN;
44 AISubsidy.GetSource <- function(subsidy_id)
46 if (!AISubsidy.IsValidSubsidy(subsidy_id)) return AIBaseStation.STATION_INVALID;
48 if (AISubsidy.IsAwarded(subsidy_id)) {
49 return AIBaseStation.STATION_INVALID;
52 return AISubsidy.GetSourceIndex(subsidy_id);
55 AISubsidy.DestinationIsTown <- function(subsidy_id)
57 if (!AISubsidy.IsValidSubsidy(subsidy_id) || AISubsidy.IsAwarded(subsidy_id)) return false;
59 return AISubsidy.GetDestinationType(subsidy_id) == AISubsidy.SPT_TOWN;
62 AISubsidy.GetDestination <- function(subsidy_id)
64 if (!AISubsidy.IsValidSubsidy(subsidy_id)) return AIBaseStation.STATION_INVALID;
66 if (AISubsidy.IsAwarded(subsidy_id)) {
67 return AIBaseStation.STATION_INVALID;
70 return AISubsidy.GetDestinationIndex(subsidy_id);
73 AITown.GetMaxProduction <- function(town_id, cargo_id)
75 return AITown.GetLastMonthProduction(town_id, cargo_id);
78 AIRail.RemoveRailWaypoint <- function(tile)
80 return AIRail.RemoveRailWaypointTileRect(tile, tile, true);
83 AIRail.RemoveRailStationTileRect <- function(tile, tile2)
85 return AIRail.RemoveRailStationTileRectangle(tile, tile2, false);
88 AIVehicle.SkipToVehicleOrder <- function(vehicle_id, order_position)
90 return AIOrder.SkipToOrder(vehicle_id, order_position);
93 AIEngine.IsValidEngine <- function(engine_id)
95 return AIEngine.IsBuildable(engine_id);
98 AIEngine._GetName <- AIEngine.GetName;
99 AIEngine.GetName <- function(engine_id)
101 if (!AIEngine.IsBuildable(engine_id)) return null;
102 return AIEngine._GetName(engine_id);
105 AIEngine._GetCargoType <- AIEngine.GetCargoType;
106 AIEngine.GetCargoType <- function(engine_id)
108 if (!AIEngine.IsBuildable(engine_id)) return 255;
109 return AIEngine._GetCargoType(engine_id);
112 AIEngine._CanRefitCargo <- AIEngine.CanRefitCargo;
113 AIEngine.CanRefitCargo <- function(engine_id, cargo_id)
115 if (!AIEngine.IsBuildable(engine_id)) return false;
116 return AIEngine._CanRefitCargo(engine_id, cargo_id);
119 AIEngine._CanPullCargo <- AIEngine.CanPullCargo;
120 AIEngine.CanPullCargo <- function(engine_id, cargo_id)
122 if (!AIEngine.IsBuildable(engine_id)) return false;
123 return AIEngine._CanPullCargo(engine_id, cargo_id);
126 AIEngine._GetCapacity <- AIEngine.GetCapacity;
127 AIEngine.GetCapacity <- function(engine_id)
129 if (!AIEngine.IsBuildable(engine_id)) return -1;
130 return AIEngine._GetCapacity(engine_id);
133 AIEngine._GetReliability <- AIEngine.GetReliability;
134 AIEngine.GetReliability <- function(engine_id)
136 if (!AIEngine.IsBuildable(engine_id)) return -1;
137 return AIEngine._GetReliability(engine_id);
140 AIEngine._GetMaxSpeed <- AIEngine.GetMaxSpeed;
141 AIEngine.GetMaxSpeed <- function(engine_id)
143 if (!AIEngine.IsBuildable(engine_id)) return -1;
144 return AIEngine._GetMaxSpeed(engine_id);
147 AIEngine._GetPrice <- AIEngine.GetPrice;
148 AIEngine.GetPrice <- function(engine_id)
150 if (!AIEngine.IsBuildable(engine_id)) return -1;
151 return AIEngine._GetPrice(engine_id);
154 AIEngine._GetMaxAge <- AIEngine.GetMaxAge;
155 AIEngine.GetMaxAge <- function(engine_id)
157 if (!AIEngine.IsBuildable(engine_id)) return -1;
158 return AIEngine._GetMaxAge(engine_id);
161 AIEngine._GetRunningCost <- AIEngine.GetRunningCost;
162 AIEngine.GetRunningCost <- function(engine_id)
164 if (!AIEngine.IsBuildable(engine_id)) return -1;
165 return AIEngine._GetRunningCost(engine_id);
168 AIEngine._GetPower <- AIEngine.GetPower;
169 AIEngine.GetPower <- function(engine_id)
171 if (!AIEngine.IsBuildable(engine_id)) return -1;
172 return AIEngine._GetPower(engine_id);
175 AIEngine._GetWeight <- AIEngine.GetWeight;
176 AIEngine.GetWeight <- function(engine_id)
178 if (!AIEngine.IsBuildable(engine_id)) return -1;
179 return AIEngine._GetWeight(engine_id);
182 AIEngine._GetMaxTractiveEffort <- AIEngine.GetMaxTractiveEffort;
183 AIEngine.GetMaxTractiveEffort <- function(engine_id)
185 if (!AIEngine.IsBuildable(engine_id)) return -1;
186 return AIEngine._GetMaxTractiveEffort(engine_id);
189 AIEngine._GetDesignDate <- AIEngine.GetDesignDate;
190 AIEngine.GetDesignDate <- function(engine_id)
192 if (!AIEngine.IsBuildable(engine_id)) return -1;
193 return AIEngine._GetDesignDate(engine_id);
196 AIEngine._GetVehicleType <- AIEngine.GetVehicleType;
197 AIEngine.GetVehicleType <- function(engine_id)
199 if (!AIEngine.IsBuildable(engine_id)) return AIVehicle.VT_INVALID;
200 return AIEngine._GetVehicleType(engine_id);
203 AIEngine._IsWagon <- AIEngine.IsWagon;
204 AIEngine.IsWagon <- function(engine_id)
206 if (!AIEngine.IsBuildable(engine_id)) return false;
207 return AIEngine._IsWagon(engine_id);
210 AIEngine._CanRunOnRail <- AIEngine.CanRunOnRail;
211 AIEngine.CanRunOnRail <- function(engine_id, track_rail_type)
213 if (!AIEngine.IsBuildable(engine_id)) return false;
214 return AIEngine._CanRunOnRail(engine_id, track_rail_type);
217 AIEngine._HasPowerOnRail <- AIEngine.HasPowerOnRail;
218 AIEngine.HasPowerOnRail <- function(engine_id, track_rail_type)
220 if (!AIEngine.IsBuildable(engine_id)) return false;
221 return AIEngine._HasPowerOnRail(engine_id, track_rail_type);
224 AIEngine._GetRoadType <- AIEngine.GetRoadType;
225 AIEngine.GetRoadType <- function(engine_id)
227 if (!AIEngine.IsBuildable(engine_id)) return AIRoad.ROADTYPE_INVALID;
228 return AIEngine._GetRoadType(engine_id);
231 AIEngine._GetRailType <- AIEngine.GetRailType;
232 AIEngine.GetRailType <- function(engine_id)
234 if (!AIEngine.IsBuildable(engine_id)) return AIRail.RAILTYPE_INVALID;
235 return AIEngine._GetRailType(engine_id);
238 AIEngine._IsArticulated <- AIEngine.IsArticulated;
239 AIEngine.IsArticulated <- function(engine_id)
241 if (!AIEngine.IsBuildable(engine_id)) return false;
242 return AIEngine._IsArticulated(engine_id);
245 AIEngine._GetPlaneType <- AIEngine.GetPlaneType;
246 AIEngine.GetPlaneType <- function(engine_id)
248 if (!AIEngine.IsBuildable(engine_id)) return -1;
249 return AIEngine._GetPlaneType(engine_id);
252 _AIWaypointList <- AIWaypointList;
253 class AIWaypointList extends _AIWaypointList {
254 constructor()
256 ::_AIWaypointList.constructor(AIWaypoint.WAYPOINT_RAIL);
260 AIRoad._BuildRoadStation <- AIRoad.BuildRoadStation;
261 AIRoad.BuildRoadStation <- function(tile, front, road_veh_type, station_id)
263 if (AIRoad.IsRoadStationTile(tile) && AICompany.IsMine(AITile.GetOwner(tile))) return false;
265 return AIRoad._BuildRoadStation(tile, front, road_veh_type, station_id);
268 AIRoad._BuildDriveThroughRoadStation <- AIRoad.BuildDriveThroughRoadStation;
269 AIRoad.BuildDriveThroughRoadStation <- function(tile, front, road_veh_type, station_id)
271 if (AIRoad.IsRoadStationTile(tile) && AICompany.IsMine(AITile.GetOwner(tile))) return false;
273 return AIRoad._BuildDriveThroughRoadStation(tile, front, road_veh_type, station_id);
276 AIBridgeList.HasNext <-
277 AIBridgeList_Length.HasNext <-
278 AICargoList.HasNext <-
279 AICargoList_IndustryAccepting.HasNext <-
280 AICargoList_IndustryProducing.HasNext <-
281 AIDepotList.HasNext <-
282 AIEngineList.HasNext <-
283 AIGroupList.HasNext <-
284 AIIndustryList.HasNext <-
285 AIIndustryList_CargoAccepting.HasNext <-
286 AIIndustryList_CargoProducing.HasNext <-
287 AIIndustryTypeList.HasNext <-
288 AIList.HasNext <-
289 AIRailTypeList.HasNext <-
290 AISignList.HasNext <-
291 AIStationList.HasNext <-
292 AIStationList_Vehicle.HasNext <-
293 AISubsidyList.HasNext <-
294 AITileList.HasNext <-
295 AITileList_IndustryAccepting.HasNext <-
296 AITileList_IndustryProducing.HasNext <-
297 AITileList_StationType.HasNext <-
298 AITownList.HasNext <-
299 AIVehicleList.HasNext <-
300 AIVehicleList_DefaultGroup.HasNext <-
301 AIVehicleList_Group.HasNext <-
302 AIVehicleList_SharedOrders.HasNext <-
303 AIVehicleList_Station.HasNext <-
304 AIWaypointList.HasNext <-
305 AIWaypointList_Vehicle.HasNext <-
306 function()
308 return !this.IsEnd();
311 AIIndustry._IsCargoAccepted <- AIIndustry.IsCargoAccepted;
312 AIIndustry.IsCargoAccepted <- function(industry_id, cargo_id)
314 return AIIndustry._IsCargoAccepted(industry_id, cargo_id) != AIIndustry.CAS_NOT_ACCEPTED;
317 AIAbstractList <- AIList;
319 AIList.ChangeItem <- AIList.SetValue;
321 AIRail.ERR_NONUNIFORM_STATIONS_DISABLED <- 0xFFFF;
323 AICompany.GetCompanyValue <- function(company)
325 return AICompany.GetQuarterlyCompanyValue(company, AICompany.CURRENT_QUARTER);
328 AITown.GetLastMonthTransported <- AITown.GetLastMonthSupplied;
330 AIEvent.AI_ET_INVALID <- AIEvent.ET_INVALID;
331 AIEvent.AI_ET_TEST <- AIEvent.ET_TEST;
332 AIEvent.AI_ET_SUBSIDY_OFFER <- AIEvent.ET_SUBSIDY_OFFER;
333 AIEvent.AI_ET_SUBSIDY_OFFER_EXPIRED <- AIEvent.ET_SUBSIDY_OFFER_EXPIRED;
334 AIEvent.AI_ET_SUBSIDY_AWARDED <- AIEvent.ET_SUBSIDY_AWARDED;
335 AIEvent.AI_ET_SUBSIDY_EXPIRED <- AIEvent.ET_SUBSIDY_EXPIRED;
336 AIEvent.AI_ET_ENGINE_PREVIEW <- AIEvent.ET_ENGINE_PREVIEW;
337 AIEvent.AI_ET_COMPANY_NEW <- AIEvent.ET_COMPANY_NEW;
338 AIEvent.AI_ET_COMPANY_IN_TROUBLE <- AIEvent.ET_COMPANY_IN_TROUBLE;
339 AIEvent.AI_ET_COMPANY_MERGER <- AIEvent.ET_COMPANY_MERGER;
340 AIEvent.AI_ET_COMPANY_BANKRUPT <- AIEvent.ET_COMPANY_BANKRUPT;
341 AIEvent.AI_ET_VEHICLE_CRASHED <- AIEvent.ET_VEHICLE_CRASHED;
342 AIEvent.AI_ET_VEHICLE_LOST <- AIEvent.ET_VEHICLE_LOST;
343 AIEvent.AI_ET_VEHICLE_WAITING_IN_DEPOT <- AIEvent.ET_VEHICLE_WAITING_IN_DEPOT;
344 AIEvent.AI_ET_VEHICLE_UNPROFITABLE <- AIEvent.ET_VEHICLE_UNPROFITABLE;
345 AIEvent.AI_ET_INDUSTRY_OPEN <- AIEvent.ET_INDUSTRY_OPEN;
346 AIEvent.AI_ET_INDUSTRY_CLOSE <- AIEvent.ET_INDUSTRY_CLOSE;
347 AIEvent.AI_ET_ENGINE_AVAILABLE <- AIEvent.ET_ENGINE_AVAILABLE;
348 AIEvent.AI_ET_STATION_FIRST_VEHICLE <- AIEvent.ET_STATION_FIRST_VEHICLE;
349 AIEvent.AI_ET_DISASTER_ZEPPELINER_CRASHED <- AIEvent.ET_DISASTER_ZEPPELINER_CRASHED;
350 AIEvent.AI_ET_DISASTER_ZEPPELINER_CLEARED <- AIEvent.ET_DISASTER_ZEPPELINER_CLEARED;
351 AIOrder.AIOF_NONE <- AIOrder.OF_NONE
352 AIOrder.AIOF_NON_STOP_INTERMEDIATE <- AIOrder.OF_NON_STOP_INTERMEDIATE
353 AIOrder.AIOF_NON_STOP_DESTINATION <- AIOrder.OF_NON_STOP_DESTINATION
354 AIOrder.AIOF_UNLOAD <- AIOrder.OF_UNLOAD
355 AIOrder.AIOF_TRANSFER <- AIOrder.OF_TRANSFER
356 AIOrder.AIOF_NO_UNLOAD <- AIOrder.OF_NO_UNLOAD
357 AIOrder.AIOF_FULL_LOAD <- AIOrder.OF_FULL_LOAD
358 AIOrder.AIOF_FULL_LOAD_ANY <- AIOrder.OF_FULL_LOAD_ANY
359 AIOrder.AIOF_NO_LOAD <- AIOrder.OF_NO_LOAD
360 AIOrder.AIOF_SERVICE_IF_NEEDED <- AIOrder.OF_SERVICE_IF_NEEDED
361 AIOrder.AIOF_STOP_IN_DEPOT <- AIOrder.OF_STOP_IN_DEPOT
362 AIOrder.AIOF_GOTO_NEAREST_DEPOT <- AIOrder.OF_GOTO_NEAREST_DEPOT
363 AIOrder.AIOF_NON_STOP_FLAGS <- AIOrder.OF_NON_STOP_FLAGS
364 AIOrder.AIOF_UNLOAD_FLAGS <- AIOrder.OF_UNLOAD_FLAGS
365 AIOrder.AIOF_LOAD_FLAGS <- AIOrder.OF_LOAD_FLAGS
366 AIOrder.AIOF_DEPOT_FLAGS <- AIOrder.OF_DEPOT_FLAGS
367 AIOrder.AIOF_INVALID <- AIOrder.OF_INVALID
369 /* 1.9 adds a vehicle type parameter. */
370 AIBridge._GetName <- AIBridge.GetName;
371 AIBridge.GetName <- function(bridge_id)
373 return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL);
376 /* 1.9 adds parent_group_id to CreateGroup function */
377 AIGroup._CreateGroup <- AIGroup.CreateGroup;
378 AIGroup.CreateGroup <- function(vehicle_type)
380 return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID);
383 /* 13 really checks RoadType against RoadType */
384 AIRoad._HasRoadType <- AIRoad.HasRoadType;
385 AIRoad.HasRoadType <- function(tile, road_type)
387 local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type));
388 foreach (rt, _ in list) {
389 if (AIRoad._HasRoadType(tile, rt)) {
390 return true;
393 return false;
396 /* 15 renames GetBridgeID */
397 AIBridge.GetBridgeID <- AIBridge.GetBridgeType;