annotate src/economy.cpp @ 12940:1b090e0c4f93 draft

(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately. Note: Savegame conversion computes the inflation from max loan. Prices from modified savegames will get lost. TTO savegames will also behave slightly different. -Change: NewGRF price modifiers now take effect everytime when loading NewGRFs instead of once on gamestart.
author frosch <frosch@openttd.org>
date Sun, 06 Sep 2009 18:53:57 +0000
parents 23e2eb186b4d
children e762f0b0f0b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12756
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12756
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12756
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12756
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12756
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12756
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12756
diff changeset
9
9111
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 9058
diff changeset
10 /** @file economy.cpp Handling of the economy. */
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
11
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
13 #include "openttd.h"
10960
a4e5b5d2837c (svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents: 10696
diff changeset
14 #include "tile_cmd.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
15 #include "company_func.h"
8116
9cc845deddfe (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents: 8114
diff changeset
16 #include "command_func.h"
12826
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12778
diff changeset
17 #include "industry.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
18 #include "town.h"
8763
d6e363672edb (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium <rubidium@openttd.org>
parents: 8626
diff changeset
19 #include "news_func.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
20 #include "network/network.h"
9428
ba7cdcf21f4c (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
21 #include "network/network_func.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
22 #include "vehicle_gui.h"
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10647
diff changeset
23 #include "ai/ai.hpp"
5854
b52317eb405c (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater <Darkvater@openttd.org>
parents: 5683
diff changeset
24 #include "aircraft.h"
11987
81554d4e6d76 (svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents: 11956
diff changeset
25 #include "train.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
26 #include "newgrf_engine.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
27 #include "newgrf_sound.h"
7168
f0216e74951d (svn r10442) -Codechange: implement the industry production callback.
rubidium <rubidium@openttd.org>
parents: 7167
diff changeset
28 #include "newgrf_industries.h"
7229
39b4e2291424 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium <rubidium@openttd.org>
parents: 7199
diff changeset
29 #include "newgrf_industrytiles.h"
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8885
diff changeset
30 #include "newgrf_station.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
31 #include "unmovable.h"
6643
18d58b36b9b3 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents: 6639
diff changeset
32 #include "group.h"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 8106
diff changeset
33 #include "strings_func.h"
8131
e300ac8001ae (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents: 8121
diff changeset
34 #include "functions.h"
e300ac8001ae (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents: 8121
diff changeset
35 #include "window_func.h"
8140
fb8a05d579da (svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents: 8139
diff changeset
36 #include "date_func.h"
8144
d18c8a0bb638 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents: 8140
diff changeset
37 #include "vehicle_func.h"
8157
019833e42fda (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium <rubidium@openttd.org>
parents: 8155
diff changeset
38 #include "sound_func.h"
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8200
diff changeset
39 #include "gfx_func.h"
9058
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
40 #include "autoreplace_func.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
41 #include "company_gui.h"
10158
c429fccf1aea (svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents: 10146
diff changeset
42 #include "signs_base.h"
12297
39ea618c207e (svn r16714) -Codechange: use pool-like accessors for Subsidy
smatz <smatz@openttd.org>
parents: 12294
diff changeset
43 #include "subsidy_base.h"
11997
e2187548a5e4 (svn r16403) -Codechange: move code related to subsidies to separate file
smatz <smatz@openttd.org>
parents: 11987
diff changeset
44 #include "subsidy_func.h"
12228
240adc64d01a (svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents: 12143
diff changeset
45 #include "station_base.h"
12475
c133b51890f4 (svn r16912) -Codechange: split waypoint.h in waypoint_base.h and waypoint_func.h
rubidium <rubidium@openttd.org>
parents: 12467
diff changeset
46 #include "waypoint_base.h"
12268
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
47 #include "economy_base.h"
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
48 #include "core/pool_func.hpp"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
49
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
50 #include "table/strings.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
51 #include "table/sprites.h"
12593
73b580ddf33f (svn r17036) -Codechange: Split price bases from economy.cpp to table/pricebase.h.
frosch <frosch@openttd.org>
parents: 12496
diff changeset
52 #include "table/pricebase.h"
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
53
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
54
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
55 /* Initialize the cargo payment-pool */
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
56 CargoPaymentPool _cargo_payment_pool("CargoPayment");
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
57 INSTANTIATE_POOL_METHODS(CargoPayment)
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
58
7926
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
59 /**
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
60 * Multiply two integer values and shift the results to right.
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
61 *
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
62 * This function multiplies two integer values. The result is
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
63 * shifted by the amount of shift to right.
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
64 *
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
65 * @param a The first integer
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
66 * @param b The second integer
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
67 * @param shift The amount to shift the value to right.
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
68 * @return The shifted result
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
69 */
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
70 static inline int32 BigMulS(const int32 a, const int32 b, const uint8 shift)
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
71 {
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
72 return (int32)((int64)a * (int64)b >> shift);
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
73 }
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
74
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
75 /**
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
76 * Multiply two unsigned integers and shift the results to right.
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
77 *
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
78 * This function multiplies two unsigned integers. The result is
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
79 * shifted by the amount of shift to right.
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
80 *
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
81 * @param a The first unsigned integer
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
82 * @param b The second unsigned integer
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
83 * @param shift The amount to shift the value to right.
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
84 * @return The shifted result
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
85 */
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
86 static inline uint32 BigMulSU(const uint32 a, const uint32 b, const uint8 shift)
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
87 {
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
88 return (uint32)((uint64)a * (uint64)b >> shift);
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
89 }
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
90
10450
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
91 typedef SmallVector<Industry *, 16> SmallIndustryList;
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
92
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
93 /* Score info */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
94 const ScoreInfo _score_info[] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
95 { SCORE_VEHICLES, 120, 100 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
96 { SCORE_STATIONS, 80, 100 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
97 { SCORE_MIN_PROFIT, 10000, 100 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
98 { SCORE_MIN_INCOME, 50000, 50 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
99 { SCORE_MAX_INCOME, 100000, 100 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
100 { SCORE_DELIVERED, 40000, 400 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
101 { SCORE_CARGO, 8, 50 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
102 { SCORE_MONEY, 10000000, 50 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
103 { SCORE_LOAN, 250000, 50 },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
104 { SCORE_TOTAL, 0, 0 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
105 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
106
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
107 int _score_part[MAX_COMPANIES][SCORE_END];
8116
9cc845deddfe (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents: 8114
diff changeset
108 Economy _economy;
9cc845deddfe (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents: 8114
diff changeset
109 Prices _price;
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
110 static Money _cargo_payment_rates[NUM_CARGO];
8119
b6ec923e9fa8 (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents: 8116
diff changeset
111 Money _additional_cash_required;
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
112 static byte _price_base_multiplier[NUM_PRICES];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
113
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
114 Money CalculateCompanyValue(const Company *c)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
115 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
116 Owner owner = c->index;
7781
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
117 Money value = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
118
7781
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
119 Station *st;
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
120 uint num = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
121
7781
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
122 FOR_ALL_STATIONS(st) {
12319
712bfd1aca6c (svn r16736) -Codechange: give some station enums a name and use that instead of 'byte'.
rubidium <rubidium@openttd.org>
parents: 12297
diff changeset
123 if (st->owner == owner) num += CountBits((byte)st->facilities);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
124 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
125
7781
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
126 value += num * _price.station_value * 25;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
127
7781
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
128 Vehicle *v;
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
129 FOR_ALL_VEHICLES(v) {
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
130 if (v->owner != owner) continue;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
131
7781
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
132 if (v->type == VEH_TRAIN ||
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
133 v->type == VEH_ROAD ||
12384
d4b73a406cf3 (svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
smatz <smatz@openttd.org>
parents: 12383
diff changeset
134 (v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft()) ||
7781
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
135 v->type == VEH_SHIP) {
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
136 value += v->value * 3 >> 1;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
137 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
138 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
139
6953
41fd36025784 (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents: 6952
diff changeset
140 /* Add real money value */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
141 value -= c->current_loan;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
142 value += c->money;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
143
7781
67423408cf20 (svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents: 7763
diff changeset
144 return max(value, (Money)1);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
145 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
146
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
147 /** if update is set to true, the economy is updated with this score
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
148 * (also the house is updated, should only be true in the on-tick event)
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
149 * @param update the economy with calculated score
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
150 * @param c company been evaluated
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
151 * @return actual score of this company
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
152 * */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
153 int UpdateCompanyRatingAndValue(Company *c, bool update)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
154 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
155 Owner owner = c->index;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
156 int score = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
157
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
158 memset(_score_part[owner], 0, sizeof(_score_part[owner]));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
159
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
160 /* Count vehicles */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
161 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
162 Vehicle *v;
6990
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6957
diff changeset
163 Money min_profit = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
164 bool min_profit_first = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
165 uint num = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
166
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
167 FOR_ALL_VEHICLES(v) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
168 if (v->owner != owner) continue;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
169 if (IsCompanyBuildableVehicleType(v->type) && v->IsPrimaryVehicle()) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
170 num++;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
171 if (v->age > 730) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
172 /* Find the vehicle with the lowest amount of profit */
8614
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8556
diff changeset
173 if (min_profit_first || min_profit > v->profit_last_year) {
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8556
diff changeset
174 min_profit = v->profit_last_year;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
175 min_profit_first = false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
176 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
177 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
178 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
179 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
180
8614
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8556
diff changeset
181 min_profit >>= 8; // remove the fract part
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8556
diff changeset
182
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
183 _score_part[owner][SCORE_VEHICLES] = num;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
184 /* Don't allow negative min_profit to show */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
185 if (min_profit > 0)
6990
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6957
diff changeset
186 _score_part[owner][SCORE_MIN_PROFIT] = ClampToI32(min_profit);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
187 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
188
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
189 /* Count stations */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
190 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
191 uint num = 0;
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10571
diff changeset
192 const Station *st;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
193
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
194 FOR_ALL_STATIONS(st) {
12319
712bfd1aca6c (svn r16736) -Codechange: give some station enums a name and use that instead of 'byte'.
rubidium <rubidium@openttd.org>
parents: 12297
diff changeset
195 if (st->owner == owner) num += CountBits((byte)st->facilities);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
196 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
197 _score_part[owner][SCORE_STATIONS] = num;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
198 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
199
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
200 /* Generate statistics depending on recent income statistics */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
201 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
202 int numec = min(c->num_valid_stat_ent, 12);
6953
41fd36025784 (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents: 6952
diff changeset
203 if (numec != 0) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
204 const CompanyEconomyEntry *cee = c->old_economy;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
205 Money min_income = cee->income + cee->expenses;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
206 Money max_income = cee->income + cee->expenses;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
207
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
208 do {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
209 min_income = min(min_income, cee->income + cee->expenses);
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
210 max_income = max(max_income, cee->income + cee->expenses);
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11234
diff changeset
211 } while (++cee, --numec);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
212
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
213 if (min_income > 0) {
6990
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6957
diff changeset
214 _score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_income);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
215 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
216
6990
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6957
diff changeset
217 _score_part[owner][SCORE_MAX_INCOME] = ClampToI32(max_income);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
218 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
219 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
220
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
221 /* Generate score depending on amount of transported cargo */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
222 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
223 const CompanyEconomyEntry *cee;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
224 int numec;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
225 uint32 total_delivered;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
226
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
227 numec = min(c->num_valid_stat_ent, 4);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
228 if (numec != 0) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
229 cee = c->old_economy;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
230 total_delivered = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
231 do {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
232 total_delivered += cee->delivered_cargo;
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11234
diff changeset
233 } while (++cee, --numec);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
234
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
235 _score_part[owner][SCORE_DELIVERED] = total_delivered;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
236 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
237 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
238
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
239 /* Generate score for variety of cargo */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
240 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
241 uint num = CountBits(c->cargo_types);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
242 _score_part[owner][SCORE_CARGO] = num;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
243 if (update) c->cargo_types = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
244 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
245
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
246 /* Generate score for company's money */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
247 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
248 if (c->money > 0) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
249 _score_part[owner][SCORE_MONEY] = ClampToI32(c->money);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
250 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
251 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
252
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
253 /* Generate score for loan */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
254 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
255 _score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - c->current_loan);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
256 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
257
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
258 /* Now we calculate the score for each item.. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
259 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
260 int total_score = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
261 int s;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
262 score = 0;
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
263 for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) {
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
264 /* Skip the total */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
265 if (i == SCORE_TOTAL) continue;
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
266 /* Check the score */
7922
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7860
diff changeset
267 s = Clamp(_score_part[owner][i], 0, _score_info[i].needed) * _score_info[i].score / _score_info[i].needed;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
268 score += s;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
269 total_score += _score_info[i].score;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
270 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
271
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
272 _score_part[owner][SCORE_TOTAL] = score;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
273
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
274 /* We always want the score scaled to SCORE_MAX (1000) */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
275 if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
276 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
277
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
278 if (update) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
279 c->old_economy[0].performance_history = score;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
280 UpdateCompanyHQ(c, score);
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
281 c->old_economy[0].company_value = CalculateCompanyValue(c);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
282 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
283
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
284 InvalidateWindow(WC_PERFORMANCE_DETAIL, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
285 return score;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
286 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
287
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
288 /* use INVALID_OWNER as new_owner to delete the company. */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
289 void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
290 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
291 Town *t;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
292 CompanyID old = _current_company;
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
293
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
294 assert(old_owner != new_owner);
6405
3f3b30a14c26 (svn r9541) -Codechange: Safeguard the company-buying routines so that the buying player and the bought player need to be two different entities
celestar <celestar@openttd.org>
parents: 6403
diff changeset
295
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
296 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
297 Company *c;
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
298 uint i;
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
299
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
300 /* See if the old_owner had shares in other companies */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
301 _current_company = old_owner;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
302 FOR_ALL_COMPANIES(c) {
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
303 for (i = 0; i < 4; i++) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
304 if (c->share_owners[i] == old_owner) {
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
305 /* Sell his shares */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
306 CommandCost res = DoCommand(0, c->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
307 /* Because we are in a DoCommand, we can't just execute an other one and
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
308 * expect the money to be removed. We need to do it ourself! */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
309 SubtractMoneyFromCompany(res);
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
310 }
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
311 }
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
312 }
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
313
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
314 /* Sell all the shares that people have on this company */
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
315 c = Company::Get(old_owner);
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
316 for (i = 0; i < 4; i++) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
317 _current_company = c->share_owners[i];
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
318 if (_current_company != INVALID_OWNER) {
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
319 /* Sell the shares */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
320 CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
321 /* Because we are in a DoCommand, we can't just execute an other one and
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
322 * expect the money to be removed. We need to do it ourself! */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
323 SubtractMoneyFromCompany(res);
6403
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
324 }
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
325 }
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
326 }
8c022dabd50e (svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents: 6369
diff changeset
327
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
328 _current_company = old_owner;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
329
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
330 /* Temporarily increase the company's money, to be sure that
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
331 * removing his/her property doesn't fail because of lack of money.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
332 * Not too drastically though, because it could overflow */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
333 if (new_owner == INVALID_OWNER) {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
334 Company::Get(old_owner)->money = UINT64_MAX >> 2; // jackpot ;p
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
335 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
336
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
337 Subsidy *s;
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
338 FOR_ALL_SUBSIDIES(s) {
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
339 if (s->awarded == old_owner) {
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
340 if (new_owner == INVALID_OWNER) {
12669
406f4ae1e2ca (svn r17124) -Codechange: store subsidies in a pool (instead of an array)
smatz <smatz@openttd.org>
parents: 12658
diff changeset
341 delete s;
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
342 } else {
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
343 s->awarded = new_owner;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
344 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
345 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
346 }
12669
406f4ae1e2ca (svn r17124) -Codechange: store subsidies in a pool (instead of an array)
smatz <smatz@openttd.org>
parents: 12658
diff changeset
347 if (new_owner == INVALID_OWNER) RebuildSubsidisedSourceAndDestinationCache();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
348
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
349 /* Take care of rating in towns */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
350 FOR_ALL_TOWNS(t) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
351 /* If a company takes over, give the ratings to that company. */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
352 if (new_owner != INVALID_OWNER) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
353 if (HasBit(t->have_ratings, old_owner)) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
354 if (HasBit(t->have_ratings, new_owner)) {
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
355 /* use max of the two ratings. */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
356 t->ratings[new_owner] = max(t->ratings[new_owner], t->ratings[old_owner]);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
357 } else {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
358 SetBit(t->have_ratings, new_owner);
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
359 t->ratings[new_owner] = t->ratings[old_owner];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
360 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
361 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
362 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
363
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
364 /* Reset the ratings for the old owner */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
365 t->ratings[old_owner] = RATING_INITIAL;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
366 ClrBit(t->have_ratings, old_owner);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
367 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
368
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
369 {
10498
730117b172e1 (svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents: 10495
diff changeset
370 FreeUnitIDGenerator unitidgen[] = {
730117b172e1 (svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents: 10495
diff changeset
371 FreeUnitIDGenerator(VEH_TRAIN, new_owner), FreeUnitIDGenerator(VEH_ROAD, new_owner),
730117b172e1 (svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents: 10495
diff changeset
372 FreeUnitIDGenerator(VEH_SHIP, new_owner), FreeUnitIDGenerator(VEH_AIRCRAFT, new_owner)
730117b172e1 (svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents: 10495
diff changeset
373 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
374
10498
730117b172e1 (svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents: 10495
diff changeset
375 Vehicle *v;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
376 FOR_ALL_VEHICLES(v) {
10492
28fa021b003c (svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents: 10479
diff changeset
377 if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
378 if (new_owner == INVALID_OWNER) {
10492
28fa021b003c (svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents: 10479
diff changeset
379 if (v->Previous() == NULL) delete v;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
380 } else {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
381 v->owner = new_owner;
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11056
diff changeset
382 v->colourmap = PAL_NONE;
12383
3c7e93b91c73 (svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents: 12319
diff changeset
383 if (v->IsEngineCountable()) Company::Get(new_owner)->num_engines[v->engine_type]++;
10498
730117b172e1 (svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents: 10495
diff changeset
384 if (v->IsPrimaryVehicle()) v->unitnumber = unitidgen[v->type].NextID();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
385 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
386 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
387 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
388 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
389
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
390 /* Change ownership of tiles */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
391 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
392 TileIndex tile = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
393 do {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
394 ChangeTileOwner(tile, old_owner, new_owner);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
395 } while (++tile != MapSize());
8200
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
396
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
397 if (new_owner != INVALID_OWNER) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
398 /* Update all signals because there can be new segment that was owned by two companies
8342
441cda3cfbdb (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents: 8306
diff changeset
399 * and signals were not propagated
441cda3cfbdb (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents: 8306
diff changeset
400 * Similiar with crossings - it is needed to bar crossings that weren't before
441cda3cfbdb (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents: 8306
diff changeset
401 * because of different owner of crossing and approaching train */
8200
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
402 tile = 0;
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
403
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
404 do {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
405 if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, new_owner) && HasSignals(tile)) {
8200
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
406 TrackBits tracks = GetTrackBits(tile);
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
407 do { // there may be two tracks with signals for TRACK_BIT_HORZ and TRACK_BIT_VERT
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
408 Track track = RemoveFirstTrack(&tracks);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
409 if (HasSignalOnTrack(tile, track)) AddTrackToSignalBuffer(tile, track, new_owner);
8200
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
410 } while (tracks != TRACK_BIT_NONE);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
411 } else if (IsLevelCrossingTile(tile) && IsTileOwner(tile, new_owner)) {
8342
441cda3cfbdb (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents: 8306
diff changeset
412 UpdateLevelCrossing(tile);
8200
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
413 }
f7f49622b3e0 (svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents: 8186
diff changeset
414 } while (++tile != MapSize());
8347
a83dd50f52f9 (svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz <smatz@openttd.org>
parents: 8342
diff changeset
415 }
8306
ea2c123b3655 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz <smatz@openttd.org>
parents: 8302
diff changeset
416
8347
a83dd50f52f9 (svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz <smatz@openttd.org>
parents: 8342
diff changeset
417 /* update signals in buffer */
a83dd50f52f9 (svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz <smatz@openttd.org>
parents: 8342
diff changeset
418 UpdateSignalsInBuffer();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
419 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
420
11234
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
421 /* convert owner of stations (including deleted ones, but excluding buoys) */
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
422 Station *st;
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
423 FOR_ALL_STATIONS(st) {
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
424 if (st->owner == old_owner) {
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
425 /* if a company goes bankrupt, set owner to OWNER_NONE so the sign doesn't disappear immediately
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
426 * also, drawing station window would cause reading invalid company's colour */
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
427 st->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
428 }
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
429 }
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
430
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
431 /* do the same for waypoints (we need to do this here so deleted waypoints are converted too) */
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
432 Waypoint *wp;
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
433 FOR_ALL_WAYPOINTS(wp) {
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
434 if (wp->owner == old_owner) {
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
435 wp->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
436 }
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
437 }
6ebdffe6e5e6 (svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents: 11221
diff changeset
438
9058
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
439 /* In all cases clear replace engine rules.
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
440 * Even if it was copied, it could interfere with new owner's rules */
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
441 RemoveAllEngineReplacementForCompany(Company::Get(old_owner));
9058
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
442
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
443 if (new_owner == INVALID_OWNER) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
444 RemoveAllGroupsForCompany(old_owner);
9058
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
445 } else {
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
446 Group *g;
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
447 FOR_ALL_GROUPS(g) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
448 if (g->owner == old_owner) g->owner = new_owner;
9058
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
449 }
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
450 }
c73011639858 (svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents: 9043
diff changeset
451
10158
c429fccf1aea (svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents: 10146
diff changeset
452 Sign *si;
c429fccf1aea (svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents: 10146
diff changeset
453 FOR_ALL_SIGNS(si) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
454 if (si->owner == old_owner) si->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
10158
c429fccf1aea (svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents: 10146
diff changeset
455 }
c429fccf1aea (svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents: 10146
diff changeset
456
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11056
diff changeset
457 /* Change colour of existing windows */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
458 if (new_owner != INVALID_OWNER) ChangeWindowOwner(old_owner, new_owner);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
459
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
460 _current_company = old;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
461
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
462 MarkWholeScreenDirty();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
463 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
464
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
465 static void ChangeNetworkOwner(Owner current_owner, Owner new_owner)
6262
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
466 {
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
467 #ifdef ENABLE_NETWORK
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
468 if (!_networking) return;
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
469
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
470 if (current_owner == _local_company) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
471 SetLocalCompany(new_owner);
6262
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
472 }
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
473
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
474 if (!_network_server) return;
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
475
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
476 NetworkServerChangeOwner(current_owner, new_owner);
6262
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
477 #endif /* ENABLE_NETWORK */
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
478 }
a457647cd27d (svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents: 6259
diff changeset
479
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
480 static void CompanyCheckBankrupt(Company *c)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
481 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
482 /* If the company has money again, it does not go bankrupt */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
483 if (c->money >= 0) {
12853
a1d8c582ef59 (svn r17343) -Codechange: it's bankruptcy, not bankrupcy, according to my Oxford Dictionary of English and Merriam-Webster.
rubidium <rubidium@openttd.org>
parents: 12852
diff changeset
484 c->quarters_of_bankruptcy = 0;
12852
c8f80b97fd61 (svn r17342) -Fix: reset bankruptcy checks when bankruptcy has been averted and don't set an unused timeout with a magic number
rubidium <rubidium@openttd.org>
parents: 12851
diff changeset
485 c->bankrupt_asked = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
486 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
487 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
488
12853
a1d8c582ef59 (svn r17343) -Codechange: it's bankruptcy, not bankrupcy, according to my Oxford Dictionary of English and Merriam-Webster.
rubidium <rubidium@openttd.org>
parents: 12852
diff changeset
489 c->quarters_of_bankruptcy++;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
490
9658
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
491 CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
492 cni->FillData(c);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
493
12853
a1d8c582ef59 (svn r17343) -Codechange: it's bankruptcy, not bankrupcy, according to my Oxford Dictionary of English and Merriam-Webster.
rubidium <rubidium@openttd.org>
parents: 12852
diff changeset
494 switch (c->quarters_of_bankruptcy) {
10495
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
495 case 0:
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
496 case 1:
9658
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
497 free(cni);
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
498 break;
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
499
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
500 case 2:
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11376
diff changeset
501 SetDParam(0, STR_NEWS_COMPANY_IN_TROUBLE_TITLE);
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11376
diff changeset
502 SetDParam(1, STR_NEWS_COMPANY_IN_TROUBLE_DESCRIPTION);
9658
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
503 SetDParamStr(2, cni->company_name);
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
504 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_TROUBLE, cni);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10647
diff changeset
505 AI::BroadcastNewEvent(new AIEventCompanyInTrouble(c->index));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
506 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
507 case 3: {
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
508 /* Check if the company has any value.. if not, declare it bankrupt
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
509 * right now */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
510 Money val = CalculateCompanyValue(c);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
511 if (val > 0) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
512 c->bankrupt_value = val;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
513 c->bankrupt_asked = 1 << c->index; // Don't ask the owner
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
514 c->bankrupt_timeout = 0;
9658
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
515 free(cni);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
516 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
517 }
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
518 /* Else, falltrue to case 4... */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
519 }
10495
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
520 default:
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
521 case 4:
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
522 if (!_networking && _local_company == c->index) {
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
523 /* If we are in offline mode, leave the company playing. Eg. there
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
524 * is no THE-END, otherwise mark the client as spectator to make sure
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
525 * he/she is no long in control of this company. However... when you
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
526 * join another company (cheat) the "unowned" company can bankrupt. */
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
527 c->bankrupt_asked = MAX_UVALUE(CompanyMask);
12851
a398faeb024e (svn r17341) -Fix: memory leak when trying to bankrupt the local company
rubidium <rubidium@openttd.org>
parents: 12826
diff changeset
528 free(cni);
10495
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
529 break;
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
530 }
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
531
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
532 /* Close everything the owner has open */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
533 DeleteCompanyWindows(c->index);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
534
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
535 /* Show bankrupt news */
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11376
diff changeset
536 SetDParam(0, STR_NEWS_COMPANY_BANKRUPT_TITLE);
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11376
diff changeset
537 SetDParam(1, STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION);
9658
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
538 SetDParamStr(2, cni->company_name);
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
539 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_BANKRUPT, cni);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
540
10495
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
541 /* Remove the company */
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
542 ChangeNetworkOwner(c->index, COMPANY_SPECTATOR);
dd7d08e0ff23 (svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents: 10493
diff changeset
543 ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
544
12143
20abba1d6d18 (svn r16559) -Codechange: introduce Company::IsValidAiID() and Company::IsValidHumanID(), don't use IsHumanCompany() where possible
smatz <smatz@openttd.org>
parents: 12114
diff changeset
545 if (c->is_ai) AI::Stop(c->index);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
546
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10647
diff changeset
547 CompanyID c_index = c->index;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
548 delete c;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10647
diff changeset
549 AI::BroadcastNewEvent(new AIEventCompanyBankrupt(c_index));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
550 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
551 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
552
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
553 static void CompaniesGenStatistics()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
554 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
555 Station *st;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
556 Company *c;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
557
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
558 FOR_ALL_STATIONS(st) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
559 _current_company = st->owner;
8230
5b61305fcdd4 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents: 8224
diff changeset
560 CommandCost cost(EXPENSES_PROPERTY, _price.station_value >> 1);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
561 SubtractMoneyFromCompany(cost);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
562 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
563
10080
1ea2b6087381 (svn r14254) -Codechange: Code style and breathing room
belugas <belugas@openttd.org>
parents: 9950
diff changeset
564 if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month))
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
565 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
566
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
567 FOR_ALL_COMPANIES(c) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
568 memmove(&c->old_economy[1], &c->old_economy[0], sizeof(c->old_economy) - sizeof(c->old_economy[0]));
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
569 c->old_economy[0] = c->cur_economy;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
570 memset(&c->cur_economy, 0, sizeof(c->cur_economy));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
571
12615
5f44b757d251 (svn r17058) -Codechange: magic numbers removal.
belugas <belugas@openttd.org>
parents: 12594
diff changeset
572 if (c->num_valid_stat_ent != MAX_HISTORY_MONTHS) c->num_valid_stat_ent++;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
573
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
574 UpdateCompanyRatingAndValue(c, true);
12046
da0c682ff327 (svn r16453) -Fix: Move some code around so a company is no longer used after deleting it
yexo <yexo@openttd.org>
parents: 12010
diff changeset
575 if (c->block_preview != 0) c->block_preview--;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
576 CompanyCheckBankrupt(c);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
577 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
578
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
579 InvalidateWindow(WC_INCOME_GRAPH, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
580 InvalidateWindow(WC_OPERATING_PROFIT, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
581 InvalidateWindow(WC_DELIVERED_CARGO, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
582 InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
583 InvalidateWindow(WC_COMPANY_VALUE, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
584 InvalidateWindow(WC_COMPANY_LEAGUE, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
585 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
586
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
587 /**
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
588 * Add monthly inflation
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
589 * @param check_year Shall the inflation get stopped after 170 years?
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
590 */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
591 void AddInflation(bool check_year)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
592 {
7244
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
593 /* The cargo payment inflation differs from the normal inflation, so the
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
594 * relative amount of money you make with a transport decreases slowly over
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
595 * the 170 years. After a few hundred years we reach a level in which the
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
596 * games will become unplayable as the maximum income will be less than
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
597 * the minimum running cost.
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
598 *
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
599 * Furthermore there are a lot of inflation related overflows all over the
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
600 * place. Solving them is hardly possible because inflation will always
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
601 * reach the overflow threshold some day. So we'll just perform the
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
602 * inflation mechanism during the first 170 years (the amount of years that
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
603 * one had in the original TTD) and stop doing the inflation after that
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
604 * because it only causes problems that can't be solved nicely and the
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
605 * inflation doesn't add anything after that either; it even makes playing
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
606 * it impossible due to the diverging cost and income rates.
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
607 */
9717
57549f1e5133 (svn r13836) -Fix [FS#2074]: Automatically recalculate inflation if NewGRFs are changed and cargo types are added, so that cargo payment rates are correct.
peter1138 <peter1138@openttd.org>
parents: 9659
diff changeset
608 if (check_year && (_cur_year - _settings_game.game_creation.starting_year) >= (ORIGINAL_MAX_YEAR - ORIGINAL_BASE_YEAR)) return;
7244
00f3d8da22e4 (svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents: 7229
diff changeset
609
6119
f319793f0549 (svn r8855) -Fix
tron <tron@openttd.org>
parents: 6111
diff changeset
610 /* Approximation for (100 + infl_amount)% ** (1 / 12) - 100%
f319793f0549 (svn r8855) -Fix
tron <tron@openttd.org>
parents: 6111
diff changeset
611 * scaled by 65536
f319793f0549 (svn r8855) -Fix
tron <tron@openttd.org>
parents: 6111
diff changeset
612 * 12 -> months per year
f319793f0549 (svn r8855) -Fix
tron <tron@openttd.org>
parents: 6111
diff changeset
613 * This is only a good approxiamtion for small values
f319793f0549 (svn r8855) -Fix
tron <tron@openttd.org>
parents: 6111
diff changeset
614 */
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
615 _economy.inflation_prices += min((_economy.inflation_prices * _economy.infl_amount * 54) >> 16, MAX_INFLATION);
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
616 _economy.inflation_payment += min((_economy.inflation_payment * _economy.infl_amount_pr * 54) >> 16, MAX_INFLATION);
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
617 }
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
618
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
619 /**
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
620 * Computes all prices, payments and maximum loan.
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
621 */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
622 void RecomputePrices()
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
623 {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
624 /* Setup maximum loan */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
625 _economy.max_loan = (_settings_game.difficulty.max_loan * _economy.inflation_prices >> 16) / 50000 * 50000;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
626
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
627 assert_compile(sizeof(_price) == NUM_PRICES * sizeof(Money));
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
628
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
629 /* Setup price bases */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
630 for (uint i = 0; i < NUM_PRICES; i++) {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
631 Money price = _price_base_specs[i].start_price;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
632
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
633 /* Apply difficulty settings */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
634 uint mod = 1;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
635 switch (_price_base_specs[i].category) {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
636 case PCAT_RUNNING:
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
637 mod = _settings_game.difficulty.vehicle_costs;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
638 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
639
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
640 case PCAT_CONSTRUCTION:
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
641 mod = _settings_game.difficulty.construction_cost;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
642 break;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
643
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
644 default: break;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
645 }
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
646 if (mod < 1) {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
647 price = price * 3 >> 2;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
648 } else if (mod > 1) {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
649 price = price * 9 >> 3;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
650 }
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
651
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
652 /* Apply inflation */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
653 price = (int64)price * _economy.inflation_prices;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
654
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
655 /* Apply newgrf modifiers, and remove fractional part of inflation */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
656 int shift = _price_base_multiplier[i] - 8 - 16;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
657 if (shift >= 0) {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
658 price <<= shift;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
659 } else {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
660 price >>= -shift;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
661 }
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
662
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
663 /* Store value */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
664 ((Money *)&_price)[i] = price;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
665 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
666
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
667 /* Setup cargo payment */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
668 memset(_cargo_payment_rates, 0, sizeof(_cargo_payment_rates));
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
669 const CargoSpec *cs;
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
670 FOR_ALL_CARGOSPECS(cs) {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
671 _cargo_payment_rates[cs->Index()] = ((int64)cs->initial_payment * _economy.inflation_payment) >> 16;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
672 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
673
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
674 InvalidateWindowClasses(WC_BUILD_VEHICLE);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
675 InvalidateWindowClasses(WC_REPLACE_VEHICLE);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
676 InvalidateWindowClasses(WC_VEHICLE_DETAILS);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
677 InvalidateWindow(WC_PAYMENT_RATES, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
678 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
679
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
680 static void CompaniesPayInterest()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
681 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
682 const Company *c;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
683
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
684 FOR_ALL_COMPANIES(c) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
685 _current_company = c->index;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
686
10568
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
687 /* Over a year the paid interest should be "loan * interest percentage",
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
688 * but... as that number is likely not dividable by 12 (pay each month),
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
689 * one needs to account for that in the monthly fee calculations.
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
690 * To easily calculate what one should pay "this" month, you calculate
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
691 * what (total) should have been paid up to this month and you substract
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
692 * whatever has been paid in the previous months. This will mean one month
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
693 * it'll be a bit more and the other it'll be a bit less than the average
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
694 * monthly fee, but on average it will be exact. */
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
695 Money yearly_fee = c->current_loan * _economy.interest_rate / 100;
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
696 Money up_to_previous_month = yearly_fee * _cur_month / 12;
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
697 Money up_to_this_month = yearly_fee * (_cur_month + 1) / 12;
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
698
35171d182079 (svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
699 SubtractMoneyFromCompany(CommandCost(EXPENSES_LOAN_INT, up_to_this_month - up_to_previous_month));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
700
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
701 SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, _price.station_value >> 2));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
702 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
703 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
704
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6227
diff changeset
705 static void HandleEconomyFluctuations()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
706 {
12933
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
707 if (_settings_game.difficulty.economy != 0) {
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
708 /* When economy is Fluctuating, decrease counter */
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
709 _economy.fluct--;
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
710 } else if (_economy.fluct <= 0) {
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
711 /* When it's Steady and we are in recession, end it now */
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
712 _economy.fluct = -12;
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
713 } else {
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
714 /* No need to do anything else in other cases */
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
715 return;
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
716 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
717
12933
23e2eb186b4d (svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents: 12927
diff changeset
718 if (_economy.fluct == 0) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
719 _economy.fluct = -(int)GB(Random(), 0, 2);
12010
d0bf08a7c260 (svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents: 12001
diff changeset
720 AddNewsItem(STR_NEWS_BEGIN_OF_RECESSION, NS_ECONOMY);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
721 } else if (_economy.fluct == -12) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
722 _economy.fluct = GB(Random(), 0, 8) + 312;
12010
d0bf08a7c260 (svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents: 12001
diff changeset
723 AddNewsItem(STR_NEWS_END_OF_RECESSION, NS_ECONOMY);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
724 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
725 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
726
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
727
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
728 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
729 * Reset changes to the price base multipliers.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
730 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6227
diff changeset
731 void ResetPriceBaseMultipliers()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
732 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
733 uint i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
734
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
735 /* 8 means no multiplier. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
736 for (i = 0; i < NUM_PRICES; i++)
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
737 _price_base_multiplier[i] = 8;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
738 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
739
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
740 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
741 * Change a price base by the given factor.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
742 * The price base is altered by factors of two, with an offset of 8.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
743 * NewBaseCost = OldBaseCost * 2^(n-8)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
744 * @param price Index of price base to change.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
745 * @param factor Amount to change by.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
746 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
747 void SetPriceBaseMultiplier(uint price, byte factor)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
748 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
749 assert(price < NUM_PRICES);
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
750 _price_base_multiplier[price] = min(factor, MAX_PRICE_MODIFIER);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
751 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
752
10146
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
753 /**
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
754 * Initialize the variables that will maintain the daily industry change system.
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
755 * @param init_counter specifies if the counter is required to be initialized
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
756 */
10571
b6779abf2e96 (svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents: 10568
diff changeset
757 void StartupIndustryDailyChanges(bool init_counter)
10146
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
758 {
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
759 uint map_size = MapLogX() + MapLogY();
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
760 /* After getting map size, it needs to be scaled appropriately and divided by 31,
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
761 * which stands for the days in a month.
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
762 * Using just 31 will make it so that a monthly reset (based on the real number of days of that month)
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
763 * would not be needed.
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
764 * Since it is based on "fractionnal parts", the leftover days will not make much of a difference
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
765 * on the overall total number of changes performed */
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
766 _economy.industry_daily_increment = (1 << map_size) / 31;
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
767
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
768 if (init_counter) {
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
769 /* A new game or a savegame from an older version will require the counter to be initialized */
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
770 _economy.industry_daily_change_counter = 0;
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
771 }
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
772 }
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
773
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6227
diff changeset
774 void StartupEconomy()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
775 {
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
776 _economy.interest_rate = _settings_game.difficulty.initial_interest;
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
777 _economy.infl_amount = _settings_game.difficulty.initial_interest;
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
778 _economy.infl_amount_pr = max(0, _settings_game.difficulty.initial_interest - 1);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
779 _economy.fluct = GB(Random(), 0, 8) + 168;
10146
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
780
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
781 /* Set up prices */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
782 RecomputePrices();
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
783
10146
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
784 StartupIndustryDailyChanges(true); // As we are starting a new game, initialize the counter too
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 10080
diff changeset
785
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
786 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
787
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
788 /**
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
789 * Resets economy to initial values
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
790 */
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
791 void InitializeEconomy()
9717
57549f1e5133 (svn r13836) -Fix [FS#2074]: Automatically recalculate inflation if NewGRFs are changed and cargo types are added, so that cargo payment rates are correct.
peter1138 <peter1138@openttd.org>
parents: 9659
diff changeset
792 {
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
793 _economy.inflation_prices = _economy.inflation_payment = 1 << 16;
9717
57549f1e5133 (svn r13836) -Fix [FS#2074]: Automatically recalculate inflation if NewGRFs are changed and cargo types are added, so that cargo payment rates are correct.
peter1138 <peter1138@openttd.org>
parents: 9659
diff changeset
794 }
8626
e6ad3a9cdfcb (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents: 8624
diff changeset
795
e6ad3a9cdfcb (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents: 8624
diff changeset
796 Money GetPriceByIndex(uint8 index)
e6ad3a9cdfcb (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents: 8624
diff changeset
797 {
e6ad3a9cdfcb (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents: 8624
diff changeset
798 if (index > NUM_PRICES) return 0;
e6ad3a9cdfcb (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents: 8624
diff changeset
799
e6ad3a9cdfcb (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents: 8624
diff changeset
800 return ((Money*)&_price)[index];
e6ad3a9cdfcb (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents: 8624
diff changeset
801 }
e6ad3a9cdfcb (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents: 8624
diff changeset
802
6954
3aa54e38394f (svn r10209) -Fix/Codechange: forgot a few changes of int32 -> Money in the previous commit
rubidium <rubidium@openttd.org>
parents: 6953
diff changeset
803 Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
804 {
12415
6a77d1df56e2 (svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents: 12384
diff changeset
805 const CargoSpec *cs = CargoSpec::Get(cargo_type);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
806
6458
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
807 /* Use callback to calculate cargo profit, if available */
7928
4e8dfd103163 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7926
diff changeset
808 if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) {
6458
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
809 uint32 var18 = min(dist, 0xFFFF) | (min(num_pieces, 0xFF) << 16) | (transit_days << 24);
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
810 uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs);
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
811 if (callback != CALLBACK_FAILED) {
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
812 int result = GB(callback, 0, 14);
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
813
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
814 /* Simulate a 15 bit signed value */
7928
4e8dfd103163 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7926
diff changeset
815 if (HasBit(callback, 14)) result = 0x4000 - result;
6458
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
816
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
817 /* "The result should be a signed multiplier that gets multiplied
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
818 * by the amount of cargo moved and the price factor, then gets
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
819 * divided by 8192." */
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
820 return result * num_pieces * _cargo_payment_rates[cargo_type] / 8192;
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
821 }
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
822 }
57cfff4ac608 (svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents: 6453
diff changeset
823
7328
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
824 /* zero the distance (thus income) if it's the bank and very short transport. */
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
825 if (_settings_game.game_creation.landscape == LT_TEMPERATE && cs->label == 'VALU' && dist < 10) return 0;
7328
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
826
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
827
7328
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
828 static const int MIN_TIME_FACTOR = 31;
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
829 static const int MAX_TIME_FACTOR = 255;
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
830
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
831 const int days1 = cs->transit_days[0];
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
832 const int days2 = cs->transit_days[1];
10417
844e13224bd1 (svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
smatz <smatz@openttd.org>
parents: 10297
diff changeset
833 const int days_over_days1 = max( transit_days - days1, 0);
844e13224bd1 (svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
smatz <smatz@openttd.org>
parents: 10297
diff changeset
834 const int days_over_days2 = max(days_over_days1 - days2, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
835
7328
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
836 /*
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
837 * The time factor is calculated based on the time it took
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
838 * (transit_days) compared two cargo-depending values. The
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
839 * range is divided into three parts:
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
840 *
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
841 * - constant for fast transits
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
842 * - linear decreasing with time with a slope of -1 for medium transports
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
843 * - linear decreasing with time with a slope of -2 for slow transports
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
844 *
35cf803fe4b9 (svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents: 7287
diff changeset
845 */
10417
844e13224bd1 (svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
smatz <smatz@openttd.org>
parents: 10297
diff changeset
846 const int time_factor = max(MAX_TIME_FACTOR - days_over_days1 - days_over_days2, MIN_TIME_FACTOR);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
847
7926
e8ce9f6469d1 (svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
848 return BigMulS(dist * time_factor * num_pieces, _cargo_payment_rates[cargo_type], 21);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
849 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
850
12267
fe4287ad4243 (svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents: 12266
diff changeset
851 /** The industries we've currently brought cargo to. */
fe4287ad4243 (svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents: 12266
diff changeset
852 static SmallIndustryList _cargo_delivery_destinations;
12239
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
853
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
854 /**
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
855 * Transfer goods from station to industry.
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
856 * All cargo is delivered to the nearest (Manhattan) industry to the station sign, which is inside the acceptance rectangle and actually accepts the cargo.
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
857 * @param st The station that accepted the cargo
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
858 * @param cargo_type Type of cargo delivered
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
859 * @param nun_pieces Amount of cargo delivered
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
860 */
12267
fe4287ad4243 (svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents: 12266
diff changeset
861 static void DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, int num_pieces)
12239
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
862 {
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
863 /* Find the nearest industrytile to the station sign inside the catchment area, whose industry accepts the cargo.
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
864 * This fails in three cases:
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
865 * 1) The station accepts the cargo because there are enough houses around it accepting the cargo.
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
866 * 2) The industries in the catchment area temporarily reject the cargo, and the daily station loop has not yet updated station acceptance.
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
867 * 3) The results of callbacks CBID_INDUSTRY_REFUSE_CARGO and CBID_INDTILE_CARGO_ACCEPTANCE are inconsistent. (documented behaviour)
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
868 */
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
869
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
870 for (uint i = 0; i < st->industries_near.Length(); i++) {
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
871 Industry *ind = st->industries_near[i];
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
872 const IndustrySpec *indspec = GetIndustrySpec(ind->type);
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
873
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
874 uint cargo_index;
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
875 for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
876 if (cargo_type == ind->accepts_cargo[cargo_index]) break;
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
877 }
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
878 /* Check if matching cargo has been found */
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
879 if (cargo_index >= lengthof(ind->accepts_cargo)) continue;
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
880
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
881 /* Check if industry temporarily refuses acceptance */
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
882 if (HasBit(indspec->callback_flags, CBM_IND_REFUSE_CARGO)) {
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
883 uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile), ind, ind->type, ind->xy);
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
884 if (res == 0) continue;
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
885 }
7165
c3b231638b80 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents: 7124
diff changeset
886
12267
fe4287ad4243 (svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents: 12266
diff changeset
887 /* Insert the industry into _cargo_delivery_destinations, if not yet contained */
fe4287ad4243 (svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents: 12266
diff changeset
888 _cargo_delivery_destinations.Include(ind);
12239
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
889
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
890 ind->incoming_cargo_waiting[cargo_index] = min(num_pieces + ind->incoming_cargo_waiting[cargo_index], 0xFFFF);
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
891
b1d30d9d4025 (svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents: 12228
diff changeset
892 return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
893 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
894 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
895
10450
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
896 /**
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
897 * Delivers goods to industries/towns and calculates the payment
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
898 * @param num_pieces amount of cargo delivered
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
899 * @param dest Station the cargo has been unloaded
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
900 * @param source_tile The origin of the cargo for distance calculation
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
901 * @param days_in_transit Travel time
12266
c9e7d3ec5c1a (svn r16681) -Codechange: only resolve the company once for vehicle payment instead of each time a cargo packet is delivered
rubidium <rubidium@openttd.org>
parents: 12265
diff changeset
902 * @param company The company delivering the cargo
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
903 * @param src_type Type of source of cargo (industry, town, headquarters)
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
904 * @param src Index of source of cargo
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
905 * @return Revenue for delivering cargo
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
906 * @note The cargo is just added to the stockpile of the industry. It is due to the caller to trigger the industry's production machinery
10450
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
907 */
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
908 static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, TileIndex source_tile, byte days_in_transit, Company *company, SourceType src_type, SourceID src)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
909 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
910 assert(num_pieces > 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
911
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
912 /* Update company statistics */
12266
c9e7d3ec5c1a (svn r16681) -Codechange: only resolve the company once for vehicle payment instead of each time a cargo packet is delivered
rubidium <rubidium@openttd.org>
parents: 12265
diff changeset
913 company->cur_economy.delivered_cargo += num_pieces;
c9e7d3ec5c1a (svn r16681) -Codechange: only resolve the company once for vehicle payment instead of each time a cargo packet is delivered
rubidium <rubidium@openttd.org>
parents: 12265
diff changeset
914 SetBit(company->cargo_types, cargo_type);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
915
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
916 const Station *st = Station::Get(dest);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
917
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
918 /* Increase town's counter for some special goods types */
12415
6a77d1df56e2 (svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents: 12384
diff changeset
919 const CargoSpec *cs = CargoSpec::Get(cargo_type);
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
920 if (cs->town_effect == TE_FOOD) st->town->new_act_food += num_pieces;
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
921 if (cs->town_effect == TE_WATER) st->town->new_act_water += num_pieces;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
922
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
923 /* Give the goods to the industry. */
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
924 DeliverGoodsToIndustry(st, cargo_type, num_pieces);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
925
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
926 /* Determine profit */
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
927 Money profit = GetTransportedGoodsIncome(num_pieces, DistanceManhattan(source_tile, st->xy), days_in_transit, cargo_type);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
928
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
929 /* Modify profit if a subsidy is in effect */
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
930 if (CheckSubsidised(cargo_type, company->index, src_type, src, st)) {
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
931 switch (_settings_game.difficulty.subsidy_multiplier) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
932 case 0: profit += profit >> 1; break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
933 case 1: profit *= 2; break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
934 case 2: profit *= 3; break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
935 default: profit *= 4; break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
936 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
937 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
938
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
939 return profit;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
940 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
941
6559
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
942 /**
10450
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
943 * Inform the industry about just delivered cargo
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
944 * DeliverGoodsToIndustry() silently incremented incoming_cargo_waiting, now it is time to do something with the new cargo.
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
945 * @param i The industry to process
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
946 */
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
947 static void TriggerIndustryProduction(Industry *i)
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
948 {
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
949 const IndustrySpec *indspec = GetIndustrySpec(i->type);
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
950 uint16 callback = indspec->callback_flags;
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
951
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
952 i->was_cargo_delivered = true;
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
953 i->last_cargo_accepted_at = _date;
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
954
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
955 if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) {
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
956 if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) {
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
957 IndustryProductionCallback(i, 0);
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
958 } else {
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
959 InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
960 }
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
961 } else {
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
962 for (uint cargo_index = 0; cargo_index < lengthof(i->incoming_cargo_waiting); cargo_index++) {
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
963 uint cargo_waiting = i->incoming_cargo_waiting[cargo_index];
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
964 if (cargo_waiting == 0) continue;
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
965
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
966 i->produced_cargo_waiting[0] = min(i->produced_cargo_waiting[0] + (cargo_waiting * indspec->input_cargo_multiplier[cargo_index][0] / 256), 0xFFFF);
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
967 i->produced_cargo_waiting[1] = min(i->produced_cargo_waiting[1] + (cargo_waiting * indspec->input_cargo_multiplier[cargo_index][1] / 256), 0xFFFF);
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
968
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
969 i->incoming_cargo_waiting[cargo_index] = 0;
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
970 }
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
971 }
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
972
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
973 TriggerIndustry(i, INDUSTRY_TRIGGER_RECEIVED_CARGO);
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
974 StartStopIndustryTileAnimation(i, IAT_INDUSTRY_RECEIVED_CARGO);
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
975 }
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
976
e3e68b2c143c (svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents: 10419
diff changeset
977 /**
12268
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
978 * Makes us a new cargo payment helper.
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
979 * @param front The front of the train
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
980 * @param destinations List to add the destinations of 'our' cargo to
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
981 */
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
982 CargoPayment::CargoPayment(Vehicle *front) :
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
983 front(front),
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
984 current_station(front->last_station_visited)
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
985 {
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
986 }
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
987
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
988 CargoPayment::~CargoPayment()
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
989 {
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
990 if (this->CleaningPool()) return;
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
991
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
992 this->front->cargo_payment = NULL;
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
993
12268
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
994 if (this->visual_profit == 0) return;
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
995
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
996 CompanyID old_company = _current_company;
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
997 _current_company = this->front->owner;
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
998
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
999 SubtractMoneyFromCompany(CommandCost(this->front->GetExpenseType(true), -this->route_profit));
12278
492621950e1a (svn r16693) -Fix [FS#3004] (r16883): cargo income was not added to the vehicle's profit.
rubidium <rubidium@openttd.org>
parents: 12268
diff changeset
1000 this->front->profit_this_year += this->visual_profit << 8;
12268
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1001
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1002 if (this->route_profit != 0) {
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1003 if (IsLocalCompany() && !PlayVehicleSound(this->front, VSE_LOAD_UNLOAD)) {
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1004 SndPlayVehicleFx(SND_14_CASHTILL, this->front);
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1005 }
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1006
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1007 ShowCostOrIncomeAnimation(this->front->x_pos, this->front->y_pos, this->front->z_pos, -this->visual_profit);
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1008 } else {
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1009 ShowFeederIncomeAnimation(this->front->x_pos, this->front->y_pos, this->front->z_pos, this->visual_profit);
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1010 }
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1011
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1012 _current_company = old_company;
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1013 }
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1014
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1015 /**
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1016 * Handle payment for final delivery of the given cargo packet.
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1017 * @param cp The cargo packet to pay for.
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1018 * @param count The number of packets to pay for.
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1019 */
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1020 void CargoPayment::PayFinalDelivery(CargoPacket *cp, uint count)
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1021 {
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1022 if (this->owner == NULL) {
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1023 this->owner = Company::Get(this->front->owner);
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1024 }
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1025
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1026 /* Handle end of route payment */
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12652
diff changeset
1027 Money profit = DeliverGoods(count, this->ct, this->current_station, cp->source_xy, cp->days_in_transit, this->owner, cp->source_type, cp->source_id);
12268
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1028 this->route_profit += profit;
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1029
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1030 /* The vehicle's profit is whatever route profit there is minus feeder shares. */
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1031 this->visual_profit += profit - cp->feeder_share;
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1032 }
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1033
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1034 /**
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1035 * Handle payment for transfer of the given cargo packet.
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1036 * @param cp The cargo packet to pay for.
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1037 * @param count The number of packets to pay for.
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1038 */
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1039 void CargoPayment::PayTransfer(CargoPacket *cp, uint count)
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1040 {
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1041 Money profit = GetTransportedGoodsIncome(
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1042 count,
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1043 /* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1044 DistanceManhattan(cp->loaded_at_xy, Station::Get(this->current_station)->xy),
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1045 cp->days_in_transit,
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1046 this->ct);
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1047
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1048 this->visual_profit += profit; // accumulate transfer profits for whole vehicle
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1049 cp->feeder_share += profit; // account for the (virtual) profit already made for the cargo packet
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1050 }
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1051
3a97d4e6f918 (svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents: 12267
diff changeset
1052 /**
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1053 * Prepare the vehicle to be unloaded.
6559
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1054 * @param front_v the vehicle to be unloaded
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1055 */
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1056 void PrepareUnload(Vehicle *front_v)
6559
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1057 {
6565
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1058 /* At this moment loading cannot be finished */
7929
4d13dbed828c (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
1059 ClrBit(front_v->vehicle_flags, VF_LOADING_FINISHED);
6565
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1060
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1061 /* Start unloading in at the first possible moment */
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1062 front_v->load_unload_time_rem = 1;
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1063
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1064 if ((front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1065 for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1066 if (v->cargo_cap > 0 && !v->cargo.Empty()) {
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7929
diff changeset
1067 SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
6559
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1068 }
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1069 }
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1070 }
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1071
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1072 assert(front_v->cargo_payment == NULL);
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1073 front_v->cargo_payment = new CargoPayment(front_v);
6559
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1074 }
b680e3433ca2 (svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents: 6500
diff changeset
1075
6580
e1cdf0b1265b (svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents: 6565
diff changeset
1076 /**
e1cdf0b1265b (svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents: 6565
diff changeset
1077 * Loads/unload the vehicle if possible.
e1cdf0b1265b (svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents: 6565
diff changeset
1078 * @param v the vehicle to be (un)loaded
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1079 * @param cargo_left the amount of each cargo type that is
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1080 * virtually left on the platform to be
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1081 * picked up by another vehicle when all
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1082 * previous vehicles have loaded.
6580
e1cdf0b1265b (svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents: 6565
diff changeset
1083 */
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1084 static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1085 {
8837
bdaf8866039c (svn r12585) -Fix (r12584): assumption that assertions were enabled during compilation/testing was flawed.
rubidium <rubidium@openttd.org>
parents: 8814
diff changeset
1086 assert(v->current_order.IsType(OT_LOADING));
12756
7e6255798f4e (svn r17222) -Fix [FS#3129, FS#3130]: with time tables vehicles would stay in the 'loading' state after they have finished loading
rubidium <rubidium@openttd.org>
parents: 12669
diff changeset
1087
7e6255798f4e (svn r17222) -Fix [FS#3129, FS#3130]: with time tables vehicles would stay in the 'loading' state after they have finished loading
rubidium <rubidium@openttd.org>
parents: 12669
diff changeset
1088 /* When we've finished loading we're just staying here till the timetable 'runs' out */
7e6255798f4e (svn r17222) -Fix [FS#3129, FS#3130]: with time tables vehicles would stay in the 'loading' state after they have finished loading
rubidium <rubidium@openttd.org>
parents: 12669
diff changeset
1089 if (HasBit(v->vehicle_flags, VF_LOADING_FINISHED)) return;
7e6255798f4e (svn r17222) -Fix [FS#3129, FS#3130]: with time tables vehicles would stay in the 'loading' state after they have finished loading
rubidium <rubidium@openttd.org>
parents: 12669
diff changeset
1090
12467
cf0ccd158d37 (svn r16901) -Fix [FS#3046] (rpbs): when marking trains stuck don't reset the unload counter/stuck when the vehicle is unloading. It'll be automatically reset once the vehicle wants to leave the station
rubidium <rubidium@openttd.org>
parents: 12443
diff changeset
1091 assert(v->load_unload_time_rem != 0);
6616
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1092
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1093 /* We have not waited enough time till the next round of loading/unloading */
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1094 if (--v->load_unload_time_rem != 0) {
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1095 if (_settings_game.order.improved_load && (v->current_order.GetLoadType() & OLFB_FULL_LOAD)) {
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1096 /* 'Reserve' this cargo for this vehicle, because we were first. */
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7474
diff changeset
1097 for (; v != NULL; v = v->Next()) {
11194
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1098 int cap_left = v->cargo_cap - v->cargo.Count();
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1099 if (cap_left > 0) cargo_left[v->cargo_type] -= cap_left;
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1100 }
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1101 }
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1102 return;
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1103 }
6616
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1104
8231
7002fda5bb72 (svn r11794) -Fix [FS#1632]: reversing a train when loading at a station with an adjacent station in the same axis crashed.
glx <glx@openttd.org>
parents: 8230
diff changeset
1105 StationID last_visited = v->last_station_visited;
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
1106 Station *st = Station::Get(last_visited);
8231
7002fda5bb72 (svn r11794) -Fix [FS#1632]: reversing a train when loading at a station with an adjacent station in the same axis crashed.
glx <glx@openttd.org>
parents: 8230
diff changeset
1107
7002fda5bb72 (svn r11794) -Fix [FS#1632]: reversing a train when loading at a station with an adjacent station in the same axis crashed.
glx <glx@openttd.org>
parents: 8230
diff changeset
1108 if (v->type == VEH_TRAIN && (!IsTileType(v->tile, MP_STATION) || GetStationIndex(v->tile) != st->index)) {
6844
70d60b0104c1 (svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents: 6823
diff changeset
1109 /* The train reversed in the station. Take the "easy" way
70d60b0104c1 (svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents: 6823
diff changeset
1110 * out and let the train just leave as it always did. */
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7929
diff changeset
1111 SetBit(v->vehicle_flags, VF_LOADING_FINISHED);
6844
70d60b0104c1 (svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents: 6823
diff changeset
1112 return;
70d60b0104c1 (svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents: 6823
diff changeset
1113 }
70d60b0104c1 (svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents: 6823
diff changeset
1114
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1115 int unloading_time = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1116 Vehicle *u = v;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1117 int result = 0;
6565
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1118
8241
4648f777da55 (svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents: 8238
diff changeset
1119 bool completely_emptied = true;
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1120 bool anything_unloaded = false;
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1121 bool anything_loaded = false;
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1122 uint32 cargo_not_full = 0;
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1123 uint32 cargo_full = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1124
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1125 v->cur_speed = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1126
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1127 CargoPayment *payment = v->cargo_payment;
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1128
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7474
diff changeset
1129 for (; v != NULL; v = v->Next()) {
6609
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1130 if (v->cargo_cap == 0) continue;
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1131
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1132 byte load_amount = EngInfo(v->engine_type)->load_amount;
10419
e723ec01b3a6 (svn r14672) -Fix [FS#2444]: Property 7 and callback 12 were broken for aircraft.
frosch <frosch@openttd.org>
parents: 10417
diff changeset
1133
e723ec01b3a6 (svn r14672) -Fix [FS#2444]: Property 7 and callback 12 were broken for aircraft.
frosch <frosch@openttd.org>
parents: 10417
diff changeset
1134 /* The default loadamount for mail is 1/4 of the load amount for passengers */
12384
d4b73a406cf3 (svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
smatz <smatz@openttd.org>
parents: 12383
diff changeset
1135 if (v->type == VEH_AIRCRAFT && !Aircraft::From(v)->IsNormalAircraft()) load_amount = (load_amount + 3) / 4;
10419
e723ec01b3a6 (svn r14672) -Fix [FS#2444]: Property 7 and callback 12 were broken for aircraft.
frosch <frosch@openttd.org>
parents: 10417
diff changeset
1136
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1137 if (_settings_game.order.gradual_loading && HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_LOAD_AMOUNT)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1138 uint16 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v);
9020
94bb527c979f (svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium <rubidium@openttd.org>
parents: 9003
diff changeset
1139 if (cb_load_amount != CALLBACK_FAILED && GB(cb_load_amount, 0, 8) != 0) load_amount = GB(cb_load_amount, 0, 8);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1140 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1141
6609
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1142 GoodsEntry *ge = &st->goods[v->cargo_type];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1143
8883
23eea6824c4b (svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium <rubidium@openttd.org>
parents: 8873
diff changeset
1144 if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && (u->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
7010
f0f87c5a431e (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents: 7002
diff changeset
1145 uint cargo_count = v->cargo.Count();
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1146 uint amount_unloaded = _settings_game.order.gradual_loading ? min(cargo_count, load_amount) : cargo_count;
11221
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1147 bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here?
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1148 bool accepted = false; // Is the cargo accepted by the station?
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1149
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1150 payment->SetCargo(v->cargo_type);
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1151
8855
2acce887e7ec (svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents: 8843
diff changeset
1152 if (HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && !(u->current_order.GetUnloadType() & OUFB_TRANSFER)) {
7010
f0f87c5a431e (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents: 7002
diff changeset
1153 /* The cargo has reached it's final destination, the packets may now be destroyed */
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1154 remaining = v->cargo.MoveTo(NULL, amount_unloaded, CargoList::MTA_FINAL_DELIVERY, payment, last_visited);
7010
f0f87c5a431e (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents: 7002
diff changeset
1155
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1156 result |= 1;
11221
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1157 accepted = true;
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1158 }
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1159
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1160 /* The !accepted || v->cargo.Count == cargo_count clause is there
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1161 * to make it possible to force unload vehicles at the station where
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1162 * they were loaded, but to not force unload the vehicle when the
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1163 * station is still accepting the cargo in the vehicle. It doesn't
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1164 * accept cargo that was loaded at the same station. */
12082
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 12046
diff changeset
1165 if ((u->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) && (!accepted || v->cargo.Count() == cargo_count)) {
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1166 remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded, u->current_order.GetUnloadType() & OUFB_TRANSFER ? CargoList::MTA_TRANSFER : CargoList::MTA_UNLOAD, payment);
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7929
diff changeset
1167 SetBit(ge->acceptance_pickup, GoodsEntry::PICKUP);
6198
a2cdd211d091 (svn r8978) -Feature: Rewrite of transfer system.
richk <richk@openttd.org>
parents: 6190
diff changeset
1168
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1169 result |= 2;
11221
6205ed0337b2 (svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents: 11194
diff changeset
1170 } else if (!accepted) {
6609
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1171 /* The order changed while unloading (unset unload/transfer) or the
12290
3ba19b02f30e (svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents: 12289
diff changeset
1172 * station does not accept our goods. */
7929
4d13dbed828c (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
1173 ClrBit(v->vehicle_flags, VF_CARGO_UNLOADING);
12290
3ba19b02f30e (svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents: 12289
diff changeset
1174
3ba19b02f30e (svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents: 12289
diff changeset
1175 /* Say we loaded something, otherwise we'll think we didn't unload
3ba19b02f30e (svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents: 12289
diff changeset
1176 * something and we didn't load something, so we must be finished
3ba19b02f30e (svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents: 12289
diff changeset
1177 * at this station. Setting the unloaded means that we will get a
3ba19b02f30e (svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents: 12289
diff changeset
1178 * retry for loading in the next cycle. */
3ba19b02f30e (svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents: 12289
diff changeset
1179 anything_unloaded = true;
6609
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1180 continue;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1181 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1182
6609
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1183 /* Deliver goods to the station */
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1184 st->time_since_unload = 0;
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1185
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1186 unloading_time += amount_unloaded;
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1187
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1188 anything_unloaded = true;
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1189 if (_settings_game.order.gradual_loading && remaining) {
8241
4648f777da55 (svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents: 8238
diff changeset
1190 completely_emptied = false;
6609
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1191 } else {
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1192 /* We have finished unloading (cargo count == 0) */
7929
4d13dbed828c (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
1193 ClrBit(v->vehicle_flags, VF_CARGO_UNLOADING);
6609
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1194 }
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1195
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1196 continue;
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1197 }
5888
11683122ef51 (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros <maedhros@openttd.org>
parents: 5854
diff changeset
1198
8885
2d7e1a978a1a (svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium <rubidium@openttd.org>
parents: 8883
diff changeset
1199 /* Do not pick up goods when we have no-load set. */
2d7e1a978a1a (svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium <rubidium@openttd.org>
parents: 8883
diff changeset
1200 if (u->current_order.GetLoadType() & OLFB_NO_LOAD) continue;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1201
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1202 /* update stats */
6609
e78f5516e040 (svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents: 6601
diff changeset
1203 int t;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1204 switch (u->type) {
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12082
diff changeset
1205 case VEH_TRAIN: t = Train::From(u)->tcache.cached_max_speed; break;
6259
4a39d6291d58 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents: 6248
diff changeset
1206 case VEH_ROAD: t = u->max_speed / 2; break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1207 default: t = u->max_speed; break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1208 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1209
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
1210 /* if last speed is 0, we treat that as if no vehicle has ever visited the station. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1211 ge->last_speed = min(t, 255);
6990
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6957
diff changeset
1212 ge->last_age = _cur_year - u->build_year;
7458
7e4d907043ef (svn r10953) -Fix [FS#1139, FS#1143]: stations would not get a rating when there were already two stations with a "more than default" rating as no cargo would be moved to the station to be picked up.
rubidium <rubidium@openttd.org>
parents: 7447
diff changeset
1213 ge->days_since_pickup = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1214
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
1215 /* If there's goods waiting at the station, and the vehicle
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
1216 * has capacity for it, load it on the vehicle. */
11194
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1217 int cap_left = v->cargo_cap - v->cargo.Count();
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1218 if (!ge->cargo.Empty() && cap_left > 0) {
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1219 uint cap = cap_left;
7010
f0f87c5a431e (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents: 7002
diff changeset
1220 uint count = ge->cargo.Count();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1221
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1222 /* Skip loading this vehicle if another train/vehicle is already handling
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1223 * the same cargo type at this station */
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1224 if (_settings_game.order.improved_load && cargo_left[v->cargo_type] <= 0) {
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7929
diff changeset
1225 SetBit(cargo_not_full, v->cargo_type);
6565
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1226 continue;
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1227 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1228
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1229 if (cap > count) cap = count;
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1230 if (_settings_game.order.gradual_loading) cap = min(cap, load_amount);
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1231 if (_settings_game.order.improved_load) {
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1232 /* Don't load stuff that is already 'reserved' for other vehicles */
7023
1997a5b53cec (svn r10287) -Fix (r10266): some surprises from that (almost always) complaining compiler...
rubidium <rubidium@openttd.org>
parents: 7014
diff changeset
1233 cap = min((uint)cargo_left[v->cargo_type], cap);
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1234 cargo_left[v->cargo_type] -= cap;
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1235 }
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1236
7010
f0f87c5a431e (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents: 7002
diff changeset
1237 if (v->cargo.Empty()) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1238
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1239 /* TODO: Regarding this, when we do gradual loading, we
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1240 * should first unload all vehicles and then start
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1241 * loading them. Since this will cause
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1242 * VEHICLE_TRIGGER_EMPTY to be called at the time when
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1243 * the whole vehicle chain is really totally empty, the
8241
4648f777da55 (svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents: 8238
diff changeset
1244 * completely_emptied assignment can then be safely
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1245 * removed; that's how TTDPatch behaves too. --pasky */
8241
4648f777da55 (svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents: 8238
diff changeset
1246 completely_emptied = false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1247 anything_loaded = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1248
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1249 ge->cargo.MoveTo(&v->cargo, cap, CargoList::MTA_CARGO_LOAD, NULL, st->xy);
6198
a2cdd211d091 (svn r8978) -Feature: Rewrite of transfer system.
richk <richk@openttd.org>
parents: 6190
diff changeset
1250
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1251 st->time_since_load = 0;
7010
f0f87c5a431e (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents: 7002
diff changeset
1252 st->last_vehicle_type = v->type;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1253
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8885
diff changeset
1254 StationAnimationTrigger(st, st->xy, STAT_ANIM_CARGO_TAKEN, v->cargo_type);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8885
diff changeset
1255
7474
7b35fd1cc99d (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium <rubidium@openttd.org>
parents: 7458
diff changeset
1256 unloading_time += cap;
7b35fd1cc99d (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium <rubidium@openttd.org>
parents: 7458
diff changeset
1257
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1258 result |= 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1259 }
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1260
11194
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1261 if (v->cargo.Count() >= v->cargo_cap) {
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7929
diff changeset
1262 SetBit(cargo_full, v->cargo_type);
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1263 } else {
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7929
diff changeset
1264 SetBit(cargo_not_full, v->cargo_type);
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1265 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1266 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1267
8241
4648f777da55 (svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents: 8238
diff changeset
1268 /* Only set completly_emptied, if we just unloaded all remaining cargo */
4648f777da55 (svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents: 8238
diff changeset
1269 completely_emptied &= anything_unloaded;
4648f777da55 (svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents: 8238
diff changeset
1270
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1271 /* We update these variables here, so gradual loading still fills
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1272 * all wagons at the same time instead of using the same 'improved'
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1273 * loading algorithm for the wagons (only fill wagon when there is
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1274 * enough to fill the previous wagons) */
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1275 if (_settings_game.order.improved_load && (u->current_order.GetLoadType() & OLFB_FULL_LOAD)) {
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1276 /* Update left cargo */
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7474
diff changeset
1277 for (v = u; v != NULL; v = v->Next()) {
11194
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1278 int cap_left = v->cargo_cap - v->cargo.Count();
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1279 if (cap_left > 0) cargo_left[v->cargo_type] -= cap_left;
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1280 }
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1281 }
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1282
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1283 v = u;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1284
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1285 if (!anything_unloaded) delete payment;
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1286
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1287 if (anything_loaded || anything_unloaded) {
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1288 if (_settings_game.order.gradual_loading) {
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1289 /* The time it takes to load one 'slice' of cargo or passengers depends
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11234
diff changeset
1290 * on the vehicle type - the values here are those found in TTDPatch */
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1291 const uint gradual_loading_wait_time[] = { 40, 20, 10, 20 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1292
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1293 unloading_time = gradual_loading_wait_time[v->type];
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1294 }
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1295 } else {
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1296 bool finished_loading = true;
8855
2acce887e7ec (svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents: 8843
diff changeset
1297 if (v->current_order.GetLoadType() & OLFB_FULL_LOAD) {
8873
9780f2a6cd20 (svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium <rubidium@openttd.org>
parents: 8855
diff changeset
1298 if (v->current_order.GetLoadType() == OLF_FULL_LOAD_ANY) {
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1299 /* if the aircraft carries passengers and is NOT full, then
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1300 * continue loading, no matter how much mail is in */
11194
1c56a71f2bb1 (svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents: 11090
diff changeset
1301 if ((v->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS) && v->cargo_cap > v->cargo.Count()) ||
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1302 (cargo_not_full && (cargo_full & ~cargo_not_full) == 0)) { // There are stull non-full cargos
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1303 finished_loading = false;
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1304 }
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1305 } else if (cargo_not_full != 0) {
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1306 finished_loading = false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1307 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1308 }
6611
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1309 unloading_time = 20;
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1310
461107df1c8f (svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents: 6609
diff changeset
1311 SB(v->vehicle_flags, VF_LOADING_FINISHED, 1, finished_loading);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1312 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1313
6259
4a39d6291d58 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents: 6248
diff changeset
1314 if (v->type == VEH_TRAIN) {
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
1315 /* Each platform tile is worth 2 rail vehicles. */
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12082
diff changeset
1316 int overhang = Train::From(v)->tcache.cached_total_length - st->GetPlatformLength(v->tile) * TILE_SIZE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1317 if (overhang > 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1318 unloading_time <<= 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1319 unloading_time += (overhang * unloading_time) / 8;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1320 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1321 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1322
7543
2e26b732a29b (svn r11063) -Codechange: make it possible for people to view the loading indicators of everyone. Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents: 7520
diff changeset
1323 /* Calculate the loading indicator fill percent and display
2e26b732a29b (svn r11063) -Codechange: make it possible for people to view the loading indicators of everyone. Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents: 7520
diff changeset
1324 * In the Game Menu do not display indicators
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1325 * If _settings_client.gui.loading_indicators == 2, show indicators (bool can be promoted to int as 0 or 1 - results in 2 > 0,1 )
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1326 * if _settings_client.gui.loading_indicators == 1, _local_company must be the owner or must be a spectator to show ind., so 1 > 0
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9359
diff changeset
1327 * if _settings_client.gui.loading_indicators == 0, do not display indicators ... 0 is never greater than anything
7543
2e26b732a29b (svn r11063) -Codechange: make it possible for people to view the loading indicators of everyone. Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents: 7520
diff changeset
1328 */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1329 if (_game_mode != GM_MENU && (_settings_client.gui.loading_indicators > (uint)(v->owner != _local_company && _local_company != COMPANY_SPECTATOR))) {
7014
d03670858cef (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents: 7010
diff changeset
1330 StringID percent_up_down = STR_NULL;
d03670858cef (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents: 7010
diff changeset
1331 int percent = CalcPercentVehicleFilled(v, &percent_up_down);
6998
13ea0d5f8acf (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents: 6991
diff changeset
1332 if (v->fill_percent_te_id == INVALID_TE_ID) {
7014
d03670858cef (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents: 7010
diff changeset
1333 v->fill_percent_te_id = ShowFillingPercent(v->x_pos, v->y_pos, v->z_pos + 20, percent, percent_up_down);
6998
13ea0d5f8acf (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents: 6991
diff changeset
1334 } else {
7014
d03670858cef (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents: 7010
diff changeset
1335 UpdateFillingPercent(v->fill_percent_te_id, percent, percent_up_down);
6998
13ea0d5f8acf (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents: 6991
diff changeset
1336 }
13ea0d5f8acf (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents: 6991
diff changeset
1337 }
13ea0d5f8acf (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents: 6991
diff changeset
1338
12496
99f1ec9a1940 (svn r16933) -Fix [FS#3054] (r16694): vehicles would wait "very long" when they had nothing to unload and gradual loading was disabled.
rubidium <rubidium@openttd.org>
parents: 12475
diff changeset
1339 /* Always wait at least 1, otherwise we'll wait 'infinitively' long. */
99f1ec9a1940 (svn r16933) -Fix [FS#3054] (r16694): vehicles would wait "very long" when they had nothing to unload and gradual loading was disabled.
rubidium <rubidium@openttd.org>
parents: 12475
diff changeset
1340 v->load_unload_time_rem = max(1, unloading_time);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1341
8241
4648f777da55 (svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents: 8238
diff changeset
1342 if (completely_emptied) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1343 TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1344 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1345
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1346 if (result != 0) {
9043
9d514f6b9e04 (svn r12862) -Codechange: reduce code duplication for VehicleType -> WindowClass lookup
smatz <smatz@openttd.org>
parents: 9020
diff changeset
1347 InvalidateWindow(GetWindowClassForVehicleType(v->type), v->owner);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1348 InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
6565
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1349
6823
afa9c0a81fda (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138 <peter1138@openttd.org>
parents: 6819
diff changeset
1350 st->MarkTilesDirty(true);
6565
547b0171c3a9 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents: 6559
diff changeset
1351 v->MarkDirty();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1352
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1353 if (result & 2) InvalidateWindow(WC_STATION_VIEW, last_visited);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1354 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1355 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1356
6616
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1357 /**
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1358 * Load/unload the vehicles in this station according to the order
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1359 * they entered.
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1360 * @param st the station to do the loading/unloading for
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1361 */
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1362 void LoadUnloadStation(Station *st)
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1363 {
12265
10c7609e2d4b (svn r16680) -Codechange: don't go through all the station unloading stuff when there is no vehicle at the station
rubidium <rubidium@openttd.org>
parents: 12239
diff changeset
1364 /* No vehicle is here... */
10c7609e2d4b (svn r16680) -Codechange: don't go through all the station unloading stuff when there is no vehicle at the station
rubidium <rubidium@openttd.org>
parents: 12239
diff changeset
1365 if (st->loading_vehicles.empty()) return;
10c7609e2d4b (svn r16680) -Codechange: don't go through all the station unloading stuff when there is no vehicle at the station
rubidium <rubidium@openttd.org>
parents: 12239
diff changeset
1366
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1367 int cargo_left[NUM_CARGO];
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1368
7010
f0f87c5a431e (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents: 7002
diff changeset
1369 for (uint i = 0; i < NUM_CARGO; i++) cargo_left[i] = st->goods[i].cargo.Count();
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1370
6616
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1371 std::list<Vehicle *>::iterator iter;
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1372 for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1373 Vehicle *v = *iter;
6618
a0ebb1506656 (svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents: 6616
diff changeset
1374 if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v, cargo_left);
6616
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1375 }
12279
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1376
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1377 /* Call the production machinery of industries */
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1378 const Industry * const *isend = _cargo_delivery_destinations.End();
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1379 for (Industry **iid = _cargo_delivery_destinations.Begin(); iid != isend; iid++) {
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1380 TriggerIndustryProduction(*iid);
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1381 }
329b186db8cd (svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents: 12278
diff changeset
1382 _cargo_delivery_destinations.Clear();
6616
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1383 }
ce5601a32593 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents: 6611
diff changeset
1384
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1385 void CompaniesMonthlyLoop()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1386 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1387 CompaniesGenStatistics();
12940
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
1388 if (_settings_game.economy.inflation) {
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
1389 AddInflation();
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
1390 RecomputePrices();
1b090e0c4f93 (svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents: 12933
diff changeset
1391 }
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1392 CompaniesPayInterest();
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1393 /* Reset the _current_company flag */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1394 _current_company = OWNER_NONE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1395 HandleEconomyFluctuations();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1396 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1397
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1398 static void DoAcquireCompany(Company *c)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1399 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1400 Company *owner;
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
1401 int i;
6953
41fd36025784 (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents: 6952
diff changeset
1402 Money value;
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10647
diff changeset
1403 CompanyID ci = c->index;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1404
9658
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
1405 CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
1406 cni->FillData(c, Company::Get(_current_company));
9658
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
1407
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11376
diff changeset
1408 SetDParam(0, STR_NEWS_COMPANY_MERGER_TITLE);
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11376
diff changeset
1409 SetDParam(1, c->bankrupt_value == 0 ? STR_NEWS_MERGER_TAKEOVER_TITLE : STR_NEWS_COMPANY_MERGER_DESCRIPTION);
9658
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
1410 SetDParamStr(2, cni->company_name);
27697e657d2e (svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents: 9652
diff changeset
1411 SetDParamStr(3, cni->other_company_name);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1412 SetDParam(4, c->bankrupt_value);
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1413 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_MERGER, cni);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10647
diff changeset
1414 AI::BroadcastNewEvent(new AIEventCompanyMerger(ci, _current_company));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1415
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6119
diff changeset
1416 /* original code does this a little bit differently */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1417 ChangeNetworkOwner(ci, _current_company);
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1418 ChangeOwnershipOfCompanyItems(ci, _current_company);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1419
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1420 if (c->bankrupt_value == 0) {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
1421 owner = Company::Get(_current_company);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1422 owner->current_loan += c->current_loan;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1423 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1424
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1425 value = CalculateCompanyValue(c) >> 2;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1426 CompanyID old_company = _current_company;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1427 for (i = 0; i != 4; i++) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1428 if (c->share_owners[i] != COMPANY_SPECTATOR) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1429 _current_company = c->share_owners[i];
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1430 SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -value));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1431 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1432 }
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1433 _current_company = old_company;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1434
12143
20abba1d6d18 (svn r16559) -Codechange: introduce Company::IsValidAiID() and Company::IsValidHumanID(), don't use IsHumanCompany() where possible
smatz <smatz@openttd.org>
parents: 12114
diff changeset
1435 if (c->is_ai) AI::Stop(c->index);
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10647
diff changeset
1436
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1437 DeleteCompanyWindows(ci);
9297
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9281
diff changeset
1438 InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9281
diff changeset
1439 InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9281
diff changeset
1440 InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9281
diff changeset
1441 InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
9659
14e241fadc66 (svn r13731) -Codechange: make a pool of the array of players.
rubidium <rubidium@openttd.org>
parents: 9658
diff changeset
1442
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1443 delete c;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1444 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1445
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1446 extern int GetAmountOwnedBy(const Company *c, Owner owner);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1447
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1448 /** Acquire shares in an opposing company.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1449 * @param tile unused
6432
fc703c6dc92c (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents: 6405
diff changeset
1450 * @param flags type of operation
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1451 * @param p1 company to buy the shares from
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1452 * @param p2 unused
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1453 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11085
diff changeset
1454 CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1455 {
8230
5b61305fcdd4 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents: 8224
diff changeset
1456 CommandCost cost(EXPENSES_OTHER);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1457
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1458 Company *c = Company::GetIfValid(p1);
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1459
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1460 /* Check if buying shares is allowed (protection against modified clients)
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1461 * Cannot buy own shares */
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1462 if (c == NULL || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1463
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1464 /* Protect new companies from hostile takeovers */
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1465 if (_cur_year - c->inaugurated_year < 6) return_cmd_error(STR_ERROR_PROTECTED);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1466
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1467 /* Those lines are here for network-protection (clients can be slow) */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1468 if (GetAmountOwnedBy(c, COMPANY_SPECTATOR) == 0) return cost;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1469
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1470 /* We can not buy out a real company (temporarily). TODO: well, enable it obviously */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1471 if (GetAmountOwnedBy(c, COMPANY_SPECTATOR) == 1 && !c->is_ai) return cost;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1472
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1473 cost.AddCost(CalculateCompanyValue(c) >> 2);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1474 if (flags & DC_EXEC) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1475 OwnerByte *b = c->share_owners;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1476 int i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1477
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1478 while (*b != COMPANY_SPECTATOR) b++; // share owners is guaranteed to contain at least one COMPANY_SPECTATOR
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1479 *b = _current_company;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1480
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1481 for (i = 0; c->share_owners[i] == _current_company;) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1482 if (++i == 4) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1483 c->bankrupt_value = 0;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1484 DoAcquireCompany(c);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1485 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1486 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1487 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1488 InvalidateWindow(WC_COMPANY, p1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1489 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1490 return cost;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1491 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1492
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1493 /** Sell shares in an opposing company.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1494 * @param tile unused
6432
fc703c6dc92c (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents: 6405
diff changeset
1495 * @param flags type of operation
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1496 * @param p1 company to sell the shares from
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1497 * @param p2 unused
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1498 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11085
diff changeset
1499 CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1500 {
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1501 Company *c = Company::GetIfValid(p1);
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1502
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1503 /* Check if selling shares is allowed (protection against modified clients)
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1504 * Cannot sell own shares */
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1505 if (c == NULL || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1506
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1507 /* Those lines are here for network-protection (clients can be slow) */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1508 if (GetAmountOwnedBy(c, _current_company) == 0) return CommandCost();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1509
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1510 /* adjust it a little to make it less profitable to sell and buy */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1511 Money cost = CalculateCompanyValue(c) >> 2;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1512 cost = -(cost - (cost >> 7));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1513
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1514 if (flags & DC_EXEC) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1515 OwnerByte *b = c->share_owners;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1516 while (*b != _current_company) b++; // share owners is guaranteed to contain company
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1517 *b = COMPANY_SPECTATOR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1518 InvalidateWindow(WC_COMPANY, p1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1519 }
8230
5b61305fcdd4 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents: 8224
diff changeset
1520 return CommandCost(EXPENSES_OTHER, cost);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1521 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1522
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1523 /** Buy up another company.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1524 * When a competing company is gone bankrupt you get the chance to purchase
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1525 * that company.
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1526 * @todo currently this only works for AI companies
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1527 * @param tile unused
6432
fc703c6dc92c (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents: 6405
diff changeset
1528 * @param flags type of operation
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1529 * @param p1 company to buy up
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1530 * @param p2 unused
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1531 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11085
diff changeset
1532 CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1533 {
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1534 Company *c = Company::GetIfValid(p1);
12855
7c31785657c1 (svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents: 12853
diff changeset
1535 if (c == NULL) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1536
12855
7c31785657c1 (svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents: 12853
diff changeset
1537 /* Disable takeovers when not asked */
7c31785657c1 (svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents: 12853
diff changeset
1538 if (!HasBit(c->bankrupt_asked, _current_company)) return CMD_ERROR;
7c31785657c1 (svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents: 12853
diff changeset
1539
7c31785657c1 (svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents: 12853
diff changeset
1540 /* Disable taking over the local company in single player */
7c31785657c1 (svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents: 12853
diff changeset
1541 if (!_networking && _local_company == c->index) return CMD_ERROR;
6405
3f3b30a14c26 (svn r9541) -Codechange: Safeguard the company-buying routines so that the buying player and the bought player need to be two different entities
celestar <celestar@openttd.org>
parents: 6403
diff changeset
1542
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1543 /* Do not allow companies to take over themselves */
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1544 if ((CompanyID)p1 == _current_company) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1545
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1546 if (flags & DC_EXEC) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1547 DoAcquireCompany(c);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1548 }
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10158
diff changeset
1549 return CommandCost(EXPENSES_OTHER, c->bankrupt_value);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1550 }