src/newgrf_commons.cpp
author belugas
Sat, 08 Sep 2007 00:37:37 +0000
changeset 8034 0f6a176ce1e9
parent 7734 56228bfe84bc
child 8128 9fe288a99e99
permissions -rw-r--r--
(svn r11058) -Fix[FS#1216]: GetTerrainType was a bit too relax with snow line.
After double checking with ttdpatch, behaviour is now more alike (Eddi)
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     1
/* $Id$ */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     2
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     3
/** @file newgrf_commons.cpp Implementation of the class OverrideManagerBase
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     4
 * and its descendance, present and futur
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     5
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     6
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     7
#include "stdafx.h"
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     8
#include "openttd.h"
7297
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
     9
#include "variables.h"
7345
6fab61079176 (svn r10089) -Fix (r10040): Use GetTileZ instead of GetClearGround in GetTerrainType as
maedhros
parents: 7331
diff changeset
    10
#include "landscape.h"
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    11
#include "town.h"
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    12
#include "industry.h"
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    13
#include "newgrf.h"
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    14
#include "newgrf_commons.h"
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    15
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    16
/** Constructor of generic class
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    17
 * @param offset end of original data for this entity. i.e: houses = 110
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    18
 * @param maximum of entities this manager can deal with. i.e: houses = 512
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    19
 * @param invalid is the ID used to identify an invalid entity id
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    20
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    21
OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    22
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    23
	max_offset = offset;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    24
	max_new_entities = maximum;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    25
	invalid_ID = invalid;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    26
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    27
	mapping_ID = CallocT<EntityIDMapping>(max_new_entities);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    28
	entity_overrides = MallocT<uint16>(max_offset);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    29
	memset(entity_overrides, invalid, sizeof(entity_overrides));
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    30
}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    31
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    32
/** Destructor of the generic class.
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    33
 * Frees allocated memory of constructor
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    34
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    35
OverrideManagerBase::~OverrideManagerBase()
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    36
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    37
	free(mapping_ID);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    38
	free(entity_overrides);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    39
}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    40
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    41
/** Since the entity IDs defined by the GRF file does not necessarily correlate
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    42
 * to those used by the game, the IDs used for overriding old entities must be
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    43
 * translated when the entity spec is set.
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    44
 * @param local_id id in grf file
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    45
 * @param entity_type original entity type
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    46
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    47
void OverrideManagerBase::Add(uint8 local_id, uint entity_type)
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    48
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    49
	assert(entity_type < max_offset);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    50
	entity_overrides[entity_type] = local_id;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    51
}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    52
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    53
/** Resets the mapping, which is used while initializing game */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    54
void OverrideManagerBase::ResetMapping()
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    55
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    56
	memset(mapping_ID, 0, (max_new_entities - 1) * sizeof(EntityIDMapping));
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    57
}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    58
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    59
/** Resets the override, which is used while initializing game */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    60
void OverrideManagerBase::ResetOverride()
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    61
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    62
	for (uint16 i = 0; i < max_offset; i++) {
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    63
		entity_overrides[i] = invalid_ID;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    64
	}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    65
}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    66
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    67
/** Return the ID (if ever available) of a previously inserted entity.
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    68
 * @param grf_local_id ID of this enity withing the grfID
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    69
 * @param grfid ID of the grf file
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    70
 * @return the ID of the candidate, of the Invalid flag item ID
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    71
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    72
uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid)
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    73
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    74
	const EntityIDMapping *map;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    75
7731
ae4ec8ea5ac5 (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: 7496
diff changeset
    76
	for (uint16 id = 0; id < max_new_entities; id++) {
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    77
		map = &mapping_ID[id];
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    78
		if (map->entity_id == grf_local_id && map->grfid == grfid) {
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    79
			return id;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    80
		}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    81
	}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    82
	return invalid_ID;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    83
}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    84
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    85
/** Reserves a place in the mapping array for an entity to be installed
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    86
 * @param grf_local_id is an arbitrary id given by the grf's author.  Also known as setid
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    87
 * @param grfid is the id of the grf file itself
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    88
 * @param substitute_id is the original entity from which data is copied for the new one
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    89
 * @return the proper usable slot id, or invalid marker if none is found
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    90
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    91
uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    92
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    93
	uint16 id = this->GetID(grf_local_id, grfid);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    94
	EntityIDMapping *map;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    95
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    96
	/* Look to see if this entity has already been added. This is done
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    97
	 * separately from the loop below in case a GRF has been deleted, and there
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    98
	 * are any gaps in the array.
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    99
	 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   100
	if (id != invalid_ID) {
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   101
		return id;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   102
	}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   103
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   104
	/* This entity hasn't been defined before, so give it an ID now. */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   105
	for (id = max_offset; id < max_new_entities; id++) {
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   106
		map = &mapping_ID[id];
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   107
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   108
		if (map->entity_id == 0 && map->grfid == 0) {
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   109
			map->entity_id     = grf_local_id;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   110
			map->grfid         = grfid;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   111
			map->substitute_id = substitute_id;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   112
			return id;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   113
		}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   114
	}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   115
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   116
	return invalid_ID;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   117
}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   118
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   119
/** Gives the substitute of the entity, as specified by the grf file
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   120
 * @param entity_id of the entity being queried
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   121
 * @return mapped id
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   122
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   123
uint16 OverrideManagerBase::GetSubstituteID(byte entity_id)
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   124
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   125
	return mapping_ID[entity_id].substitute_id;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   126
}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   127
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   128
/** Install the specs into the HouseSpecs array
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   129
 * It will find itself the proper slot onwhich it will go
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   130
 * @param hs HouseSpec read from the grf file, ready for inclusion
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   131
 */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   132
