src/newgrf_house.cpp
author belugas
Thu, 22 Mar 2007 03:42:43 +0000
changeset 6357 f0f5e7d1713c
parent 6343 76d17f784c13
child 6427 7dc1012757d8
permissions -rw-r--r--
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     1
/* $Id$ */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     2
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     3
/** @file newgrf_house.cpp */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     4
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     5
#include "stdafx.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     6
#include "openttd.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     7
#include "functions.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     8
#include "variables.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     9
#include "debug.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    10
#include "viewport.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6332
diff changeset
    11
#include "landscape.h"
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    12
#include "date.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    13
#include "town.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    14
#include "town_map.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    15
#include "sound.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    16
#include "sprite.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    17
#include "strings.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    18
#include "table/strings.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    19
#include "table/sprites.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    20
#include "table/town_land.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    21
#include "newgrf.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    22
#include "newgrf_house.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    23
#include "newgrf_spritegroup.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    24
#include "newgrf_callbacks.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    25
#include "newgrf_town.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    26
#include "newgrf_sound.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    27
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    28
static BuildingCounts    _building_counts;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    29
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    30
HouseIDMapping _house_id_mapping[HOUSE_MAX];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    31
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    32
/* Since the house IDs defined by the GRF file don't necessarily correlate
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    33
 * to those used by the game, the IDs used for overriding old houses must be
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    34
 * translated when the house spec is set. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    35
static uint16 _house_overrides[NEW_HOUSE_OFFSET];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    36
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    37
void AddHouseOverride(uint8 local_id, uint house_type)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    38
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    39
	assert(house_type < NEW_HOUSE_OFFSET);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    40
	_house_overrides[house_type] = local_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    41
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    42
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    43
void ResetHouseOverrides()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    44
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    45
	for (int i = 0; i != lengthof(_house_overrides); i++) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    46
		_house_overrides[i] = INVALID_HOUSE_ID;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    47
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    48
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    49
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    50
static HouseID GetHouseID(byte grf_local_id, uint32 grfid)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    51
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    52
	const HouseIDMapping *map;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    53
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    54
	for (HouseID house_id = NEW_HOUSE_OFFSET; house_id != lengthof(_house_id_mapping); house_id++) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    55
		map = &_house_id_mapping[house_id];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    56
		if (map->house_id == grf_local_id && map->grfid == grfid) return house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    57
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    58
	return INVALID_HOUSE_ID;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    59
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    60
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    61
static HouseID AddHouseID(byte grf_local_id, uint32 grfid, byte substitute_id)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    62
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    63
	HouseID house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    64
	HouseIDMapping *map;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    65
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    66
	/* Look to see if this house has already been added. This is done
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    67
	 * separately from the loop below in case a GRF has been deleted, and there
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    68
	 * are any gaps in the array. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    69
	house_id = GetHouseID(grf_local_id, grfid);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    70
	if (house_id != INVALID_HOUSE_ID) return house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    71
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    72
	/* This house hasn't been defined before, so give it an ID now. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    73
	for (house_id = NEW_HOUSE_OFFSET; house_id != lengthof(_house_id_mapping); house_id++) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    74
		map = &_house_id_mapping[house_id];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    75
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    76
		if (map->house_id == 0 && map->grfid == 0) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    77
			map->house_id      = grf_local_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    78
			map->grfid         = grfid;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    79
			map->substitute_id = substitute_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    80
			return house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    81
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    82
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    83
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    84
	return INVALID_HOUSE_ID;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    85
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    86
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    87
void SetHouseSpec(const HouseSpec *hs)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    88
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    89
	HouseID house_id = AddHouseID(hs->local_id, hs->grffile->grfid, hs->substitute_id);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    90
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    91
	if (house_id == INVALID_HOUSE_ID) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    92
		grfmsg(1, "SetHouseSpec: Too many houses allocated. Ignoring.");
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    93
		return;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    94
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    95
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    96
	memcpy(&_house_specs[house_id], hs, sizeof(*hs));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    97
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    98
	/* Now add the overrides. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    99
	for (int i = 0; i != lengthof(_house_overrides); i++) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   100
		HouseSpec *overridden_hs = GetHouseSpecs(i);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   101
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   102
		if (_house_overrides[i] != hs->local_id) continue;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   103
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   104
		overridden_hs->override = house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   105
		_house_overrides[i] = INVALID_HOUSE_ID;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   106
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   107
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   108
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   109
void ResetHouseIDMapping()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   110
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   111
	memset(&_house_id_mapping, 0, sizeof(_house_id_mapping));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   112
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   113
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   114
void CheckHouseIDs()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   115
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   116
	for (TileIndex t = 0; t < MapSize(); t++) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   117
		HouseID house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   118
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   119
		if (!IsTileType(t, MP_HOUSE)) continue;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   120
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   121
		house_id = GetHouseType(t);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   122
		if (!GetHouseSpecs(house_id)->enabled && house_id >= NEW_HOUSE_OFFSET) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   123
			/* The specs for this type of house are not available any more, so
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   124
			 * replace it with the substitute original house type. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   125
			SetHouseType(t, _house_id_mapping[house_id].substitute_id);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   126
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   127
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   128
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   129
	InitializeBuildingCounts();
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   130
	AfterLoadCountBuildings();
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   131
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   132
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   133
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   134
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   135
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   136
	/* Start from 1 because 0 means that no class has been assigned. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   137
	for (int i = 1; i != lengthof(_class_mapping); i++) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   138
		HouseClassMapping *map = &_class_mapping[i];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   139
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   140
		if (map->class_id == grf_class_id && map->grfid == grfid) return (HouseClassID)i;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   141
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   142
		if (map->class_id == 0 && map->grfid == 0) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   143
			map->class_id = grf_class_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   144
			map->grfid    = grfid;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   145
			return (HouseClassID)i;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   146
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   147
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   148
	return HOUSE_NO_CLASS;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   149
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   150
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   151
void InitializeBuildingCounts()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   152
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   153
	memset(&_building_counts, 0, sizeof(_building_counts));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   154
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   155
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   156
/**
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   157
 * IncreaseBuildingCount()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   158
 * Increase the count of a building when it has been added by a town.
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   159
 * @param t The town that the building is being built in
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   160
 * @param house_id The id of the house being added
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   161
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   162
void IncreaseBuildingCount(Town *t, HouseID house_id)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   163
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   164
	HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   165
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   166
	if (!_have_newhouses) return;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   167
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   168
	/* If there are 255 buildings of this type in this town, there are also
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   169
	 * at least that many houses of the same class in the town, and
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   170
	 * therefore on the map as well. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   171
	if (t->building_counts.id_count[house_id] == 255) return;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   172
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   173
	t->building_counts.id_count[house_id]++;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   174
	if (_building_counts.id_count[house_id] < 255) _building_counts.id_count[house_id]++;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   175
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   176
	/* Similarly, if there are 255 houses of this class in this town, there
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   177
	 * must be at least that number on the map too. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   178
	if (class_id == HOUSE_NO_CLASS || t->building_counts.class_count[class_id] == 255) return;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   179
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   180
	t->building_counts.class_count[class_id]++;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   181
	if (_building_counts.class_count[class_id] < 255) _building_counts.class_count[class_id]++;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   182
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   183
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   184
/**
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   185
 * DecreaseBuildingCount()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   186
 * Decrease the number of a building when it is deleted.
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   187
 * @param t The town that the building was built in
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   188
 * @param house_id The id of the house being removed
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   189
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   190
void DecreaseBuildingCount(Town *t, HouseID house_id)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   191
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   192
	HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   193
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   194
	if (!_have_newhouses) return;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   195
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   196
	if (t->building_counts.id_count[house_id] > 0) t->building_counts.id_count[house_id]--;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   197
	if (_building_counts.id_count[house_id] > 0)   _building_counts.id_count[house_id]--;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   198
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   199
	if (class_id == HOUSE_NO_CLASS) return;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   200
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   201
	if (t->building_counts.class_count[class_id] > 0) t->building_counts.class_count[class_id]--;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   202
	if (_building_counts.class_count[class_id] > 0)   _building_counts.class_count[class_id]--;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   203
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   204
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   205
/**
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   206
 * AfterLoadCountBuildings()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   207
 *
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   208
 * After a savegame has been loaded, count the number of buildings on the map.
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   209
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   210
void AfterLoadCountBuildings()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   211
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   212
	if (!_have_newhouses) return;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   213
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   214
	for (TileIndex t = 0; t < MapSize(); t++) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   215
		if (!IsTileType(t, MP_HOUSE)) continue;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   216
		IncreaseBuildingCount(GetTownByTile(t), GetHouseType(t));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   217
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   218
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   219
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   220
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   221
static uint32 HouseGetRandomBits(const ResolverObject *object)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   222
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   223
	const TileIndex tile = object->u.house.tile;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   224
	return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseRandomBits(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   225
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   226
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   227
static uint32 HouseGetTriggers(const ResolverObject *object)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   228
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   229
	const TileIndex tile = object->u.house.tile;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   230
	return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseTriggers(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   231
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   232
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   233
static void HouseSetTriggers(const ResolverObject *object, int triggers)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   234
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   235
	const TileIndex tile = object->u.house.tile;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   236
	if (IsTileType(tile, MP_HOUSE)) SetHouseTriggers(tile, triggers);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   237
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   238
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   239
static uint32 GetNumHouses(HouseID house_id, const Town *town)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   240
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   241
	uint8 map_id_count, town_id_count, map_class_count, town_class_count;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   242
	HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   243
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   244
	map_id_count     = _building_counts.id_count[house_id];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   245
	map_class_count  = _building_counts.class_count[class_id];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   246
	town_id_count    = town->building_counts.id_count[house_id];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   247
	town_class_count = town->building_counts.class_count[class_id];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   248
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   249
	return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   250
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   251
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   252
static uint32 GetTerrainType(TileIndex tile)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   253
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   254
	switch (_opt.landscape) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   255
		case LT_TROPIC: return GetTropicZone(tile) == TROPICZONE_DESERT ? 1 : 2;
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   256
		case LT_ARCTIC: return GetTileZ(tile) >= GetSnowLine() ? 4 : 0;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   257
		default:        return 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   258
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   259
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   260
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   261
static uint32 GetGRFParameter(HouseID house_id, byte parameter)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   262
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   263
	const HouseSpec *hs = GetHouseSpecs(house_id);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   264
	const GRFFile *file = hs->grffile;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   265
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   266
	if (parameter >= file->param_end) return 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   267
	return file->param[parameter];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   268
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   269
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   270
/**
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   271
 * HouseGetVariable():
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   272
 *
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   273
 * Used by the resolver to get values for feature 07 deterministic spritegroups.
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   274
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   275
static uint32 HouseGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   276
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   277
	const Town *town = object->u.house.town;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   278
	TileIndex tile   = object->u.house.tile;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   279
	HouseID house_id = object->u.house.house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   280
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   281
	if (object->scope == VSG_SCOPE_PARENT) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   282
		return TownGetVariable(variable, parameter, available, town);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   283
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   284
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   285
	switch (variable) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   286
		/* Construction stage. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   287
		case 0x40: return (IsTileType(tile, MP_HOUSE) ? GetHouseBuildingStage(tile) : 0) | OriginalTileRandomiser(TileX(tile), TileY(tile)) << 2;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   288
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   289
		/* Building age. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   290
		case 0x41: return clamp(_cur_year - GetHouseConstructionYear(tile), 0, 0xFF);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   291
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   292
		/* Town zone */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   293
		case 0x42: return GetTownRadiusGroup(town, tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   294
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   295
		/* Terrain type */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   296
		case 0x43: return GetTerrainType(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   297
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   298
		/* Number of this type of building on the map. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   299
		case 0x44: return GetNumHouses(house_id, town);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   300
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   301
		/* Whether the town is being created or just expanded. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   302
		case 0x45: return _generating_world ? 1 : 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   303
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   304
		/* Current animation frame. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   305
		case 0x46: return IsTileType(tile, MP_HOUSE) ? GetHouseAnimationFrame(tile) : 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   306
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   307
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   308
		/* Building counts for old houses with id = parameter. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   309
		case 0x60: return GetNumHouses(parameter, town);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   310
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   311
		/* Building counts for new houses with id = parameter. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   312
		case 0x61: {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   313
			const HouseSpec *hs = GetHouseSpecs(house_id);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   314
			if (hs->grffile == NULL) return 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   315
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   316
			HouseID new_house = GetHouseID(parameter, hs->grffile->grfid);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   317
			return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, town);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   318
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   319
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   320
		/* Land info for nearby tiles. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   321
		case 0x62: {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   322
			int8 x = GB(parameter, 0, 4);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   323
			int8 y = GB(parameter, 4, 4);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   324
			byte tile_type;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   325
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   326
			if (x >= 8) x -= 16;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   327
			if (y >= 8) y -= 16;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   328
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   329
			tile += TileDiffXY(x, y);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   330
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   331
			tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   333
			return GetTileType(tile) << 24 | (TileHeight(tile) * 8) << 16 | tile_type << 8 | GetTileSlope(tile, NULL);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   334
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   335
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   336
		/* Read GRF parameter */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   337
		case 0x7F: return GetGRFParameter(object->u.house.house_id, parameter);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   338
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   339
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   340
	DEBUG(grf, 1, "Unhandled house property 0x%X", variable);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   341
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   342
	*available = false;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   343
	return UINT_MAX;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   344
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   345
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   346
static const SpriteGroup *HouseResolveReal(const ResolverObject *object, const SpriteGroup *group)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   347
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   348
	/* Houses do not have 'real' groups */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   349
	return NULL;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   350
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   351
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   352
/**
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   353
 * NewHouseResolver():
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   354
 *
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   355
 * Returns a resolver object to be used with feature 07 spritegroups.
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   356
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   357
static void NewHouseResolver(ResolverObject *res, HouseID house_id, TileIndex tile, Town *town)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   358
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   359
	res->GetRandomBits = HouseGetRandomBits;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   360
	res->GetTriggers   = HouseGetTriggers;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   361
	res->SetTriggers   = HouseSetTriggers;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   362
	res->GetVariable   = HouseGetVariable;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   363
	res->ResolveReal   = HouseResolveReal;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   364
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   365
	res->u.house.tile     = tile;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   366
	res->u.house.town     = town;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   367
	res->u.house.house_id = house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   368
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   369
	res->callback        = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   370
	res->callback_param1 = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   371
	res->callback_param2 = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   372
	res->last_value      = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   373
	res->trigger         = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   374
	res->reseed          = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   375
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   376
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   377
uint16 GetHouseCallback(uint16 callback, uint32 param1, HouseID house_id, Town *town, TileIndex tile)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   378
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   379
	ResolverObject object;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   380
	const SpriteGroup *group;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   381
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   382
	NewHouseResolver(&object, house_id, tile, town);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   383
	object.callback = callback;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   384
	object.callback_param1 = param1;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   385
	object.callback_param2 = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   386
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   387
	group = Resolve(GetHouseSpecs(house_id)->spritegroup, &object);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   388
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   389
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   390
	return group->g.callback.result;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   391
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   392
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   393
void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte stage, HouseID house_id)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   394
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   395
	const DrawTileSprites *dts = group->g.layout.dts;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   396
	const DrawTileSeqStruct *dtss;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   397
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   398
	SpriteID image = dts->ground_sprite;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   399
	SpriteID pal   = dts->ground_pal;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   400
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   401
	if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   402
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   403
	foreach_draw_tile_seq(dtss, dts->seq) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   404
		if (GB(dtss->image, 0, SPRITE_WIDTH) == 0) continue;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   405
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   406
		image = dtss->image + stage;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   407
		pal   = dtss->pal;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   408
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   409
		if (!HASBIT(image, SPRITE_MODIFIER_OPAQUE) && ((_display_opt & DO_TRANS_BUILDINGS))) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   410
			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   411
			pal = PALETTE_TO_TRANSPARENT;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   412
		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   413
			if (pal == 0) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   414
				const HouseSpec *hs = GetHouseSpecs(house_id);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   415
				if (HASBIT(hs->callback_mask, CBM_BUILDING_COLOUR)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   416
					uint16 callback = GetHouseCallback(CBID_BUILDING_COLOUR, 0, house_id, GetTownByTile(ti->tile), ti->tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   417
					if (callback != CALLBACK_FAILED) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   418
						/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   419
						pal = HASBIT(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   420
					}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   421
				} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   422
					pal = hs->random_colour[OriginalTileRandomiser(ti->x, ti->y)] + PALETTE_RECOLOR_START;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   423
				}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   424
			}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   425
		} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   426
			pal = PAL_NONE;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   427
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   428
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   429
		if ((byte)dtss->delta_z != 0x80) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   430
			AddSortableSpriteToDraw(
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   431
				image, pal,
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   432
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   433
				dtss->size_x, dtss->size_y,
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   434
				dtss->size_z, ti->z + dtss->delta_z
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   435
			);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   436
		} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   437
			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   438
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   439
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   440
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   441
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   442
void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   443
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   444
	const HouseSpec *hs = GetHouseSpecs(house_id);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   445
	const SpriteGroup *group;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   446
	ResolverObject object;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   447
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   448
	if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   449
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   450
	NewHouseResolver(&object, house_id, ti->tile, GetTownByTile(ti->tile));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   451
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   452
	group = Resolve(hs->spritegroup, &object);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   453
	if (group == NULL || group->type != SGT_TILELAYOUT) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   454
		/* XXX: This is for debugging purposes really, and shouldn't stay. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   455
		DrawGroundSprite(SPR_SHADOW_CELL, PAL_NONE);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   456
	} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   457
		/* Limit the building stage to the number of stages supplied. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   458
		byte stage = GetHouseBuildingStage(ti->tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   459
		stage = clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   460
		DrawTileLayout(ti, group, stage, house_id);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   461
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   462
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   463
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   464
void AnimateNewHouseTile(TileIndex tile)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   465
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   466
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   467
	byte animation_speed = hs->animation_speed;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   468
	bool frame_set_by_callback = false;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   469
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   470
	if (HASBIT(hs->callback_mask, CBM_ANIMATION_SPEED)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   471
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, GetHouseType(tile), GetTownByTile(tile), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   472
		if (callback_res != CALLBACK_FAILED) animation_speed = clamp(callback_res & 0xFF, 2, 16);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   473
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   474
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   475
	/* An animation speed of 2 means the animation frame changes 4 ticks, and
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   476
	 * increasing this value by one doubles the wait. 2 is the minimum value
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   477
	 * allowed for animation_speed, which corresponds to 120ms, and 16 is the
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   478
	 * maximum, corresponding to around 33 minutes. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   479
	if (_tick_counter % (1 << animation_speed) != 0) return;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   480
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   481
	byte frame      = GetHouseAnimationFrame(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   482
	byte num_frames = GB(hs->animation_frames, 0, 7);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   483
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   484
	if (HASBIT(hs->callback_mask, CBM_ANIMATION_NEXT_FRAME)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   485
		uint32 param = (hs->extra_flags & CALLBACK_1A_RANDOM_BITS) ? Random() : 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   486
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_NEXT_FRAME, param, GetHouseType(tile), GetTownByTile(tile), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   487
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   488
		if (callback_res != CALLBACK_FAILED) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   489
			frame_set_by_callback = true;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   490
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   491
			switch (callback_res & 0xFF) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   492
				case 0xFF:
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   493
					DeleteAnimatedTile(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   494
					break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   495
				case 0xFE:
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   496
					/* Carry on as normal. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   497
					frame_set_by_callback = false;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   498
					break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   499
				default:
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   500
					frame = callback_res & 0xFF;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   501
					break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   502
			}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   503
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   504
			/* If the lower 7 bits of the upper byte of the callback
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   505
			 * result are not empty, it is a sound effect. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   506
			if (GB(callback_res, 8, 7) != 0) PlayHouseSound(GB(callback_res, 8, 7), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   507
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   508
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   509
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   510
	if (!frame_set_by_callback) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   511
		if (frame < num_frames) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   512
			frame++;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   513
		} else if (frame == num_frames && HASBIT(hs->animation_frames, 7)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   514
			/* This animation loops, so start again from the beginning */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   515
			frame = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   516
		} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   517
			/* This animation doesn't loop, so stay here */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   518
			DeleteAnimatedTile(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   519
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   520
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   521
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   522
	SetHouseAnimationFrame(tile, frame);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   523
	MarkTileDirtyByTile(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   524
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   525
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   526
void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   527
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   528
	switch (callback_result & 0xFF) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   529
		case 0xFD: /* Do nothing. */         break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   530
		case 0xFE: AddAnimatedTile(tile);    break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   531
		case 0xFF: DeleteAnimatedTile(tile); break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   532
		default:
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   533
			SetHouseAnimationFrame(tile, callback_result & 0xFF);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   534
			AddAnimatedTile(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   535
			break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   536
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   537
	/* If the lower 7 bits of the upper byte of the callback
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   538
	 * result are not empty, it is a sound effect. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   539
	if (GB(callback_result, 8, 7) != 0) PlayHouseSound(GB(callback_result, 8, 7), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   540
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   541
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   542
bool CanDeleteHouse(TileIndex tile)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   543
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   544
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   545
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   546
	/* Human players are always allowed to remove buildings, as is water and
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   547
	 * anyone using the scenario editor. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   548
	if ((IsValidPlayer(_current_player) && IsHumanPlayer(_current_player))
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   549
			|| _current_player == OWNER_WATER || _current_player == OWNER_NONE) return true;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   550
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   551
	if (HASBIT(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   552
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, GetHouseType(tile), GetTownByTile(tile), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   553
		return (callback_res == CALLBACK_FAILED || callback_res == 0);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   554
	} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   555
		return !(hs->extra_flags & BUILDING_IS_PROTECTED);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   556
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   557
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   558
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   559
static void AnimationControl(TileIndex tile, uint16 random_bits)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   560
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   561
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   562
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   563
	if (HASBIT(hs->callback_mask, CBM_ANIMATION_START_STOP)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   564
		uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   565
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, GetHouseType(tile), GetTownByTile(tile), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   566
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   567
		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   568
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   569
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   570
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   571
bool NewHouseTileLoop(TileIndex tile)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   572
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   573
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   574
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   575
	if (GetHouseProcessingTime(tile) > 0) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   576
		DecHouseProcessingTime(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   577
		return true;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   578
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   579
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   580
	/* @todo: Magic with triggers goes here.  Got to implement that, one day. .. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   581
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   582
	if (HASBIT(hs->callback_mask, CBM_ANIMATION_START_STOP)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   583
		/* If this house is marked as having a synchronised callback, all the
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   584
		 * tiles will have the callback called at once, rather than when the
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   585
		 * tile loop reaches them. This should only be enabled for the northern
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   586
		 * tile, or strange things will happen (here, and in TTDPatch). */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   587
		if (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   588
			uint16 random = GB(Random(), 0, 16);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   589
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   590
			if (hs->building_flags & BUILDING_HAS_1_TILE)  AnimationControl(tile, random);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   591
			if (hs->building_flags & BUILDING_2_TILES_Y)   AnimationControl(TILE_ADDXY(tile, 0, 1), random);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   592
			if (hs->building_flags & BUILDING_2_TILES_X)   AnimationControl(TILE_ADDXY(tile, 1, 0), random);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   593
			if (hs->building_flags & BUILDING_HAS_4_TILES) AnimationControl(TILE_ADDXY(tile, 1, 1), random);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   594
		} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   595
			AnimationControl(tile, 0);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   596
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   597
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   598
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   599
	/* Check callback 21, which determines if a house should be destroyed. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   600
	if (HASBIT(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   601
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, GetHouseType(tile), GetTownByTile(tile), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   602
		if (callback_res != CALLBACK_FAILED && callback_res > 0) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   603
			ClearTownHouse(GetTownByTile(tile), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   604
			return false;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   605
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   606
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   607
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   608
	SetHouseProcessingTime(tile, hs->processing_time);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   609
	return true;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   610
}