From 2269c3aa76d327004cfb94d799672cc38da9ad94 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 20 Aug 2024 19:02:14 +0300 Subject: [PATCH] Preserve belts when placing zoomer --- source/application.cpp | 74 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/source/application.cpp b/source/application.cpp index 2c768d5..0ca2883 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -492,10 +492,13 @@ namespace gmtk using index = index_base; using path_index = index_base; - void sink_belt(ecs::container & world, location m) + // 1 - from center to m + // -1 - from m to center + // 0 - no belt + int sink_belt(ecs::container & world, location m) { if (auto entity = world.index().find(m.up()); !entity || !world.get(*entity).contains()) - return; + return 0; auto & index = world.index(); @@ -526,6 +529,8 @@ namespace gmtk add_belt(world, mde, ne); sink_belt(world, md); + + return 1; } else if (cv.belts_from.contains(me)) { @@ -545,7 +550,11 @@ namespace gmtk add_belt(world, mde, cde); sink_belt(world, md); + + return -1; } + else + return 0; } void sink(ecs::container & world, location & c, location & m) @@ -687,12 +696,63 @@ namespace gmtk zoomer{} ); - auto c = l.down(); + auto & index = map.world->index(); - sink_belt(*map.world, c.left()); - sink_belt(*map.world, c.right()); - sink_belt(*map.world, c.bottom()); - sink_belt(*map.world, c.top()); + auto c = l.down(); + auto cd = c.down(); + + if (int d = sink_belt(*map.world, c.left())) + { + for (int i = 0; i < 3; ++i) + { + auto e0 = index.get(cd.moved({-i, 0})); + auto e1 = index.get(cd.moved({-i-1, 0})); + + if (d == 1) + add_belt(*map.world, e0, e1); + else + add_belt(*map.world, e1, e0); + } + } + if (int d = sink_belt(*map.world, c.right())) + { + for (int i = 0; i < 3; ++i) + { + auto e0 = index.get(cd.moved({i, 0})); + auto e1 = index.get(cd.moved({i+1, 0})); + + if (d == 1) + add_belt(*map.world, e0, e1); + else + add_belt(*map.world, e1, e0); + } + } + if (int d = sink_belt(*map.world, c.bottom())) + { + for (int i = 0; i < 3; ++i) + { + auto e0 = index.get(cd.moved({0, -i})); + auto e1 = index.get(cd.moved({0, -i-1})); + + if (d == 1) + add_belt(*map.world, e0, e1); + else + add_belt(*map.world, e1, e0); + } + } + if (int d = sink_belt(*map.world, c.top())) + { + for (int i = 0; i < 3; ++i) + { + auto e0 = index.get(cd.moved({0, i})); + auto e1 = index.get(cd.moved({0, i+1})); + + if (d == 1) + add_belt(*map.world, e0, e1); + else + add_belt(*map.world, e1, e0); + } + } return true; } break;