forked from bvschaik/julius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigration.c
170 lines (155 loc) · 5.91 KB
/
migration.c
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "migration.h"
#include "building/house_population.h"
#include "city/data_private.h"
#include "city/figures.h"
#include "city/message.h"
#include "core/calc.h"
#include "game/tutorial.h"
static void update_status(void)
{
if (city_data.sentiment.value > 70) {
city_data.migration.percentage = 100;
} else if (city_data.sentiment.value > 60) {
city_data.migration.percentage = 75;
} else if (city_data.sentiment.value >= 50) {
city_data.migration.percentage = 50;
} else if (city_data.sentiment.value > 40) {
city_data.migration.percentage = 0;
} else if (city_data.sentiment.value > 30) {
city_data.migration.percentage = -10;
} else if (city_data.sentiment.value > 20) {
city_data.migration.percentage = -25;
} else {
city_data.migration.percentage = -50;
}
city_data.migration.immigration_amount_per_batch = 0;
city_data.migration.emigration_amount_per_batch = 0;
int population_cap = tutorial_get_population_cap(200000);
if (city_data.population.population >= population_cap) {
city_data.migration.percentage = 0;
return;
}
// war scares immigrants away
if (city_figures_total_invading_enemies() > 3 &&
city_data.migration.percentage > 0) {
city_data.migration.percentage = 0;
return;
}
if (city_data.migration.percentage > 0) {
// immigration
if (city_data.migration.emigration_duration) {
city_data.migration.emigration_duration--;
} else {
city_data.migration.immigration_amount_per_batch =
calc_adjust_with_percentage(12, city_data.migration.percentage);
city_data.migration.immigration_duration = 2;
}
} else if (city_data.migration.percentage < 0) {
// emigration
if (city_data.migration.immigration_duration) {
city_data.migration.immigration_duration--;
} else if (city_data.population.population > 100) {
city_data.migration.emigration_amount_per_batch =
calc_adjust_with_percentage(12, -city_data.migration.percentage);
city_data.migration.emigration_duration = 2;
}
}
}
static void create_immigrants(int num_people)
{
int immigrated = house_population_create_immigrants(num_people);
city_data.migration.immigrated_today += immigrated;
city_data.migration.newcomers += city_data.migration.immigrated_today;
if (immigrated == 0) {
city_data.migration.refused_immigrants_today += num_people;
}
}
static void create_emigrants(int num_people)
{
city_data.migration.emigrated_today += house_population_create_emigrants(num_people);
}
static void create_migrants(void)
{
city_data.migration.immigrated_today = 0;
city_data.migration.emigrated_today = 0;
city_data.migration.refused_immigrants_today = 0;
if (city_data.migration.immigration_amount_per_batch > 0) {
if (city_data.migration.immigration_amount_per_batch >= 4) {
create_immigrants(city_data.migration.immigration_amount_per_batch);
} else if (city_data.migration.immigration_amount_per_batch
+ city_data.migration.immigration_queue_size >= 4) {
create_immigrants(city_data.migration.immigration_amount_per_batch
+ city_data.migration.immigration_queue_size);
city_data.migration.immigration_queue_size = 0;
} else {
// queue them for next round
city_data.migration.immigration_queue_size += city_data.migration.immigration_amount_per_batch;
}
}
if (city_data.migration.emigration_amount_per_batch > 0) {
if (city_data.migration.emigration_amount_per_batch >= 4) {
create_emigrants(city_data.migration.emigration_amount_per_batch);
} else if (city_data.migration.emigration_amount_per_batch + city_data.migration.emigration_queue_size >= 4) {
create_emigrants(city_data.migration.emigration_amount_per_batch
+ city_data.migration.emigration_queue_size);
city_data.migration.emigration_queue_size = 0;
if (!city_data.migration.emigration_message_shown) {
city_data.migration.emigration_message_shown = 1;
city_message_post(1, MESSAGE_EMIGRATION, 0, 0);
}
} else {
// queue them for next round
city_data.migration.emigration_queue_size += city_data.migration.emigration_amount_per_batch;
}
}
city_data.migration.immigration_amount_per_batch = 0;
city_data.migration.emigration_amount_per_batch = 0;
}
void city_migration_update(void)
{
update_status();
create_migrants();
}
void city_migration_determine_no_immigration_cause(void)
{
switch (city_data.sentiment.low_mood_cause) {
case LOW_MOOD_CAUSE_NO_FOOD:
city_data.migration.no_immigration_cause = 2;
break;
case LOW_MOOD_CAUSE_NO_JOBS:
city_data.migration.no_immigration_cause = 1;
break;
case LOW_MOOD_CAUSE_HIGH_TAXES:
city_data.migration.no_immigration_cause = 3;
break;
case LOW_MOOD_CAUSE_LOW_WAGES:
city_data.migration.no_immigration_cause = 0;
break;
case LOW_MOOD_CAUSE_MANY_TENTS:
city_data.migration.no_immigration_cause = 4;
break;
default:
city_data.migration.no_immigration_cause = 5;
break;
}
}
int city_migration_no_immigration_cause(void)
{
return city_data.migration.no_immigration_cause;
}
int city_migration_no_room_for_immigrants(void)
{
return city_data.migration.refused_immigrants_today || city_data.population.room_in_houses <= 0;
}
int city_migration_percentage(void)
{
return city_data.migration.percentage;
}
int city_migration_newcomers(void)
{
return city_data.migration.newcomers;
}
void city_migration_reset_newcomers(void)
{
city_data.migration.newcomers = 0;
}