src/town_gui.cpp
author celestar
Mon, 19 Mar 2007 12:38:16 +0000
branchgamebalance
changeset 9895 7bd07f43b0e3
parent 9891 7d3a5979a733
child 9898 324dad59eb35
permissions -rw-r--r--
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1260
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1299
diff changeset
     7
#include "strings.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1323
diff changeset
     8
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 410
diff changeset
     9
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "player.h"
5720
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5682
diff changeset
    17
#include "network/network.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2070
diff changeset
    18
#include "variables.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    19
#include "helpers.hpp"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
static const Widget _town_authority_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
    22
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
    23
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   316,     0,    13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
    24
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   316,    14,   105, 0x0,                      STR_NULL},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
    25
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   304,   106,   157, 0x0,                      STR_2043_LIST_OF_THINGS_TO_DO_AT},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
    26
{  WWT_SCROLLBAR,   RESIZE_NONE,    13,   305,   316,   106,   157, 0x0,                      STR_0190_SCROLL_BAR_SCROLLS_LIST},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
    27
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   316,   158,   209, 0x0,                      STR_NULL},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
    28
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,   316,   210,   221, STR_2042_DO_IT,           STR_2044_CARRY_OUT_THE_HIGHLIGHTED},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
    29
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
extern const byte _town_action_costs[8];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    34
/** Get a list of available actions to do at a town.
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    35
 * @param *nump if not NULL add put the number of available actions in it
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    36
 * @param pid the player that is querying the town
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    37
 * @param *t the town that is queried
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    38
 * @return bitmasked value of enabled actions
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    39
 */
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    40
uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	int32 avail, ref;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    43
	int num = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	uint avail_buttons = 0x7F; // by default all buttons except bribe are enabled.
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    45
	uint buttons = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4709
diff changeset
    47
	if (pid != PLAYER_SPECTATOR) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    48
		uint i;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    49
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
		// bribe option enabled?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
		if (_patches.bribe) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
			// if unwanted, disable everything.
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    53
			if (t->unwanted[pid]) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
				avail_buttons = 0;
