introduce item_id + cleanup
parent
331ee39672
commit
890bc09d1f
|
@ -6,6 +6,7 @@
|
||||||
typedef enum {
|
typedef enum {
|
||||||
// NOTE(zaklaus): Debug
|
// NOTE(zaklaus): Debug
|
||||||
ASSET_EMPTY,
|
ASSET_EMPTY,
|
||||||
|
ASSET_BUILDMODE_HIGHLIGHT,
|
||||||
|
|
||||||
// NOTE(zaklaus): entities
|
// NOTE(zaklaus): entities
|
||||||
ASSET_PLAYER,
|
ASSET_PLAYER,
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
static asset assets[] = {
|
static asset assets[] = {
|
||||||
ASSET_TEX(ASSET_EMPTY),
|
ASSET_TEX(ASSET_EMPTY),
|
||||||
|
ASSET_TEX(ASSET_BUILDMODE_HIGHLIGHT),
|
||||||
ASSET_TEX(ASSET_DEMO_ICEMAKER),
|
ASSET_TEX(ASSET_DEMO_ICEMAKER),
|
||||||
|
|
||||||
// NOTE(zaklaus): blocks
|
// NOTE(zaklaus): blocks
|
||||||
|
|
|
@ -86,7 +86,7 @@ void buildmode_draw(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_outside_range)
|
if (!is_outside_range)
|
||||||
renderer_draw_single(cam.x, cam.y, ASSET_EMPTY, ColorAlpha(WHITE, 0.2f));
|
renderer_draw_single(cam.x, cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(WHITE, 0.2f));
|
||||||
|
|
||||||
build_num_placements = zpl_min(build_num_placements, qty);
|
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++) {
|
for (size_t i = 0; i < build_num_placements; i++) {
|
||||||
item_placement *it = &build_placements[i];
|
item_placement *it = &build_placements[i];
|
||||||
renderer_draw_single(it->x, it->y, ASSET_EMPTY, ColorAlpha(WHITE, 0.4f));
|
renderer_draw_single(it->x, it->y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(WHITE, 0.4f));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (build_is_in_draw_mode) {
|
if (build_is_in_draw_mode) {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "items_list.c"
|
#include "items_list.c"
|
||||||
#define ITEMS_COUNT (sizeof(items)/sizeof(item_desc))
|
#define ITEMS_COUNT (sizeof(items)/sizeof(item_desc))
|
||||||
|
|
||||||
static inline uint16_t item_resolve_proxy(uint16_t id) {
|
static inline item_id item_resolve_proxy(item_id id) {
|
||||||
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
||||||
item_usage usage = items[id].usage;
|
item_usage usage = items[id].usage;
|
||||||
if (usage == UKIND_PROXY) {
|
if (usage == UKIND_PROXY) {
|
||||||
|
@ -37,8 +37,8 @@ uint64_t item_spawn(asset_id kind, uint32_t qty) {
|
||||||
return (uint64_t)e;
|
return (uint64_t)e;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t item_find(asset_id kind) {
|
item_id item_find(asset_id kind) {
|
||||||
for (uint16_t i=0; i<ITEMS_COUNT; i++) {
|
for (item_id i=0; i<ITEMS_COUNT; i++) {
|
||||||
if (items[i].kind == kind)
|
if (items[i].kind == kind)
|
||||||
return item_resolve_proxy(i);
|
return item_resolve_proxy(i);
|
||||||
}
|
}
|
||||||
|
@ -47,20 +47,20 @@ uint16_t item_find(asset_id kind) {
|
||||||
|
|
||||||
void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata) {
|
void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata) {
|
||||||
(void)ecs;
|
(void)ecs;
|
||||||
uint16_t item_id = item_find(it->kind);
|
uint16_t it_id = item_find(it->kind);
|
||||||
item_desc *desc = &items[item_id];
|
item_desc *desc = &items[it_id];
|
||||||
if (it->quantity <= 0) return;
|
if (it->quantity <= 0) return;
|
||||||
switch (item_get_usage(item_id)) {
|
switch (item_get_usage(it_id)) {
|
||||||
case UKIND_HOLD: /* NOOP */ break;
|
case UKIND_HOLD: /* NOOP */ break;
|
||||||
case UKIND_PLACE:{
|
case UKIND_PLACE:{
|
||||||
world_block_lookup l = world_block_from_realpos(p.x, p.y);
|
world_block_lookup l = world_block_from_realpos(p.x, p.y);
|
||||||
if (l.is_outer && l.bid > 0) {
|
if (l.is_outer && l.bid > 0) {
|
||||||
asset_id item_asset = blocks_get_asset(l.bid);
|
asset_id item_asset = blocks_get_asset(l.bid);
|
||||||
uint16_t item_asset_id = item_find(item_asset);
|
item_id item_asset_id = item_find(item_asset);
|
||||||
if (item_asset_id == ASSET_INVALID) return;
|
if (item_asset_id == ASSET_INVALID) return;
|
||||||
|
|
||||||
// NOTE(zaklaus): If we replace the same item, refund 1 qty and let it replace it
|
// NOTE(zaklaus): If we replace the same item, refund 1 qty and let it replace it
|
||||||
if (item_asset_id == item_id) {
|
if (item_asset_id == it_id) {
|
||||||
it->quantity++;
|
it->quantity++;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -80,17 +80,17 @@ void item_despawn(uint64_t id) {
|
||||||
entity_despawn(id);
|
entity_despawn(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t item_max_quantity(uint16_t id) {
|
uint32_t item_max_quantity(item_id id) {
|
||||||
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
||||||
return items[id].max_quantity;
|
return items[id].max_quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
item_usage item_get_usage(uint16_t id) {
|
item_usage item_get_usage(item_id id) {
|
||||||
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
||||||
return items[id].usage;
|
return items[id].usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool item_get_place_directional(uint16_t id) {
|
bool item_get_place_directional(item_id id) {
|
||||||
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
||||||
return items[id].place.directional;
|
return items[id].place.directional;
|
||||||
}
|
}
|
|
@ -34,14 +34,16 @@ typedef struct {
|
||||||
};
|
};
|
||||||
} item_desc;
|
} item_desc;
|
||||||
|
|
||||||
|
typedef uint16_t item_id;
|
||||||
|
|
||||||
// NOTE(zaklaus): item drops
|
// NOTE(zaklaus): item drops
|
||||||
uint64_t item_spawn(asset_id kind, uint32_t qty);
|
uint64_t item_spawn(asset_id kind, uint32_t qty);
|
||||||
void item_despawn(uint64_t id);
|
void item_despawn(uint64_t id);
|
||||||
|
|
||||||
// NOTE(zaklaus): items
|
// NOTE(zaklaus): items
|
||||||
uint16_t item_find(asset_id kind);
|
item_id item_find(asset_id kind);
|
||||||
void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata);
|
void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata);
|
||||||
|
|
||||||
uint32_t item_max_quantity(uint16_t id);
|
uint32_t item_max_quantity(item_id id);
|
||||||
item_usage item_get_usage(uint16_t id);
|
item_usage item_get_usage(item_id id);
|
||||||
bool item_get_place_directional(uint16_t id);
|
bool item_get_place_directional(item_id id);
|
||||||
|
|
|
@ -8,7 +8,7 @@ typedef enum {
|
||||||
BLOCK_FLAG_ESSENTIAL = (1 << 3),
|
BLOCK_FLAG_ESSENTIAL = (1 << 3),
|
||||||
} block_flags;
|
} block_flags;
|
||||||
|
|
||||||
typedef uint8_t block_id;
|
typedef uint16_t block_id;
|
||||||
|
|
||||||
int32_t blocks_setup(void);
|
int32_t blocks_setup(void);
|
||||||
void blocks_destroy(void);
|
void blocks_destroy(void);
|
||||||
|
|
Loading…
Reference in New Issue