void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   133
{
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   134
	HouseID house_id = this->AddEntityID(hs->local_id, hs->grffile->grfid, hs->substitute_id);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   135
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   136
	if (house_id == invalid_ID) {
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   137
		grfmsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   138
		return;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   139
	}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   140
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   141
	memcpy(&_house_specs[house_id], hs, sizeof(*hs));
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   142
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   143
	/* Now add the overrides. */
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   144
	for (int i = 0; i != max_offset; i++) {
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   145
		HouseSpec *overridden_hs = GetHouseSpecs(i);
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   146
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   147
		if (entity_overrides[i] != hs->local_id) continue;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   148
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   149
		overridden_hs->override = house_id;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   150
		entity_overrides[i] = invalid_ID;
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   151
	}
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   152
}
7297
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   153
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   154
/** Method to find an entity ID and to mark it as reserved for the Industry to be included.
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   155
 * @param grf_local_id ID used by the grf file for pre-installation work (equivalent of TTDPatch's setid
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   156
 * @param grfid ID of the current grf file
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   157
 * @param substitute_id industry from which data has been copied
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   158
 * @return a free entity id (slotid) if ever one has been found, or Invalid_ID marker otherwise
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   159
 */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   160
uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   161
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   162
	/* This entity hasn't been defined before, so give it an ID now. */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   163
	for (uint16 id = 0; id < max_new_entities; id++) {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   164
		/* Get the real live industry */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   165
		const IndustrySpec *inds = GetIndustrySpec(id);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   166
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   167
		/* This industry must be one that is not available(enabled), mostly because of climate.
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   168
		 * And it must not already be used by a grf (grffile == NULL).
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   169
		 * So reseve this slot here, as it is the chosen one */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   170
		if (!inds->enabled && inds->grf_prop.grffile == NULL) {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   171
			EntityIDMapping *map = &mapping_ID[id];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   172
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   173
			if (map->entity_id == 0 && map->grfid == 0) {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   174
				/* winning slot, mark it as been used */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   175
				map->entity_id     = grf_local_id;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   176
				map->grfid         = grfid;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   177
				map->substitute_id = substitute_id;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   178
				return id;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   179
			}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   180
		}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   181
	}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   182
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   183
	return invalid_ID;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   184
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   185
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   186
/** Method to install the new indistry data in its proper slot
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   187
 * The slot assigment is internal of this method, since it requires
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   188
 * checking what is available
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   189
 * @param inds Industryspec that comes from the grf decoding process
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   190
 */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   191
