|
6 | 6 | #include "modules/World.h" |
7 | 7 | #include "modules/Translation.h" |
8 | 8 | #include "modules/Materials.h" |
| 9 | +#include "modules/Maps.h" |
9 | 10 | #include "modules/Items.h" |
10 | 11 |
|
11 | 12 | #include "DataDefs.h" |
|
19 | 20 | #include "df/historical_figure.h" |
20 | 21 | #include "df/general_ref_is_nemesisst.h" |
21 | 22 | #include "df/general_ref_contains_itemst.h" |
| 23 | +#include "df/general_ref_contained_in_itemst.h" |
| 24 | +#include "df/general_ref_unit_holderst.h" |
22 | 25 | #include "df/general_ref_building_civzone_assignedst.h" |
23 | 26 | #include "df/material.h" |
24 | 27 | #include "df/craft_material_class.h" |
@@ -421,21 +424,27 @@ bool isWeaponArmor(df::item *item) |
421 | 424 | } |
422 | 425 | } |
423 | 426 |
|
424 | | -int containsMetalItems(df::item *item, bool all, bool non_trader) |
| 427 | +int containsMetalItems(df::item *item, bool all, bool non_trader, bool rec = false) |
425 | 428 | { |
426 | 429 | int cnt = 0; |
427 | 430 |
|
428 | 431 | auto &refs = item->itemrefs; |
429 | 432 | for (size_t i = 0; i < refs.size(); i++) |
430 | 433 | { |
431 | 434 | auto ref = refs[i]; |
432 | | - if (!strict_virtual_cast<df::general_ref_contains_itemst>(ref)) |
433 | | - continue; |
434 | 435 |
|
435 | | - df::item *child = ref->getItem(); |
436 | | - if (!child) continue; |
| 436 | + if (strict_virtual_cast<df::general_ref_unit_holderst>(ref)) |
| 437 | + return 0; |
| 438 | + if (!rec && strict_virtual_cast<df::general_ref_contained_in_itemst>(ref)) |
| 439 | + return 0; |
| 440 | + |
| 441 | + if (strict_virtual_cast<df::general_ref_contains_itemst>(ref)) |
| 442 | + { |
| 443 | + df::item *child = ref->getItem(); |
| 444 | + if (!child) continue; |
437 | 445 |
|
438 | | - cnt += containsMetalItems(child, all, non_trader); |
| 446 | + cnt += containsMetalItems(child, all, non_trader, true); |
| 447 | + } |
439 | 448 | } |
440 | 449 |
|
441 | 450 | if (!non_trader && !isShopItem(item)) |
@@ -787,29 +796,27 @@ command_result adv_tools (Core * c, std::vector <std::string> & parameters) |
787 | 796 | int total = 0; |
788 | 797 | std::map<df::coord,int> counts; |
789 | 798 |
|
790 | | - for (size_t i = 0; i < world->map.map_blocks.size(); i++) |
| 799 | + auto &items = world->items.all; |
| 800 | + for (size_t i = 0; i < items.size(); i++) |
791 | 801 | { |
792 | | - df::map_block *block = world->map.map_blocks[i]; |
| 802 | + df::item *item = items[i]; |
793 | 803 |
|
794 | | - for (size_t j = 0; j < block->items.size(); j++) |
795 | | - { |
796 | | - df::item *item = df::item::find(block->items[j]); |
797 | | - if (!item) |
798 | | - continue; |
| 804 | + int num = containsMetalItems(item, all, non_trader); |
| 805 | + if (!num) |
| 806 | + continue; |
799 | 807 |
|
800 | | - int num = containsMetalItems(item, all, non_trader); |
801 | | - if (!num) |
802 | | - continue; |
| 808 | + df::map_block *block = Maps::getBlockAbs(item->pos); |
| 809 | + if (!block) |
| 810 | + continue; |
803 | 811 |
|
804 | | - total += num; |
805 | | - counts[(item->pos - player_pos)/10] += num; |
| 812 | + total += num; |
| 813 | + counts[(item->pos - player_pos)/10] += num; |
806 | 814 |
|
807 | | - auto &designations = block->designation; |
808 | | - auto &dgn = designations[item->pos.x%16][item->pos.y%16]; |
| 815 | + auto &designations = block->designation; |
| 816 | + auto &dgn = designations[item->pos.x%16][item->pos.y%16]; |
809 | 817 |
|
810 | | - dgn.bits.hidden = 0; // revealed |
811 | | - dgn.bits.pile = 1; // visible |
812 | | - } |
| 818 | + dgn.bits.hidden = 0; // revealed |
| 819 | + dgn.bits.pile = 1; // visible |
813 | 820 | } |
814 | 821 |
|
815 | 822 | joinCounts(counts); |
|
0 commit comments