|
32 | 32 | #include "overlays/city_overlay.h"
|
33 | 33 | #include "sound/sound_building.h"
|
34 | 34 | #include "city/city.h"
|
| 35 | +#include "figure/figure.h" |
| 36 | +#include "figuretype/figure_cartpusher.h" |
| 37 | +#include "config/config.h" |
35 | 38 |
|
36 | 39 | #include <string.h>
|
37 | 40 | #include <map>
|
@@ -523,6 +526,63 @@ bool building::is_military() {
|
523 | 526 | return building_is_military(type);
|
524 | 527 | }
|
525 | 528 |
|
| 529 | +figure *building::create_figure_generic(e_figure_type _type, e_figure_action created_action, e_building_slot slot, int created_dir) { |
| 530 | + figure *f = figure_create(_type, road_access, created_dir); |
| 531 | + f->action_state = created_action; |
| 532 | + f->set_home(id); |
| 533 | + set_figure(slot, f); |
| 534 | + |
| 535 | + return f; |
| 536 | +} |
| 537 | + |
| 538 | +figure *building::create_cartpusher(e_resource resource_id, int quantity, e_figure_action created_action, e_building_slot slot) { |
| 539 | + figure *f = create_figure_generic(FIGURE_CART_PUSHER, created_action, slot, DIR_4_BOTTOM_LEFT); |
| 540 | + auto cart = f->dcast_cartpusher(); |
| 541 | + if (!cart) { |
| 542 | + return f; |
| 543 | + } |
| 544 | + |
| 545 | + cart->load_resource(resource_id, quantity); |
| 546 | + cart->set_destination(0); |
| 547 | + cart->base.immigrant_home_building_id = 0; |
| 548 | + |
| 549 | + set_figure(slot, cart->id()); // warning: this overwrites any existing figure! |
| 550 | + if (config_get(CONFIG_GP_CH_CART_SPEED_QUANTITY)) { |
| 551 | + f->progress_inside_speed = std::clamp(quantity / 400, 0, 2); |
| 552 | + } |
| 553 | + cart->wait_ticks = 30; |
| 554 | + |
| 555 | + return f; |
| 556 | +} |
| 557 | + |
| 558 | +figure *building::create_figure_with_destination(e_figure_type _type, building *destination, e_figure_action created_action, e_building_slot slot) { |
| 559 | + figure *f = create_figure_generic(_type, created_action, slot, DIR_4_BOTTOM_LEFT); |
| 560 | + f->set_destination(destination->id); |
| 561 | + f->immigrant_home_building_id = 0; |
| 562 | + |
| 563 | + set_figure(slot, f->id); // warning: this overwrites any existing figure! |
| 564 | + return f; |
| 565 | +} |
| 566 | + |
| 567 | +figure *building::create_roaming_figure(e_figure_type _type, e_figure_action created_action, e_building_slot slot) { |
| 568 | + figure *f = create_figure_generic(_type, created_action, slot, figure_roam_direction); |
| 569 | + |
| 570 | + f->set_destination(0); |
| 571 | + f->immigrant_home_building_id = 0; |
| 572 | + |
| 573 | + set_figure(slot, f->id); // warning: this overwrites any existing figure! |
| 574 | + f->init_roaming_from_building(figure_roam_direction); |
| 575 | + f->set_home(id); |
| 576 | + |
| 577 | + // update building to have a different roamer direction for next time |
| 578 | + figure_roam_direction += 2; |
| 579 | + if (figure_roam_direction > 6) { |
| 580 | + figure_roam_direction = 0; |
| 581 | + } |
| 582 | + |
| 583 | + return f; |
| 584 | +} |
| 585 | + |
526 | 586 | ///////////////
|
527 | 587 |
|
528 | 588 | bool building_is_fort(int type) {
|
|
0 commit comments