Skip to content

Commit 5965dda

Browse files
committed
buildings: warship wharf now request for works and show animation
1 parent 5a44905 commit 5965dda

11 files changed

+107
-31
lines changed

src/building/building_fishing_wharf.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,6 @@ void building_fishing_wharf::update_graphic() {
108108
set_animation(animkey);
109109
}
110110

111-
void building_fishing_wharf::on_tick(bool refresh_only) {
112-
auto &anim_wharf = base.anim;
113-
if (anim_wharf.valid()) {
114-
data.dock.docker_anim_frame++;
115-
data.dock.docker_anim_frame %= (anim_wharf.max_frames * anim_wharf.frame_duration);
116-
}
117-
}
118-
119111
void building_fishing_wharf::spawn_figure() {
120112
check_labor_problem();
121113

src/building/building_fishing_wharf.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class building_fishing_wharf : public building_industry {
1818
virtual void update_count() const override;
1919
virtual void update_day() override;
2020
virtual void update_graphic() override;
21-
virtual void on_tick(bool refresh_only) override;
2221
virtual void spawn_figure() override;
2322
virtual void on_place_checks() override;
2423
virtual void on_undo() override;

src/building/building_warship_wharf.cpp

+31-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#include "js/js_game.h"
44
#include "city/labor.h"
55
#include "grid/water.h"
6+
#include "grid/figure.h"
7+
#include "grid/image.h"
68
#include "grid/building_tiles.h"
9+
#include "city/city.h"
10+
#include "building/count.h"
711

812
building_warship_wharf::static_params warship_wharf_m;
913

1014
void building_warship_wharf::static_params::load(archive arch) {
1115
}
1216

13-
void building_warship_wharf::on_create(int orientation) {
14-
data.wharf.orientation = orientation;
15-
}
16-
1717
void building_warship_wharf::on_place(int orientation, int variant) {
1818
int orientation_rel = city_view_relative_orientation(orientation);
1919
map_water_add_building(id(), tile(), params().building_size, anim(animkeys().base).first_img() + orientation_rel);
@@ -32,6 +32,31 @@ void building_warship_wharf::update_map_orientation(int orientation) {
3232
map_water_add_building(id(), tile(), size(), image_id);
3333
}
3434

35-
void building_warship_wharf::bind_dynamic(io_buffer *iob, size_t version) {
36-
iob->bind(BIND_SIGNATURE_UINT8, &data.wharf.orientation);
35+
void building_warship_wharf::spawn_figure() {
36+
check_labor_problem();
37+
38+
if (has_road_access()) {
39+
common_spawn_labor_seeker(100);
40+
}
41+
}
42+
43+
void building_warship_wharf::update_count() const {
44+
if (num_workers() > 0 && base.has_open_water_access) {
45+
const figure *boat = get_figure(BUILDING_SLOT_BOAT);
46+
if (!boat->is_valid()) {
47+
g_city.buildings.request_warship_boat();
48+
}
49+
}
50+
51+
building_increase_type_count(BUILDING_WARSHIP_WHARF, num_workers() > 0);
52+
}
53+
54+
bool building_warship_wharf::ship_moored() const {
55+
figure *f = base.get_figure(BUILDING_SLOT_BOAT);
56+
if (!f->is_valid()) {
57+
return false;
58+
}
59+
60+
const bool moored = f->action_state == FIGURE_ACTION_203_WARSHIP_MOORED;
61+
return moored;
3762
}

src/building/building_warship_wharf.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ class building_warship_wharf : public building_wharf {
1111
virtual void load(archive arch) override;
1212
};
1313

14-
virtual void on_create(int orientation) override;
1514
virtual void on_place(int orientation, int variant) override;
1615
virtual void on_place_update_tiles(int orientation, int variant) override;
1716
virtual void update_map_orientation(int orientation) override;
18-
virtual void bind_dynamic(io_buffer *iob, size_t version) override;
17+
virtual void spawn_figure() override;
18+
virtual void update_count() const override;
19+
virtual bool ship_moored() const override;
1920

2021
static const static_params &current_params() { return (const static_params &)params(TYPE); }
2122
};

src/building/building_wharf.cpp

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "building_wharf.h"
22

3-
#include "js/js_game.h"
43
#include "city/labor.h"
54
#include "grid/water.h"
5+
#include "grid/image.h"
66

77
building_transport_wharf::static_params transport_wharf_m;
88

@@ -18,3 +18,52 @@ void building_wharf::on_place_update_tiles(int orientation, int variant) {
1818
int orientation_rel = city_view_relative_orientation(orientation);
1919
map_water_add_building(id(), tile(), transport_wharf_m.building_size, anim(animkeys().base).first_img() + orientation_rel);
2020
}
21+
22+
void building_wharf::bind_dynamic(io_buffer *iob, size_t version) {
23+
iob->bind(BIND_SIGNATURE_UINT8, &data.wharf.orientation);
24+
}
25+
26+
inline void building_wharf::on_tick(bool refresh_only) {
27+
auto &anim_wharf = base.anim;
28+
if (anim_wharf.valid()) {
29+
data.dock.docker_anim_frame++;
30+
data.dock.docker_anim_frame %= (anim_wharf.max_frames * anim_wharf.frame_duration);
31+
}
32+
}
33+
34+
void building_wharf::update_graphic() {
35+
building_impl::update_graphic();
36+
37+
if (!can_play_animation()) {
38+
set_animation(animkeys().none);
39+
return;
40+
}
41+
42+
int image_warf = map_image_at(tile());
43+
int image_warf_base = anim(animkeys().base).first_img();
44+
xstring animkey;
45+
if (!ship_moored()) {
46+
if (image_warf == image_warf_base) animkey = animkeys().wait_n;
47+
else if (image_warf == image_warf_base + 1) animkey = animkeys().wait_w;
48+
else if (image_warf == image_warf_base + 2) animkey = animkeys().wait_s;
49+
else animkey = animkeys().wait_e;
50+
} else {
51+
if (image_warf == image_warf_base) animkey = animkeys().work_n;
52+
else if (image_warf == image_warf_base + 1) animkey = animkeys().work_w;
53+
else if (image_warf == image_warf_base + 2) animkey = animkeys().work_s;
54+
else animkey = animkeys().work_e;
55+
}
56+
57+
set_animation(animkey);
58+
}
59+
60+
bool building_wharf::draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color color_mask) {
61+
auto &anim_wharf = base.anim;
62+
if (anim_wharf.valid()) {
63+
int img_id = anim_wharf.start() + (data.dock.docker_anim_frame / anim_wharf.frame_duration) * 4;
64+
const image_t *img = image_get(img_id);
65+
ImageDraw::img_generic(ctx, img_id, point + anim_wharf.pos, color_mask, 1.f, true);
66+
}
67+
68+
return true;
69+
}

src/building/building_wharf.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ class building_wharf : public building_impl {
88

99
virtual void on_create(int orientation) override;
1010
virtual void on_place_update_tiles(int orientation, int variant) override;
11-
//virtual void window_info_background(object_info &c) override;
12-
//virtual void spawn_figure() override;
11+
virtual void on_tick(bool refresh_only) override;
12+
virtual void bind_dynamic(io_buffer *iob, size_t version) override;
13+
virtual void update_graphic() override;
14+
virtual bool draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color color_mask) override;
15+
16+
virtual bool ship_moored() const { return false; }
1317
};
1418

1519
class building_transport_wharf : public building_wharf {

src/building/building_workshop_papyrus.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020

2121
buildings::model_t<building_papyrus_maker> papyrus_maker_m;
2222

23-
ANK_REGISTER_CONFIG_ITERATOR(config_load_building_papyrus_maker);
24-
void config_load_building_papyrus_maker() {
25-
papyrus_maker_m.load();
26-
}
27-
2823
declare_console_command(addpapyrus, game_cheat_add_resource<RESOURCE_PAPYRUS>);
2924

3025
void building_papyrus_maker::on_create(int orientation) {
@@ -36,12 +31,12 @@ void building_papyrus_maker::update_count() const {
3631
}
3732

3833
bool building_papyrus_maker::draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color color_mask) {
39-
building_draw_normal_anim(ctx, point, &base, tile, papyrus_maker_m.anim["work"], color_mask);
34+
building_draw_normal_anim(ctx, point, &base, tile, anim(animkeys().work), color_mask);
4035

4136
int amount = std::min<int>(2, ceil((float)base.stored_amount() / 100.0) - 1);
4237
if (amount >= 0) {
43-
const auto &anim = papyrus_maker_m.anim["reed"];
44-
ImageDraw::img_generic(ctx, anim.first_img() + amount, point + anim.pos, color_mask);
38+
const auto &ranim = anim("reed");
39+
ImageDraw::img_generic(ctx, ranim.first_img() + amount, point + ranim.pos, color_mask);
4540
}
4641
return true;
4742
}

src/city/buildings.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct city_buildings_t {
3232
int8_t triumphal_arches_placed;
3333

3434
int8_t shipyard_boats_requested;
35+
int8_t warship_boats_requested;
3536

3637
using tracked_building_ids = std::vector<building_id>;
3738
using tracked_buildings_t = std::array<tracked_building_ids, BUILDING_MAX>;
@@ -69,6 +70,7 @@ struct city_buildings_t {
6970

7071
void clear_fishing_boat_requests() { shipyard_boats_requested = 0; }
7172
void request_fishing_boat() { ++shipyard_boats_requested; }
73+
void request_warship_boat() { ++warship_boats_requested; }
7274

7375
bool has_working_dock() const { return !tracked_buildings->at(BUILDING_DOCK).empty(); }
7476
bool has_working_shipyard() const { return !tracked_buildings->at(BUILDING_SHIPWRIGHT).empty(); }

src/city/city.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,9 @@ io_buffer* iob_city_data = new io_buffer([](io_buffer* iob, size_t version) {
763763
iob->bind(BIND_SIGNATURE_INT32, &data.unused.unused_4524[i]);
764764
}
765765

766-
iob->bind(BIND_SIGNATURE_INT32, &data.buildings.shipyard_boats_requested);
766+
iob->bind(BIND_SIGNATURE_INT8, &data.buildings.shipyard_boats_requested);
767+
iob->bind(BIND_SIGNATURE_INT8, &data.buildings.warship_boats_requested);
768+
iob->bind____skip(2);
767769
iob->bind(BIND_SIGNATURE_INT32, &data.figures.enemies);
768770
iob->bind(BIND_SIGNATURE_INT32, &data.sentiment.wages);
769771
iob->bind(BIND_SIGNATURE_INT32, &data.population.people_in_huts);

src/figure/action.h

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ enum e_figure_action {
181181
FIGURE_ACTION_200_HIPPODROME_HORSE_CREATED = 200,
182182
FIGURE_ACTION_201_HIPPODROME_HORSE_RACING = 201,
183183
FIGURE_ACTION_202_HIPPODROME_HORSE_DONE = 202,
184+
FIGURE_ACTION_203_WARSHIP_MOORED = 203,
184185

185186
FIGURE_ACTION_10_HIPPO_MOVING = 10,
186187
FIGURE_ACTION_19_HIPPO_IDLE = 19,

src/scripts/building_info.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,14 @@ building_warship_wharf = {
12141214
animations : {
12151215
preview : { pack:PACK_TERRAIN, id:28 },
12161216
base : { pack:PACK_TERRAIN, id:28 },
1217-
work_n : { pos:[135, -7], pack:PACK_SPR_AMBIENT, id:55, offset:3, max_frames:25, duration:8 },
1218-
// work : { pack:PACK_TERRAIN, id:18, offset:1 }
1217+
work_n : { pos:[65, 0], pack:PACK_SPR_AMBIENT, id:47, offset:0, max_frames:24, duration:1 },
1218+
work_w : { pos:[80, 7], pack:PACK_SPR_AMBIENT, id:47, offset:0, max_frames:24, duration:3 },
1219+
work_s : { pos:[65, 7], pack:PACK_SPR_AMBIENT, id:56, offset:1, max_frames:20, duration:4 },
1220+
work_e : { pos:[55, -27], pack:PACK_SPR_AMBIENT, id:46, offset:3, max_frames:24, duration:4 },
1221+
wait_n : { pos:[85, 20], pack:PACK_SPR_AMBIENT, id:55, offset:3, max_frames:25, duration:8 },
1222+
wait_w : { pos:[85, 7], pack:PACK_SPR_AMBIENT, id:55, offset:0, max_frames:25, duration:3 },
1223+
wait_s : { pos:[65, 22], pack:PACK_SPR_AMBIENT, id:55, offset:1, max_frames:25, duration:4 },
1224+
wait_e : { pos:[55, -27], pack:PACK_SPR_AMBIENT, id:55, offset:3, max_frames:25, duration:4 },
12191225
},
12201226
building_size : 3,
12211227
fire_proof : true,

0 commit comments

Comments
 (0)