src/newgrf_commons.cpp
author glx
Mon, 12 Nov 2007 20:42:35 +0000
changeset 7874 ccad4f4f3c3e
parent 7873 9bb5874c81df
child 7875 6e6e7606b77a
permissions -rw-r--r--
(svn r11424) -Fix: an override can be set only once
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     1
/* $Id$ */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     2
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     3
/** @file newgrf_commons.cpp Implementation of the class OverrideManagerBase
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     4
 * and its descendance, present and futur
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     5
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     6
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     7
#include "stdafx.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
     8
#include "openttd.h"
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
     9
#include "variables.h"
6849
e1b7913352f8 (svn r10089) -Fix (r10040): Use GetTileZ instead of GetClearGround in GetTerrainType as
maedhros
parents: 6835
diff changeset
    10
#include "landscape.h"
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    11
#include "town.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    12
#include "industry.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    13
#include "newgrf.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    14
#include "newgrf_commons.h"
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    15
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    16
/** Constructor of generic class
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    17
 * @param offset end of original data for this entity. i.e: houses = 110
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    18
 * @param maximum of entities this manager can deal with. i.e: houses = 512
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    19
 * @param invalid is the ID used to identify an invalid entity id
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    20
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    21
OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    22
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    23
	max_offset = offset;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    24
	max_new_entities = maximum;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    25
	invalid_ID = invalid;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    26
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    27
	mapping_ID = CallocT<EntityIDMapping>(max_new_entities);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    28
	entity_overrides = MallocT<uint16>(max_offset);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    29
	memset(entity_overrides, invalid, sizeof(entity_overrides));
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    30
	grfid_overrides = CallocT<uint32>(max_offset);
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    31
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    32
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    33
/** Destructor of the generic class.
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    34
 * Frees allocated memory of constructor
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    35
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    36
OverrideManagerBase::~OverrideManagerBase()
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    37
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    38
	free(mapping_ID);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    39
	free(entity_overrides);
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    40
	free(grfid_overrides);
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    41
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    42
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    43
/** Since the entity IDs defined by the GRF file does not necessarily correlate
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    44
 * to those used by the game, the IDs used for overriding old entities must be
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    45
 * translated when the entity spec is set.
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    46
 * @param local_id ID in grf file
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    47
 * @param grfid  ID of the grf file
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    48
 * @param entity_type original entity type
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    49
 */
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    50
void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    51
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    52
	assert(entity_type < max_offset);
7874
ccad4f4f3c3e (svn r11424) -Fix: an override can be set only once
glx
parents: 7873
diff changeset
    53
	/* An override can be set only once */
ccad4f4f3c3e (svn r11424) -Fix: an override can be set only once
glx
parents: 7873
diff changeset
    54
	if (entity_overrides[entity_type] != invalid_ID) return;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    55
	entity_overrides[entity_type] = local_id;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    56
	grfid_overrides[entity_type] = grfid;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    57
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    58
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    59
/** Resets the mapping, which is used while initializing game */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    60
void OverrideManagerBase::ResetMapping()
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    61
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    62
	memset(mapping_ID, 0, (max_new_entities - 1) * sizeof(EntityIDMapping));
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    63
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    64
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    65
/** Resets the override, which is used while initializing game */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    66
void OverrideManagerBase::ResetOverride()
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    67
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    68
	for (uint16 i = 0; i < max_offset; i++) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    69
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
    70
		grfid_overrides[i] = 0;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    71
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    72
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    73
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    74
/** Return the ID (if ever available) of a previously inserted entity.
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    75
 * @param grf_local_id ID of this enity withing the grfID
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    76
 * @param grfid ID of the grf file
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    77
 * @return the ID of the candidate, of the Invalid flag item ID
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    78
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    79
uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid)
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    80
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    81
	const EntityIDMapping *map;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    82
7235
be9f15574c61 (svn r10516) -Fix: if doing a lookup for a ID, scan the whole range instead of only the "new" ones because the old ones could be overriden too.
rubidium
parents: 7000
diff changeset
    83
	for (uint16 id = 0; id < max_new_entities; id++) {
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    84
		map = &mapping_ID[id];
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    85
		if (map->entity_id == grf_local_id && map->grfid == grfid) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    86
			return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    87
		}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    88
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    89
	return invalid_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
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    92
/** 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
    93
 * @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
    94
 * @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
    95
 * @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
    96
 * @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
    97
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
    98
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
    99
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   100
	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
   101
	EntityIDMapping *map;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   102
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   103
	/* 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
   104
	 * 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
   105
	 * 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
   106
	 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   107
	if (id != invalid_ID) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   108
		return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   109
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   110
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   111
	/* 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
   112
	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
   113
		map = &mapping_ID[id];
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   114
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
   115
		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
   116
			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
   117
			map->grfid         = grfid;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   118
			map->substitute_id = substitute_id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   119
			return id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   120
		}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   121
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   122
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   123
	return invalid_ID;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   124
}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   125
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   126
/** 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
   127
 * @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
   128
 * @return mapped 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
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
   131
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   132
	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
   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
/** 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
   136
 * 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
   137
 * @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
   138
 */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   139
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
   140
{
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   141
	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
   142
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   143
	if (house_id == invalid_ID) {
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   144
		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
   145
		return;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   146
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   147
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   148
	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
   149
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   150
	/* Now add the overrides. */
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   151
	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
   152
		HouseSpec *overridden_hs = GetHouseSpecs(i);
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   153
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   154
		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
   155
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   156
		overridden_hs->override = house_id;
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   157
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   158
		grfid_overrides[i] = 0;
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   159
	}
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
diff changeset
   160
}
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   161
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
   162
