author | belugas |
Sat, 09 Jun 2007 02:05:51 +0000 | |
changeset 6835 | 31c89aab2d61 |
parent 6827 | e2450e25ad95 |
child 7000 | 603a41cb93f8 |
permissions | -rw-r--r-- |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
1 |
/* $Id$ */ |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
2 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
3 |
/** @file newgrf_commons.h This file simplyfies and embeds a common mechanism of |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
4 |
* loading/saving and mapping of grf entities. |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
5 |
*/ |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
6 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
7 |
#ifndef NEWGRF_COMMONS_H |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
8 |
#define NEWGRF_COMMONS_H |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
9 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
10 |
/** |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
11 |
* Maps an entity id stored on the map to a GRF file. |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
12 |
* Entities are objects used ingame (houses, industries, industry tiles) for |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
13 |
* which we need to correlate the ids from the grf files with the ones in the |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
14 |
* the savegames themselves. |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
15 |
* An array of EntityIDMapping structs is saved with the savegame so |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
16 |
* that those GRFs can be loaded in a different order, or removed safely. The |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
17 |
* index in the array is the entity's ID stored on the map. |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
18 |
* |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
19 |
* The substitute ID is the ID of an original entity that should be used instead |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
20 |
* if the GRF containing the new entity is not available. |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
21 |
*/ |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
22 |
struct EntityIDMapping { |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
23 |
uint32 grfid; ///< The GRF ID of the file the entity belongs to |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
24 |
uint8 entity_id; ///< The entity ID within the GRF file |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
25 |
uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
26 |
}; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
27 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
28 |
class OverrideManagerBase |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
29 |
{ |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
30 |
protected: |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
31 |
uint16 *entity_overrides; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
32 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
33 |
uint16 max_offset; ///< what is the length of the original entity's array of specs |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
34 |
uint16 max_new_entities; ///< what is the amount of entities, old and new summed |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
35 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
36 |
uint16 invalid_ID; ///< ID used to dected invalid entities; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
37 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
38 |
public: |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
39 |
EntityIDMapping *mapping_ID; ///< mapping of ids from grf files. Public out of convenience |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
40 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
41 |
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
42 |
virtual ~OverrideManagerBase(); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
43 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
44 |
void ResetOverride(); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
45 |
void ResetMapping(); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
46 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
47 |
void Add(uint8 local_id, uint entity_type); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
48 |
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
49 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
50 |
uint16 GetSubstituteID(byte entity_id); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
51 |
uint16 GetID(uint8 grf_local_id, uint32 grfid); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
52 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
53 |
inline uint16 GetMaxMapping() { return max_new_entities; }; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
54 |
inline uint16 GetMaxOffset() { return max_offset; }; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
55 |
}; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
56 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
57 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
58 |
struct HouseSpec; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
59 |
class HouseOverrideManager : public OverrideManagerBase |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
60 |
{ |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
61 |
public: |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
62 |
HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
63 |
OverrideManagerBase(offset, maximum, invalid) {}; |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
64 |
void SetEntitySpec(const HouseSpec *hs); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
65 |
}; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
66 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
67 |
|
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
68 |
struct IndustrySpec; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
69 |
class IndustryOverrideManager : public OverrideManagerBase |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
70 |
{ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
71 |
public: |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
72 |
IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
73 |
OverrideManagerBase(offset, maximum, invalid) {}; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
74 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
75 |
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
76 |
void SetEntitySpec(const IndustrySpec *inds); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
77 |
}; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
78 |
|
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
79 |
extern HouseOverrideManager _house_mngr; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
6827
diff
changeset
|
80 |
extern IndustryOverrideManager _industry_mngr; |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
81 |
|
6801
9d82611443fd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
6629
diff
changeset
|
82 |
uint32 GetTerrainType(TileIndex tile); |
6827
e2450e25ad95
(svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents:
6801
diff
changeset
|
83 |
TileIndex GetNearbyTile(byte parameter, TileIndex tile); |
6801
9d82611443fd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
6629
diff
changeset
|
84 |
|
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
85 |
#endif /* NEWGRF_COMMONS_H */ |