src/newgrf_commons.cpp
author peter1138
Tue, 22 Jan 2008 07:27:06 +0000
changeset 8374 7a1b6c89cb89
parent 8270 e7c342f6b14c
child 8394 8d765e1d2641
permissions -rw-r--r--
(svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
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"
8108
b42a0e5c67ef (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 7875
diff changeset
    15
#include "tile_map.h"
8118
fa5fe5491657 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents: 8108
diff changeset
    16
#include "station_map.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8118
diff changeset
    17
#include "settings_type.h"
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    18
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    19
/** Constructor of generic class
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    20
 * @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
    21
 * @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
    22
 * @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
    23
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    24
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
    25
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    26
	max_offset = offset;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    27
	max_new_entities = maximum;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    28
	invalid_ID = invalid;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    29
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    30
	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
    31
	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
    32
	memset(entity_overrides, invalid, sizeof(entity_overrides));
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    33
	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
    34
}
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
/** Destructor of the generic class.
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    37
 * Frees allocated memory of constructor
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    38
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    39
OverrideManagerBase::~OverrideManagerBase()
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    40
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    41
	free(mapping_ID);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    42
	free(entity_overrides);
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    43
	free(grfid_overrides);
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    44
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    45
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    46
/** 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
    47
 * 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
    48
 * translated when the entity spec is set.
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    49
 * @param local_id ID in grf file
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    50
 * @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
    51
 * @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
    52
 */
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    53
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
    54
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    55
	assert(entity_type < max_offset);
7874
ccad4f4f3c3e (svn r11424) -Fix: an override can be set only once
glx
parents: 7873
diff changeset
    56
	/* An override can be set only once */
ccad4f4f3c3e (svn r11424) -Fix: an override can be set only once
glx
parents: 7873
diff changeset
    57
	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
    58
	entity_overrides[entity_type] = local_id;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    59
	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
    60
}
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
/** 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
    63
void OverrideManagerBase::ResetMapping()
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
	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
    66
}
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
/** 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
    69
void OverrideManagerBase::ResetOverride()
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    70
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    71
	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
    72
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    73
		grfid_overrides[i] = 0;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    74
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    75
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    76
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    77
/** 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
    78
 * @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
    79
 * @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
    80
 * @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
    81
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    82
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
    83
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    84
	const EntityIDMapping *map;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    85
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
    86
	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
    87
		map = &mapping_ID[id];
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    88
		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
    89
			return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    90
		}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    91
	}
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
    92
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
	/* 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
    94
	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
    95
		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
    96
	}
6e6e7606b77a (svn r11425) -Fix [FS#1424]: overriden industries were ignored when mapping newgrf industry type to 'real' industry type
glx
parents: 7874
diff changeset
    97
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    98
	return invalid_ID;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    99
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   100
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   101
/** 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
   102
 * @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
   103
 * @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
   104
 * @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
   105
 * @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
   106
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   107
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
   108
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   109
	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
   110
	EntityIDMapping *map;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   111
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   112
	/* 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
   113
	 * 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
   114
	 * 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
   115
	 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   116
	if (id != invalid_ID) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   117
		return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   118
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   119
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   120
	/* 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
   121
	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
   122
		map = &mapping_ID[id];
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   123
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
   124
		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
   125
			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
   126
			map->grfid         = grfid;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   127
			map->substitute_id = substitute_id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   128
			return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   129
		}
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
	return invalid_ID;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   133
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   134
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   135
/** 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
   136
 * @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
   137
 * @return mapped id
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   138
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   139
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
   140
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   141
	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
   142
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   143
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   144
/** 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
   145
 * 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
   146
 * @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
   147
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   148
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
   149
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   150
	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
   151
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   152
	if (house_id == invalid_ID) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   153
		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
   154
		return;
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
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   157
	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
   158
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   159
	/* Now add the overrides. */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   160
	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
   161
		HouseSpec *overridden_hs = GetHouseSpecs(i);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   162
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   163
		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
   164
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   165
		overridden_hs->override = house_id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   166
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   167
		grfid_overrides[i] = 0;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   168
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   169
}
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   170
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
   171
/** 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
   172
 * @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
   173
 * @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
   174
 * @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
   175
 * @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
   176
 */
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
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
   178
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   179
	/* 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
   180
	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
   181
		/* 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
   182
		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
   183
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
   184
		/* 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
   185
		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
   186
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
		/* 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
   188
		 * 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
   189
		 * 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
   190
		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
   191
			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
   192
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
			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
   194
				/* 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
   195
				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
   196
				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
   197
				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
   198
				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
   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
		}
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
	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
   204
}
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
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
/** 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
   207
 * 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
   208
 * 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
   209
 * @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
   210
 */
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
   211
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
   212
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   213
	/* 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
   214
	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
   215
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
   216
	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
   217
		/* 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
   218
		 * 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
   219
		 * 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
   220
		 * 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
   221
		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
   222
		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
   223
	}
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
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
	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
   226
		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
   227
		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
   228
	}
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
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
	/* 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
   231
	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
   232
	/* 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
   233
	_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
   234
}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   235
7000
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   236
void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   237
{
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   238
	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
   239
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   240
	if (indt_id == invalid_ID) {
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   241
		grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   242
		return;
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
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   245
	memcpy(&_industry_tile_specs[indt_id], its, sizeof(*its));
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   246
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   247
	/* Now add the overrides. */
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   248
	for (int i = 0; i < max_offset; i++) {
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   249
		IndustryTileSpec *overridden_its = &_industry_tile_specs[i];
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   250
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   251
		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
   252
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   253
		overridden_its->grf_prop.override = indt_id;
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   254
		overridden_its->enabled = false;
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   255
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   256
		grfid_overrides[i] = 0;
7000
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   257
	}
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   258
}
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   259
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   260
/** 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
   261
 * 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
   262
 * @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
   263
 * @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
   264
 *         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
   265
uint32 GetTerrainType(TileIndex tile)
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   266
{
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   267
	switch (_opt.landscape) {
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   268
		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
   269
		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
   270
		default:        return 0;
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   271
	}
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   272
}
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   273
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
   274
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
   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
	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
   277
	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
   278
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
   279
	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
   280
	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
   281
8118
fa5fe5491657 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents: 8108
diff changeset
   282
	/* Swap width and height depending on axis for railway stations */
fa5fe5491657 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents: 8108
diff changeset
   283
	if (IsRailwayStationTile(tile) && GetRailStationAxis(tile) == AXIS_X) Swap(x, y);
fa5fe5491657 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents: 8108
diff changeset
   284
7238
8986d0158eb9 (svn r10519) -Fix: when getting a "nearby" tile, make sure you never roam outside of the map.
rubidium
parents: 7235
diff changeset
   285
	/* 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
   286
	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
   287
}