# town_gui.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "debug.h"`
`#include "town.h"`
`#include "viewport_func.h"`
`#include "gfx_func.h"`
`#include "gui.h"`
`#include "window_gui.h"`
`#include "textbuf_gui.h"`
`#include "command_func.h"`
`#include "player_func.h"`
`#include "player_base.h"`
`#include "player_gui.h"`
`#include "network/network.h"`
`#include "variables.h"`
`#include "strings_func.h"`
`#include "economy_func.h"`
`#include "core/alloc_func.hpp"`
`#include "settings_type.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Enumerations

enum | TownAuthorityWidget { TWA_CLOSEBOX = 0, TWA_CAPTION, TWA_RATING_INFO, TWA_COMMAND_LIST, TWA_SCROLLBAR, TWA_ACTION_INFO, TWA_EXECUTE }

enum

TownActions {
TACT_NONE = 0x00, TACT_ADVERTISE_SMALL = 0x01, TACT_ADVERTISE_MEDIUM = 0x02, TACT_ADVERTISE_LARGE = 0x04,
TACT_ROAD_REBUILD = 0x08, TACT_BUILD_STATUE = 0x10, TACT_FOUND_BUILDINGS = 0x20, TACT_BUY_RIGHTS = 0x40,
TACT_BRIBE = 0x80, TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE, TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS, TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE,
TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS
}

enum | TownDirectoryWidget { TDW_SORTNAME = 3, TDW_SORTPOPULATION, TDW_CENTERTOWN }

## Functions

| DECLARE_ENUM_AS_BIT_SET (TownActions)
uint | GetMaskOfTownActions (int *nump, PlayerID pid, const Town *t)
| Get a list of available actions to do at a town.
static int | GetNthSetBit (uint32 bits, int n)
| Get the position of the Nth set bit.
static void | TownAuthorityWndProc (Window *w, WindowEvent *e)
static void | ShowTownAuthorityWindow (uint town)
static void | TownViewWndProc (Window *w, WindowEvent *e)
void | ShowTownViewWindow (TownID town)
static int CDECL | TownNameSorter (const void *a, const void *b)
static int CDECL | TownPopSorter (const void *a, const void *b)
static void | MakeSortedTownList ()
static void | TownDirectoryWndProc (Window *w, WindowEvent *e)
void | ShowTownDirectory ()

## Variables

static const Widget | _town_authority_widgets []
const byte | _town_action_costs [8]
static const WindowDesc | _town_authority_desc
static const Widget | _town_view_widgets []
static const WindowDesc | _town_view_desc
static const Widget | _town_view_scen_widgets []
static const WindowDesc | _town_view_scen_desc
static const Widget | _town_directory_widgets []
static uint | _num_town_sort
static char | _bufcache [64]
static const Town * | _last_town
static const WindowDesc | _town_directory_desc

## Detailed Description

Definition in file town_gui.cpp.

## Function Documentation

uint GetMaskOfTownActions | ( | int * | nump,
|  | PlayerID | pid,
|  | const Town * | t |
| ) |  |  |

Get a list of available actions to do at a town.

Parameters:

  | nump | if not NULL add put the number of available actions in it
  | pid | the player that is querying the town
  | t | the town that is queried

Returns:
  bitmasked value of enabled actions

Definition at line 77 of file town_gui.cpp.

References HasBit(), and PLAYER_SPECTATOR.

Referenced by CmdDoTownAction(), and TownAuthorityWndProc().

static int GetNthSetBit | ( | uint32 | bits,
|  | int | n |
| ) |  |  | `[static]`

Get the position of the Nth set bit.

If there is no Nth bit set return -1

Parameters:

  | bits | The value to search in
  | n | The Nth set bit from which we want to know the position

Returns:
  The position of the Nth set bit

Definition at line 126 of file town_gui.cpp.

References FOR_EACH_SET_BIT.

Referenced by TownAuthorityWndProc().

static void TownAuthorityWndProc | ( | Window * | w,
|  | WindowEvent * | e |
| ) |  |  | `[static]`

< Draw only the 5 fitting lines

Definition at line 138 of file town_gui.cpp.

References CMD_DO_TOWN_ACTION, CMD_MSG, DoCommandP(), GetMaskOfTownActions(), GetNthSetBit(), HasBit(), IsInsideMM(), and SetWindowDirty().

## Variable Documentation

const WindowDesc _town_authority_desc`[static]`

Initial value:

     {
      WDP_AUTO, WDP_AUTO, 317, 222, 317, 222,
      WC_TOWN_AUTHORITY, WC_NONE,
      WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
      _town_authority_widgets,
      TownAuthorityWndProc
    }

Definition at line 255 of file town_gui.cpp.

const Widget _town_authority_widgets[]`[static]`

Initial value:

     {
    {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
    {    WWT_CAPTION,   RESIZE_NONE,    13,    11,   316,     0,    13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS},
    {      WWT_PANEL,   RESIZE_NONE,    13,     0,   316,    14,   105, 0x0,                      STR_NULL},
    {      WWT_PANEL,   RESIZE_NONE,    13,     0,   304,   106,   157, 0x0,                      STR_2043_LIST_OF_THINGS_TO_DO_AT},
    {  WWT_SCROLLBAR,   RESIZE_NONE,    13,   305,   316,   106,   157, 0x0,                      STR_0190_SCROLL_BAR_SCROLLS_LIST},
    {      WWT_PANEL,   RESIZE_NONE,    13,     0,   316,   158,   209, 0x0,                      STR_NULL},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,   316,   210,   221, STR_2042_DO_IT,           STR_2044_CARRY_OUT_THE_HIGHLIGHTED},
    {   WIDGETS_END},
    }

Definition at line 38 of file town_gui.cpp.

const WindowDesc _town_directory_desc`[static]`

Initial value:

     {
      WDP_AUTO, WDP_AUTO, 208, 202, 208, 202,
      WC_TOWN_DIRECTORY, WC_NONE,
      WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
      _town_directory_widgets,
      TownDirectoryWndProc
    }

Definition at line 555 of file town_gui.cpp.

const Widget _town_directory_widgets[]`[static]`

Initial value:

     {
    {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
    {    WWT_CAPTION,   RESIZE_NONE,    13,    11,   195,     0,    13, STR_2000_TOWNS,         STR_018C_WINDOW_TITLE_DRAG_THIS},
    {  WWT_STICKYBOX,   RESIZE_NONE,    13,   196,   207,     0,    13, 0x0,                    STR_STICKY_BUTTON},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    98,    14,    25, STR_SORT_BY_NAME,       STR_SORT_ORDER_TIP},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    99,   195,    14,    25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP},
    {      WWT_PANEL, RESIZE_BOTTOM,    13,     0,   195,    26,   189, 0x0,                    STR_200A_TOWN_NAMES_CLICK_ON_NAME},
    {  WWT_SCROLLBAR, RESIZE_BOTTOM,    13,   196,   207,    14,   189, 0x0,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
    {      WWT_PANEL,     RESIZE_TB,    13,     0,   195,   190,   201, 0x0,                    STR_NULL},
    {  WWT_RESIZEBOX,     RESIZE_TB,    13,   196,   207,   190,   201, 0x0,                    STR_RESIZE_BUTTON},
    {   WIDGETS_END},
    }

Definition at line 404 of file town_gui.cpp.

const WindowDesc _town_view_desc`[static]`

Initial value:

     {
      WDP_AUTO, WDP_AUTO, 260, 150, 260, 150,
      WC_TOWN_VIEW, WC_NONE,
      WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
      _town_view_widgets,
      TownViewWndProc
    }

Definition at line 352 of file town_gui.cpp.

const WindowDesc _town_view_scen_desc`[static]`

Initial value:

     {
      WDP_AUTO, WDP_AUTO, 260, 150, 260, 150,
      WC_TOWN_VIEW, WC_NONE,
      WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
      _town_view_scen_widgets,
      TownViewWndProc
    }

Definition at line 375 of file town_gui.cpp.

const Widget _town_view_scen_widgets[]`[static]`

Initial value:

     {
    {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},
    {    WWT_CAPTION,   RESIZE_NONE,    13,    11,   172,     0,    13, STR_2005,          STR_018C_WINDOW_TITLE_DRAG_THIS},
    {  WWT_STICKYBOX,   RESIZE_NONE,    13,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},
    {      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,    14,   105, 0x0,               STR_NULL},
    {      WWT_INSET,   RESIZE_NONE,    13,     2,   257,    16,   103, 0x0,               STR_NULL},
    {      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,   106,   137, 0x0,               STR_NULL},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    85,   138,   149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON},
    {      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,               STR_NULL},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   173,   247,     0,    13, STR_0130_RENAME,   STR_200C_CHANGE_TOWN_NAME},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    86,   171,   138,   149, STR_023C_EXPAND,   STR_023B_INCREASE_SIZE_OF_TOWN},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   172,   259,   138,   149, STR_0290_DELETE,   STR_0291_DELETE_THIS_TOWN_COMPLETELY},
    {   WIDGETS_END},
    }

Definition at line 360 of file town_gui.cpp.

const Widget _town_view_widgets[]`[static]`

Initial value:

     {
    {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
    {    WWT_CAPTION,   RESIZE_NONE,    13,    11,   247,     0,    13, STR_2005,                 STR_018C_WINDOW_TITLE_DRAG_THIS},
    {  WWT_STICKYBOX,   RESIZE_NONE,    13,   248,   259,     0,    13, 0x0,                      STR_STICKY_BUTTON},
    {      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,    14,   105, 0x0,                      STR_NULL},
    {      WWT_INSET,   RESIZE_NONE,    13,     2,   257,    16,   103, 0x0,                      STR_NULL},
    {      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,   106,   137, 0x0,                      STR_NULL},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    85,   138,   149, STR_00E4_LOCATION,        STR_200B_CENTER_THE_MAIN_VIEW_ON},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    86,   171,   138,   149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL},
    { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   172,   259,   138,   149, STR_0130_RENAME,          STR_200C_CHANGE_TOWN_NAME},
    {   WIDGETS_END},
    }

Definition at line 339 of file town_gui.cpp.