Skip to content

Commit 8324a16

Browse files
committed
building: fixed searching free dock for trade ship
1 parent 796c863 commit 8324a16

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/building/building_dock.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int building_dock::trader_city_id() {
191191
: 0;
192192
}
193193

194-
bool building_dock::is_good_accepted(e_resource r) {
194+
bool building_dock::is_trade_accepted(e_resource r) {
195195
return data.dock.trading_goods.is_set(r);
196196
}
197197

@@ -209,15 +209,14 @@ bool building_dock_accepts_ship(int ship_id, int dock_id) {
209209

210210
empire_city* city = g_empire.city(f->empire_city_id);
211211
const resource_list resources = city_resource_get_available();
212+
int any_acceptance = 0;
212213
for (auto r: resources) {
213214
if (city->sells_resource[r.type] || city->buys_resource[r.type]) {
214-
if (!dock->is_good_accepted(r.type)) {
215-
dock_id = 0;
216-
return false;
217-
}
215+
any_acceptance += dock->is_trade_accepted(r.type) ? 1 : 0;
218216
}
219217
}
220-
return true;
218+
219+
return (any_acceptance > 0);
221220
}
222221

223222
building_dest map_get_free_destination_dock(int ship_id) {
@@ -227,17 +226,21 @@ building_dest map_get_free_destination_dock(int ship_id) {
227226
int dock_id = 0;
228227
for (int i = 0; i < 10; i++) {
229228
dock_id = city_buildings_get_working_dock(i);
230-
if (!dock_id)
229+
if (!dock_id) {
231230
continue;
231+
}
232+
232233
if (!building_dock_accepts_ship(ship_id, dock_id)) {
233234
dock_id = 0;
234235
continue;
235236
}
236237

237238
building* dock = building_get(dock_id);
238-
if (!dock->data.dock.trade_ship_id || dock->data.dock.trade_ship_id == ship_id)
239+
if (!dock->data.dock.trade_ship_id || dock->data.dock.trade_ship_id == ship_id) {
239240
break;
241+
}
240242
}
243+
241244
// BUG: when 10 docks in city, always takes last one... regardless of whether it is free
242245
if (dock_id <= 0)
243246
return {0, tile2i::invalid};

src/building/building_dock.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class building_dock : public building_impl {
2828
void unaccept_all_goods();
2929
int trader_id();
3030
int trader_city_id();
31-
bool is_good_accepted(e_resource r);
31+
bool is_trade_accepted(e_resource r);
3232
void toggle_good_accepted(e_resource r);
3333
int count_idle_dockers() const;
3434

src/window/window_info_dock.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void dock_orders_window::window_info_foreground(object_info &c) {
103103
ui.icon(items_area.pos + item_icon_column.pos + vec2i{ 0, row_y }, r.type);
104104
ui.label(ui::str(23, r.type), items_area.pos + item_name_column.pos + vec2i{ 0, row_y });
105105

106-
auto status = window_dock_get_order_instruction(INSTR_DOCK, r.type, dock->is_good_accepted(r.type));
106+
auto status = window_dock_get_order_instruction(INSTR_DOCK, r.type, dock->is_trade_accepted(r.type));
107107
ui.button(status.first, items_area.pos + vec2i{ item_orders_column.pos.x, row_y }, item_row.size, fonts_vec{ status.second }, UiFlags_NoBody | UiFlags_AlignYCentered)
108108
.onclick([building_id, resource = r.type] {
109109
building_dock *b = ::building_get(building_id)->dcast_dock();

0 commit comments

Comments
 (0)