src/newgrf_commons.h
author belugas
Thu, 21 Jun 2007 17:09:10 +0000
changeset 7496 628e1191ee45
parent 7331 0a7f00fed4e6
child 7821 5388aa2cd1d2
permissions -rw-r--r--
(svn r10256) -Add: Addition of IndustryTileOverrideManager
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     1
/* $Id$ */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     2
4ce0c7a12a3f (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
4ce0c7a12a3f (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.
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     5
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     6
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     7
#ifndef NEWGRF_COMMONS_H
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     8
#define NEWGRF_COMMONS_H
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     9
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    10
/**
4ce0c7a12a3f (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.
4ce0c7a12a3f (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
4ce0c7a12a3f (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
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    14
 * the savegames themselves.
4ce0c7a12a3f (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
4ce0c7a12a3f (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
4ce0c7a12a3f (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.
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    18
 *
4ce0c7a12a3f (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
4ce0c7a12a3f (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.
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    21
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    22
struct EntityIDMapping {
4ce0c7a12a3f (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
4ce0c7a12a3f (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
4ce0c7a12a3f (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
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    26
};
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    27
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    28
class OverrideManagerBase
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    29
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    30
protected:
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    31
	uint16 *entity_overrides;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    32
4ce0c7a12a3f (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
4ce0c7a12a3f (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
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    35
4ce0c7a12a3f (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;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    37
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    38
public:
4ce0c7a12a3f (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
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    40
4ce0c7a12a3f (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);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    42
	virtual ~OverrideManagerBase();
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    43
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    44
	void ResetOverride();
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    45
	void ResetMapping();
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    46
4ce0c7a12a3f (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);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    48
	virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    49
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    50
	uint16 GetSubstituteID(byte entity_id);
4ce0c7a12a3f (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);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    52
4ce0c7a12a3f (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; };
4ce0c7a12a3f (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; };
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    55
};
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    56
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    57
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    58
struct HouseSpec;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    59
class HouseOverrideManager : public OverrideManagerBase
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    60
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    61
public:
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    62
	HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    63
			OverrideManagerBase(offset, maximum, invalid) {};
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    64
	void SetEntitySpec(const HouseSpec *hs);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    65
};
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    66
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    67
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    68
struct IndustrySpec;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    69
class IndustryOverrideManager : public OverrideManagerBase
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    70
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    71
	public:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    72
		IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    73
				OverrideManagerBase(offset, maximum, invalid) {};
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    74
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    75
		virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    76
		void SetEntitySpec(const IndustrySpec *inds);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    77
};
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    78
7496
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    79
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    80
struct IndustryTileSpec;
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    81
class IndustryTileOverrideManager : public OverrideManagerBase
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    82
{
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    83
	public:
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    84
		IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    85
				OverrideManagerBase(offset, maximum, invalid) {};
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    86
		void SetEntitySpec(const IndustryTileSpec *indts);
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    87
};
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    88
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    89
extern HouseOverrideManager _house_mngr;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
    90
extern IndustryOverrideManager _industry_mngr;
7496
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7331
diff changeset
    91
extern IndustryTileOverrideManager _industile_mngr;
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    92
7297
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
    93
uint32 GetTerrainType(TileIndex tile);
7323
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
    94
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
7297
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
    95
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    96
#endif /* NEWGRF_COMMONS_H */