From dcd5f0046a99e55c072c4d237201994f1c7bde27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Wed, 3 Nov 2021 17:16:35 +0100 Subject: [PATCH] refund block if we replace the same ID --- code/game/src/gui/build_mode.c | 4 ++-- code/game/src/items.c | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/code/game/src/gui/build_mode.c b/code/game/src/gui/build_mode.c index 413e4e9..8ff7425 100644 --- a/code/game/src/gui/build_mode.c +++ b/code/game/src/gui/build_mode.c @@ -86,7 +86,7 @@ void buildmode_draw(void) { } if (!is_outside_range) - renderer_draw_single(cam.x, cam.y, ASSET_EMPTY, ColorAlpha(BLUE, 0.4f)); + renderer_draw_single(cam.x, cam.y, ASSET_EMPTY, ColorAlpha(WHITE, 0.2f)); build_num_placements = zpl_min(build_num_placements, qty); } @@ -94,7 +94,7 @@ void buildmode_draw(void) { for (size_t i = 0; i < build_num_placements; i++) { item_placement *it = &build_placements[i]; - renderer_draw_single(it->x, it->y, ASSET_EMPTY, ColorAlpha(BLUE, 0.4f)); + renderer_draw_single(it->x, it->y, ASSET_EMPTY, ColorAlpha(WHITE, 0.4f)); } if (build_is_in_draw_mode) { diff --git a/code/game/src/items.c b/code/game/src/items.c index 3c6380a..faaa833 100644 --- a/code/game/src/items.c +++ b/code/game/src/items.c @@ -55,13 +55,14 @@ void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata) { case UKIND_PLACE:{ world_block_lookup l = world_block_from_realpos(p.x, p.y); if (l.is_outer && l.block_id > 0) { - // NOTE(zaklaus): Check if block is a placeable item, cancel the placement if not met asset_id item_asset = blocks_get_asset(l.block_id); uint16_t item_asset_id = item_find(item_asset); if (item_asset_id == ASSET_INVALID) return; - if (item_get_usage(item_asset_id) > UKIND_END_PLACE) return; - world_chunk_destroy_block(p.x, p.y, true); + // NOTE(zaklaus): If we replace the same item, refund 1 qty and let it replace it + if (item_asset_id == item_id) { + it->quantity++; + } } world_chunk_replace_block(l.chunk_id, l.id, blocks_find(desc->place.kind + (asset_id)udata)); it->quantity--;