diff --git a/code/game/src/gui/build_mode.c b/code/game/src/gui/build_mode.c index eb80e03..4fc7633 100644 --- a/code/game/src/gui/build_mode.c +++ b/code/game/src/gui/build_mode.c @@ -7,6 +7,7 @@ extern bool inv_is_inside; static uint8_t build_num_placements = 0; static item_placement build_placements[BUILD_MAX_PLACEMENTS] = {0}; +bool build_is_deletion_mode = false; void buildmode_clear_buffers(void) { item_placement empty_placement = { .x = 0.0f, .y = 0.0f, .kind = -1 }; @@ -38,11 +39,19 @@ void buildmode_draw(void) { buildmode_clear_buffers(); } + if (IsKeyPressed(KEY_B)){ + build_is_deletion_mode = !build_is_deletion_mode; + } + ItemDrop *item = &e->items[e->selected_item]; - if (e->has_items && !e->inside_vehicle && item->quantity > 0 && !is_outside_range) { - uint16_t item_id = item_find(item->kind); - item_usage usage = item_get_usage(item_id); + if (e->has_items && !e->inside_vehicle && item->quantity > 0 && !is_outside_range || build_is_deletion_mode) { + item_usage usage = 0; + uint16_t item_id = 0; + if (!build_is_deletion_mode){ + item_id = item_find(item->kind); + usage = item_get_usage(item_id); + } if (usage < UKIND_END_PLACE) { if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON) && !build_is_in_draw_mode) { build_is_in_draw_mode = true; @@ -50,8 +59,13 @@ void buildmode_draw(void) { buildmode_clear_buffers(); } - uint32_t qty = item->quantity; - bool directional = item_get_place_directional(item_id); + uint32_t qty = BUILD_MAX_PLACEMENTS; + bool directional = false; + + if (!build_is_deletion_mode){ + directional = item_get_place_directional(item_id); + qty = item->quantity; + } if (build_is_in_draw_mode) { for (size_t i = 0; i < BUILD_MAX_PLACEMENTS; i++) { @@ -80,11 +94,10 @@ void buildmode_draw(void) { break; } } - } if (!is_outside_range) - renderer_draw_single((float)cam.x, (float)cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(WHITE, 0.2f)); + renderer_draw_single((float)cam.x, (float)cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(build_is_deletion_mode ? RED : WHITE, 0.2f)); build_num_placements = zpl_min(build_num_placements, qty); } @@ -92,7 +105,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_BUILDMODE_HIGHLIGHT, ColorAlpha(WHITE, 0.4f)); + renderer_draw_single(it->x, it->y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(build_is_deletion_mode ? RED : WHITE, 0.4f)); } if (build_is_in_draw_mode) { diff --git a/code/game/src/item_placement.h b/code/game/src/item_placement.h index f2fb961..1a2087e 100644 --- a/code/game/src/item_placement.h +++ b/code/game/src/item_placement.h @@ -1,6 +1,6 @@ #pragma once -#define BUILD_MAX_PLACEMENTS 20 +#define BUILD_MAX_PLACEMENTS 40 typedef struct { float x; diff --git a/code/game/src/items.h b/code/game/src/items.h index 44081e2..ef1a131 100644 --- a/code/game/src/items.h +++ b/code/game/src/items.h @@ -7,6 +7,7 @@ typedef enum { // NOTE(zaklaus): hardcoded fields for placement ops + UKIND_DELETE, UKIND_PLACE, UKIND_PLACE_ITEM, UKIND_END_PLACE, diff --git a/code/game/src/packets/pkt_send_keystate.c b/code/game/src/packets/pkt_send_keystate.c index 5c3a3a1..b6d92e9 100644 --- a/code/game/src/packets/pkt_send_keystate.c +++ b/code/game/src/packets/pkt_send_keystate.c @@ -26,6 +26,7 @@ pkt_desc pkt_send_keystate_desc[] = { { PKT_UINT(pkt_send_keystate, swap_from) }, { PKT_UINT(pkt_send_keystate, swap_to) }, { PKT_UINT(pkt_send_keystate, placement_num) }, + { PKT_UINT(pkt_send_keystate, deletion_mode) }, { PKT_ARRAY(pkt_send_keystate, placements) }, { PKT_END }, }; @@ -73,6 +74,7 @@ int32_t pkt_send_keystate_handler(pkt_header *header) { i->swap_from = zpl_clamp(table.swap_from, 0, ITEMS_CONTAINER_SIZE-1); i->swap_to = zpl_clamp(table.swap_to, 0, ITEMS_CONTAINER_SIZE-1); i->storage_action = table.storage_action; + i->deletion_mode = table.deletion_mode; if (table.placement_num > 0) { i->num_placements = zpl_clamp(table.placement_num, 0, BUILD_MAX_PLACEMENTS); diff --git a/code/game/src/packets/pkt_send_keystate.h b/code/game/src/packets/pkt_send_keystate.h index 830481a..407ef97 100644 --- a/code/game/src/packets/pkt_send_keystate.h +++ b/code/game/src/packets/pkt_send_keystate.h @@ -25,6 +25,7 @@ typedef struct { // TODO(zaklaus): build mode uint8_t placement_num; + uint8_t deletion_mode; item_placement placements[BUILD_MAX_PLACEMENTS]; } pkt_send_keystate; diff --git a/code/game/src/platform_raylib.c b/code/game/src/platform_raylib.c index 615c768..55a0b2c 100644 --- a/code/game/src/platform_raylib.c +++ b/code/game/src/platform_raylib.c @@ -106,6 +106,7 @@ void platform_input_update_input_frame(game_keystate_data data) { if (data.swap_from != last_input_data.swap_from) goto send_data; if (data.swap_to != last_input_data.swap_to) goto send_data; if (data.placement_num != last_input_data.placement_num) goto send_data; + if (data.deletion_mode != last_input_data.deletion_mode) goto send_data; if (zpl_memcompare(data.placements, last_input_data.placements, zpl_size_of(data.placements))) goto send_data; return; @@ -172,6 +173,8 @@ void platform_input() { .swap_storage = inv_swap_storage, .swap_from = inv->swap_from, .swap_to = inv->swap_to, + + .deletion_mode = build_is_deletion_mode, }; if (build_submit_placements) { diff --git a/code/game/src/world/world.c b/code/game/src/world/world.c index 8329031..6462940 100644 --- a/code/game/src/world/world.c +++ b/code/game/src/world/world.c @@ -491,6 +491,7 @@ world_block_lookup world_block_from_realpos(float x, float y) { void world_chunk_destroy_block(float x, float y, bool drop_item) { world_block_lookup l = world_block_from_realpos(x, y); + if (blocks_get_flags(l.bid) & BLOCK_FLAG_ESSENTIAL) return; world_chunk_replace_block(l.chunk_id, l.id, 0); if (l.is_outer && l.bid > 0 && drop_item) { diff --git a/code/modules/modules/components.h b/code/modules/modules/components.h index 4659d5a..d53d3d4 100644 --- a/code/modules/modules/components.h +++ b/code/modules/modules/components.h @@ -58,6 +58,7 @@ typedef struct { uint8_t num_placements; float placements_x[20]; float placements_y[20]; + uint8_t deletion_mode; } Input; typedef struct { diff --git a/code/modules/source/system_items.c b/code/modules/source/system_items.c index 572ddb0..48d6dd9 100644 --- a/code/modules/source/system_items.c +++ b/code/modules/source/system_items.c @@ -256,11 +256,21 @@ void UseItem(ecs_iter_t *it) { } ItemDrop *item = &inv[i].items[in[i].selected_item]; - if (!item || item->quantity <= 0) continue; - uint16_t item_id = item_find(item->kind); - item_usage usage = item_get_usage(item_id); + uint16_t item_id = 0; + item_usage usage = UKIND_DELETE; - if (in[i].use && usage > UKIND_END_PLACE) + if (!in[i].deletion_mode){ + item_id = item_find(item->kind); + usage = item_get_usage(item_id); + if (!item || item->quantity <= 0) continue; + } + + if (!in[i].use && usage == UKIND_DELETE){ + for (size_t j = 0; j < in[i].num_placements; j++) { + world_chunk_destroy_block(in[i].placements_x[j], in[i].placements_y[j], true); + } + } + else if (in[i].use && usage > UKIND_END_PLACE) item_use(it->world, item, p[i], 0); else if (in[i].num_placements > 0 && usage < UKIND_END_PLACE) { asset_id ofs = 0;