src/newgrf_house.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10360 049db04f827f
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
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
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9028
diff changeset
     3
/** @file newgrf_house.cpp Implementation of NewGRF houses. */
6332
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 "variables.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     8
#include "debug.h"
8225
cd84a95b6630 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8157
diff changeset
     9
#include "viewport_func.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6332
diff changeset
    10
#include "landscape.h"
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    11
#include "town.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    12
#include "town_map.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    13
#include "sprite.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    14
#include "newgrf.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    15
#include "newgrf_house.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    16
#include "newgrf_spritegroup.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    17
#include "newgrf_callbacks.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    18
#include "newgrf_town.h"
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    19
#include "newgrf_sound.h"
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 6427
diff changeset
    20
#include "newgrf_commons.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7691
diff changeset
    21
#include "transparency.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8114
diff changeset
    22
#include "functions.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    23
#include "company_func.h"
9005
d6b0e0a54ef2 (svn r12800) -Codechange: move the animated tile related functions out of texteff.cpp (it isn't a text effect after all). Also remove a few more functions from functions.
rubidium
parents: 8806
diff changeset
    24
#include "animated_tile_func.h"
9006
7666e7b47088 (svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium
parents: 9005
diff changeset
    25
#include "date_func.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    26
#include "company_base.h"
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    27
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    28
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    29
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    30
#include "table/town_land.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    31
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    32
static BuildingCounts    _building_counts;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    33
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
    34
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 6427
diff changeset
    35
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    36
8707
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    37
/**
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    38
 * Check and update town and house values.
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    39
 *
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    40
 * Checked are the HouseIDs. Updated are the
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    41
 * town population the number of houses per
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    42
 * town, the town radius and the max passengers
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    43
 * of the town.
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    44
 */
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    45
void UpdateHousesAndTowns()
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    46
{
8291
fe13faa125d5 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8264
diff changeset
    47
	Town *town;
7465
616fd25c5da0 (svn r10968) -Codechange: Remove a tileloop performed in the AfterLoadCountBuildings function and use the main loop of CheckhouseIDs instead
belugas
parents: 7335
diff changeset
    48
	InitializeBuildingCounts();
616fd25c5da0 (svn r10968) -Codechange: Remove a tileloop performed in the AfterLoadCountBuildings function and use the main loop of CheckhouseIDs instead
belugas
parents: 7335
diff changeset
    49
8707
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    50
	/* Reset town population and num_houses */
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    51
	FOR_ALL_TOWNS(town) {
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    52
		town->population = 0;
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    53
		town->num_houses = 0;
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    54
	}
8291
fe13faa125d5 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8264
diff changeset
    55
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    56
	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
    57
		HouseID house_id;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    58
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    59
		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
    60
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    61
		house_id = GetHouseType(t);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    62
		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
    63
			/* 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
    64
			 * replace it with the substitute original house type. */
7465
616fd25c5da0 (svn r10968) -Codechange: Remove a tileloop performed in the AfterLoadCountBuildings function and use the main loop of CheckhouseIDs instead
belugas
parents: 7335
diff changeset
    65
			house_id = _house_mngr.GetSubstituteID(house_id);
616fd25c5da0 (svn r10968) -Codechange: Remove a tileloop performed in the AfterLoadCountBuildings function and use the main loop of CheckhouseIDs instead
belugas
parents: 7335
diff changeset
    66
			SetHouseType(t, house_id);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    67
		}
8707
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    68
8291
fe13faa125d5 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8264
diff changeset
    69
		town = GetTownByTile(t);
fe13faa125d5 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8264
diff changeset
    70
		IncreaseBuildingCount(town, house_id);
fe13faa125d5 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8264
diff changeset
    71
		if (IsHouseCompleted(t)) town->population += GetHouseSpecs(house_id)->population;
8707
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    72
9657
e7e747f71cf6 (svn r13729) -Fix: assumption that non-north tiles of a house do not have the 1x1 building bit set was flawed with some NewGRFs. This caused the amount of houses to differ, which causes the town radii to differ, which causes desyncs when towns are expanded.
rubidium
parents: 9652
diff changeset
    73
		/* Increase the number of houses for every house, but only once. */
e7e747f71cf6 (svn r13729) -Fix: assumption that non-north tiles of a house do not have the 1x1 building bit set was flawed with some NewGRFs. This caused the amount of houses to differ, which causes the town radii to differ, which causes desyncs when towns are expanded.
rubidium
parents: 9652
diff changeset
    74
		if (GetHouseNorthPart(house_id) == 0) town->num_houses++;
8707
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    75
	}
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    76
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    77
	/* Update the population and num_house dependant values */
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    78
	FOR_ALL_TOWNS(town) {
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    79
		UpdateTownRadius(town);
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8571
diff changeset
    80
		UpdateTownMaxPass(town);
6332
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
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
    85
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    86
	/* 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
    87
	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
    88
		HouseClassMapping *map = &_class_mapping[i];
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    89
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    90
		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
    91
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    92
		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
    93
			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
    94
			map->grfid    = grfid;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    95
			return (HouseClassID)i;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    96
		}
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
	return HOUSE_NO_CLASS;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    99
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   100
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   101
void InitializeBuildingCounts()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   102
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   103
	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
   104
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   105
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
 * IncreaseBuildingCount()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   108
 * 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
   109
 * @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
   110
 * @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
   111
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   112
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
   113
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   114
	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
   115
6914
6219e65dd7bf (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents: 6827
diff changeset
   116
	if (!_loaded_newgrf_features.has_newhouses) return;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   117
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   118
	/* 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
   119
	 * 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
   120
	 * 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
   121
	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
   122
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   123
	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
   124
	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
   125
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   126
	/* 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
   127
	 * 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
   128
	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
   129
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   130
	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
   131
	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
   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
/**
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   135
 * DecreaseBuildingCount()
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   136
 * 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
   137
 * @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
   138
 * @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
   139
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   140
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
   141
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   142
	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
   143
6914
6219e65dd7bf (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents: 6827
diff changeset
   144
	if (!_loaded_newgrf_features.has_newhouses) return;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   145
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   146
	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
   147
	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
   148
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   149
	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
   150
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   151
	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
   152
	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
   153
}
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
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
   156
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   157
	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
   158
	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
   159
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   160
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   161
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
   162
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   163
	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
   164
	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
   165
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   166
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   167
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
   168
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   169
	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
   170
	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
   171
}
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
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
   174
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   175
	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
   176
	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
   177
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   178
	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
   179
	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
   180
	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
   181
	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
   182
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   183
	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
   184
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   185
6827
e2450e25ad95 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 6801
diff changeset
   186
uint32 GetNearbyTileInformation(byte parameter, TileIndex tile)
e2450e25ad95 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 6801
diff changeset
   187
{
e2450e25ad95 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 6801
diff changeset
   188
	tile = GetNearbyTile(parameter, tile);
8458
38fe72ff1402 (svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
frosch
parents: 8291
diff changeset
   189
	return GetNearbyTileInformation(tile);
6827
e2450e25ad95 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 6801
diff changeset
   190
}
e2450e25ad95 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 6801
diff changeset
   191
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   192
/** Structure with user-data for SearchNearbyHouseXXX - functions */
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   193
typedef struct {
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   194
	const HouseSpec *hs;  ///< Specs of the house, that startet the search
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   195
	TileIndex north_tile; ///< Northern tile of the house.
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   196
} SearchNearbyHouseData;
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   197
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   198
/** Callback function to search a house by its HouseID
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   199
 * @param tile TileIndex to be examined
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   200
 * @param user_data SearchNearbyHouseData
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   201
 * @return true or false, if found or not
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   202
 */
9592
835ccfd13653 (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 9589
diff changeset
   203
static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   204
{
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   205
	if (IsTileType(tile, MP_HOUSE)) {
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   206
		HouseID house = GetHouseType(tile); // tile been examined
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   207
		const HouseSpec *hs = GetHouseSpecs(house);
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   208
		if (hs->grffile != NULL) { // must be one from a grf file
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   209
			SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   210
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   211
			TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   212
			if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   213
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   214
			return hs->local_id == nbhd->hs->local_id &&  // same local id as the one requested
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   215
				hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   216
		}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   217
	}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   218
	return false;
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   219
}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   220
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   221
/** Callback function to search a house by its classID
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   222
 * @param tile TileIndex to be examined
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   223
 * @param user_data SearchNearbyHouseData
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   224
 * @return true or false, if found or not
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   225
 */
9592
835ccfd13653 (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 9589
diff changeset
   226
static bool SearchNearbyHouseClass(TileIndex tile, void *user_data)
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   227
{
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   228
	if (IsTileType(tile, MP_HOUSE)) {
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   229
		HouseID house = GetHouseType(tile); // tile been examined
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   230
		const HouseSpec *hs = GetHouseSpecs(house);
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   231
		if (hs->grffile != NULL) { // must be one from a grf file
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   232
			SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   233
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   234
			TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   235
			if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   236
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   237
			return hs->class_id == nbhd->hs->class_id &&  // same classid as the one requested
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   238
				hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   239
		}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   240
	}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   241
	return false;
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   242
}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   243
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   244
/** Callback function to search a house by its grfID
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   245
 * @param tile TileIndex to be examined
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   246
 * @param user_data SearchNearbyHouseData
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   247
 * @return true or false, if found or not
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   248
 */
9592
835ccfd13653 (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 9589
diff changeset
   249
static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data)
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   250
{
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   251
	if (IsTileType(tile, MP_HOUSE)) {
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   252
		HouseID house = GetHouseType(tile); // tile been examined
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   253
		const HouseSpec *hs = GetHouseSpecs(house);
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   254
		if (hs->grffile != NULL) { // must be one from a grf file
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   255
			SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   256
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   257
			TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   258
			if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   259
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   260
			return hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   261
		}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   262
	}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   263
	return false;
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   264
}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   265
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   266
/** This function will activate a search around a central tile, looking for some houses
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   267
 * that fit the requested characteristics
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   268
 * @param parameter that is given by the callback.
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   269
 *                  bits 0..6 radius of the search
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   270
 *                  bits 7..8 search type i.e.: 0 = houseID/ 1 = classID/ 2 = grfID
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   271
 * @param tile TileIndex from which to start the search
9592
835ccfd13653 (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 9589
diff changeset
   272
 * @param house the HouseID that is associated to the house, the callback is called for
835ccfd13653 (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 9589
diff changeset
   273
 * @return the Manhattan distance from the center tile, if any, and 0 if failure
835ccfd13653 (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 9589
diff changeset
   274
 */
835ccfd13653 (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 9589
diff changeset
   275
static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseID house)
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   276
{
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   277
	static TestTileOnSearchProc * const search_procs[3] = {
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   278
		SearchNearbyHouseID,
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   279
		SearchNearbyHouseClass,
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   280
		SearchNearbyHouseGRFID,
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   281
	};
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   282
	TileIndex found_tile = tile;
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   283
	uint8 searchtype = GB(parameter, 6, 2);
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   284
	uint8 searchradius = GB(parameter, 0, 6);
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   285
	if (searchtype >= lengthof(search_procs)) return 0;  // do not run on ill-defined code
9589
594a93aae48b (svn r13629) -Fix [FS#2108](r13603): diameter != radius
frosch
parents: 9574
diff changeset
   286
	if (searchradius < 1) return 0; // do not use a too low radius
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   287
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   288
	SearchNearbyHouseData nbhd;
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   289
	nbhd.hs = GetHouseSpecs(house);
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   290
	nbhd.north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   291
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   292
	/* Use a pointer for the tile to start the search. Will be required for calculating the distance*/
9594
8ea48f013588 (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 9592
diff changeset
   293
	if (CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &nbhd)) {
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   294
		return DistanceManhattan(found_tile, tile);
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   295
	}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   296
	return 0;
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   297
}
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   298
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   299
/**
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   300
 * HouseGetVariable():
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   301
 *
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   302
 * 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
   303
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   304
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
   305
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   306
	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
   307
	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
   308
	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
   309
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   310
	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
   311
		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
   312
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   313
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   314
	switch (variable) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   315
		/* Construction stage. */
8791
a882cc95f19c (svn r12513) -Codechange: rename OriginalTileRandomiser something more descriptive
skidd13
parents: 8756
diff changeset
   316
		case 0x40: return (IsTileType(tile, MP_HOUSE) ? GetHouseBuildingStage(tile) : 0) | TileHash2Bit(TileX(tile), TileY(tile)) << 2;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   317
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   318
		/* Building age. */
10360
049db04f827f (svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch
parents: 10355
diff changeset
   319
		case 0x41: return GetHouseAge(tile);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   320
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   321
		/* Town zone */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   322
		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
   323
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   324
		/* Terrain type */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   325
		case 0x43: return GetTerrainType(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   326
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   327
		/* 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
   328
		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
   329
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   330
		/* 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
   331
		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
   332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   333
		/* Current animation frame. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   334
		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
   335
10110
47ebe4990978 (svn r14294) -Feature[newGRF]: Add Variational Action 2 Variable 0x47 for houses, Coordinates of the house tile
belugas
parents: 9750
diff changeset
   336
		/* Position of the house */
10111
7a66cb62eef3 (svn r14295) -Fix(r14294): If the house is not built yet, still give me proper coordinates, pretty please!
belugas
parents: 10110
diff changeset
   337
		case 0x47: return TileY(tile) << 16 | TileX(tile);
6332
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
		/* 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
   340
		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
   341
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   342
		/* 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
   343
		case 0x61: {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   344
			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
   345
			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
   346
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 6427
diff changeset
   347
			HouseID new_house = _house_mngr.GetID(parameter, hs->grffile->grfid);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   348
			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
   349
		}
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
		/* Land info for nearby tiles. */
6827
e2450e25ad95 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 6801
diff changeset
   352
		case 0x62: return GetNearbyTileInformation(parameter, tile);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   353
9523
8a60ed4426b7 (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 9111
diff changeset
   354
		/* Current animation frame of nearby house tiles */
8a60ed4426b7 (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 9111
diff changeset
   355
		case 0x63: {
8a60ed4426b7 (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 9111
diff changeset
   356
			TileIndex testtile = GetNearbyTile(parameter, tile);
8a60ed4426b7 (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 9111
diff changeset
   357
			return IsTileType(testtile, MP_HOUSE) ? GetHouseAnimationFrame(testtile) : 0;
8a60ed4426b7 (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 9111
diff changeset
   358
		}
8a60ed4426b7 (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 9111
diff changeset
   359
9574
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   360
		/* Cargo acceptance history of nearby stations */
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   361
		/*case 0x64: not implemented yet */
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   362
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   363
		/* Distance test for some house types */
7ff7285bf59f (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 9549
diff changeset
   364
		case 0x65: return GetDistanceFromNearbyHouse(parameter, tile, object->u.house.house_id);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   365
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   366
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   367
	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
   368
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   369
	*available = false;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   370
	return UINT_MAX;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   371
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   372
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   373
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
   374
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   375
	/* 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
   376
	return NULL;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   377
}
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
/**
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   380
 * NewHouseResolver():
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
 * 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
   383
 */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   384
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
   385
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   386
	res->GetRandomBits = HouseGetRandomBits;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   387
	res->GetTriggers   = HouseGetTriggers;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   388
	res->SetTriggers   = HouseSetTriggers;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   389
	res->GetVariable   = HouseGetVariable;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   390
	res->ResolveReal   = HouseResolveReal;
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
	res->u.house.tile     = tile;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   393
	res->u.house.town     = town;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   394
	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
   395
7327
d810677fb909 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 6914
diff changeset
   396
	res->callback        = CBID_NO_CALLBACK;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   397
	res->callback_param1 = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   398
	res->callback_param2 = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   399
	res->last_value      = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   400
	res->trigger         = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   401
	res->reseed          = 0;
8756
b6f8dc6a246f (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 8707
diff changeset
   402
	res->count           = 0;
9750
7114408dd1fa (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents: 9659
diff changeset
   403
7114408dd1fa (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents: 9659
diff changeset
   404
	const HouseSpec *hs = GetHouseSpecs(house_id);
7114408dd1fa (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents: 9659
diff changeset
   405
	res->grffile         = (hs != NULL ? hs->grffile : NULL);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   406
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   407
7327
d810677fb909 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 6914
diff changeset
   408
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile)
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   409
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   410
	ResolverObject object;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   411
	const SpriteGroup *group;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   412
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   413
	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
   414
	object.callback = callback;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   415
	object.callback_param1 = param1;
6642
ced51f7c19aa (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 6629
diff changeset
   416
	object.callback_param2 = param2;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   417
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   418
	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
   419
	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
   420
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   421
	return group->g.callback.result;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   422
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   423
10257
2c37b72eec95 (svn r14488) -Fix: Synchronize drawing of spritelayouts in DrawTileLayout (Houses), IndustryDrawTileLayout, DrawStationTile, DrawTile_Station and DrawTile_Track (Waypoint).
frosch
parents: 10208
diff changeset
   424
static void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte stage, HouseID house_id)
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   425
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   426
	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
   427
	const DrawTileSeqStruct *dtss;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   428
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   429
	const HouseSpec *hs = GetHouseSpecs(house_id);
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   430
	SpriteID palette = hs->random_colour[TileHash2Bit(ti->x, ti->y)] + PALETTE_RECOLOR_START;
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   431
	if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) {
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   432
		uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile);
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   433
		if (callback != CALLBACK_FAILED) {
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   434
			/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   435
			palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   436
		}
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   437
	}
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   438
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
   439
	SpriteID image = dts->ground.sprite;
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
   440
	SpriteID pal   = dts->ground.pal;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   441
7619
a1cf1e29bb38 (svn r11149) -Fix [FS#1225]: Draw building stages for new house ground sprites.
maedhros
parents: 7523
diff changeset
   442
	if (IS_CUSTOM_SPRITE(image)) image += stage;
a1cf1e29bb38 (svn r11149) -Fix [FS#1225]: Draw building stages for new house ground sprites.
maedhros
parents: 7523
diff changeset
   443
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   444
	if (GB(image, 0, SPRITE_WIDTH) != 0) {
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   445
		DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   446
	}
6332
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
	foreach_draw_tile_seq(dtss, dts->seq) {
8570
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8458
diff changeset
   449
		if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   450
8570
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8458
diff changeset
   451
		image = dtss->image.sprite;
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8458
diff changeset
   452
		pal   = dtss->image.pal;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   453
9549
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9523
diff changeset
   454
		/* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9523
diff changeset
   455
		if (IsInvisibilitySet(TO_HOUSES) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9523
diff changeset
   456
7619
a1cf1e29bb38 (svn r11149) -Fix [FS#1225]: Draw building stages for new house ground sprites.
maedhros
parents: 7523
diff changeset
   457
		if (IS_CUSTOM_SPRITE(image)) image += stage;
a1cf1e29bb38 (svn r11149) -Fix [FS#1225]: Draw building stages for new house ground sprites.
maedhros
parents: 7523
diff changeset
   458
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10354
diff changeset
   459
		pal = SpriteLayoutPaletteTransform(image, pal, palette);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   460
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   461
		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
   462
			AddSortableSpriteToDraw(
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   463
				image, pal,
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   464
				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
   465
				dtss->size_x, dtss->size_y,
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7327
diff changeset
   466
				dtss->size_z, ti->z + dtss->delta_z,
10257
2c37b72eec95 (svn r14488) -Fix: Synchronize drawing of spritelayouts in DrawTileLayout (Houses), IndustryDrawTileLayout, DrawStationTile, DrawTile_Station and DrawTile_Track (Waypoint).
frosch
parents: 10208
diff changeset
   467
				!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_HOUSES)
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   468
			);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   469
		} else {
10257
2c37b72eec95 (svn r14488) -Fix: Synchronize drawing of spritelayouts in DrawTileLayout (Houses), IndustryDrawTileLayout, DrawStationTile, DrawTile_Station and DrawTile_Track (Waypoint).
frosch
parents: 10208
diff changeset
   470
			/* For industries and houses delta_x and delta_y are unsigned */
2c37b72eec95 (svn r14488) -Fix: Synchronize drawing of spritelayouts in DrawTileLayout (Houses), IndustryDrawTileLayout, DrawStationTile, DrawTile_Station and DrawTile_Track (Waypoint).
frosch
parents: 10208
diff changeset
   471
			AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_HOUSES));
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   472
		}
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
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   476
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
   477
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   478
	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
   479
	const SpriteGroup *group;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   480
	ResolverObject object;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   481
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
   482
	if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
6332
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
	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
   485
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   486
	group = Resolve(hs->spritegroup, &object);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   487
	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
   488
		/* 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
   489
		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
   490
	} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   491
		/* 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
   492
		byte stage = GetHouseBuildingStage(ti->tile);
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7868
diff changeset
   493
		stage = Clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   494
		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
   495
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   496
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   497
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   498
void AnimateNewHouseTile(TileIndex tile)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   499
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   500
	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
   501
	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
   502
	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
   503
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   504
	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_SPEED)) {
6642
ced51f7c19aa (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 6629
diff changeset
   505
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7868
diff changeset
   506
		if (callback_res != CALLBACK_FAILED) animation_speed = Clamp(callback_res & 0xFF, 2, 16);
6332
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
	/* 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
   510
	 * 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
   511
	 * 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
   512
	 * 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
   513
	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
   514
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   515
	byte frame      = GetHouseAnimationFrame(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   516
	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
   517
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   518
	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_NEXT_FRAME)) {
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   519
		uint32 param = (hs->extra_flags & CALLBACK_1A_RANDOM_BITS) ? Random() : 0;
6642
ced51f7c19aa (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 6629
diff changeset
   520
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_NEXT_FRAME, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
6332
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
		if (callback_res != CALLBACK_FAILED) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   523
			frame_set_by_callback = true;
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
			switch (callback_res & 0xFF) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   526
				case 0xFF:
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   527
					DeleteAnimatedTile(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   528
					break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   529
				case 0xFE:
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   530
					/* Carry on as normal. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   531
					frame_set_by_callback = false;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   532
					break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   533
				default:
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   534
					frame = callback_res & 0xFF;
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
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   538
			/* 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
   539
			 * result are not empty, it is a sound effect. */
9018
403898e0b54e (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents: 9006
diff changeset
   540
			if (GB(callback_res, 8, 7) != 0) PlayTileSound(hs->grffile, GB(callback_res, 8, 7), tile);
6332
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
	}
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
	if (!frame_set_by_callback) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   545
		if (frame < num_frames) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   546
			frame++;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   547
		} else if (frame == num_frames && HasBit(hs->animation_frames, 7)) {
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   548
			/* 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
   549
			frame = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   550
		} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   551
			/* 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
   552
			DeleteAnimatedTile(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   553
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   554
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   555
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   556
	SetHouseAnimationFrame(tile, frame);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   557
	MarkTileDirtyByTile(tile);
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
9018
403898e0b54e (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents: 9006
diff changeset
   560
void ChangeHouseAnimationFrame(const GRFFile *file, TileIndex tile, uint16 callback_result)
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   561
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   562
	switch (callback_result & 0xFF) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   563
		case 0xFD: /* Do nothing. */         break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   564
		case 0xFE: AddAnimatedTile(tile);    break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   565
		case 0xFF: DeleteAnimatedTile(tile); break;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   566
		default:
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   567
			SetHouseAnimationFrame(tile, callback_result & 0xFF);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   568
			AddAnimatedTile(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   569
			break;
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
	/* 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
   572
	 * result are not empty, it is a sound effect. */
9018
403898e0b54e (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents: 9006
diff changeset
   573
	if (GB(callback_result, 8, 7) != 0) PlayTileSound(file, GB(callback_result, 8, 7), tile);
6332
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
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   576
bool CanDeleteHouse(TileIndex tile)
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   577
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   578
	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
   579
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10111
diff changeset
   580
	/* Humans are always allowed to remove buildings, as is water and
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   581
	 * anyone using the scenario editor. */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10111
diff changeset
   582
	if ((IsValidCompanyID(_current_company) && IsHumanCompany(_current_company))
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10111
diff changeset
   583
			|| _current_company == OWNER_WATER || _current_company == OWNER_NONE) return true;
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   584
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   585
	if (HasBit(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {
6642
ced51f7c19aa (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 6629
diff changeset
   586
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   587
		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
   588
	} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   589
		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
   590
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   591
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   592
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   593
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
   594
{
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   595
	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
   596
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   597
	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) {
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   598
		uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
6642
ced51f7c19aa (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 6629
diff changeset
   599
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   600
9018
403898e0b54e (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents: 9006
diff changeset
   601
		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(hs->grffile, tile, callback_res);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   602
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   603
}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   604
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   605
bool NewHouseTileLoop(TileIndex tile)
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
	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
   608
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   609
	if (GetHouseProcessingTime(tile) > 0) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   610
		DecHouseProcessingTime(tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   611
		return true;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   612
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   613
7861
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   614
	TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP);
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   615
	TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   616
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   617
	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) {
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   618
		/* 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
   619
		 * 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
   620
		 * 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
   621
		 * 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
   622
		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
   623
			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
   624
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   625
			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
   626
			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
   627
			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
   628
			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
   629
		} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   630
			AnimationControl(tile, 0);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   631
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   632
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   633
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   634
	/* Check callback 21, which determines if a house should be destroyed. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   635
	if (HasBit(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) {
6642
ced51f7c19aa (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 6629
diff changeset
   636
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
9020
8174bbda9abe (svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium
parents: 9018
diff changeset
   637
		if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) > 0) {
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   638
			ClearTownHouse(GetTownByTile(tile), tile);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   639
			return false;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   640
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   641
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   642
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   643
	SetHouseProcessingTime(tile, hs->processing_time);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   644
	return true;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   645
}
7861
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   646
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   647
static void DoTriggerHouse(TileIndex tile, HouseTrigger trigger, byte base_random, bool first)
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   648
{
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   649
	ResolverObject object;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   650
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   651
	/* We can't trigger a non-existent building... */
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   652
	assert(IsTileType(tile, MP_HOUSE));
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   653
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   654
	HouseID hid = GetHouseType(tile);
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   655
	HouseSpec *hs = GetHouseSpecs(hid);
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   656
9028
f60408bc972b (svn r12844) -Fix: the industry tick trigger should only be triggered once every 256 ticks, not every tick... Also bail out of the triggers a little earlier if you know they are not going to happen anyway.
rubidium
parents: 9020
diff changeset
   657
	if (hs->spritegroup == NULL) return;
f60408bc972b (svn r12844) -Fix: the industry tick trigger should only be triggered once every 256 ticks, not every tick... Also bail out of the triggers a little earlier if you know they are not going to happen anyway.
rubidium
parents: 9020
diff changeset
   658
7861
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   659
	NewHouseResolver(&object, hid, tile, GetTownByTile(tile));
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   660
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   661
	object.callback = CBID_RANDOM_TRIGGER;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   662
	object.trigger = trigger;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   663
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   664
	const SpriteGroup *group = Resolve(hs->spritegroup, &object);
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   665
	if (group == NULL) return;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   666
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   667
	byte new_random_bits = Random();
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   668
	byte random_bits = GetHouseRandomBits(tile);
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   669
	random_bits &= ~object.reseed;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   670
	random_bits |= (first ? new_random_bits : base_random) & object.reseed;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   671
	SetHouseRandomBits(tile, random_bits);
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   672
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   673
	switch (trigger) {
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   674
		case HOUSE_TRIGGER_TILE_LOOP:
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   675
			/* Random value already set. */
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   676
			break;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   677
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   678
		case HOUSE_TRIGGER_TILE_LOOP_TOP:
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   679
			if (!first) break;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   680
			/* Random value of first tile already set. */
7866
c934f62ece21 (svn r11416) -Fix(r11411): For once, the warnings of MSVC are not useless. Inversion of the two parameters of DoTriggerHouse cause a complain which was legit, in this case
belugas
parents: 7861
diff changeset
   681
			if (hs->building_flags & BUILDING_2_TILES_Y)   DoTriggerHouse(TILE_ADDXY(tile, 0, 1), trigger, random_bits, false);
c934f62ece21 (svn r11416) -Fix(r11411): For once, the warnings of MSVC are not useless. Inversion of the two parameters of DoTriggerHouse cause a complain which was legit, in this case
belugas
parents: 7861
diff changeset
   682
			if (hs->building_flags & BUILDING_2_TILES_X)   DoTriggerHouse(TILE_ADDXY(tile, 1, 0), trigger, random_bits, false);
c934f62ece21 (svn r11416) -Fix(r11411): For once, the warnings of MSVC are not useless. Inversion of the two parameters of DoTriggerHouse cause a complain which was legit, in this case
belugas
parents: 7861
diff changeset
   683
			if (hs->building_flags & BUILDING_HAS_4_TILES) DoTriggerHouse(TILE_ADDXY(tile, 1, 1), trigger, random_bits, false);
7861
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   684
			break;
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   685
	}
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   686
}
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   687
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   688
void TriggerHouse(TileIndex t, HouseTrigger trigger)
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   689
{
7868
0775357181e8 (svn r11418) -Fix (r11416): forgot an instance
glx
parents: 7866
diff changeset
   690
	DoTriggerHouse(t, trigger, 0, true);
7861
77e12b5259fe (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7849
diff changeset
   691
}