Index: src/ai/api/ai_airport.hpp =================================================================== --- src/ai/api/ai_airport.hpp (revision 12180) +++ src/ai/api/ai_airport.hpp (working copy) @@ -83,7 +83,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the airport has been/can be build or not. */ - bool BuildAirport(TileIndex tile, AirportType type); + static bool BuildAirport(TileIndex tile, AirportType type); /** * Removes a airport. @@ -91,7 +91,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the airport has been/can be removed or not. */ - bool RemoveAirport(TileIndex tile); + static bool RemoveAirport(TileIndex tile); /** * Get the first hanger tile of the airport. @@ -99,7 +99,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return the first hanger tile of the airport. */ - TileIndex GetHangarOfAirport(TileIndex tile); + static TileIndex GetHangarOfAirport(TileIndex tile); }; #endif /* AI_AIRPORT_HPP */ Index: src/ai/api/ai_industry.hpp =================================================================== --- src/ai/api/ai_industry.hpp (revision 12180) +++ src/ai/api/ai_industry.hpp (working copy) @@ -24,7 +24,7 @@ * @return the maximum industry index. * @post return value is always non-negative. */ - IndustryID GetMaxIndustryID(); + static IndustryID GetMaxIndustryID(); /** * Gets the number of industries. This is different than GetMaxIndustryID() @@ -32,7 +32,7 @@ * @return the number of industries. * @post return value is always non-negative. */ - int32 GetIndustryCount(); + static int32 GetIndustryCount(); /** * Checks whether the given industry index is valid. @@ -48,7 +48,7 @@ * @return the name of the industry. * @note the returned name must be free'd (C++ only). */ - char *GetName(IndustryID industry_id); + static char *GetName(IndustryID industry_id); /** * Gets the production of a cargo of the industry. Index: src/ai/api/ai_road.hpp =================================================================== --- src/ai/api/ai_road.hpp (revision 12180) +++ src/ai/api/ai_road.hpp (working copy) @@ -35,7 +35,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return true if and only if the tile has road. */ - bool IsRoadTile(TileIndex tile); + static bool IsRoadTile(TileIndex tile); /** * Checks whether the given tile is actually a tile with a road depot. @@ -43,7 +43,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return true if and only if the tile has a road depot. */ - bool IsRoadDepotTile(TileIndex tile); + static bool IsRoadDepotTile(TileIndex tile); /** * Checks whether the given tile is actually a tile with a road station. @@ -51,7 +51,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return true if and only if the tile has a road station. */ - bool IsRoadStationTile(TileIndex tile); + static bool IsRoadStationTile(TileIndex tile); /** * Checks whether the given tile is actually a tile with a drive through @@ -60,7 +60,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return true if and only if the tile has a drive through road station. */ - bool IsDriveThroughRoadStationTile(TileIndex tile); + static bool IsDriveThroughRoadStationTile(TileIndex tile); /** * Checks whether the given tiles are directly connected, i.e. whether @@ -73,7 +73,7 @@ * @pre t1 and t2 are directly neighbouring tiles. * @return true if and only if a road vehicle can go from t1 to t2. */ - bool AreRoadTilesConnected(TileIndex t1, TileIndex t2); + static bool AreRoadTilesConnected(TileIndex t1, TileIndex t2); /** * Count how many neighbours are road. @@ -89,7 +89,7 @@ * @pre IsRoadDepotTile(depot). * @return the tile in front of the depot. */ - TileIndex GetRoadDepotFrontTile(TileIndex depot); + static TileIndex GetRoadDepotFrontTile(TileIndex depot); /** * Gets the tile in front of a road station. @@ -97,7 +97,7 @@ * @pre IsRoadStationTile(station). * @return the tile in front of the road station. */ - TileIndex GetRoadStationFrontTile(TileIndex station); + static TileIndex GetRoadStationFrontTile(TileIndex station); /** * Gets the tile at the back of a drive through road station. @@ -107,7 +107,7 @@ * @pre IsDriveThroughRoadStationTile(station). * @return the tile at the back of the drive through road station. */ - TileIndex GetDriveThroughBackTile(TileIndex station); + static TileIndex GetDriveThroughBackTile(TileIndex station); /** * Builds a road from the center of tile start to the @@ -122,7 +122,7 @@ * AIMap::GetTileY(start) == AIMap::GetTileY(end). * @return whether the road has been/can be build or not. */ - bool BuildRoad(TileIndex start, TileIndex end); + static bool BuildRoad(TileIndex start, TileIndex end); /** * Builds a road from the edge of tile start to the @@ -137,7 +137,7 @@ * AIMap::GetTileY(start) == AIMap::GetTileY(end). * @return whether the road has been/can be build or not. */ - bool BuildRoadFull(TileIndex start, TileIndex end); + static bool BuildRoadFull(TileIndex start, TileIndex end); /** * Builds a road depot. @@ -148,7 +148,7 @@ * @pre tile is not equal to front * @return whether the road depot has been/can be build or not. */ - bool BuildRoadDepot(TileIndex tile, TileIndex front); + static bool BuildRoadDepot(TileIndex tile, TileIndex front); /** * Builds a road bus or truck station. @@ -162,7 +162,7 @@ * @pre tile is not equal to front * @return whether the station has been/can be build or not. */ - bool BuildRoadStation(TileIndex tile, TileIndex front, bool truck, bool drive_through); + static bool BuildRoadStation(TileIndex tile, TileIndex front, bool truck, bool drive_through); /** * Removes a road from the center of tile start to the @@ -176,7 +176,7 @@ * AIMap::GetTileY(start) == AIMap::GetTileY(end). * @return whether the road has been/can be removed or not. */ - bool RemoveRoad(TileIndex start, TileIndex end); + static bool RemoveRoad(TileIndex start, TileIndex end); /** * Removes a road from the edge of tile start to the @@ -190,7 +190,7 @@ * AIMap::GetTileY(start) == AIMap::GetTileY(end). * @return whether the road has been/can be removed or not. */ - bool RemoveRoadFull(TileIndex start, TileIndex end); + static bool RemoveRoadFull(TileIndex start, TileIndex end); /** * Removes a road depot. @@ -199,7 +199,7 @@ * @pre tile is a road depot. * @return whether the road depot has been/can be removed or not. */ - bool RemoveRoadDepot(TileIndex tile); + static bool RemoveRoadDepot(TileIndex tile); /** * Removes a road bus or truck station. @@ -208,7 +208,7 @@ * @pre tile is a road station. * @return whether the station has been/can be removed or not. */ - bool RemoveRoadStation(TileIndex tile); + static bool RemoveRoadStation(TileIndex tile); }; #endif /* AI_ROAD_HPP */ Index: src/ai/api/ai_engine.hpp.sq =================================================================== --- src/ai/api/ai_engine.hpp.sq (revision 12180) +++ src/ai/api/ai_engine.hpp.sq (working copy) @@ -22,6 +22,8 @@ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetReliability, "GetReliability", 2, "xi"); SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetMaxSpeed, "GetMaxSpeed", 2, "xi"); SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetPrice, "GetPrice", 2, "xi"); + SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetMaxAge, "GetMaxAge", 2, "xi"); + SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetRunningCost, "GetRunningCost", 2, "xi"); SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetVehicleType, "GetVehicleType", 2, "xi"); SQAIEngine.PostRegister(engine); Index: src/ai/api/ai_map.hpp.sq =================================================================== --- src/ai/api/ai_map.hpp.sq (revision 12180) +++ src/ai/api/ai_map.hpp.sq (working copy) @@ -26,8 +26,7 @@ SQAIMap.DefSQStaticMethod(engine, &AIMap::DistanceMax, "DistanceMax", 3, "xii"); SQAIMap.DefSQStaticMethod(engine, &AIMap::DistanceSquare, "DistanceSquare", 3, "xii"); SQAIMap.DefSQStaticMethod(engine, &AIMap::DistanceFromEdge, "DistanceFromEdge", 2, "xi"); + SQAIMap.DefSQStaticMethod(engine, &AIMap::DemolishTile, "DemolishTile", 2, "xi"); - SQAIMap.DefSQMethod(engine, &AIMap::DemolishTile, "DemolishTile", 2, "xi"); - SQAIMap.PostRegister(engine); } Index: src/ai/api/ai_order.cpp =================================================================== --- src/ai/api/ai_order.cpp (revision 12180) +++ src/ai/api/ai_order.cpp (working copy) @@ -90,14 +90,14 @@ bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags) { if (!AIVehicle::IsValidVehicle(vehicle_id)) return false; - return this->InsertOrder(vehicle_id, GetVehicle(vehicle_id)->num_orders, destination, order_flags); + return InsertOrder(vehicle_id, GetVehicle(vehicle_id)->num_orders, destination, order_flags); } bool AIOrder::InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrder::AIOrderFlags order_flags) { /* IsValidVehicleOrder is not good enough because it does not allow appending. */ if (!AIVehicle::IsValidVehicle(vehicle_id) || order_id > ::GetVehicle(vehicle_id)->num_orders || - !this->AreOrderFlagsValid(destination, order_flags)) return false; + !AreOrderFlagsValid(destination, order_flags)) return false; Order order; order.type = ::GetOrderTypeByTile(destination); @@ -109,29 +109,29 @@ default: NOT_REACHED(); return false; } - return this->DoCommand(0, vehicle_id | (order_id << 16), PackOrder(&order), CMD_INSERT_ORDER); + return DoCommand(0, vehicle_id | (order_id << 16), PackOrder(&order), CMD_INSERT_ORDER); } bool AIOrder::RemoveOrder(VehicleID vehicle_id, uint32 order_id) { if (!IsValidVehicleOrder(vehicle_id, order_id)) return false; - return this->DoCommand(0, vehicle_id, order_id, CMD_DELETE_ORDER); + return DoCommand(0, vehicle_id, order_id, CMD_DELETE_ORDER); } bool AIOrder::ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrder::AIOrderFlags order_flags) { if (!IsValidVehicleOrder(vehicle_id, order_id) || - !this->AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags)) return false; + !AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags)) return false; for (;;) { /* Loop as long as there is a difference between the requested and * the current orders of the vehicle. */ - AIOrderFlags current = this->GetOrderFlags(vehicle_id, order_id); + AIOrderFlags current = GetOrderFlags(vehicle_id, order_id); AIOrderFlags diff = current ^ order_flags; if (diff == 0) return true; - bool res = this->DoCommand(0, vehicle_id | (order_id << 16), FIND_FIRST_BIT(diff), CMD_MODIFY_ORDER); + bool res = DoCommand(0, vehicle_id | (order_id << 16), FIND_FIRST_BIT(diff), CMD_MODIFY_ORDER); if (!res) return false; } } @@ -141,26 +141,26 @@ if (!IsValidVehicleOrder(vehicle_id, order_id_move) || !IsValidVehicleOrder(vehicle_id, order_id_target)) return false; - return this->DoCommand(0, vehicle_id, order_id_move | (order_id_target << 16), CMD_MOVE_ORDER); + return DoCommand(0, vehicle_id, order_id_move | (order_id_target << 16), CMD_MOVE_ORDER); } bool AIOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) { if (!AIVehicle::IsValidVehicle(vehicle_id) || !AIVehicle::IsValidVehicle(main_vehicle_id)) return false; - return this->DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_COPY, CMD_CLONE_ORDER); + return DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_COPY, CMD_CLONE_ORDER); } bool AIOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) { if (!AIVehicle::IsValidVehicle(vehicle_id) || !AIVehicle::IsValidVehicle(main_vehicle_id)) return false; - return this->DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_SHARE, CMD_CLONE_ORDER); + return DoCommand(0, vehicle_id | (main_vehicle_id << 16), CO_SHARE, CMD_CLONE_ORDER); } bool AIOrder::UnshareOrders(VehicleID vehicle_id) { if (!AIVehicle::IsValidVehicle(vehicle_id)) return false; - return this->DoCommand(0, vehicle_id, CO_UNSHARE, CMD_CLONE_ORDER); + return DoCommand(0, vehicle_id, CO_UNSHARE, CMD_CLONE_ORDER); } Index: src/ai/api/ai_marine.cpp =================================================================== --- src/ai/api/ai_marine.cpp (revision 12180) +++ src/ai/api/ai_marine.cpp (working copy) @@ -52,7 +52,7 @@ /* Outside of the map */ if (tile >= ::MapSize()) return false; - return this->DoCommand(tile, vertical, 0, CMD_BUILD_SHIP_DEPOT, false); + return DoCommand(tile, vertical, 0, CMD_BUILD_SHIP_DEPOT, false); } bool AIMarine::BuildDock(TileIndex tile) @@ -60,7 +60,7 @@ /* Outside of the map */ if (tile >= ::MapSize()) return false; - return this->DoCommand(tile, 1, 0, CMD_BUILD_DOCK, false); + return DoCommand(tile, 1, 0, CMD_BUILD_DOCK, false); } bool AIMarine::BuildBuoy(TileIndex tile) @@ -68,7 +68,7 @@ /* Outside of the map */ if (tile >= ::MapSize()) return false; - return this->DoCommand(tile, 0, 0, CMD_BUILD_BUOY, false); + return DoCommand(tile, 0, 0, CMD_BUILD_BUOY, false); } bool AIMarine::BuildLock(TileIndex tile) @@ -76,7 +76,7 @@ /* Outside of the map */ if (tile >= ::MapSize()) return false; - return this->DoCommand(tile, 0, 0, CMD_BUILD_LOCK, false); + return DoCommand(tile, 0, 0, CMD_BUILD_LOCK, false); } bool AIMarine::BuildCanal(TileIndex tile) @@ -84,7 +84,7 @@ /* Outside of the map */ if (tile >= ::MapSize()) return false; - return this->DoCommand(tile, tile, 0, CMD_BUILD_CANAL, false); + return DoCommand(tile, tile, 0, CMD_BUILD_CANAL, false); } bool AIMarine::RemoveWaterDepot(TileIndex tile) @@ -95,7 +95,7 @@ /* Not a water depot tile */ if (!IsWaterDepotTile(tile)) return false; - return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); + return DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); } bool AIMarine::RemoveDock(TileIndex tile) @@ -106,7 +106,7 @@ /* Not a dock tile */ if (!IsDockTile(tile)) return false; - return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); + return DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); } bool AIMarine::RemoveBuoy(TileIndex tile) @@ -117,7 +117,7 @@ /* Not a buoy tile */ if (!IsBuoyTile(tile)) return false; - return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); + return DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); } bool AIMarine::RemoveLock(TileIndex tile) @@ -128,7 +128,7 @@ /* Not a lock tile */ if (!IsLockTile(tile)) return false; - return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); + return DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); } bool AIMarine::RemoveCanal(TileIndex tile) @@ -139,5 +139,5 @@ /* Not a canal tile */ if (!IsCanalTile(tile)) return false; - return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); + return DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR, false); } Index: src/ai/api/ai_sign.hpp.sq =================================================================== --- src/ai/api/ai_sign.hpp.sq (revision 12180) +++ src/ai/api/ai_sign.hpp.sq (working copy) @@ -15,14 +15,13 @@ SQAISign.AddConstructor(engine, "x"); SQAISign.DefSQStaticMethod(engine, &AISign::GetClassName, "GetClassName", 1, "x"); + SQAISign.DefSQStaticMethod(engine, &AISign::GetMaxSignID, "GetMaxSignID", 1, "x"); + SQAISign.DefSQStaticMethod(engine, &AISign::GetSignCount, "GetSignCount", 1, "x"); SQAISign.DefSQStaticMethod(engine, &AISign::IsValidSign, "IsValidSign", 2, "xi"); + SQAISign.DefSQStaticMethod(engine, &AISign::GetText, "GetText", 2, "xi"); + SQAISign.DefSQStaticMethod(engine, &AISign::GetLocation, "GetLocation", 2, "xi"); + SQAISign.DefSQStaticMethod(engine, &AISign::RemoveSign, "RemoveSign", 2, "xi"); + SQAISign.DefSQStaticMethod(engine, &AISign::BuildSign, "BuildSign", 3, "xis"); - SQAISign.DefSQMethod(engine, &AISign::GetMaxSignID, "GetMaxSignID", 1, "x"); - SQAISign.DefSQMethod(engine, &AISign::GetSignCount, "GetSignCount", 1, "x"); - SQAISign.DefSQMethod(engine, &AISign::GetText, "GetText", 2, "xi"); - SQAISign.DefSQMethod(engine, &AISign::GetLocation, "GetLocation", 2, "xi"); - SQAISign.DefSQMethod(engine, &AISign::RemoveSign, "RemoveSign", 2, "xi"); - SQAISign.DefSQMethod(engine, &AISign::BuildSign, "BuildSign", 3, "xis"); - SQAISign.PostRegister(engine); } Index: src/ai/api/ai_town.hpp =================================================================== --- src/ai/api/ai_town.hpp (revision 12180) +++ src/ai/api/ai_town.hpp (working copy) @@ -23,7 +23,7 @@ * @return the maximum town index. * @post return value is always non-negative. */ - TownID GetMaxTownID(); + static TownID GetMaxTownID(); /** * Gets the number of towns. This is different than GetMaxTownID() @@ -31,7 +31,7 @@ * @return the number of towns. * @post return value is always non-negative. */ - int32 GetTownCount(); + static int32 GetTownCount(); /** * Checks whether the given town index is valid. Index: src/ai/api/ai_cargo.hpp =================================================================== --- src/ai/api/ai_cargo.hpp (revision 12180) +++ src/ai/api/ai_cargo.hpp (working copy) @@ -30,14 +30,14 @@ * @return the cargo label. * @note the returned cargo label must be free'd (C++ only). */ - char *GetCargoLabel(CargoID cargo_type); + static char *GetCargoLabel(CargoID cargo_type); /** * Checks whether the give cargo is a freight or not. * @param cargo_type is this cargo freight or not? * @return true if and only if the cargo is freight. */ - bool IsFreight(CargoID cargo_type); + static bool IsFreight(CargoID cargo_type); /** * Get the income for transporting a piece of cargo over the @@ -47,7 +47,7 @@ * @param cargo_type the cargo to transport. * @return the amount of money that would be earned by this trip. */ - int32 GetCargoIncome(uint32 distance, uint32 days_in_transit, CargoID cargo_type); + static int32 GetCargoIncome(uint32 distance, uint32 days_in_transit, CargoID cargo_type); }; #endif /* AI_CARGO_HPP */ Index: src/ai/api/ai_tile.hpp =================================================================== --- src/ai/api/ai_tile.hpp (revision 12180) +++ src/ai/api/ai_tile.hpp (working copy) @@ -6,6 +6,7 @@ #define AI_TILE_HPP #include "ai_abstractlist.hpp" +#include "../../industry_type.h" /** * Class that handles all tile related functions. @@ -83,34 +84,42 @@ static int32 GetHeight(TileIndex tile); /** - * Check how much cargo this tile accepts. - * It creates a radius around the tile and adds up all acceptance of this - * cargo and returns that value. + * Check if this tile accepts the cargo. + * It creates a radius around the tile and checks if the cargo is + * accepted within that radius. * @pre tile is always positive and smaller than AIMap::GetMapSize(). - * @param tile the tile to check on. + * @param the tile to check on. * @param cargo_type the cargo to check the acceptance of. * @param width the width of the station. * @param height the height of the station. * @param radius the radius of the station. - * @return value below 8 means no acceptance; the more the better. + * @return true if the cargo is accepted, false otherwise. */ - static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius); + static bool GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius); /** - * Check how much cargo this tile produces. - * It creates a radius around the tile and adds up all production of this - * cargo and returns that value. + * Check if this tile produces the given cargo. + * It creates a radius around the tile and checks if the cargo is + * produced within that radius. * @pre tile is always positive and smaller than AIMap::GetMapSize(). - * @param tile the tile to check on. + * @param the tile to check on. * @param cargo_type the cargo to check the production of. * @param width the width of the station. * @param height the height of the station. * @param radius the radius of the station. - * @return the production for the given cargo type. + * @return true if the cargo is produced, false otherwise. */ - static int32 GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad); + static bool GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad); + /** + * Get the IndustryID of the industry located on this tile (if any). + * @param the tile to check on. + * @return The IndustryID of the industry, or INVALID_INDUSTRY if no industry is located on this tile + */ + static IndustryID GetIndustry(TileIndex tile); + + /** * Raise the given corners of the tile. The corners can be combined, * for example: SLOPE_N | SLOPE_W (= SLOPE_NW) * @pre tile is always positive and smaller than AIMap::GetMapSize(). @@ -118,7 +127,7 @@ * @param slope corners to raise (SLOPE_xxx). * @return 0 means failed, 1 means success. */ - bool RaiseTile(TileIndex tile, int32 slope); + static bool RaiseTile(TileIndex tile, int32 slope); /** * Lower the given corners of the tile. The corners can be combined, @@ -128,7 +137,7 @@ * @param slope corners to lower (SLOPE_xxx). * @return 0 means failed, 1 means success. */ - bool LowerTile(TileIndex tile, int32 slope); + static bool LowerTile(TileIndex tile, int32 slope); }; Index: src/ai/api/ai_sign.hpp =================================================================== --- src/ai/api/ai_sign.hpp (revision 12180) +++ src/ai/api/ai_sign.hpp (working copy) @@ -22,7 +22,7 @@ * @return the maximum sign index. * @post return value is always non-negative. */ - SignID GetMaxSignID(); + static SignID GetMaxSignID(); /** * Gets the number of signs. This is different than GetMaxSignID() @@ -30,7 +30,7 @@ * @return the number of signs. * @post return value is always non-negative. */ - int32 GetSignCount(); + static int32 GetSignCount(); /** * Checks whether the given sign index is valid. @@ -46,7 +46,7 @@ * @return the text on the sign. * @note the returned name must be free'd (C++ only). */ - char *GetText(SignID sign_id); + static char *GetText(SignID sign_id); /** * Gets the location of the sign. @@ -55,7 +55,7 @@ * @return the location of the sign. * @post return value is always positive and below AIMap::GetMapSize(). */ - TileIndex GetLocation(SignID sign_id); + static TileIndex GetLocation(SignID sign_id); /** * Removes a sign from the map. @@ -63,7 +63,7 @@ * @pre sign_id has to be valid (use IsValidSign()). * @return true if and only if the sign has been removed. */ - bool RemoveSign(SignID sign_id); + static bool RemoveSign(SignID sign_id); /** * Builds a sign on the map. @@ -75,7 +75,7 @@ * In test-mode it returns 0 if successful, or any other value to indicate * failure. */ - SignID BuildSign(TileIndex location, const char *text); + static SignID BuildSign(TileIndex location, const char *text); }; #endif /* AI_SIGN_HPP */ Index: src/ai/api/ai_engine.hpp =================================================================== --- src/ai/api/ai_engine.hpp (revision 12180) +++ src/ai/api/ai_engine.hpp (working copy) @@ -78,6 +78,23 @@ static uint32 GetPrice(EngineID engine_id); /** + * Get the max age of a brand new engine. + * @param engine_id the engine to get the max age of. + * @pre IsValidEngine(engine_id). + * @returns The max age of a new engine in days. + */ + static int32 GetMaxAge(EngineID engine_id); + + /** + * Get the running cost of a road vehicle with the given engine. + * @param engine_id the engine to get the running cost of. + * @pre IsValidEngine(engine_id). + * @return The running cost of a vehicle per year (divide by + * 364 to get the running cost per day). + */ + static Money GetRunningCost(EngineID engine_id); + + /** * Get the type of an engine. * @param engine_id the engine to get the type of. * @pre IsValidEngine(engine_id). Index: src/ai/api/ai_company.hpp =================================================================== --- src/ai/api/ai_company.hpp (revision 12180) +++ src/ai/api/ai_company.hpp (working copy) @@ -34,7 +34,7 @@ * @param company the company index to resolve. * @return the resolved company index. */ - CompanyIndex ResolveCompanyIndex(CompanyIndex company); + static CompanyIndex ResolveCompanyIndex(CompanyIndex company); /** * Set the name of your company. @@ -42,7 +42,7 @@ * @pre name != NULL * @return true if the name was changed. */ - bool SetCompanyName(const char *name); + static bool SetCompanyName(const char *name); /** * Get the name of the given company. @@ -51,7 +51,7 @@ * @return the name of the given company. * @note the returned company name must be free'd (C++ only). */ - char *GetCompanyName(CompanyIndex company); + static char *GetCompanyName(CompanyIndex company); /** * Set the name of your president. @@ -59,7 +59,7 @@ * @pre name != NULL * @return true if the name was changed. */ - bool SetPresidentName(const char *name); + static bool SetPresidentName(const char *name); /** * Get the name of the president of the given company. @@ -68,7 +68,7 @@ * @return the name of the president of the given company. * @note the returned president name must be free'd (C++ only). */ - char *GetPresidentName(CompanyIndex company); + static char *GetPresidentName(CompanyIndex company); /** * Gets the current value of the given company. @@ -76,7 +76,7 @@ * @pre ResolveCompanyIndex(company) != INVALID_COMPANY * @return the current value of the given company. */ - int32 GetCompanyValue(CompanyIndex company); + static int32 GetCompanyValue(CompanyIndex company); /** * Gets the bank balance. In other words, the amount of money the given company can spent. @@ -84,7 +84,7 @@ * @pre ResolveCompanyIndex(company) != INVALID_COMPANY * @return the actual bank balance. */ - int32 GetBankBalance(CompanyIndex company); + static int32 GetBankBalance(CompanyIndex company); /** * Gets the amount your company have loaned. @@ -92,7 +92,7 @@ * @post the return value is always non-negative. * @post GetLoanInterval() is always a multiplier of the return value. */ - int32 GetLoanAmount(); + static int32 GetLoanAmount(); /** * Gets the maximum amount your company can loan. @@ -100,14 +100,14 @@ * @post the return value is always non-negative. * @post GetLoanInterval() is always a multiplier of the return value. */ - int32 GetMaxLoanAmount(); + static int32 GetMaxLoanAmount(); /** * Gets the interval/loan step. * @return the loan step. * @post return value is always positive. */ - int32 GetLoanInterval(); + static int32 GetLoanInterval(); /** * Sets the amount to loan. @@ -118,7 +118,7 @@ * @pre loan - GetLoanAmount() + GetBankBalance() must be non-negative. * @return true if the loan could be set to your requested amount. */ - bool SetLoanAmount(int32 loan); + static bool SetLoanAmount(int32 loan); /** * Sets the minimum amount to loan, i.e. the given amount of loan rounded up. @@ -127,7 +127,7 @@ * @pre loan must be below GetMaxLoan(). * @return true if we could allocate a minimum of "loan" loan. */ - bool SetMinimumLoanAmount(int32 loan); + static bool SetMinimumLoanAmount(int32 loan); }; DECLARE_POSTFIX_INCREMENT(AICompany::CompanyIndex); Index: src/ai/api/ai_town.hpp.sq =================================================================== --- src/ai/api/ai_town.hpp.sq (revision 12180) +++ src/ai/api/ai_town.hpp.sq (working copy) @@ -15,13 +15,12 @@ SQAITown.AddConstructor(engine, "x"); SQAITown.DefSQStaticMethod(engine, &AITown::GetClassName, "GetClassName", 1, "x"); + SQAITown.DefSQStaticMethod(engine, &AITown::GetMaxTownID, "GetMaxTownID", 1, "x"); + SQAITown.DefSQStaticMethod(engine, &AITown::GetTownCount, "GetTownCount", 1, "x"); SQAITown.DefSQStaticMethod(engine, &AITown::IsValidTown, "IsValidTown", 2, "xi"); SQAITown.DefSQStaticMethod(engine, &AITown::GetName, "GetName", 2, "xi"); SQAITown.DefSQStaticMethod(engine, &AITown::GetPopulation, "GetPopulation", 2, "xi"); SQAITown.DefSQStaticMethod(engine, &AITown::GetLocation, "GetLocation", 2, "xi"); - SQAITown.DefSQMethod(engine, &AITown::GetMaxTownID, "GetMaxTownID", 1, "x"); - SQAITown.DefSQMethod(engine, &AITown::GetTownCount, "GetTownCount", 1, "x"); - SQAITown.PostRegister(engine); } Index: src/ai/api/ai_airport.cpp =================================================================== --- src/ai/api/ai_airport.cpp (revision 12180) +++ src/ai/api/ai_airport.cpp (working copy) @@ -53,7 +53,7 @@ if (tile >= ::MapSize()) return false; if (type > AT_HELISTATION) return 0; - return this->DoCommand(tile, type, 0, CMD_BUILD_AIRPORT); + return DoCommand(tile, type, 0, CMD_BUILD_AIRPORT); } bool AIAirport::RemoveAirport(TileIndex tile) @@ -64,7 +64,7 @@ /* Not a airport tile */ if (!IsAirportTile(tile) && !IsHangarTile(tile)) return false; - return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } TileIndex AIAirport::GetHangarOfAirport(TileIndex tile) Index: src/ai/api/ai_industry.cpp =================================================================== --- src/ai/api/ai_industry.cpp (revision 12180) +++ src/ai/api/ai_industry.cpp (working copy) @@ -25,7 +25,7 @@ char *AIIndustry::GetName(IndustryID industry_id) { - if (!this->IsValidIndustry(industry_id)) return NULL; + if (!IsValidIndustry(industry_id)) return NULL; static const int len = 64; char *industry_name = MallocT(len); Index: src/ai/api/ai_map.hpp =================================================================== --- src/ai/api/ai_map.hpp (revision 12180) +++ src/ai/api/ai_map.hpp (working copy) @@ -122,7 +122,7 @@ * @pre t has to be valid (use IsValidTile(t)). * @return true if and only if the destruction succeeded */ - bool DemolishTile(TileIndex t); + static bool DemolishTile(TileIndex t); }; #endif /* AI_MAP_HPP */ Index: src/ai/api/ai_cargo.hpp.sq =================================================================== --- src/ai/api/ai_cargo.hpp.sq (revision 12180) +++ src/ai/api/ai_cargo.hpp.sq (working copy) @@ -14,12 +14,11 @@ SQAICargo.PreRegister(engine); SQAICargo.AddConstructor(engine, "x"); - SQAICargo.DefSQStaticMethod(engine, &AICargo::GetClassName, "GetClassName", 1, "x"); - SQAICargo.DefSQStaticMethod(engine, &AICargo::IsValidCargo, "IsValidCargo", 2, "xi"); + SQAICargo.DefSQStaticMethod(engine, &AICargo::GetClassName, "GetClassName", 1, "x"); + SQAICargo.DefSQStaticMethod(engine, &AICargo::IsValidCargo, "IsValidCargo", 2, "xi"); + SQAICargo.DefSQStaticMethod(engine, &AICargo::GetCargoLabel, "GetCargoLabel", 2, "xi"); + SQAICargo.DefSQStaticMethod(engine, &AICargo::IsFreight, "IsFreight", 2, "xi"); + SQAICargo.DefSQStaticMethod(engine, &AICargo::GetCargoIncome, "GetCargoIncome", 4, "xiii"); - SQAICargo.DefSQMethod(engine, &AICargo::GetCargoLabel, "GetCargoLabel", 2, "xi"); - SQAICargo.DefSQMethod(engine, &AICargo::IsFreight, "IsFreight", 2, "xi"); - SQAICargo.DefSQMethod(engine, &AICargo::GetCargoIncome, "GetCargoIncome", 4, "xiii"); - SQAICargo.PostRegister(engine); } Index: src/ai/api/ai_vehicle.hpp =================================================================== --- src/ai/api/ai_vehicle.hpp (revision 12180) +++ src/ai/api/ai_vehicle.hpp (working copy) @@ -52,7 +52,7 @@ * as the vehicle isn't really built yet. Build it for real first before * assigning orders. */ - VehicleID BuildVehicle(TileIndex depot, EngineID engine_id); + static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id); /** * Clones a vehicle at the given depot, copying or cloning it's orders. @@ -65,7 +65,7 @@ * it failed. Check the return value using IsValidVehicle. In test-mode * 0 is returned if it was successful; any other value indicates failure. */ - VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders); + static VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders); /** * Refits a vehicle to the given cargo type @@ -77,7 +77,7 @@ * @pre the vehicle must be stopped in the depot * @return true if and only if the refit succeeded. */ - bool RefitVehicle(VehicleID vehicle_id, CargoID cargo); + static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo); /** * Sells the given vehicle. @@ -87,7 +87,7 @@ * @pre the vehicle must be stopped in the depot * @return true if and only if the vehicle has been sold. */ - bool SellVehicle(VehicleID vehicle_id); + static bool SellVehicle(VehicleID vehicle_id); /** * Sends the given vehicle to a depot. @@ -95,7 +95,7 @@ * @pre IsValidVehicle(vehicle_id). * @return true if and only if the vehicle has been sent to a depot. */ - bool SendVehicleToDepot(VehicleID vehicle_id); + static bool SendVehicleToDepot(VehicleID vehicle_id); /** * Check if a vehicle is in a depot. @@ -103,7 +103,7 @@ * @pre isValidVehicle(vehicle_id). * @return true if and only if the vehicle is in a depot. */ - bool IsInDepot(VehicleID vehicle_id); + static bool IsInDepot(VehicleID vehicle_id); /** * Check if a vehicle is in a depot and stopped. @@ -111,7 +111,7 @@ * @pre isValidVehicle(vehicle_id). * @return true if and only if the vehicle is in a depot and stopped. */ - bool IsStoppedInDepot(VehicleID vehicle_id); + static bool IsStoppedInDepot(VehicleID vehicle_id); /** * Starts or stops the given vehicle depending on the current state. @@ -119,7 +119,7 @@ * @pre IsValidVehicle(vehicle_id). * @return true if and only if the vehicle has been started or stopped. */ - bool StartStopVehicle(VehicleID vehicle_id); + static bool StartStopVehicle(VehicleID vehicle_id); /** * Skips the current order of the given vehicle. @@ -128,7 +128,7 @@ * @pre IsValidVehicleOrder(vehicle_id, order_id). * @return true if and only if the order has been skipped. */ - bool SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id); + static bool SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id); /** * Set the name of a vehicle. @@ -139,7 +139,7 @@ * @pre You have to own the vehicle. * @return true if and only if the name was changed. */ - bool SetName(VehicleID vehicle_id, const char *name); + static bool SetName(VehicleID vehicle_id, const char *name); /** * Get the current location of a vehicle. @@ -223,6 +223,7 @@ * @return the vehicle type. */ static AIVehicle::VehicleType GetVehicleType(VehicleID vehicle_id); + }; #endif /* AI_VEHICLE_HPP */ Index: src/ai/api/ai_road.cpp =================================================================== --- src/ai/api/ai_road.cpp (revision 12180) +++ src/ai/api/ai_road.cpp (working copy) @@ -12,7 +12,7 @@ if (tile >= ::MapSize()) return false; return (::IsTileType(tile, MP_ROAD) && ::GetRoadTileType(tile) != ROAD_TILE_DEPOT) || - this->IsDriveThroughRoadStationTile(tile); + IsDriveThroughRoadStationTile(tile); } bool AIRoad::IsRoadDepotTile(TileIndex tile) @@ -73,21 +73,21 @@ TileIndex AIRoad::GetRoadDepotFrontTile(TileIndex depot) { - if (!this->IsRoadDepotTile(depot)) return INVALID_TILE; + if (!IsRoadDepotTile(depot)) return INVALID_TILE; return depot + ::TileOffsByDiagDir(::GetRoadDepotDirection(depot)); } TileIndex AIRoad::GetRoadStationFrontTile(TileIndex station) { - if (!this->IsRoadStationTile(station)) return INVALID_TILE; + if (!IsRoadStationTile(station)) return INVALID_TILE; return station + ::TileOffsByDiagDir(::GetRoadStopDir(station)); } TileIndex AIRoad::GetDriveThroughBackTile(TileIndex station) { - if (!this->IsDriveThroughRoadStationTile(station)) return INVALID_TILE; + if (!IsDriveThroughRoadStationTile(station)) return INVALID_TILE; return station + ::TileOffsByDiagDir(::ReverseDiagDir(::GetRoadStopDir(station))); } @@ -100,7 +100,7 @@ if (TileX(start) != TileX(end) && TileY(start) != TileY(end)) return false; - return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ROADTYPE_ROAD << 3), CMD_BUILD_LONG_ROAD); + return DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ROADTYPE_ROAD << 3), CMD_BUILD_LONG_ROAD); } bool AIRoad::BuildRoadFull(TileIndex start, TileIndex end) @@ -111,7 +111,7 @@ if (TileX(start) != TileX(end) && TileY(start) != TileY(end)) return false; - return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 2 : 1), CMD_BUILD_LONG_ROAD); + return DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 2 : 1), CMD_BUILD_LONG_ROAD); } bool AIRoad::BuildRoadDepot(TileIndex tile, TileIndex front) @@ -121,7 +121,7 @@ uint entrance_dir = (TileX(tile) == TileX(front)) ? (TileY(tile) < TileY(front) ? 1 : 3) : (TileX(tile) < TileX(front) ? 2 : 0); - return this->DoCommand(tile, entrance_dir, ROADTYPE_ROAD << 2, CMD_BUILD_ROAD_DEPOT); + return DoCommand(tile, entrance_dir, ROADTYPE_ROAD << 2, CMD_BUILD_ROAD_DEPOT); } bool AIRoad::BuildRoadStation(TileIndex tile, TileIndex front, bool truck, bool drive_through) @@ -136,7 +136,7 @@ entrance_dir = (TileX(tile) == TileX(front)) ? (TileY(tile) < TileY(front) ? 1 : 3) : (TileX(tile) < TileX(front) ? 2 : 0); } - return this->DoCommand(tile, entrance_dir, (drive_through ? 2 : 0) | (truck ? 1 : 0) | (ROADTYPES_ROAD << 2), CMD_BUILD_ROAD_STOP); + return DoCommand(tile, entrance_dir, (drive_through ? 2 : 0) | (truck ? 1 : 0) | (ROADTYPES_ROAD << 2), CMD_BUILD_ROAD_STOP); } bool AIRoad::RemoveRoad(TileIndex start, TileIndex end) @@ -147,7 +147,7 @@ if (TileX(start) != TileX(end) && TileY(start) != TileY(end)) return false; - return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ROADTYPE_ROAD << 3), CMD_REMOVE_LONG_ROAD); + return DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ROADTYPE_ROAD << 3), CMD_REMOVE_LONG_ROAD); } bool AIRoad::RemoveRoadFull(TileIndex start, TileIndex end) @@ -158,7 +158,7 @@ if (TileX(start) != TileX(end) && TileY(start) != TileY(end)) return false; - return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 2 : 1), CMD_REMOVE_LONG_ROAD); + return DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 2 : 1), CMD_REMOVE_LONG_ROAD); } bool AIRoad::RemoveRoadDepot(TileIndex tile) @@ -169,7 +169,7 @@ /* Not a road depot tile */ if (!IsTileType(tile, MP_ROAD) || GetRoadTileType(tile) != ROAD_TILE_DEPOT) return false; - return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } bool AIRoad::RemoveRoadStation(TileIndex tile) @@ -180,5 +180,5 @@ /* Not a road station tile */ if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile)) return false; - return this->DoCommand(tile, 0, GetRoadStopType(tile), CMD_REMOVE_ROAD_STOP); + return DoCommand(tile, 0, GetRoadStopType(tile), CMD_REMOVE_ROAD_STOP); } Index: src/ai/api/ai_vehicle.hpp.sq =================================================================== --- src/ai/api/ai_vehicle.hpp.sq (revision 12180) +++ src/ai/api/ai_vehicle.hpp.sq (working copy) @@ -24,29 +24,28 @@ SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_AIR, "VEHICLE_AIR"); SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_INVALID, "VEHICLE_INVALID"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetClassName, "GetClassName", 1, "x"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidVehicle, "IsValidVehicle", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetLocation, "GetLocation", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetEngineType, "GetEngineType", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetUnitNumber, "GetUnitNumber", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetName, "GetName", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetAge, "GetAge", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetMaxAge, "GetMaxAge", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetAgeLeft, "GetAgeLeft", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetProfitThisYear, "GetProfitThisYear", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetProfitLastYear, "GetProfitLastYear", 2, "xi"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetVehicleType, "GetVehicleType", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetClassName, "GetClassName", 1, "x"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidVehicle, "IsValidVehicle", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::BuildVehicle, "BuildVehicle", 3, "xii"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::CloneVehicle, "CloneVehicle", 4, "xiib"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::RefitVehicle, "RefitVehicle", 3, "xii"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SellVehicle, "SellVehicle", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SendVehicleToDepot, "SendVehicleToDepot", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsInDepot, "IsInDepot", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsStoppedInDepot, "IsStoppedInDepot", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::StartStopVehicle, "StartStopVehicle", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SkipToVehicleOrder, "SkipToVehicleOrder", 3, "xii"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SetName, "SetName", 3, "xis"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetLocation, "GetLocation", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetEngineType, "GetEngineType", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetUnitNumber, "GetUnitNumber", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetName, "GetName", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetAge, "GetAge", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetMaxAge, "GetMaxAge", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetAgeLeft, "GetAgeLeft", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetProfitThisYear, "GetProfitThisYear", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetProfitLastYear, "GetProfitLastYear", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetVehicleType, "GetVehicleType", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::BuildVehicle, "BuildVehicle", 3, "xii"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::CloneVehicle, "CloneVehicle", 4, "xiib"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::RefitVehicle, "RefitVehicle", 3, "xii"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::SellVehicle, "SellVehicle", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::SendVehicleToDepot, "SendVehicleToDepot", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::IsInDepot, "IsInDepot", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::IsStoppedInDepot, "IsStoppedInDepot", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::StartStopVehicle, "StartStopVehicle", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::SkipToVehicleOrder, "SkipToVehicleOrder", 3, "xii"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::SetName, "SetName", 3, "xis"); - SQAIVehicle.PostRegister(engine); } Index: src/ai/api/ai_industry.hpp.sq =================================================================== --- src/ai/api/ai_industry.hpp.sq (revision 12180) +++ src/ai/api/ai_industry.hpp.sq (working copy) @@ -14,15 +14,14 @@ SQAIIndustry.PreRegister(engine); SQAIIndustry.AddConstructor(engine, "x"); - SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetClassName, "GetClassName", 1, "x"); - SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsValidIndustry, "IsValidIndustry", 2, "xi"); - SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetProduction, "GetProduction", 3, "xii"); - SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsCargoAccepted, "IsCargoAccepted", 3, "xii"); - SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLocation, "GetLocation", 2, "xi"); + SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetClassName, "GetClassName", 1, "x"); + SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetMaxIndustryID, "GetMaxIndustryID", 1, "x"); + SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount", 1, "x"); + SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsValidIndustry, "IsValidIndustry", 2, "xi"); + SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetName, "GetName", 2, "xi"); + SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetProduction, "GetProduction", 3, "xii"); + SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsCargoAccepted, "IsCargoAccepted", 3, "xii"); + SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLocation, "GetLocation", 2, "xi"); - SQAIIndustry.DefSQMethod(engine, &AIIndustry::GetMaxIndustryID, "GetMaxIndustryID", 1, "x"); - SQAIIndustry.DefSQMethod(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount", 1, "x"); - SQAIIndustry.DefSQMethod(engine, &AIIndustry::GetName, "GetName", 2, "xi"); - SQAIIndustry.PostRegister(engine); } Index: src/ai/api/ai_road.hpp.sq =================================================================== --- src/ai/api/ai_road.hpp.sq (revision 12180) +++ src/ai/api/ai_road.hpp.sq (working copy) @@ -14,25 +14,24 @@ SQAIRoad.PreRegister(engine); SQAIRoad.AddConstructor(engine, "x"); - SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetClassName, "GetClassName", 1, "x"); - SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetNeighbourRoadCount, "GetNeighbourRoadCount", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetClassName, "GetClassName", 1, "x"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadTile, "IsRoadTile", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadDepotTile, "IsRoadDepotTile", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadStationTile, "IsRoadStationTile", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsDriveThroughRoadStationTile, "IsDriveThroughRoadStationTile", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::AreRoadTilesConnected, "AreRoadTilesConnected", 3, "xii"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetNeighbourRoadCount, "GetNeighbourRoadCount", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetRoadDepotFrontTile, "GetRoadDepotFrontTile", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetRoadStationFrontTile, "GetRoadStationFrontTile", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetDriveThroughBackTile, "GetDriveThroughBackTile", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildRoad, "BuildRoad", 3, "xii"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildRoadFull, "BuildRoadFull", 3, "xii"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildRoadDepot, "BuildRoadDepot", 3, "xii"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildRoadStation, "BuildRoadStation", 5, "xiibb"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::RemoveRoad, "RemoveRoad", 3, "xii"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::RemoveRoadFull, "RemoveRoadFull", 3, "xii"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::RemoveRoadDepot, "RemoveRoadDepot", 2, "xi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::RemoveRoadStation, "RemoveRoadStation", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::IsRoadTile, "IsRoadTile", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::IsRoadDepotTile, "IsRoadDepotTile", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::IsRoadStationTile, "IsRoadStationTile", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::IsDriveThroughRoadStationTile, "IsDriveThroughRoadStationTile", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::AreRoadTilesConnected, "AreRoadTilesConnected", 3, "xii"); - SQAIRoad.DefSQMethod(engine, &AIRoad::GetRoadDepotFrontTile, "GetRoadDepotFrontTile", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::GetRoadStationFrontTile, "GetRoadStationFrontTile", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::GetDriveThroughBackTile, "GetDriveThroughBackTile", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::BuildRoad, "BuildRoad", 3, "xii"); - SQAIRoad.DefSQMethod(engine, &AIRoad::BuildRoadFull, "BuildRoadFull", 3, "xii"); - SQAIRoad.DefSQMethod(engine, &AIRoad::BuildRoadDepot, "BuildRoadDepot", 3, "xii"); - SQAIRoad.DefSQMethod(engine, &AIRoad::BuildRoadStation, "BuildRoadStation", 5, "xiibb"); - SQAIRoad.DefSQMethod(engine, &AIRoad::RemoveRoad, "RemoveRoad", 3, "xii"); - SQAIRoad.DefSQMethod(engine, &AIRoad::RemoveRoadFull, "RemoveRoadFull", 3, "xii"); - SQAIRoad.DefSQMethod(engine, &AIRoad::RemoveRoadDepot, "RemoveRoadDepot", 2, "xi"); - SQAIRoad.DefSQMethod(engine, &AIRoad::RemoveRoadStation, "RemoveRoadStation", 2, "xi"); - SQAIRoad.PostRegister(engine); } Index: src/ai/api/ai_order.hpp =================================================================== --- src/ai/api/ai_order.hpp (revision 12180) +++ src/ai/api/ai_order.hpp (working copy) @@ -65,7 +65,7 @@ * @return the number of orders for the given vehicle or a negative * value when the vehicle does not exist. */ - int32 GetNumberOfOrders(VehicleID vehicle_id); + static int32 GetNumberOfOrders(VehicleID vehicle_id); /** * Gets the destination of the given order for the given vehicle. @@ -74,7 +74,7 @@ * @pre IsValidVehicleOrder(vehicle_id, order_id). * @return the destination tile of the order. */ - TileIndex GetOrderDestination(VehicleID vehicle_id, uint32 order_id); + static TileIndex GetOrderDestination(VehicleID vehicle_id, uint32 order_id); /** * Gets the AIOrderFlags of the given order for the given vehicle. @@ -83,7 +83,7 @@ * @pre IsValidVehicleOrder(vehicle_id, order_id). * @return the AIOrderFlags of the order. */ - AIOrderFlags GetOrderFlags(VehicleID vehicle_id, uint32 order_id); + static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, uint32 order_id); /** * Appends an order to the end of the vehicle's order list. @@ -94,7 +94,7 @@ * @pre AreOrderFlagsValid(destination, order_flags). * @return true if and only if the order was appended. */ - bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags); + static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags); /** * Inserts an order before the given order_id into the vehicle's order list. @@ -106,7 +106,7 @@ * @pre AreOrderFlagsValid(destination, order_flags). * @return true if and only if the order was inserted. */ - bool InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrderFlags order_flags); + static bool InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrderFlags order_flags); /** * Removes an order from the vehicle's order list. @@ -115,7 +115,7 @@ * @pre AIVehicle::IsValidVehicleOrder(vehicle_id, order_id). * @return true if and only if the order was removed. */ - bool RemoveOrder(VehicleID vehicle_id, uint32 order_id); + static bool RemoveOrder(VehicleID vehicle_id, uint32 order_id); /** * Changes the order flags of the given order. @@ -126,7 +126,7 @@ * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags). * @return true if and only if the order was changed. */ - bool ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrderFlags order_flags); + static bool ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrderFlags order_flags); /** * Move an order inside the orderlist @@ -141,7 +141,7 @@ * to a higher place (e.g. from 7 to 9) the target will be moved * downwards (e.g. 8). */ - bool MoveOrder(VehicleID vehicle_id, uint32 order_id_move, uint32 order_id_target); + static bool MoveOrder(VehicleID vehicle_id, uint32 order_id_move, uint32 order_id_target); /** * Copies the orders from another vehicle. The orders of the main @@ -152,7 +152,7 @@ * @pre AIVehicle::IsValidVehicle(main_vehicle_id). * @return true if and only if the copying succeeded. */ - bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); + static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); /** * Shares the orders between two vehicles. The orders of the main @@ -163,7 +163,7 @@ * @pre AIVehicle::IsValidVehicle(main_vehicle_id). * @return true if and only if the sharing succeeded. */ - bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); + static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); /** * Removes the given vehicle from a shared orders list. @@ -171,7 +171,7 @@ * @pre AIVehicle::IsValidVehicle(vehicle_id). * @return true if and only if the unsharing succeeded. */ - bool UnshareOrders(VehicleID vehicle_id); + static bool UnshareOrders(VehicleID vehicle_id); }; DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags); Index: src/ai/api/ai_marine.hpp =================================================================== --- src/ai/api/ai_marine.hpp (revision 12180) +++ src/ai/api/ai_marine.hpp (working copy) @@ -64,7 +64,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the water depot has been/can be build or not. */ - bool BuildWaterDepot(TileIndex tile, bool vertical); + static bool BuildWaterDepot(TileIndex tile, bool vertical); /** * Builds a dock where tile is the tile still on land. @@ -72,7 +72,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the dock has been/can be build or not. */ - bool BuildDock(TileIndex tile); + static bool BuildDock(TileIndex tile); /** * Builds a buoy on tile. @@ -80,7 +80,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the buoy has been/can be build or not. */ - bool BuildBuoy(TileIndex tile); + static bool BuildBuoy(TileIndex tile); /** * Builds a lock on tile. @@ -88,7 +88,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the lock has been/can be build or not. */ - bool BuildLock(TileIndex tile); + static bool BuildLock(TileIndex tile); /** * Builds a canal on tile. @@ -96,7 +96,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the canal has been/can be build or not. */ - bool BuildCanal(TileIndex tile); + static bool BuildCanal(TileIndex tile); /** * Removes a water depot. @@ -104,7 +104,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the water depot has been/can be removed or not. */ - bool RemoveWaterDepot(TileIndex tile); + static bool RemoveWaterDepot(TileIndex tile); /** * Removes a dock. @@ -112,7 +112,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the dock has been/can be removed or not. */ - bool RemoveDock(TileIndex tile); + static bool RemoveDock(TileIndex tile); /** * Removes a buoy. @@ -120,7 +120,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the buoy has been/can be removed or not. */ - bool RemoveBuoy(TileIndex tile); + static bool RemoveBuoy(TileIndex tile); /** * Removes a lock. @@ -128,7 +128,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the lock has been/can be removed or not. */ - bool RemoveLock(TileIndex tile); + static bool RemoveLock(TileIndex tile); /** * Removes a canal. @@ -136,7 +136,7 @@ * @pre tile is always positive and smaller than AIMap::GetMapSize(). * @return whether the canal has been/can be removed or not. */ - bool RemoveCanal(TileIndex tile); + static bool RemoveCanal(TileIndex tile); }; #endif /* AI_MARINE_HPP */ Index: src/ai/api/ai_cargo.cpp =================================================================== --- src/ai/api/ai_cargo.cpp (revision 12180) +++ src/ai/api/ai_cargo.cpp (working copy) @@ -15,7 +15,7 @@ char *AICargo::GetCargoLabel(CargoID cargo_type) { - if (!this->IsValidCargo(cargo_type)) return NULL; + if (!IsValidCargo(cargo_type)) return NULL; const CargoSpec *cargo = GetCargo(cargo_type); /* cargo->label is a uint32 packing a 4 character non-terminated string, @@ -30,13 +30,13 @@ bool AICargo::IsFreight(CargoID cargo_type) { - if (!this->IsValidCargo(cargo_type)) return false; + if (!IsValidCargo(cargo_type)) return false; const CargoSpec *cargo = GetCargo(cargo_type); return cargo->is_freight; } int32 AICargo::GetCargoIncome(uint32 distance, uint32 days_in_transit, CargoID cargo_type) { - if (!this->IsValidCargo(cargo_type)) return 0; + if (!IsValidCargo(cargo_type)) return 0; return GetTransportedGoodsIncome(1, distance, days_in_transit, cargo_type); } Index: src/ai/api/ai_company.hpp.sq =================================================================== --- src/ai/api/ai_company.hpp.sq (revision 12180) +++ src/ai/api/ai_company.hpp.sq (working copy) @@ -23,20 +23,19 @@ SQAICompany.DefSQConst(engine, AICompany::MY_COMPANY, "MY_COMPANY"); SQAICompany.DefSQConst(engine, AICompany::INVALID_COMPANY, "INVALID_COMPANY"); - SQAICompany.DefSQStaticMethod(engine, &AICompany::GetClassName, "GetClassName", 1, "x"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::GetClassName, "GetClassName", 1, "x"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::ResolveCompanyIndex, "ResolveCompanyIndex", 2, "xi"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::SetCompanyName, "SetCompanyName", 2, "xs"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::GetCompanyName, "GetCompanyName", 2, "xi"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentName, "SetPresidentName", 2, "xs"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentName, "GetPresidentName", 2, "xi"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::GetCompanyValue, "GetCompanyValue", 2, "xi"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::GetBankBalance, "GetBankBalance", 2, "xi"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::GetLoanAmount, "GetLoanAmount", 1, "x"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::GetMaxLoanAmount, "GetMaxLoanAmount", 1, "x"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::GetLoanInterval, "GetLoanInterval", 1, "x"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::SetLoanAmount, "SetLoanAmount", 2, "xi"); + SQAICompany.DefSQStaticMethod(engine, &AICompany::SetMinimumLoanAmount, "SetMinimumLoanAmount", 2, "xi"); - SQAICompany.DefSQMethod(engine, &AICompany::ResolveCompanyIndex, "ResolveCompanyIndex", 2, "xi"); - SQAICompany.DefSQMethod(engine, &AICompany::SetCompanyName, "SetCompanyName", 2, "xs"); - SQAICompany.DefSQMethod(engine, &AICompany::GetCompanyName, "GetCompanyName", 2, "xi"); - SQAICompany.DefSQMethod(engine, &AICompany::SetPresidentName, "SetPresidentName", 2, "xs"); - SQAICompany.DefSQMethod(engine, &AICompany::GetPresidentName, "GetPresidentName", 2, "xi"); - SQAICompany.DefSQMethod(engine, &AICompany::GetCompanyValue, "GetCompanyValue", 2, "xi"); - SQAICompany.DefSQMethod(engine, &AICompany::GetBankBalance, "GetBankBalance", 2, "xi"); - SQAICompany.DefSQMethod(engine, &AICompany::GetLoanAmount, "GetLoanAmount", 1, "x"); - SQAICompany.DefSQMethod(engine, &AICompany::GetMaxLoanAmount, "GetMaxLoanAmount", 1, "x"); - SQAICompany.DefSQMethod(engine, &AICompany::GetLoanInterval, "GetLoanInterval", 1, "x"); - SQAICompany.DefSQMethod(engine, &AICompany::SetLoanAmount, "SetLoanAmount", 2, "xi"); - SQAICompany.DefSQMethod(engine, &AICompany::SetMinimumLoanAmount, "SetMinimumLoanAmount", 2, "xi"); - SQAICompany.PostRegister(engine); } Index: src/ai/api/ai_tile.cpp =================================================================== --- src/ai/api/ai_tile.cpp (revision 12180) +++ src/ai/api/ai_tile.cpp (working copy) @@ -9,6 +9,8 @@ #include "../../station.h" #include "../../command_type.h" #include "../../settings_type.h" +#include "../../industry.h" +#include "../../industry_map.h" bool AITile::IsBuildable(TileIndex tile) { @@ -50,32 +52,42 @@ return ::TileHeight(tile); } -int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad) +bool AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad) { /* Outside of the map */ if (tile >= ::MapSize()) return 0; AcceptedCargo accepts; GetAcceptanceAroundTiles(accepts, tile, width, height, _patches.modified_catchment ? rad : 4); - return accepts[cargo_type]; + + // Value below indicate the cargo is NOT accepted + return accepts[cargo_type] >= 8; } -int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad) +bool AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad) { /* Outside of the map */ if (tile >= ::MapSize()) return 0; AcceptedCargo produced; GetProductionAroundTiles(produced, tile, width, height, _patches.modified_catchment ? rad : 4); - return produced[cargo_type]; + return produced[cargo_type] > 0; } + +IndustryID AITile::GetIndustry(TileIndex tile) +{ + if(!IsTileType(tile, MP_INDUSTRY)) + return INVALID_INDUSTRY; + return GetIndustryIndex(tile); +} + bool AITile::RaiseTile(TileIndex tile, int32 slope) { /* Outside of the map */ if (tile >= ::MapSize()) return false; - return this->DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND); + return DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND); } bool AITile::LowerTile(TileIndex tile, int32 slope) @@ -83,5 +95,5 @@ /* Outside of the map */ if (tile >= ::MapSize()) return false; - return this->DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND); + return DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND); } Index: src/ai/api/ai_sign.cpp =================================================================== --- src/ai/api/ai_sign.cpp (revision 12180) +++ src/ai/api/ai_sign.cpp (working copy) @@ -48,7 +48,7 @@ bool AISign::RemoveSign(SignID sign_id) { _cmd_text = ""; - return this->DoCommand(0, sign_id, 0, CMD_RENAME_SIGN); + return DoCommand(0, sign_id, 0, CMD_RENAME_SIGN); } SignID AISign::BuildSign(TileIndex location, const char *text) @@ -58,14 +58,14 @@ /* Reset the internal NewSignID in case we are in TestMode */ AIObject::SetNewSignID(0); - bool ret = this->DoCommand(location, 0, 0, CMD_PLACE_SIGN); + bool ret = DoCommand(location, 0, 0, CMD_PLACE_SIGN); if (!ret) return INVALID_SIGN; SignID new_sign_id = AIObject::GetNewSignID(); _cmd_text = text; - ret = this->DoCommand(0, new_sign_id, 0, CMD_RENAME_SIGN); + ret = DoCommand(0, new_sign_id, 0, CMD_RENAME_SIGN); if (!ret) { - this->RemoveSign(new_sign_id); + RemoveSign(new_sign_id); return INVALID_SIGN; } return new_sign_id; Index: src/ai/api/ai_marine.hpp.sq =================================================================== --- src/ai/api/ai_marine.hpp.sq (revision 12180) +++ src/ai/api/ai_marine.hpp.sq (working copy) @@ -20,17 +20,16 @@ SQAIMarine.DefSQStaticMethod(engine, &AIMarine::IsBuoyTile, "IsBuoyTile", 2, "xi"); SQAIMarine.DefSQStaticMethod(engine, &AIMarine::IsLockTile, "IsLockTile", 2, "xi"); SQAIMarine.DefSQStaticMethod(engine, &AIMarine::IsCanalTile, "IsCanalTile", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::BuildWaterDepot, "BuildWaterDepot", 3, "xib"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::BuildDock, "BuildDock", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::BuildBuoy, "BuildBuoy", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::BuildLock, "BuildLock", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::BuildCanal, "BuildCanal", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::RemoveWaterDepot, "RemoveWaterDepot", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::RemoveDock, "RemoveDock", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::RemoveBuoy, "RemoveBuoy", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::RemoveLock, "RemoveLock", 2, "xi"); + SQAIMarine.DefSQStaticMethod(engine, &AIMarine::RemoveCanal, "RemoveCanal", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::BuildWaterDepot, "BuildWaterDepot", 3, "xib"); - SQAIMarine.DefSQMethod(engine, &AIMarine::BuildDock, "BuildDock", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::BuildBuoy, "BuildBuoy", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::BuildLock, "BuildLock", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::BuildCanal, "BuildCanal", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::RemoveWaterDepot, "RemoveWaterDepot", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::RemoveDock, "RemoveDock", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::RemoveBuoy, "RemoveBuoy", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::RemoveLock, "RemoveLock", 2, "xi"); - SQAIMarine.DefSQMethod(engine, &AIMarine::RemoveCanal, "RemoveCanal", 2, "xi"); - SQAIMarine.PostRegister(engine); } Index: src/ai/api/ai_order.hpp.sq =================================================================== --- src/ai/api/ai_order.hpp.sq (revision 12180) +++ src/ai/api/ai_order.hpp.sq (working copy) @@ -29,18 +29,17 @@ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetClassName, "GetClassName", 1, "x"); SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsValidVehicleOrder, "IsValidVehicleOrder", 3, "xii"); SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AreOrderFlagsValid, "AreOrderFlagsValid", 3, "xii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetNumberOfOrders, "GetNumberOfOrders", 2, "xi"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetOrderDestination, "GetOrderDestination", 3, "xii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetOrderFlags, "GetOrderFlags", 3, "xii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AppendOrder, "AppendOrder", 4, "xiii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::InsertOrder, "InsertOrder", 5, "xiiii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::RemoveOrder, "RemoveOrder", 3, "xii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ChangeOrder, "ChangeOrder", 4, "xiii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::MoveOrder, "MoveOrder", 4, "xiii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::CopyOrders, "CopyOrders", 3, "xii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ShareOrders, "ShareOrders", 3, "xii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::UnshareOrders, "UnshareOrders", 2, "xi"); - SQAIOrder.DefSQMethod(engine, &AIOrder::GetNumberOfOrders, "GetNumberOfOrders", 2, "xi"); - SQAIOrder.DefSQMethod(engine, &AIOrder::GetOrderDestination, "GetOrderDestination", 3, "xii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::GetOrderFlags, "GetOrderFlags", 3, "xii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::AppendOrder, "AppendOrder", 4, "xiii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::InsertOrder, "InsertOrder", 5, "xiiii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::RemoveOrder, "RemoveOrder", 3, "xii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::ChangeOrder, "ChangeOrder", 4, "xiii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::MoveOrder, "MoveOrder", 4, "xiii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::CopyOrders, "CopyOrders", 3, "xii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::ShareOrders, "ShareOrders", 3, "xii"); - SQAIOrder.DefSQMethod(engine, &AIOrder::UnshareOrders, "UnshareOrders", 2, "xi"); - SQAIOrder.PostRegister(engine); } Index: src/ai/api/ai_engine.cpp =================================================================== --- src/ai/api/ai_engine.cpp (revision 12180) +++ src/ai/api/ai_engine.cpp (working copy) @@ -151,6 +151,20 @@ } } +/* static */ int32 AIEngine::GetMaxAge(EngineID engine_id) +{ + if(!AIEngine::IsValidEngine(engine_id)) return -1; + + return ::GetEngine(engine_id)->lifelength * 366; +} + +/* static*/ Money AIEngine::GetRunningCost(EngineID engine_id) +{ + if(!AIEngine::IsValidEngine(engine_id)) return -1; + + return RoadVehInfo(engine_id)->running_cost * _price.roadveh_running; +} + /* static */ AIVehicle::VehicleType AIEngine::GetVehicleType(EngineID engine_id) { if (!AIEngine::IsValidEngine(engine_id)) return AIVehicle::VEHICLE_INVALID; Index: src/ai/api/ai_company.cpp =================================================================== --- src/ai/api/ai_company.cpp (revision 12180) +++ src/ai/api/ai_company.cpp (working copy) @@ -24,12 +24,12 @@ if (name == NULL) return false; _cmd_text = name; - return this->DoCommand(0, 0, 0, CMD_CHANGE_COMPANY_NAME); + return DoCommand(0, 0, 0, CMD_CHANGE_COMPANY_NAME); } char *AICompany::GetCompanyName(AICompany::CompanyIndex company) { - company = this->ResolveCompanyIndex(company); + company = ResolveCompanyIndex(company); if (company == INVALID_COMPANY) return NULL; static const int len = 64; @@ -45,12 +45,12 @@ if (name == NULL) return false; _cmd_text = name; - return this->DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME); + return DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME); } char *AICompany::GetPresidentName(AICompany::CompanyIndex company) { - company = this->ResolveCompanyIndex(company); + company = ResolveCompanyIndex(company); static const int len = 64; char *president_name = MallocT(len); @@ -66,7 +66,7 @@ int32 AICompany::GetCompanyValue(AICompany::CompanyIndex company) { - company = this->ResolveCompanyIndex(company); + company = ResolveCompanyIndex(company); if (company == INVALID_COMPANY) return 0; return GetPlayer((PlayerID)company)->cur_economy.company_value; @@ -74,7 +74,7 @@ int32 AICompany::GetBankBalance(AICompany::CompanyIndex company) { - company = this->ResolveCompanyIndex(company); + company = ResolveCompanyIndex(company); if (company == INVALID_COMPANY) return 0; return ClampToI32(GetPlayer((PlayerID)company)->player_money); @@ -98,29 +98,29 @@ bool AICompany::SetLoanAmount(int32 loan) { if (loan < 0 || - (loan % this->GetLoanInterval()) != 0 || - loan > this->GetMaxLoanAmount() || - (loan - this->GetLoanAmount() + this->GetBankBalance(MY_COMPANY)) < 0) { + (loan % GetLoanInterval()) != 0 || + loan > GetMaxLoanAmount() || + (loan - GetLoanAmount() + GetBankBalance(MY_COMPANY)) < 0) { return false; } - if (loan == this->GetLoanAmount()) return true; + if (loan == GetLoanAmount()) return true; - return this->DoCommand(0, - abs(loan - this->GetLoanAmount()), 2, - (loan > this->GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN); + return DoCommand(0, + abs(loan - GetLoanAmount()), 2, + (loan > GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN); } bool AICompany::SetMinimumLoanAmount(int32 loan) { if (loan < 0) return false; - int32 over_interval = loan % this->GetLoanInterval(); - if (over_interval != 0) loan += this->GetLoanInterval() - over_interval; + int32 over_interval = loan % GetLoanInterval(); + if (over_interval != 0) loan += GetLoanInterval() - over_interval; - if (loan > this->GetMaxLoanAmount()) return false; + if (loan > GetMaxLoanAmount()) return false; - this->SetLoanAmount(loan); + SetLoanAmount(loan); - return this->GetLoanAmount() == loan; + return GetLoanAmount() == loan; } Index: src/ai/api/ai_airport.hpp.sq =================================================================== --- src/ai/api/ai_airport.hpp.sq (revision 12180) +++ src/ai/api/ai_airport.hpp.sq (working copy) @@ -35,10 +35,9 @@ SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportWidth, "GetAirportWidth", 2, "xi"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportHeight, "GetAirportHeight", 2, "xi"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportCoverageRadius, "GetAirportCoverageRadius", 2, "xi"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::BuildAirport, "BuildAirport", 3, "xii"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::RemoveAirport, "RemoveAirport", 2, "xi"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetHangarOfAirport, "GetHangarOfAirport", 2, "xi"); - SQAIAirport.DefSQMethod(engine, &AIAirport::BuildAirport, "BuildAirport", 3, "xii"); - SQAIAirport.DefSQMethod(engine, &AIAirport::RemoveAirport, "RemoveAirport", 2, "xi"); - SQAIAirport.DefSQMethod(engine, &AIAirport::GetHangarOfAirport, "GetHangarOfAirport", 2, "xi"); - SQAIAirport.PostRegister(engine); } Index: src/ai/api/ai_map.cpp =================================================================== --- src/ai/api/ai_map.cpp (revision 12180) +++ src/ai/api/ai_map.cpp (working copy) @@ -63,5 +63,5 @@ bool AIMap::DemolishTile(TileIndex t) { - return this->DoCommand(t, 0, 0, CMD_LANDSCAPE_CLEAR); + return DoCommand(t, 0, 0, CMD_LANDSCAPE_CLEAR); } Index: src/ai/api/ai_vehicle.cpp =================================================================== --- src/ai/api/ai_vehicle.cpp (revision 12180) +++ src/ai/api/ai_vehicle.cpp (working copy) @@ -13,6 +13,8 @@ #include "../../aircraft.h" #include "../../strings_func.h" #include "../../core/alloc_func.hpp" +#include "../../command_type.h" +#include "../../command_func.h" #include "table/strings.h" /* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id) @@ -29,10 +31,10 @@ bool ret; switch (::GetEngine(engine_id)->type) { - case VEH_ROAD: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_ROAD_VEH); break; - case VEH_TRAIN: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_RAIL_VEHICLE); break; - case VEH_SHIP: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_SHIP); break; - case VEH_AIRCRAFT: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_AIRCRAFT); break; + case VEH_ROAD: ret = DoCommand(depot, engine_id, 0, CMD_BUILD_ROAD_VEH); break; + case VEH_TRAIN: ret = DoCommand(depot, engine_id, 0, CMD_BUILD_RAIL_VEHICLE); break; + case VEH_SHIP: ret = DoCommand(depot, engine_id, 0, CMD_BUILD_SHIP); break; + case VEH_AIRCRAFT: ret = DoCommand(depot, engine_id, 0, CMD_BUILD_AIRCRAFT); break; default: NOT_REACHED(); return INVALID_VEHICLE; } @@ -41,24 +43,24 @@ VehicleID AIVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; /* Reset the internal NewVehicleID in case we are in TestMode */ AIObject::SetNewVehicleID(0); - bool ret = this->DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE); + bool ret = DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE); return ret ? AIObject::GetNewVehicleID() : INVALID_VEHICLE; } bool AIVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo) { - if (!this->IsValidVehicle(vehicle_id) || !AICargo::IsValidCargo(cargo)) return false; + if (!IsValidVehicle(vehicle_id) || !AICargo::IsValidCargo(cargo)) return false; switch (::GetVehicle(vehicle_id)->type) { - case VEH_ROAD: return this->DoCommand(0, vehicle_id, cargo, CMD_REFIT_ROAD_VEH); - case VEH_TRAIN: return this->DoCommand(0, vehicle_id, cargo, CMD_REFIT_RAIL_VEHICLE); - case VEH_SHIP: return this->DoCommand(0, vehicle_id, cargo, CMD_REFIT_SHIP); - case VEH_AIRCRAFT: return this->DoCommand(0, vehicle_id, cargo, CMD_REFIT_AIRCRAFT); + case VEH_ROAD: return DoCommand(0, vehicle_id, cargo, CMD_REFIT_ROAD_VEH); + case VEH_TRAIN: return DoCommand(0, vehicle_id, cargo, CMD_REFIT_RAIL_VEHICLE); + case VEH_SHIP: return DoCommand(0, vehicle_id, cargo, CMD_REFIT_SHIP); + case VEH_AIRCRAFT: return DoCommand(0, vehicle_id, cargo, CMD_REFIT_AIRCRAFT); default: return false; } } @@ -66,51 +68,51 @@ bool AIVehicle::SellVehicle(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; switch (::GetVehicle(vehicle_id)->type) { - case VEH_ROAD: return this->DoCommand(0, vehicle_id, 0, CMD_SELL_ROAD_VEH); - case VEH_TRAIN: return this->DoCommand(0, vehicle_id, 0, CMD_SELL_RAIL_WAGON); - case VEH_SHIP: return this->DoCommand(0, vehicle_id, 0, CMD_SELL_SHIP); - case VEH_AIRCRAFT: return this->DoCommand(0, vehicle_id, 0, CMD_SELL_AIRCRAFT); + case VEH_ROAD: return DoCommand(0, vehicle_id, 0, CMD_SELL_ROAD_VEH); + case VEH_TRAIN: return DoCommand(0, vehicle_id, 0, CMD_SELL_RAIL_WAGON); + case VEH_SHIP: return DoCommand(0, vehicle_id, 0, CMD_SELL_SHIP); + case VEH_AIRCRAFT: return DoCommand(0, vehicle_id, 0, CMD_SELL_AIRCRAFT); default: return false; } } bool AIVehicle::SendVehicleToDepot(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; switch (::GetVehicle(vehicle_id)->type) { - case VEH_ROAD: return this->DoCommand(0, vehicle_id, 0, CMD_SEND_ROADVEH_TO_DEPOT); - case VEH_TRAIN: return this->DoCommand(0, vehicle_id, 0, CMD_SEND_TRAIN_TO_DEPOT); - case VEH_SHIP: return this->DoCommand(0, vehicle_id, 0, CMD_SEND_SHIP_TO_DEPOT); - case VEH_AIRCRAFT: return this->DoCommand(0, vehicle_id, 0, CMD_SEND_AIRCRAFT_TO_HANGAR); + case VEH_ROAD: return DoCommand(0, vehicle_id, 0, CMD_SEND_ROADVEH_TO_DEPOT); + case VEH_TRAIN: return DoCommand(0, vehicle_id, 0, CMD_SEND_TRAIN_TO_DEPOT); + case VEH_SHIP: return DoCommand(0, vehicle_id, 0, CMD_SEND_SHIP_TO_DEPOT); + case VEH_AIRCRAFT: return DoCommand(0, vehicle_id, 0, CMD_SEND_AIRCRAFT_TO_HANGAR); default: return false; } } bool AIVehicle::IsInDepot(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; return ::GetVehicle(vehicle_id)->IsInDepot(); } bool AIVehicle::IsStoppedInDepot(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; return ::GetVehicle(vehicle_id)->IsStoppedInDepot(); } bool AIVehicle::StartStopVehicle(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; switch (::GetVehicle(vehicle_id)->type) { - case VEH_ROAD: return this->DoCommand(0, vehicle_id, 0, CMD_START_STOP_ROADVEH); - case VEH_TRAIN: return this->DoCommand(0, vehicle_id, 0, CMD_START_STOP_TRAIN); - case VEH_SHIP: return this->DoCommand(0, vehicle_id, 0, CMD_START_STOP_SHIP); - case VEH_AIRCRAFT: return this->DoCommand(0, vehicle_id, 0, CMD_START_STOP_AIRCRAFT); + case VEH_ROAD: return DoCommand(0, vehicle_id, 0, CMD_START_STOP_ROADVEH); + case VEH_TRAIN: return DoCommand(0, vehicle_id, 0, CMD_START_STOP_TRAIN); + case VEH_SHIP: return DoCommand(0, vehicle_id, 0, CMD_START_STOP_SHIP); + case VEH_AIRCRAFT: return DoCommand(0, vehicle_id, 0, CMD_START_STOP_AIRCRAFT); default: return false; } } @@ -119,16 +121,16 @@ { if (!AIOrder::IsValidVehicleOrder(vehicle_id, order_id)) return false; - return this->DoCommand(0, vehicle_id, order_id, CMD_SKIP_TO_ORDER); + return DoCommand(0, vehicle_id, order_id, CMD_SKIP_TO_ORDER); } bool AIVehicle::SetName(VehicleID vehicle_id, const char *name) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; if (name == NULL) return false; _cmd_text = name; - return this->DoCommand(0, vehicle_id, 0, CMD_NAME_VEHICLE); + return DoCommand(0, vehicle_id, 0, CMD_NAME_VEHICLE); } /* static */ TileIndex AIVehicle::GetLocation(VehicleID vehicle_id) @@ -211,3 +213,4 @@ default: return VEHICLE_INVALID; } } + Index: src/ai/api/ai_tile.hpp.sq =================================================================== --- src/ai/api/ai_tile.hpp.sq (revision 12180) +++ src/ai/api/ai_tile.hpp.sq (working copy) @@ -47,9 +47,9 @@ SQAITile.DefSQStaticMethod(engine, &AITile::GetHeight, "GetHeight", 2, "xi"); SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoAcceptance, "GetCargoAcceptance", 6, "xiiiii"); SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoProduction, "GetCargoProduction", 6, "xiiiii"); + SQAITile.DefSQStaticMethod(engine, &AITile::GetIndustry, "GetIndustry", 2, "xi"); + SQAITile.DefSQStaticMethod(engine, &AITile::RaiseTile, "RaiseTile", 3, "xii"); + SQAITile.DefSQStaticMethod(engine, &AITile::LowerTile, "LowerTile", 3, "xii"); - SQAITile.DefSQMethod(engine, &AITile::RaiseTile, "RaiseTile", 3, "xii"); - SQAITile.DefSQMethod(engine, &AITile::LowerTile, "LowerTile", 3, "xii"); - SQAITile.PostRegister(engine); }