void IndustryOverrideManager::SetEntitySpec(const IndustrySpec *inds)
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   192
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   193
	/* First step : We need to find if this industry is already specified in the savegame data */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   194
	IndustryType ind_id = this->GetID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   195
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   196
	if (ind_id == invalid_ID) { // not found?  So this is the introduction of a new industry
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   197
		/* Second step is dealing with the override. */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   198
		if (inds->grf_prop.override != invalid_ID && _industry_specs[inds->grf_prop.override].grf_prop.override == invalid_ID) {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   199
			/* this is an override, which means it will take the place of the industry it is
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   200
			 * designed to replace. Before we conclude that the override is allowed,
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   201
			* we first need to verify that the slot is not holding another override
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   202
			* If it's the case,it will be considered as a normal substitute */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   203
			ind_id = inds->grf_prop.override;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   204
		} else {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   205
			/* It has already been overriden, so you've lost your place old boy.
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   206
			 * Or it is a simple substitute.
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   207
			 * In both case, we need to find a free available slot */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   208
			ind_id = this->AddEntityID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid, inds->grf_prop.subst_id);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   209
		}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   210
	}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   211
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   212
	if (ind_id == invalid_ID) {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   213
		grfmsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   214
		return;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   215
	}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   216
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   217
	/* Now that we know we can use the given id, copy the spech to its final destination*/
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   218
	memcpy(&_industry_specs[ind_id], inds, sizeof(*inds));
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   219
	/* and mark it as usable*/
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   220
	_industry_specs[ind_id].enabled = true;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   221
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 7323
diff changeset
   222
7496
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   223
void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   224
{
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   225
	IndustryGfx indt_id = this->AddEntityID(its->grf_prop.local_id, its->grf_prop.grffile->grfid, its->grf_prop.subst_id);
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   226
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   227
	if (indt_id == invalid_ID) {
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   228
		grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   229
		return;
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   230
	}
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   231
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   232
	memcpy(&_industry_tile_specs[indt_id], its, sizeof(*its));
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   233
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   234
	/* Now add the overrides. */
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   235
	for (int i = 0; i < max_offset; i++) {
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   236
		IndustryTileSpec *overridden_its = &_industry_tile_specs[i];
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   237
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   238
		if (entity_overrides[i] != its->grf_prop.local_id) continue;
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   239
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   240
		overridden_its->grf_prop.override = indt_id;
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   241
		overridden_its->enabled = false;
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   242
		entity_overrides[i] = invalid_ID;
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   243
	}
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   244
}
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7345
diff changeset
   245
7297
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   246
/** Function used by houses (and soon industries) to get information
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   247
 * on type of "terrain" the tile it is queries sits on.
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   248
 * @param tile TileIndex of the tile been queried
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   249
 * @return value corresponding to the grf expected format:
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   250
 *         Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   251
uint32 GetTerrainType(TileIndex tile)
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   252
{
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   253
	switch (_opt.landscape) {
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   254
		case LT_TROPIC: return GetTropicZone(tile) == TROPICZONE_DESERT ? 1 : 2;
8034
0f6a176ce1e9 (svn r11058) -Fix[FS#1216]: GetTerrainType was a bit too relax with snow line.
belugas
parents: 7734
diff changeset
   255
		case LT_ARCTIC: return GetTileZ(tile) > GetSnowLine() ? 4 : 0;
7297
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   256
		default:        return 0;
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   257
	}
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   258
}
1df77fb920bd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 7125
diff changeset
   259
7323
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   260
TileIndex GetNearbyTile(byte parameter, TileIndex tile)
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   261
{
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   262
	int8 x = GB(parameter, 0, 4);
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   263
	int8 y = GB(parameter, 4, 4);
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   264
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   265
	if (x >= 8) x -= 16;
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   266
	if (y >= 8) y -= 16;
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   267
7734
56228bfe84bc (svn r10519) -Fix: when getting a "nearby" tile, make sure you never roam outside of the map.
rubidium
parents: 7731
diff changeset
   268
	/* Make sure we never roam outside of the map */
56228bfe84bc (svn r10519) -Fix: when getting a "nearby" tile, make sure you never roam outside of the map.
rubidium
parents: 7731
diff changeset
   269
	return TILE_MASK(tile + TileDiffXY(x, y));
7323
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   270
}