Skip to content

Commit c6b9fac

Browse files
author
s.kushnirenko
committed
trade ship: correct wait on queue
1 parent c9ece0c commit c6b9fac

8 files changed

+39
-16
lines changed

src/building/building_dock.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ int building_dock::trader_id() {
323323
return figure_get(data.dock.trade_ship_id)->trader_id;
324324
}
325325

326+
int building_dock::trader_city_id() {
327+
return data.dock.trade_ship_id
328+
? figure_get(data.dock.trade_ship_id)->empire_city_id
329+
: 0;
330+
}
331+
326332
bool building_dock::is_good_accepted(int index) {
327333
int goods_bit = 1 << index;
328334
return !(base.subtype.market_goods & goods_bit);

src/building/building_dock.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class building_dock : public building_impl {
2525
virtual bool draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color color_mask) override;
2626

2727
int trader_id();
28+
int trader_city_id();
2829
bool is_good_accepted(int index);
2930
void toggle_good_accepted(int index);
3031
int count_idle_dockers() const;

src/figure/figure.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ const figure_impl::static_params &figure_impl::params(e_figure_type e) {
315315
return (it == figure_impl_params->end()) ? figure_impl::static_params::dummy : *it->second;
316316
}
317317

318+
void figure_impl::advance_action(int action, tile2i t) {
319+
advance_action(action);
320+
base.destination_tile = t;
321+
}
322+
318323
void figure_impl::set_destination(building *b, tile2i t) {
319324
base.set_destination(b);
320325
base.destination_tile = t;

src/figure/figure.h

+1
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ class figure_impl {
549549
inline uint8_t direction() const { return base.direction; }
550550
inline const building *home() const { return base.home(); }
551551
inline void advance_action(int action) { int saved_action = action; base.advance_action(action); on_action_changed(saved_action); }
552+
void advance_action(int action, tile2i t);
552553
virtual void on_action_changed(int saved_action) {}
553554
inline bool do_returnhome(e_terrain_usage terrainchoice, short next_action = -1) { return base.do_returnhome(terrainchoice, next_action); }
554555
inline bool do_gotobuilding(building *dest, bool stop_at_road = true, e_terrain_usage terrainchoice = TERRAIN_USAGE_ROADS, short NEXT_ACTION = -1, short FAIL_ACTION = -1) { return base.do_gotobuilding(dest, stop_at_road, terrainchoice, NEXT_ACTION, FAIL_ACTION); }

src/figuretype/figure_docker.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ int figure_docker::trader_id() {
239239
return dock->trader_id();
240240
}
241241

242+
int figure_docker::trader_city_id() {
243+
building_dock *dock = home()->dcast_dock();
244+
return dock->trader_city_id();
245+
}
246+
242247
bool figure_docker::deliver_import_resource(building* dock) {
243248
int ship_id = dock->data.dock.trade_ship_id;
244249
if (!ship_id) {
@@ -407,9 +412,13 @@ void figure_docker::figure_action() {
407412
break;
408413

409414
case FIGURE_ACTION_137_DOCKER_EXPORT_RETURNING:
410-
do_gotobuilding(destination(), true, TERRAIN_USAGE_ROADS, FIGURE_ACTION_134_DOCKER_EXPORT_QUEUE, ACTION_8_RECALCULATE);
411-
if (destination()->state != BUILDING_STATE_VALID)
415+
if (do_gotobuilding(destination(), true, TERRAIN_USAGE_ROADS, FIGURE_ACTION_134_DOCKER_EXPORT_QUEUE, ACTION_8_RECALCULATE)) {
416+
load_resource(RESOURCE_NONE, 0);
417+
}
418+
419+
if (destination()->state != BUILDING_STATE_VALID) {
412420
poof();
421+
}
413422
break;
414423

415424
case FIGURE_ACTION_138_DOCKER_IMPORT_RETURNING:
@@ -442,10 +451,7 @@ void figure_docker::figure_action() {
442451
case FIGURE_ACTION_140_DOCKER_EXPORT_AT_WAREHOUSE:
443452
wait_ticks++;
444453
if (wait_ticks > 10) {
445-
int trade_city_id = b->data.dock.trade_ship_id
446-
? figure_get(b->data.dock.trade_ship_id)->empire_city_id
447-
: 0;
448-
454+
int trade_city_id = trader_city_id();
449455
advance_action(FIGURE_ACTION_138_DOCKER_IMPORT_RETURNING);
450456
wait_ticks = 0;
451457
const bool can_export = try_export_resource(destination(), base.resource_id, trade_city_id);

src/figuretype/figure_docker.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class figure_docker : public figure_carrier {
1717
virtual void poof() override;
1818

1919
int trader_id();
20+
int trader_city_id();
2021
bool deliver_import_resource(building *dock);
2122
tile2i get_trade_center_location();
2223
bool fetch_export_resource(building* dock);

src/figuretype/figure_flotsam.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ void figure_flotsam::figure_action() {
3939
if (wait_ticks <= 0) {
4040
base.action_state = FIGURE_ACTION_129_FLOTSAM_FLOATING;
4141
wait_ticks = 0;
42-
if (!base.resource_id && city_god_osiris_create_shipwreck_flotsam())
42+
if (!base.resource_id && city_god_osiris_create_shipwreck_flotsam()) {
4343
base.min_max_seen = 1;
44+
}
4445

4546
destination_tile = scenario_map_river_exit();
46-
// map_point river_exit = scenario_map_river_exit();
47-
// destination_tile.x() = river_exit.x();
48-
// destination_tile.y() = river_exit.y();
4947
}
5048
break;
5149

src/figuretype/figure_trader_ship.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,8 @@ void figure_trade_ship::figure_action() {
140140
}
141141
}
142142
if (destination()->state != BUILDING_STATE_VALID) {
143-
base.action_state = FIGURE_ACTION_115_TRADE_SHIP_LEAVING;
143+
advance_action(FIGURE_ACTION_115_TRADE_SHIP_LEAVING, scenario_map_river_exit());
144144
base.wait_ticks = 0;
145-
base.destination_tile = scenario_map_river_exit();
146-
// map_point river_exit = scenario_map_river_exit();
147-
// destination_tile.x() = river_exit.x();
148-
// destination_tile.y() = river_exit.y();
149145
}
150146
break;
151147

@@ -211,6 +207,10 @@ void figure_trade_ship::figure_action() {
211207
base.action_state = FIGURE_ACTION_113_TRADE_SHIP_GOING_TO_DOCK_QUEUE;
212208
base.destination_tile = free_dock.tile;
213209
}
210+
211+
if (base.trade_ship_failed_dock_attempts >= 10) {
212+
advance_action(FIGURE_ACTION_115_TRADE_SHIP_LEAVING, scenario_map_river_exit());
213+
}
214214
base.wait_ticks = 0;
215215
}
216216
base.anim.frame = 0;
@@ -278,7 +278,7 @@ void figure_trade_ship::update_animation() {
278278
}
279279

280280
void figure_trade_ship::poof() {
281-
//
281+
figure_carrier::poof();
282282
}
283283

284284
const animations_t &figure_trade_ship::anim() const {
@@ -355,6 +355,11 @@ bool figure_trade_ship::window_info_background(object_info &c) {
355355
}
356356

357357
void figure_trade_ship::update_day() {
358+
const bool on_raid = action_state(FIGURE_ACTION_114_TRADE_SHIP_ANCHORED, FIGURE_ACTION_112_TRADE_SHIP_MOORED);
359+
if (!on_raid) {
360+
return;
361+
}
362+
358363
building* b = destination();
359364
for (const int docker_id: b->data.dock.docker_ids) {
360365
figure* docker = figure_get(docker_id);

0 commit comments

Comments
 (0)