src/newgrf_commons.cpp
author rubidium
Sat, 17 Nov 2007 12:42:15 +0000
changeset 7898 7c6a9c9030b5
parent 7875 6e6e7606b77a
child 8108 b42a0e5c67ef
permissions -rw-r--r--
(svn r11449) -Fix [FS#1160]: trams could deadlock themselves. As of now trams will turn as roadvehicles do when the player cannot build a tram track piece on the next tile without destroying anything. It will not turn when the player can build the before mentioned track piece on the 'next' tile.
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.cpp Implementation of the class OverrideManagerBase
eba0ac353e4d (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
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
#include "stdafx.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     8
#include "openttd.h"
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
     9
#include "variables.h"
6849
e1b7913352f8 (svn r10089) -Fix (r10040): Use GetTileZ instead of GetClearGround in GetTerrainType as
maedhros
parents: 6835
diff changeset
    10
#include "landscape.h"
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    11
#include "town.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    12
#include "industry.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    13
#include "newgrf.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    14
#include "newgrf_commons.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    15
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    16
/** Constructor of generic class
eba0ac353e4d (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
eba0ac353e4d (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
eba0ac353e4d (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
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    20
 */
eba0ac353e4d (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)
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    22
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    23
	max_offset = offset;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    24
	max_new_entities = maximum;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    25
	invalid_ID = invalid;
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
	mapping_ID = CallocT<EntityIDMapping>(max_new_entities);
eba0ac353e4d (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);
eba0ac353e4d (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));
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    30
	grfid_overrides = CallocT<uint32>(max_offset);
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    31
}
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
/** Destructor of the generic class.
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    34
 * Frees allocated memory of constructor
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
OverrideManagerBase::~OverrideManagerBase()
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
	free(mapping_ID);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    39
	free(entity_overrides);
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    40
	free(grfid_overrides);
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    41
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    42
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    43
/** Since the entity IDs defined by the GRF file does not necessarily correlate
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    44
 * to those used by the game, the IDs used for overriding old entities must be
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    45
 * translated when the entity spec is set.
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    46
 * @param local_id ID in grf file
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    47
 * @param grfid  ID of the grf file
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    48
 * @param entity_type original entity type
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    49
 */
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    50
void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    51
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    52
	assert(entity_type < max_offset);
7874
ccad4f4f3c3e (svn r11424) -Fix: an override can be set only once
glx
parents: 7873
diff changeset
    53
	/* An override can be set only once */
ccad4f4f3c3e (svn r11424) -Fix: an override can be set only once
glx
parents: 7873
diff changeset
    54
	if (entity_overrides[entity_type] != invalid_ID) return;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    55
	entity_overrides[entity_type] = local_id;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    56
	grfid_overrides[entity_type] = grfid;
