author | rubidium |
Fri, 03 Aug 2007 22:09:42 +0000 | |
branch | noai |
changeset 9694 | e72987579514 |
parent 9629 | 66dde6412125 |
child 9704 | 197cb8c6ae17 |
permissions | -rw-r--r-- |
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 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
28 |
class OverrideManagerBase { |
9624 | 29 |
protected: |
30 |
uint16 *entity_overrides; |
|
31 |
||
32 |
uint16 max_offset; ///< what is the length of the original entity's array of specs |
|
33 |
uint16 max_new_entities; ///< what is the amount of entities, old and new summed |
|
34 |
||
35 |
uint16 invalid_ID; ///< ID used to dected invalid entities; |
|
36 |
||
37 |
public: |
|
38 |
EntityIDMapping *mapping_ID; ///< mapping of ids from grf files. Public out of convenience |
|
39 |
||
40 |
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid); |
|
41 |
virtual ~OverrideManagerBase(); |
|
42 |
||
43 |
void ResetOverride(); |
|
44 |
void ResetMapping(); |
|
45 |
||
46 |
void Add(uint8 local_id, uint entity_type); |
|
9626 | 47 |
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); |
9624 | 48 |
|
49 |
uint16 GetSubstituteID(byte entity_id); |
|
50 |
uint16 GetID(uint8 grf_local_id, uint32 grfid); |
|
51 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
52 |
inline uint16 GetMaxMapping() { return max_new_entities; } |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
53 |
inline uint16 GetMaxOffset() { return max_offset; } |
9624 | 54 |
}; |
55 |
||
56 |
||
57 |
struct HouseSpec; |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
58 |
class HouseOverrideManager : public OverrideManagerBase { |
9624 | 59 |
public: |
9626 | 60 |
HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
61 |
OverrideManagerBase(offset, maximum, invalid) {} |
9624 | 62 |
void SetEntitySpec(const HouseSpec *hs); |
63 |
}; |
|
64 |
||
65 |
||
9626 | 66 |
struct IndustrySpec; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
67 |
class IndustryOverrideManager : public OverrideManagerBase { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
68 |
public: |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
69 |
IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
70 |
OverrideManagerBase(offset, maximum, invalid) {} |
9626 | 71 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
72 |
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
73 |
void SetEntitySpec(const IndustrySpec *inds); |
9626 | 74 |
}; |
75 |
||
9629 | 76 |
|
77 |
struct IndustryTileSpec; |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
78 |
class IndustryTileOverrideManager : public OverrideManagerBase { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
79 |
public: |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
80 |
IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
81 |
OverrideManagerBase(offset, maximum, invalid) {} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
82 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
83 |
void SetEntitySpec(const IndustryTileSpec *indts); |
9629 | 84 |
}; |
85 |
||
9624 | 86 |
extern HouseOverrideManager _house_mngr; |
9626 | 87 |
extern IndustryOverrideManager _industry_mngr; |
9629 | 88 |
extern IndustryTileOverrideManager _industile_mngr; |
9626 | 89 |
|
90 |
uint32 GetTerrainType(TileIndex tile); |
|
91 |
TileIndex GetNearbyTile(byte parameter, TileIndex tile); |
|
9624 | 92 |
|
93 |
#endif /* NEWGRF_COMMONS_H */ |