author | truebrain |
Mon, 16 Jun 2008 14:43:19 +0000 | |
branch | noai |
changeset 10978 | 13fd0364b2c6 |
parent 9732 | f8eb3e208514 |
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; |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9704
diff
changeset
|
31 |
uint32 *grfid_overrides; |
9624 | 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; |
|
9704 | 37 |
virtual bool CheckValidNewID(uint16 testid) { return true; } |
9624 | 38 |
|
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 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9704
diff
changeset
|
48 |
void Add(uint8 local_id, uint32 grfid, uint entity_type); |
9626 | 49 |
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); |
9624 | 50 |
|
51 |
uint16 GetSubstituteID(byte entity_id); |
|
9732 | 52 |
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid); |
9624 | 53 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
54 |
inline uint16 GetMaxMapping() { return max_new_entities; } |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
55 |
inline uint16 GetMaxOffset() { return max_offset; } |
9624 | 56 |
}; |
57 |
||
58 |
||
59 |
struct HouseSpec; |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
60 |
class HouseOverrideManager : public OverrideManagerBase { |
9624 | 61 |
public: |
9626 | 62 |
HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
63 |
OverrideManagerBase(offset, maximum, invalid) {} |
9624 | 64 |
void SetEntitySpec(const HouseSpec *hs); |
65 |
}; |
|
66 |
||
67 |
||
9626 | 68 |
struct IndustrySpec; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
69 |
class IndustryOverrideManager : public OverrideManagerBase { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
70 |
public: |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
71 |
IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
72 |
OverrideManagerBase(offset, maximum, invalid) {} |
9626 | 73 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
74 |
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); |
9732 | 75 |
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid); |
9704 | 76 |
void SetEntitySpec(IndustrySpec *inds); |
9626 | 77 |
}; |
78 |
||
9629 | 79 |
|
80 |
struct IndustryTileSpec; |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
81 |
class IndustryTileOverrideManager : public OverrideManagerBase { |
9704 | 82 |
protected: |
83 |
virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; } |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
84 |
public: |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
85 |
IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
86 |
OverrideManagerBase(offset, maximum, invalid) {} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
87 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
88 |
void SetEntitySpec(const IndustryTileSpec *indts); |
9629 | 89 |
}; |
90 |
||
9624 | 91 |
extern HouseOverrideManager _house_mngr; |
9626 | 92 |
extern IndustryOverrideManager _industry_mngr; |
9629 | 93 |
extern IndustryTileOverrideManager _industile_mngr; |
9626 | 94 |
|
95 |
uint32 GetTerrainType(TileIndex tile); |
|
96 |
TileIndex GetNearbyTile(byte parameter, TileIndex tile); |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9722
diff
changeset
|
97 |
uint32 GetNearbyTileInformation(TileIndex tile); |
9624 | 98 |
|
99 |
#endif /* NEWGRF_COMMONS_H */ |