# newgrf_town.cpp

Go to the documentation of this file.

    00001 /* $Id: newgrf_town.cpp 17248 2009-08-21 20:21:05Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "stdafx.h"
    00013 #include "debug.h"
    00014 #include "town.h"
    00015
    00022 uint32 TownGetVariable(byte variable, byte parameter, bool *available, const Town *t)
    00023 {
    00024   switch (variable) {
    00025     /* Larger towns */
    00026     case 0x40:
    00027       if (_settings_game.economy.larger_towns == 0) return 2;
    00028       if (t->larger_town) return 1;
    00029       return 0;
    00030
    00031     /* Town index */
    00032     case 0x41: return t->index;
    00033
    00034     /* Town properties */
    00035     case 0x80: return t->xy;
    00036     case 0x81: return GB(t->xy, 8, 8);
    00037     case 0x82: return ClampToU16(t->population);
    00038     case 0x83: return GB(ClampToU16(t->population), 8, 8);
    00039     case 0x8A: return t->grow_counter;
    00040     case 0x92: return t->flags;  // In original game, 0x92 and 0x93 are really one word. Since flags is a byte, this is to adjust
    00041     case 0x93: return 0;
    00042     case 0x94: return ClampToU16(t->squared_town_zone_radius[0]);
    00043     case 0x95: return GB(ClampToU16(t->squared_town_zone_radius[0]), 8, 8);
    00044     case 0x96: return ClampToU16(t->squared_town_zone_radius[1]);
    00045     case 0x97: return GB(ClampToU16(t->squared_town_zone_radius[1]), 8, 8);
    00046     case 0x98: return ClampToU16(t->squared_town_zone_radius[2]);
    00047     case 0x99: return GB(ClampToU16(t->squared_town_zone_radius[2]), 8, 8);
    00048     case 0x9A: return ClampToU16(t->squared_town_zone_radius[3]);
    00049     case 0x9B: return GB(ClampToU16(t->squared_town_zone_radius[3]), 8, 8);
    00050     case 0x9C: return ClampToU16(t->squared_town_zone_radius[4]);
    00051     case 0x9D: return GB(ClampToU16(t->squared_town_zone_radius[4]), 8, 8);
    00052     case 0x9E: return t->ratings[0];
    00053     case 0x9F: return GB(t->ratings[0], 8, 8);
    00054     case 0xA0: return t->ratings[1];
    00055     case 0xA1: return GB(t->ratings[1], 8, 8);
    00056     case 0xA2: return t->ratings[2];
    00057     case 0xA3: return GB(t->ratings[2], 8, 8);
    00058     case 0xA4: return t->ratings[3];
    00059     case 0xA5: return GB(t->ratings[3], 8, 8);
    00060     case 0xA6: return t->ratings[4];
    00061     case 0xA7: return GB(t->ratings[4], 8, 8);
    00062     case 0xA8: return t->ratings[5];
    00063     case 0xA9: return GB(t->ratings[5], 8, 8);
    00064     case 0xAA: return t->ratings[6];
    00065     case 0xAB: return GB(t->ratings[6], 8, 8);
    00066     case 0xAC: return t->ratings[7];
    00067     case 0xAD: return GB(t->ratings[7], 8, 8);
    00068     case 0xAE: return t->have_ratings;
    00069     case 0xB2: return t->statues;
    00070     case 0xB6: return ClampToU16(t->num_houses);
    00071     case 0xB9: return t->growth_rate;
    00072     case 0xBA: return ClampToU16(t->new_max_pass);
    00073     case 0xBB: return GB(ClampToU16(t->new_max_pass), 8, 8);
    00074     case 0xBC: return ClampToU16(t->new_max_mail);
    00075     case 0xBD: return GB(ClampToU16(t->new_max_mail), 8, 8);
    00076     case 0xBE: return ClampToU16(t->new_act_pass);
    00077     case 0xBF: return GB(ClampToU16(t->new_act_pass), 8, 8);
    00078     case 0xC0: return ClampToU16(t->new_act_mail);
    00079     case 0xC1: return GB(ClampToU16(t->new_act_mail), 8, 8);
    00080     case 0xC2: return ClampToU16(t->max_pass);
    00081     case 0xC3: return GB(ClampToU16(t->max_pass), 8, 8);
    00082     case 0xC4: return ClampToU16(t->max_mail);
    00083     case 0xC5: return GB(ClampToU16(t->max_mail), 8, 8);
    00084     case 0xC6: return ClampToU16(t->act_pass);
    00085     case 0xC7: return GB(ClampToU16(t->act_pass), 8, 8);
    00086     case 0xC8: return ClampToU16(t->act_mail);
    00087     case 0xC9: return GB(ClampToU16(t->act_mail), 8, 8);
    00088     case 0xCA: return t->pct_pass_transported;
    00089     case 0xCB: return t->pct_mail_transported;
    00090     case 0xCC: return t->new_act_food;
    00091     case 0xCD: return GB(t->new_act_food, 8, 8);
    00092     case 0xCE: return t->new_act_water;
    00093     case 0xCF: return GB(t->new_act_water, 8, 8);
    00094     case 0xD0: return t->act_food;
    00095     case 0xD1: return GB(t->act_food, 8, 8);
    00096     case 0xD2: return t->act_water;
    00097     case 0xD3: return GB(t->act_water, 8, 8);
    00098     case 0xD4: return t->road_build_months;
    00099     case 0xD5: return t->fund_buildings_months;
    00100   }
    00101
    00102   DEBUG(grf, 1, "Unhandled town property 0x%X", variable);
    00103
    00104   *available = false;
    00105   return UINT_MAX;
    00106 }