Skip to content

Commit a8635db

Browse files
author
s.kushnirenko
committed
feat: add building_well class definition
what: + add implementation for updating well image based on average desirability +add window info background for well building
1 parent 5f3341a commit a8635db

12 files changed

+67
-43
lines changed

src/building/building.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "building/building_booth.h"
1717
#include "building/building_health.h"
1818
#include "building/building_pottery.h"
19+
#include "building/building_well.h"
1920
#include "city/buildings.h"
2021
#include "city/population.h"
2122
#include "city/warning.h"
@@ -330,6 +331,7 @@ building_impl *building::dcast() {
330331
case BUILDING_BOOTH: _ptr = new building_booth(*this); break;
331332
case BUILDING_APOTHECARY: _ptr = new building_apothecary(*this); break;
332333
case BUILDING_POTTERY_WORKSHOP: _ptr = new building_pottery(*this); break;
334+
case BUILDING_WELL: _ptr = new building_well(*this); break;
333335

334336
case BUILDING_SMALL_MASTABA:
335337
case BUILDING_SMALL_MASTABA_SIDE:
@@ -497,14 +499,11 @@ e_overlay building::get_overlay() const {
497499
case BUILDING_JUGGLER_SCHOOL:
498500
return OVERLAY_BOOTH;
499501

500-
case BUILDING_WELL:
501-
return OVERLAY_WATER;
502-
503502
case BUILDING_PHYSICIAN:
504503
return OVERLAY_PHYSICIAN;
505504
}
506505

507-
return OVERLAY_NONE;
506+
return const_cast<building*>(this)->dcast()->get_overlay();
508507
}
509508

510509
void building_clear_all() {

src/building/building.h

+4
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,13 @@ class building_impl {
383383
virtual void on_create() {}
384384
virtual void spawn_figure() {}
385385
virtual void update_graphic() {}
386+
virtual void update_month() {}
386387
virtual void update_day() {}
387388
virtual void window_info_background(object_info &ctx) {}
388389
virtual void window_info_foreground(object_info &ctx) {}
389390
virtual bool draw_ornaments_and_animations_height(vec2i point, tile2i tile, painter &ctx);
391+
virtual e_overlay get_overlay() const { return OVERLAY_NONE; }
392+
virtual bool need_road_access() const { return true; }
390393

391394
inline bool is_main() { return base.is_main(); }
392395
inline figure *create_roaming_figure(e_figure_type _type, e_figure_action created_action, e_building_slot slot) { return base.create_roaming_figure(_type, created_action, slot); }
@@ -395,6 +398,7 @@ class building_impl {
395398
inline tile2i tile() const { return base.tile; }
396399
inline e_building_type type() const { return base.type; }
397400

401+
398402
building &base;
399403
building::impl_data_t &data;
400404
};

src/building/building_well.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "building_well.h"
2+
3+
#include "grid/desirability.h"
4+
#include "grid/image.h"
5+
#include "grid/water_supply.h"
6+
#include "window/building/common.h"
7+
#include "graphics/elements/panel.h"
8+
#include "graphics/elements/lang_text.h"
9+
10+
void building_well::update_month() {
11+
int avg_desirability = map_desirabilty_avg(tile(), 4);
12+
map_image_set(tile(), avg_desirability > 30 ? IMG_WELL_FANCY : IMG_WELL);
13+
}
14+
15+
void building_well::window_info_background(object_info &c) {
16+
c.help_id = 62;
17+
window_building_play_sound(&c, "wavs/well.wav");
18+
outer_panel_draw(c.offset, c.width_blocks, c.height_blocks);
19+
lang_text_draw_centered(109, 0, c.offset.x, c.offset.y + 10, 16 * c.width_blocks, FONT_LARGE_BLACK_ON_LIGHT);
20+
int well_necessity = map_water_supply_is_well_unnecessary(c.building_id, 2);
21+
int text_id = 0;
22+
if (well_necessity == WELL_NECESSARY) { // well is OK
23+
text_id = 1;
24+
} else if (well_necessity == WELL_UNNECESSARY_FOUNTAIN) { // all houses have fountain
25+
text_id = 2;
26+
} else if (well_necessity == WELL_UNNECESSARY_NO_HOUSES) { // no houses around
27+
text_id = 3;
28+
}
29+
30+
if (text_id) {
31+
window_building_draw_description_at(c, 16 * c.height_blocks - 160, 109, text_id);
32+
}
33+
}

src/building/building_well.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include "building/building.h"
4+
5+
class building_well : public building_impl {
6+
public:
7+
building_well(building &b) : building_impl(b) {}
8+
//virtual void on_create() override;
9+
virtual void update_month() override;
10+
virtual bool need_road_access() const { return false; }
11+
virtual void window_info_background(object_info &ctx) override;
12+
};

src/building/figure.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1136,10 +1136,8 @@ void building::update_month() {
11361136
}
11371137
break;
11381138

1139-
case BUILDING_WELL: {
1140-
int avg_desirability = map_desirabilty_avg(tile, 4);
1141-
map_image_set(tile, avg_desirability > 30 ? IMG_WELL_FANCY : IMG_WELL);
1142-
}
1139+
default:
1140+
dcast()->update_month();
11431141
break;
11441142
}
11451143
}

