9624
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
/** @file newgrf_commons.h This file simplyfies and embeds a common mechanism of
|
|
4 |
* loading/saving and mapping of grf entities.
|
|
5 |
*/
|
|
6 |
|
|
7 |
#ifndef NEWGRF_COMMONS_H
|
|
8 |
#define NEWGRF_COMMONS_H
|
|
9 |
|
|
10 |
/**
|
|
11 |
* Maps an entity id stored on the map to a GRF file.
|
|
12 |
* Entities are objects used ingame (houses, industries, industry tiles) for
|
|
13 |
* which we need to correlate the ids from the grf files with the ones in the
|
|
14 |
* the savegames themselves.
|
|
15 |
* An array of EntityIDMapping structs is saved with the savegame so
|
|
16 |
* that those GRFs can be loaded in a different order, or removed safely. The
|
|
17 |
* index in the array is the entity's ID stored on the map.
|
|
18 |
*
|
|
19 |
* The substitute ID is the ID of an original entity that should be used instead
|
|
20 |
* if the GRF containing the new entity is not available.
|
|
21 |
*/
|
|
22 |
struct EntityIDMapping {
|
|
23 |
uint32 grfid; ///< The GRF ID of the file the entity belongs to
|
|
24 |
uint8 entity_id; ///< The entity ID within the GRF file
|
|
25 |
uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available
|
|
26 |
};
|
|
27 |
|
|
28 |
class OverrideManagerBase
|
|
29 |
{
|
|
30 |
protected:
|
|
31 |
uint16 *entity_overrides;
|
|
32 |
|
|
33 |
uint16 max_offset; ///< what is the length of the original entity's array of specs
|
|
34 |
uint16 max_new_entities; ///< what is the amount of entities, old and new summed
|
|
35 |
|
|
36 |
uint16 invalid_ID; ///< ID used to dected invalid entities;
|
|
37 |
|
|
38 |
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
|
|
39 |
public:
|
|
40 |
EntityIDMapping *mapping_ID; ///< mapping of ids from grf files. Public out of convenience
|
|
41 |
|
|
42 |
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
|
|
43 |
virtual ~OverrideManagerBase();
|
|
44 |
|
|
45 |
void ResetOverride();
|
|
46 |
void ResetMapping();
|
|
47 |
|
|
48 |
void Add(uint8 local_id, uint entity_type);
|
|
49 |
|
|
50 |
uint16 GetSubstituteID(byte entity_id);
|
|
51 |
uint16 GetID(uint8 grf_local_id, uint32 grfid);
|
|
52 |
|
|
53 |
inline uint16 GetMaxMapping() { return max_new_entities; };
|
|
54 |
inline uint16 GetMaxOffset() { return max_offset; };
|
|
55 |
};
|
|
56 |
|
|
57 |
|
|
58 |
struct HouseSpec;
|
|
59 |
class HouseOverrideManager : public OverrideManagerBase
|
|
60 |
{
|
|
61 |
public:
|
|
62 |
HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : OverrideManagerBase(offset, maximum, invalid) {};
|
|
63 |
void SetEntitySpec(const HouseSpec *hs);
|
|
64 |
};
|
|
65 |
|
|
66 |
|
|
67 |
extern HouseOverrideManager _house_mngr;
|
|
68 |
|
|
69 |
#endif /* NEWGRF_COMMONS_H */
|