Skip to content

Commit c025720

Browse files
committed
refactor: house_tax_coverage option moved from building common class
1 parent c0e4ae2 commit c025720

11 files changed

+33
-20
lines changed

src/building/building.h

-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ class building {
169169
e_building_type type;
170170
short native_meeting_center_id;
171171
unsigned short road_network_id;
172-
//unsigned short creation_sequence_index;
173172
short houses_covered;
174173
short percentage_houses_covered;
175174
short distance_from_entry;
@@ -205,7 +204,6 @@ class building {
205204
unsigned char fire_proof; // cannot catch fire or collapse
206205
unsigned char damage_proof;
207206
unsigned char map_random_7bit;
208-
unsigned char house_tax_coverage;
209207
unsigned short tax_collector_id;
210208
short formation_id;
211209
int tax_income_or_storage;

src/building/building_debug_properties.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void game_debug_show_properties_object(pcstr prefix, building *b) {
2626
bstring256 type_name; type_name.printf("%s [%d]", token::find_name(e_building_type_tokens, b->type), b->type);
2727
game_debug_show_property("type", type_name);
2828
game_debug_show_property("road_network_id", b->road_network_id);
29-
game_debug_show_property("houses_covered", b->houses_covered);
29+
//game_debug_show_property("houses_covered", b->houses_covered);
3030
game_debug_show_property("percentage_houses_covered", b->percentage_houses_covered);
3131
//game_debug_show_property("house_population", b->house_population);
3232
//game_debug_show_property("house_population_room", b->house_population_room);
@@ -59,7 +59,7 @@ void game_debug_show_properties_object(pcstr prefix, building *b) {
5959
game_debug_show_property("health_proof", b->health_proof);
6060
game_debug_show_property("fire_proof", b->fire_proof);
6161
game_debug_show_property("damage_proof", b->damage_proof);
62-
game_debug_show_property("house_tax_coverage", b->house_tax_coverage);
62+
//game_debug_show_property("house_tax_coverage", b->house_tax_coverage);
6363
game_debug_show_property("tax_collector_id", b->tax_collector_id);
6464
game_debug_show_property("formation_id", b->formation_id);
6565
game_debug_show_property("tax_income_or_storage", b->tax_income_or_storage);

src/building/building_house.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ void building_house::bind_dynamic(io_buffer *iob, size_t version) {
199199
iob->bind(BIND_SIGNATURE_UINT8, &d.criminal_active);
200200
iob->bind(BIND_SIGNATURE_INT16, &d.highest_population);
201201
iob->bind(BIND_SIGNATURE_INT16, &d.population);
202+
iob->bind(BIND_SIGNATURE_UINT8, &d.tax_coverage);
202203
}
203204

204205
int building_house::get_fire_risk(int value) const {

src/building/building_house.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class building_house : public building_impl {
5757
uint8_t water_supply;
5858
uint8_t house_happiness;
5959
uint8_t criminal_active;
60+
uint8_t tax_coverage;
6061
};
6162

6263
virtual void on_create(int orientation) override;

src/city/city_buildings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ io_buffer *iob_buildings = new io_buffer([] (io_buffer *iob, size_t version) {
284284
iob->bind(BIND_SIGNATURE_UINT8, &b->fire_proof);
285285

286286
iob->bind(BIND_SIGNATURE_UINT8, &b->map_random_7bit); // 20 (workcamp 1)
287-
iob->bind(BIND_SIGNATURE_UINT8, &b->house_tax_coverage);
287+
iob->bind____skip(1);
288288
iob->bind(BIND_SIGNATURE_UINT8, &b->health_proof);
289289
iob->bind(BIND_SIGNATURE_INT16, &b->formation_id);
290290

src/city/finance.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,15 @@ void city_finance_estimate_taxes() {
149149

150150
buildings_valid_do([] (building &b) {
151151
auto house = b.dcast_house();
152-
153-
if (!(house && b.house_size || b.house_tax_coverage)) {
152+
if (!house) {
154153
return;
155154
}
156155

157156
auto &housed = house->runtime_data();
157+
if (!housed.tax_coverage) {
158+
return;
159+
}
160+
158161
int is_nobles = (housed.level >= HOUSE_COMMON_MANOR);
159162
int tax_multiplier = model_get_house(housed.level)->tax_multiplier;
160163
int level_tax_rate_multiplier = difficulty_adjust_money(tax_multiplier);
@@ -216,7 +219,7 @@ static void city_finance_collect_monthly_taxes() {
216219
city_data.population.at_level[housed.level] += population;
217220

218221
int tax = population * trm;
219-
if (b.house_tax_coverage) {
222+
if (housed.tax_coverage) {
220223
if (is_nobles) {
221224
city_data.taxes.taxed_nobles += population;
222225
city_data.taxes.monthly.collected_nobles += tax;

src/city/houses.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,15 @@ void city_t::house_service_decay_services() {
155155
void city_t::house_service_decay_tax_collector() {
156156
OZZY_PROFILER_SECTION("Game/Run/Tick/Tax Collector Update");
157157
for (int i = 1; i < MAX_BUILDINGS; i++) {
158-
building* b = building_get(i);
159-
if (b->state == BUILDING_STATE_VALID && b->house_tax_coverage)
160-
b->house_tax_coverage--;
158+
auto house = building_get(i)->dcast_house();
159+
if (!house && house->state() != BUILDING_STATE_VALID) {
160+
continue;
161+
}
162+
163+
auto &housed = house->runtime_data();
164+
if (housed.tax_coverage) {
165+
housed.tax_coverage--;
166+
}
161167
}
162168
}
163169

src/city/labor.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,12 @@ void city_labor_t::set_building_worker_weight() {
399399
continue;
400400

401401
e_labor_category cat = category_for_building(b);
402-
if (cat == LABOR_CATEGORY_WATER_HEALTH)
402+
if (cat == LABOR_CATEGORY_WATER_HEALTH) {
403403
b->percentage_houses_covered = water_per_10k_per_building;
404-
else if (cat >= 0) {
404+
} else if (cat >= 0) {
405405
b->percentage_houses_covered = 0;
406406
if (b->houses_covered) {
407-
b->percentage_houses_covered
408-
= calc_percentage(100 * b->houses_covered, categories[cat].total_houses_covered);
407+
b->percentage_houses_covered = calc_percentage(100 * b->houses_covered, categories[cat].total_houses_covered);
409408
}
410409
}
411410
}

src/figuretype/figure_tax_collector.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int figure_tax_collector::provide_service() {
130130
return;
131131
}
132132

133-
if (b->house_size && house->house_population() > 0) {
133+
if (house->house_population() > 0) {
134134
int tax_multiplier = model_get_house(house->house_level())->tax_multiplier;
135135
if (tax_multiplier > max_tax_multiplier) {
136136
max_tax_multiplier = tax_multiplier;
@@ -144,7 +144,7 @@ int figure_tax_collector::provide_service() {
144144
f->data.taxman.reach_taxed++;
145145
}
146146
b->tax_collector_id = f->home()->id;
147-
b->house_tax_coverage = 50;
147+
house->runtime_data().tax_coverage = 50;
148148
}
149149
});
150150
base.min_max_seen = max_tax_rate;

src/overlays/city_overlay_tax_income.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "city_overlay_tax_income.h"
22

3-
#include "building/building.h"
3+
#include "building/building_house.h"
44
#include "graphics/elements/tooltip.h"
55
#include "core/calc.h"
66
#include "city/finance.h"
@@ -24,12 +24,17 @@ int city_overlay_tax_income::get_column_height(const building *b) const {
2424
}
2525

2626
xstring city_overlay_tax_income::get_tooltip_for_building(tooltip_context *c, const building *b) const {
27+
auto house = ((building*)b)->dcast_house();
28+
if (!house) {
29+
return ui::str(66, 43);
30+
}
31+
2732
int denarii = calc_adjust_with_percentage(b->tax_income_or_storage / 2, city_finance_tax_percentage());
2833
if (denarii > 0) {
2934
c->has_numeric_prefix = 1;
3035
c->numeric_prefix = denarii;
3136
return ui::str(66, 45);
32-
} else if (b->house_tax_coverage > 0) {
37+
} else if (house->runtime_data().tax_coverage > 0) {
3338
return ui::str(66, 44);
3439
} else {
3540
return ui::str(66, 43);

src/window/window_house_info.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void info_window_house::init(object_info &c) {
128128
ui["people_text"].text_var("%s ( %s )", people_text.c_str(), adv_people_text.c_str());
129129

130130
bstring256 tax_info_text;
131-
if (house->base.house_tax_coverage) {
131+
if (housed.tax_coverage) {
132132
int pct = calc_adjust_with_percentage(house->base.tax_income_or_storage / 2, city_finance_tax_percentage());
133133
tax_info_text.printf("%s %u %s", ui::str(127, 24), pct, ui::str(127, 25));
134134
} else {

0 commit comments

Comments
 (0)