-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCitygrowth.nut
119 lines (108 loc) · 3.23 KB
/
Citygrowth.nut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* This file is part of CityBuilder, which is a GameScript for OpenTTD
*
* CityBuilder 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 of the License
*
* CityBuilder 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CityBuilder; If not, see <http://www.gnu.org/licenses/> or
* write to the Free Software Foundation, Inc., 51 Franklin Street,
* Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
require("Place.nut");
function _min_size__(){return GSController.GetSetting("min_size_max_growth");}
////////////////////////////////////////////////////
// Contributors:
////////////////////////////////////////////////////
class City extends Place{
diff = 0;
mult = 1.0;
sign_id = -1;
transport_pct = 0;
mode = 0;
constructor(town_id) {
::Place.constructor(town_id);
this.mode = this.cities_setting;
if(mode == 2){this.mult *= ((GSBase.RandRange(10000).tofloat()) / 5000.0 + 1.0);}
mult *= (GSController.GetSetting("city_cgg").tofloat()) / 1000.0;
if(mode > 0){DisableDefaultGoals();}
}
function SetGrowthRate();
function Manage();
function SetRate();
function DoSigns();
function SetSigns();
function GetPop();
function Set(new_id, new_mult, new_sign_id, new_start_population);
function _typeof();
}
function City::_typeof(){return "City";}
function City::Set(new_id, new_mult, new_sign_id, new_start_population){
id = new_id;
mult = new_mult;
sign_id = new_sign_id;
start_population = new_start_population;
}
function City::GetPop(){
return pop;}
function City::Manage() {
if(mode == 1 || mode == 2) {
SetGrowthRate();
DoSigns();
}
ApplyGrowth();
}
function City::SetRate() {
if(mode == 1 || mode == 2) {
GSTown.SetGrowthRate(id, 30996);
}
pop = GSTown.GetPopulation(id);
}
function City::SetGrowthRate(){
// if regrowth is on:
this.transport_pct = GSTown.GetLastMonthTransportedPercentage(this.id,this.paxcargo);
local num_houses = GSTown.GetHouseCount(this.id);
if(this.regrow > 100) {
if(pop < start_population) {
this.is_growing = 3;
this.growthRate = this.slow_factor * 1000.0 / (this.mult * max(this.pop, _min_size__()).tofloat());
return;
}
}
if( transport_pct < req && this.pop > this.tsize) {
// don't grow at all.
this.is_growing = 0;
this.growthRate = 0;
} else {
// grow at full speed.
this.is_growing = 3;
this.growthRate = this.slow_factor * 1000.0 / (this.mult * max(this.pop, _min_size__()).tofloat());
}
}
function City::DoSigns(){
switch(mode) {
case(1): // MTR
SetSigns();
break;
case(2): // MTR, Random
SetSigns();
break;
default:
break;
}
}
function City::SetSigns(){
// add a desc to the town window with the actual percentage.
if(!is_growing) {
GSTown.SetText(id, GSText(GSText.STR_CITYBUILDER_CITY_NOGROW, transport_pct, req, 1<<paxcargo));
} else {
GSTown.SetText(id, GSText(GSText.STR_CITYBUILDER_CITY_GROW, transport_pct, req, 1<<paxcargo));
}
}