start turret
This commit is contained in:
44
items/item.c
44
items/item.c
@@ -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];
|
||||
|
Reference in New Issue
Block a user