2659
4e007ef29d98 (svn r3201) -Fix: Allow bribing up to the maximum rating for bribing, don't disable this option at some arbitrary value early
tron
parents: 2639
diff changeset
    55
			} else if (t->ratings[pid] < RATING_BRIBE_MAXIMUM) {
4e007ef29d98 (svn r3201) -Fix: Allow bribing up to the maximum rating for bribing, don't disable this option at some arbitrary value early
tron
parents: 2639
diff changeset
    56
				SETBIT(avail_buttons, 7); // Allow bribing
4e007ef29d98 (svn r3201) -Fix: Allow bribing up to the maximum rating for bribing, don't disable this option at some arbitrary value early
tron
parents: 2639
diff changeset
    57
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
		// Things worth more than this are not shown
1962
51ee4f459268 (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1891
diff changeset
    61
		avail = GetPlayer(pid)->player_money + _price.station_value * 200;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
		ref = _price.build_industry >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    64
		for (i = 0; i != lengthof(_town_action_costs); i++, avail_buttons >>= 1) {
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    65
			if (HASBIT(avail_buttons, 0) && avail >= _town_action_costs[i] * ref) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
				SETBIT(buttons, i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    71
		/* Disable build statue if already built */
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    72
		if (HASBIT(t->statues, pid)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
			CLRBIT(buttons, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
			num--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    79
	if (nump != NULL) *nump = num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	return buttons;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
static int GetNthSetBit(uint32 bits, int n)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	int i = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    86
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	if (n >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
		do {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    89
			if (bits & 1 && --n < 0) return i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
			i++;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    91
		} while (bits >>= 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	return -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
static void TownAuthorityWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
{
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    98
	switch (e->event) {
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
    99
	case WE_PAINT: {
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   100
		const Town *t = GetTown(w->window_number);
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   101
		int numact;
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   102
		uint buttons = GetMaskOfTownActions(&numact, _local_player, t);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   103
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
		SetVScrollCount(w, numact + 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
		if (WP(w,def_d).data_1 != -1 && !HASBIT(buttons, WP(w,def_d).data_1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
			WP(w,def_d).data_1 = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   109
		SetWindowWidgetDisabledState(w, 6, WP(w, def_d).data_1 == -1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
			int y;
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3692
diff changeset
   113
			const Player *p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
			int r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
			StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   117
			SetDParam(0, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
			DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
			DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, 0);
122
6e56237f536c (svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents: 121
diff changeset
   121
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
			// Draw list of players
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
			y = 25;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
			FOR_ALL_PLAYERS(p) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   125
				if (p->is_active && (HASBIT(t->have_ratings, p->index) || t->exclusivity == p->index)) {
125
3716c3a69f4f (svn r126) Forgot to remove some test code
dominik
parents: 122
diff changeset
   126
					DrawPlayerIcon(p->index, 2, y);
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 69
diff changeset
   127
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   128
					SetDParam(0, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   129
					SetDParam(1, p->name_2);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   130
					SetDParam(2, GetPlayerNameString(p->index, 3));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
					r = t->ratings[p->index];
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   133
					(str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   134
					(str++,                    r <= RATING_VERYPOOR)  || // Very Poor
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   135
					(str++,                    r <= RATING_POOR)      || // Poor
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   136
					(str++,                    r <= RATING_MEDIOCRE)  || // Mediocore
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   137
					(str++,                    r <= RATING_GOOD)      || // Good
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   138
					(str++,                    r <= RATING_VERYGOOD)  || // Very Good
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   139
					(str++,                    r <= RATING_EXCELLENT) || // Excellent
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
   140
					(str++,                    true);                    // Outstanding
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 1962
diff changeset
   142
					SetDParam(4, str);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5860
diff changeset
   143
					if (t->exclusivity == p->index) { // red icon for player with exclusive rights
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5860
diff changeset
   144
						DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5860
diff changeset
   145
					}
246
de179e5f7c3d (svn r247) -Fix: Town exclusivity was not shown in town-window because stringformat ({YELLOW}) overrode colour-code. Now the exclusive player gets a red icon in front of its name
darkvater
parents: 222
diff changeset
   146
de179e5f7c3d (svn r247) -Fix: Town exclusivity was not shown in town-window because stringformat ({YELLOW}) overrode colour-code. Now the exclusive player gets a red icon in front of its name
darkvater
parents: 222
diff changeset
   147
					DrawString(28, y, STR_2024, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   148
					y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
		// Draw actions list
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
			int y = 107, i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
			int pos = w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
			if (--pos < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
				DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   160
				y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
			}
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   162
			for (i = 0; buttons; i++, buttons >>= 1) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   163
				if (pos <= -5) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
				if (buttons&1 && --pos < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
					DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
					y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
		}
122
6e56237f536c (svn r123) Fixed some indentions... btw credits for the last commit go to Celestar
dominik
parents: 121
diff changeset
   171
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   173
			int i = WP(w,def_d).data_1;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   174
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   175
			if (i != -1) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   176
				SetDParam(1, (_price.build_industry >> 8) * _town_action_costs[i]);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   177
				SetDParam(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
				DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + i, 313);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   181
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   182
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   185
		switch (e->we.click.widget) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
		case 3: { /* listbox */
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   187
			const Town *t = GetTown(w->window_number);
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   188
			int y = (e->we.click.pt.y - 0x6B) / 10;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   189
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   190
			if (!IS_INT_INSIDE(y, 0, 5)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1363
diff changeset
   192
			y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + w->vscroll.pos - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
			if (y >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
				WP(w,def_d).data_1 = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
		case 6: { /* carry out the action */
1803
24a94314cfa9 (svn r2307) - Fix (regression): it was not possible to change the drive-side in the intro-game.
Darkvater
parents: 1793
diff changeset
   201
			DoCommandP(GetTown(w->window_number)->xy, w->window_number, WP(w,def_d).data_1, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	case WE_4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
static const WindowDesc _town_authority_desc = {
5070
0bbf5264bfb7 (svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents: 4939
diff changeset
   214
	WDP_AUTO, WDP_AUTO, 317, 222,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6001
diff changeset
   215
	WC_TOWN_AUTHORITY, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	_town_authority_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	TownAuthorityWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 246
diff changeset
   221
static void ShowTownAuthorityWindow(uint town)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3692
diff changeset
   223
	Window *w = AllocateWindowDescFront(&_town_authority_desc, town);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   225
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
		w->vscroll.cap = 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
		WP(w,def_d).data_1 = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
static void TownViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
{
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   233
	Town *t = GetTown(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   235
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
	case WE_PAINT:
891
b701cd0b20ae (svn r1377) -Fix: only a server can rename a town in a MP game
darkvater
parents: 867
diff changeset
   237
		// disable renaming town in network games if you are not the server
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   238
		SetWindowWidgetDisabledState(w, 8, _networking && !_network_server);
891
b701cd0b20ae (svn r1377) -Fix: only a server can rename a town in a MP game
darkvater
parents: 867
diff changeset
   239
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   240
		SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		DrawWindowWidgets(w);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   242
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   243
		SetDParam(0, t->population);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   244
		SetDParam(1, t->num_houses);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   245
		DrawString(2, 107, STR_2006_POPULATION, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   246
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   247
		SetDParam(0, t->act_pass);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   248
		SetDParam(1, t->max_pass);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   249
		DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   251
		SetDParam(0, t->act_mail);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   252
		SetDParam(1, t->max_mail);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   253
		DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   254
9890
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   255
		{
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   256
			int activity = t->GetActivity() * 100;
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   257
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   258
			SetDParam(0, STR_TOWN_ECONOMY_POOR + t->GetWealthLevel());
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   259
			SetDParam(1, activity);
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   260
			DrawString(2, 137, STR_TOWN_ECONOMY_STATUS, 0);
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   261
		}
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   262
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		DrawWindowViewport(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   267
		switch (e->we.click.widget) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   268
			case 6: /* scroll to location */
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   269
				ScrollMainWindowToTile(t->xy);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   270
				break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   271
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   272
			case 7: /* town authority */
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   273
				ShowTownAuthorityWindow(w->window_number);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   274
				break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   275
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   276
			case 8: /* rename */
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   277
				SetDParam(0, w->window_number);
5682
eeddbbacd4ac (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5568
diff changeset
   278
				ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, w, CS_ALPHANUMERAL);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   279
				break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   280
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   281
			case 9: /* expand town */
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   282
				ExpandTown(t);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   283
				break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   284
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   285
			case 10: /* delete town */
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   286
				DeleteTown(t);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   287
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2406
diff changeset
   291
	case WE_ON_EDIT_TEXT:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   292
		if (e->we.edittext.str[0] != '\0') {
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   293
			_cmd_text = e->we.edittext.str;
1820
9b6458526480 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1803
diff changeset
   294
			DoCommandP(0, w->window_number, 0, NULL,
9b6458526480 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1803
diff changeset
   295
				CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
9b6458526480 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1803
diff changeset
   296
		}
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2406
diff changeset
   297
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
static const Widget _town_view_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   303
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   304
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   247,     0,    13, STR_2005,                 STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   305
{  WWT_STICKYBOX,   RESIZE_NONE,    13,   248,   259,     0,    13, 0x0,                      STR_STICKY_BUTTON},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
   306
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,    14,   105, 0x0,                      STR_NULL},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   307
{      WWT_INSET,   RESIZE_NONE,    13,     2,   257,    16,   103, 0x0,                      STR_NULL},
9890
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   308
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,   106,   147, 0x0,                      STR_NULL},
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   309
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    85,   148,   159, STR_00E4_LOCATION,        STR_200B_CENTER_THE_MAIN_VIEW_ON},
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   310
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    86,   171,   148,   159, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL},
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   311
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   172,   259,   148,   159, STR_0130_RENAME,          STR_200C_CHANGE_TOWN_NAME},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   312
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
static const WindowDesc _town_view_desc = {
9890
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   316
	WDP_AUTO, WDP_AUTO, 260, 160,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6001
diff changeset
   317
	WC_TOWN_VIEW, WC_NONE,
758
bd9e868b9fae (svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents: 727
diff changeset
   318
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	_town_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	TownViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
static const Widget _town_view_scen_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   324
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   325
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   172,     0,    13, STR_2005,          STR_018C_WINDOW_TITLE_DRAG_THIS},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   326
{  WWT_STICKYBOX,   RESIZE_NONE,    13,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4913
diff changeset
   327
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,    14,   105, 0x0,               STR_NULL},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   328
{      WWT_INSET,   RESIZE_NONE,    13,     2,   257,    16,   103, 0x0,               STR_NULL},
9890
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   329
{      WWT_PANEL,   RESIZE_NONE,    13,     0,   259,   106,   147, 0x0,               STR_NULL},
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   330
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    85,   148,   159, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   331
{      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,               STR_NULL},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   332
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   173,   247,     0,    13, STR_0130_RENAME,   STR_200C_CHANGE_TOWN_NAME},
9890
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   333
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    86,   171,   148,   159, STR_023C_EXPAND,   STR_023B_INCREASE_SIZE_OF_TOWN},
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   334
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   172,   259,   148,   159, STR_0290_DELETE,   STR_0291_DELETE_THIS_TOWN_COMPLETELY},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   335
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
static const WindowDesc _town_view_scen_desc = {
9890
37b56728c471 (svn r9170) [gamebalance] -Feature: Show the economic status of the town in the view window
celestar
parents: 6144
diff changeset
   339
	WDP_AUTO, WDP_AUTO, 260, 160,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6001
diff changeset
   340
	WC_TOWN_VIEW, WC_NONE,
758
bd9e868b9fae (svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents: 727
diff changeset
   341
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	_town_view_scen_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	TownViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
3349
1ad72db34298 (svn r4133) - Some miscellaneous changes (unconverted TownID in function definition, Owner instead of byte, remove obsolete member and compare waypoint index with 0 not STR_NULL)
Darkvater
parents: 2952
diff changeset
   346
void ShowTownViewWindow(TownID town)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	if (_game_mode != GM_EDITOR) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
		w = AllocateWindowDescFront(&_town_view_desc, town);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
		w = AllocateWindowDescFront(&_town_view_scen_desc, town);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   356
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
		w->flags4 |= WF_DISABLE_VP_SCROLL;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   358
		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetTown(town)->xy, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
static const Widget _town_directory_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   363
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   364
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   300,     0,    13, STR_2000_TOWNS,         STR_018C_WINDOW_TITLE_DRAG_THIS},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   365
{  WWT_STICKYBOX,   RESIZE_NONE,    13,   301,   312,     0,    13, 0x0,                    STR_STICKY_BUTTON},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   366
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    74,    14,    25, STR_SORT_BY_NAME,       STR_SORT_ORDER_TIP},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   367
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    75,   149,    14,    25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   368
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   150,   224,    14,    25, STR_SORT_BY_GDP_CAPITA, STR_SORT_ORDER_TIP},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   369
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   225,   300,    14,    25, STR_SORT_BY_GDP_TOTAL,  STR_SORT_ORDER_TIP},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   370
{      WWT_PANEL, RESIZE_BOTTOM,    13,     0,   300,    26,   189, 0x0,                    STR_200A_TOWN_NAMES_CLICK_ON_NAME},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   371
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    13,   301,   312,    14,   189, 0x0,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   372
{      WWT_PANEL,     RESIZE_TB,    13,     0,   312,   190,   201, 0x0,                    STR_NULL},
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   373
{  WWT_RESIZEBOX,     RESIZE_TB,    13,   301,   312,   190,   201, 0x0,                    STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   374
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
// used to get a sorted list of the towns
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
static uint _num_town_sort;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
static char _bufcache[64];
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   382
static const Town* _last_town;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 125
diff changeset
   384
static int CDECL TownNameSorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
{
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   386
	const Town* ta = *(const Town**)a;
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   387
	const Town* tb = *(const Town**)b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
	char buf1[64];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	int r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
4416
e0e9a72882d0 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
   391
	SetDParam(0, ta->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4848
diff changeset
   392
	GetString(buf1, STR_TOWN, lastof(buf1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
1260
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1093
diff changeset
   394
	/* If 'b' is the same town as in the last round, use the cached value
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1093
diff changeset
   395
	 *  We do this to speed stuff up ('b' is called with the same value a lot of
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   396
	 *  times after eachother) */
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   397
	if (tb != _last_town) {
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   398
		_last_town = tb;
4416
e0e9a72882d0 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
   399
		SetDParam(0, tb->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4848
diff changeset
   400
		GetString(_bufcache, STR_TOWN, lastof(_bufcache));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	r = strcmp(buf1, _bufcache);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	if (_town_sort_order & 1) r = -r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 125
diff changeset
   408
static int CDECL TownPopSorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
{
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   410
	const Town* ta = *(const Town**)a;
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   411
	const Town* tb = *(const Town**)b;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 125
diff changeset
   412
	int r = ta->population - tb->population;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
	if (_town_sort_order & 1) r = -r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   417
static int CDECL TownGDPSorter(const void *a, const void *b)
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   418
{
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   419
	const Town* ta = *(const Town**)a;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   420
	const Town* tb = *(const Town**)b;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   421
	int r = (ta->GetActivity() * 100) - (tb->GetActivity() * 100);
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   422
	if (_town_sort_order & 1) r = -r;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   423
	return r;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   424
}
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   425
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   426
static int CDECL TownOutputSorter(const void *a, const void *b)
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   427
{
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   428
	const Town* ta = *(const Town**)a;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   429
	const Town* tb = *(const Town**)b;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   430
	int r = (ta->GetActivity() * 100 * ta->population) - (tb->GetActivity() * 100 * tb->population);
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   431
	if (_town_sort_order & 1) r = -r;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   432
	return r;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   433
}
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   434
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 9891
diff changeset
   435
static void MakeSortedTownList()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   437
	const Town* t;
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   438
	int (*townsortproc[])(const void *a, const void *b) = {
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   439
		TownNameSorter, TownPopSorter, TownGDPSorter, TownOutputSorter
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   440
	};
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   441
	uint n = 0;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   442
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   443
	/* Create array for sorting */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   444
	_town_sort = ReallocT(_town_sort, GetMaxTownIndex() + 1);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5247
diff changeset
   445
	if (_town_sort == NULL) error("Could not allocate memory for the town-sorting-list");
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   446
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   447
	FOR_ALL_TOWNS(t) _town_sort[n++] = t;
821
4af53631a47a (svn r1292) -Codechange: also updated the town/industry sort-list to be uint16 compatible
truelight
parents: 758
diff changeset
   448
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	_num_town_sort = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   451
	_last_town = NULL; // used for "cache"
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   452
	qsort((void*)_town_sort, n, sizeof(_town_sort[0]), townsortproc[_town_sort_order / 2]);
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 16
diff changeset
   453
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5247
diff changeset
   454
	DEBUG(misc, 3, "Resorting towns list");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
static void TownDirectoryWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   460
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	case WE_PAINT: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
		if (_town_sort_dirty) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
			_town_sort_dirty = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
			MakeSortedTownList();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   467
		SetVScrollCount(w, _num_town_sort);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
		DrawWindowWidgets(w);
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   470
		DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, 66 + (_town_sort_order / 2) * 75, 15, 0x10);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   471
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   472
		{
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   473
			int n = 0;
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   474
			uint16 i = w->vscroll.pos;
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   475
			int y = 28;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   477
			while (i < _num_town_sort) {
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   478
				const Town* t = _town_sort[i];
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   479
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   480
				assert(t->xy);
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   481
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   482
				SetDParam(0, t->index);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   483
				SetDParam(1, t->population);
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   484
				SetDParam(2, t->GetActivity() * 100);
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   485
				DrawString(2, y, STR_2057, 0);
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   486
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   487
				y += 10;
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   488
				i++;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   489
				if (++n == w->vscroll.cap) break; // max number of towns in 1 window
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   490
			}
1080
9695461dc645 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1005
diff changeset
   491
			SetDParam(0, GetWorldPopulation());
9695461dc645 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1005
diff changeset
   492
			DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   497
		switch (e->we.click.widget) {
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   498
		case 3:    /* Sort by Name ascending/descending */
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   499
		case 4:    /* Sort by Population ascending/descending */
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   500
		case 5:    /* Sort by GDP per capita */
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   501
		case 6: {  /* Sort by economic output */
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   502
			int sorter = e->we.click.widget - 3;
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   503
			_town_sort_order = (_town_sort_order == 2 * sorter) ? 2 * sorter + 1 : 2 * sorter;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
			_town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   508
		case 7: { /* Click on Town Matrix */
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   509
			const Town* t;
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   510
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   511
			uint16 id_v = (e->we.click.pt.y - 28) / 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   513
			if (id_v >= w->vscroll.cap) return; // click out of bounds
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   514
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   515
			id_v += w->vscroll.pos;
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   516
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   517
			if (id_v >= _num_town_sort) return; // click out of town bounds
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 164
diff changeset
   518
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   519
			t = _town_sort[id_v];
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   520
			assert(t->xy);
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   521
			ScrollMainWindowToTile(t->xy);
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   522
			break;
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4171
diff changeset
   523
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   526
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	case WE_4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
		break;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   530
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   531
	case WE_RESIZE:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4434
diff changeset
   532
		w->vscroll.cap += e->we.sizing.diff.y / 10;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   533
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   534
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
static const WindowDesc _town_directory_desc = {
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   538
	WDP_AUTO, WDP_AUTO, 313, 202,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6001
diff changeset
   539
	WC_TOWN_DIRECTORY, WC_NONE,
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   540
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	_town_directory_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
	TownDirectoryWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 9891
diff changeset
   546
void ShowTownDirectory()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3692
diff changeset
   548
	Window *w = AllocateWindowDescFront(&_town_directory_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   550
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
		w->vscroll.cap = 16;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 821
diff changeset
   552
		w->resize.step_height = 10;
1080
9695461dc645 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1005
diff changeset
   553
		w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
}
9891
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   556
7d3a5979a733 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town).
celestar
parents: 9890
diff changeset
   557