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 */ 7 8 /** @file script_industry.hpp Everything to query and build industries. */ 9 10 #ifndef SCRIPT_INDUSTRY_HPP 11 #define SCRIPT_INDUSTRY_HPP 12 13 #include "script_company.hpp" 14 #include "script_date.hpp" 15 #include "script_object.hpp" 16 #include "../../industry.h" 17 18 /** 19 * Class that handles all industry related functions. 20 * @api ai game 21 */ 22 class ScriptIndustry : public ScriptObject { 23 public: 24 /** Ways for an industry to accept a cargo. */ 25 enum CargoAcceptState { 26 CAS_NOT_ACCEPTED, ///< The CargoID is not accepted by this industry. 27 CAS_ACCEPTED, ///< The industry currently accepts this CargoID. 28 CAS_TEMP_REFUSED, ///< The industry temporarily refuses to accept this CargoID but may do so again in the future. 29 }; 30 31 /** 32 * Control flags for industry 33 * @api -ai 34 */ 35 enum IndustryControlFlags { 36 /** 37 * When industry production change is evaluated, rolls to decrease are ignored. 38 * This also prevents industry closure due to production dropping to the lowest level. 39 */ 40 INDCTL_NO_PRODUCTION_DECREASE = ::INDCTL_NO_PRODUCTION_DECREASE, 41 /** 42 * When industry production change is evaluated, rolls to increase are ignored. 43 */ 44 INDCTL_NO_PRODUCTION_INCREASE = ::INDCTL_NO_PRODUCTION_INCREASE, 45 /** 46 * Industry can not close regardless of production level or time since last delivery. 47 * This does not prevent a closure already announced. 48 */ 49 INDCTL_NO_CLOSURE = ::INDCTL_NO_CLOSURE, 50 }; 51 52 /** 53 * Gets the number of industries. 54 * @return The number of industries. 55 * @note The maximum valid IndustryID can be higher than the value returned. 56 */ 57 static int32 GetIndustryCount(); 58 59 /** 60 * Checks whether the given industry index is valid. 61 * @param industry_id The index to check. 62 * @return True if and only if the industry is valid. 63 */ 64 static bool IsValidIndustry(IndustryID industry_id); 65 66 /** 67 * Get the IndustryID of a tile, if there is an industry. 68 * @param tile The tile to find the IndustryID of. 69 * @return IndustryID of the industry. 70 * @post Use IsValidIndustry() to see if the industry is valid. 71 * @note GetIndustryID will return an invalid IndustryID for the 72 * station tile of industries with a dock/heliport. 73 */ 74 static IndustryID GetIndustryID(TileIndex tile); 75 76 /** 77 * Get the name of the industry. 78 * @param industry_id The industry to get the name of. 79 * @pre IsValidIndustry(industry_id). 80 * @return The name of the industry. 81 */ 82 static char *GetName(IndustryID industry_id); 83 84 /** 85 * Set the custom text of an industry, shown in the GUI. 86 * @param industry_id The industry to set the custom text of. 87 * @param text The text to set it to (can be either a raw string, or a ScriptText object). If null is passed, the text will be removed. 88 * @pre IsValidIndustry(industry_id). 89 * @return True if the action succeeded. 90 * @api -ai 91 */ 92 static bool SetText(IndustryID industry_id, Text *text); 93 94 /** 95 * See whether an industry currently accepts a certain cargo. 96 * @param industry_id The index of the industry. 97 * @param cargo_id The index of the cargo. 98 * @pre IsValidIndustry(industry_id). 99 * @pre ScriptCargo::IsValidCargo(cargo_id). 100 * @return Whether the industry accepts, temporarily refuses or never accepts this cargo. 101 */ 102 static CargoAcceptState IsCargoAccepted(IndustryID industry_id, CargoID cargo_id); 103 104 /** 105 * Get the amount of cargo stockpiled for processing. 106 * @param industry_id The index of the industry. 107 * @param cargo_id The index of the cargo. 108 * @pre IsValidIndustry(industry_id). 109 * @pre ScriptCargo::IsValidCargo(cargo_id). 110 * @return The amount of cargo that is waiting for processing. 111 */ 112 static int32 GetStockpiledCargo(IndustryID industry_id, CargoID cargo_id); 113 114 /** 115 * Get the total last month's production of the given cargo at an industry. 116 * @param industry_id The index of the industry. 117 * @param cargo_id The index of the cargo. 118 * @pre IsValidIndustry(industry_id). 119 * @pre ScriptCargo::IsValidCargo(cargo_id). 120 * @return The last month's production of the given cargo for this industry. 121 */ 122 static int32 GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id); 123 124 /** 125 * Get the total amount of cargo transported from an industry last month. 126 * @param industry_id The index of the industry. 127 * @param cargo_id The index of the cargo. 128 * @pre IsValidIndustry(industry_id). 129 * @pre ScriptCargo::IsValidCargo(cargo_id). 130 * @return The amount of given cargo transported from this industry last month. 131 */ 132 static int32 GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id); 133 134 /** 135 * Get the percentage of cargo transported from an industry last month. 136 * @param industry_id The index of the industry. 137 * @param cargo_id The index of the cargo. 138 * @pre IsValidIndustry(industry_id). 139 * @pre ScriptCargo::IsValidCargo(cargo_id). 140 * @return The percentage of given cargo transported from this industry last month. 141 */ 142 static int32 GetLastMonthTransportedPercentage(IndustryID industry_id, CargoID cargo_id); 143 144 /** 145 * Gets the location of the industry. 146 * @param industry_id The index of the industry. 147 * @pre IsValidIndustry(industry_id). 148 * @return The location of the industry. 149 */ 150 static TileIndex GetLocation(IndustryID industry_id); 151 152 /** 153 * Get the number of stations around an industry. All stations that can 154 * service the industry are counted, your own stations but also your 155 * opponents stations. 156 * @param industry_id The index of the industry. 157 * @pre IsValidIndustry(industry_id). 158 * @return The number of stations around an industry. 159 */ 160 static int32 GetAmountOfStationsAround(IndustryID industry_id); 161 162 /** 163 * Get the manhattan distance from the tile to the ScriptIndustry::GetLocation() 164 * of the industry. 165 * @param industry_id The industry to get the distance to. 166 * @param tile The tile to get the distance to. 167 * @pre IsValidIndustry(industry_id). 168 * @pre ScriptMap::IsValidTile(tile). 169 * @return The distance between industry and tile. 170 */ 171 static int32 GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile); 172 173 /** 174 * Get the square distance from the tile to the ScriptIndustry::GetLocation() 175 * of the industry. 176 * @param industry_id The industry to get the distance to. 177 * @param tile The tile to get the distance to. 178 * @pre IsValidIndustry(industry_id). 179 * @pre ScriptMap::IsValidTile(tile). 180 * @return The distance between industry and tile. 181 */ 182 static int32 GetDistanceSquareToTile(IndustryID industry_id, TileIndex tile); 183 184 /** 185 * Is this industry built on water. 186 * @param industry_id The index of the industry. 187 * @pre IsValidIndustry(industry_id). 188 * @return True when the industry is built on water. 189 */ 190 static bool IsBuiltOnWater(IndustryID industry_id); 191 192 /** 193 * Does this industry have a heliport? 194 * @param industry_id The index of the industry. 195 * @pre IsValidIndustry(industry_id). 196 * @return True when the industry has a heliport. 197 */ 198 static bool HasHeliport(IndustryID industry_id); 199 200 /** 201 * Gets the location of the industry's heliport. 202 * @param industry_id The index of the industry. 203 * @pre IsValidIndustry(industry_id). 204 * @pre HasHeliport(industry_id). 205 * @return The location of the industry's heliport. 206 */ 207 static TileIndex GetHeliportLocation(IndustryID industry_id); 208 209 /** 210 * Does this industry have a dock? 211 * @param industry_id The index of the industry. 212 * @pre IsValidIndustry(industry_id). 213 * @return True when the industry has a dock. 214 */ 215 static bool HasDock(IndustryID industry_id); 216 217 /** 218 * Gets the location of the industry's dock. 219 * @param industry_id The index of the industry. 220 * @pre IsValidIndustry(industry_id). 221 * @pre HasDock(industry_id). 222 * @return The location of the industry's dock. 223 */ 224 static TileIndex GetDockLocation(IndustryID industry_id); 225 226 /** 227 * Get the IndustryType of the industry. 228 * @param industry_id The index of the industry. 229 * @pre IsValidIndustry(industry_id). 230 * @return The IndustryType of the industry. 231 */ 232 static IndustryType GetIndustryType(IndustryID industry_id); 233 234 /** 235 * Get the last year this industry had any production output. 236 * @param industry_id The index of the industry. 237 * @pre IsValidIndustry(industry_id). 238 * @return Year the industry last had production, 0 if error. 239 * @api -ai 240 */ 241 static int32 GetLastProductionYear(IndustryID industry_id); 242 243 /** 244 * Get the last date this industry accepted any cargo delivery. 245 * @param industry_id The index of the industry. 246 * @param cargo_type The cargo to query, or CT_INVALID to query latest of all accepted cargoes. 247 * @pre IsValidIndustry(industry_id). 248 * @pre IsValidCargo(cargo_type) || cargo_type == CT_INVALID. 249 * @return Date the industry last received cargo from a delivery, or ScriptDate::DATE_INVALID on error. 250 * @api -ai 251 */ 252 static ScriptDate::Date GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type); 253 254 /** 255 * Get the current control flags for an industry. 256 * @param industry_id The index of the industry. 257 * @pre IsValidIndustry(industry_id). 258 * @return Bit flags of the IndustryControlFlags enumeration. 259 * @api -ai 260 */ 261 static uint32 GetControlFlags(IndustryID industry_id); 262 263 /** 264 * Change the control flags for an industry. 265 * @param industry_id The index of the industry. 266 * @param control_flags New flags as a combination of IndustryControlFlags values. 267 * @pre IsValidIndustry(industry_id). 268 * @pre No ScriptCompanyMode may be in scope. 269 * @return True if the action succeeded. 270 * @api -ai 271 */ 272 static bool SetControlFlags(IndustryID industry_id, uint32 control_flags); 273 274 /** 275 * Find out which company currently has the exclusive rights to deliver cargo to the industry. 276 * @param industry_id The index of the industry. 277 * @pre IsValidIndustry(industry_id). 278 * @return The company that has the exclusive rights. The value 279 * ScriptCompany::COMPANY_INVALID means that there are currently no 280 * exclusive rights given out to anyone. 281 */ 282 static ScriptCompany::CompanyID GetExclusiveSupplier(IndustryID industry_id); 283 284 /** 285 * Sets or resets the company that has exclusive right to deliver cargo to the industry. 286 * @param industry_id The index of the industry. 287 * @param company_id The company to set (ScriptCompany::COMPANY_INVALID to reset). 288 * @pre IsValidIndustry(industry_id). 289 * @return True if the action succeeded. 290 * @api -ai 291 */ 292 static bool SetExclusiveSupplier(IndustryID industry_id, ScriptCompany::CompanyID company_id); 293 294 /** 295 * Find out which company currently has the exclusive rights to take cargo from the industry. 296 * @param industry_id The index of the industry. 297 * @pre IsValidIndustry(industry_id). 298 * @return The company that has the exclusive rights. The value 299 * ScriptCompany::COMPANY_SPECTATOR means that there are currently no 300 * exclusive rights given out to anyone. 301 */ 302 static ScriptCompany::CompanyID GetExclusiveConsumer(IndustryID industry_id); 303 304 /** 305 * Sets or resets the company that has exclusive right to take cargo from the industry. 306 * @param industry_id The index of the industry. 307 * @param company_id The company to set (ScriptCompany::COMPANY_INVALID to reset). 308 * @pre IsValidIndustry(industry_id). 309 * @return True if the action succeeded. 310 * @api -ai 311 */ 312 static bool SetExclusiveConsumer(IndustryID industry_id, ScriptCompany::CompanyID company_id); 313 314 }; 315 316 #endif /* SCRIPT_INDUSTRY_HPP */ 317