| 524 | } |
| 525 | |
| 526 | static void flood_fill(lua_State *L, bool enable) { |
| 527 | df::coord start_pos; |
| 528 | bool zlevel = false; |
| 529 | |
| 530 | df::burrow *burrow = get_burrow(L, 1); |
| 531 | if (!burrow) { |
| 532 | luaL_argerror(L, 1, "invalid burrow specifier or burrow not found"); |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | Lua::CheckDFAssign(L, &start_pos, 2); |
| 537 | get_opts(L, 3, zlevel); |
| 538 | |
| 539 | df::tile_designation *start_des = Maps::getTileDesignation(start_pos); |
| 540 | if (!start_des) { |
| 541 | luaL_argerror(L, 2, "invalid starting coordinates"); |
| 542 | return; |
| 543 | } |
| 544 | bool start_outside = is_outside(start_pos, start_des); |
| 545 | bool start_hidden = start_des->bits.hidden; |
| 546 | uint16_t start_walk = Maps::getWalkableGroup(start_pos); |
| 547 | DEBUG(status).print("starting pos: ({},{},{}); outside: {}; hidden: {}\n", |
| 548 | start_pos.x, start_pos.y, start_pos.z, start_outside, start_hidden); |
| 549 | |
| 550 | std::stack<df::coord> flood; |
| 551 | flood.emplace(start_pos); |
| 552 | |
| 553 | while(!flood.empty()) { |
| 554 | const df::coord pos = flood.top(); |
| 555 | flood.pop(); |
| 556 | |
| 557 | TRACE(status).print("pos: ({},{},{})\n", pos.x, pos.y, pos.z); |
| 558 | |
| 559 | df::tile_designation *des = Maps::getTileDesignation(pos); |
| 560 | if (!des || |
| 561 | is_outside(pos, des) != start_outside || |
| 562 | des->bits.hidden != start_hidden) |
| 563 | { |
| 564 | continue; |
| 565 | } |
| 566 | |
| 567 | uint16_t walk = get_walk_group(pos); |
| 568 | if (!start_walk && walk) |
| 569 | continue; |
| 570 | |
| 571 | if (pos != start_pos && enable == Burrows::isAssignedTile(burrow, pos)) |
| 572 | continue; |
| 573 | |
| 574 | Burrows::setAssignedTile(burrow, pos, enable); |
| 575 | |
| 576 | // only go one tile outside of a walkability group (trees don't count) |
| 577 | df::tiletype *tt = Maps::getTileType(pos); |
| 578 | if (start_walk && start_walk != walk && tt && !is_tree_trunk(tt)) |
| 579 | continue; |
| 580 | |
| 581 | flood.emplace(pos.x-1, pos.y-1, pos.z); |
| 582 | flood.emplace(pos.x, pos.y-1, pos.z); |
| 583 | flood.emplace(pos.x+1, pos.y-1, pos.z); |
no test coverage detected