maedhros@6658: /* $Id$ */ maedhros@6658: rubidium@10429: /** @file newgrf_town.cpp Implementation of the town part of NewGRF houses. */ maedhros@6658: maedhros@6658: #include "stdafx.h" maedhros@6658: #include "openttd.h" rubidium@8766: #include "settings_type.h" maedhros@6658: #include "debug.h" rubidium@8627: #include "core/bitmath_func.hpp" smatz@9106: #include "core/math_func.hpp" maedhros@6658: #include "town.h" maedhros@6658: maedhros@6658: /** This function implements the town variables that newGRF defines. maedhros@6658: * @param variable that is queried maedhros@6658: * @param parameter unused maedhros@6658: * @param available will return false if ever the variable asked for does not exist maedhros@6658: * @param t is of course the town we are inquiring maedhros@6658: * @return the value stored in the corresponding variable*/ maedhros@6658: uint32 TownGetVariable(byte variable, byte parameter, bool *available, const Town *t) maedhros@6658: { maedhros@6658: switch (variable) { maedhros@6658: /* Larger towns */ peter1138@7016: case 0x40: rubidium@10775: if (_settings_game.economy.larger_towns == 0) return 2; maedhros@7018: if (t->larger_town) return 1; peter1138@7016: return 0; maedhros@6658: maedhros@6658: /* Town index */ maedhros@6658: case 0x41: return t->index; maedhros@6658: maedhros@6658: /* Town properties */ maedhros@6658: case 0x80: return t->xy; maedhros@6658: case 0x81: return GB(t->xy, 8, 8); smatz@9106: case 0x82: return ClampToU16(t->population); smatz@9106: case 0x83: return GB(ClampToU16(t->population), 8, 8); maedhros@6658: case 0x8A: return t->grow_counter; maedhros@6658: case 0x92: return t->flags12; // In original game, 0x92 and 0x93 are really one word. Since flags12 is a byte, this is to adjust maedhros@6658: case 0x93: return 0; rubidium@10195: case 0x94: return ClampToU16(t->squared_town_zone_radius[0]); rubidium@10195: case 0x95: return GB(ClampToU16(t->squared_town_zone_radius[0]), 8, 8); rubidium@10195: case 0x96: return ClampToU16(t->squared_town_zone_radius[1]); rubidium@10195: case 0x97: return GB(ClampToU16(t->squared_town_zone_radius[1]), 8, 8); rubidium@10195: case 0x98: return ClampToU16(t->squared_town_zone_radius[2]); rubidium@10195: case 0x99: return GB(ClampToU16(t->squared_town_zone_radius[2]), 8, 8); rubidium@10195: case 0x9A: return ClampToU16(t->squared_town_zone_radius[3]); rubidium@10195: case 0x9B: return GB(ClampToU16(t->squared_town_zone_radius[3]), 8, 8); rubidium@10195: case 0x9C: return ClampToU16(t->squared_town_zone_radius[4]); rubidium@10195: case 0x9D: return GB(ClampToU16(t->squared_town_zone_radius[4]), 8, 8); maedhros@6658: case 0x9E: return t->ratings[0]; frosch@9131: case 0x9F: return GB(t->ratings[0], 8, 8); frosch@9131: case 0xA0: return t->ratings[1]; frosch@9131: case 0xA1: return GB(t->ratings[1], 8, 8); frosch@9131: case 0xA2: return t->ratings[2]; frosch@9131: case 0xA3: return GB(t->ratings[2], 8, 8); frosch@9131: case 0xA4: return t->ratings[3]; frosch@9131: case 0xA5: return GB(t->ratings[3], 8, 8); frosch@9131: case 0xA6: return t->ratings[4]; frosch@9131: case 0xA7: return GB(t->ratings[4], 8, 8); frosch@9131: case 0xA8: return t->ratings[5]; frosch@9131: case 0xA9: return GB(t->ratings[5], 8, 8); frosch@9131: case 0xAA: return t->ratings[6]; frosch@9131: case 0xAB: return GB(t->ratings[6], 8, 8); frosch@9131: case 0xAC: return t->ratings[7]; frosch@9131: case 0xAD: return GB(t->ratings[7], 8, 8); maedhros@6658: case 0xAE: return t->have_ratings; maedhros@6658: case 0xB2: return t->statues; skidd13@9203: case 0xB6: return ClampToU16(t->num_houses); maedhros@6658: case 0xB9: return t->growth_rate; smatz@9106: case 0xBA: return ClampToU16(t->new_max_pass); smatz@9106: case 0xBB: return GB(ClampToU16(t->new_max_pass), 8, 8); smatz@9106: case 0xBC: return ClampToU16(t->new_max_mail); smatz@9106: case 0xBD: return GB(ClampToU16(t->new_max_mail), 8, 8); smatz@9106: case 0xBE: return ClampToU16(t->new_act_pass); smatz@9106: case 0xBF: return GB(ClampToU16(t->new_act_pass), 8, 8); smatz@9106: case 0xC0: return ClampToU16(t->new_act_mail); smatz@9106: case 0xC1: return GB(ClampToU16(t->new_act_mail), 8, 8); smatz@9106: case 0xC2: return ClampToU16(t->max_pass); smatz@9106: case 0xC3: return GB(ClampToU16(t->max_pass), 8, 8); smatz@9106: case 0xC4: return ClampToU16(t->max_mail); smatz@9106: case 0xC5: return GB(ClampToU16(t->max_mail), 8, 8); smatz@9106: case 0xC6: return ClampToU16(t->act_pass); smatz@9106: case 0xC7: return GB(ClampToU16(t->act_pass), 8, 8); smatz@9106: case 0xC8: return ClampToU16(t->act_mail); smatz@9106: case 0xC9: return GB(ClampToU16(t->act_mail), 8, 8); maedhros@6658: case 0xCA: return t->pct_pass_transported; maedhros@6658: case 0xCB: return t->pct_mail_transported; maedhros@6658: case 0xCC: return t->new_act_food; maedhros@6658: case 0xCD: return GB(t->new_act_food, 8, 8); maedhros@6658: case 0xCE: return t->new_act_water; maedhros@6658: case 0xCF: return GB(t->new_act_water, 8, 8); maedhros@6658: case 0xD0: return t->act_food; maedhros@6658: case 0xD1: return GB(t->act_food, 8, 8); maedhros@6658: case 0xD2: return t->act_water; maedhros@6658: case 0xD3: return GB(t->act_water, 8, 8); maedhros@6658: case 0xD4: return t->road_build_months; maedhros@6658: case 0xD5: return t->fund_buildings_months; maedhros@6658: } maedhros@6658: maedhros@6658: DEBUG(grf, 1, "Unhandled town property 0x%X", variable); maedhros@6658: maedhros@6658: *available = false; maedhros@6658: return (uint32)-1; maedhros@6658: }