Skip to content

Commit d34ff2d

Browse files
committed
restored logic for shipyard
1 parent c516847 commit d34ff2d

12 files changed

+85
-29
lines changed

src/building/building_shipyard.cpp

+57-16
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,36 @@ void building_shipyard::spawn_figure() {
4040
}
4141

4242
int pct_workers = worker_percentage();
43-
if (pct_workers >= 100)
44-
data.industry.progress += 10;
45-
else if (pct_workers >= 75)
46-
data.industry.progress += 8;
47-
else if (pct_workers >= 50)
48-
data.industry.progress += 6;
49-
else if (pct_workers >= 25)
50-
data.industry.progress += 4;
51-
else if (pct_workers >= 1)
52-
data.industry.progress += 2;
43+
if (pct_workers >= 100) data.industry.progress += 10;
44+
else if (pct_workers >= 75) data.industry.progress += 8;
45+
else if (pct_workers >= 50) data.industry.progress += 6;
46+
else if (pct_workers >= 25) data.industry.progress += 4;
47+
else if (pct_workers >= 1) data.industry.progress += 2;
5348

54-
if (data.industry.progress >= 160) {
49+
tile2i boat_tile;
50+
if (data.industry.progress >= 160 && map_water_can_spawn_boat(tile(), size(), boat_tile)) {
5551
data.industry.progress = 0;
56-
tile2i boat_tile;
57-
if (map_water_can_spawn_fishing_boat(tile(), size(), boat_tile)) {
52+
data.wharf.process_type = FIGURE_NONE;
53+
if (data.wharf.process_type == FIGURE_WARSHIP) {
54+
figure *f = figure_create(FIGURE_WARSHIP, boat_tile, DIR_0_TOP_RIGHT);
55+
f->action_state = FIGURE_ACTION_205_WARSHIP_CREATED;
56+
f->set_home(&base);
57+
base.set_figure(BUILDING_SLOT_BOAT, f);
58+
} else if (data.wharf.process_type == FIGURE_FISHING_BOAT) {
5859
figure *f = figure_create(FIGURE_FISHING_BOAT, boat_tile, DIR_0_TOP_RIGHT);
5960
f->action_state = FIGURE_ACTION_190_FISHING_BOAT_CREATED;
6061
f->set_home(&base);
6162
base.set_figure(BUILDING_SLOT_BOAT, f);
63+
} else {
64+
assert(false && "building_shipyard: incorrect type requested");
6265
}
6366
}
6467
}
6568

6669
void building_shipyard::bind_dynamic(io_buffer *iob, size_t version) {
6770
building_industry::bind_dynamic(iob, version);
6871

69-
data.industry.first_material_id = RESOURCE_BARLEY;
72+
data.industry.first_material_id = RESOURCE_TIMBER;
7073

7174
iob->bind(BIND_SIGNATURE_UINT8, &data.wharf.orientation);
7275
iob->bind(BIND_SIGNATURE_UINT8, &data.wharf.process_type);
@@ -80,8 +83,7 @@ void building_shipyard::update_map_orientation(int orientation) {
8083
}
8184

8285
bool building_shipyard::draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color mask) {
83-
const animation_t &canim = anim(animkeys().work);
84-
building_draw_normal_anim(ctx, point, &base, tile, canim, mask);
86+
draw_normal_anim(ctx, point, tile, mask);
8587

8688
int amount = ceil((float)base.stored_amount() / 100.0) - 1;
8789
if (amount >= 0) {
@@ -107,6 +109,45 @@ void building_shipyard::on_place_update_tiles(int orientation, int variant) {
107109
map_water_add_building(id(), tile(), size(), anim(animkeys().base).first_img() + orientation_rel);
108110
}
109111

112+
void building_shipyard::update_day() {
113+
if (data.wharf.process_type == FIGURE_WARSHIP && g_city.buildings.warship_boats_requested > 0) {
114+
g_city.buildings.warship_boats_requested--;
115+
return;
116+
}
117+
118+
if (data.wharf.process_type == FIGURE_FISHING_BOAT && g_city.buildings.fishing_boats_requested > 0) {
119+
g_city.buildings.fishing_boats_requested--;
120+
return;
121+
}
122+
123+
if (data.wharf.process_type == FIGURE_NONE) {
124+
if (g_city.buildings.warship_boats_requested > 0 && base.stored_full_amount > 400) {
125+
data.wharf.process_type = FIGURE_WARSHIP;
126+
g_city.buildings.warship_boats_requested--;
127+
return;
128+
}
129+
130+
if (g_city.buildings.fishing_boats_requested > 0) {
131+
data.wharf.process_type = FIGURE_FISHING_BOAT;
132+
g_city.buildings.fishing_boats_requested--;
133+
return;
134+
}
135+
136+
assert(false && "Should be a correct type for build");
137+
}
138+
}
139+
140+
void building_shipyard::update_graphic() {
141+
xstring animkey;
142+
switch (data.wharf.process_type) {
143+
case FIGURE_WARSHIP: animkey = animkeys().work_warship; break;
144+
case FIGURE_FISHING_BOAT: animkey = animkeys().work_fishing_boat; break;
145+
case FIGURE_TRANSPORT: animkey = animkeys().work_transport; break;
146+
}
147+
148+
set_animation(animkey);
149+
}
150+
110151
void building_shipyard::update_count() const {
111152
const bool is_active = (num_workers() > 0 && base.has_open_water_access);
112153
g_city.buildings.track_building(type(), id(), is_active);

src/building/building_shipyard.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class building_shipyard : public building_industry {
1515

1616
virtual void on_create(int orientation) override;
1717
virtual void on_place_update_tiles(int orientation, int variant) override;
18+
virtual void update_day() override;
19+
virtual void update_graphic() override;
1820
virtual void update_count() const override;
1921
virtual void spawn_figure() override;
2022
virtual void update_map_orientation(int orientation);

src/city/buildings.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ struct city_buildings_t {
3131
int8_t triumphal_arches_available;
3232
int8_t triumphal_arches_placed;
3333

34-
int8_t shipyard_boats_requested;
34+
int8_t fishing_boats_requested;
3535
int8_t warship_boats_requested;
36+
int8_t transport_boats_requested;
3637

3738
using tracked_building_ids = std::vector<building_id>;
3839
using tracked_buildings_t = std::array<tracked_building_ids, BUILDING_MAX>;
@@ -68,9 +69,10 @@ struct city_buildings_t {
6869
void track_building(e_building_type type, building_id id, bool active);
6970
const tracked_building_ids &track_buildings(e_building_type type) const { return tracked_buildings->at(type); }
7071

71-
void clear_fishing_boat_requests() { shipyard_boats_requested = 0; }
72-
void request_fishing_boat() { ++shipyard_boats_requested; }
72+
void clear_fishing_boat_requests() { fishing_boats_requested = 0; }
73+
void request_fishing_boat() { ++fishing_boats_requested; }
7374
void request_warship_boat() { ++warship_boats_requested; }
75+
void request_transport_boat() { ++transport_boats_requested; }
7476

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

src/city/city.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ 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_INT8, &data.buildings.shipyard_boats_requested);
766+
iob->bind(BIND_SIGNATURE_INT8, &data.buildings.fishing_boats_requested);
767767
iob->bind(BIND_SIGNATURE_INT8, &data.buildings.warship_boats_requested);
768768
iob->bind____skip(2);
769769
iob->bind(BIND_SIGNATURE_INT32, &data.figures.enemies);

src/figure/action.h

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ enum e_figure_action {
185185
FIGURE_ACTION_202_HIPPODROME_HORSE_DONE = 202,
186186
FIGURE_ACTION_203_WARSHIP_MOORED = 203,
187187
FIGURE_ACTION_204_WARSHIP_ATTACK = 204,
188+
FIGURE_ACTION_205_WARSHIP_CREATED = 205,
188189

189190
FIGURE_ACTION_10_HIPPO_MOVING = 10,
190191
FIGURE_ACTION_19_HIPPO_IDLE = 19,

src/figure/figure_type.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ enum e_figure_type {
111111
FIGURE_OSTRICH_HUNTER = 73,
112112
FIGURE_HUNTER_ARROW = 74,
113113
FIGURE_LUMBERJACK = 75,
114-
FIGURE_PHARAOH = 76,
115-
FIGURE_GOVERNOR = 77,
114+
FIGURE_FERRY_BOAT = 76,
115+
FIGURE_TRANSPORT = 77,
116116
FIGURE_WARSHIP = 78,
117117
FIGURE_CARPENTER = 79,
118118
FIGURE_BRICKLAYER = 80,
@@ -145,6 +145,8 @@ enum e_figure_type {
145145
FIGURE_LOCUST = 107,
146146
FIGURE_TOMB_ARTISAN = 108,
147147
FIGURE_MUMMY = 109,
148+
FIGURE_PHARAOH = 110,
149+
FIGURE_GOVERNOR = 111,
148150

149151
FIGURE_MAX,
150152
};

src/graphics/animkeys.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const xstring id_anim_t::square = "square";
3737
const xstring id_anim_t::juggler = "juggler";
3838
const xstring id_anim_t::barley = "barley";
3939
const xstring id_anim_t::wood = "wood";
40+
const xstring id_anim_t::work_warship = "work_warship";
41+
const xstring id_anim_t::work_fishing_boat = "work_fishing_boat";
42+
const xstring id_anim_t::work_transport = "work_transport";
4043

4144
const id_anim_t &animkeys() {
4245
return g_animkeys;

src/graphics/animkeys.h

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ struct id_anim_t {
3939
static const xstring juggler;
4040
static const xstring barley;
4141
static const xstring wood;
42+
static const xstring work_warship;
43+
static const xstring work_fishing_boat;
44+
static const xstring work_transport;
4245
};
4346

4447
const id_anim_t &animkeys();

src/grid/water.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static int num_surrounding_water_tiles(int grid_offset) {
339339
return amount;
340340
}
341341

342-
bool map_water_can_spawn_fishing_boat(tile2i tile, int size, tile2i &boat_tile) {
342+
bool map_water_can_spawn_boat(tile2i tile, int size, tile2i &boat_tile) {
343343
int base_offset = tile.grid_offset();
344344
offsets_array offsets;
345345
map_grid_adjacent_offsets(size, offsets);

src/grid/water.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ water_dest map_water_get_wharf_for_new_fishing_boat(figure &boat);
4444
water_dest map_water_find_alternative_fishing_boat_tile(figure &boat);
4545
water_dest map_water_find_shipwreck_tile(figure &wreck);
4646
void map_water_rebuild_shores();
47-
bool map_water_can_spawn_fishing_boat(tile2i tile, int size, tile2i &boat_tile);
47+
bool map_water_can_spawn_boat(tile2i tile, int size, tile2i &boat_tile);

src/scripts/building_info.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,10 @@ building_shipyard = {
12601260
animations : {
12611261
preview : { pack: PACK_TERRAIN, id:26, max_frames:1 },
12621262
base : { pack: PACK_TERRAIN, id:26, max_frames:1 },
1263-
work : { pos : [70, 20], pack:PACK_SPR_AMBIENT, id:54, max_frames: 11 },
1264-
wood : { pos : [65, 3], pack:PACK_GENERAL, id:202 }
1263+
wood : { pos : [65, 3], pack:PACK_GENERAL, id:202 },
1264+
work_warship : { pos : [70, 20], pack:PACK_SPR_AMBIENT, id:54, max_frames: 11 },
1265+
work_fishing_boat : { pos : [70, 20], pack:PACK_SPR_AMBIENT, id:54, max_frames: 11 },
1266+
work_transport : { pos : [70, 20], pack:PACK_SPR_AMBIENT, id:54, max_frames: 11 },
12651267
},
12661268
building_size : 3,
12671269
window_info_height_id : 1,

src/scripts/ui.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1330,9 +1330,9 @@ window shipyard_info_window = {
13301330
warning_text : text({pos: [28, 40], wrap:px(27), font : FONT_NORMAL_BLACK_ON_LIGHT, multiline:true }),
13311331
inner_panel : inner_panel({pos : [16, 150], size: [27, 5],
13321332
ui : {
1333-
workers_img : image({pack:PACK_GENERAL, id:134, offset:14, pos:[40, 10] }),
1334-
workers_text : text({pos: [70, 16], font: FONT_NORMAL_BLACK_ON_DARK}),
1335-
workers_desc : text({pos: [70, 16 + 16], font: FONT_NORMAL_BLACK_ON_DARK, multiline:true, wrap:px(24) }),
1333+
workers_img : image({pack:PACK_GENERAL, id:134, offset:14, pos:[20, 10] }),
1334+
workers_text : text({pos: [50, 16], font: FONT_NORMAL_BLACK_ON_DARK}),
1335+
workers_desc : text({pos: [50, 16 + 16], font: FONT_NORMAL_BLACK_ON_DARK, multiline:true, wrap:px(24) }),
13361336
}
13371337
}),
13381338
ready_prod : text({pos: [30, 110], size: [px(27), 20], font : FONT_NORMAL_BLACK_ON_LIGHT }),

0 commit comments

Comments
 (0)