src/city/warnings.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

3-
#include "building/building_type.h"
4-
#include "grid/point.h"
3+
#include "building/building.h"
54

65
void building_construction_warning_reset(void);
76
void building_construction_warning_check_food_stocks(int type);

src/grid/terrain.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ void map_terrain_add_in_area(int x_min, int y_min, int x_max, int y_max, int ter
4545
}
4646
}
4747
}
48-
void map_terrain_add_with_radius(int x, int y, int size, int radius, int terrain) {
49-
grid_area area = map_grid_get_area(tile2i(x, y), size, radius);
48+
void map_terrain_add_with_radius(tile2i tile, int size, int radius, int terrain) {
49+
grid_area area = map_grid_get_area(tile, size, radius);
5050

51-
map_grid_area_foreach(area.tmin, area.tmax, [&] (tile2i tile) {
52-
map_terrain_add(tile.grid_offset(), terrain);
51+
map_grid_area_foreach(area.tmin, area.tmax, [&] (tile2i t) {
52+
map_terrain_add(t.grid_offset(), terrain);
5353
});
5454
}
5555
void map_terrain_remove_with_radius(int x, int y, int size, int radius, int terrain) {

src/grid/terrain.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void map_terrain_remove(int grid_offset, int terrain);
9191

9292
void map_terrain_add_in_area(int x_min, int y_min, int x_max, int y_max, int terrain);
9393

94-
void map_terrain_add_with_radius(int x, int y, int size, int radius, int terrain);
94+
void map_terrain_add_with_radius(tile2i tile, int size, int radius, int terrain);
9595

9696
void map_terrain_remove_with_radius(int x, int y, int size, int radius, int terrain);
9797

src/grid/water_supply.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ void map_water_supply_update_houses() {
6363
} else if (b.house_size) {
6464
b.has_water_access = false;
6565
b.has_well_access = 0;
66-
if (b.data.house.water_supply
67-
|| map_terrain_exists_tile_in_area_with_type(b.tile.x(), b.tile.y(), b.size, TERRAIN_FOUNTAIN_RANGE)) {
66+
if (b.data.house.water_supply|| map_terrain_exists_tile_in_area_with_type(b.tile.x(), b.tile.y(), b.size, TERRAIN_FOUNTAIN_RANGE)) {
6867
b.has_water_access = true;
6968
}
7069
}
@@ -120,7 +119,7 @@ static void fill_canals_from_offset(int grid_offset) {
120119
if (image_id >= image_without_water) {
121120
map_image_set(grid_offset, image_id - IMAGE_CANAL_FULL_OFFSET);
122121
}
123-
map_terrain_add_with_radius(MAP_X(grid_offset), MAP_Y(grid_offset), 1, 2, TERRAIN_IRRIGATION_RANGE);
122+
map_terrain_add_with_radius(tile2i(grid_offset), 1, 2, TERRAIN_IRRIGATION_RANGE);
124123

125124
next_offset = -1;
126125
for (int i = 0; i < 4; i++) {
@@ -201,7 +200,7 @@ static void update_canals_from_water_lifts() {
201200
if (b->has_water_access) {
202201
fill_canals_from_offset(b->tile.grid_offset() + OUTPUT_OFFSETS[b->data.industry.orientation][0]);
203202
fill_canals_from_offset(b->tile.grid_offset() + OUTPUT_OFFSETS[b->data.industry.orientation][1]);
204-
map_terrain_add_with_radius(b->tile.x(), b->tile.y(), 2, 2, TERRAIN_IRRIGATION_RANGE);
203+
map_terrain_add_with_radius(b->tile, 2, 2, TERRAIN_IRRIGATION_RANGE);
205204
}
206205
}
207206
}
@@ -219,14 +218,12 @@ void map_update_canals(void) {
219218
update_canals_from_water_lifts();
220219
}
221220

222-
void map_update_wells_range(void) {
221+
void map_update_wells_range() {
223222
OZZY_PROFILER_SECTION("Game/Run/Tick/Wells Range Update");
224223
map_terrain_remove_all(TERRAIN_FOUNTAIN_RANGE);
225-
buildings_valid_do([&](building& b) {
226-
if (b.type == BUILDING_WELL) {
227-
map_terrain_add_with_radius(b.tile.x(), b.tile.y(), 1, 3, TERRAIN_FOUNTAIN_RANGE);
228-
}
229-
});
224+
buildings_valid_do([](building& b) {
225+
map_terrain_add_with_radius(b.tile, 1, 3, TERRAIN_FOUNTAIN_RANGE);
226+
}, BUILDING_WELL);
230227
}
231228

232229
e_well_status map_water_supply_is_well_unnecessary(int well_id, int radius) {

src/window/building/utility.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,6 @@ void window_building_draw_water_supply(object_info* c) {
220220
inner_panel_draw(c->offset.x + 16, c->offset.y + 144, c->width_blocks - 2, 4);
221221
window_building_draw_employment(c, 150);
222222
}
223-
void window_building_draw_well(object_info* c) {
224-
c->help_id = 62;
225-
window_building_play_sound(c, "wavs/well.wav");
226-
outer_panel_draw(c->offset, c->width_blocks, c->height_blocks);
227-
lang_text_draw_centered(109, 0, c->offset.x, c->offset.y + 10, 16 * c->width_blocks, FONT_LARGE_BLACK_ON_LIGHT);
228-
int well_necessity = map_water_supply_is_well_unnecessary(c->building_id, 2);
229-
int text_id = 0;
230-
if (well_necessity == WELL_NECESSARY) // well is OK
231-
text_id = 1;
232-
else if (well_necessity == WELL_UNNECESSARY_FOUNTAIN) // all houses have fountain
233-
text_id = 2;
234-
else if (well_necessity == WELL_UNNECESSARY_NO_HOUSES) // no houses around
235-
text_id = 3;
236-
if (text_id)
237-
window_building_draw_description_at(c, 16 * c->height_blocks - 160, 109, text_id);
238-
}
239223

240224
void window_building_draw_mission_post(object_info* c) {
241225
c->help_id = 8;

src/window/building/utility.h

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ void window_building_draw_water_lift(object_info* c);
1919
void window_building_draw_aqueduct(object_info* c);
2020
void window_building_draw_fountain(object_info* c);
2121
void window_building_draw_water_supply(object_info* c);
22-
void window_building_draw_well(object_info* c);
2322

2423
void window_building_draw_mission_post(object_info* c);
2524
void window_building_draw_native_hut(object_info* c);

src/window/window_building_info.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ static void draw_refresh_background() {
727727
case BUILDING_WATER_LIFT: window_building_draw_water_lift(&context); break;
728728
case BUILDING_MENU_BEAUTIFICATION: window_building_draw_fountain(&context); break;
729729
case BUILDING_WATER_SUPPLY: window_building_draw_water_supply(&context); break;
730-
case BUILDING_WELL: window_building_draw_well(&context); break;
731730

732731
case BUILDING_SMALL_STATUE:
733732
case BUILDING_MEDIUM_STATUE:

0 commit comments

Comments
 (0)