src/newgrf_town.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9203 55b0289562a8
child 10195 a4ffa2310bd8
permissions -rw-r--r--
update tags
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
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     3
/** @file newgrf_town.cpp */
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"
8766
c86cfa3a7580 (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8627
diff changeset
     7
#include "settings_type.h"
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
     8
#include "debug.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: 7652
diff changeset
     9
#include "core/bitmath_func.hpp"
9106
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    10
#include "core/math_func.hpp"
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
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    13
/** This function implements the town variables that newGRF defines.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    14
 * @param variable that is queried
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    15
 * @param parameter unused
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    16
 * @param available will return false if ever the variable asked for does not exist
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    17
 * @param t is of course the town we are inquiring
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    18
 * @return the value stored in the corresponding variable*/
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    19
uint32 TownGetVariable(byte variable, byte parameter, bool *available, const Town *t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    20
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    21
	switch (variable) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    22
		/* Larger towns */
7016
c5c554ec339b (svn r9706) -Codechange: Support NewGRF town var 40 'largertowns' variable properly.
peter1138
parents: 6658
diff changeset
    23
		case 0x40:
c5c554ec339b (svn r9706) -Codechange: Support NewGRF town var 40 'largertowns' variable properly.
peter1138
parents: 6658
diff changeset
    24
			if (_patches.larger_towns == 0) return 2;
7018
cf6ba638333e (svn r9709) -Fix (r9706): Larger towns use t->larger_towns, not the town index.
maedhros
parents: 7016
diff changeset
    25
			if (t->larger_town) return 1;
7016
c5c554ec339b (svn r9706) -Codechange: Support NewGRF town var 40 'largertowns' variable properly.
peter1138
parents: 6658
diff changeset
    26
			return 0;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    27
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    28
		/* Town index */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    29
		case 0x41: return t->index;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    30
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    31
		/* Town properties */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    32
		case 0x80: return t->xy;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    33
		case 0x81: return GB(t->xy, 8, 8);
9106
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    34
		case 0x82: return ClampToU16(t->population);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    35
		case 0x83: return GB(ClampToU16(t->population), 8, 8);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    36
		case 0x8A: return t->grow_counter;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    37
		case 0x92: return t->flags12;  // In original game, 0x92 and 0x93 are really one word. Since flags12 is a byte, this is to adjust
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    38
		case 0x93: return 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    39
		case 0x94: return t->radius[0];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    40
		case 0x95: return GB(t->radius[0], 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    41
		case 0x96: return t->radius[1];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    42
		case 0x97: return GB(t->radius[1], 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    43
		case 0x98: return t->radius[2];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    44
		case 0x99: return GB(t->radius[2], 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    45
		case 0x9A: return t->radius[3];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    46
		case 0x9B: return GB(t->radius[3], 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    47
		case 0x9C: return t->radius[4];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    48
		case 0x9D: return GB(t->radius[4], 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    49
		case 0x9E: return t->ratings[0];
9131
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    50
		case 0x9F: return GB(t->ratings[0], 8, 8);
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    51
		case 0xA0: return t->ratings[1];
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    52
		case 0xA1: return GB(t->ratings[1], 8, 8);
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    53
		case 0xA2: return t->ratings[2];
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    54
		case 0xA3: return GB(t->ratings[2], 8, 8);
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    55
		case 0xA4: return t->ratings[3];
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    56
		case 0xA5: return GB(t->ratings[3], 8, 8);
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    57
		case 0xA6: return t->ratings[4];
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    58
		case 0xA7: return GB(t->ratings[4], 8, 8);
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    59
		case 0xA8: return t->ratings[5];
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    60
		case 0xA9: return GB(t->ratings[5], 8, 8);
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    61
		case 0xAA: return t->ratings[6];
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    62
		case 0xAB: return GB(t->ratings[6], 8, 8);
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    63
		case 0xAC: return t->ratings[7];
026fc3b22eec (svn r12247) -Fix (r9315): Town variables 0x9E to 0xAD (company ratings) returned wrong values.
frosch
parents: 9106
diff changeset
    64
		case 0xAD: return GB(t->ratings[7], 8, 8);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    65
		case 0xAE: return t->have_ratings;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    66
		case 0xB2: return t->statues;
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: 9131
diff changeset
    67
		case 0xB6: return ClampToU16(t->num_houses);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    68
		case 0xB9: return t->growth_rate;
9106
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    69
		case 0xBA: return ClampToU16(t->new_max_pass);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    70
		case 0xBB: return GB(ClampToU16(t->new_max_pass), 8, 8);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    71
		case 0xBC: return ClampToU16(t->new_max_mail);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    72
		case 0xBD: return GB(ClampToU16(t->new_max_mail), 8, 8);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    73
		case 0xBE: return ClampToU16(t->new_act_pass);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    74
		case 0xBF: return GB(ClampToU16(t->new_act_pass), 8, 8);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    75
		case 0xC0: return ClampToU16(t->new_act_mail);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    76
		case 0xC1: return GB(ClampToU16(t->new_act_mail), 8, 8);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    77
		case 0xC2: return ClampToU16(t->max_pass);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    78
		case 0xC3: return GB(ClampToU16(t->max_pass), 8, 8);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    79
		case 0xC4: return ClampToU16(t->max_mail);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    80
		case 0xC5: return GB(ClampToU16(t->max_mail), 8, 8);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    81
		case 0xC6: return ClampToU16(t->act_pass);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    82
		case 0xC7: return GB(ClampToU16(t->act_pass), 8, 8);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    83
		case 0xC8: return ClampToU16(t->act_mail);
604b69ee3879 (svn r12192) -Fix: clamp various town variables to 16bit prior to returning the value
smatz
parents: 8766
diff changeset
    84
		case 0xC9: return GB(ClampToU16(t->act_mail), 8, 8);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    85
		case 0xCA: return t->pct_pass_transported;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    86
		case 0xCB: return t->pct_mail_transported;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    87
		case 0xCC: return t->new_act_food;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    88
		case 0xCD: return GB(t->new_act_food, 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    89
		case 0xCE: return t->new_act_water;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    90
		case 0xCF: return GB(t->new_act_water, 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    91
		case 0xD0: return t->act_food;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    92
		case 0xD1: return GB(t->act_food, 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    93
		case 0xD2: return t->act_water;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    94
		case 0xD3: return GB(t->act_water, 8, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    95
		case 0xD4: return t->road_build_months;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    96
		case 0xD5: return t->fund_buildings_months;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
    97
	}
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
	DEBUG(grf, 1, "Unhandled town property 0x%X", variable);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   100
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   101
	*available = false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   102
	return (uint32)-1;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
diff changeset
   103
}