Skip to content

Commit 84eb270

Browse files
committed
maintenance: add mission fire_damage option
1 parent 9ef3595 commit 84eb270

10 files changed

+70
-49
lines changed

src/building/building.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ void building_impl::on_tick(bool refresh_only) {
976976
void building_impl::static_params::load(archive arch) {
977977
labor_category = arch.r_type<e_labor_category>("labor_category");
978978
fire_proof = arch.r_bool("fire_proof");
979+
fire_risk_update = arch.r_int("fire_risk_update", 50);
979980
damage_proof = arch.r_bool("damage_proof");
980981
input_resource = arch.r_type<e_resource>("input_resource");
981982
input_resource_second = arch.r_type<e_resource>("input_resource_second");

src/building/building.h

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ class building_impl {
392392
static static_params dummy;
393393
pcstr name;
394394
bool fire_proof;
395+
int8_t fire_risk_update;
395396
bool damage_proof;
396397
bool is_draggable;
397398
xstring meta_id;

src/building/building_house.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ void building_house::bind_dynamic(io_buffer *iob, size_t version) {
211211
}
212212

213213
int building_house::get_fire_risk(int value) const {
214-
if (house_level() == BUILDING_HOUSE_VACANT_LOT && is_vacant_lot()) {
214+
const bool is_empty = (house_level() == HOUSE_CRUDE_HUT) && is_vacant_lot();
215+
if (is_empty) {
215216
return 0;
216217
}
217218

src/building/maintenance.cpp

+6-23
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ void building_maintenance_check_fire_collapse(void) {
127127
int max_id = building_get_highest_id();
128128

129129
buildings_valid_do([&] (building &b) {
130-
if (b.fire_proof) {
131-
return;
132-
}
133-
134130
const model_building *model = model_get_building(b.type);
135131

136132
/////// COLLAPSE
@@ -150,34 +146,21 @@ void building_maintenance_check_fire_collapse(void) {
150146
}
151147

152148
/////// FIRE
153-
int random_building = (b.id + map_random_get(b.tile.grid_offset())) & 7;
154-
if (random_building == random_global) {
149+
int random_building = (b.id + map_random_get(b.tile)) & 7;
150+
if (!b.fire_proof && random_building == random_global) {
155151
b.fire_risk += model->fire_risk;
156-
int expected_fire_risk = 0;
157-
auto house = b.dcast_house();
158-
if (!house) {
159-
expected_fire_risk += 50;
160-
} else if (house && house->house_population() <= 0) {
161-
expected_fire_risk = 0;
162-
} else if (house && house->house_level() <= HOUSE_COMMON_SHANTY) {
163-
expected_fire_risk += 100;
164-
} else if (house && house->house_level() <= HOUSE_COMMON_MANOR) {
165-
expected_fire_risk += 50;
166-
} else {
167-
expected_fire_risk += 20;
168-
}
169-
170-
if (tutorial_extra_fire_risk()) {
171-
expected_fire_risk += 50;
172-
}
152+
153+
int expected_fire_risk = building_impl::params(b.type).fire_risk_update;
173154

155+
expected_fire_risk += scenario_additional_fire_damage(b.type);
174156
expected_fire_risk = b.dcast()->get_fire_risk(expected_fire_risk);
175157
b.fire_risk += expected_fire_risk;
176158
// if (climate == CLIMATE_NORTHERN)
177159
// b->fire_risk = 0;
178160
// else if (climate == CLIMATE_DESERT)
179161
// b->fire_risk += 30;
180162
}
163+
181164
if (b.fire_risk > 1000) {
182165
fire_building(&b);
183166
recalculate_terrain = 1;

src/game/tutorial.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ int tutorial_handle_fire() {
307307
return 0;
308308
}
309309

310-
g_tutorials_flags.tutorial_1.fire = 1;
310+
g_tutorials_flags.tutorial_1.fire = true;
311+
g_scenario_data.add_fire_damage.clear();
311312
building_menu_update(tutorial_stage.tutorial_fire);
312313
post_message(MESSAGE_TUTORIAL_FIRE_IN_THE_VILLAGE);
313314
return 1;

src/game/tutorial.h

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ int tutorial_get_immediate_goal_text();
9999

100100
int tutorial_adjust_request_year(int* year);
101101

102-
int tutorial_extra_fire_risk();
103102
int tutorial_extra_damage_risk();
104103

105104
int tutorial_handle_fire();

src/scenario/scenario.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,22 @@ void scenario_load_meta_data(const mission_id_t &missionid) {
5959
}
6060

6161
g_scenario_data.init_resources.clear();
62-
arch.r_array("resources", [&] (archive res) {
63-
e_resource resource = arch.r_type<e_resource>("resource");
64-
bool allowed = arch.r_bool("allowed");
62+
arch.r_objects("resources", [] (pcstr key, archive rarch) {
63+
e_resource resource = rarch.r_type<e_resource>("type");
64+
bool allowed = rarch.r_bool("allow");
6565
g_scenario_data.init_resources.push_back({ resource, allowed });
6666
});
6767

68+
g_scenario_data.add_fire_damage.clear();
69+
arch.r_objects("fire_damage", [&] (pcstr key, archive barch) {
70+
e_building_type type = barch.r_type<e_building_type>("type");
71+
int8_t value = barch.r_int("value");
72+
g_scenario_data.add_fire_damage.push_back({ type, value });
73+
});
74+
6875
g_scenario_data.building_stages.clear();
69-
arch.r_objects("stages", [](pcstr key, archive stage_arch) {
70-
auto buildings = archive::r_array_num<e_building_type>(stage_arch);
76+
arch.r_objects("stages", [](pcstr key, archive sarch) {
77+
auto buildings = archive::r_array_num<e_building_type>(sarch);
7178
g_scenario_data.building_stages.push_back({key, buildings});
7279
});
7380
});
@@ -125,6 +132,12 @@ bool scenario_is_mission_rank(custom_span<int> missions) {
125132
return false;
126133
}
127134

135+
int scenario_additional_fire_damage(e_building_type type) {
136+
const auto &dmg = g_scenario_data.add_fire_damage;
137+
auto it = std::find_if(dmg.begin(), dmg.end(), [type] (auto &i) { return i.type == type; });
138+
return (it != dmg.end()) ? it->value : 0;
139+
}
140+
128141
int scenario_is_before_mission(int mission) {
129142
return !g_scenario_data.settings.is_custom && g_scenario_data.settings.campaign_mission_rank < mission;
130143
}

src/scenario/scenario.h

+22-15
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ struct demand_change_t {
156156
int is_rise;
157157
};
158158

159+
struct add_fire_damage_t {
160+
e_building_type type;
161+
int8_t value;
162+
};
163+
159164
struct building_stage_t {
160165
xstring key;
161166
std::vector<e_building_type> buildings;
@@ -263,7 +268,7 @@ struct scenario_data_t {
263268

264269
bool allowed_buildings[BUILDING_MAX] = { 0 };
265270
std::vector<resource_allow> init_resources;
266-
271+
std::vector<add_fire_damage_t> add_fire_damage;
267272
std::vector<building_stage_t> building_stages;
268273

269274
struct {
@@ -334,39 +339,41 @@ bool scenario_is_mission_rank(const Args ... args) {
334339
return scenario_is_mission_rank(make_span(values));
335340
}
336341

342+
int scenario_additional_fire_damage(e_building_type type);
343+
337344
int scenario_is_before_mission(int mission);
338345

339-
int scenario_starting_kingdom(void);
346+
int scenario_starting_kingdom();
340347

341-
int scenario_starting_personal_savings(void);
348+
int scenario_starting_personal_savings();
342349

343-
const uint8_t* scenario_name(void);
350+
const uint8_t* scenario_name();
344351

345352
void scenario_set_name(const uint8_t* name);
346353

347-
int scenario_is_open_play(void);
354+
int scenario_is_open_play();
348355

349-
int scenario_open_play_id(void);
356+
int scenario_open_play_id();
350357

351-
int scenario_property_climate(void);
358+
int scenario_property_climate();
352359

353-
int scenario_property_start_year(void);
360+
int scenario_property_start_year();
354361

355362
int scenario_property_kingdom_supplies_grain();
356363

357-
int scenario_property_enemy(void);
364+
int scenario_property_enemy();
358365

359-
int scenario_property_player_rank(void);
366+
int scenario_property_player_rank();
360367

361-
int scenario_image_id(void);
368+
int scenario_image_id();
362369

363-
const uint8_t* scenario_subtitle(void);
370+
const uint8_t* scenario_subtitle();
364371

365-
int scenario_initial_funds(void);
372+
int scenario_initial_funds();
366373

367-
int scenario_rescue_loan(void);
374+
int scenario_rescue_loan();
368375

369-
int scenario_property_monuments_is_enabled(void);
376+
int scenario_property_monuments_is_enabled();
370377
int scenario_property_monument(int field);
371378
void scenario_set_monument(int field, int m);
372379

src/scripts/buildings.js

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ building_house_crude_hut = {
113113
},
114114
building_size : 1,
115115
num_types : 2,
116+
fire_risk_update : 100,
116117
is_draggable : true,
117118
window_info_height_id : 5,
118119
}
@@ -123,6 +124,7 @@ building_house_sturdy_hut = {
123124
minimap: {pack: PACK_GENERAL, id:148},
124125
},
125126
building_size : 1,
127+
fire_risk_update : 100,
126128
num_types : 2,
127129
window_info_height_id : 5,
128130
}
@@ -133,6 +135,7 @@ building_house_meager_shanty = {
133135
minimap: {pack: PACK_GENERAL, id:148},
134136
},
135137
building_size : 1,
138+
fire_risk_update : 100,
136139
num_types : 2,
137140
window_info_height_id : 5,
138141
}
@@ -143,6 +146,7 @@ building_house_common_shanty = {
143146
minimap: {pack: PACK_GENERAL, id:148},
144147
},
145148
building_size : 1,
149+
fire_risk_update : 100,
146150
num_types : 2,
147151
window_info_height_id : 5,
148152
}

src/scripts/missions.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ var mission0 = { // Nubt
1515
gods_least_mood : 50,
1616
religion_enabled : false,
1717
player_rank : 0,
18+
19+
fire_damage : {
20+
house0: { type:BUILDING_HOUSE_CRUDE_HUT, value: +50 },
21+
house1: { type:BUILDING_HOUSE_STURDY_HUT, value: +50 },
22+
house2: { type:BUILDING_HOUSE_STURDY_HUT, value: +50 },
23+
},
24+
1825
stages : {
1926
tutorial_fire: [BUILDING_FIREHOUSE],
2027
tutorial_food: [BUILDING_HUNTING_LODGE, BUILDING_GRANARY, BUILDING_BAZAAR],
@@ -371,9 +378,13 @@ var mission9 = { // Abu
371378
choice_image1_pos : [192, 144],
372379
choice_title : [144, 22],
373380

374-
resources : [
375-
RESOURCE_GRAIN, RESOURCE_BARLEY, RESOURCE_FLAX, RESOURCE_LETTUCE, RESOURCE_CHICKPEAS
376-
],
381+
resources : {
382+
grain : { type:RESOURCE_GRAIN, allow: true},
383+
barley: { type:RESOURCE_BARLEY, allow: true},
384+
flax: { type:RESOURCE_FLAX, allow:true},
385+
lettuce: { type:RESOURCE_LETTUCE, allow:true},
386+
chickpeas: { type:RESOURCE_CHICKPEAS, allow:true},
387+
},
377388

378389
buildings : [
379390
BUILDING_SMALL_STATUE, BUILDING_MEDIUM_STATUE, BUILDING_LARGE_STATUE, BUILDING_GARDENS, BUILDING_PLAZA,

0 commit comments

Comments
 (0)