src/player_gui.cpp
changeset 10207 c291a21b304e
parent 10151 0dd6c35bf0cc
equal deleted inserted replaced
10206:0050610c0368 10207:c291a21b304e
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 /** @file player_gui.cpp Player related GUIs. */
     3 /** @file company_gui.cpp Company related GUIs. */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "gui.h"
     7 #include "gui.h"
     8 #include "window_gui.h"
     8 #include "window_gui.h"
    35 
    35 
    36 enum {
    36 enum {
    37 	FIRST_GUI_CALL = INT_MAX,  ///< default value to specify thuis is the first call of the resizable gui
    37 	FIRST_GUI_CALL = INT_MAX,  ///< default value to specify thuis is the first call of the resizable gui
    38 };
    38 };
    39 
    39 
    40 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
    40 static void DoShowCompanyFinances(CompanyID company, bool show_small, bool show_stickied, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
    41 static void DoSelectPlayerFace(Window *parent, bool show_big, int top =  FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
    41 static void DoSelectCompanyManagerFace(Window *parent, bool show_big, int top =  FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
    42 
    42 
    43 static void DrawPlayerEconomyStats(const Player *p, bool small)
    43 static void DrawCompanyEconomyStats(const Company *c, bool small)
    44 {
    44 {
    45 	int x, y, i, j, year;
    45 	int x, y, i, j, year;
    46 	const Money (*tbl)[EXPENSES_END];
    46 	const Money (*tbl)[EXPENSES_END];
    47 	Money sum, cost;
    47 	Money sum, cost;
    48 	StringID str;
    48 	StringID str;
    56 
    56 
    57 		/* draw the price columns */
    57 		/* draw the price columns */
    58 		year = _cur_year - 2;
    58 		year = _cur_year - 2;
    59 		j = 3;
    59 		j = 3;
    60 		x = 215;
    60 		x = 215;
    61 		tbl = p->yearly_expenses + 2;
    61 		tbl = c->yearly_expenses + 2;
    62 		do {
    62 		do {
    63 			if (year >= p->inaugurated_year) {
    63 			if (year >= c->inaugurated_year) {
    64 				SetDParam(0, year);
    64 				SetDParam(0, year);
    65 				DrawStringRightAlignedUnderline(x, 15, STR_7010, TC_FROMSTRING);
    65 				DrawStringRightAlignedUnderline(x, 15, STR_7010, TC_FROMSTRING);
    66 				sum = 0;
    66 				sum = 0;
    67 				for (i = 0; i != EXPENSES_END; i++) {
    67 				for (i = 0; i != EXPENSES_END; i++) {
    68 					/* draw one row in the price column */
    68 					/* draw one row in the price column */
    97 	} else {
    97 	} else {
    98 		y = 15;
    98 		y = 15;
    99 	}
    99 	}
   100 
   100 
   101 	DrawString(2, y, STR_7026_BANK_BALANCE, TC_FROMSTRING);
   101 	DrawString(2, y, STR_7026_BANK_BALANCE, TC_FROMSTRING);
   102 	SetDParam(0, p->player_money);
   102 	SetDParam(0, c->money);
   103 	DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
   103 	DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
   104 
   104 
   105 	y += 10;
   105 	y += 10;
   106 
   106 
   107 	DrawString(2, y, STR_7027_LOAN, TC_FROMSTRING);
   107 	DrawString(2, y, STR_7027_LOAN, TC_FROMSTRING);
   108 	SetDParam(0, p->current_loan);
   108 	SetDParam(0, c->current_loan);
   109 	DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
   109 	DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
   110 
   110 
   111 	y += 12;
   111 	y += 12;
   112 
   112 
   113 	GfxFillRect(182 - 75, y - 2, 182, y - 2, 215);
   113 	GfxFillRect(182 - 75, y - 2, 182, y - 2, 215);
   114 
   114 
   115 	SetDParam(0, p->player_money - p->current_loan);
   115 	SetDParam(0, c->money - c->current_loan);
   116 	DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
   116 	DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
   117 }
   117 }
   118 
   118 
   119 enum PlayerFinancesWindowWidgets {
   119 enum CompanyFinancesWindowWidgets {
   120 	PFW_WIDGET_TOGGLE_SIZE   = 2,
   120 	CFW_WIDGET_TOGGLE_SIZE   = 2,
   121 	PFW_WIDGET_INCREASE_LOAN = 6,
   121 	CFW_WIDGET_INCREASE_LOAN = 6,
   122 	PFW_WIDGET_REPAY_LOAN    = 7,
   122 	CFW_WIDGET_REPAY_LOAN    = 7,
   123 };
   123 };
   124 
   124 
   125 static const Widget _player_finances_widgets[] = {
   125 static const Widget _company_finances_widgets[] = {
   126 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
   126 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
   127 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   379,     0,    13, STR_700E_FINANCES,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   127 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   379,     0,    13, STR_700E_FINANCES,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   128 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_GREY,   380,   394,     0,    13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
   128 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_GREY,   380,   394,     0,    13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
   129 {  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_GREY,   395,   406,     0,    13, 0x0,                    STR_STICKY_BUTTON},
   129 {  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_GREY,   395,   406,     0,    13, 0x0,                    STR_STICKY_BUTTON},
   130 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   406,    14, 39 + 10 * EXPENSES_END, 0x0,    STR_NULL},
   130 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   406,    14, 39 + 10 * EXPENSES_END, 0x0,    STR_NULL},
   132 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,   202, 74 + 10 * EXPENSES_END, 85 + 10 * EXPENSES_END, STR_7029_BORROW,        STR_7035_INCREASE_SIZE_OF_LOAN},
   132 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,   202, 74 + 10 * EXPENSES_END, 85 + 10 * EXPENSES_END, STR_7029_BORROW,        STR_7035_INCREASE_SIZE_OF_LOAN},
   133 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   203,   406, 74 + 10 * EXPENSES_END, 85 + 10 * EXPENSES_END, STR_702A_REPAY,         STR_7036_REPAY_PART_OF_LOAN},
   133 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   203,   406, 74 + 10 * EXPENSES_END, 85 + 10 * EXPENSES_END, STR_702A_REPAY,         STR_7036_REPAY_PART_OF_LOAN},
   134 {   WIDGETS_END},
   134 {   WIDGETS_END},
   135 };
   135 };
   136 
   136 
   137 static const Widget _player_finances_small_widgets[] = {
   137 static const Widget _company_finances_small_widgets[] = {
   138 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
   138 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
   139 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   253,     0,    13, STR_700E_FINANCES,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   139 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   253,     0,    13, STR_700E_FINANCES,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   140 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_GREY,   254,   267,     0,    13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
   140 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_GREY,   254,   267,     0,    13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
   141 {  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_GREY,   268,   279,     0,    13, 0x0,                    STR_STICKY_BUTTON},
   141 {  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_GREY,   268,   279,     0,    13, 0x0,                    STR_STICKY_BUTTON},
   142 {      WWT_EMPTY,   RESIZE_NONE,  COLOUR_GREY,     0,     0,     0,     0, 0x0,                    STR_NULL},
   142 {      WWT_EMPTY,   RESIZE_NONE,  COLOUR_GREY,     0,     0,     0,     0, 0x0,                    STR_NULL},
   144 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,   139,    48,    59, STR_7029_BORROW,        STR_7035_INCREASE_SIZE_OF_LOAN},
   144 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,   139,    48,    59, STR_7029_BORROW,        STR_7035_INCREASE_SIZE_OF_LOAN},
   145 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   140,   279,    48,    59, STR_702A_REPAY,         STR_7036_REPAY_PART_OF_LOAN},
   145 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   140,   279,    48,    59, STR_702A_REPAY,         STR_7036_REPAY_PART_OF_LOAN},
   146 {   WIDGETS_END},
   146 {   WIDGETS_END},
   147 };
   147 };
   148 
   148 
   149 struct PlayerFinancesWindow : Window {
   149 struct CompanyFinancesWindow : Window {
   150 	bool small;
   150 	bool small;
   151 
   151 
   152 	PlayerFinancesWindow(const WindowDesc *desc, PlayerID player, bool show_small,
   152 	CompanyFinancesWindow(const WindowDesc *desc, CompanyID company, bool show_small,
   153 					bool show_stickied, int top, int left) :
   153 					bool show_stickied, int top, int left) :
   154 			Window(desc, player),
   154 			Window(desc, company),
   155 			small(show_small)
   155 			small(show_small)
   156 	{
   156 	{
   157 		this->caption_color = this->window_number;
   157 		this->caption_color = this->window_number;
   158 
   158 
   159 		if (show_stickied) this->flags4 |= WF_STICKY;
   159 		if (show_stickied) this->flags4 |= WF_STICKY;
   167 		this->FindWindowPlacementAndResize(desc);
   167 		this->FindWindowPlacementAndResize(desc);
   168 	}
   168 	}
   169 
   169 
   170 	virtual void OnPaint()
   170 	virtual void OnPaint()
   171 	{
   171 	{
   172 		PlayerID player = (PlayerID)this->window_number;
   172 		CompanyID company = (CompanyID)this->window_number;
   173 		const Player *p = GetPlayer(player);
   173 		const Company *c = GetCompany(company);
   174 
   174 
   175 		/* Recheck the size of the window as it might need to be resized due to the local player changing */
   175 		/* Recheck the size of the window as it might need to be resized due to the local company changing */
   176 		int new_height = ((player != _local_player) ? 0 : 12) + ((this->small != 0) ? 48 : 74 + 10 * EXPENSES_END);
   176 		int new_height = ((company != _local_company) ? 0 : 12) + ((this->small != 0) ? 48 : 74 + 10 * EXPENSES_END);
   177 		if (this->height != new_height) {
   177 		if (this->height != new_height) {
   178 			/* Make window dirty before and after resizing */
   178 			/* Make window dirty before and after resizing */
   179 			this->SetDirty();
   179 			this->SetDirty();
   180 			this->height = new_height;
   180 			this->height = new_height;
   181 			this->SetDirty();
   181 			this->SetDirty();
   182 
   182 
   183 			this->SetWidgetHiddenState(PFW_WIDGET_INCREASE_LOAN, player != _local_player);
   183 			this->SetWidgetHiddenState(CFW_WIDGET_INCREASE_LOAN, company != _local_company);
   184 			this->SetWidgetHiddenState(PFW_WIDGET_REPAY_LOAN,    player != _local_player);
   184 			this->SetWidgetHiddenState(CFW_WIDGET_REPAY_LOAN,    company != _local_company);
   185 		}
   185 		}
   186 
   186 
   187 		/* Borrow button only shows when there is any more money to loan */
   187 		/* Borrow button only shows when there is any more money to loan */
   188 		this->SetWidgetDisabledState(PFW_WIDGET_INCREASE_LOAN, p->current_loan == _economy.max_loan);
   188 		this->SetWidgetDisabledState(CFW_WIDGET_INCREASE_LOAN, c->current_loan == _economy.max_loan);
   189 
   189 
   190 		/* Repay button only shows when there is any more money to repay */
   190 		/* Repay button only shows when there is any more money to repay */
   191 		this->SetWidgetDisabledState(PFW_WIDGET_REPAY_LOAN, player != _local_player || p->current_loan == 0);
   191 		this->SetWidgetDisabledState(CFW_WIDGET_REPAY_LOAN, company != _local_company || c->current_loan == 0);
   192 
   192 
   193 		SetDParam(0, p->index);
   193 		SetDParam(0, c->index);
   194 		SetDParam(1, p->index);
   194 		SetDParam(1, c->index);
   195 		SetDParam(2, LOAN_INTERVAL);
   195 		SetDParam(2, LOAN_INTERVAL);
   196 		this->DrawWidgets();
   196 		this->DrawWidgets();
   197 
   197 
   198 		DrawPlayerEconomyStats(p, this->small);
   198 		DrawCompanyEconomyStats(c, this->small);
   199 	}
   199 	}
   200 
   200 
   201 	virtual void OnClick(Point pt, int widget)
   201 	virtual void OnClick(Point pt, int widget)
   202 	{
   202 	{
   203 		switch (widget) {
   203 		switch (widget) {
   204 			case PFW_WIDGET_TOGGLE_SIZE: {/* toggle size */
   204 			case CFW_WIDGET_TOGGLE_SIZE: {/* toggle size */
   205 				bool new_mode = !this->small;
   205 				bool new_mode = !this->small;
   206 				bool stickied = !!(this->flags4 & WF_STICKY);
   206 				bool stickied = !!(this->flags4 & WF_STICKY);
   207 				int oldtop = this->top;   ///< current top position of the window before closing it
   207 				int oldtop = this->top;   ///< current top position of the window before closing it
   208 				int oldleft = this->left; ///< current left position of the window before closing it
   208 				int oldleft = this->left; ///< current left position of the window before closing it
   209 				PlayerID player = (PlayerID)this->window_number;
   209 				CompanyID company = (CompanyID)this->window_number;
   210 
   210 
   211 				delete this;
   211 				delete this;
   212 				/* Open up the (toggled size) Finance window at the same position as the previous */
   212 				/* Open up the (toggled size) Finance window at the same position as the previous */
   213 				DoShowPlayerFinances(player, new_mode, stickied, oldtop, oldleft);
   213 				DoShowCompanyFinances(company, new_mode, stickied, oldtop, oldleft);
   214 			}
   214 			}
   215 			break;
   215 			break;
   216 
   216 
   217 			case PFW_WIDGET_INCREASE_LOAN: /* increase loan */
   217 			case CFW_WIDGET_INCREASE_LOAN: /* increase loan */
   218 				DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
   218 				DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
   219 				break;
   219 				break;
   220 
   220 
   221 			case PFW_WIDGET_REPAY_LOAN: /* repay loan */
   221 			case CFW_WIDGET_REPAY_LOAN: /* repay loan */
   222 				DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
   222 				DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
   223 				break;
   223 				break;
   224 		}
   224 		}
   225 	}
   225 	}
   226 };
   226 };
   227 
   227 
   228 static const WindowDesc _player_finances_desc = {
   228 static const WindowDesc _company_finances_desc = {
   229 	WDP_AUTO, WDP_AUTO, 407, 86 + 10 * EXPENSES_END, 407, 86 + 10 * EXPENSES_END,
   229 	WDP_AUTO, WDP_AUTO, 407, 86 + 10 * EXPENSES_END, 407, 86 + 10 * EXPENSES_END,
   230 	WC_FINANCES, WC_NONE,
   230 	WC_FINANCES, WC_NONE,
   231 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
   231 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
   232 	_player_finances_widgets,
   232 	_company_finances_widgets,
   233 };
   233 };
   234 
   234 
   235 static const WindowDesc _player_finances_small_desc = {
   235 static const WindowDesc _company_finances_small_desc = {
   236 	WDP_AUTO, WDP_AUTO, 280, 60, 280, 60,
   236 	WDP_AUTO, WDP_AUTO, 280, 60, 280, 60,
   237 	WC_FINANCES, WC_NONE,
   237 	WC_FINANCES, WC_NONE,
   238 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
   238 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
   239 	_player_finances_small_widgets,
   239 	_company_finances_small_widgets,
   240 };
   240 };
   241 
   241 
   242 /**
   242 /**
   243  * Open the small/large finance window of the player
   243  * Open the small/large finance window of the company
   244  *
   244  *
   245  * @param player         the player who's finances are requested to be seen
   245  * @param company        the company who's finances are requested to be seen
   246  * @param show_small     show large or small version opf the window
   246  * @param show_small     show large or small version opf the window
   247  * @param show_stickied  previous "stickyness" of the window
   247  * @param show_stickied  previous "stickyness" of the window
   248  * @param top            previous top position of the window
   248  * @param top            previous top position of the window
   249  * @param left           previous left position of the window
   249  * @param left           previous left position of the window
   250  *
   250  *
   251  * @pre is player a valid player
   251  * @pre is company a valid company
   252  */
   252  */
   253 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top, int left)
   253 static void DoShowCompanyFinances(CompanyID company, bool show_small, bool show_stickied, int top, int left)
   254 {
   254 {
   255 	if (!IsValidPlayerID(player)) return;
   255 	if (!IsValidCompanyID(company)) return;
   256 
   256 
   257 	if (BringWindowToFrontById(WC_FINANCES, player)) return;
   257 	if (BringWindowToFrontById(WC_FINANCES, company)) return;
   258 	new PlayerFinancesWindow(show_small ? &_player_finances_small_desc : &_player_finances_desc, player, show_small, show_stickied, top, left);
   258 	new CompanyFinancesWindow(show_small ? &_company_finances_small_desc : &_company_finances_desc, company, show_small, show_stickied, top, left);
   259 }
   259 }
   260 
   260 
   261 void ShowPlayerFinances(PlayerID player)
   261 void ShowCompanyFinances(CompanyID company)
   262 {
   262 {
   263 	DoShowPlayerFinances(player, false, false);
   263 	DoShowCompanyFinances(company, false, false);
   264 }
   264 }
   265 
   265 
   266 /* List of colours for the livery window */
   266 /* List of colours for the livery window */
   267 static const StringID _colour_dropdown[] = {
   267 static const StringID _colour_dropdown[] = {
   268 	STR_00D1_DARK_BLUE,
   268 	STR_00D1_DARK_BLUE,
   319 		DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOR_START + this->result, x + 16, y + 7);
   319 		DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOR_START + this->result, x + 16, y + 7);
   320 		DrawStringTruncated(x + 32, y + 3, this->String(), sel ? TC_WHITE : TC_BLACK, width - 30);
   320 		DrawStringTruncated(x + 32, y + 3, this->String(), sel ? TC_WHITE : TC_BLACK, width - 30);
   321 	}
   321 	}
   322 };
   322 };
   323 
   323 
   324 struct SelectPlayerLiveryWindow : public Window {
   324 struct SelectCompanyLiveryWindow : public Window {
   325 private:
   325 private:
   326 	uint32 sel;
   326 	uint32 sel;
   327 	LiveryClass livery_class;
   327 	LiveryClass livery_class;
   328 
   328 
   329 	enum PlayerLiveryWindowWidgets {
   329 	enum SelectCompanyLiveryWindowWidgets {
   330 		PLW_WIDGET_CLOSE,
   330 		SCLW_WIDGET_CLOSE,
   331 		PLW_WIDGET_CAPTION,
   331 		SCLW_WIDGET_CAPTION,
   332 		PLW_WIDGET_CLASS_GENERAL,
   332 		SCLW_WIDGET_CLASS_GENERAL,
   333 		PLW_WIDGET_CLASS_RAIL,
   333 		SCLW_WIDGET_CLASS_RAIL,
   334 		PLW_WIDGET_CLASS_ROAD,
   334 		SCLW_WIDGET_CLASS_ROAD,
   335 		PLW_WIDGET_CLASS_SHIP,
   335 		SCLW_WIDGET_CLASS_SHIP,
   336 		PLW_WIDGET_CLASS_AIRCRAFT,
   336 		SCLW_WIDGET_CLASS_AIRCRAFT,
   337 		PLW_WIDGET_SPACER_CLASS,
   337 		SCLW_WIDGET_SPACER_CLASS,
   338 		PLW_WIDGET_SPACER_DROPDOWN,
   338 		SCLW_WIDGET_SPACER_DROPDOWN,
   339 		PLW_WIDGET_PRI_COL_DROPDOWN,
   339 		SCLW_WIDGET_PRI_COL_DROPDOWN,
   340 		PLW_WIDGET_SEC_COL_DROPDOWN,
   340 		SCLW_WIDGET_SEC_COL_DROPDOWN,
   341 		PLW_WIDGET_MATRIX,
   341 		SCLW_WIDGET_MATRIX,
   342 	};
   342 	};
   343 
   343 
   344 	void ShowColourDropDownMenu(uint32 widget)
   344 	void ShowColourDropDownMenu(uint32 widget)
   345 	{
   345 	{
   346 		uint32 used_colours = 0;
   346 		uint32 used_colours = 0;
   347 		const Livery *livery;
   347 		const Livery *livery;
   348 		LiveryScheme scheme;
   348 		LiveryScheme scheme;
   349 
   349 
   350 		/* Disallow other player colours for the primary colour */
   350 		/* Disallow other company colours for the primary colour */
   351 		if (HasBit(this->sel, LS_DEFAULT) && widget == PLW_WIDGET_PRI_COL_DROPDOWN) {
   351 		if (HasBit(this->sel, LS_DEFAULT) && widget == SCLW_WIDGET_PRI_COL_DROPDOWN) {
   352 			const Player *p;
   352 			const Company *c;
   353 			FOR_ALL_PLAYERS(p) {
   353 			FOR_ALL_COMPANIES(c) {
   354 				if (p->index != _local_player) SetBit(used_colours, p->player_color);
   354 				if (c->index != _local_company) SetBit(used_colours, c->colour);
   355 			}
   355 			}
   356 		}
   356 		}
   357 
   357 
   358 		/* Get the first selected livery to use as the default dropdown item */
   358 		/* Get the first selected livery to use as the default dropdown item */
   359 		for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
   359 		for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
   360 			if (HasBit(this->sel, scheme)) break;
   360 			if (HasBit(this->sel, scheme)) break;
   361 		}
   361 		}
   362 		if (scheme == LS_END) scheme = LS_DEFAULT;
   362 		if (scheme == LS_END) scheme = LS_DEFAULT;
   363 		livery = &GetPlayer((PlayerID)this->window_number)->livery[scheme];
   363 		livery = &GetCompany((CompanyID)this->window_number)->livery[scheme];
   364 
   364 
   365 		DropDownList *list = new DropDownList();
   365 		DropDownList *list = new DropDownList();
   366 		for (uint i = 0; i < lengthof(_colour_dropdown); i++) {
   366 		for (uint i = 0; i < lengthof(_colour_dropdown); i++) {
   367 			list->push_back(new DropDownListColourItem(i, HasBit(used_colours, i)));
   367 			list->push_back(new DropDownListColourItem(i, HasBit(used_colours, i)));
   368 		}
   368 		}
   369 
   369 
   370 		ShowDropDownList(this, list, widget == PLW_WIDGET_PRI_COL_DROPDOWN ? livery->colour1 : livery->colour2, widget);
   370 		ShowDropDownList(this, list, widget == SCLW_WIDGET_PRI_COL_DROPDOWN ? livery->colour1 : livery->colour2, widget);
   371 	}
   371 	}
   372 
   372 
   373 public:
   373 public:
   374 	SelectPlayerLiveryWindow(const WindowDesc *desc, PlayerID player) : Window(desc, player)
   374 	SelectCompanyLiveryWindow(const WindowDesc *desc, CompanyID company) : Window(desc, company)
   375 	{
   375 	{
   376 		this->caption_color = player;
   376 		this->caption_color = company;
   377 		this->livery_class = LC_OTHER;
   377 		this->livery_class = LC_OTHER;
   378 		this->sel = 1;
   378 		this->sel = 1;
   379 		this->LowerWidget(PLW_WIDGET_CLASS_GENERAL);
   379 		this->LowerWidget(SCLW_WIDGET_CLASS_GENERAL);
   380 		this->OnInvalidateData(_loaded_newgrf_features.has_2CC);
   380 		this->OnInvalidateData(_loaded_newgrf_features.has_2CC);
   381 		this->FindWindowPlacementAndResize(desc);
   381 		this->FindWindowPlacementAndResize(desc);
   382 	}
   382 	}
   383 
   383 
   384 	virtual void OnPaint()
   384 	virtual void OnPaint()
   385 	{
   385 	{
   386 		const Player *p = GetPlayer((PlayerID)this->window_number);
   386 		const Company *c = GetCompany((CompanyID)this->window_number);
   387 		LiveryScheme scheme = LS_DEFAULT;
   387 		LiveryScheme scheme = LS_DEFAULT;
   388 		int y = 51;
   388 		int y = 51;
   389 
   389 
   390 		/* Disable dropdown controls if no scheme is selected */
   390 		/* Disable dropdown controls if no scheme is selected */
   391 		this->SetWidgetDisabledState(PLW_WIDGET_PRI_COL_DROPDOWN, this->sel == 0);
   391 		this->SetWidgetDisabledState(SCLW_WIDGET_PRI_COL_DROPDOWN, this->sel == 0);
   392 		this->SetWidgetDisabledState(PLW_WIDGET_SEC_COL_DROPDOWN, this->sel == 0);
   392 		this->SetWidgetDisabledState(SCLW_WIDGET_SEC_COL_DROPDOWN, this->sel == 0);
   393 
   393 
   394 		if (this->sel != 0) {
   394 		if (this->sel != 0) {
   395 			for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
   395 			for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
   396 				if (HasBit(this->sel, scheme)) break;
   396 				if (HasBit(this->sel, scheme)) break;
   397 			}
   397 			}
   398 			if (scheme == LS_END) scheme = LS_DEFAULT;
   398 			if (scheme == LS_END) scheme = LS_DEFAULT;
   399 		}
   399 		}
   400 
   400 
   401 		SetDParam(0, STR_00D1_DARK_BLUE + p->livery[scheme].colour1);
   401 		SetDParam(0, STR_00D1_DARK_BLUE + c->livery[scheme].colour1);
   402 		SetDParam(1, STR_00D1_DARK_BLUE + p->livery[scheme].colour2);
   402 		SetDParam(1, STR_00D1_DARK_BLUE + c->livery[scheme].colour2);
   403 
   403 
   404 		this->DrawWidgets();
   404 		this->DrawWidgets();
   405 
   405 
   406 		for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   406 		for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   407 			if (_livery_class[scheme] == this->livery_class) {
   407 			if (_livery_class[scheme] == this->livery_class) {
   408 				bool sel = HasBit(this->sel, scheme) != 0;
   408 				bool sel = HasBit(this->sel, scheme) != 0;
   409 
   409 
   410 				if (scheme != LS_DEFAULT) {
   410 				if (scheme != LS_DEFAULT) {
   411 					DrawSprite(p->livery[scheme].in_use ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, 2, y);
   411 					DrawSprite(c->livery[scheme].in_use ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, 2, y);
   412 				}
   412 				}
   413 
   413 
   414 				DrawString(15, y, STR_LIVERY_DEFAULT + scheme, sel ? TC_WHITE : TC_BLACK);
   414 				DrawString(15, y, STR_LIVERY_DEFAULT + scheme, sel ? TC_WHITE : TC_BLACK);
   415 
   415 
   416 				DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour1), 152, y);
   416 				DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(c->livery[scheme].colour1), 152, y);
   417 				DrawString(165, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour1, sel ? TC_WHITE : TC_GOLD);
   417 				DrawString(165, y, STR_00D1_DARK_BLUE + c->livery[scheme].colour1, sel ? TC_WHITE : TC_GOLD);
   418 
   418 
   419 				if (!this->IsWidgetHidden(PLW_WIDGET_SEC_COL_DROPDOWN)) {
   419 				if (!this->IsWidgetHidden(SCLW_WIDGET_SEC_COL_DROPDOWN)) {
   420 					DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour2), 277, y);
   420 					DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(c->livery[scheme].colour2), 277, y);
   421 					DrawString(290, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour2, sel ? TC_WHITE : TC_GOLD);
   421 					DrawString(290, y, STR_00D1_DARK_BLUE + c->livery[scheme].colour2, sel ? TC_WHITE : TC_GOLD);
   422 				}
   422 				}
   423 
   423 
   424 				y += 14;
   424 				y += 14;
   425 			}
   425 			}
   426 		}
   426 		}
   437 			3,
   437 			3,
   438 		};
   438 		};
   439 
   439 
   440 		switch (widget) {
   440 		switch (widget) {
   441 			/* Livery Class buttons */
   441 			/* Livery Class buttons */
   442 			case PLW_WIDGET_CLASS_GENERAL:
   442 			case SCLW_WIDGET_CLASS_GENERAL:
   443 			case PLW_WIDGET_CLASS_RAIL:
   443 			case SCLW_WIDGET_CLASS_RAIL:
   444 			case PLW_WIDGET_CLASS_ROAD:
   444 			case SCLW_WIDGET_CLASS_ROAD:
   445 			case PLW_WIDGET_CLASS_SHIP:
   445 			case SCLW_WIDGET_CLASS_SHIP:
   446 			case PLW_WIDGET_CLASS_AIRCRAFT: {
   446 			case SCLW_WIDGET_CLASS_AIRCRAFT: {
   447 				LiveryScheme scheme;
   447 				LiveryScheme scheme;
   448 
   448 
   449 				this->RaiseWidget(this->livery_class + PLW_WIDGET_CLASS_GENERAL);
   449 				this->RaiseWidget(this->livery_class + SCLW_WIDGET_CLASS_GENERAL);
   450 				this->livery_class = (LiveryClass)(widget - PLW_WIDGET_CLASS_GENERAL);
   450 				this->livery_class = (LiveryClass)(widget - SCLW_WIDGET_CLASS_GENERAL);
   451 				this->sel = 0;
   451 				this->sel = 0;
   452 				this->LowerWidget(this->livery_class + PLW_WIDGET_CLASS_GENERAL);
   452 				this->LowerWidget(this->livery_class + SCLW_WIDGET_CLASS_GENERAL);
   453 
   453 
   454 				/* Select the first item in the list */
   454 				/* Select the first item in the list */
   455 				for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   455 				for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   456 					if (_livery_class[scheme] == this->livery_class) {
   456 					if (_livery_class[scheme] == this->livery_class) {
   457 						this->sel = 1 << scheme;
   457 						this->sel = 1 << scheme;
   458 						break;
   458 						break;
   459 					}
   459 					}
   460 				}
   460 				}
   461 				this->height = 49 + livery_height[this->livery_class] * 14;
   461 				this->height = 49 + livery_height[this->livery_class] * 14;
   462 				this->widget[PLW_WIDGET_MATRIX].bottom = this->height - 1;
   462 				this->widget[SCLW_WIDGET_MATRIX].bottom = this->height - 1;
   463 				this->widget[PLW_WIDGET_MATRIX].data = livery_height[this->livery_class] << 8 | 1;
   463 				this->widget[SCLW_WIDGET_MATRIX].data = livery_height[this->livery_class] << 8 | 1;
   464 				MarkWholeScreenDirty();
   464 				MarkWholeScreenDirty();
   465 				break;
   465 				break;
   466 			}
   466 			}
   467 
   467 
   468 			case PLW_WIDGET_PRI_COL_DROPDOWN: /* First colour dropdown */
   468 			case SCLW_WIDGET_PRI_COL_DROPDOWN: /* First colour dropdown */
   469 				ShowColourDropDownMenu(PLW_WIDGET_PRI_COL_DROPDOWN);
   469 				ShowColourDropDownMenu(SCLW_WIDGET_PRI_COL_DROPDOWN);
   470 				break;
   470 				break;
   471 
   471 
   472 			case PLW_WIDGET_SEC_COL_DROPDOWN: /* Second colour dropdown */
   472 			case SCLW_WIDGET_SEC_COL_DROPDOWN: /* Second colour dropdown */
   473 				ShowColourDropDownMenu(PLW_WIDGET_SEC_COL_DROPDOWN);
   473 				ShowColourDropDownMenu(SCLW_WIDGET_SEC_COL_DROPDOWN);
   474 				break;
   474 				break;
   475 
   475 
   476 			case PLW_WIDGET_MATRIX: {
   476 			case SCLW_WIDGET_MATRIX: {
   477 				LiveryScheme scheme;
   477 				LiveryScheme scheme;
   478 				LiveryScheme j = (LiveryScheme)((pt.y - 48) / 14);
   478 				LiveryScheme j = (LiveryScheme)((pt.y - 48) / 14);
   479 
   479 
   480 				for (scheme = LS_BEGIN; scheme <= j; scheme++) {
   480 				for (scheme = LS_BEGIN; scheme <= j; scheme++) {
   481 					if (_livery_class[scheme] != this->livery_class) j++;
   481 					if (_livery_class[scheme] != this->livery_class) j++;
   483 				}
   483 				}
   484 				if (j >= LS_END) return;
   484 				if (j >= LS_END) return;
   485 
   485 
   486 				/* If clicking on the left edge, toggle using the livery */
   486 				/* If clicking on the left edge, toggle using the livery */
   487 				if (pt.x < 10) {
   487 				if (pt.x < 10) {
   488 					DoCommandP(0, j | (2 << 8), !GetPlayer((PlayerID)this->window_number)->livery[j].in_use, NULL, CMD_SET_PLAYER_COLOR);
   488 					DoCommandP(0, j | (2 << 8), !GetCompany((CompanyID)this->window_number)->livery[j].in_use, NULL, CMD_SET_COMPANY_COLOR);
   489 				}
   489 				}
   490 
   490 
   491 				if (_ctrl_pressed) {
   491 				if (_ctrl_pressed) {
   492 					ToggleBit(this->sel, j);
   492 					ToggleBit(this->sel, j);
   493 				} else {
   493 				} else {
   501 
   501 
   502 	virtual void OnDropdownSelect(int widget, int index)
   502 	virtual void OnDropdownSelect(int widget, int index)
   503 	{
   503 	{
   504 		for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   504 		for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   505 			if (HasBit(this->sel, scheme)) {
   505 			if (HasBit(this->sel, scheme)) {
   506 				DoCommandP(0, scheme | (widget == PLW_WIDGET_PRI_COL_DROPDOWN ? 0 : 256), index, NULL, CMD_SET_PLAYER_COLOR);
   506 				DoCommandP(0, scheme | (widget == SCLW_WIDGET_PRI_COL_DROPDOWN ? 0 : 256), index, NULL, CMD_SET_COMPANY_COLOR);
   507 			}
   507 			}
   508 		}
   508 		}
   509 	}
   509 	}
   510 
   510 
   511 	virtual void OnInvalidateData(int data = 0)
   511 	virtual void OnInvalidateData(int data = 0)
   514 
   514 
   515 		if (has2cc == !!data) return;
   515 		if (has2cc == !!data) return;
   516 
   516 
   517 		has2cc = !!data;
   517 		has2cc = !!data;
   518 
   518 
   519 		int r = this->widget[has2cc ? PLW_WIDGET_SEC_COL_DROPDOWN : PLW_WIDGET_PRI_COL_DROPDOWN].right;
   519 		int r = this->widget[has2cc ? SCLW_WIDGET_SEC_COL_DROPDOWN : SCLW_WIDGET_PRI_COL_DROPDOWN].right;
   520 		this->SetWidgetHiddenState(PLW_WIDGET_SEC_COL_DROPDOWN, !has2cc);
   520 		this->SetWidgetHiddenState(SCLW_WIDGET_SEC_COL_DROPDOWN, !has2cc);
   521 		this->widget[PLW_WIDGET_CAPTION].right = r;
   521 		this->widget[SCLW_WIDGET_CAPTION].right = r;
   522 		this->widget[PLW_WIDGET_SPACER_CLASS].right = r;
   522 		this->widget[SCLW_WIDGET_SPACER_CLASS].right = r;
   523 		this->widget[PLW_WIDGET_MATRIX].right = r;
   523 		this->widget[SCLW_WIDGET_MATRIX].right = r;
   524 		this->width = r + 1;
   524 		this->width = r + 1;
   525 	}
   525 	}
   526 };
   526 };
   527 
   527 
   528 static const Widget _select_player_livery_widgets[] = {
   528 static const Widget _select_company_livery_widgets[] = {
   529 { WWT_CLOSEBOX, RESIZE_NONE,  COLOUR_GREY,   0,  10,   0,  13, STR_00C5,                  STR_018B_CLOSE_WINDOW },
   529 { WWT_CLOSEBOX, RESIZE_NONE,  COLOUR_GREY,   0,  10,   0,  13, STR_00C5,                  STR_018B_CLOSE_WINDOW },
   530 {  WWT_CAPTION, RESIZE_NONE,  COLOUR_GREY,  11, 399,   0,  13, STR_7007_NEW_COLOR_SCHEME, STR_018C_WINDOW_TITLE_DRAG_THIS },
   530 {  WWT_CAPTION, RESIZE_NONE,  COLOUR_GREY,  11, 399,   0,  13, STR_7007_NEW_COLOR_SCHEME, STR_018C_WINDOW_TITLE_DRAG_THIS },
   531 {   WWT_IMGBTN, RESIZE_NONE,  COLOUR_GREY,   0,  21,  14,  35, SPR_IMG_COMPANY_GENERAL,   STR_LIVERY_GENERAL_TIP },
   531 {   WWT_IMGBTN, RESIZE_NONE,  COLOUR_GREY,   0,  21,  14,  35, SPR_IMG_COMPANY_GENERAL,   STR_LIVERY_GENERAL_TIP },
   532 {   WWT_IMGBTN, RESIZE_NONE,  COLOUR_GREY,  22,  43,  14,  35, SPR_IMG_TRAINLIST,         STR_LIVERY_TRAIN_TIP },
   532 {   WWT_IMGBTN, RESIZE_NONE,  COLOUR_GREY,  22,  43,  14,  35, SPR_IMG_TRAINLIST,         STR_LIVERY_TRAIN_TIP },
   533 {   WWT_IMGBTN, RESIZE_NONE,  COLOUR_GREY,  44,  65,  14,  35, SPR_IMG_TRUCKLIST,         STR_LIVERY_ROADVEH_TIP },
   533 {   WWT_IMGBTN, RESIZE_NONE,  COLOUR_GREY,  44,  65,  14,  35, SPR_IMG_TRUCKLIST,         STR_LIVERY_ROADVEH_TIP },
   539 { WWT_DROPDOWN, RESIZE_NONE,  COLOUR_GREY, 275, 399,  36,  47, STR_02E1,                  STR_LIVERY_SECONDARY_TIP },
   539 { WWT_DROPDOWN, RESIZE_NONE,  COLOUR_GREY, 275, 399,  36,  47, STR_02E1,                  STR_LIVERY_SECONDARY_TIP },
   540 {   WWT_MATRIX, RESIZE_NONE,  COLOUR_GREY,   0, 399,  48,  48 + 1 * 14, (1 << 8) | 1,     STR_LIVERY_PANEL_TIP },
   540 {   WWT_MATRIX, RESIZE_NONE,  COLOUR_GREY,   0, 399,  48,  48 + 1 * 14, (1 << 8) | 1,     STR_LIVERY_PANEL_TIP },
   541 { WIDGETS_END },
   541 { WIDGETS_END },
   542 };
   542 };
   543 
   543 
   544 static const WindowDesc _select_player_livery_desc = {
   544 static const WindowDesc _select_company_livery_desc = {
   545 	WDP_AUTO, WDP_AUTO, 400, 49 + 1 * 14, 400, 49 + 1 * 14,
   545 	WDP_AUTO, WDP_AUTO, 400, 49 + 1 * 14, 400, 49 + 1 * 14,
   546 	WC_PLAYER_COLOR, WC_NONE,
   546 	WC_COMPANY_COLOR, WC_NONE,
   547 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
   547 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
   548 	_select_player_livery_widgets,
   548 	_select_company_livery_widgets,
   549 };
   549 };
   550 
   550 
   551 /**
   551 /**
   552  * Draws the face of a player.
   552  * Draws the face of a company manager's face.
   553  * @param pf    the player's face
   553  * @param cmf   the company manager's face
   554  * @param color the (background) color of the gradient
   554  * @param color the (background) color of the gradient
   555  * @param x     x-position to draw the face
   555  * @param x     x-position to draw the face
   556  * @param y     y-position to draw the face
   556  * @param y     y-position to draw the face
   557  */
   557  */
   558 void DrawPlayerFace(PlayerFace pf, int color, int x, int y)
   558 void DrawCompanyManagerFace(CompanyManagerFace cmf, int color, int x, int y)
   559 {
   559 {
   560 	GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM);
   560 	GenderEthnicity ge = (GenderEthnicity)GetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, GE_WM);
   561 
   561 
   562 	bool has_moustache   = !HasBit(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE,   ge) != 0;
   562 	bool has_moustache   = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE,   ge) != 0;
   563 	bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge) != 0;
   563 	bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge) != 0;
   564 	bool has_glasses     = GetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge) != 0;
   564 	bool has_glasses     = GetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge) != 0;
   565 	SpriteID pal;
   565 	SpriteID pal;
   566 
   566 
   567 	/* Modify eye colour palette only if 2 or more valid values exist */
   567 	/* Modify eye colour palette only if 2 or more valid values exist */
   568 	if (_pf_info[PFV_EYE_COLOUR].valid_values[ge] < 2) {
   568 	if (_cmf_info[CMFV_EYE_COLOUR].valid_values[ge] < 2) {
   569 		pal = PAL_NONE;
   569 		pal = PAL_NONE;
   570 	} else {
   570 	} else {
   571 		switch (GetPlayerFaceBits(pf, PFV_EYE_COLOUR, ge)) {
   571 		switch (GetCompanyManagerFaceBits(cmf, CMFV_EYE_COLOUR, ge)) {
   572 			default: NOT_REACHED();
   572 			default: NOT_REACHED();
   573 			case 0: pal = PALETTE_TO_BROWN; break;
   573 			case 0: pal = PALETTE_TO_BROWN; break;
   574 			case 1: pal = PALETTE_TO_BLUE;  break;
   574 			case 1: pal = PALETTE_TO_BLUE;  break;
   575 			case 2: pal = PALETTE_TO_GREEN; break;
   575 			case 2: pal = PALETTE_TO_GREEN; break;
   576 		}
   576 		}
   577 	}
   577 	}
   578 
   578 
   579 	/* Draw the gradient (background) */
   579 	/* Draw the gradient (background) */
   580 	DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOR(color), x, y);
   580 	DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOR(color), x, y);
   581 
   581 
   582 	for (PlayerFaceVariable pfv = PFV_CHEEKS; pfv < PFV_END; pfv++) {
   582 	for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) {
   583 		switch (pfv) {
   583 		switch (cmfv) {
   584 			case PFV_MOUSTACHE:   if (!has_moustache)   continue; break;
   584 			case CMFV_MOUSTACHE:   if (!has_moustache)   continue; break;
   585 			case PFV_LIPS:        /* FALL THROUGH */
   585 			case CMFV_LIPS:        /* FALL THROUGH */
   586 			case PFV_NOSE:        if (has_moustache)    continue; break;
   586 			case CMFV_NOSE:        if (has_moustache)    continue; break;
   587 			case PFV_TIE_EARRING: if (!has_tie_earring) continue; break;
   587 			case CMFV_TIE_EARRING: if (!has_tie_earring) continue; break;
   588 			case PFV_GLASSES:     if (!has_glasses)     continue; break;
   588 			case CMFV_GLASSES:     if (!has_glasses)     continue; break;
   589 			default: break;
   589 			default: break;
   590 		}
   590 		}
   591 		DrawSprite(GetPlayerFaceSprite(pf, pfv, ge), (pfv == PFV_EYEBROWS) ? pal : PAL_NONE, x, y);
   591 		DrawSprite(GetCompanyManagerFaceSprite(cmf, cmfv, ge), (cmfv == CMFV_EYEBROWS) ? pal : PAL_NONE, x, y);
   592 	}
   592 	}
   593 }
   593 }
   594 
   594 
   595 /** Widget description for the normal/simple player face selection dialog */
   595 /** Widget description for the normal/simple company manager face selection dialog */
   596 static const Widget _select_player_face_widgets[] = {
   596 static const Widget _select_company_manager_face_widgets[] = {
   597 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},              // PFW_WIDGET_CLOSEBOX
   597 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},              // SCMFW_WIDGET_CLOSEBOX
   598 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   174,     0,    13, STR_7043_FACE_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},    // PFW_WIDGET_CAPTION
   598 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   174,     0,    13, STR_7043_FACE_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},    // SCMFW_WIDGET_CAPTION
   599 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_GREY,   175,   189,     0,    13, SPR_LARGE_SMALL_WINDOW,  STR_FACE_ADVANCED_TIP},              // PFW_WIDGET_TOGGLE_LARGE_SMALL
   599 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_GREY,   175,   189,     0,    13, SPR_LARGE_SMALL_WINDOW,  STR_FACE_ADVANCED_TIP},              // SCMFW_WIDGET_TOGGLE_LARGE_SMALL
   600 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   189,    14,   150, 0x0,                     STR_NULL},                           // PFW_WIDGET_SELECT_FACE
   600 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   189,    14,   150, 0x0,                     STR_NULL},                           // SCMFW_WIDGET_SELECT_FACE
   601 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,    94,   151,   162, STR_012E_CANCEL,         STR_7047_CANCEL_NEW_FACE_SELECTION}, // PFW_WIDGET_CANCEL
   601 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,    94,   151,   162, STR_012E_CANCEL,         STR_7047_CANCEL_NEW_FACE_SELECTION}, // SCMFW_WIDGET_CANCEL
   602 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   189,   151,   162, STR_012F_OK,             STR_7048_ACCEPT_NEW_FACE_SELECTION}, // PFW_WIDGET_ACCEPT
   602 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   189,   151,   162, STR_012F_OK,             STR_7048_ACCEPT_NEW_FACE_SELECTION}, // SCMFW_WIDGET_ACCEPT
   603 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   187,    75,    86, STR_7044_MALE,           STR_7049_SELECT_MALE_FACES},         // PFW_WIDGET_MALE
   603 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   187,    75,    86, STR_7044_MALE,           STR_7049_SELECT_MALE_FACES},         // SCMFW_WIDGET_MALE
   604 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   187,    87,    98, STR_7045_FEMALE,         STR_704A_SELECT_FEMALE_FACES},       // PFW_WIDGET_FEMALE
   604 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   187,    87,    98, STR_7045_FEMALE,         STR_704A_SELECT_FEMALE_FACES},       // SCMFW_WIDGET_FEMALE
   605 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   137,   148, STR_7046_NEW_FACE,       STR_704B_GENERATE_RANDOM_NEW_FACE},  // PFW_WIDGET_RANDOM_NEW_FACE
   605 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   137,   148, STR_7046_NEW_FACE,       STR_704B_GENERATE_RANDOM_NEW_FACE},  // SCMFW_WIDGET_RANDOM_NEW_FACE
   606 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   187,    16,    27, STR_FACE_ADVANCED,       STR_FACE_ADVANCED_TIP},              // PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON
   606 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   187,    16,    27, STR_FACE_ADVANCED,       STR_FACE_ADVANCED_TIP},              // SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON
   607 {   WIDGETS_END},
   607 {   WIDGETS_END},
   608 };
   608 };
   609 
   609 
   610 /** Widget description for the advanced player face selection dialog */
   610 /** Widget description for the advanced company manager face selection dialog */
   611 static const Widget _select_player_face_adv_widgets[] = {
   611 static const Widget _select_company_manager_face_adv_widgets[] = {
   612 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},              // PFW_WIDGET_CLOSEBOX
   612 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},              // SCMFW_WIDGET_CLOSEBOX
   613 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   204,     0,    13, STR_7043_FACE_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},    // PFW_WIDGET_CAPTION
   613 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   204,     0,    13, STR_7043_FACE_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},    // SCMFW_WIDGET_CAPTION
   614 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_GREY,   205,   219,     0,    13, SPR_LARGE_SMALL_WINDOW,  STR_FACE_SIMPLE_TIP},                // PFW_WIDGET_TOGGLE_LARGE_SMALL
   614 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_GREY,   205,   219,     0,    13, SPR_LARGE_SMALL_WINDOW,  STR_FACE_SIMPLE_TIP},                // SCMFW_WIDGET_TOGGLE_LARGE_SMALL
   615 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   219,    14,   207, 0x0,                     STR_NULL},                           // PFW_WIDGET_SELECT_FACE
   615 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   219,    14,   207, 0x0,                     STR_NULL},                           // SCMFW_WIDGET_SELECT_FACE
   616 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,    94,   208,   219, STR_012E_CANCEL,         STR_7047_CANCEL_NEW_FACE_SELECTION}, // PFW_WIDGET_CANCEL
   616 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,    94,   208,   219, STR_012E_CANCEL,         STR_7047_CANCEL_NEW_FACE_SELECTION}, // SCMFW_WIDGET_CANCEL
   617 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   219,   208,   219, STR_012F_OK,             STR_7048_ACCEPT_NEW_FACE_SELECTION}, // PFW_WIDGET_ACCEPT
   617 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   219,   208,   219, STR_012F_OK,             STR_7048_ACCEPT_NEW_FACE_SELECTION}, // SCMFW_WIDGET_ACCEPT
   618 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    96,   156,    32,    43, STR_7044_MALE,           STR_7049_SELECT_MALE_FACES},         // PFW_WIDGET_MALE
   618 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    96,   156,    32,    43, STR_7044_MALE,           STR_7049_SELECT_MALE_FACES},         // SCMFW_WIDGET_MALE
   619 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,   157,   217,    32,    43, STR_7045_FEMALE,         STR_704A_SELECT_FEMALE_FACES},       // PFW_WIDGET_FEMALE
   619 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,   157,   217,    32,    43, STR_7045_FEMALE,         STR_704A_SELECT_FEMALE_FACES},       // SCMFW_WIDGET_FEMALE
   620 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   137,   148, STR_RANDOM,              STR_704B_GENERATE_RANDOM_NEW_FACE},  // PFW_WIDGET_RANDOM_NEW_FACE
   620 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   137,   148, STR_RANDOM,              STR_704B_GENERATE_RANDOM_NEW_FACE},  // SCMFW_WIDGET_RANDOM_NEW_FACE
   621 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   217,    16,    27, STR_FACE_SIMPLE,         STR_FACE_SIMPLE_TIP},                // PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON
   621 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    95,   217,    16,    27, STR_FACE_SIMPLE,         STR_FACE_SIMPLE_TIP},                // SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON
   622 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   158,   169, STR_FACE_LOAD,           STR_FACE_LOAD_TIP},                  // PFW_WIDGET_LOAD
   622 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   158,   169, STR_FACE_LOAD,           STR_FACE_LOAD_TIP},                  // SCMFW_WIDGET_LOAD
   623 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   170,   181, STR_FACE_FACECODE,       STR_FACE_FACECODE_TIP},              // PFW_WIDGET_FACECODE
   623 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   170,   181, STR_FACE_FACECODE,       STR_FACE_FACECODE_TIP},              // SCMFW_WIDGET_FACECODE
   624 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   182,   193, STR_FACE_SAVE,           STR_FACE_SAVE_TIP},                  // PFW_WIDGET_SAVE
   624 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     2,    93,   182,   193, STR_FACE_SAVE,           STR_FACE_SAVE_TIP},                  // SCMFW_WIDGET_SAVE
   625 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    96,   156,    46,    57, STR_FACE_EUROPEAN,       STR_FACE_SELECT_EUROPEAN},           // PFW_WIDGET_ETHNICITY_EUR
   625 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,    96,   156,    46,    57, STR_FACE_EUROPEAN,       STR_FACE_SELECT_EUROPEAN},           // SCMFW_WIDGET_ETHNICITY_EUR
   626 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,   157,   217,    46,    57, STR_FACE_AFRICAN,        STR_FACE_SELECT_AFRICAN},            // PFW_WIDGET_ETHNICITY_AFR
   626 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,   157,   217,    46,    57, STR_FACE_AFRICAN,        STR_FACE_SELECT_AFRICAN},            // SCMFW_WIDGET_ETHNICITY_AFR
   627 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   175,   217,    60,    71, STR_EMPTY,               STR_FACE_MOUSTACHE_EARRING_TIP},     // PFW_WIDGET_HAS_MOUSTACHE_EARRING
   627 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   175,   217,    60,    71, STR_EMPTY,               STR_FACE_MOUSTACHE_EARRING_TIP},     // SCMFW_WIDGET_HAS_MOUSTACHE_EARRING
   628 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   175,   217,    72,    83, STR_EMPTY,               STR_FACE_GLASSES_TIP},               // PFW_WIDGET_HAS_GLASSES
   628 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   175,   217,    72,    83, STR_EMPTY,               STR_FACE_GLASSES_TIP},               // SCMFW_WIDGET_HAS_GLASSES
   629 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   110,   121, SPR_ARROW_LEFT,          STR_FACE_EYECOLOUR_TIP},             // PFW_WIDGET_EYECOLOUR_L
   629 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   110,   121, SPR_ARROW_LEFT,          STR_FACE_EYECOLOUR_TIP},             // SCMFW_WIDGET_EYECOLOUR_L
   630 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   110,   121, STR_EMPTY,               STR_FACE_EYECOLOUR_TIP},             // PFW_WIDGET_EYECOLOUR
   630 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   110,   121, STR_EMPTY,               STR_FACE_EYECOLOUR_TIP},             // SCMFW_WIDGET_EYECOLOUR
   631 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   110,   121, SPR_ARROW_RIGHT,         STR_FACE_EYECOLOUR_TIP},             // PFW_WIDGET_EYECOLOUR_R
   631 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   110,   121, SPR_ARROW_RIGHT,         STR_FACE_EYECOLOUR_TIP},             // SCMFW_WIDGET_EYECOLOUR_R
   632 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   158,   169, SPR_ARROW_LEFT,          STR_FACE_CHIN_TIP},                  // PFW_WIDGET_CHIN_L
   632 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   158,   169, SPR_ARROW_LEFT,          STR_FACE_CHIN_TIP},                  // SCMFW_WIDGET_CHIN_L
   633 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   158,   169, STR_EMPTY,               STR_FACE_CHIN_TIP},                  // PFW_WIDGET_CHIN
   633 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   158,   169, STR_EMPTY,               STR_FACE_CHIN_TIP},                  // SCMFW_WIDGET_CHIN
   634 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   158,   169, SPR_ARROW_RIGHT,         STR_FACE_CHIN_TIP},                  // PFW_WIDGET_CHIN_R
   634 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   158,   169, SPR_ARROW_RIGHT,         STR_FACE_CHIN_TIP},                  // SCMFW_WIDGET_CHIN_R
   635 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,    98,   109, SPR_ARROW_LEFT,          STR_FACE_EYEBROWS_TIP},              // PFW_WIDGET_EYEBROWS_L
   635 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,    98,   109, SPR_ARROW_LEFT,          STR_FACE_EYEBROWS_TIP},              // SCMFW_WIDGET_EYEBROWS_L
   636 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,    98,   109, STR_EMPTY,               STR_FACE_EYEBROWS_TIP},              // PFW_WIDGET_EYEBROWS
   636 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,    98,   109, STR_EMPTY,               STR_FACE_EYEBROWS_TIP},              // SCMFW_WIDGET_EYEBROWS
   637 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,    98,   109, SPR_ARROW_RIGHT,         STR_FACE_EYEBROWS_TIP},              // PFW_WIDGET_EYEBROWS_R
   637 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,    98,   109, SPR_ARROW_RIGHT,         STR_FACE_EYEBROWS_TIP},              // SCMFW_WIDGET_EYEBROWS_R
   638 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   146,   157, SPR_ARROW_LEFT,          STR_FACE_LIPS_MOUSTACHE_TIP},        // PFW_WIDGET_LIPS_MOUSTACHE_L
   638 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   146,   157, SPR_ARROW_LEFT,          STR_FACE_LIPS_MOUSTACHE_TIP},        // SCMFW_WIDGET_LIPS_MOUSTACHE_L
   639 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   146,   157, STR_EMPTY,               STR_FACE_LIPS_MOUSTACHE_TIP},        // PFW_WIDGET_LIPS_MOUSTACHE
   639 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   146,   157, STR_EMPTY,               STR_FACE_LIPS_MOUSTACHE_TIP},        // SCMFW_WIDGET_LIPS_MOUSTACHE
   640 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   146,   157, SPR_ARROW_RIGHT,         STR_FACE_LIPS_MOUSTACHE_TIP},        // PFW_WIDGET_LIPS_MOUSTACHE_R
   640 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   146,   157, SPR_ARROW_RIGHT,         STR_FACE_LIPS_MOUSTACHE_TIP},        // SCMFW_WIDGET_LIPS_MOUSTACHE_R
   641 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   134,   145, SPR_ARROW_LEFT,          STR_FACE_NOSE_TIP},                  // PFW_WIDGET_NOSE_L
   641 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   134,   145, SPR_ARROW_LEFT,          STR_FACE_NOSE_TIP},                  // SCMFW_WIDGET_NOSE_L
   642 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   134,   145, STR_EMPTY,               STR_FACE_NOSE_TIP},                  // PFW_WIDGET_NOSE
   642 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   134,   145, STR_EMPTY,               STR_FACE_NOSE_TIP},                  // SCMFW_WIDGET_NOSE
   643 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   134,   145, SPR_ARROW_RIGHT,         STR_FACE_NOSE_TIP},                  // PFW_WIDGET_NOSE_R
   643 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   134,   145, SPR_ARROW_RIGHT,         STR_FACE_NOSE_TIP},                  // SCMFW_WIDGET_NOSE_R
   644 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,    86,    97, SPR_ARROW_LEFT,          STR_FACE_HAIR_TIP},                  // PFW_WIDGET_HAIR_L
   644 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,    86,    97, SPR_ARROW_LEFT,          STR_FACE_HAIR_TIP},                  // SCMFW_WIDGET_HAIR_L
   645 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,    86,    97, STR_EMPTY,               STR_FACE_HAIR_TIP},                  // PFW_WIDGET_HAIR
   645 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,    86,    97, STR_EMPTY,               STR_FACE_HAIR_TIP},                  // SCMFW_WIDGET_HAIR
   646 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,    86,    97, SPR_ARROW_RIGHT,         STR_FACE_HAIR_TIP},                  // PFW_WIDGET_HAIR_R
   646 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,    86,    97, SPR_ARROW_RIGHT,         STR_FACE_HAIR_TIP},                  // SCMFW_WIDGET_HAIR_R
   647 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   170,   181, SPR_ARROW_LEFT,          STR_FACE_JACKET_TIP},                // PFW_WIDGET_JACKET_L
   647 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   170,   181, SPR_ARROW_LEFT,          STR_FACE_JACKET_TIP},                // SCMFW_WIDGET_JACKET_L
   648 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   170,   181, STR_EMPTY,               STR_FACE_JACKET_TIP},                // PFW_WIDGET_JACKET
   648 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   170,   181, STR_EMPTY,               STR_FACE_JACKET_TIP},                // SCMFW_WIDGET_JACKET
   649 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   170,   181, SPR_ARROW_RIGHT,         STR_FACE_JACKET_TIP},                // PFW_WIDGET_JACKET_R
   649 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   170,   181, SPR_ARROW_RIGHT,         STR_FACE_JACKET_TIP},                // SCMFW_WIDGET_JACKET_R
   650 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   182,   193, SPR_ARROW_LEFT,          STR_FACE_COLLAR_TIP},                // PFW_WIDGET_COLLAR_L
   650 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   182,   193, SPR_ARROW_LEFT,          STR_FACE_COLLAR_TIP},                // SCMFW_WIDGET_COLLAR_L
   651 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   182,   193, STR_EMPTY,               STR_FACE_COLLAR_TIP},                // PFW_WIDGET_COLLAR
   651 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   182,   193, STR_EMPTY,               STR_FACE_COLLAR_TIP},                // SCMFW_WIDGET_COLLAR
   652 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   182,   193, SPR_ARROW_RIGHT,         STR_FACE_COLLAR_TIP},                // PFW_WIDGET_COLLAR_R
   652 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   182,   193, SPR_ARROW_RIGHT,         STR_FACE_COLLAR_TIP},                // SCMFW_WIDGET_COLLAR_R
   653 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   194,   205, SPR_ARROW_LEFT,          STR_FACE_TIE_EARRING_TIP},           // PFW_WIDGET_TIE_EARRING_L
   653 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   194,   205, SPR_ARROW_LEFT,          STR_FACE_TIE_EARRING_TIP},           // SCMFW_WIDGET_TIE_EARRING_L
   654 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   194,   205, STR_EMPTY,               STR_FACE_TIE_EARRING_TIP},           // PFW_WIDGET_TIE_EARRING
   654 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   194,   205, STR_EMPTY,               STR_FACE_TIE_EARRING_TIP},           // SCMFW_WIDGET_TIE_EARRING
   655 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   194,   205, SPR_ARROW_RIGHT,         STR_FACE_TIE_EARRING_TIP},           // PFW_WIDGET_TIE_EARRING_R
   655 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   194,   205, SPR_ARROW_RIGHT,         STR_FACE_TIE_EARRING_TIP},           // SCMFW_WIDGET_TIE_EARRING_R
   656 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   122,   133, SPR_ARROW_LEFT,          STR_FACE_GLASSES_TIP_2},             // PFW_WIDGET_GLASSES_L
   656 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    175,  183,   122,   133, SPR_ARROW_LEFT,          STR_FACE_GLASSES_TIP_2},             // SCMFW_WIDGET_GLASSES_L
   657 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   122,   133, STR_EMPTY,               STR_FACE_GLASSES_TIP_2},             // PFW_WIDGET_GLASSES
   657 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    184,  208,   122,   133, STR_EMPTY,               STR_FACE_GLASSES_TIP_2},             // SCMFW_WIDGET_GLASSES
   658 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   122,   133, SPR_ARROW_RIGHT,         STR_FACE_GLASSES_TIP_2},             // PFW_WIDGET_GLASSES_R
   658 { WWT_PUSHIMGBTN,   RESIZE_NONE,  COLOUR_GREY,    209,  217,   122,   133, SPR_ARROW_RIGHT,         STR_FACE_GLASSES_TIP_2},             // SCMFW_WIDGET_GLASSES_R
   659 {   WIDGETS_END},
   659 {   WIDGETS_END},
   660 };
   660 };
   661 
   661 
   662 class SelectPlayerFaceWindow : public Window
   662 class SelectCompanyManagerFaceWindow : public Window
   663 {
   663 {
   664 	PlayerFace face; // player face bits
   664 	CompanyManagerFace face; ///< company manager face bits
   665 	bool advanced;   // advance player face selection window
   665 	bool advanced; ///< advanced company manager face selection window
   666 
   666 
   667 	GenderEthnicity ge;
   667 	GenderEthnicity ge;
   668 	bool is_female;
   668 	bool is_female;
   669 	bool is_moust_male;
   669 	bool is_moust_male;
   670 
   670 
   671 	/**
   671 	/**
   672 	 * Names of the widgets. Keep them in the same order as in the widget array.
   672 	 * Names of the widgets. Keep them in the same order as in the widget array.
   673 	 * Do not change the order of the widgets from PFW_WIDGET_HAS_MOUSTACHE_EARRING to PFW_WIDGET_GLASSES_R,
   673 	 * Do not change the order of the widgets from SCMFW_WIDGET_HAS_MOUSTACHE_EARRING to SCMFW_WIDGET_GLASSES_R,
   674 	 * this order is needed for the WE_CLICK event of DrawFaceStringLabel().
   674 	 * this order is needed for the WE_CLICK event of DrawFaceStringLabel().
   675 	 */
   675 	 */
   676 	enum PlayerFaceWindowWidgets {
   676 	enum SelectCompanyManagerFaceWidgets {
   677 		PFW_WIDGET_CLOSEBOX = 0,
   677 		SCMFW_WIDGET_CLOSEBOX = 0,
   678 		PFW_WIDGET_CAPTION,
   678 		SCMFW_WIDGET_CAPTION,
   679 		PFW_WIDGET_TOGGLE_LARGE_SMALL,
   679 		SCMFW_WIDGET_TOGGLE_LARGE_SMALL,
   680 		PFW_WIDGET_SELECT_FACE,
   680 		SCMFW_WIDGET_SELECT_FACE,
   681 		PFW_WIDGET_CANCEL,
   681 		SCMFW_WIDGET_CANCEL,
   682 		PFW_WIDGET_ACCEPT,
   682 		SCMFW_WIDGET_ACCEPT,
   683 		PFW_WIDGET_MALE,
   683 		SCMFW_WIDGET_MALE,
   684 		PFW_WIDGET_FEMALE,
   684 		SCMFW_WIDGET_FEMALE,
   685 		PFW_WIDGET_RANDOM_NEW_FACE,
   685 		SCMFW_WIDGET_RANDOM_NEW_FACE,
   686 		PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON,
   686 		SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON,
   687 		/* from here is the advanced player face selection window */
   687 		/* from here is the advanced company manager face selection window */
   688 		PFW_WIDGET_LOAD,
   688 		SCMFW_WIDGET_LOAD,
   689 		PFW_WIDGET_FACECODE,
   689 		SCMFW_WIDGET_FACECODE,
   690 		PFW_WIDGET_SAVE,
   690 		SCMFW_WIDGET_SAVE,
   691 		PFW_WIDGET_ETHNICITY_EUR,
   691 		SCMFW_WIDGET_ETHNICITY_EUR,
   692 		PFW_WIDGET_ETHNICITY_AFR,
   692 		SCMFW_WIDGET_ETHNICITY_AFR,
   693 		PFW_WIDGET_HAS_MOUSTACHE_EARRING,
   693 		SCMFW_WIDGET_HAS_MOUSTACHE_EARRING,
   694 		PFW_WIDGET_HAS_GLASSES,
   694 		SCMFW_WIDGET_HAS_GLASSES,
   695 		PFW_WIDGET_EYECOLOUR_L,
   695 		SCMFW_WIDGET_EYECOLOUR_L,
   696 		PFW_WIDGET_EYECOLOUR,
   696 		SCMFW_WIDGET_EYECOLOUR,
   697 		PFW_WIDGET_EYECOLOUR_R,
   697 		SCMFW_WIDGET_EYECOLOUR_R,
   698 		PFW_WIDGET_CHIN_L,
   698 		SCMFW_WIDGET_CHIN_L,
   699 		PFW_WIDGET_CHIN,
   699 		SCMFW_WIDGET_CHIN,
   700 		PFW_WIDGET_CHIN_R,
   700 		SCMFW_WIDGET_CHIN_R,
   701 		PFW_WIDGET_EYEBROWS_L,
   701 		SCMFW_WIDGET_EYEBROWS_L,
   702 		PFW_WIDGET_EYEBROWS,
   702 		SCMFW_WIDGET_EYEBROWS,
   703 		PFW_WIDGET_EYEBROWS_R,
   703 		SCMFW_WIDGET_EYEBROWS_R,
   704 		PFW_WIDGET_LIPS_MOUSTACHE_L,
   704 		SCMFW_WIDGET_LIPS_MOUSTACHE_L,
   705 		PFW_WIDGET_LIPS_MOUSTACHE,
   705 		SCMFW_WIDGET_LIPS_MOUSTACHE,
   706 		PFW_WIDGET_LIPS_MOUSTACHE_R,
   706 		SCMFW_WIDGET_LIPS_MOUSTACHE_R,
   707 		PFW_WIDGET_NOSE_L,
   707 		SCMFW_WIDGET_NOSE_L,
   708 		PFW_WIDGET_NOSE,
   708 		SCMFW_WIDGET_NOSE,
   709 		PFW_WIDGET_NOSE_R,
   709 		SCMFW_WIDGET_NOSE_R,
   710 		PFW_WIDGET_HAIR_L,
   710 		SCMFW_WIDGET_HAIR_L,
   711 		PFW_WIDGET_HAIR,
   711 		SCMFW_WIDGET_HAIR,
   712 		PFW_WIDGET_HAIR_R,
   712 		SCMFW_WIDGET_HAIR_R,
   713 		PFW_WIDGET_JACKET_L,
   713 		SCMFW_WIDGET_JACKET_L,
   714 		PFW_WIDGET_JACKET,
   714 		SCMFW_WIDGET_JACKET,
   715 		PFW_WIDGET_JACKET_R,
   715 		SCMFW_WIDGET_JACKET_R,
   716 		PFW_WIDGET_COLLAR_L,
   716 		SCMFW_WIDGET_COLLAR_L,
   717 		PFW_WIDGET_COLLAR,
   717 		SCMFW_WIDGET_COLLAR,
   718 		PFW_WIDGET_COLLAR_R,
   718 		SCMFW_WIDGET_COLLAR_R,
   719 		PFW_WIDGET_TIE_EARRING_L,
   719 		SCMFW_WIDGET_TIE_EARRING_L,
   720 		PFW_WIDGET_TIE_EARRING,
   720 		SCMFW_WIDGET_TIE_EARRING,
   721 		PFW_WIDGET_TIE_EARRING_R,
   721 		SCMFW_WIDGET_TIE_EARRING_R,
   722 		PFW_WIDGET_GLASSES_L,
   722 		SCMFW_WIDGET_GLASSES_L,
   723 		PFW_WIDGET_GLASSES,
   723 		SCMFW_WIDGET_GLASSES,
   724 		PFW_WIDGET_GLASSES_R,
   724 		SCMFW_WIDGET_GLASSES_R,
   725 	};
   725 	};
   726 	/**
   726 	/**
   727 	 * Draw dynamic a label to the left of the button and a value in the button
   727 	 * Draw dynamic a label to the left of the button and a value in the button
   728 	 *
   728 	 *
   729 	 * @param widget_index   index of this widget in the window
   729 	 * @param widget_index   index of this widget in the window
   752 		}
   752 		}
   753 	}
   753 	}
   754 
   754 
   755 	void UpdateData()
   755 	void UpdateData()
   756 	{
   756 	{
   757 		this->ge = (GenderEthnicity)GB(this->face, _pf_info[PFV_GEN_ETHN].offset, _pf_info[PFV_GEN_ETHN].length); // get the gender and ethnicity
   757 		this->ge = (GenderEthnicity)GB(this->face, _cmf_info[CMFV_GEN_ETHN].offset, _cmf_info[CMFV_GEN_ETHN].length); // get the gender and ethnicity
   758 		this->is_female = HasBit(this->ge, GENDER_FEMALE); // get the gender: 0 == male and 1 == female
   758 		this->is_female = HasBit(this->ge, GENDER_FEMALE); // get the gender: 0 == male and 1 == female
   759 		this->is_moust_male = !is_female && GetPlayerFaceBits(this->face, PFV_HAS_MOUSTACHE, this->ge) != 0; // is a male face with moustache
   759 		this->is_moust_male = !is_female && GetCompanyManagerFaceBits(this->face, CMFV_HAS_MOUSTACHE, this->ge) != 0; // is a male face with moustache
   760 	}
   760 	}
   761 
   761 
   762 public:
   762 public:
   763 	SelectPlayerFaceWindow(const WindowDesc *desc, Window *parent, bool advanced, int top, int left) : Window(desc, parent->window_number)
   763 	SelectCompanyManagerFaceWindow(const WindowDesc *desc, Window *parent, bool advanced, int top, int left) : Window(desc, parent->window_number)
   764 	{
   764 	{
   765 		this->parent = parent;
   765 		this->parent = parent;
   766 		this->caption_color = this->window_number;
   766 		this->caption_color = this->window_number;
   767 		this->face = GetPlayer((PlayerID)this->window_number)->face;
   767 		this->face = GetCompany((CompanyID)this->window_number)->face;
   768 		this->advanced = advanced;
   768 		this->advanced = advanced;
   769 
   769 
   770 		this->UpdateData();
   770 		this->UpdateData();
   771 
   771 
   772 		/* Check if repositioning from default is required */
   772 		/* Check if repositioning from default is required */
   779 	}
   779 	}
   780 
   780 
   781 	virtual void OnPaint()
   781 	virtual void OnPaint()
   782 	{
   782 	{
   783 		/* lower the non-selected gender button */
   783 		/* lower the non-selected gender button */
   784 		this->SetWidgetLoweredState(PFW_WIDGET_MALE,  !this->is_female);
   784 		this->SetWidgetLoweredState(SCMFW_WIDGET_MALE,  !this->is_female);
   785 		this->SetWidgetLoweredState(PFW_WIDGET_FEMALE, this->is_female);
   785 		this->SetWidgetLoweredState(SCMFW_WIDGET_FEMALE, this->is_female);
   786 
   786 
   787 		/* advanced player face selection window */
   787 		/* advanced company manager face selection window */
   788 		if (this->advanced) {
   788 		if (this->advanced) {
   789 			/* lower the non-selected ethnicity button */
   789 			/* lower the non-selected ethnicity button */
   790 			this->SetWidgetLoweredState(PFW_WIDGET_ETHNICITY_EUR, !HasBit(this->ge, ETHNICITY_BLACK));
   790 			this->SetWidgetLoweredState(SCMFW_WIDGET_ETHNICITY_EUR, !HasBit(this->ge, ETHNICITY_BLACK));
   791 			this->SetWidgetLoweredState(PFW_WIDGET_ETHNICITY_AFR,  HasBit(this->ge, ETHNICITY_BLACK));
   791 			this->SetWidgetLoweredState(SCMFW_WIDGET_ETHNICITY_AFR,  HasBit(this->ge, ETHNICITY_BLACK));
   792 
   792 
   793 
   793 
   794 			/* Disable dynamically the widgets which PlayerFaceVariable has less than 2 options
   794 			/* Disable dynamically the widgets which CompanyManagerFaceVariable has less than 2 options
   795 			* (or in other words you haven't any choice).
   795 			* (or in other words you haven't any choice).
   796 			* If the widgets depend on a HAS-variable and this is false the widgets will be disabled, too. */
   796 			* If the widgets depend on a HAS-variable and this is false the widgets will be disabled, too. */
   797 
   797 
   798 			/* Eye colour buttons */
   798 			/* Eye colour buttons */
   799 			this->SetWidgetsDisabledState(_pf_info[PFV_EYE_COLOUR].valid_values[this->ge] < 2,
   799 			this->SetWidgetsDisabledState(_cmf_info[CMFV_EYE_COLOUR].valid_values[this->ge] < 2,
   800 				PFW_WIDGET_EYECOLOUR, PFW_WIDGET_EYECOLOUR_L, PFW_WIDGET_EYECOLOUR_R, WIDGET_LIST_END);
   800 				SCMFW_WIDGET_EYECOLOUR, SCMFW_WIDGET_EYECOLOUR_L, SCMFW_WIDGET_EYECOLOUR_R, WIDGET_LIST_END);
   801 
   801 
   802 			/* Chin buttons */
   802 			/* Chin buttons */
   803 			this->SetWidgetsDisabledState(_pf_info[PFV_CHIN].valid_values[this->ge] < 2,
   803 			this->SetWidgetsDisabledState(_cmf_info[CMFV_CHIN].valid_values[this->ge] < 2,
   804 				PFW_WIDGET_CHIN, PFW_WIDGET_CHIN_L, PFW_WIDGET_CHIN_R, WIDGET_LIST_END);
   804 				SCMFW_WIDGET_CHIN, SCMFW_WIDGET_CHIN_L, SCMFW_WIDGET_CHIN_R, WIDGET_LIST_END);
   805 
   805 
   806 			/* Eyebrows buttons */
   806 			/* Eyebrows buttons */
   807 			this->SetWidgetsDisabledState(_pf_info[PFV_EYEBROWS].valid_values[this->ge] < 2,
   807 			this->SetWidgetsDisabledState(_cmf_info[CMFV_EYEBROWS].valid_values[this->ge] < 2,
   808 				PFW_WIDGET_EYEBROWS, PFW_WIDGET_EYEBROWS_L, PFW_WIDGET_EYEBROWS_R, WIDGET_LIST_END);
   808 				SCMFW_WIDGET_EYEBROWS, SCMFW_WIDGET_EYEBROWS_L, SCMFW_WIDGET_EYEBROWS_R, WIDGET_LIST_END);
   809 
   809 
   810 			/* Lips or (if it a male face with a moustache) moustache buttons */
   810 			/* Lips or (if it a male face with a moustache) moustache buttons */
   811 			this->SetWidgetsDisabledState(_pf_info[this->is_moust_male ? PFV_MOUSTACHE : PFV_LIPS].valid_values[this->ge] < 2,
   811 			this->SetWidgetsDisabledState(_cmf_info[this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS].valid_values[this->ge] < 2,
   812 				PFW_WIDGET_LIPS_MOUSTACHE, PFW_WIDGET_LIPS_MOUSTACHE_L, PFW_WIDGET_LIPS_MOUSTACHE_R, WIDGET_LIST_END);
   812 				SCMFW_WIDGET_LIPS_MOUSTACHE, SCMFW_WIDGET_LIPS_MOUSTACHE_L, SCMFW_WIDGET_LIPS_MOUSTACHE_R, WIDGET_LIST_END);
   813 
   813 
   814 			/* Nose buttons | male faces with moustache haven't any nose options */
   814 			/* Nose buttons | male faces with moustache haven't any nose options */
   815 			this->SetWidgetsDisabledState(_pf_info[PFV_NOSE].valid_values[this->ge] < 2 || this->is_moust_male,
   815 			this->SetWidgetsDisabledState(_cmf_info[CMFV_NOSE].valid_values[this->ge] < 2 || this->is_moust_male,
   816 				PFW_WIDGET_NOSE, PFW_WIDGET_NOSE_L, PFW_WIDGET_NOSE_R, WIDGET_LIST_END);
   816 				SCMFW_WIDGET_NOSE, SCMFW_WIDGET_NOSE_L, SCMFW_WIDGET_NOSE_R, WIDGET_LIST_END);
   817 
   817 
   818 			/* Hair buttons */
   818 			/* Hair buttons */
   819 			this->SetWidgetsDisabledState(_pf_info[PFV_HAIR].valid_values[this->ge] < 2,
   819 			this->SetWidgetsDisabledState(_cmf_info[CMFV_HAIR].valid_values[this->ge] < 2,
   820 				PFW_WIDGET_HAIR, PFW_WIDGET_HAIR_L, PFW_WIDGET_HAIR_R, WIDGET_LIST_END);
   820 				SCMFW_WIDGET_HAIR, SCMFW_WIDGET_HAIR_L, SCMFW_WIDGET_HAIR_R, WIDGET_LIST_END);
   821 
   821 
   822 			/* Jacket buttons */
   822 			/* Jacket buttons */
   823 			this->SetWidgetsDisabledState(_pf_info[PFV_JACKET].valid_values[this->ge] < 2,
   823 			this->SetWidgetsDisabledState(_cmf_info[CMFV_JACKET].valid_values[this->ge] < 2,
   824 				PFW_WIDGET_JACKET, PFW_WIDGET_JACKET_L, PFW_WIDGET_JACKET_R, WIDGET_LIST_END);
   824 				SCMFW_WIDGET_JACKET, SCMFW_WIDGET_JACKET_L, SCMFW_WIDGET_JACKET_R, WIDGET_LIST_END);
   825 
   825 
   826 			/* Collar buttons */
   826 			/* Collar buttons */
   827 			this->SetWidgetsDisabledState(_pf_info[PFV_COLLAR].valid_values[this->ge] < 2,
   827 			this->SetWidgetsDisabledState(_cmf_info[CMFV_COLLAR].valid_values[this->ge] < 2,
   828 				PFW_WIDGET_COLLAR, PFW_WIDGET_COLLAR_L, PFW_WIDGET_COLLAR_R, WIDGET_LIST_END);
   828 				SCMFW_WIDGET_COLLAR, SCMFW_WIDGET_COLLAR_L, SCMFW_WIDGET_COLLAR_R, WIDGET_LIST_END);
   829 
   829 
   830 			/* Tie/earring buttons | female faces without earring haven't any earring options */
   830 			/* Tie/earring buttons | female faces without earring haven't any earring options */
   831 			this->SetWidgetsDisabledState(_pf_info[PFV_TIE_EARRING].valid_values[this->ge] < 2 ||
   831 			this->SetWidgetsDisabledState(_cmf_info[CMFV_TIE_EARRING].valid_values[this->ge] < 2 ||
   832 					(this->is_female && GetPlayerFaceBits(this->face, PFV_HAS_TIE_EARRING, this->ge) == 0),
   832 					(this->is_female && GetCompanyManagerFaceBits(this->face, CMFV_HAS_TIE_EARRING, this->ge) == 0),
   833 				PFW_WIDGET_TIE_EARRING, PFW_WIDGET_TIE_EARRING_L, PFW_WIDGET_TIE_EARRING_R, WIDGET_LIST_END);
   833 				SCMFW_WIDGET_TIE_EARRING, SCMFW_WIDGET_TIE_EARRING_L, SCMFW_WIDGET_TIE_EARRING_R, WIDGET_LIST_END);
   834 
   834 
   835 			/* Glasses buttons | faces without glasses haven't any glasses options */
   835 			/* Glasses buttons | faces without glasses haven't any glasses options */
   836 			this->SetWidgetsDisabledState(_pf_info[PFV_GLASSES].valid_values[this->ge] < 2 || GetPlayerFaceBits(this->face, PFV_HAS_GLASSES, this->ge) == 0,
   836 			this->SetWidgetsDisabledState(_cmf_info[CMFV_GLASSES].valid_values[this->ge] < 2 || GetCompanyManagerFaceBits(this->face, CMFV_HAS_GLASSES, this->ge) == 0,
   837 				PFW_WIDGET_GLASSES, PFW_WIDGET_GLASSES_L, PFW_WIDGET_GLASSES_R, WIDGET_LIST_END);
   837 				SCMFW_WIDGET_GLASSES, SCMFW_WIDGET_GLASSES_L, SCMFW_WIDGET_GLASSES_R, WIDGET_LIST_END);
   838 		}
   838 		}
   839 
   839 
   840 		this->DrawWidgets();
   840 		this->DrawWidgets();
   841 
   841 
   842 		/* Draw dynamic button value and labels for the advanced player face selection window */
   842 		/* Draw dynamic button value and labels for the advanced company manager face selection window */
   843 		if (this->advanced) {
   843 		if (this->advanced) {
   844 			if (this->is_female) {
   844 			if (this->is_female) {
   845 				/* Only for female faces */
   845 				/* Only for female faces */
   846 				this->DrawFaceStringLabel(PFW_WIDGET_HAS_MOUSTACHE_EARRING, STR_FACE_EARRING,   GetPlayerFaceBits(this->face, PFV_HAS_TIE_EARRING, this->ge), true );
   846 				this->DrawFaceStringLabel(SCMFW_WIDGET_HAS_MOUSTACHE_EARRING, STR_FACE_EARRING,   GetCompanyManagerFaceBits(this->face, CMFV_HAS_TIE_EARRING, this->ge), true );
   847 				this->DrawFaceStringLabel(PFW_WIDGET_TIE_EARRING,           STR_FACE_EARRING,   GetPlayerFaceBits(this->face, PFV_TIE_EARRING,     this->ge), false);
   847 				this->DrawFaceStringLabel(SCMFW_WIDGET_TIE_EARRING,           STR_FACE_EARRING,   GetCompanyManagerFaceBits(this->face, CMFV_TIE_EARRING,     this->ge), false);
   848 			} else {
   848 			} else {
   849 				/* Only for male faces */
   849 				/* Only for male faces */
   850 				this->DrawFaceStringLabel(PFW_WIDGET_HAS_MOUSTACHE_EARRING, STR_FACE_MOUSTACHE, GetPlayerFaceBits(this->face, PFV_HAS_MOUSTACHE,   this->ge), true );
   850 				this->DrawFaceStringLabel(SCMFW_WIDGET_HAS_MOUSTACHE_EARRING, STR_FACE_MOUSTACHE, GetCompanyManagerFaceBits(this->face, CMFV_HAS_MOUSTACHE,   this->ge), true );
   851 				this->DrawFaceStringLabel(PFW_WIDGET_TIE_EARRING,           STR_FACE_TIE,       GetPlayerFaceBits(this->face, PFV_TIE_EARRING,     this->ge), false);
   851 				this->DrawFaceStringLabel(SCMFW_WIDGET_TIE_EARRING,           STR_FACE_TIE,       GetCompanyManagerFaceBits(this->face, CMFV_TIE_EARRING,     this->ge), false);
   852 			}
   852 			}
   853 			if (this->is_moust_male) {
   853 			if (this->is_moust_male) {
   854 				/* Only for male faces with moustache */
   854 				/* Only for male faces with moustache */
   855 				this->DrawFaceStringLabel(PFW_WIDGET_LIPS_MOUSTACHE,        STR_FACE_MOUSTACHE, GetPlayerFaceBits(this->face, PFV_MOUSTACHE,       this->ge), false);
   855 				this->DrawFaceStringLabel(SCMFW_WIDGET_LIPS_MOUSTACHE,        STR_FACE_MOUSTACHE, GetCompanyManagerFaceBits(this->face, CMFV_MOUSTACHE,       this->ge), false);
   856 			} else {
   856 			} else {
   857 				/* Only for female faces or male faces without moustache */
   857 				/* Only for female faces or male faces without moustache */
   858 				this->DrawFaceStringLabel(PFW_WIDGET_LIPS_MOUSTACHE,        STR_FACE_LIPS,      GetPlayerFaceBits(this->face, PFV_LIPS,            this->ge), false);
   858 				this->DrawFaceStringLabel(SCMFW_WIDGET_LIPS_MOUSTACHE,        STR_FACE_LIPS,      GetCompanyManagerFaceBits(this->face, CMFV_LIPS,            this->ge), false);
   859 			}
   859 			}
   860 			/* For all faces */
   860 			/* For all faces */
   861 			this->DrawFaceStringLabel(PFW_WIDGET_HAS_GLASSES,           STR_FACE_GLASSES,     GetPlayerFaceBits(this->face, PFV_HAS_GLASSES,     this->ge), true );
   861 			this->DrawFaceStringLabel(SCMFW_WIDGET_HAS_GLASSES,           STR_FACE_GLASSES,     GetCompanyManagerFaceBits(this->face, CMFV_HAS_GLASSES,     this->ge), true );
   862 			this->DrawFaceStringLabel(PFW_WIDGET_HAIR,                  STR_FACE_HAIR,        GetPlayerFaceBits(this->face, PFV_HAIR,            this->ge), false);
   862 			this->DrawFaceStringLabel(SCMFW_WIDGET_HAIR,                  STR_FACE_HAIR,        GetCompanyManagerFaceBits(this->face, CMFV_HAIR,            this->ge), false);
   863 			this->DrawFaceStringLabel(PFW_WIDGET_EYEBROWS,              STR_FACE_EYEBROWS,    GetPlayerFaceBits(this->face, PFV_EYEBROWS,        this->ge), false);
   863 			this->DrawFaceStringLabel(SCMFW_WIDGET_EYEBROWS,              STR_FACE_EYEBROWS,    GetCompanyManagerFaceBits(this->face, CMFV_EYEBROWS,        this->ge), false);
   864 			this->DrawFaceStringLabel(PFW_WIDGET_EYECOLOUR,             STR_FACE_EYECOLOUR,   GetPlayerFaceBits(this->face, PFV_EYE_COLOUR,      this->ge), false);
   864 			this->DrawFaceStringLabel(SCMFW_WIDGET_EYECOLOUR,             STR_FACE_EYECOLOUR,   GetCompanyManagerFaceBits(this->face, CMFV_EYE_COLOUR,      this->ge), false);
   865 			this->DrawFaceStringLabel(PFW_WIDGET_GLASSES,               STR_FACE_GLASSES,     GetPlayerFaceBits(this->face, PFV_GLASSES,         this->ge), false);
   865 			this->DrawFaceStringLabel(SCMFW_WIDGET_GLASSES,               STR_FACE_GLASSES,     GetCompanyManagerFaceBits(this->face, CMFV_GLASSES,         this->ge), false);
   866 			this->DrawFaceStringLabel(PFW_WIDGET_NOSE,                  STR_FACE_NOSE,        GetPlayerFaceBits(this->face, PFV_NOSE,            this->ge), false);
   866 			this->DrawFaceStringLabel(SCMFW_WIDGET_NOSE,                  STR_FACE_NOSE,        GetCompanyManagerFaceBits(this->face, CMFV_NOSE,            this->ge), false);
   867 			this->DrawFaceStringLabel(PFW_WIDGET_CHIN,                  STR_FACE_CHIN,        GetPlayerFaceBits(this->face, PFV_CHIN,            this->ge), false);
   867 			this->DrawFaceStringLabel(SCMFW_WIDGET_CHIN,                  STR_FACE_CHIN,        GetCompanyManagerFaceBits(this->face, CMFV_CHIN,            this->ge), false);
   868 			this->DrawFaceStringLabel(PFW_WIDGET_JACKET,                STR_FACE_JACKET,      GetPlayerFaceBits(this->face, PFV_JACKET,          this->ge), false);
   868 			this->DrawFaceStringLabel(SCMFW_WIDGET_JACKET,                STR_FACE_JACKET,      GetCompanyManagerFaceBits(this->face, CMFV_JACKET,          this->ge), false);
   869 			this->DrawFaceStringLabel(PFW_WIDGET_COLLAR,                STR_FACE_COLLAR,      GetPlayerFaceBits(this->face, PFV_COLLAR,          this->ge), false);
   869 			this->DrawFaceStringLabel(SCMFW_WIDGET_COLLAR,                STR_FACE_COLLAR,      GetCompanyManagerFaceBits(this->face, CMFV_COLLAR,          this->ge), false);
   870 		}
   870 		}
   871 
   871 
   872 		/* Draw the player face picture */
   872 		/* Draw the company manager face picture */
   873 		DrawPlayerFace(this->face, GetPlayer((PlayerID)this->window_number)->player_color, 2, 16);
   873 		DrawCompanyManagerFace(this->face, GetCompany((CompanyID)this->window_number)->colour, 2, 16);
   874 	}
   874 	}
   875 
   875 
   876 	virtual void OnClick(Point pt, int widget)
   876 	virtual void OnClick(Point pt, int widget)
   877 	{
   877 	{
   878 		switch (widget) {
   878 		switch (widget) {
   879 			/* Toggle size, advanced/simple face selection */
   879 			/* Toggle size, advanced/simple face selection */
   880 			case PFW_WIDGET_TOGGLE_LARGE_SMALL:
   880 			case SCMFW_WIDGET_TOGGLE_LARGE_SMALL:
   881 			case PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON: {
   881 			case SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON: {
   882 				DoCommandP(0, 0, this->face, NULL, CMD_SET_PLAYER_FACE);
   882 				DoCommandP(0, 0, this->face, NULL, CMD_SET_COMPANY_MANAGER_FACE);
   883 
   883 
   884 				/* Backup some data before deletion */
   884 				/* Backup some data before deletion */
   885 				int oldtop = this->top;     ///< current top position of the window before closing it
   885 				int oldtop = this->top;     ///< current top position of the window before closing it
   886 				int oldleft = this->left;   ///< current top position of the window before closing it
   886 				int oldleft = this->left;   ///< current top position of the window before closing it
   887 				bool adv = !this->advanced;
   887 				bool adv = !this->advanced;
   888 				Window *parent = this->parent;
   888 				Window *parent = this->parent;
   889 
   889 
   890 				delete this;
   890 				delete this;
   891 
   891 
   892 				/* Open up the (toggled size) Face selection window at the same position as the previous */
   892 				/* Open up the (toggled size) Face selection window at the same position as the previous */
   893 				DoSelectPlayerFace(parent, adv, oldtop, oldleft);
   893 				DoSelectCompanyManagerFace(parent, adv, oldtop, oldleft);
   894 			} break;
   894 			} break;
   895 
   895 
   896 
   896 
   897 			/* OK button */
   897 			/* OK button */
   898 			case PFW_WIDGET_ACCEPT:
   898 			case SCMFW_WIDGET_ACCEPT:
   899 				DoCommandP(0, 0, this->face, NULL, CMD_SET_PLAYER_FACE);
   899 				DoCommandP(0, 0, this->face, NULL, CMD_SET_COMPANY_MANAGER_FACE);
   900 				/* Fall-Through */
   900 				/* Fall-Through */
   901 
   901 
   902 			/* Cancel button */
   902 			/* Cancel button */
   903 			case PFW_WIDGET_CANCEL:
   903 			case SCMFW_WIDGET_CANCEL:
   904 				delete this;
   904 				delete this;
   905 				break;
   905 				break;
   906 
   906 
   907 			/* Load button */
   907 			/* Load button */
   908 			case PFW_WIDGET_LOAD:
   908 			case SCMFW_WIDGET_LOAD:
   909 				this->face = _player_face;
   909 				this->face = _company_manager_face;
   910 				ScaleAllPlayerFaceBits(this->face);
   910 				ScaleAllCompanyManagerFaceBits(this->face);
   911 				ShowErrorMessage(INVALID_STRING_ID, STR_FACE_LOAD_DONE, 0, 0);
   911 				ShowErrorMessage(INVALID_STRING_ID, STR_FACE_LOAD_DONE, 0, 0);
   912 				this->UpdateData();
   912 				this->UpdateData();
   913 				this->SetDirty();
   913 				this->SetDirty();
   914 				break;
   914 				break;
   915 
   915 
   916 			/* 'Player face number' button, view and/or set player face number */
   916 			/* 'Company manager face number' button, view and/or set company manager face number */
   917 			case PFW_WIDGET_FACECODE:
   917 			case SCMFW_WIDGET_FACECODE:
   918 				SetDParam(0, this->face);
   918 				SetDParam(0, this->face);
   919 				ShowQueryString(STR_JUST_INT, STR_FACE_FACECODE_CAPTION, 10 + 1, 0, this, CS_NUMERAL, QSF_NONE);
   919 				ShowQueryString(STR_JUST_INT, STR_FACE_FACECODE_CAPTION, 10 + 1, 0, this, CS_NUMERAL, QSF_NONE);
   920 				break;
   920 				break;
   921 
   921 
   922 			/* Save button */
   922 			/* Save button */
   923 			case PFW_WIDGET_SAVE:
   923 			case SCMFW_WIDGET_SAVE:
   924 				_player_face = this->face;
   924 				_company_manager_face = this->face;
   925 				ShowErrorMessage(INVALID_STRING_ID, STR_FACE_SAVE_DONE, 0, 0);
   925 				ShowErrorMessage(INVALID_STRING_ID, STR_FACE_SAVE_DONE, 0, 0);
   926 				break;
   926 				break;
   927 
   927 
   928 			/* Toggle gender (male/female) button */
   928 			/* Toggle gender (male/female) button */
   929 			case PFW_WIDGET_MALE:
   929 			case SCMFW_WIDGET_MALE:
   930 			case PFW_WIDGET_FEMALE:
   930 			case SCMFW_WIDGET_FEMALE:
   931 				SetPlayerFaceBits(this->face, PFV_GENDER, this->ge, widget - PFW_WIDGET_MALE);
   931 				SetCompanyManagerFaceBits(this->face, CMFV_GENDER, this->ge, widget - SCMFW_WIDGET_MALE);
   932 				ScaleAllPlayerFaceBits(this->face);
   932 				ScaleAllCompanyManagerFaceBits(this->face);
   933 				this->UpdateData();
   933 				this->UpdateData();
   934 				this->SetDirty();
   934 				this->SetDirty();
   935 				break;
   935 				break;
   936 
   936 
   937 			/* Randomize face button */
   937 			/* Randomize face button */
   938 			case PFW_WIDGET_RANDOM_NEW_FACE:
   938 			case SCMFW_WIDGET_RANDOM_NEW_FACE:
   939 				RandomPlayerFaceBits(this->face, this->ge, this->advanced);
   939 				RandomCompanyManagerFaceBits(this->face, this->ge, this->advanced);
   940 				this->UpdateData();
   940 				this->UpdateData();
   941 				this->SetDirty();
   941 				this->SetDirty();
   942 				break;
   942 				break;
   943 
   943 
   944 			/* Toggle ethnicity (european/african) button */
   944 			/* Toggle ethnicity (european/african) button */
   945 			case PFW_WIDGET_ETHNICITY_EUR:
   945 			case SCMFW_WIDGET_ETHNICITY_EUR:
   946 			case PFW_WIDGET_ETHNICITY_AFR:
   946 			case SCMFW_WIDGET_ETHNICITY_AFR:
   947 				SetPlayerFaceBits(this->face, PFV_ETHNICITY, this->ge, widget - PFW_WIDGET_ETHNICITY_EUR);
   947 				SetCompanyManagerFaceBits(this->face, CMFV_ETHNICITY, this->ge, widget - SCMFW_WIDGET_ETHNICITY_EUR);
   948 				ScaleAllPlayerFaceBits(this->face);
   948 				ScaleAllCompanyManagerFaceBits(this->face);
   949 				this->UpdateData();
   949 				this->UpdateData();
   950 				this->SetDirty();
   950 				this->SetDirty();
   951 				break;
   951 				break;
   952 
   952 
   953 			default:
   953 			default:
   954 				/* For all buttons from PFW_WIDGET_HAS_MOUSTACHE_EARRING to PFW_WIDGET_GLASSES_R is the same function.
   954 				/* For all buttons from SCMFW_WIDGET_HAS_MOUSTACHE_EARRING to SCMFW_WIDGET_GLASSES_R is the same function.
   955 				* Therefor is this combined function.
   955 				* Therefor is this combined function.
   956 				* First it checks which PlayerFaceVariable will be change and then
   956 				* First it checks which CompanyManagerFaceVariable will be change and then
   957 				* a: invert the value for boolean variables
   957 				* a: invert the value for boolean variables
   958 				* or b: it checks inside of IncreasePlayerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
   958 				* or b: it checks inside of IncreaseCompanyManagerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
   959 				if (this->advanced && widget >= PFW_WIDGET_HAS_MOUSTACHE_EARRING && widget <= PFW_WIDGET_GLASSES_R) {
   959 				if (this->advanced && widget >= SCMFW_WIDGET_HAS_MOUSTACHE_EARRING && widget <= SCMFW_WIDGET_GLASSES_R) {
   960 					PlayerFaceVariable pfv; // which PlayerFaceVariable shall be edited
   960 					CompanyManagerFaceVariable cmfv; // which CompanyManagerFaceVariable shall be edited
   961 
   961 
   962 					if (widget < PFW_WIDGET_EYECOLOUR_L) { // Bool buttons
   962 					if (widget < SCMFW_WIDGET_EYECOLOUR_L) { // Bool buttons
   963 						switch (widget - PFW_WIDGET_HAS_MOUSTACHE_EARRING) {
   963 						switch (widget - SCMFW_WIDGET_HAS_MOUSTACHE_EARRING) {
   964 							default: NOT_REACHED();
   964 							default: NOT_REACHED();
   965 							case 0: pfv = this->is_female ? PFV_HAS_TIE_EARRING : PFV_HAS_MOUSTACHE; break; // Has earring/moustache button
   965 							case 0: cmfv = this->is_female ? CMFV_HAS_TIE_EARRING : CMFV_HAS_MOUSTACHE; break; // Has earring/moustache button
   966 							case 1: pfv = PFV_HAS_GLASSES; break; // Has glasses button
   966 							case 1: cmfv = CMFV_HAS_GLASSES; break; // Has glasses button
   967 						}
   967 						}
   968 						SetPlayerFaceBits(this->face, pfv, this->ge, !GetPlayerFaceBits(this->face, pfv, this->ge));
   968 						SetCompanyManagerFaceBits(this->face, cmfv, this->ge, !GetCompanyManagerFaceBits(this->face, cmfv, this->ge));
   969 						ScaleAllPlayerFaceBits(this->face);
   969 						ScaleAllCompanyManagerFaceBits(this->face);
   970 					} else { // Value buttons
   970 					} else { // Value buttons
   971 						switch ((widget - PFW_WIDGET_EYECOLOUR_L) / 3) {
   971 						switch ((widget - SCMFW_WIDGET_EYECOLOUR_L) / 3) {
   972 							default: NOT_REACHED();
   972 							default: NOT_REACHED();
   973 							case 0: pfv = PFV_EYE_COLOUR; break;  // Eye colour buttons
   973 							case 0: cmfv = CMFV_EYE_COLOUR; break;  // Eye colour buttons
   974 							case 1: pfv = PFV_CHIN; break;        // Chin buttons
   974 							case 1: cmfv = CMFV_CHIN; break;        // Chin buttons
   975 							case 2: pfv = PFV_EYEBROWS; break;    // Eyebrows buttons
   975 							case 2: cmfv = CMFV_EYEBROWS; break;    // Eyebrows buttons
   976 							case 3: pfv = this->is_moust_male ? PFV_MOUSTACHE : PFV_LIPS; break; // Moustache or lips buttons
   976 							case 3: cmfv = this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS; break; // Moustache or lips buttons
   977 							case 4: pfv = PFV_NOSE; break;        // Nose buttons
   977 							case 4: cmfv = CMFV_NOSE; break;        // Nose buttons
   978 							case 5: pfv = PFV_HAIR; break;        // Hair buttons
   978 							case 5: cmfv = CMFV_HAIR; break;        // Hair buttons
   979 							case 6: pfv = PFV_JACKET; break;      // Jacket buttons
   979 							case 6: cmfv = CMFV_JACKET; break;      // Jacket buttons
   980 							case 7: pfv = PFV_COLLAR; break;      // Collar buttons
   980 							case 7: cmfv = CMFV_COLLAR; break;      // Collar buttons
   981 							case 8: pfv = PFV_TIE_EARRING; break; // Tie/earring buttons
   981 							case 8: cmfv = CMFV_TIE_EARRING; break; // Tie/earring buttons
   982 							case 9: pfv = PFV_GLASSES; break;     // Glasses buttons
   982 							case 9: cmfv = CMFV_GLASSES; break;     // Glasses buttons
   983 						}
   983 						}
   984 						/* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
   984 						/* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
   985 						IncreasePlayerFaceBits(this->face, pfv, this->ge, (((widget - PFW_WIDGET_EYECOLOUR_L) % 3) != 0) ? 1 : -1);
   985 						IncreaseCompanyManagerFaceBits(this->face, cmfv, this->ge, (((widget - SCMFW_WIDGET_EYECOLOUR_L) % 3) != 0) ? 1 : -1);
   986 					}
   986 					}
   987 					this->UpdateData();
   987 					this->UpdateData();
   988 					this->SetDirty();
   988 					this->SetDirty();
   989 				}
   989 				}
   990 				break;
   990 				break;
   992 	}
   992 	}
   993 
   993 
   994 	virtual void OnQueryTextFinished(char *str)
   994 	virtual void OnQueryTextFinished(char *str)
   995 	{
   995 	{
   996 		if (str == NULL) return;
   996 		if (str == NULL) return;
   997 		/* Set a new player face number */
   997 		/* Set a new company manager face number */
   998 		if (!StrEmpty(str)) {
   998 		if (!StrEmpty(str)) {
   999 			this->face = strtoul(str, NULL, 10);
   999 			this->face = strtoul(str, NULL, 10);
  1000 			ScaleAllPlayerFaceBits(this->face);
  1000 			ScaleAllCompanyManagerFaceBits(this->face);
  1001 			ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_SET, 0, 0);
  1001 			ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_SET, 0, 0);
  1002 			this->UpdateData();
  1002 			this->UpdateData();
  1003 			this->SetDirty();
  1003 			this->SetDirty();
  1004 		} else {
  1004 		} else {
  1005 			ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_ERR, 0, 0);
  1005 			ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_ERR, 0, 0);
  1006 		}
  1006 		}
  1007 	}
  1007 	}
  1008 };
  1008 };
  1009 
  1009 
  1010 /** normal/simple player face selection window description */
  1010 /** normal/simple company manager face selection window description */
  1011 static const WindowDesc _select_player_face_desc = {
  1011 static const WindowDesc _select_company_manager_face_desc = {
  1012 	WDP_AUTO, WDP_AUTO, 190, 163, 190, 163,
  1012 	WDP_AUTO, WDP_AUTO, 190, 163, 190, 163,
  1013 	WC_PLAYER_FACE, WC_NONE,
  1013 	WC_COMPANY_MANAGER_FACE, WC_NONE,
  1014 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
  1014 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
  1015 	_select_player_face_widgets,
  1015 	_select_company_manager_face_widgets,
  1016 };
  1016 };
  1017 
  1017 
  1018 /** advanced player face selection window description */
  1018 /** advanced company manager face selection window description */
  1019 static const WindowDesc _select_player_face_adv_desc = {
  1019 static const WindowDesc _select_company_manager_face_adv_desc = {
  1020 	WDP_AUTO, WDP_AUTO, 220, 220, 220, 220,
  1020 	WDP_AUTO, WDP_AUTO, 220, 220, 220, 220,
  1021 	WC_PLAYER_FACE, WC_NONE,
  1021 	WC_COMPANY_MANAGER_FACE, WC_NONE,
  1022 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
  1022 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
  1023 	_select_player_face_adv_widgets,
  1023 	_select_company_manager_face_adv_widgets,
  1024 };
  1024 };
  1025 
  1025 
  1026 /**
  1026 /**
  1027  * Open the simple/advanced player face selection window
  1027  * Open the simple/advanced company manager face selection window
  1028  *
  1028  *
  1029  * @param player the player which face shall be edited
  1029  * @param parent the parent company window
  1030  * @param adv    simple or advanced player face selection window
  1030  * @param adv    simple or advanced face selection window
  1031  * @param top    previous top position of the window
  1031  * @param top    previous top position of the window
  1032  * @param left   previous left position of the window
  1032  * @param left   previous left position of the window
  1033  *
       
  1034  * @pre is player a valid player
       
  1035  */
  1033  */
  1036 static void DoSelectPlayerFace(Window *parent, bool adv, int top, int left)
  1034 static void DoSelectCompanyManagerFace(Window *parent, bool adv, int top, int left)
  1037 {
  1035 {
  1038 	if (!IsValidPlayerID((PlayerID)parent->window_number)) return;
  1036 	if (!IsValidCompanyID((CompanyID)parent->window_number)) return;
  1039 
  1037 
  1040 	if (BringWindowToFrontById(WC_PLAYER_FACE, parent->window_number)) return;
  1038 	if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE, parent->window_number)) return;
  1041 	new SelectPlayerFaceWindow(adv ? &_select_player_face_adv_desc : &_select_player_face_desc, parent, adv, top, left); // simple or advanced window
  1039 	new SelectCompanyManagerFaceWindow(adv ? &_select_company_manager_face_adv_desc : &_select_company_manager_face_desc, parent, adv, top, left); // simple or advanced window
  1042 }
  1040 }
  1043 
  1041 
  1044 
  1042 
  1045 /* Names of the widgets. Keep them in the same order as in the widget array */
  1043 /* Names of the widgets. Keep them in the same order as in the widget array */
  1046 enum PlayerCompanyWindowWidgets {
  1044 enum CompanyWindowWidgets {
  1047 	PCW_WIDGET_CLOSEBOX = 0,
  1045 	CW_WIDGET_CLOSEBOX = 0,
  1048 	PCW_WIDGET_CAPTION,
  1046 	CW_WIDGET_CAPTION,
  1049 	PCW_WIDGET_FACE,
  1047 	CW_WIDGET_FACE,
  1050 	PCW_WIDGET_NEW_FACE,
  1048 	CW_WIDGET_NEW_FACE,
  1051 	PCW_WIDGET_COLOR_SCHEME,
  1049 	CW_WIDGET_COLOR_SCHEME,
  1052 	PCW_WIDGET_PRESIDENT_NAME,
  1050 	CW_WIDGET_PRESIDENT_NAME,
  1053 	PCW_WIDGET_COMPANY_NAME,
  1051 	CW_WIDGET_COMPANY_NAME,
  1054 	PCW_WIDGET_BUILD_VIEW_HQ,
  1052 	CW_WIDGET_BUILD_VIEW_HQ,
  1055 	PCW_WIDGET_RELOCATE_HQ,
  1053 	CW_WIDGET_RELOCATE_HQ,
  1056 	PCW_WIDGET_BUY_SHARE,
  1054 	CW_WIDGET_BUY_SHARE,
  1057 	PCW_WIDGET_SELL_SHARE,
  1055 	CW_WIDGET_SELL_SHARE,
  1058 	PCW_WIDGET_COMPANY_PASSWORD,
  1056 	CW_WIDGET_COMPANY_PASSWORD,
  1059 };
  1057 };
  1060 
  1058 
  1061 static const Widget _player_company_widgets[] = {
  1059 static const Widget _company_widgets[] = {
  1062 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
  1060 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
  1063 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   359,     0,    13, STR_7001,                          STR_018C_WINDOW_TITLE_DRAG_THIS},
  1061 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   359,     0,    13, STR_7001,                          STR_018C_WINDOW_TITLE_DRAG_THIS},
  1064 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   359,    14,   157, 0x0,                               STR_NULL},
  1062 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   359,    14,   157, 0x0,                               STR_NULL},
  1065 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,    89,   158,   169, STR_7004_NEW_FACE,                 STR_7030_SELECT_NEW_FACE_FOR_PRESIDENT},
  1063 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,    89,   158,   169, STR_7004_NEW_FACE,                 STR_7030_SELECT_NEW_FACE_FOR_PRESIDENT},
  1066 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    90,   179,   158,   169, STR_7005_COLOR_SCHEME,             STR_7031_CHANGE_THE_COMPANY_VEHICLE},
  1064 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,    90,   179,   158,   169, STR_7005_COLOR_SCHEME,             STR_7031_CHANGE_THE_COMPANY_VEHICLE},
  1075 };
  1073 };
  1076 
  1074 
  1077 
  1075 
  1078 /**
  1076 /**
  1079  * Draws text "Vehicles:" and number of all vehicle types, or "(none)"
  1077  * Draws text "Vehicles:" and number of all vehicle types, or "(none)"
  1080  * @param player ID of player to print statistics of
  1078  * @param company ID of company to print statistics of
  1081  */
  1079  */
  1082 static void DrawPlayerVehiclesAmount(PlayerID player)
  1080 static void DrawCompanyVehiclesAmount(CompanyID company)
  1083 {
  1081 {
  1084 	const int x = 110;
  1082 	const int x = 110;
  1085 	int y = 63;
  1083 	int y = 63;
  1086 	const Vehicle *v;
  1084 	const Vehicle *v;
  1087 	uint train = 0;
  1085 	uint train = 0;
  1090 	uint ship  = 0;
  1088 	uint ship  = 0;
  1091 
  1089 
  1092 	DrawString(x, y, STR_7039_VEHICLES, TC_FROMSTRING);
  1090 	DrawString(x, y, STR_7039_VEHICLES, TC_FROMSTRING);
  1093 
  1091 
  1094 	FOR_ALL_VEHICLES(v) {
  1092 	FOR_ALL_VEHICLES(v) {
  1095 		if (v->owner == player) {
  1093 		if (v->owner == company) {
  1096 			switch (v->type) {
  1094 			switch (v->type) {
  1097 				case VEH_TRAIN:    if (IsFrontEngine(v)) train++; break;
  1095 				case VEH_TRAIN:    if (IsFrontEngine(v)) train++; break;
  1098 				case VEH_ROAD:     if (IsRoadVehFront(v)) road++; break;
  1096 				case VEH_ROAD:     if (IsRoadVehFront(v)) road++; break;
  1099 				case VEH_AIRCRAFT: if (IsNormalAircraft(v)) air++; break;
  1097 				case VEH_AIRCRAFT: if (IsNormalAircraft(v)) air++; break;
  1100 				case VEH_SHIP:     ship++; break;
  1098 				case VEH_SHIP:     ship++; break;
  1129 			DrawString(x + 70, y, STR_SHIPS, TC_FROMSTRING);
  1127 			DrawString(x + 70, y, STR_SHIPS, TC_FROMSTRING);
  1130 		}
  1128 		}
  1131 	}
  1129 	}
  1132 }
  1130 }
  1133 
  1131 
  1134 int GetAmountOwnedBy(const Player *p, PlayerID owner)
  1132 int GetAmountOwnedBy(const Company *c, Owner owner)
  1135 {
  1133 {
  1136 	return (p->share_owners[0] == owner) +
  1134 	return (c->share_owners[0] == owner) +
  1137 				 (p->share_owners[1] == owner) +
  1135 				 (c->share_owners[1] == owner) +
  1138 				 (p->share_owners[2] == owner) +
  1136 				 (c->share_owners[2] == owner) +
  1139 				 (p->share_owners[3] == owner);
  1137 				 (c->share_owners[3] == owner);
  1140 }
  1138 }
  1141 
  1139 
  1142 /**
  1140 /**
  1143  * Draws list of all companies with shares
  1141  * Draws list of all companies with shares
  1144  * @param p pointer to the Player structure
  1142  * @param c pointer to the Company structure
  1145  */
  1143  */
  1146 static void DrawCompanyOwnerText(const Player *p)
  1144 static void DrawCompanyOwnerText(const Company *c)
  1147 {
  1145 {
  1148 	const Player *p2;
  1146 	const Company *c2;
  1149 	uint num = 0;
  1147 	uint num = 0;
  1150 	const byte height = GetCharacterHeight(FS_NORMAL);
  1148 	const byte height = GetCharacterHeight(FS_NORMAL);
  1151 
  1149 
  1152 	FOR_ALL_PLAYERS(p2) {
  1150 	FOR_ALL_COMPANIES(c2) {
  1153 		uint amt = GetAmountOwnedBy(p, p2->index);
  1151 		uint amt = GetAmountOwnedBy(c, c2->index);
  1154 		if (amt != 0) {
  1152 		if (amt != 0) {
  1155 			SetDParam(0, amt * 25);
  1153 			SetDParam(0, amt * 25);
  1156 			SetDParam(1, p2->index);
  1154 			SetDParam(1, c2->index);
  1157 
  1155 
  1158 			DrawString(120, (num++) * height + 116, STR_707D_OWNED_BY, TC_FROMSTRING);
  1156 			DrawString(120, (num++) * height + 116, STR_707D_OWNED_BY, TC_FROMSTRING);
  1159 		}
  1157 		}
  1160 	}
  1158 	}
  1161 }
  1159 }
  1162 
  1160 
  1163 /**
  1161 /**
  1164  * Player company window event definition
  1162  * Window with general information about a company
  1165  *
       
  1166  * @param w window pointer
       
  1167  * @param e event been triggered
       
  1168  */
  1163  */
  1169 struct PlayerCompanyWindow : Window
  1164 struct CompanyWindow : Window
  1170 {
  1165 {
  1171 	PlayerCompanyWindowWidgets query_widget;
  1166 	CompanyWindowWidgets query_widget;
  1172 
  1167 
  1173 	PlayerCompanyWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
  1168 	CompanyWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
  1174 	{
  1169 	{
  1175 		this->caption_color = this->window_number;
  1170 		this->caption_color = this->window_number;
  1176 		this->FindWindowPlacementAndResize(desc);
  1171 		this->FindWindowPlacementAndResize(desc);
  1177 	}
  1172 	}
  1178 
  1173 
  1179 	virtual void OnPaint()
  1174 	virtual void OnPaint()
  1180 	{
  1175 	{
  1181 		const Player *p = GetPlayer((PlayerID)this->window_number);
  1176 		const Company *c = GetCompany((CompanyID)this->window_number);
  1182 		bool local = this->window_number == _local_player;
  1177 		bool local = this->window_number == _local_company;
  1183 
  1178 
  1184 		this->SetWidgetHiddenState(PCW_WIDGET_NEW_FACE,       !local);
  1179 		this->SetWidgetHiddenState(CW_WIDGET_NEW_FACE,       !local);
  1185 		this->SetWidgetHiddenState(PCW_WIDGET_COLOR_SCHEME,   !local);
  1180 		this->SetWidgetHiddenState(CW_WIDGET_COLOR_SCHEME,   !local);
  1186 		this->SetWidgetHiddenState(PCW_WIDGET_PRESIDENT_NAME, !local);
  1181 		this->SetWidgetHiddenState(CW_WIDGET_PRESIDENT_NAME, !local);
  1187 		this->SetWidgetHiddenState(PCW_WIDGET_COMPANY_NAME,   !local);
  1182 		this->SetWidgetHiddenState(CW_WIDGET_COMPANY_NAME,   !local);
  1188 		this->widget[PCW_WIDGET_BUILD_VIEW_HQ].data = (local && p->location_of_HQ == 0) ? STR_706F_BUILD_HQ : STR_7072_VIEW_HQ;
  1183 		this->widget[CW_WIDGET_BUILD_VIEW_HQ].data = (local && c->location_of_HQ == 0) ? STR_706F_BUILD_HQ : STR_7072_VIEW_HQ;
  1189 		if (local && p->location_of_HQ != 0) this->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; //HQ is already built.
  1184 		if (local && c->location_of_HQ != 0) this->widget[CW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; //HQ is already built.
  1190 		this->SetWidgetDisabledState(PCW_WIDGET_BUILD_VIEW_HQ, !local && p->location_of_HQ == 0);
  1185 		this->SetWidgetDisabledState(CW_WIDGET_BUILD_VIEW_HQ, !local && c->location_of_HQ == 0);
  1191 		this->SetWidgetHiddenState(PCW_WIDGET_RELOCATE_HQ,      !local || p->location_of_HQ == 0);
  1186 		this->SetWidgetHiddenState(CW_WIDGET_RELOCATE_HQ,      !local || c->location_of_HQ == 0);
  1192 		this->SetWidgetHiddenState(PCW_WIDGET_BUY_SHARE,        local);
  1187 		this->SetWidgetHiddenState(CW_WIDGET_BUY_SHARE,        local);
  1193 		this->SetWidgetHiddenState(PCW_WIDGET_SELL_SHARE,       local);
  1188 		this->SetWidgetHiddenState(CW_WIDGET_SELL_SHARE,       local);
  1194 		this->SetWidgetHiddenState(PCW_WIDGET_COMPANY_PASSWORD, !local || !_networking);
  1189 		this->SetWidgetHiddenState(CW_WIDGET_COMPANY_PASSWORD, !local || !_networking);
  1195 
  1190 
  1196 		if (!local) {
  1191 		if (!local) {
  1197 			if (_settings_game.economy.allow_shares) { // Shares are allowed
  1192 			if (_settings_game.economy.allow_shares) { // Shares are allowed
  1198 				/* If all shares are owned by someone (none by nobody), disable buy button */
  1193 				/* If all shares are owned by someone (none by nobody), disable buy button */
  1199 				this->SetWidgetDisabledState(PCW_WIDGET_BUY_SHARE, GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0 ||
  1194 				this->SetWidgetDisabledState(CW_WIDGET_BUY_SHARE, GetAmountOwnedBy(c, INVALID_OWNER) == 0 ||
  1200 						/* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */
  1195 						/* Only 25% left to buy. If the company is human, disable buying it up.. TODO issues! */
  1201 						(GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) ||
  1196 						(GetAmountOwnedBy(c, INVALID_OWNER) == 1 && !c->is_ai) ||
  1202 						/* Spectators cannot do anything of course */
  1197 						/* Spectators cannot do anything of course */
  1203 						_local_player == PLAYER_SPECTATOR);
  1198 						_local_company == COMPANY_SPECTATOR);
  1204 
  1199 
  1205 				/* If the player doesn't own any shares, disable sell button */
  1200 				/* If the company doesn't own any shares, disable sell button */
  1206 				this->SetWidgetDisabledState(PCW_WIDGET_SELL_SHARE, (GetAmountOwnedBy(p, _local_player) == 0) ||
  1201 				this->SetWidgetDisabledState(CW_WIDGET_SELL_SHARE, (GetAmountOwnedBy(c, _local_company) == 0) ||
  1207 						/* Spectators cannot do anything of course */
  1202 						/* Spectators cannot do anything of course */
  1208 						_local_player == PLAYER_SPECTATOR);
  1203 						_local_company == COMPANY_SPECTATOR);
  1209 			} else { // Shares are not allowed, disable buy/sell buttons
  1204 			} else { // Shares are not allowed, disable buy/sell buttons
  1210 				this->DisableWidget(PCW_WIDGET_BUY_SHARE);
  1205 				this->DisableWidget(CW_WIDGET_BUY_SHARE);
  1211 				this->DisableWidget(PCW_WIDGET_SELL_SHARE);
  1206 				this->DisableWidget(CW_WIDGET_SELL_SHARE);
  1212 			}
  1207 			}
  1213 		}
  1208 		}
  1214 
  1209 
  1215 		SetDParam(0, p->index);
  1210 		SetDParam(0, c->index);
  1216 		SetDParam(1, p->index);
  1211 		SetDParam(1, c->index);
  1217 
  1212 
  1218 		this->DrawWidgets();
  1213 		this->DrawWidgets();
  1219 
  1214 
  1220 		/* Player face */
  1215 		/* Company manager's face */
  1221 		DrawPlayerFace(p->face, p->player_color, 2, 16);
  1216 		DrawCompanyManagerFace(c->face, c->colour, 2, 16);
  1222 
  1217 
  1223 		/* "xxx (Manager)" */
  1218 		/* "xxx (Manager)" */
  1224 		SetDParam(0, p->index);
  1219 		SetDParam(0, c->index);
  1225 		DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, MAX_LENGTH_PRESIDENT_NAME_PIXELS);
  1220 		DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, MAX_LENGTH_PRESIDENT_NAME_PIXELS);
  1226 
  1221 
  1227 		/* "Inaugurated:" */
  1222 		/* "Inaugurated:" */
  1228 		SetDParam(0, p->inaugurated_year);
  1223 		SetDParam(0, c->inaugurated_year);
  1229 		DrawString(110, 23, STR_7038_INAUGURATED, TC_FROMSTRING);
  1224 		DrawString(110, 23, STR_7038_INAUGURATED, TC_FROMSTRING);
  1230 
  1225 
  1231 		/* "Colour scheme:" */
  1226 		/* "Colour scheme:" */
  1232 		DrawString(110, 43, STR_7006_COLOR_SCHEME, TC_FROMSTRING);
  1227 		DrawString(110, 43, STR_7006_COLOR_SCHEME, TC_FROMSTRING);
  1233 		/* Draw company-colour bus */
  1228 		/* Draw company-colour bus */
  1234 		DrawSprite(SPR_VEH_BUS_SW_VIEW, PLAYER_SPRITE_COLOR(p->index), 215, 44);
  1229 		DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOR(c->index), 215, 44);
  1235 
  1230 
  1236 		/* "Vehicles:" */
  1231 		/* "Vehicles:" */
  1237 		DrawPlayerVehiclesAmount((PlayerID)this->window_number);
  1232 		DrawCompanyVehiclesAmount((CompanyID)this->window_number);
  1238 
  1233 
  1239 		/* "Company value:" */
  1234 		/* "Company value:" */
  1240 		SetDParam(0, CalculateCompanyValue(p));
  1235 		SetDParam(0, CalculateCompanyValue(c));
  1241 		DrawString(110, 106, STR_7076_COMPANY_VALUE, TC_FROMSTRING);
  1236 		DrawString(110, 106, STR_7076_COMPANY_VALUE, TC_FROMSTRING);
  1242 
  1237 
  1243 		/* Shares list */
  1238 		/* Shares list */
  1244 		DrawCompanyOwnerText(p);
  1239 		DrawCompanyOwnerText(c);
  1245 	}
  1240 	}
  1246 
  1241 
  1247 	virtual void OnClick(Point pt, int widget)
  1242 	virtual void OnClick(Point pt, int widget)
  1248 	{
  1243 	{
  1249 		switch (widget) {
  1244 		switch (widget) {
  1250 			case PCW_WIDGET_NEW_FACE: DoSelectPlayerFace(this, false); break;
  1245 			case CW_WIDGET_NEW_FACE: DoSelectCompanyManagerFace(this, false); break;
  1251 
  1246 
  1252 			case PCW_WIDGET_COLOR_SCHEME:
  1247 			case CW_WIDGET_COLOR_SCHEME:
  1253 				if (BringWindowToFrontById(WC_PLAYER_COLOR, this->window_number)) break;
  1248 				if (BringWindowToFrontById(WC_COMPANY_COLOR, this->window_number)) break;
  1254 				new SelectPlayerLiveryWindow(&_select_player_livery_desc, (PlayerID)this->window_number);
  1249 				new SelectCompanyLiveryWindow(&_select_company_livery_desc, (CompanyID)this->window_number);
  1255 				break;
  1250 				break;
  1256 
  1251 
  1257 			case PCW_WIDGET_PRESIDENT_NAME:
  1252 			case CW_WIDGET_PRESIDENT_NAME:
  1258 				this->query_widget = PCW_WIDGET_PRESIDENT_NAME;
  1253 				this->query_widget = CW_WIDGET_PRESIDENT_NAME;
  1259 				SetDParam(0, this->window_number);
  1254 				SetDParam(0, this->window_number);
  1260 				ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
  1255 				ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
  1261 				break;
  1256 				break;
  1262 
  1257 
  1263 			case PCW_WIDGET_COMPANY_NAME:
  1258 			case CW_WIDGET_COMPANY_NAME:
  1264 				this->query_widget = PCW_WIDGET_COMPANY_NAME;
  1259 				this->query_widget = CW_WIDGET_COMPANY_NAME;
  1265 				SetDParam(0, this->window_number);
  1260 				SetDParam(0, this->window_number);
  1266 				ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
  1261 				ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
  1267 				break;
  1262 				break;
  1268 
  1263 
  1269 			case PCW_WIDGET_BUILD_VIEW_HQ: {
  1264 			case CW_WIDGET_BUILD_VIEW_HQ: {
  1270 				TileIndex tile = GetPlayer((PlayerID)this->window_number)->location_of_HQ;
  1265 				TileIndex tile = GetCompany((CompanyID)this->window_number)->location_of_HQ;
  1271 				if (tile == 0) {
  1266 				if (tile == 0) {
  1272 					if ((byte)this->window_number != _local_player) return;
  1267 					if ((byte)this->window_number != _local_company) return;
  1273 					SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, this);
  1268 					SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, this);
  1274 					SetTileSelectSize(2, 2);
  1269 					SetTileSelectSize(2, 2);
  1275 					this->LowerWidget(PCW_WIDGET_BUILD_VIEW_HQ);
  1270 					this->LowerWidget(CW_WIDGET_BUILD_VIEW_HQ);
  1276 					this->InvalidateWidget(PCW_WIDGET_BUILD_VIEW_HQ);
  1271 					this->InvalidateWidget(CW_WIDGET_BUILD_VIEW_HQ);
  1277 				} else {
  1272 				} else {
  1278 					if (_ctrl_pressed) {
  1273 					if (_ctrl_pressed) {
  1279 						ShowExtraViewPortWindow(tile);
  1274 						ShowExtraViewPortWindow(tile);
  1280 					} else {
  1275 					} else {
  1281 						ScrollMainWindowToTile(tile);
  1276 						ScrollMainWindowToTile(tile);
  1282 					}
  1277 					}
  1283 				}
  1278 				}
  1284 				break;
  1279 				break;
  1285 			}
  1280 			}
  1286 
  1281 
  1287 			case PCW_WIDGET_RELOCATE_HQ:
  1282 			case CW_WIDGET_RELOCATE_HQ:
  1288 				SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, this);
  1283 				SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, this);
  1289 				SetTileSelectSize(2, 2);
  1284 				SetTileSelectSize(2, 2);
  1290 				this->LowerWidget(PCW_WIDGET_RELOCATE_HQ);
  1285 				this->LowerWidget(CW_WIDGET_RELOCATE_HQ);
  1291 				this->InvalidateWidget(PCW_WIDGET_RELOCATE_HQ);
  1286 				this->InvalidateWidget(CW_WIDGET_RELOCATE_HQ);
  1292 				break;
  1287 				break;
  1293 
  1288 
  1294 			case PCW_WIDGET_BUY_SHARE:
  1289 			case CW_WIDGET_BUY_SHARE:
  1295 				DoCommandP(0, this->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
  1290 				DoCommandP(0, this->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
  1296 				break;
  1291 				break;
  1297 
  1292 
  1298 			case PCW_WIDGET_SELL_SHARE:
  1293 			case CW_WIDGET_SELL_SHARE:
  1299 				DoCommandP(0, this->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
  1294 				DoCommandP(0, this->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
  1300 				break;
  1295 				break;
  1301 
  1296 
  1302 #ifdef ENABLE_NETWORK
  1297 #ifdef ENABLE_NETWORK
  1303 			case PCW_WIDGET_COMPANY_PASSWORD:
  1298 			case CW_WIDGET_COMPANY_PASSWORD:
  1304 				if (this->window_number == _local_player) ShowNetworkCompanyPasswordWindow(this);
  1299 				if (this->window_number == _local_company) ShowNetworkCompanyPasswordWindow(this);
  1305 				break;
  1300 				break;
  1306 #endif /* ENABLE_NETWORK */
  1301 #endif /* ENABLE_NETWORK */
  1307 		}
  1302 		}
  1308 	}
  1303 	}
  1309 
  1304 
  1315 
  1310 
  1316 	virtual void OnPlaceObject(Point pt, TileIndex tile)
  1311 	virtual void OnPlaceObject(Point pt, TileIndex tile)
  1317 	{
  1312 	{
  1318 		if (DoCommandP(tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS)))
  1313 		if (DoCommandP(tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS)))
  1319 			ResetObjectToPlace();
  1314 			ResetObjectToPlace();
  1320 			this->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; // this button can now behave as a normal push button
  1315 			this->widget[CW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; // this button can now behave as a normal push button
  1321 			this->RaiseButtons();
  1316 			this->RaiseButtons();
  1322 	}
  1317 	}
  1323 
  1318 
  1324 	virtual void OnPlaceObjectAbort()
  1319 	virtual void OnPlaceObjectAbort()
  1325 	{
  1320 	{
  1332 
  1327 
  1333 		_cmd_text = str;
  1328 		_cmd_text = str;
  1334 		switch (this->query_widget) {
  1329 		switch (this->query_widget) {
  1335 			default: NOT_REACHED();
  1330 			default: NOT_REACHED();
  1336 
  1331 
  1337 			case PCW_WIDGET_PRESIDENT_NAME:
  1332 			case CW_WIDGET_PRESIDENT_NAME:
  1338 				DoCommandP(0, 0, 0, NULL, CMD_RENAME_PRESIDENT | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
  1333 				DoCommandP(0, 0, 0, NULL, CMD_RENAME_PRESIDENT | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
  1339 				break;
  1334 				break;
  1340 
  1335 
  1341 			case PCW_WIDGET_COMPANY_NAME:
  1336 			case CW_WIDGET_COMPANY_NAME:
  1342 				DoCommandP(0, 0, 0, NULL, CMD_RENAME_COMPANY | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
  1337 				DoCommandP(0, 0, 0, NULL, CMD_RENAME_COMPANY | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
  1343 				break;
  1338 				break;
  1344 		}
  1339 		}
  1345 	}
  1340 	}
  1346 };
  1341 };
  1347 
  1342 
  1348 static const WindowDesc _player_company_desc = {
  1343 static const WindowDesc _company_desc = {
  1349 	WDP_AUTO, WDP_AUTO, 360, 170, 360, 170,
  1344 	WDP_AUTO, WDP_AUTO, 360, 170, 360, 170,
  1350 	WC_COMPANY, WC_NONE,
  1345 	WC_COMPANY, WC_NONE,
  1351 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
  1346 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
  1352 	_player_company_widgets,
  1347 	_company_widgets,
  1353 };
  1348 };
  1354 
  1349 
  1355 void ShowPlayerCompany(PlayerID player)
  1350 void ShowCompany(CompanyID company)
  1356 {
  1351 {
  1357 	if (!IsValidPlayerID(player)) return;
  1352 	if (!IsValidCompanyID(company)) return;
  1358 
  1353 
  1359 	AllocateWindowDescFront<PlayerCompanyWindow>(&_player_company_desc, player);
  1354 	AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
  1360 }
  1355 }
  1361 
  1356 
  1362 
  1357 
  1363 
  1358 
  1364 struct BuyCompanyWindow : Window {
  1359 struct BuyCompanyWindow : Window {
  1367 		this->FindWindowPlacementAndResize(desc);
  1362 		this->FindWindowPlacementAndResize(desc);
  1368 	}
  1363 	}
  1369 
  1364 
  1370 	virtual void OnPaint()
  1365 	virtual void OnPaint()
  1371 	{
  1366 	{
  1372 		Player *p = GetPlayer((PlayerID)this->window_number);
  1367 		Company *c = GetCompany((CompanyID)this->window_number);
  1373 		SetDParam(0, STR_COMPANY_NAME);
  1368 		SetDParam(0, STR_COMPANY_NAME);
  1374 		SetDParam(1, p->index);
  1369 		SetDParam(1, c->index);
  1375 		this->DrawWidgets();
  1370 		this->DrawWidgets();
  1376 
  1371 
  1377 		DrawPlayerFace(p->face, p->player_color, 2, 16);
  1372 		DrawCompanyManagerFace(c->face, c->colour, 2, 16);
  1378 
  1373 
  1379 		SetDParam(0, p->index);
  1374 		SetDParam(0, c->index);
  1380 		SetDParam(1, p->bankrupt_value);
  1375 		SetDParam(1, c->bankrupt_value);
  1381 		DrawStringMultiCenter(214, 65, STR_705B_WE_ARE_LOOKING_FOR_A_TRANSPORT, 238);
  1376 		DrawStringMultiCenter(214, 65, STR_705B_WE_ARE_LOOKING_FOR_A_TRANSPORT, 238);
  1382 	}
  1377 	}
  1383 
  1378 
  1384 	virtual void OnClick(Point pt, int widget)
  1379 	virtual void OnClick(Point pt, int widget)
  1385 	{
  1380 	{
  1410 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
  1405 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
  1411 	_buy_company_widgets,
  1406 	_buy_company_widgets,
  1412 };
  1407 };
  1413 
  1408 
  1414 
  1409 
  1415 void ShowBuyCompanyDialog(uint player)
  1410 void ShowBuyCompanyDialog(CompanyID company)
  1416 {
  1411 {
  1417 	AllocateWindowDescFront<BuyCompanyWindow>(&_buy_company_desc, player);
  1412 	AllocateWindowDescFront<BuyCompanyWindow>(&_buy_company_desc, company);
  1418 }
  1413 }
  1419 
  1414 
  1420 /********** HIGHSCORE and ENDGAME windows */
  1415 /********** HIGHSCORE and ENDGAME windows */
  1421 
  1416 
  1422 extern StringID EndGameGetPerformanceTitleFromValue(uint value);
  1417 extern StringID EndGameGetPerformanceTitleFromValue(uint value);
  1463 		/* Pause in single-player to have a look at the highscore at your own leisure */
  1458 		/* Pause in single-player to have a look at the highscore at your own leisure */
  1464 		if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
  1459 		if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
  1465 
  1460 
  1466 		this->background_img = SPR_TYCOON_IMG1_BEGIN;
  1461 		this->background_img = SPR_TYCOON_IMG1_BEGIN;
  1467 
  1462 
  1468 		if (_local_player != PLAYER_SPECTATOR) {
  1463 		if (_local_company != COMPANY_SPECTATOR) {
  1469 			const Player *p = GetPlayer(_local_player);
  1464 			const Company *c = GetCompany(_local_company);
  1470 			if (p->old_economy[0].performance_history == SCORE_MAX) {
  1465 			if (c->old_economy[0].performance_history == SCORE_MAX) {
  1471 				this->background_img = SPR_TYCOON_IMG2_BEGIN;
  1466 				this->background_img = SPR_TYCOON_IMG2_BEGIN;
  1472 			}
  1467 			}
  1473 		}
  1468 		}
  1474 
  1469 
  1475 		/* In a network game show the endscores of the custom difficulty 'network' which is the last one
  1470 		/* In a network game show the endscores of the custom difficulty 'network' which is the last one
  1476 		 * as well as generate a TOP5 of that game, and not an all-time top5. */
  1471 		 * as well as generate a TOP5 of that game, and not an all-time top5. */
  1477 		if (_networking) {
  1472 		if (_networking) {
  1478 			this->window_number = lengthof(_highscore_table) - 1;
  1473 			this->window_number = lengthof(_highscore_table) - 1;
  1479 			this->rank = SaveHighScoreValueNetwork();
  1474 			this->rank = SaveHighScoreValueNetwork();
  1480 		} else {
  1475 		} else {
  1481 			/* in single player _local player is always valid */
  1476 			/* in single player _local company is always valid */
  1482 			const Player *p = GetPlayer(_local_player);
  1477 			const Company *c = GetCompany(_local_company);
  1483 			this->window_number = _settings_game.difficulty.diff_level;
  1478 			this->window_number = _settings_game.difficulty.diff_level;
  1484 			this->rank = SaveHighScoreValue(p);
  1479 			this->rank = SaveHighScoreValue(c);
  1485 		}
  1480 		}
  1486 
  1481 
  1487 		MarkWholeScreenDirty();
  1482 		MarkWholeScreenDirty();
  1488 	}
  1483 	}
  1489 
  1484 
  1493 		ShowHighscoreTable(this->window_number, this->rank);
  1488 		ShowHighscoreTable(this->window_number, this->rank);
  1494 	}
  1489 	}
  1495 
  1490 
  1496 	virtual void OnPaint()
  1491 	virtual void OnPaint()
  1497 	{
  1492 	{
  1498 		const Player *p;
  1493 		const Company *c;
  1499 		uint x, y;
  1494 		uint x, y;
  1500 
  1495 
  1501 		this->SetupHighScoreEndWindow(&x, &y);
  1496 		this->SetupHighScoreEndWindow(&x, &y);
  1502 
  1497 
  1503 		if (!IsValidPlayerID(_local_player)) return;
  1498 		if (!IsValidCompanyID(_local_company)) return;
  1504 
  1499 
  1505 		p = GetPlayer(_local_player);
  1500 		c = GetCompany(_local_company);
  1506 		/* We need to get performance from last year because the image is shown
  1501 		/* We need to get performance from last year because the image is shown
  1507 		 * at the start of the new year when these things have already been copied */
  1502 		 * at the start of the new year when these things have already been copied */
  1508 		if (this->background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/
  1503 		if (this->background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/
  1509 			SetDParam(0, p->index);
  1504 			SetDParam(0, c->index);
  1510 			SetDParam(1, p->index);
  1505 			SetDParam(1, c->index);
  1511 			SetDParam(2, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history));
  1506 			SetDParam(2, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
  1512 			DrawStringMultiCenter(x + (640 / 2), y + 107, STR_021C_OF_ACHIEVES_STATUS, 640);
  1507 			DrawStringMultiCenter(x + (640 / 2), y + 107, STR_021C_OF_ACHIEVES_STATUS, 640);
  1513 		} else {
  1508 		} else {
  1514 			SetDParam(0, p->index);
  1509 			SetDParam(0, c->index);
  1515 			SetDParam(1, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history));
  1510 			SetDParam(1, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
  1516 			DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640);
  1511 			DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640);
  1517 		}
  1512 		}
  1518 	}
  1513 	}
  1519 };
  1514 };
  1520 
  1515