src/newgrf_house.cpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 21:51:14 +0300
changeset 11180 982e9f814f97
parent 11171 04fc8e49df1b
permissions -rw-r--r--
scan for tarfiles in CACHE_DIR, remember what Subdirectory a tar was found in, set the GCF_FLAG on GRFs loaded from there, and hide those in the NewGRF GUI
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     1
/* $Id$ */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     2
10429
1b99254f9607 (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: 10303
diff changeset
     3
/** @file newgrf_house.cpp Implementation of NewGRF houses. */
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     4
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     5
#include "stdafx.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     6
#include "openttd.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     7
#include "variables.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     8
#include "debug.h"
8721
b7971ad9bdd9 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8653
diff changeset
     9
#include "viewport_func.h"
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6658
diff changeset
    10
#include "landscape.h"
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    11
#include "town.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    12
#include "town_map.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    13
#include "sprite.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    14
#include "newgrf.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    15
#include "newgrf_house.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    16
#include "newgrf_spritegroup.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    17
#include "newgrf_callbacks.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    18
#include "newgrf_town.h"
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    19
#include "newgrf_sound.h"
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 6923
diff changeset
    20
#include "newgrf_commons.h"
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8187
diff changeset
    21
#include "transparency.h"
8627
448ebf3a8291 (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: 8610
diff changeset
    22
#include "functions.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8733
diff changeset
    23
#include "player_func.h"
10268
434c8d706e7e (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: 9302
diff changeset
    24
#include "animated_tile_func.h"
10269
a833a213bf38 (svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium
parents: 10268
diff changeset
    25
#include "date_func.h"
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    26
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    27
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    28
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    29
#include "table/town_land.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    30
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    31
static BuildingCounts    _building_counts;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    32
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    33
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 6923
diff changeset
    34
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    35
9203
55b0289562a8 (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: 9067
diff changeset
    36
/**
55b0289562a8 (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: 9067
diff changeset
    37
 * Check and update town and house values.
55b0289562a8 (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: 9067
diff changeset
    38
 *
55b0289562a8 (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: 9067
diff changeset
    39
 * Checked are the HouseIDs. Updated are the
55b0289562a8 (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: 9067
diff changeset
    40
 * town population the number of houses per
55b0289562a8 (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: 9067
diff changeset
    41
 * town, the town radius and the max passengers
55b0289562a8 (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: 9067
diff changeset
    42
 * of the town.
55b0289562a8 (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: 9067
diff changeset
    43
 */
55b0289562a8 (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: 9067
diff changeset
    44
void UpdateHousesAndTowns()
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    45
{
8787
3cf49b620b77 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8760
diff changeset
    46
	Town *town;
7961
46bee18c1a36 (svn r10968) -Codechange: Remove a tileloop performed in the AfterLoadCountBuildings function and use the main loop of CheckhouseIDs instead
belugas
parents: 7831
diff changeset
    47
	InitializeBuildingCounts();
46bee18c1a36 (svn r10968) -Codechange: Remove a tileloop performed in the AfterLoadCountBuildings function and use the main loop of CheckhouseIDs instead
belugas
parents: 7831
diff changeset
    48
9203
55b0289562a8 (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: 9067
diff changeset
    49
	/* Reset town population and num_houses */
55b0289562a8 (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: 9067
diff changeset
    50
	FOR_ALL_TOWNS(town) {
55b0289562a8 (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: 9067
diff changeset
    51
		town->population = 0;
55b0289562a8 (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: 9067
diff changeset
    52
		town->num_houses = 0;
55b0289562a8 (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: 9067
diff changeset
    53
	}
8787
3cf49b620b77 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8760
diff changeset
    54
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    55
	for (TileIndex t = 0; t < MapSize(); t++) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    56
		HouseID house_id;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    57
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    58
		if (!IsTileType(t, MP_HOUSE)) continue;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    59
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    60
		house_id = GetHouseType(t);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    61
		if (!GetHouseSpecs(house_id)->enabled && house_id >= NEW_HOUSE_OFFSET) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    62
			/* The specs for this type of house are not available any more, so
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    63
			 * replace it with the substitute original house type. */
7961
46bee18c1a36 (svn r10968) -Codechange: Remove a tileloop performed in the AfterLoadCountBuildings function and use the main loop of CheckhouseIDs instead
belugas
parents: 7831
diff changeset
    64
			house_id = _house_mngr.GetSubstituteID(house_id);
46bee18c1a36 (svn r10968) -Codechange: Remove a tileloop performed in the AfterLoadCountBuildings function and use the main loop of CheckhouseIDs instead
belugas
parents: 7831
diff changeset
    65
			SetHouseType(t, house_id);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    66
		}
9203
55b0289562a8 (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: 9067
diff changeset
    67
8787
3cf49b620b77 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8760
diff changeset
    68
		town = GetTownByTile(t);
3cf49b620b77 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8760
diff changeset
    69
		IncreaseBuildingCount(town, house_id);
3cf49b620b77 (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
glx
parents: 8760
diff changeset
    70
		if (IsHouseCompleted(t)) town->population += GetHouseSpecs(house_id)->population;
9203
55b0289562a8 (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: 9067
diff changeset
    71
11171
04fc8e49df1b (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: 11161
diff changeset
    72
		/* Increase the number of houses for every house, but only once. */
04fc8e49df1b (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: 11161
diff changeset
    73
		if (GetHouseNorthPart(house_id) == 0) town->num_houses++;
9203
55b0289562a8 (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: 9067
diff changeset
    74
	}
55b0289562a8 (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: 9067
diff changeset
    75
55b0289562a8 (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: 9067
diff changeset
    76
	/* Update the population and num_house dependant values */
55b0289562a8 (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: 9067
diff changeset
    77
	FOR_ALL_TOWNS(town) {
55b0289562a8 (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: 9067
diff changeset
    78
		UpdateTownRadius(town);
55b0289562a8 (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: 9067
diff changeset
    79
		UpdateTownMaxPass(town);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    80
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    81
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    82
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    83
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    84
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    85
	/* Start from 1 because 0 means that no class has been assigned. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    86
	for (int i = 1; i != lengthof(_class_mapping); i++) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    87
		HouseClassMapping *map = &_class_mapping[i];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    88
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    89
		if (map->class_id == grf_class_id && map->grfid == grfid) return (HouseClassID)i;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    90
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    91
		if (map->class_id == 0 && map->grfid == 0) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    92
			map->class_id = grf_class_id;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    93
			map->grfid    = grfid;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    94
			return (HouseClassID)i;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    95
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    96
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    97
	return HOUSE_NO_CLASS;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    98
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    99
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   100
void InitializeBuildingCounts()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   101
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   102
	memset(&_building_counts, 0, sizeof(_building_counts));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   103
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   104
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   105
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   106
 * IncreaseBuildingCount()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   107
 * Increase the count of a building when it has been added by a town.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   108
 * @param t The town that the building is being built in
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   109
 * @param house_id The id of the house being added
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   110
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   111
void IncreaseBuildingCount(Town *t, HouseID house_id)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   112
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   113
	HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   114
7410
358b83972e29 (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents: 7323
diff changeset
   115
	if (!_loaded_newgrf_features.has_newhouses) return;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   116
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   117
	/* If there are 255 buildings of this type in this town, there are also
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   118
	 * at least that many houses of the same class in the town, and
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   119
	 * therefore on the map as well. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   120
	if (t->building_counts.id_count[house_id] == 255) return;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   121
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   122
	t->building_counts.id_count[house_id]++;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   123
	if (_building_counts.id_count[house_id] < 255) _building_counts.id_count[house_id]++;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   124
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   125
	/* Similarly, if there are 255 houses of this class in this town, there
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   126
	 * must be at least that number on the map too. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   127
	if (class_id == HOUSE_NO_CLASS || t->building_counts.class_count[class_id] == 255) return;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   128
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   129
	t->building_counts.class_count[class_id]++;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   130
	if (_building_counts.class_count[class_id] < 255) _building_counts.class_count[class_id]++;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   131
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   132
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   133
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   134
 * DecreaseBuildingCount()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   135
 * Decrease the number of a building when it is deleted.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   136
 * @param t The town that the building was built in
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   137
 * @param house_id The id of the house being removed
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   138
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   139
void DecreaseBuildingCount(Town *t, HouseID house_id)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   140
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   141
	HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   142
7410
358b83972e29 (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents: 7323
diff changeset
   143
	if (!_loaded_newgrf_features.has_newhouses) return;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   144
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   145
	if (t->building_counts.id_count[house_id] > 0) t->building_counts.id_count[house_id]--;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   146
	if (_building_counts.id_count[house_id] > 0)   _building_counts.id_count[house_id]--;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   147
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   148
	if (class_id == HOUSE_NO_CLASS) return;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   149
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   150
	if (t->building_counts.class_count[class_id] > 0) t->building_counts.class_count[class_id]--;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   151
	if (_building_counts.class_count[class_id] > 0)   _building_counts.class_count[class_id]--;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   152
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   153
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   154
static uint32 HouseGetRandomBits(const ResolverObject *object)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   155
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   156
	const TileIndex tile = object->u.house.tile;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   157
	return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseRandomBits(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   158
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   159
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   160
static uint32 HouseGetTriggers(const ResolverObject *object)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   161
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   162
	const TileIndex tile = object->u.house.tile;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   163
	return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseTriggers(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   164
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   165
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   166
static void HouseSetTriggers(const ResolverObject *object, int triggers)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   167
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   168
	const TileIndex tile = object->u.house.tile;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   169
	if (IsTileType(tile, MP_HOUSE)) SetHouseTriggers(tile, triggers);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   170
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   171
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   172
static uint32 GetNumHouses(HouseID house_id, const Town *town)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   173
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   174
	uint8 map_id_count, town_id_count, map_class_count, town_class_count;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   175
	HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   176
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   177
	map_id_count     = _building_counts.id_count[house_id];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   178
	map_class_count  = _building_counts.class_count[class_id];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   179
	town_id_count    = town->building_counts.id_count[house_id];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   180
	town_class_count = town->building_counts.class_count[class_id];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   181
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   182
	return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   183
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   184
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   185
static uint32 GetGRFParameter(HouseID house_id, byte parameter)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   186
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   187
	const HouseSpec *hs = GetHouseSpecs(house_id);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   188
	const GRFFile *file = hs->grffile;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   189
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   190
	if (parameter >= file->param_end) return 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   191
	return file->param[parameter];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   192
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   193
7323
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   194
uint32 GetNearbyTileInformation(byte parameter, TileIndex tile)
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   195
{
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   196
	tile = GetNearbyTile(parameter, tile);
8954
ca1d17502817 (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: 8787
diff changeset
   197
	return GetNearbyTileInformation(tile);
7323
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   198
}
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   199
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   200
/** Structure with user-data for SearchNearbyHouseXXX - functions */
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   201
typedef struct {
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   202
	const HouseSpec *hs;  ///< Specs of the house, that startet the search
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   203
	TileIndex north_tile; ///< Northern tile of the house.
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   204
} SearchNearbyHouseData;
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   205
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   206
/** Callback function to search a house by its HouseID
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   207
 * @param tile TileIndex to be examined
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   208
 * @param user_data SearchNearbyHouseData
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   209
 * @return true or false, if found or not
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   210
 */
11075
1acf0ed0da9d (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 11072
diff changeset
   211
static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   212
{
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   213
	if (IsTileType(tile, MP_HOUSE)) {
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   214
		HouseID house = GetHouseType(tile); // tile been examined
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   215
		const HouseSpec *hs = GetHouseSpecs(house);
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   216
		if (hs->grffile != NULL) { // must be one from a grf file
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   217
			SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   218
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   219
			TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   220
			if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   221
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   222
			return hs->local_id == nbhd->hs->local_id &&  // same local id as the one requested
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   223
				hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   224
		}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   225
	}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   226
	return false;
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   227
}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   228
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   229
/** Callback function to search a house by its classID
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   230
 * @param tile TileIndex to be examined
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   231
 * @param user_data SearchNearbyHouseData
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   232
 * @return true or false, if found or not
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   233
 */
11075
1acf0ed0da9d (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 11072
diff changeset
   234
static bool SearchNearbyHouseClass(TileIndex tile, void *user_data)
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   235
{
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   236
	if (IsTileType(tile, MP_HOUSE)) {
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   237
		HouseID house = GetHouseType(tile); // tile been examined
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   238
		const HouseSpec *hs = GetHouseSpecs(house);
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   239
		if (hs->grffile != NULL) { // must be one from a grf file
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   240
			SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   241
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   242
			TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   243
			if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   244
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   245
			return hs->class_id == nbhd->hs->class_id &&  // same classid as the one requested
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   246
				hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   247
		}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   248
	}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   249
	return false;
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   250
}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   251
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   252
/** Callback function to search a house by its grfID
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   253
 * @param tile TileIndex to be examined
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   254
 * @param user_data SearchNearbyHouseData
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   255
 * @return true or false, if found or not
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   256
 */
11075
1acf0ed0da9d (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 11072
diff changeset
   257
static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data)
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   258
{
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   259
	if (IsTileType(tile, MP_HOUSE)) {
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   260
		HouseID house = GetHouseType(tile); // tile been examined
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   261
		const HouseSpec *hs = GetHouseSpecs(house);
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   262
		if (hs->grffile != NULL) { // must be one from a grf file
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   263
			SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   264
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   265
			TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   266
			if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   267
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   268
			return hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   269
		}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   270
	}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   271
	return false;
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   272
}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   273
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   274
/** This function will activate a search around a central tile, looking for some houses
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   275
 * that fit the requested characteristics
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   276
 * @param parameter that is given by the callback.
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   277
 *                  bits 0..6 radius of the search
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   278
 *                  bits 7..8 search type i.e.: 0 = houseID/ 1 = classID/ 2 = grfID
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   279
 * @param tile TileIndex from which to start the search
11075
1acf0ed0da9d (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 11072
diff changeset
   280
 * @param house the HouseID that is associated to the house, the callback is called for
1acf0ed0da9d (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 11072
diff changeset
   281
 * @return the Manhattan distance from the center tile, if any, and 0 if failure
1acf0ed0da9d (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 11072
diff changeset
   282
 */
1acf0ed0da9d (svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch
parents: 11072
diff changeset
   283
static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseID house)
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   284
{
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   285
	static TestTileOnSearchProc * const search_procs[3] = {
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   286
		SearchNearbyHouseID,
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   287
		SearchNearbyHouseClass,
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   288
		SearchNearbyHouseGRFID,
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   289
	};
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   290
	TileIndex found_tile = tile;
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   291
	uint8 searchtype = GB(parameter, 6, 2);
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   292
	uint8 searchradius = GB(parameter, 0, 6);
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   293
	if (searchtype >= lengthof(search_procs)) return 0;  // do not run on ill-defined code
11072
f7d931681bca (svn r13629) -Fix [FS#2108](r13603): diameter != radius
frosch
parents: 11047
diff changeset
   294
	if (searchradius < 1) return 0; // do not use a too low radius
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   295
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   296
	SearchNearbyHouseData nbhd;
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   297
	nbhd.hs = GetHouseSpecs(house);
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   298
	nbhd.north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   299
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   300
	/* Use a pointer for the tile to start the search. Will be required for calculating the distance*/
11077
eed344c0481e (svn r13634) -Codechange: Let house var 0x65 ignore the house, the variable is queried for.
frosch
parents: 11075
diff changeset
   301
	if (CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &nbhd)) {
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   302
		return DistanceManhattan(found_tile, tile);
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   303
	}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   304
	return 0;
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   305
}
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   306
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   307
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   308
 * HouseGetVariable():
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   309
 *
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   310
 * Used by the resolver to get values for feature 07 deterministic spritegroups.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   311
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   312
static uint32 HouseGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   313
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   314
	const Town *town = object->u.house.town;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   315
	TileIndex tile   = object->u.house.tile;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   316
	HouseID house_id = object->u.house.house_id;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   317
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   318
	if (object->scope == VSG_SCOPE_PARENT) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   319
		return TownGetVariable(variable, parameter, available, town);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   320
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   321
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   322
	switch (variable) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   323
		/* Construction stage. */
9287
2e497ff0d009 (svn r12513) -Codechange: rename OriginalTileRandomiser something more descriptive
skidd13
parents: 9252
diff changeset
   324
		case 0x40: return (IsTileType(tile, MP_HOUSE) ? GetHouseBuildingStage(tile) : 0) | TileHash2Bit(TileX(tile), TileY(tile)) << 2;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   325
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   326
		/* Building age. */
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8364
diff changeset
   327
		case 0x41: return Clamp(_cur_year - GetHouseConstructionYear(tile), 0, 0xFF);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   328
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   329
		/* Town zone */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   330
		case 0x42: return GetTownRadiusGroup(town, tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   331
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   332
		/* Terrain type */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   333
		case 0x43: return GetTerrainType(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   334
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   335
		/* Number of this type of building on the map. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   336
		case 0x44: return GetNumHouses(house_id, town);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   337
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   338
		/* Whether the town is being created or just expanded. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   339
		case 0x45: return _generating_world ? 1 : 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   340
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   341
		/* Current animation frame. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   342
		case 0x46: return IsTileType(tile, MP_HOUSE) ? GetHouseAnimationFrame(tile) : 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   343
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   344
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   345
		/* Building counts for old houses with id = parameter. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   346
		case 0x60: return GetNumHouses(parameter, town);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   347
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   348
		/* Building counts for new houses with id = parameter. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   349
		case 0x61: {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   350
			const HouseSpec *hs = GetHouseSpecs(house_id);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   351
			if (hs->grffile == NULL) return 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   352
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 6923
diff changeset
   353
			HouseID new_house = _house_mngr.GetID(parameter, hs->grffile->grfid);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   354
			return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, town);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   355
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   356
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   357
		/* Land info for nearby tiles. */
7323
b2871568db92 (svn r10066) -Codechange: Expose function GetNearbyTile by moving it to newgrf_commons.[cpp|h]. Will be used by industries in a few.
belugas
parents: 7297
diff changeset
   358
		case 0x62: return GetNearbyTileInformation(parameter, tile);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   359
10965
a2b5f6f9be0c (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 10429
diff changeset
   360
		/* Current animation frame of nearby house tiles */
a2b5f6f9be0c (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 10429
diff changeset
   361
		case 0x63: {
a2b5f6f9be0c (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 10429
diff changeset
   362
			TileIndex testtile = GetNearbyTile(parameter, tile);
a2b5f6f9be0c (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 10429
diff changeset
   363
			return IsTileType(testtile, MP_HOUSE) ? GetHouseAnimationFrame(testtile) : 0;
a2b5f6f9be0c (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 10429
diff changeset
   364
		}
a2b5f6f9be0c (svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
belugas
parents: 10429
diff changeset
   365
11047
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   366
		/* Cargo acceptance history of nearby stations */
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   367
		/*case 0x64: not implemented yet */
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   368
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   369
		/* Distance test for some house types */
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   370
		case 0x65: return GetDistanceFromNearbyHouse(parameter, tile, object->u.house.house_id);
f4e7290c23b9 (svn r13603) -Feature{newGRF]: Add var 65 in Variational Action 2 Variables for Houses.
belugas
parents: 11009
diff changeset
   371
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   372
		/* Read GRF parameter */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   373
		case 0x7F: return GetGRFParameter(object->u.house.house_id, parameter);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   374
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   375
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   376
	DEBUG(grf, 1, "Unhandled house property 0x%X", variable);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   377
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   378
	*available = false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   379
	return UINT_MAX;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   380
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   381
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   382
static const SpriteGroup *HouseResolveReal(const ResolverObject *object, const SpriteGroup *group)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   383
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   384
	/* Houses do not have 'real' groups */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   385
	return NULL;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   386
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   387
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   388
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   389
 * NewHouseResolver():
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   390
 *
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   391
 * Returns a resolver object to be used with feature 07 spritegroups.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   392
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   393
static void NewHouseResolver(ResolverObject *res, HouseID house_id, TileIndex tile, Town *town)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   394
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   395
	res->GetRandomBits = HouseGetRandomBits;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   396
	res->GetTriggers   = HouseGetTriggers;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   397
	res->SetTriggers   = HouseSetTriggers;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   398
	res->GetVariable   = HouseGetVariable;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   399
	res->ResolveReal   = HouseResolveReal;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   400
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   401
	res->u.house.tile     = tile;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   402
	res->u.house.town     = town;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   403
	res->u.house.house_id = house_id;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   404
7823
cad4dec2b899 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7410
diff changeset
   405
	res->callback        = CBID_NO_CALLBACK;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   406
	res->callback_param1 = 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   407
	res->callback_param2 = 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   408
	res->last_value      = 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   409
	res->trigger         = 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   410
	res->reseed          = 0;
9252
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 9203
diff changeset
   411
	res->count           = 0;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   412
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   413
7823
cad4dec2b899 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7410
diff changeset
   414
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile)
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   415
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   416
	ResolverObject object;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   417
	const SpriteGroup *group;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   418
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   419
	NewHouseResolver(&object, house_id, tile, town);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   420
	object.callback = callback;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   421
	object.callback_param1 = param1;
7138
feca3eff4054 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 7125
diff changeset
   422
	object.callback_param2 = param2;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   423
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   424
	group = Resolve(GetHouseSpecs(house_id)->spritegroup, &object);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   425
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   426
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   427
	return group->g.callback.result;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   428
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   429
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   430
void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte stage, HouseID house_id)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   431
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   432
	const DrawTileSprites *dts = group->g.layout.dts;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   433
	const DrawTileSeqStruct *dtss;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   434
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
   435
	SpriteID image = dts->ground.sprite;
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
   436
	SpriteID pal   = dts->ground.pal;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   437
8115
95deea94d1f5 (svn r11149) -Fix [FS#1225]: Draw building stages for new house ground sprites.
maedhros
parents: 8019
diff changeset
   438
	if (IS_CUSTOM_SPRITE(image)) image += stage;
95deea94d1f5 (svn r11149) -Fix [FS#1225]: Draw building stages for new house ground sprites.
maedhros
parents: 8019
diff changeset
   439
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   440
	if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   441
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   442
	foreach_draw_tile_seq(dtss, dts->seq) {
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8954
diff changeset
   443
		if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   444
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8954
diff changeset
   445
		image = dtss->image.sprite;
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8954
diff changeset
   446
		pal   = dtss->image.pal;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   447
11009
8dcebd74faca (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: 10965
diff changeset
   448
		/* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
8dcebd74faca (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: 10965
diff changeset
   449
		if (IsInvisibilitySet(TO_HOUSES) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
8dcebd74faca (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: 10965
diff changeset
   450
8115
95deea94d1f5 (svn r11149) -Fix [FS#1225]: Draw building stages for new house ground sprites.
maedhros
parents: 8019
diff changeset
   451
		if (IS_CUSTOM_SPRITE(image)) image += stage;
95deea94d1f5 (svn r11149) -Fix [FS#1225]: Draw building stages for new house ground sprites.
maedhros
parents: 8019
diff changeset
   452
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   453
		if ((HasBit(image, SPRITE_MODIFIER_OPAQUE) || !IsTransparencySet(TO_HOUSES)) && HasBit(image, PALETTE_MODIFIER_COLOR)) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   454
			if (pal == 0) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   455
				const HouseSpec *hs = GetHouseSpecs(house_id);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   456
				if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) {
8138
7dc73953c47e (svn r11173) -Codechange: rename some callback enums so they are more uniform.
rubidium
parents: 8115
diff changeset
   457
					uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   458
					if (callback != CALLBACK_FAILED) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   459
						/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   460
						pal = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   461
					}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   462
				} else {
9287
2e497ff0d009 (svn r12513) -Codechange: rename OriginalTileRandomiser something more descriptive
skidd13
parents: 9252
diff changeset
   463
					pal = hs->random_colour[TileHash2Bit(ti->x, ti->y)] + PALETTE_RECOLOR_START;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   464
				}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   465
			}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   466
		} else {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   467
			pal = PAL_NONE;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   468
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   469
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   470
		if ((byte)dtss->delta_z != 0x80) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   471
			AddSortableSpriteToDraw(
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   472
				image, pal,
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   473
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   474
				dtss->size_x, dtss->size_y,
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7823
diff changeset
   475
				dtss->size_z, ti->z + dtss->delta_z,
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8187
diff changeset
   476
				IsTransparencySet(TO_HOUSES)
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   477
			);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   478
		} else {
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8187
diff changeset
   479
			AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, IsTransparencySet(TO_HOUSES));
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   480
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   481
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   482
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   483
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   484
void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   485
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   486
	const HouseSpec *hs = GetHouseSpecs(house_id);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   487
	const SpriteGroup *group;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   488
	ResolverObject object;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   489
7831
5dded9b03500 (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: 7829
diff changeset
   490
	if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   491
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   492
	NewHouseResolver(&object, house_id, ti->tile, GetTownByTile(ti->tile));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   493
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   494
	group = Resolve(hs->spritegroup, &object);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   495
	if (group == NULL || group->type != SGT_TILELAYOUT) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   496
		/* XXX: This is for debugging purposes really, and shouldn't stay. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   497
		DrawGroundSprite(SPR_SHADOW_CELL, PAL_NONE);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   498
	} else {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   499
		/* Limit the building stage to the number of stages supplied. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   500
		byte stage = GetHouseBuildingStage(ti->tile);
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8364
diff changeset
   501
		stage = Clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   502
		DrawTileLayout(ti, group, stage, house_id);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   503
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   504
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   505
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   506
void AnimateNewHouseTile(TileIndex tile)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   507
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   508
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   509
	byte animation_speed = hs->animation_speed;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   510
	bool frame_set_by_callback = false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   511
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   512
	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_SPEED)) {
7138
feca3eff4054 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 7125
diff changeset
   513
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8364
diff changeset
   514
		if (callback_res != CALLBACK_FAILED) animation_speed = Clamp(callback_res & 0xFF, 2, 16);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   515
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   516
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   517
	/* An animation speed of 2 means the animation frame changes 4 ticks, and
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   518
	 * increasing this value by one doubles the wait. 2 is the minimum value
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   519
	 * allowed for animation_speed, which corresponds to 120ms, and 16 is the
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   520
	 * maximum, corresponding to around 33 minutes. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   521
	if (_tick_counter % (1 << animation_speed) != 0) return;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   522
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   523
	byte frame      = GetHouseAnimationFrame(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   524
	byte num_frames = GB(hs->animation_frames, 0, 7);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   525
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   526
	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_NEXT_FRAME)) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   527
		uint32 param = (hs->extra_flags & CALLBACK_1A_RANDOM_BITS) ? Random() : 0;
7138
feca3eff4054 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 7125
diff changeset
   528
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_NEXT_FRAME, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   529
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   530
		if (callback_res != CALLBACK_FAILED) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   531
			frame_set_by_callback = true;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   532
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   533
			switch (callback_res & 0xFF) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   534
				case 0xFF:
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   535
					DeleteAnimatedTile(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   536
					break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   537
				case 0xFE:
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   538
					/* Carry on as normal. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   539
					frame_set_by_callback = false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   540
					break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   541
				default:
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   542
					frame = callback_res & 0xFF;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   543
					break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   544
			}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   545
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   546
			/* If the lower 7 bits of the upper byte of the callback
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   547
			 * result are not empty, it is a sound effect. */
10285
ba2d207f4a26 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents: 10269
diff changeset
   548
			if (GB(callback_res, 8, 7) != 0) PlayTileSound(hs->grffile, GB(callback_res, 8, 7), tile);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   549
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   550
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   551
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   552
	if (!frame_set_by_callback) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   553
		if (frame < num_frames) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   554
			frame++;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   555
		} else if (frame == num_frames && HasBit(hs->animation_frames, 7)) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   556
			/* This animation loops, so start again from the beginning */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   557
			frame = 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   558
		} else {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   559
			/* This animation doesn't loop, so stay here */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   560
			DeleteAnimatedTile(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   561
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   562
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   563
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   564
	SetHouseAnimationFrame(tile, frame);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   565
	MarkTileDirtyByTile(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   566
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   567
10285
ba2d207f4a26 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents: 10269
diff changeset
   568
void ChangeHouseAnimationFrame(const GRFFile *file, TileIndex tile, uint16 callback_result)
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   569
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   570
	switch (callback_result & 0xFF) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   571
		case 0xFD: /* Do nothing. */         break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   572
		case 0xFE: AddAnimatedTile(tile);    break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   573
		case 0xFF: DeleteAnimatedTile(tile); break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   574
		default:
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   575
			SetHouseAnimationFrame(tile, callback_result & 0xFF);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   576
			AddAnimatedTile(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   577
			break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   578
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   579
	/* If the lower 7 bits of the upper byte of the callback
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   580
	 * result are not empty, it is a sound effect. */
10285
ba2d207f4a26 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents: 10269
diff changeset
   581
	if (GB(callback_result, 8, 7) != 0) PlayTileSound(file, GB(callback_result, 8, 7), tile);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   582
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   583
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   584
bool CanDeleteHouse(TileIndex tile)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   585
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   586
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   587
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   588
	/* Human players are always allowed to remove buildings, as is water and
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   589
	 * anyone using the scenario editor. */
11161
7d0fac8f14cd (svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents: 11077
diff changeset
   590
	if ((IsValidPlayerID(_current_player) && IsHumanPlayer(_current_player))
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   591
			|| _current_player == OWNER_WATER || _current_player == OWNER_NONE) return true;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   592
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   593
	if (HasBit(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {
7138
feca3eff4054 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 7125
diff changeset
   594
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   595
		return (callback_res == CALLBACK_FAILED || callback_res == 0);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   596
	} else {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   597
		return !(hs->extra_flags & BUILDING_IS_PROTECTED);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   598
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   599
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   600
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   601
static void AnimationControl(TileIndex tile, uint16 random_bits)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   602
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   603
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   604
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   605
	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   606
		uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
7138
feca3eff4054 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 7125
diff changeset
   607
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   608
10285
ba2d207f4a26 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents: 10269
diff changeset
   609
		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(hs->grffile, tile, callback_res);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   610
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   611
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   612
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   613
bool NewHouseTileLoop(TileIndex tile)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   614
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   615
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   616
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   617
	if (GetHouseProcessingTime(tile) > 0) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   618
		DecHouseProcessingTime(tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   619
		return true;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   620
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   621
8357
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   622
	TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP);
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   623
	TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   624
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   625
	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   626
		/* If this house is marked as having a synchronised callback, all the
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   627
		 * tiles will have the callback called at once, rather than when the
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   628
		 * tile loop reaches them. This should only be enabled for the northern
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   629
		 * tile, or strange things will happen (here, and in TTDPatch). */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   630
		if (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   631
			uint16 random = GB(Random(), 0, 16);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   632
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   633
			if (hs->building_flags & BUILDING_HAS_1_TILE)  AnimationControl(tile, random);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   634
			if (hs->building_flags & BUILDING_2_TILES_Y)   AnimationControl(TILE_ADDXY(tile, 0, 1), random);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   635
			if (hs->building_flags & BUILDING_2_TILES_X)   AnimationControl(TILE_ADDXY(tile, 1, 0), random);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   636
			if (hs->building_flags & BUILDING_HAS_4_TILES) AnimationControl(TILE_ADDXY(tile, 1, 1), random);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   637
		} else {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   638
			AnimationControl(tile, 0);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   639
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   640
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   641
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   642
	/* Check callback 21, which determines if a house should be destroyed. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   643
	if (HasBit(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) {
7138
feca3eff4054 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents: 7125
diff changeset
   644
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
10287
dd14c80bad05 (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: 10285
diff changeset
   645
		if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) > 0) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   646
			ClearTownHouse(GetTownByTile(tile), tile);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   647
			return false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   648
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   649
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   650
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   651
	SetHouseProcessingTime(tile, hs->processing_time);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   652
	return true;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   653
}
8357
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   654
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   655
static void DoTriggerHouse(TileIndex tile, HouseTrigger trigger, byte base_random, bool first)
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   656
{
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   657
	ResolverObject object;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   658
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   659
	/* We can't trigger a non-existent building... */
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   660
	assert(IsTileType(tile, MP_HOUSE));
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   661
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   662
	HouseID hid = GetHouseType(tile);
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   663
	HouseSpec *hs = GetHouseSpecs(hid);
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   664
10303
78028cd29075 (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: 10287
diff changeset
   665
	if (hs->spritegroup == NULL) return;
78028cd29075 (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: 10287
diff changeset
   666
8357
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   667
	NewHouseResolver(&object, hid, tile, GetTownByTile(tile));
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   668
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   669
	object.callback = CBID_RANDOM_TRIGGER;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   670
	object.trigger = trigger;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   671
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   672
	const SpriteGroup *group = Resolve(hs->spritegroup, &object);
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   673
	if (group == NULL) return;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   674
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   675
	byte new_random_bits = Random();
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   676
	byte random_bits = GetHouseRandomBits(tile);
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   677
	random_bits &= ~object.reseed;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   678
	random_bits |= (first ? new_random_bits : base_random) & object.reseed;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   679
	SetHouseRandomBits(tile, random_bits);
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   680
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   681
	switch (trigger) {
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   682
		case HOUSE_TRIGGER_TILE_LOOP:
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   683
			/* Random value already set. */
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   684
			break;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   685
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   686
		case HOUSE_TRIGGER_TILE_LOOP_TOP:
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   687
			if (!first) break;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   688
			/* Random value of first tile already set. */
8362
6b3ddf7a6a99 (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: 8357
diff changeset
   689
			if (hs->building_flags & BUILDING_2_TILES_Y)   DoTriggerHouse(TILE_ADDXY(tile, 0, 1), trigger, random_bits, false);
6b3ddf7a6a99 (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: 8357
diff changeset
   690
			if (hs->building_flags & BUILDING_2_TILES_X)   DoTriggerHouse(TILE_ADDXY(tile, 1, 0), trigger, random_bits, false);
6b3ddf7a6a99 (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: 8357
diff changeset
   691
			if (hs->building_flags & BUILDING_HAS_4_TILES) DoTriggerHouse(TILE_ADDXY(tile, 1, 1), trigger, random_bits, false);
8357
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   692
			break;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   693
	}
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   694
}
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   695
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   696
void TriggerHouse(TileIndex t, HouseTrigger trigger)
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   697
{
8364
1ce2fc624842 (svn r11418) -Fix (r11416): forgot an instance
glx
parents: 8362
diff changeset
   698
	DoTriggerHouse(t, trigger, 0, true);
8357
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 8345
diff changeset
   699
}