149 overridden_hs->override = house_id; |
149 overridden_hs->override = house_id; |
150 entity_overrides[i] = invalid_ID; |
150 entity_overrides[i] = invalid_ID; |
151 } |
151 } |
152 } |
152 } |
153 |
153 |
|
154 /** Method to find an entity ID and to mark it as reserved for the Industry to be included. |
|
155 * @param grf_local_id ID used by the grf file for pre-installation work (equivalent of TTDPatch's setid |
|
156 * @param grfid ID of the current grf file |
|
157 * @param substitute_id industry from which data has been copied |
|
158 * @return a free entity id (slotid) if ever one has been found, or Invalid_ID marker otherwise |
|
159 */ |
|
160 uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) |
|
161 { |
|
162 /* This entity hasn't been defined before, so give it an ID now. */ |
|
163 for (uint16 id = 0; id < max_new_entities; id++) { |
|
164 /* Get the real live industry */ |
|
165 const IndustrySpec *inds = GetIndustrySpec(id); |
|
166 |
|
167 /* This industry must be one that is not available(enabled), mostly because of climate. |
|
168 * And it must not already be used by a grf (grffile == NULL). |
|
169 * So reseve this slot here, as it is the chosen one */ |
|
170 if (!inds->enabled && inds->grf_prop.grffile == NULL) { |
|
171 EntityIDMapping *map = &mapping_ID[id]; |
|
172 |
|
173 if (map->entity_id == 0 && map->grfid == 0) { |
|
174 /* winning slot, mark it as been used */ |
|
175 map->entity_id = grf_local_id; |
|
176 map->grfid = grfid; |
|
177 map->substitute_id = substitute_id; |
|
178 return id; |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 return invalid_ID; |
|
184 } |
|
185 |
|
186 /** Method to install the new indistry data in its proper slot |
|
187 * The slot assigment is internal of this method, since it requires |
|
188 * checking what is available |
|
189 * @param inds Industryspec that comes from the grf decoding process |
|
190 */ |
|
191 void IndustryOverrideManager::SetEntitySpec(const IndustrySpec *inds) |
|
192 { |
|
193 /* First step : We need to find if this industry is already specified in the savegame data */ |
|
194 IndustryType ind_id = this->GetID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid); |
|
195 |
|
196 if (ind_id == invalid_ID) { // not found? So this is the introduction of a new industry |
|
197 /* Second step is dealing with the override. */ |
|
198 if (inds->grf_prop.override != invalid_ID && _industry_specs[inds->grf_prop.override].grf_prop.override == invalid_ID) { |
|
199 /* this is an override, which means it will take the place of the industry it is |
|
200 * designed to replace. Before we conclude that the override is allowed, |
|
201 * we first need to verify that the slot is not holding another override |
|
202 * If it's the case,it will be considered as a normal substitute */ |
|
203 ind_id = inds->grf_prop.override; |
|
204 } else { |
|
205 /* It has already been overriden, so you've lost your place old boy. |
|
206 * Or it is a simple substitute. |
|
207 * In both case, we need to find a free available slot */ |
|
208 ind_id = this->AddEntityID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid, inds->grf_prop.subst_id); |
|
209 } |
|
210 } |
|
211 |
|
212 if (ind_id == invalid_ID) { |
|
213 grfmsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring."); |
|
214 return; |
|
215 } |
|
216 |
|
217 /* Now that we know we can use the given id, copy the spech to its final destination*/ |
|
218 memcpy(&_industry_specs[ind_id], inds, sizeof(*inds)); |
|
219 /* and mark it as usable*/ |
|
220 _industry_specs[ind_id].enabled = true; |
|
221 } |
|
222 |
154 /** Function used by houses (and soon industries) to get information |
223 /** Function used by houses (and soon industries) to get information |
155 * on type of "terrain" the tile it is queries sits on. |
224 * on type of "terrain" the tile it is queries sits on. |
156 * @param tile TileIndex of the tile been queried |
225 * @param tile TileIndex of the tile been queried |
157 * @return value corresponding to the grf expected format: |
226 * @return value corresponding to the grf expected format: |
158 * Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */ |
227 * Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */ |