economy.c
author truelight
Thu, 03 Mar 2005 14:56:28 +0000
changeset 1416 f3ac4388c069
parent 1415 e3877505327d
child 1538 c67f0386df1d
permissions -rw-r--r--
(svn r1920) -Fix: no longer a station where you only unload is bad for your town-rating
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
#include "ttd.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: 1308
diff changeset
     3
#include "strings.h" // XXX InjectDParam()
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 499
diff changeset
     4
#include "table/strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 653
diff changeset
     5
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "town.h"
239
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
    17
#include "network.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 260
diff changeset
    18
#include "sound.h"
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
    19
#include "engine.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
    20
#include "network_data.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    22
// get a mask of the allowed currencies depending on the year
768
deb40d3554a2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
    23
uint GetMaskOfAllowedCurrencies(void)
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    24
{
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    25
	int i;
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    26
	uint mask = 0;
768
deb40d3554a2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
    27
	for (i = 0; i != lengthof(_currency_specs); i++) {
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    28
		uint16 to_euro = _currency_specs[i].to_euro;
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    29
		if (i == 23) mask |= (1 << 23); // always allow custom currency
970
492ca84ecc6c (svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents: 967
diff changeset
    30
		if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= (to_euro-MAX_YEAR_BEGIN_REAL)) continue;
492ca84ecc6c (svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents: 967
diff changeset
    31
		if (_cur_year < (2000-MAX_YEAR_BEGIN_REAL) && (to_euro == CF_ISEURO)) continue;
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    32
		mask |= (1 << i);
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    33
	}
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    34
	return mask;
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    35
}
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    36
768
deb40d3554a2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
    37
void CheckSwitchToEuro(void)
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    38
{
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    39
	if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    40
			_currency_specs[_opt.currency].to_euro != CF_ISEURO &&
970
492ca84ecc6c (svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents: 967
diff changeset
    41
			_cur_year >= (_currency_specs[_opt.currency].to_euro-MAX_YEAR_BEGIN_REAL)) {
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    42
		_opt.currency = 2; // this is the index of euro above.
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    43
		AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    44
	}
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    45
}
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 716
diff changeset
    46
147
d0c8100d18cf (svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents: 116
diff changeset
    47
void UpdatePlayerHouse(Player *p, uint score)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	byte val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	uint tile = p->location_of_house;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	if (tile == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	(val = 128, score < 170) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	(val+= 4, score < 350) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	(val+= 4, score < 520) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	(val+= 4, score < 720) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
	(val+= 4, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
/* house is already big enough */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	if (val <= _map5[tile])
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	_map5[tile + TILE_XY(0,0)] = val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	_map5[tile + TILE_XY(0,1)] = ++val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
	_map5[tile + TILE_XY(1,0)] = ++val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	_map5[tile + TILE_XY(1,1)] = ++val;
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
	MarkTileDirtyByTile(tile + TILE_XY(0,0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	MarkTileDirtyByTile(tile + TILE_XY(0,1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	MarkTileDirtyByTile(tile + TILE_XY(1,0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	MarkTileDirtyByTile(tile + TILE_XY(1,1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
200
03b8104d1479 (svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents: 193
diff changeset
    76
int64 CalculateCompanyValue(Player *p) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	byte owner = p->index;
200
03b8104d1479 (svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents: 193
diff changeset
    78
	int64 value;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
    79
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
		Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
		uint num = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
    83
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
			if (st->xy != 0 && st->owner == owner) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
				uint facil = st->facilities;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
				do num += (facil&1); while (facil >>= 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
		value = num * _price.station_value * 25;
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
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
		Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
		FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
			if (v->owner != owner)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
				continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
			if (v->type == VEH_Train ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
					v->type == VEH_Road ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
					(v->type == VEH_Aircraft && v->subtype<=2) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
					v->type == VEH_Ship) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
				value += v->value * 3 >> 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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
997
71cf4e50d259 (svn r1495) -Fix: Loan does not count against the company value
celestar
parents: 970
diff changeset
   109
	value += p->money64 - p->current_loan; // add real money value
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 997
diff changeset
   110
997
71cf4e50d259 (svn r1495) -Fix: Loan does not count against the company value
celestar
parents: 970
diff changeset
   111
	return max(value, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   114
// if update is set to true, the economy is updated with this score
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   115
//  (also the house is updated, should only be true in the on-tick event)
147
d0c8100d18cf (svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents: 116
diff changeset
   116
int UpdateCompanyRatingAndValue(Player *p, bool update)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	byte owner = p->index;
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   119
	int score = 0;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   120
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   121
	memset(_score_part[owner], 0, sizeof(_score_part[owner]));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
/* Count vehicles */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
		Vehicle *v;
1415
e3877505327d (svn r1919) -Fix: Minimum profit of vehicles was calculated wrong for Performance Rating
truelight
parents: 1407
diff changeset
   126
		int32 min_profit = score_info[SCORE_MIN_PROFIT].needed;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
		uint num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
		FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
			if (v->owner != owner)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
				continue;
1067
a083a6dd1419 (svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents: 1019
diff changeset
   132
			if ((v->type == VEH_Train && v->subtype == TS_Front_Engine) ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
					v->type == VEH_Road ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
					(v->type == VEH_Aircraft && v->subtype<=2) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
					v->type == VEH_Ship) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
				if (v->age > 730) {
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   138
					if (min_profit > v->profit_last_year)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
						min_profit = v->profit_last_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   144
		_score_part[owner][SCORE_VEHICLES] = num;
1407
bbcdd50795e3 (svn r1911) Put back an "if" i accidently removed in r1898
tron
parents: 1394
diff changeset
   145
		if (min_profit > 0)
bbcdd50795e3 (svn r1911) Put back an "if" i accidently removed in r1898
tron
parents: 1394
diff changeset
   146
			_score_part[owner][SCORE_MIN_PROFIT] = min_profit;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
/* Count stations */
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
		uint num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
		Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
			if (st->xy != 0 && st->owner == owner) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
				int facil = st->facilities;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
				do num += facil&1; while (facil>>=1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
		}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   160
		_score_part[owner][SCORE_STATIONS] = num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
/* Generate statistics depending on recent income statistics */
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
		PlayerEconomyEntry *pee;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
		int numec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
		int32 min_income;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   168
		int32 max_income;
0
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
		numec = min(p->num_valid_stat_ent, 12);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
		if (numec != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
			min_income = 0x7FFFFFFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
			max_income = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
			pee = p->old_economy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
			do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
				min_income = min(min_income, pee->income + pee->expenses);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
				max_income = max(max_income, pee->income + pee->expenses);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
			} while (++pee,--numec);
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
			if (min_income > 0)
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   181
				_score_part[owner][SCORE_MIN_INCOME] = min_income;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   183
			_score_part[owner][SCORE_MAX_INCOME] = max_income;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
/* Generate score depending on amount of transported cargo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
		PlayerEconomyEntry *pee;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
		int numec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
		uint32 total_delivered;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
		numec = min(p->num_valid_stat_ent, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
		if (numec != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
			pee = p->old_economy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
			total_delivered = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
			do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
				total_delivered += pee->delivered_cargo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
			} while (++pee,--numec);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   201
			_score_part[owner][SCORE_DELIVERED] = total_delivered;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   204
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
/* Generate score for variety of cargo */
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
		uint cargo = p->cargo_types;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		uint num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		do num += cargo&1; while (cargo>>=1);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   210
		_score_part[owner][SCORE_CARGO] = num;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   211
		if (update)
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   212
			p->cargo_types = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
/* Generate score for player money */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
		int32 money = p->player_money;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
		if (money > 0) {
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   219
			_score_part[owner][SCORE_MONEY] = money;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
/* Generate score for loan */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
	{
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   225
		_score_part[owner][SCORE_LOAN] = score_info[SCORE_LOAN].needed - p->current_loan;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   226
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   227
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   228
	// Now we calculate the score for each item..
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   229
	{
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   230
		int i;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   231
		int total_score = 0;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   232
		int s;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   233
		score = 0;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   234
		for (i=0;i<NUM_SCORE;i++) {
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   235
			// Skip the total
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   236
			if (i == SCORE_TOTAL) continue;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   237
			// Check the score
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   238
			s = (_score_part[owner][i] >= score_info[i].needed) ? score_info[i].score : ((_score_part[owner][i] * score_info[i].score) / score_info[i].needed);
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   239
			if (s < 0) s = 0;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   240
			score += s;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   241
			total_score += score_info[i].score;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   242
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   243
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   244
		_score_part[owner][SCORE_TOTAL] = score;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   245
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   246
		// We always want the score scaled to SCORE_MAX (1000)
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   247
		if (total_score != SCORE_MAX)
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   248
			score = score * SCORE_MAX / total_score;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   251
	if (update) {
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   252
    	p->old_economy[0].performance_history = score;
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   253
    	UpdatePlayerHouse(p, score);
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   254
    	p->old_economy[0].company_value = CalculateCompanyValue(p);
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   255
    }
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   256
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   257
	InvalidateWindow(WC_PERFORMANCE_DETAIL, 0);
147
d0c8100d18cf (svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents: 116
diff changeset
   258
	return score;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
// use 255 as new_player to delete the player.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
void ChangeOwnershipOfPlayerItems(byte old_player, byte new_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	byte old = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	_current_player = old_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	if (new_player == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
		Subsidy *s;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   269
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
		for(s=_subsidies; s != endof(_subsidies); s++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
			if (s->cargo_type != 0xff && s->age >= 12) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   272
				Station *st = GetStation(s->to);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
				if (st->owner == old_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
					s->cargo_type = 0xff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
	// take care of rating in towns
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		Town *t;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   282
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
		// if a player takes over, give the ratings to that player.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
		if (new_player != 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
			FOR_ALL_TOWNS(t) if (t->xy && HASBIT(t->have_ratings, old_player)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
				if (HASBIT(t->have_ratings, new_player)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
					// use max of the two ratings.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
					t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
					SETBIT(t->have_ratings, new_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
					t->ratings[new_player] = t->ratings[old_player];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
		// reset rating for the towns.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
		FOR_ALL_TOWNS(t) if (t->xy) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
			t->ratings[old_player] = 500;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
			CLRBIT(t->have_ratings, old_player);
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
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   302
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
		int num_train = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
		int num_road = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
		int num_ship = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
		int num_aircraft = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
		Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
		// Determine Ids for the new vehicles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
		FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
			if (v->owner == new_player) {
1067
a083a6dd1419 (svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents: 1019
diff changeset
   313
				if (v->type == VEH_Train && v->subtype == TS_Front_Engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
					num_train++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
				else if (v->type == VEH_Road)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
					num_road++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
				else if (v->type == VEH_Ship)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
					num_ship++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
				else if (v->type == VEH_Aircraft && v->subtype <= 2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
					num_aircraft++;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
		FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
			if (v->owner == old_player && IS_BYTE_INSIDE(v->type, VEH_Train, VEH_Aircraft+1) ) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
				if (new_player == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
					DeleteWindowById(WC_VEHICLE_VIEW, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
					DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
					DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
					DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
					v->owner = new_player;
1067
a083a6dd1419 (svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents: 1019
diff changeset
   333
					if (v->type == VEH_Train && v->subtype == TS_Front_Engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
						v->unitnumber = ++num_train;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
					else if (v->type == VEH_Road)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
						v->unitnumber = ++num_road;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
					else if (v->type == VEH_Ship)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
						v->unitnumber = ++num_ship;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
					else if (v->type == VEH_Aircraft && v->subtype <= 2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
						v->unitnumber = ++num_aircraft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
		}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
	// Change ownership of tiles
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
		uint tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
			ChangeTileOwner(tile, old_player, new_player);
863
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 830
diff changeset
   351
		} while (++tile != MapSize());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	// Change color of existing windows
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	if (new_player != 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
		Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
		for(w=_windows; w != _last_window; w++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
			if (w->caption_color == old_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
				w->caption_color = new_player;
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
780
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   363
	{
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   364
		Player *p;
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   365
		uint i;
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   366
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   367
		/* Check for shares */
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   368
		FOR_ALL_PLAYERS(p) {
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   369
			for(i = 0; i < 4; i++) {
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   370
				/* 'Sell' the share if this player has any */
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   371
				if (p->share_owners[i] == _current_player)
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   372
					p->share_owners[i] = 0xFF;
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   373
			}
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   374
		}
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   375
		p = DEREF_PLAYER(_current_player);
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   376
		/* Sell all the shares that people have on this company */
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   377
		for(i = 0; i < 4; i++)
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   378
			p->share_owners[i] = 0xFF;
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   379
	}
f7d6976a1fc8 (svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents: 768
diff changeset
   380
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	_current_player = old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
extern void DeletePlayerWindows(int pi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
static void PlayersCheckBankrupt(Player *p)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	int owner;
200
03b8104d1479 (svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents: 193
diff changeset
   391
	int64 val;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   393
	// If the player has money again, it does not go bankrupt
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
	if (p->player_money >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		p->quarters_of_bankrupcy = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	p->quarters_of_bankrupcy++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
	owner = p->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   403
	switch (p->quarters_of_bankrupcy) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   404
		case 2:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   405
			AddNewsItem( (StringID)(owner + 16),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   406
				NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   407
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   408
		case 3: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   409
			/* XXX - In multiplayer, should we ask other players if it wants to take
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   410
		          over when it is a human company? -- TrueLight */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   411
			if (IS_HUMAN_PLAYER(owner)) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   412
				AddNewsItem( (StringID)(owner + 16),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   413
					NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   414
				break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   415
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   417
			// Check if the company has any value.. if not, declare it bankrupt
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   418
			//  right now
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   419
			val = CalculateCompanyValue(p);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   420
			if (val > 0) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   421
				p->bankrupt_value = val;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   422
				p->bankrupt_asked = 1 << owner; // Don't ask the owner
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   423
				p->bankrupt_timeout = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   424
				break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   425
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   426
			// Else, falltrue to case 4...
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   428
		case 4: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   429
			// Close everything the owner has open
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   430
			DeletePlayerWindows(owner);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   432
//		Show bankrupt news
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   433
			SetDParam(0, p->name_1);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   434
			SetDParam(1, p->name_2);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   435
			AddNewsItem( (StringID)(owner + 16*3), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   436
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   437
			// If the player is human, and it is no network play, leave the player playing
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   438
			if (IS_HUMAN_PLAYER(owner) && !_networking) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   439
				p->bankrupt_asked = 255;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   440
				p->bankrupt_timeout = 0x456;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   441
			} else {
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 599
diff changeset
   442
#ifdef ENABLE_NETWORK
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   443
				if (IS_HUMAN_PLAYER(owner) && _network_server) {
687
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   444
					// If we are the server, make sure it is clear that his player is no
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   445
					//  longer with us!
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   446
					NetworkClientInfo *ci;
716
40a349345f82 (svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents: 687
diff changeset
   447
					NetworkClientState *cs;
687
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   448
					/* Find all clients that were in control of this company */
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   449
					FOR_ALL_CLIENTS(cs) {
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   450
						ci = DEREF_CLIENT_INFO(cs);
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   451
						if ((ci->client_playas-1) == owner) {
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   452
							ci->client_playas = OWNER_SPECTATOR;
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   453
							// Send the new info to all the clients
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   454
							NetworkUpdateClientInfo(_network_own_client_index);
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   455
						}
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   456
					}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   457
				}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   458
				// Make sure the player no longer controls the company
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   459
				if (IS_HUMAN_PLAYER(owner) && owner == _local_player) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   460
					// Switch the player to spectator..
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   461
					_local_player = OWNER_SPECTATOR;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   462
				}
687
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   463
#endif /* ENABLE_NETWORK */
e8d646a00eb1 (svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents: 679
diff changeset
   464
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   465
				// Convert everything the player owns to NO_OWNER
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   466
				p->money64 = p->player_money = 100000000;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   467
				ChangeOwnershipOfPlayerItems(owner, 0xFF); // 255 is no owner
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   468
				// Register the player as not-active
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   469
				p->is_active = false;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   470
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
void DrawNewsBankrupcy(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   479
	DrawNewsBorder(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	p = DEREF_PLAYER(WP(w,news_d).ni->string_id & 15);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	DrawPlayerFace(p->face, p->player_color, 2, 23);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
	GfxFillRect(3, 23, 3+91, 23+118, 0x4323);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   485
	SetDParam(0, p->president_name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   486
	SetDParam(1, p->president_name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
	DrawStringMultiCenter(49, 148, STR_7058_PRESIDENT, 94);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
	switch(WP(w,news_d).ni->string_id >> 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
	case 1:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		DrawStringCentered(w->width>>1, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   494
		SetDParam(0, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   495
		SetDParam(1, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
		DrawStringMultiCenter(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
			((w->width - 101) >> 1) + 98,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
			90,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
			STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
			w->width - 101);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
	case 2: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
		int32 price;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
		DrawStringCentered(w->width>>1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
		COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   509
		SetDParam(2, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   510
		SetDParam(3, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
		price = WP(w,news_d).ni->params[2];
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   512
		SetDParam(4, price);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
		DrawStringMultiCenter(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
			((w->width - 101) >> 1) + 98,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
			90,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
			price==0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
			w->width - 101);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
	case 3:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
		DrawStringCentered(w->width>>1, 1, STR_705C_BANKRUPT, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
		COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
		DrawStringMultiCenter(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
			((w->width - 101) >> 1) + 98,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
			90,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
			STR_705D_HAS_BEEN_CLOSED_DOWN_BY,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
			w->width - 101);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   529
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
	case 4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
		DrawStringCentered(w->width>>1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   533
		SetDParam(0, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   534
		SetDParam(1, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
		COPY_IN_DPARAM(2,WP(w,news_d).ni->params, 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
		DrawStringMultiCenter(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
			((w->width - 101) >> 1) + 98,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
			90,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
			STR_705F_STARTS_CONSTRUCTION_NEAR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
			w->width - 101);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
	default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
		NOT_REACHED();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
StringID GetNewsStringBankrupcy(NewsItem *ni)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
	Player *p = DEREF_PLAYER(ni->string_id & 0xF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	switch(ni->string_id >> 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
	case 1:
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   554
		SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   555
		SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   556
		SetDParam(2, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   557
		SetDParam(3, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
		return STR_02B6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
	case 2:
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   560
		SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   561
		SetDParam(1, STR_705A_HAS_BEEN_SOLD_TO_FOR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
		COPY_IN_DPARAM(2,ni->params, 2);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   563
		SetDParam(4, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   564
		SetDParam(5, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
		COPY_IN_DPARAM(6,ni->params + 2, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
		return STR_02B6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
	case 3:
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   568
		SetDParam(0, STR_705C_BANKRUPT);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   569
		SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
		COPY_IN_DPARAM(2,ni->params, 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
		return STR_02B6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
	case 4:
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   573
		SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   574
		SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   575
		SetDParam(2, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   576
		SetDParam(3, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
		COPY_IN_DPARAM(4,ni->params, 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
		return STR_02B6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
	default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
		NOT_REACHED();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   582
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
	/* useless, but avoids compiler warning this way */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
   587
static void PlayersGenStatistics(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
		if (st->xy != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
			_current_player = st->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
			SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
			SubtractMoneyFromPlayer(_price.station_value >> 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
	if (!HASBIT(1<<0|1<<3|1<<6|1<<9, _cur_month))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
	FOR_ALL_PLAYERS(p) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
		if (p->is_active) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
			memmove(&p->old_economy, &p->cur_economy, sizeof(p->old_economy));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
			memset(&p->cur_economy, 0, sizeof(p->cur_economy));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
			if (p->num_valid_stat_ent != 24)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
				p->num_valid_stat_ent++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 33
diff changeset
   611
			UpdateCompanyRatingAndValue(p, true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
			PlayersCheckBankrupt(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
			if (p->block_preview != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
				p->block_preview--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	InvalidateWindow(WC_INCOME_GRAPH, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	InvalidateWindow(WC_OPERATING_PROFIT, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	InvalidateWindow(WC_DELIVERED_CARGO, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
	InvalidateWindow(WC_COMPANY_VALUE, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	InvalidateWindow(WC_COMPANY_LEAGUE, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
static void AddSingleInflation(int32 *value, uint16 *frac, int32 amt)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	int64 tmp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
	int32 low;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
	tmp = BIGMULS(*value, amt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	*frac = (uint16)(low = (uint16)tmp + *frac);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	*value += (int32)(tmp >> 16) + (low >> 16);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
   636
static void AddInflation(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	int32 inf = _economy.infl_amount * 54;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	for(i=0; i!=NUM_PRICES; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
		AddSingleInflation( (int32*)&_price + i, _price_frac + i, inf );
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	_economy.max_loan_unround += BIGMULUS(_economy.max_loan_unround, inf, 16);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   646
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	if (_economy.max_loan + 50000 <= _economy.max_loan_unround)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
		_economy.max_loan += 50000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	inf = _economy.infl_amount_pr * 54;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
	for(i=0; i!=NUM_CARGO; i++) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   652
		AddSingleInflation(
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
			_cargo_payment_rates + i,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
			_cargo_payment_rates_frac + i,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
			inf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	InvalidateWindowClasses(WC_BUILD_VEHICLE);
1098
481fbdea1569 (svn r1599) fix: autoreplace window now updates when inflation alters prices
bjarni
parents: 1093
diff changeset
   660
	InvalidateWindowClasses(WC_REPLACE_VEHICLE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	InvalidateWindowClasses(WC_VEHICLE_DETAILS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	InvalidateWindow(WC_PAYMENT_RATES, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
   665
static void PlayersPayInterest(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
	int interest = _economy.interest_rate * 54;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
	FOR_ALL_PLAYERS(p) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
		if (!p->is_active)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
			continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
		_current_player = p->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
		SET_EXPENSES_TYPE(EXPENSES_LOAN_INT);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   676
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
		SubtractMoneyFromPlayer(BIGMULUS(p->current_loan, interest, 16));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
		SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
		SubtractMoneyFromPlayer(_price.station_value >> 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
   684
static void HandleEconomyFluctuations(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
	if (_opt.diff.economy == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	if (--_economy.fluct == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
		_economy.fluct = - (int)(Random()&3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
		AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
	} else if (_economy.fluct == -12) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
		_economy.fluct = (Random()&255) + 312;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
		AddNewsItem(STR_7074_RECESSION_OVER_UPTURN_IN, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
static byte _price_category[NUM_PRICES] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
	0, 2, 2, 2, 2, 2, 2, 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	2, 2, 2, 2, 2, 2, 2, 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
	2, 2, 2, 2, 2, 2, 2, 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	2, 2, 2, 2, 2, 2, 2, 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	2, 2, 2, 2, 2, 2, 2, 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	2, 2, 1, 1, 1, 1, 1, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
	2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
static const int32 _price_base[NUM_PRICES] = {
9
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   709
	100,		// station_value
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   710
	100,		// build_rail
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   711
	95,			// build_road
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   712
	65,			// build_signals
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   713
	275,		// build_bridge
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   714
	600,		// build_train_depot
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   715
	500,		// build_road_depot
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   716
	700,		// build_ship_depot
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   717
	450,		// build_tunnel
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   718
	200,		// train_station_track
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   719
	180,		// train_station_length
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   720
	600,		// build_airport
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   721
	200,		// build_bus_station
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   722
	200,		// build_truck_station
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   723
	350,		// build_dock
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   724
	400000,	// build_railvehicle
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   725
	2000,		// build_railwagon
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   726
	700000,	// aircraft_base
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   727
	14000,	// roadveh_base
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   728
	65000,	// ship_base
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   729
	20,			// build_trees
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   730
	250,		// terraform
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   731
	20,			// clear_1
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   732
	40,			// purchase_land
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   733
	200,		// clear_2
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   734
	500,		// clear_3
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   735
	20,			// remove_trees
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   736
	-70,		// remove_rail
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   737
	10,			// remove_signals
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   738
	50,			// clear_bridge
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   739
	80,			// remove_train_depot
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   740
	80,			// remove_road_depot
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   741
	90,			// remove_ship_depot
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   742
	30,			// clear_tunnel
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   743
	10000,	// clear_water
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   744
	50,			// remove_rail_station
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   745
	30,			// remove_airport
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   746
	50,			// remove_bus_station
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   747
	50,			// remove_truck_station
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   748
	55,			// remove_dock
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   749
	1600,		// remove_house
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   750
	40,			// remove_road
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   751
	5600,		// running_rail[0] railroad
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   752
	5200,		// running_rail[1] monorail
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   753
	4800,		// running_rail[2] maglev
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   754
	9600,		// aircraft_running
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   755
	1600,		// roadveh_running
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   756
	5600,		// ship_running
b1ecf90eb6da (svn r10) Some documentation on _price_base array
dominik
parents: 4
diff changeset
   757
	1000000, // build_industry
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
   760
void StartupEconomy(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
	assert(sizeof(_price) == NUM_PRICES * sizeof(int32));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
	for(i=0; i!=NUM_PRICES; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
		int32 price = _price_base[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
		if (_price_category[i] != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
			uint mod = _price_category[i] == 1 ? _opt.diff.vehicle_costs : _opt.diff.construction_cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
			if (mod < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
				price = price * 3 >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
			} else if (mod > 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
				price = price * 9 >> 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
		((int32*)&_price)[i] = price;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
		_price_frac[i] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
	_economy.interest_rate = _opt.diff.initial_interest;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	_economy.infl_amount = _opt.diff.initial_interest;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
	_economy.infl_amount_pr = max(0, _opt.diff.initial_interest - 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	_economy.max_loan_unround = _economy.max_loan = _opt.diff.max_loan * 1000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	_economy.fluct = (byte)(Random()) + 168;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
Pair SetupSubsidyDecodeParam(Subsidy *s, bool mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	int tile, tile2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
	Pair tp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
	/* if mode is false, convert into plural */
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   796
	SetDParam(0, _cargoc.names_s[s->cargo_type] + (mode?0:32));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
	if (s->age < 12) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
		if (!(s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL)) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   800
			SetDParam(1, STR_2029);
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   801
			i = GetIndustry(s->from);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
			tile = i->xy;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   803
			SetDParam(2, i->town->townnametype);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   804
			SetDParam(3, i->town->townnameparts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   806
			SetDParam(4, i->type + STR_4802_COAL_MINE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
			if (s->cargo_type != CT_GOODS && s->cargo_type != CT_FOOD) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   809
				SetDParam(5, STR_2029);
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   810
				i = GetIndustry(s->to);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
				tile2 = i->xy;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   812
				SetDParam(8, i->type + STR_4802_COAL_MINE);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   813
				SetDParam(6, i->town->townnametype);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   814
				SetDParam(7, i->town->townnameparts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
			} else {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   816
				t = GetTown(s->to);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
				tile2 = t->xy;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   818
				SetDParam(5, t->townnametype);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   819
				SetDParam(6, t->townnameparts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
		} else {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   822
			t = GetTown(s->from);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
			tile = t->xy;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   824
			SetDParam(1, t->townnametype);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   825
			SetDParam(2, t->townnameparts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   827
			t = GetTown(s->to);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
			tile2 = t->xy;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   829
			SetDParam(3, t->townnametype);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   830
			SetDParam(4, t->townnameparts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
	} else {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   833
		st = GetStation(s->from);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
		tile = st->xy;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   835
		SetDParam(1, st->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   837
		st = GetStation(s->to);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
		tile2 = st->xy;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
   839
		SetDParam(2, st->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
	tp.a = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
	tp.b = tile2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	return tp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
820
9d311999f866 (svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents: 816
diff changeset
   848
void DeleteSubsidyWithIndustry(uint16 index)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
	Subsidy *s;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   851
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
	for(s=_subsidies; s != endof(_subsidies); s++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
		if (s->cargo_type != 0xFF && s->age < 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
				s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
				(index == s->from || (s->cargo_type!=CT_GOODS && s->cargo_type!=CT_FOOD && index==s->to))) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
			s->cargo_type = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   858
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
820
9d311999f866 (svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents: 816
diff changeset
   861
void DeleteSubsidyWithStation(uint16 index)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	Subsidy *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	bool dirty = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   865
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	for(s=_subsidies; s != endof(_subsidies); s++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
		if (s->cargo_type != 0xFF && s->age >= 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
				(s->from == index || s->to == index)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
			s->cargo_type = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
			dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   872
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
	if (dirty)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
		InvalidateWindow(WC_SUBSIDIES_LIST, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
typedef struct FoundRoute {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	uint distance;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	byte cargo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
	void *from;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
	void *to;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
} FoundRoute;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
static void FindSubsidyPassengerRoute(FoundRoute *fr)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	Town *from,*to;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	fr->distance = (uint)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   891
	fr->from = from = GetTown(RandomRange(_total_towns));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
	if (from->xy == 0 || from->population < 400)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   895
	fr->to = to = GetTown(RandomRange(_total_towns));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	if (from==to || to->xy == 0 || to->population < 400 || to->pct_pass_transported > 42)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1098
diff changeset
   899
	fr->distance = DistanceManhattan(from->xy, to->xy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
static void FindSubsidyCargoRoute(FoundRoute *fr)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	int trans, total;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	byte cargo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	fr->distance = (uint)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   910
	fr->from = i = GetIndustry(RandomRange(_total_industries));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
	if (i->xy == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	// Randomize cargo type
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   915
	if (Random()&1 && i->produced_cargo[1] != 0xFF) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
		cargo = i->produced_cargo[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
		trans = i->pct_transported[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
		total = i->total_production[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
		cargo = i->produced_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
		trans = i->pct_transported[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
		total = i->total_production[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
	// Quit if no production in this industry
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
	//  or if the cargo type is passengers
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	//  or if the pct transported is already large enough
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	if (total == 0  || trans > 42 || cargo == 0xFF || cargo == CT_PASSENGERS)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
	fr->cargo = cargo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
	if (cargo == CT_GOODS || cargo == CT_FOOD) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
		// The destination is a town
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   935
		Town *t = GetTown(RandomRange(_total_towns));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   936
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
		// Only want big towns
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
		if (t->xy == 0 || t->population < 900)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
			return;
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1098
diff changeset
   940
		fr->distance = DistanceManhattan(i->xy, t->xy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
		fr->to = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
		// The destination is an industry
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
   944
		Industry *i2 = GetIndustry(RandomRange(_total_industries));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   945
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
		// The industry must accept the cargo
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   947
		if (i == i2 || i2->xy == 0 ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
				(cargo != i2->accepts_cargo[0] &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
				cargo != i2->accepts_cargo[1] &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
				cargo != i2->accepts_cargo[2]))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
			return;
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1098
diff changeset
   952
		fr->distance = DistanceManhattan(i->xy, i2->xy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
		fr->to = i2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   957
static bool CheckSubsidyDuplicate(Subsidy *s)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
	Subsidy *ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
	for(ss=_subsidies; ss != endof(_subsidies); ss++) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   962
		if (s != ss &&
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   963
//				ss->age < 12 &&
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   964
				ss->from == s->from &&
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
   965
				ss->to == s->to &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
				ss->cargo_type == s->cargo_type) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
			s->cargo_type = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
239
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   974
void RemoteSubsidyAdd(Subsidy *s_new)
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   975
{
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   976
	Subsidy *s;
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   977
	Pair pair;
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   978
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   979
	// search the first free subsidy
240
f1efbac04112 (svn r241) -Fix: Trailing spaces :O
darkvater
parents: 239
diff changeset
   980
	for(s=_subsidies; s != endof(_subsidies); s++)
239
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   981
		if (s->cargo_type == 0xFF)
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   982
			break;
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   983
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   984
	memcpy(s,s_new,sizeof(Subsidy));
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   985
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   986
	pair = SetupSubsidyDecodeParam(s, 0);
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   987
	AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   988
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   989
	InvalidateWindow(WC_SUBSIDIES_LIST, 0);
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   990
}
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
   991
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
   992
static void SubsidyMonthlyHandler(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
	Subsidy *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	Pair pair;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
	uint n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	FoundRoute fr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	bool modified = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
	for(s=_subsidies; s != endof(_subsidies); s++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
		if (s->cargo_type == 0xFF)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
			continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
		if (s->age == 12-1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
			pair = SetupSubsidyDecodeParam(s, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
			AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
			s->cargo_type = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
			modified = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
		} else if (s->age == 2*12-1) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1011
			st = GetStation(s->to);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
			if (st->owner == _local_player) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
				pair = SetupSubsidyDecodeParam(s, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
				AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
			s->cargo_type = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
			modified = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
			s->age++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
	// 25% chance to go on
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1024
	if (CHANCE16(1,4)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
		// Find a free slot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
		s = _subsidies;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
		while (s->cargo_type != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
			if (++s == endof(_subsidies))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
				goto no_add;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1031
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
		n = 1000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
			FindSubsidyPassengerRoute(&fr);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
			if (fr.distance <= 70) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
				s->cargo_type = CT_PASSENGERS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
				s->from = ((Town*)fr.from)->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
				s->to = ((Town*)fr.to)->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
				goto add_subsidy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
			FindSubsidyCargoRoute(&fr);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
			if (fr.distance <= 70) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
				s->cargo_type = fr.cargo;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1044
				s->from = ((Industry*)fr.from)->index;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1045
				s->to = (fr.cargo == CT_GOODS || fr.cargo == CT_FOOD) ? ((Town*)fr.to)->index : ((Industry*)fr.to)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
	add_subsidy:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
				if (!CheckSubsidyDuplicate(s)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
					s->age = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
					pair = SetupSubsidyDecodeParam(s, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
					AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
					modified = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
			}
239
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 236
diff changeset
  1055
		} while (n--);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
no_add:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
	if (modified)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
		InvalidateWindow(WC_SUBSIDIES_LIST, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
static const byte _subsidies_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	SLE_VAR(Subsidy,cargo_type,		SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
	SLE_VAR(Subsidy,age,					SLE_UINT8),
820
9d311999f866 (svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents: 816
diff changeset
  1065
	SLE_CONDVAR(Subsidy,from,			SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
9d311999f866 (svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents: 816
diff changeset
  1066
	SLE_CONDVAR(Subsidy,from,			SLE_UINT16, 5, 255),
9d311999f866 (svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents: 816
diff changeset
  1067
	SLE_CONDVAR(Subsidy,to,				SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
9d311999f866 (svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents: 816
diff changeset
  1068
	SLE_CONDVAR(Subsidy,to,				SLE_UINT16, 5, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
  1072
static void Save_SUBS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
	Subsidy *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
	for(i=0; i!=lengthof(_subsidies); i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
		s = &_subsidies[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
		if (s->cargo_type != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
			SlSetArrayIndex(i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
			SlObject(s, _subsidies_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
  1086
static void Load_SUBS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
	while ((index = SlIterateArray()) != -1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
		SlObject(&_subsidies[index], _subsidies_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, byte cargo_type)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	int cargo = cargo_type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
	byte f;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
	/* zero the distance if it's the bank and very short transport. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
	if (_opt.landscape == LT_NORMAL && cargo == CT_VALUABLES && dist < 10)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
		dist = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
	f = 255;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	if (transit_days > _cargoc.transit_days_1[cargo]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
		transit_days -= _cargoc.transit_days_1[cargo];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
		f -= transit_days;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1106
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
		if (transit_days > _cargoc.transit_days_2[cargo]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
			transit_days -= _cargoc.transit_days_2[cargo];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
			if (f < transit_days)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
				f = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
			else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
				f -= transit_days;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
	if (f < 31) f = 31;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
	return BIGMULSS(dist * f * num_pieces, _cargo_payment_rates[cargo], 21);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
static void DeliverGoodsToIndustry(TileIndex xy, byte cargo_type, int num_pieces)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1123
	Industry *ind, *best;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
	int t, u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
	/* Check if there's an industry close to the station that accepts
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
	 * the cargo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
	best = NULL;
33
431df1abc34b (svn r34) -Fix [990770] Cargo delivery area patch for bug #989322. If station sign was too far away, there were goods acceptance/delivery issues (Celstar)
darkvater
parents: 9
diff changeset
  1129
	u = _patches.station_spread + 8;
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 820
diff changeset
  1130
	FOR_ALL_INDUSTRIES(ind) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
		if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
				 == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
				 ind->produced_cargo[0] != 0xFF &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
				 ind->produced_cargo[0] != cargo_type &&
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1098
diff changeset
  1135
				 (t = DistanceManhattan(ind->xy, xy)) < u) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
			u = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
			best = ind;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	/* Found one? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	if (best != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
		best->was_cargo_delivered = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
		best->cargo_waiting[0] = min(best->cargo_waiting[0] + num_pieces, 0xFFFF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
static bool CheckSubsidised(Station *from, Station *to, byte cargo_type)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	Subsidy *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	TileIndex xy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	Pair pair;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	// check if there is an already existing subsidy that applies to us
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
	for(s=_subsidies; s != endof(_subsidies); s++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
		if (s->cargo_type == cargo_type &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
				s->age >= 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
				s->from == from->index &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
				s->to == to->index)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
	/* check if there's a new subsidy that applies.. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	for(s=_subsidies; s != endof(_subsidies); s++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
		if (s->cargo_type == cargo_type && s->age < 12) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1167
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
			/* Check distance from source */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
			if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1170
				xy = GetTown(s->from)->xy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
			} else {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1172
				xy = (GetIndustry(s->from))->xy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
			}
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1098
diff changeset
  1174
			if (DistanceMax(xy, from->xy) > 9)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
				continue;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1176
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
			/* Check distance from dest */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
			if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_GOODS || cargo_type == CT_FOOD) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1179
				xy = GetTown(s->to)->xy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
			} else {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1181
				xy = (GetIndustry(s->to))->xy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1098
diff changeset
  1184
			if (DistanceMax(xy, to->xy) > 9)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
				continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
			/* Found a subsidy, change the values to indicate that it's in use */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
			s->age = 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
			s->from = from->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
			s->to = to->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
			/* Add a news item */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
			pair = SetupSubsidyDecodeParam(s, 0);
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: 1308
diff changeset
  1194
			InjectDParam(2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
			p = DEREF_PLAYER(_current_player);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
  1197
			SetDParam(0, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
  1198
			SetDParam(1, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
			AddNewsItem(
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1200
				STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
				NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
				pair.a, pair.b);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
			InvalidateWindow(WC_SUBSIDIES_LIST, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1245
diff changeset
  1211
static int32 DeliverGoods(int num_pieces, byte cargo_type, uint16 source, uint16 dest, byte days_in_transit)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
	bool subsidised;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
	Station *s_from, *s_to;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
	int32 profit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
 	assert(num_pieces > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	// Update player statistics
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
		Player *p = DEREF_PLAYER(_current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
		p->cur_economy.delivered_cargo += num_pieces;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
		SETBIT(p->cargo_types, cargo_type);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
	// Get station pointers.
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1227
	s_from = GetStation(source);
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1228
	s_to = GetStation(dest);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	// Check if a subsidy applies.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	subsidised = CheckSubsidised(s_from, s_to, cargo_type);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
	// Increase town's counter for some special goods types
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
		Town *t = s_to->town;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
		if (cargo_type == CT_FOOD) t->new_act_food += num_pieces;
1308
286dda1121ca (svn r1812) [1117058] Use CT_WATER instead of CT_STEEL when accounting water which gets delivered to a town (worked because CT_STEEL and CT_WATER share the same enum number)
tron
parents: 1266
diff changeset
  1237
		if (cargo_type == CT_WATER)  t->new_act_water += num_pieces;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
	// Give the goods to the industry.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
	DeliverGoodsToIndustry(s_to->xy, cargo_type, num_pieces);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1242
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
	// Determine profit
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
	{
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1098
diff changeset
  1245
		int t = DistanceManhattan(s_from->xy, s_to->xy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
		int r = num_pieces;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
		profit = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
			int u = min(r, 255);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
			r -= u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
			profit += GetTransportedGoodsIncome(u, t, days_in_transit, cargo_type);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
		} while (r != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
	// Modify profit if a subsidy is in effect
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
	if (subsidised) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
		if (_opt.diff.subsidy_multiplier < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
			/* 1.5x */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
			profit += profit >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
		} else if (_opt.diff.subsidy_multiplier == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
			/* 2x */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
			profit *= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
		} else if (_opt.diff.subsidy_multiplier == 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
			/* 3x */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
			profit *= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
			/* 4x */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
			profit *= 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
	// Computers get 25% extra profit if they're intelligent.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
	if (_opt.diff.competitor_intelligence>=1 && !IS_HUMAN_PLAYER(_current_player))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
		profit += profit >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
	return profit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
523
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1279
/*
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1280
 * Returns true if Vehicle v should wait loading because other vehicle is
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1281
 * already loading the same cargo type
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1282
 * v = vehicle to load, u = GetFirstInChain(v)
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1283
 */
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1284
static bool LoadWait(const Vehicle *v, const Vehicle *u) {
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1285
	const Vehicle *w;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1286
	const Vehicle *x;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1287
	bool has_any_cargo = false;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1288
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  1289
	if (!(u->current_order.flags & OF_FULL_LOAD)) return false;
523
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1290
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1291
	for (w = u; w != NULL; w = w->next) {
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1292
		if (w->cargo_count != 0) {
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1293
			if (v->cargo_type == w->cargo_type &&
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1294
					u->last_station_visited == w->cargo_source)
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1295
				return false;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1296
			has_any_cargo = true;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1297
		}
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1298
	}
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1299
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1300
	FOR_ALL_VEHICLES(x) {
1067
a083a6dd1419 (svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents: 1019
diff changeset
  1301
		if ((x->type != VEH_Train || x->subtype == TS_Front_Engine) && // for all locs
523
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1302
				u->last_station_visited == x->last_station_visited && // at the same station
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1303
				!(x->vehstatus & VS_STOPPED) && // not stopped
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  1304
				x->current_order.type == OT_LOADING && // loading
523
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1305
				u != x) { // not itself
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1306
			bool other_has_any_cargo = false;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1307
			bool has_space_for_same_type = false;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1308
			bool other_has_same_type = false;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1309
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1310
			for (w = x; w != NULL; w = w->next) {
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1311
				if (w->cargo_count < w->cargo_cap && v->cargo_type == w->cargo_type)
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1312
					has_space_for_same_type = true;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1313
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1314
				if (w->cargo_count != 0) {
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1315
					if (v->cargo_type == w->cargo_type &&
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1316
							u->last_station_visited == w->cargo_source)
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1317
						other_has_same_type = true;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1318
					other_has_any_cargo = true;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1319
				}
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1320
			}
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1321
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1322
			if (has_space_for_same_type) {
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1323
				if (other_has_same_type) return true;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1324
				if (other_has_any_cargo && !has_any_cargo) return true;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1325
			}
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1326
		}
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1327
	}
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1328
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1329
	return false;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1330
}
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1331
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
int LoadUnloadVehicle(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
	int profit = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
	int unloading_time = 20;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
	Vehicle *u = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
	int result = 0;
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1245
diff changeset
  1338
	uint16 last_visited;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
	GoodsEntry *ge;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
	int t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
	uint count, cap;
260
32fcaaf9f4ef (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 240
diff changeset
  1343
	byte old_player;
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1344
	bool completely_empty = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  1346
	assert(v->current_order.type == OT_LOADING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
	v->cur_speed = 0;
260
32fcaaf9f4ef (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 240
diff changeset
  1349
	old_player = _current_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
	_current_player = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 863
diff changeset
  1352
	st = GetStation(last_visited = v->last_station_visited);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
499
509765981930 (svn r792) Small cleanup: Kill a goto
tron
parents: 445
diff changeset
  1354
	for (; v != NULL; v = v->next) {
509765981930 (svn r792) Small cleanup: Kill a goto
tron
parents: 445
diff changeset
  1355
		if (v->cargo_cap == 0) continue;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1356
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
		ge = &st->goods[v->cargo_type];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
		/* unload? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
		if (v->cargo_count != 0) {
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1245
diff changeset
  1361
			if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
				// deliver goods to the station
1416
f3ac4388c069 (svn r1920) -Fix: no longer a station where you only unload is bad for your town-rating
truelight
parents: 1415
diff changeset
  1363
				st->time_since_unload = 0;
f3ac4388c069 (svn r1920) -Fix: no longer a station where you only unload is bad for your town-rating
truelight
parents: 1415
diff changeset
  1364
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
				unloading_time += v->cargo_count; /* TTDBUG: bug in original TTD */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
				profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_days);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
				result |= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
				v->cargo_count = 0;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  1369
			} else if (u->current_order.flags & OF_UNLOAD) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
				/* unload goods and let it wait at the station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
				st->time_since_unload = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1372
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
				if ((t=ge->waiting_acceptance & 0xFFF) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
					// No goods waiting at station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
					ge->enroute_time = v->cargo_days;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
					ge->enroute_from = v->cargo_source;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
					// Goods already waiting at station. Set counters to the worst value.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
					if (v->cargo_days >= ge->enroute_time)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
						ge->enroute_time = v->cargo_days;
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1245
diff changeset
  1381
					if (last_visited != ge->enroute_from)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
						ge->enroute_from = v->cargo_source;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
				// Update amount of waiting cargo
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
				ge->waiting_acceptance = (ge->waiting_acceptance &~0xFFF) | min(v->cargo_count + t, 0xFFF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
				result |= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
				v->cargo_count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
			}
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1389
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1390
			if (v->cargo_count != 0)
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1391
				completely_empty = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1393
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
		/* don't pick up goods that we unloaded */
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  1395
		if (u->current_order.flags & OF_UNLOAD) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
		/* update stats */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
		ge->days_since_pickup = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
		t = u->max_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
		if (u->type == VEH_Road) t >>=1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1401
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
		// if last speed is 0, we treat that as if no vehicle has ever visited the station.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
		ge->last_speed = t < 255 ? t : 255;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
		ge->last_age = _cur_year - v->build_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
		// If there's goods waiting at the station, and the vehicle
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
		//  has capacity for it, load it on the vehicle.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
		if ((count=ge->waiting_acceptance & 0xFFF) != 0 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
				(cap = v->cargo_cap - v->cargo_count) != 0) {
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1410
			if (v->cargo_count == 0)
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1411
				TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1412
523
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1413
			/* Skip loading this vehicle if another train/vehicle is already handling
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1414
			 * the same cargo type at this station */
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1415
			if (_patches.improved_load && LoadWait(v,u)) continue;
1184a22723ad (svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents: 507
diff changeset
  1416
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1417
			/* TODO: Regarding this, when we do gradual loading, we
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1418
			 * should first unload all vehicles and then start
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1419
			 * loading them. Since this will cause
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1420
			 * VEHICLE_TRIGGER_EMPTY to be called at the time when
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1421
			 * the whole vehicle chain is really totally empty, the
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1422
			 * @completely_empty assignment can then be safely
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1423
			 * removed; that's how TTDPatch behaves too. --pasky */
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1424
			completely_empty = false;
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1425
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
			if (cap > count) cap = count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
			v->cargo_count += cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
			ge->waiting_acceptance -= cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
			unloading_time += cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
			st->time_since_load = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 147
diff changeset
  1431
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
			// And record the source of the cargo, and the days in travel.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
			v->cargo_source = ge->enroute_from;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
			v->cargo_days = ge->enroute_time;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
			result |= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
			st->last_vehicle = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
	v = u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
	if (v->type == VEH_Train) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
		int num = - (int)GetStationPlatforms(st, v->tile) * 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
		do num++; while ( (v=v->next) != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
		if (num > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
			unloading_time <<=1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
			unloading_time += num * unloading_time;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
		v = u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
	v->load_unload_time_rem = unloading_time;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1454
	if (completely_empty) {
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1455
		TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY);
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1456
	}
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 337
diff changeset
  1457
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
	if (result != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
		if (result & 2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
			InvalidateWindow(WC_STATION_VIEW, last_visited);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
		if (profit != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
			v->profit_this_year += profit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
			SubtractMoneyFromPlayer(-profit);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
			if (_current_player == _local_player)
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1469
				SndPlayVehicleFx(SND_14_CASHTILL, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
			ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, -profit);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
260
32fcaaf9f4ef (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 240
diff changeset
  1475
	_current_player = old_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
	return result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
  1479
void PlayersMonthlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
	PlayersGenStatistics();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
	if (_patches.inflation)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
		AddInflation();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
	PlayersPayInterest();
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 200
diff changeset
  1485
	// Reset the _current_player flag
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 200
diff changeset
  1486
	_current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	HandleEconomyFluctuations();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
	SubsidyMonthlyHandler();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
static void DoAcquireCompany(Player *p)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
	Player *owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
	int i,pi;
200
03b8104d1479 (svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents: 193
diff changeset
  1495
	int64 value;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
  1497
	SetDParam(0, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
  1498
	SetDParam(1, p->name_2);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 523
diff changeset
  1499
	SetDParam(2, p->bankrupt_value);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
	AddNewsItem( (StringID)(_current_player + 16*2), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
	// original code does this a little bit differently
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
	pi = p->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
	ChangeOwnershipOfPlayerItems(pi, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
	if (p->bankrupt_value == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
		owner = DEREF_PLAYER(_current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
		owner->current_loan += p->current_loan;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
	value = CalculateCompanyValue(p) >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	for(i=0; i!=4; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
		if (p->share_owners[i] != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
			owner = DEREF_PLAYER(p->share_owners[i]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
			owner->money64 += value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
			owner->yearly_expenses[0][EXPENSES_OTHER] += value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
			UpdatePlayerMoney32(owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
	p->is_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
	DeletePlayerWindows(pi);
967
cd64c19d3de4 (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 930
diff changeset
  1524
	RebuildVehicleLists();	//Updates the open windows to add the newly acquired vehicles to the lists
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
599
80e49e323483 (svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents: 555
diff changeset
  1527
extern int GetAmountOwnedBy(Player *p, byte owner);
80e49e323483 (svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents: 555
diff changeset
  1528
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
int32 CmdBuyShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
	Player *p;
200
03b8104d1479 (svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents: 193
diff changeset
  1532
	int64 cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
	byte *b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
	p = DEREF_PLAYER(p1);
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 997
diff changeset
  1538
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 997
diff changeset
  1539
997
71cf4e50d259 (svn r1495) -Fix: Loan does not count against the company value
celestar
parents: 970
diff changeset
  1540
	if (_cur_year - p->inaugurated_year < 6) {
71cf4e50d259 (svn r1495) -Fix: Loan does not count against the company value
celestar
parents: 970
diff changeset
  1541
		_error_message = STR_7080_PROTECTED;
71cf4e50d259 (svn r1495) -Fix: Loan does not count against the company value
celestar
parents: 970
diff changeset
  1542
		return CMD_ERROR;
71cf4e50d259 (svn r1495) -Fix: Loan does not count against the company value
celestar
parents: 970
diff changeset
  1543
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
930
524b02923ede (svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents: 919
diff changeset
  1545
	/* Check if buying shares is allowed (protection against modified clients */
524b02923ede (svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents: 919
diff changeset
  1546
	if (!_patches.allow_shares)
524b02923ede (svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents: 919
diff changeset
  1547
		return CMD_ERROR;
524b02923ede (svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents: 919
diff changeset
  1548
599
80e49e323483 (svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents: 555
diff changeset
  1549
	/* Those lines are here for network-protection (clients can be slow) */
80e49e323483 (svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents: 555
diff changeset
  1550
	if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0)
80e49e323483 (svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents: 555
diff changeset
  1551
		return 0;
930
524b02923ede (svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents: 919
diff changeset
  1552
599
80e49e323483 (svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents: 555
diff changeset
  1553
	/* We can not buy out a real player in networking */
80e49e323483 (svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents: 555
diff changeset
  1554
	if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai)
80e49e323483 (svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents: 555
diff changeset
  1555
		return 0;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 997
diff changeset
  1556
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
	cost = CalculateCompanyValue(p) >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
		b = p->share_owners;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
		while (*b != 0xFF) b++; /* share owners is guaranteed to contain at least one 0xFF */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
		*b = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
		for(i=0;p->share_owners[i] == _current_player;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
			if (++i == 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
				p->bankrupt_value = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
				DoAcquireCompany(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
		InvalidateWindow(WC_COMPANY, (int)p1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
int32 CmdSellShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
	Player *p;
200
03b8104d1479 (svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents: 193
diff changeset
  1578
	int64 cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
	byte *b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
	p = DEREF_PLAYER(p1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
930
524b02923ede (svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents: 919
diff changeset
  1584
	/* Check if selling shares is allowed (protection against modified clients */
524b02923ede (svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents: 919
diff changeset
  1585
	if (!_patches.allow_shares)
524b02923ede (svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents: 919
diff changeset
  1586
		return CMD_ERROR;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 997
diff changeset
  1587
653
3c902c647791 (svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents: 630
diff changeset
  1588
	/* Those lines are here for network-protection (clients can be slow) */
3c902c647791 (svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents: 630
diff changeset
  1589
	if (GetAmountOwnedBy(p, _current_player) == 0)
3c902c647791 (svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents: 630
diff changeset
  1590
		return 0;
3c902c647791 (svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents: 630
diff changeset
  1591
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
	/* adjust it a little to make it less profitable to sell and buy */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
	cost = CalculateCompanyValue(p) >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1594
	cost = -(cost - (cost >> 7));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
		b = p->share_owners;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
		while (*b != _current_player) b++; /* share owners is guaranteed to contain player */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
		*b = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
		InvalidateWindow(WC_COMPANY, (int)p1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
int32 CmdBuyCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
	p = DEREF_PLAYER(p1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
	if (flags & 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
		DoAcquireCompany(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
	return p->bankrupt_value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1614
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1616
// Prices
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
  1617
static void SaveLoad_PRIC(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
	SlArray(&_price, NUM_PRICES, SLE_INT32);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
	SlArray(&_price_frac, NUM_PRICES, SLE_UINT16);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
// Cargo payment rates
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
  1624
static void SaveLoad_CAPR(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
	SlArray(&_cargo_payment_rates, NUM_CARGO, SLE_INT32);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
	SlArray(&_cargo_payment_rates_frac, NUM_CARGO, SLE_UINT16);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
static const byte _economy_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
	SLE_VAR(Economy,max_loan,						SLE_INT32),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
	SLE_VAR(Economy,max_loan_unround,		SLE_INT32),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
	SLE_VAR(Economy,fluct,							SLE_FILE_I16 | SLE_VAR_I32),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
	SLE_VAR(Economy,interest_rate,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
	SLE_VAR(Economy,infl_amount,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	SLE_VAR(Economy,infl_amount_pr,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
// Economy variables
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
  1641
static void SaveLoad_ECMY(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
	SlObject(&_economy, &_economy_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
const ChunkHandler _economy_chunk_handlers[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	{ 'PRIC', SaveLoad_PRIC, SaveLoad_PRIC, CH_RIFF | CH_AUTO_LENGTH},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
	{ 'CAPR', SaveLoad_CAPR, SaveLoad_CAPR, CH_RIFF | CH_AUTO_LENGTH},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
	{ 'SUBS', Save_SUBS,			Load_SUBS, CH_ARRAY},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
	{ 'ECMY', SaveLoad_ECMY, SaveLoad_ECMY, CH_RIFF | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655