start turret

This commit is contained in:
2025-06-10 16:29:17 +02:00
parent 79c8b747cd
commit a17e3abbff
17 changed files with 213 additions and 68 deletions

View File

@@ -20,6 +20,28 @@ const int dirDx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dirDy[8] = {1, 0, -1, -1, -1, 0, 1, 1};
const float epsilon = 0.999f; // if we can't move, back it off just below 1
bool putOntoNext(ItemOnBelt *itm, int nx, int ny, Tile *next, TileTypeReg *ntt, int newLane) {
if (next->items[newLane].type == 0 && (*ntt).allowedInItems[newLane][itm->type]) {
// MOVE it
ItemOnBelt moved = *itm;
moved.tileX = nx;
moved.tileY = ny;
if (!(*ntt).itemMoves) {
moved.offset = 0.5f;
}
next->items[newLane] = moved;
// clear this one
itm->type = 0;
return true;
} else {
// both slots full → wait at end
itm->offset = epsilon;
return false;
}
}
void updateItems() {
for (int i = 0; i < neededUpdates.activeCount; i++) {
@@ -89,25 +111,13 @@ void updateItems() {
}
if (next->items[newLane].type == 0 && ntt.allowedInItems[newLane][itm->type]) {
// MOVE it
ItemOnBelt moved = *itm;
moved.tileX = nx;
moved.tileY = ny;
if (!ntt.itemMoves) {
moved.offset = 0.5f;
if (!putOntoNext(itm, nx, ny, next, &ntt, newLane) && next->type != TYPE_BELT) {
for (uint8_t nLane = 0; nLane < ItemSlotCount; nLane++) {
if (putOntoNext(itm, nx, ny, next, &ntt, nLane)) {
break;
}
}
next->items[newLane] = moved;
// clear this one
itm->type = 0;
} else {
// both slots full → wait at end
itm->offset = epsilon;
}
} else {
}
}
const UpdateTileCallback cb = ItemTileCallbacks[t->type];

View File

@@ -19,6 +19,7 @@ typedef enum ItemType {
TYPE_BELT,
TYPE_FURNACE,
TYPE_MINER,
TYPE_TURRET,
IRON_ORE = ITEMREGISTRY_SIZE / 2,
SILVER_ORE,
GOLD_ORE,