/** 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
   163
 * @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
   164
 * @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
   165
 * @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
   166
 * @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
   167
 */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   168
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
   169
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   170
	/* 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
   171
	for (uint16 id = 0; id < max_new_entities; 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
   172
		/* 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
   173
		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
   174
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
		/* 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
   176
		 * 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
   177
		 * 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
   178
		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
   179
			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
   180
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   181
			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
   182
				/* 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
   183
				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
   184
				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
   185
				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
   186
				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
   187
			}
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
		}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   189
	}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   190
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
	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
   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
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
/** 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
   195
 * 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
   196
 * 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
   197
 * @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
   198
 */
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
   199
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
   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
	/* 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
   202
	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
   203
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
	if (ind_id == invalid_ID) { // not found?  So this is the introduction of a new 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
   205
		/* Second step is dealing with the override. */
7714
24777a3bda1c (svn r11248) -Fix[FS#1314]: The logic behind industry slot allocation was implying that the only condition an override could be placed in a slot is that there were no previous override.
belugas
parents: 7667
diff changeset
   206
		if (inds->grf_prop.override != invalid_ID && _industry_specs[inds->grf_prop.override].grf_prop.grffile == NULL) {
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
   207
			/* this is an override, which means it will take the place of the industry it is
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
			 * designed to replace. Before we conclude that the override is allowed,
7714
24777a3bda1c (svn r11248) -Fix[FS#1314]: The logic behind industry slot allocation was implying that the only condition an override could be placed in a slot is that there were no previous override.
belugas
parents: 7667
diff changeset
   209
			* we first need to verify that the slot is not holding another industry from a grf
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
   210
			* If it's the case,it will be considered as a normal substitute */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   211
			ind_id = inds->grf_prop.override;
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
		} else {
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
			/* It has already been overriden, so you've lost your place old boy.
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
			 * Or it is a simple substitute.
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
			 * In both case, we need to find a free available 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
   216
			ind_id = this->AddEntityID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid, inds->grf_prop.subst_id);
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
   217
			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
   218
		}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   219
	}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   220
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents: 6827
diff changeset
   221
	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
   222
		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
   223
		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
   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
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
	/* 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
   227
	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
   228
	/* 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
   229
	_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
   230
}
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
7000
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   232
void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   233
{
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   234
	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
   235
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   236
	if (indt_id == invalid_ID) {
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   237
		grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   238
		return;
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
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   241
	memcpy(&_industry_tile_specs[indt_id], its, sizeof(*its));
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   242
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   243
	/* Now add the overrides. */
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   244
	for (int i = 0; i < max_offset; i++) {
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   245
		IndustryTileSpec *overridden_its = &_industry_tile_specs[i];
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   246
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   247
		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
   248
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   249
		overridden_its->grf_prop.override = indt_id;
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   250
		overridden_its->enabled = false;
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   251
		entity_overrides[i] = invalid_ID;
7873
9bb5874c81df (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 7714
diff changeset
   252
		grfid_overrides[i] = 0;
7000
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   253
	}
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   254
}
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6849
diff changeset
   255
6801
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   256
/** 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
   257
 * 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
   258
 * @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
   259
 * @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
   260
 *         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
   261
uint32 GetTerrainType(TileIndex tile)
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   262
{
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   263
	switch (_opt.landscape) {
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   264
		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
   265
		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
   266
		default:        return 0;
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   267
	}
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   268
}
9d82611443fd (svn r10040) -Codechange: Make the function GetTerrainType public, as other functions require it
belugas
parents: 6629
diff changeset
   269
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
   270
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
   271
{
e2450e25ad95 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 6801
diff changeset
   272
	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
   273
	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
   274
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
	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
   276
	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
   277
7238
8986d0158eb9 (svn r10519) -Fix: when getting a "nearby" tile, make sure you never roam outside of the map.
rubidium
parents: 7235
diff changeset
   278
	/* 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
   279
	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
   280
}