6629
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
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    59
/** Resets the mapping, which is used while initializing game */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    60
void OverrideManagerBase::ResetMapping()
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    61
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    62
	memset(mapping_ID, 0, (max_new_entities - 1) * sizeof(EntityIDMapping));
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    63
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    64
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    65
/** Resets the override, which is used while initializing game */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    66
void OverrideManagerBase::ResetOverride()
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    67
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    68
	for (uint16 i = 0; i < max_offset; i++) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    69
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    70
		grfid_overrides[i] = 0;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    71
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    72
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    73
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    74
/** Return the ID (if ever available) of a previously inserted entity.
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    75
 * @param grf_local_id ID of this enity withing the grfID
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    76
 * @param grfid ID of the grf file
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    77
 * @return the ID of the candidate, of the Invalid flag item ID
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    78
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    79
uint16 OverrideManagerBase::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
    80
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    81
	const EntityIDMapping *map;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    82
7235
be9f15574c61 (svn r10516) -Fix: if doing a lookup for a ID, scan the whole range instead of only the "new" ones because the old ones could be overriden too.
rubidium
parents: 7000
diff changeset
    83
	for (uint16 id = 0; id < max_new_entities; id++) {
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    84
		map = &mapping_ID[id];
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    85
		if (map->entity_id == grf_local_id && map->grfid == grfid) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    86
			return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    87
		}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    88
	}
7875
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
    89
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
    90
	/* No mapping found, try the overrides */
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
    91
	for (uint16 id = 0; id < max_offset; id++) {
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
    92
		if (entity_overrides[id] == grf_local_id && grfid_overrides[id] == grfid) return id;
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
    93
	}
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
    94
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    95
	return invalid_ID;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    96
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    97
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    98
/** Reserves a place in the mapping array for an entity to be installed
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    99
 * @param grf_local_id is an arbitrary id given by the grf's author.  Also known as setid
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   100
 * @param grfid is the id of the grf file itself
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   101
 * @param substitute_id is the original entity from which data is copied for the new one
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   102
 * @return the proper usable slot id, or invalid marker if none is found
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   103
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   104
uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   105
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   106
	uint16 id = this->GetID(grf_local_id, grfid);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   107
	EntityIDMapping *map;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   108
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   109
	/* Look to see if this entity has already been added. This is done
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   110
	 * separately from the loop below in case a GRF has been deleted, and there
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   111
	 * are any gaps in the array.
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   112
	 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   113
	if (id != invalid_ID) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   114
		return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   115
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   116
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   117
	/* This entity hasn't been defined before, so give it an ID now. */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   118
	for (id = max_offset; id < max_new_entities; id++) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   119
		map = &mapping_ID[id];
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   120
7632
08e14d61a557 (svn r11163) -Codechange: Verify that the IndustryTileOverrideManager skip the magic value of 0xFF when assigning a new tileID. This is really important, since the value is reserved for water checking.
belugas
parents: 7538
diff changeset
   121
		if (CheckValidNewID(id) && map->entity_id == 0 && map->grfid == 0) {
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   122
			map->entity_id     = grf_local_id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   123
			map->grfid         = grfid;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   124
			map->substitute_id = substitute_id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   125
			return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   126
		}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   127
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   128
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   129
	return invalid_ID;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   130
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   131
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   132
/** Gives the substitute of the entity, as specified by the grf file
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   133
 * @param entity_id of the entity being queried
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   134
 * @return mapped id
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   135
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   136
uint16 OverrideManagerBase::GetSubstituteID(byte entity_id)
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   137
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   138
	return mapping_ID[entity_id].substitute_id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   139
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   140
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   141
/** Install the specs into the HouseSpecs array
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   142
 * It will find itself the proper slot onwhich it will go
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   143
 * @param hs HouseSpec read from the grf file, ready for inclusion
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   144
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   145
void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   146
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   147
	HouseID house_id = this->AddEntityID(hs->local_id, hs->grffile->grfid, hs->substitute_id);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   148
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   149
	if (house_id == invalid_ID) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   150
		grfmsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   151
		return;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   152
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   153
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   154
	memcpy(&_house_specs[house_id], hs, sizeof(*hs));
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   155
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   156
	/* Now add the overrides. */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   157
	for (int i = 0; i != max_offset; i++) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   158
		HouseSpec *overridden_hs = GetHouseSpecs(i);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   159
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   160
		if (entity_overrides[i] != hs->local_id || grfid_overrides[i] != hs->grffile->grfid) continue;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   161
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   162
		overridden_hs->override = house_id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   163
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   164
		grfid_overrides[i] = 0;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   165
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   166
}
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   167
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
   168
/** Method to find an entity ID and to mark it as reserved for the Industry to be included.
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   169
 * @param grf_local_id ID used by the grf file for pre-installation work (equivalent of TTDPatch's setid
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   170
 * @param grfid ID of the current grf file
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   171
 * @param substitute_id industry from which data has been copied
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   172
 * @return a free entity id (slotid) if ever one has been found, or Invalid_ID marker otherwise
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   173
 */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   174
