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 newgrf_generic.h Functions related to generic callbacks. */
9 
10 #ifndef NEWGRF_GENERIC_H
11 #define NEWGRF_GENERIC_H
12 
13 #include "industry_type.h"
14 #include "newgrf.h"
15 #include "tile_type.h"
16 
17 struct SpriteGroup;
18 
19 /** AI events for asking the NewGRF for information. */
20 enum AIConstructionEvent {
21 	AICE_TRAIN_CHECK_RAIL_ENGINE     = 0x00, ///< Check if we should build an engine
22 	AICE_TRAIN_CHECK_ELRAIL_ENGINE   = 0x01, ///< Check if we should build an engine
23 	AICE_TRAIN_CHECK_MONORAIL_ENGINE = 0x02, ///< Check if we should build an engine
24 	AICE_TRAIN_CHECK_MAGLEV_ENGINE   = 0x03, ///< Check if we should build an engine
25 	AICE_TRAIN_GET_RAIL_WAGON        = 0x08, ///< Check if we should build an engine
26 	AICE_TRAIN_GET_ELRAIL_WAGON      = 0x09, ///< Check if we should build an engine
27 	AICE_TRAIN_GET_MONORAIL_WAGON    = 0x0A, ///< Check if we should build an engine
28 	AICE_TRAIN_GET_MAGLEV_WAGON      = 0x0B, ///< Check if we should build an engine
29 	AICE_TRAIN_GET_RAILTYPE          = 0x0F, ///< Check if we should build a railtype
30 
31 	AICE_ROAD_CHECK_ENGINE           = 0x00, ///< Check if we should build an engine
32 	AICE_ROAD_GET_FIRST_ENGINE       = 0x01, ///< Unused, we check all
33 	AICE_ROAD_GET_NUMBER_ENGINES     = 0x02, ///< Unused, we check all
34 
35 	AICE_SHIP_CHECK_ENGINE           = 0x00, ///< Check if we should build an engine
36 	AICE_SHIP_GET_FIRST_ENGINE       = 0x01, ///< Unused, we check all
37 	AICE_SHIP_GET_NUMBER_ENGINES     = 0x02, ///< Unused, we check all
38 
39 	AICE_AIRCRAFT_CHECK_ENGINE       = 0x00, ///< Check if we should build an engine
40 
41 	AICE_STATION_GET_STATION_ID      = 0x00, ///< Get a station ID to build
42 };
43 
44 static const IndustryType IT_AI_UNKNOWN = 0xFE; ///< The AI has no specific industry in mind.
45 static const IndustryType IT_AI_TOWN    = 0xFF; ///< The AI actually wants to transport to/from a town, not an industry.
46 
47 void ResetGenericCallbacks();
48 void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *group);
49 
50 uint16 GetAiPurchaseCallbackResult(uint8 feature, CargoID cargo_type, uint8 default_selection, IndustryType src_industry, IndustryType dst_industry, uint8 distance, AIConstructionEvent event, uint8 count, uint8 station_size, const GRFFile **file);
51 
52 /** Play an ambient sound effect for an empty tile. */
AmbientSoundEffect(TileIndex tile)53 static inline void AmbientSoundEffect(TileIndex tile)
54 {
55 	/* Only run callback if enabled. */
56 	if (!HasGrfMiscBit(GMB_AMBIENT_SOUND_CALLBACK)) return;
57 
58 	extern void AmbientSoundEffectCallback(TileIndex tile);
59 	AmbientSoundEffectCallback(tile);
60 }
61 
62 #endif /* NEWGRF_GENERIC_H */
63