author | belugas |
Fri, 08 Jun 2007 17:54:18 +0000 | |
changeset 7323 | b2871568db92 |
parent 7297 | 1df77fb920bd |
child 7331 | 0a7f00fed4e6 |
permissions | -rw-r--r-- |
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.cpp Implementation of the class OverrideManagerBase |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
4 |
* and its descendance, present and futur |
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 |
#include "stdafx.h" |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
8 |
#include "openttd.h" |
7297
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
9 |
#include "variables.h" |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
10 |
#include "clear_map.h" |
7125
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
11 |
#include "town.h" |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
12 |
#include "industry.h" |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
13 |
#include "newgrf.h" |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
14 |
#include "newgrf_commons.h" |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
15 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
16 |
/** Constructor of generic class |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
17 |
* @param offset end of original data for this entity. i.e: houses = 110 |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
18 |
* @param maximum of entities this manager can deal with. i.e: houses = 512 |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
19 |
* @param invalid is the ID used to identify an invalid entity id |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
20 |
*/ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
21 |
OverrideManagerBase::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
|
22 |
{ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
23 |
max_offset = offset; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
24 |
max_new_entities = maximum; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
25 |
invalid_ID = invalid; |
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 |
mapping_ID = CallocT<EntityIDMapping>(max_new_entities); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
28 |
entity_overrides = MallocT<uint16>(max_offset); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
29 |
memset(entity_overrides, invalid, sizeof(entity_overrides)); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
30 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
31 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
32 |
/** Destructor of the generic class. |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
33 |
* Frees allocated memory of constructor |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
34 |
*/ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
35 |
OverrideManagerBase::~OverrideManagerBase() |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
36 |
{ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
37 |
free(mapping_ID); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
38 |
free(entity_overrides); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
39 |
} |
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 |
/** Since the entity IDs defined by the GRF file does not necessarily correlate |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
42 |
* to those used by the game, the IDs used for overriding old entities must be |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
43 |
* translated when the entity spec is set. |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
44 |
* @param local_id id in grf file |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
45 |
* @param entity_type original entity type |
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 OverrideManagerBase::Add(uint8 local_id, uint entity_type) |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
48 |
{ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
49 |
assert(entity_type < max_offset); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
50 |
entity_overrides[entity_type] = local_id; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
51 |
} |
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 |
/** Resets the mapping, which is used while initializing game */ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
54 |
void OverrideManagerBase::ResetMapping() |
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 |
memset(mapping_ID, 0, (max_new_entities - 1) * sizeof(EntityIDMapping)); |
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 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
59 |
/** Resets the override, which is used while initializing game */ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
60 |
void OverrideManagerBase::ResetOverride() |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
61 |
{ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
62 |
for (uint16 i = 0; i < max_offset; i++) { |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
63 |
entity_overrides[i] = invalid_ID; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
64 |
} |
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 |
/** Return the ID (if ever available) of a previously inserted entity. |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
68 |
* @param grf_local_id ID of this enity withing the grfID |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
69 |
* @param grfid ID of the grf file |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
70 |
* @return the ID of the candidate, of the Invalid flag item ID |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
71 |
*/ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
72 |
uint16 OverrideManagerBase::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
|
73 |
{ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
74 |
const EntityIDMapping *map; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
75 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
76 |
for (uint16 id = max_offset; id < max_new_entities; id++) { |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
77 |
map = &mapping_ID[id]; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
78 |
if (map->entity_id == grf_local_id && map->grfid == grfid) { |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
79 |
return id; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
80 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
81 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
82 |
return invalid_ID; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
83 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
84 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
85 |
/** Reserves a place in the mapping array for an entity to be installed |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
86 |
* @param grf_local_id is an arbitrary id given by the grf's author. Also known as setid |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
87 |
* @param grfid is the id of the grf file itself |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
88 |
* @param substitute_id is the original entity from which data is copied for the new one |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
89 |
* @return the proper usable slot id, or invalid marker if none is found |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
90 |
*/ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
91 |
uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
92 |
{ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
93 |
uint16 id = this->GetID(grf_local_id, grfid); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
94 |
EntityIDMapping *map; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
95 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
96 |
/* Look to see if this entity has already been added. This is done |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
97 |
* separately from the loop below in case a GRF has been deleted, and there |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
98 |
* are any gaps in the array. |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
99 |
*/ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
100 |
if (id != invalid_ID) { |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
101 |
return id; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
102 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
103 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
104 |
/* This entity hasn't been defined before, so give it an ID now. */ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
105 |
for (id = max_offset; id < max_new_entities; id++) { |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
106 |
map = &mapping_ID[id]; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
107 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
108 |
if (map->entity_id == 0 && map->grfid == 0) { |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
109 |
map->entity_id = grf_local_id; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
110 |
map->grfid = grfid; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
111 |
map->substitute_id = substitute_id; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
112 |
return id; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
113 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
114 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
115 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
116 |
return invalid_ID; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
117 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
118 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
119 |
/** Gives the substitute of the entity, as specified by the grf file |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
120 |
* @param entity_id of the entity being queried |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
121 |
* @return mapped id |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
122 |
*/ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
123 |
uint16 OverrideManagerBase::GetSubstituteID(byte entity_id) |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
124 |
{ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
125 |
return mapping_ID[entity_id].substitute_id; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
126 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
127 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
128 |
/** Install the specs into the HouseSpecs array |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
129 |
* It will find itself the proper slot onwhich it will go |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
130 |
* @param hs HouseSpec read from the grf file, ready for inclusion |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
131 |
*/ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
132 |
void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs) |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
133 |
{ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
134 |
HouseID house_id = this->AddEntityID(hs->local_id, hs->grffile->grfid, hs->substitute_id); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
135 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
136 |
if (house_id == invalid_ID) { |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
137 |
grfmsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring."); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
138 |
return; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
139 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
140 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
141 |
memcpy(&_house_specs[house_id], hs, sizeof(*hs)); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
142 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
143 |
/* Now add the overrides. */ |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
144 |
for (int i = 0; i != max_offset; i++) { |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
145 |
HouseSpec *overridden_hs = GetHouseSpecs(i); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
146 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
147 |
if (entity_overrides[i] != hs->local_id) continue; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
148 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
149 |
overridden_hs->override = house_id; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
150 |
entity_overrides[i] = invalid_ID; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
151 |
} |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff
changeset
|
152 |
} |
7297
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
153 |
|
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
154 |
/** Function used by houses (and soon industries) to get information |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
155 |
* on type of "terrain" the tile it is queries sits on. |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
156 |
* @param tile TileIndex of the tile been queried |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
157 |
* @return value corresponding to the grf expected format: |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
158 |
* Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */ |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
159 |
uint32 GetTerrainType(TileIndex tile) |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
160 |
{ |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
161 |
switch (_opt.landscape) { |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
162 |
case LT_TROPIC: return GetTropicZone(tile) == TROPICZONE_DESERT ? 1 : 2; |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
163 |
case LT_ARCTIC: return (GetClearGround(tile) == CLEAR_SNOW) ? 4 : 0; |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
164 |
default: return 0; |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
165 |
} |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
166 |
} |
1df77fb920bd
(svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents:
7125
diff
changeset
|
167 |
|
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
|
168 |
TileIndex GetNearbyTile(byte parameter, TileIndex tile) |
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
|
169 |
{ |
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
|
170 |
int8 x = GB(parameter, 0, 4); |
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
|
171 |
int8 y = GB(parameter, 4, 4); |
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
|
172 |
|
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
|
173 |
if (x >= 8) x -= 16; |
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
|
174 |
if (y >= 8) y -= 16; |
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
|
175 |
|
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
|
176 |
return tile + TileDiffXY(x, y); |
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
|
177 |
} |