uint16 IndustryOverrideManager::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
   175
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   176
	/* This entity hasn't been defined before, so give it an ID now. */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   177
	for (uint16 id = 0; id < max_new_entities; id++) {
7875
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   178
		/* Skip overriden industries */
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   179
		if (id < max_offset && entity_overrides[id] != invalid_ID) continue;
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   180
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
   181
		/* Get the real live industry */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   182
		const IndustrySpec *inds = GetIndustrySpec(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
   183
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   184
		/* This industry must be one that is not available(enabled), mostly because of climate.
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   185
		 * And it must not already be used by a grf (grffile == NULL).
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   186
		 * So reseve this slot here, as it is the chosen one */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   187
		if (!inds->enabled && inds->grf_prop.grffile == NULL) {
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   188
			EntityIDMapping *map = &mapping_ID[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
   189
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   190
			if (map->entity_id == 0 && map->grfid == 0) {
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   191
				/* winning slot, mark it as been used */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   192
				map->entity_id     = grf_local_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
   193
				map->grfid         = grfid;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   194
				map->substitute_id = 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
   195
				return 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
   196
			}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   197
		}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   198
	}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   199
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   200
	return invalid_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
   201
}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   202
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   203
/** Method to install the new indistry data in its proper slot
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   204
 * The slot assigment is internal of this method, since it requires
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   205
 * checking what is available
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   206
 * @param inds Industryspec that comes from the grf decoding process
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   207
 */
7667
0355390b08d9 (svn r11198) -Fix: When industry override is not possible because it is already been overridden, mark the new candidate as not being an override
belugas
parents: 7632
diff changeset
   208
void IndustryOverrideManager::SetEntitySpec(IndustrySpec *inds)
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
   209
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   210
	/* First step : We need to find if this industry is already specified in the savegame data */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   211
	IndustryType ind_id = this->GetID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   212
7875
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   213
	if (ind_id == invalid_ID) {
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   214
		/* Not found.
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   215
		 * Or it has already been overriden, so you've lost your place old boy.
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   216
		 * Or it is a simple substitute.
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   217
		 * We need to find a free available slot */
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   218
		ind_id = this->AddEntityID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid, inds->grf_prop.subst_id);
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
   219
		inds->grf_prop.override = invalid_ID;  // make sure it will not be detected as overriden
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
   220
	}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   221
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   222
	if (ind_id == invalid_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
   223
		grfmsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   224
		return;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   225
	}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   226
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   227
	/* Now that we know we can use the given id, copy the spech to its final destination*/
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   228
	memcpy(&_industry_specs[ind_id], inds, sizeof(*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
   229
	/* and mark it as usable*/
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   230
	_industry_specs[ind_id].enabled = true;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   231
}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   232
7000
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   233
void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   234
{
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   235
	IndustryGfx indt_id = this->AddEntityID(its->grf_prop.local_id, its->grf_prop.grffile->grfid, its->grf_prop.subst_id);
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   236
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   237
	if (indt_id == invalid_ID) {
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   238
		grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   239
		return;
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   240
	}
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   241
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   242
	memcpy(&_industry_tile_specs[indt_id], its, sizeof(*its));
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   243
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   244
	/* Now add the overrides. */
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   245
	for (int i = 0; i < max_offset; i++) {
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   246
		IndustryTileSpec *overridden_its = &_industry_tile_specs[i];
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   247
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   248
		if (entity_overrides[i] != its->grf_prop.local_id || grfid_overrides[i] != its->grf_prop.grffile->grfid) continue;
7000
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   249
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   250
		overridden_its->grf_prop.override = indt_id;
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   251
		overridden_its->enabled = false;
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   252
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   253
		grfid_overrides[i] = 0;
7000
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   254
	}
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   255
}
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   256
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   257
/** Function used by houses (and soon industries) to get information
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   258
 * on type of "terrain" the tile it is queries sits on.
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   259
 * @param tile TileIndex of the tile been queried
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   260
 * @return value corresponding to the grf expected format:
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   261
 *         Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   262
uint32 GetTerrainType(TileIndex tile)
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   263
{
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   264
	switch (_opt.landscape) {
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   265
		case LT_TROPIC: return GetTropicZone(tile) == TROPICZONE_DESERT ? 1 : 2;
7538
3741a86b9036 (svn r11058) -Fix[FS#1216]: GetTerrainType was a bit too relax with snow line.
belugas
parents: 7238
diff changeset
   266
		case LT_ARCTIC: return GetTileZ(tile) > GetSnowLine() ? 4 : 0;
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   267
		default:        return 0;
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   268
	}
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   269
}
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   270
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
   271
TileIndex GetNearbyTile(byte parameter, TileIndex tile)
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
   272
{
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
   273
	int8 x = GB(parameter, 0, 4);
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
   274
	int8 y = GB(parameter, 4, 4);
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
   275
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
   276
	if (x >= 8) x -= 16;
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
   277
	if (y >= 8) y -= 16;
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
   278
7238
8986d0158eb9 (svn r10519) -Fix: when getting a "nearby" tile, make sure you never roam outside of the map.
rubidium
parents: 7235
diff changeset
   279
	/* Make sure we never roam outside of the map */
8986d0158eb9 (svn r10519) -Fix: when getting a "nearby" tile, make sure you never roam outside of the map.
rubidium
parents: 7235
diff changeset
   280
	return TILE_MASK(tile + TileDiffXY(x, y));
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
   281
}