Skip to content

Commit

Permalink
Make autofarmer process one tile at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
heimskr committed Nov 2, 2023
1 parent 6ee207f commit 1ba650f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/tileentity/Autofarmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Game3 {

private:
float accumulatedTime = 0.f;
Position centerOffset{};

Autofarmer();
Autofarmer(Identifier tile_id, Position);
Expand Down
18 changes: 8 additions & 10 deletions src/tileentity/Autofarmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace Game3 {
constexpr EnergyAmount ENERGY_PER_OPERATION = 50;
constexpr ItemCount INPUT_CAPACITY = 5;
constexpr ItemCount OUTPUT_CAPACITY = 20;
constexpr float PERIOD = 4.;
constexpr Index DIAMETER = 5;
constexpr float PERIOD = 4. / (DIAMETER * DIAMETER);
}

Autofarmer::Autofarmer():
Expand Down Expand Up @@ -168,16 +168,14 @@ namespace Game3 {
current_energy = energyContainer->energy;
}

for (Index row = center.row - DIAMETER / 2;
row < center.row + DIAMETER / 2 + odd; ++row) {
for (Index column = center.column - DIAMETER / 2;
column < center.column + DIAMETER / 2 + odd; ++column) {
if (current_energy <= operations * ENERGY_PER_OPERATION)
break;
if (operations * ENERGY_PER_OPERATION <= current_energy)
if (autofarm(center + centerOffset, input_empty))
++operations;

if (autofarm(Position{row, column}, input_empty))
++operations;
}
if (++centerOffset.column == DIAMETER / 2 + odd) {
centerOffset.column = -DIAMETER / 2;
if (++centerOffset.row == DIAMETER / 2 + odd)
centerOffset.row = -DIAMETER / 2;
}

return operations;
Expand Down

0 comments on commit 1ba650f

Please sign in to comment.