items can have storage now
parent
3f96594fdb
commit
e51d941010
|
@ -24,6 +24,7 @@ typedef struct {
|
|||
float vehicle_power;
|
||||
float vehicle_brake_force;
|
||||
float veh_enter_radius;
|
||||
float blueprint_build_time;
|
||||
} game_rulesdef;
|
||||
|
||||
extern game_rulesdef game_rules;
|
||||
|
|
|
@ -23,4 +23,5 @@ game_rulesdef game_rules = {
|
|||
.vehicle_power = 97.89f,
|
||||
.vehicle_brake_force = 0.84f,
|
||||
.veh_enter_radius = 45.0f,
|
||||
.blueprint_build_time = 1.5f,
|
||||
};
|
||||
|
|
|
@ -17,8 +17,8 @@ static block blocks[] = {
|
|||
BLOCK(ASSET_FENCE, BLOCK_FLAG_COLLISION, '[', .drag = 1.0f , .friction = 1.0f, .bounce = 1.0f),
|
||||
BLOCK(ASSET_WOOD, BLOCK_FLAG_COLLISION, ']', .drag = 1.0f , .friction = 1.0f, .bounce = 0.0f),
|
||||
BLOCK(ASSET_TREE, BLOCK_FLAG_COLLISION|BLOCK_FLAG_DESTROY_ON_COLLISION, '@', .drag = 1.0f , .friction = 1.0f, .bounce = 0.0f),
|
||||
BLOCK(ASSET_CHEST, BLOCK_FLAG_DEVICE, 'C'),
|
||||
BLOCK(ASSET_FURNACE, BLOCK_FLAG_DEVICE, 'F'),
|
||||
BLOCK(ASSET_CHEST, BLOCK_FLAG_ENTITY, 'C'),
|
||||
BLOCK(ASSET_FURNACE, BLOCK_FLAG_ENTITY, 'F'),
|
||||
|
||||
BLOCK(ASSET_BELT_LEFT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = -150.0f),
|
||||
BLOCK(ASSET_BELT_RIGHT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = 150.0f),
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#define ITEM_HOLD(asset, qty)\
|
||||
#define ITEM_HOLD(asset, qty, ...)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_HOLD,\
|
||||
.attachment = UDATA_NONE,\
|
||||
.max_quantity = qty,\
|
||||
__VA_ARGS__\
|
||||
}
|
||||
|
||||
#define ITEM_ENERGY(asset, producer_asset, qty, energy_value)\
|
||||
#define ITEM_ENERGY(asset, producer_asset, qty, energy_value, ...)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_HOLD,\
|
||||
|
@ -17,10 +18,11 @@
|
|||
.energy_source = {\
|
||||
.producer = producer_asset,\
|
||||
.energy_level = energy_value\
|
||||
}\
|
||||
},\
|
||||
__VA_ARGS__\
|
||||
}
|
||||
|
||||
#define ITEM_BLUEPRINT(asset, qty, w_, h_, plan_)\
|
||||
#define ITEM_BLUEPRINT(asset, qty, w_, h_, plan_, ...)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_PLACE_ITEM_DATA,\
|
||||
|
@ -33,10 +35,11 @@
|
|||
},\
|
||||
.place_item = {\
|
||||
.id = asset\
|
||||
}\
|
||||
},\
|
||||
__VA_ARGS__\
|
||||
}
|
||||
|
||||
#define ITEM_INGREDIENT(asset, qty, _producer, _product, _additional)\
|
||||
#define ITEM_INGREDIENT(asset, qty, _producer, _product, _additional, ...)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_HOLD,\
|
||||
|
@ -46,10 +49,11 @@
|
|||
.producer = _producer,\
|
||||
.product = _product,\
|
||||
.additional_ingredient = _additional,\
|
||||
}\
|
||||
},\
|
||||
__VA_ARGS__\
|
||||
}
|
||||
|
||||
#define ITEM_BLOCK(asset, qty, build_asset)\
|
||||
#define ITEM_BLOCK(asset, qty, build_asset, ...)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_PLACE,\
|
||||
|
@ -57,10 +61,11 @@
|
|||
.max_quantity = qty,\
|
||||
.place = {\
|
||||
.kind = build_asset,\
|
||||
}\
|
||||
},\
|
||||
__VA_ARGS__\
|
||||
}
|
||||
|
||||
#define ITEM_BLOCK_DIR(asset, qty, build_asset)\
|
||||
#define ITEM_BLOCK_DIR(asset, qty, build_asset, ...)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_PLACE,\
|
||||
|
@ -69,20 +74,22 @@
|
|||
.place = {\
|
||||
.kind = build_asset,\
|
||||
.directional = true,\
|
||||
}\
|
||||
},\
|
||||
__VA_ARGS__\
|
||||
}
|
||||
|
||||
#define ITEM_PROXY(asset, proxy_id)\
|
||||
#define ITEM_PROXY(asset, proxy_id, ...)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_PROXY,\
|
||||
.attachment = UDATA_NONE,\
|
||||
.proxy = {\
|
||||
.id = proxy_id,\
|
||||
}\
|
||||
},\
|
||||
__VA_ARGS__\
|
||||
}
|
||||
|
||||
#define ITEM_ENT(asset, qty, eid)\
|
||||
#define ITEM_ENT(asset, qty, eid, ...)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_PLACE_ITEM,\
|
||||
|
@ -90,8 +97,9 @@
|
|||
.max_quantity = qty,\
|
||||
.place_item = {\
|
||||
.id = eid\
|
||||
}\
|
||||
},\
|
||||
__VA_ARGS__\
|
||||
}
|
||||
|
||||
#define ITEM_SELF(asset, qty) ITEM_BLOCK(asset, qty, asset)
|
||||
#define ITEM_SELF_DIR(asset, qty) ITEM_BLOCK_DIR(asset, qty, asset)
|
||||
#define ITEM_SELF(asset, qty, ...) ITEM_BLOCK(asset, qty, asset, __VA_ARGS__)
|
||||
#define ITEM_SELF_DIR(asset, qty, ...) ITEM_BLOCK_DIR(asset, qty, asset, __VA_ARGS__)
|
||||
|
|
|
@ -43,6 +43,12 @@ uint64_t item_spawn(asset_id kind, uint32_t qty) {
|
|||
|
||||
item_desc *it = &items[item_find(kind)];
|
||||
|
||||
if (it->has_storage) {
|
||||
ecs_add(world_ecs(), e, BlockHarvest);
|
||||
ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer);
|
||||
*storage = (ItemContainer){0};
|
||||
}
|
||||
|
||||
switch (it->attachment) {
|
||||
case UDATA_ENERGY_SOURCE: {
|
||||
EnergySource *f = ecs_get_mut(world_ecs(), e, EnergySource);
|
||||
|
|
|
@ -29,6 +29,7 @@ typedef struct {
|
|||
item_usage usage;
|
||||
item_attachment attachment;
|
||||
uint32_t max_quantity;
|
||||
uint8_t has_storage;
|
||||
|
||||
// NOTE(zaklaus): usage data
|
||||
union {
|
||||
|
|
|
@ -382,3 +382,19 @@ void HarvestIntoContainers(ecs_iter_t *it) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThrowItemsOut(ecs_iter_t *it) {
|
||||
ItemContainer *storage = ecs_field(it, ItemContainer, 1);
|
||||
Position *p = ecs_field(it, Position, 2);
|
||||
|
||||
for (int i = 0; i < it->count; i++) {
|
||||
for (int j = 0; j < ITEMS_CONTAINER_SIZE; j++) {
|
||||
ecs_entity_t item_slot_ent = storage[i].items[j];
|
||||
Item *item = item_get_data(item_slot_ent);
|
||||
if (!item) continue;
|
||||
|
||||
item_show(item_slot_ent, true);
|
||||
entity_set_position(item_slot_ent, p[i].x, p[i].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ void PlayerClosestInteractable(ecs_iter_t *it){
|
|||
|
||||
for (int i = 0; i < it->count; ++i) {
|
||||
size_t ents_count;
|
||||
int64_t *ents = world_chunk_fetch_entities_realpos(in[i].bx, in[i].by, &ents_count);
|
||||
int64_t *ents = world_chunk_query_entities(it->entities[i], &ents_count, 2);
|
||||
|
||||
ecs_entity_t closest_pick = 0;
|
||||
float min_pick = ZPL_F32_MAX;
|
||||
|
@ -225,6 +225,7 @@ void SystemsImport(ecs_world_t *ecs) {
|
|||
ECS_SYSTEM(ecs, ResetActivators, EcsPostUpdate, components.Input);
|
||||
|
||||
ECS_SYSTEM(ecs, ClearVehicle, EcsUnSet, components.Vehicle);
|
||||
ECS_SYSTEM(ecs, ThrowItemsOut, EcsUnSet, components.ItemContainer, components.Position);
|
||||
|
||||
ECS_SYSTEM(ecs, DisableWorldEdit, EcsPostUpdate);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ typedef enum {
|
|||
BLOCK_FLAG_HAZARD = (1 << 2),
|
||||
BLOCK_FLAG_ESSENTIAL = (1 << 3),
|
||||
BLOCK_FLAG_DESTROY_ON_COLLISION = (1 << 4),
|
||||
BLOCK_FLAG_DEVICE = (1 << 5),
|
||||
BLOCK_FLAG_ENTITY = (1 << 5),
|
||||
} block_flags;
|
||||
|
||||
typedef uint16_t block_id;
|
||||
|
|
|
@ -559,14 +559,14 @@ int64_t world_chunk_from_entity(ecs_entity_t id) {
|
|||
|
||||
void world_chunk_replace_worldgen_block(int64_t id, uint16_t block_idx, block_id bid) {
|
||||
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size));
|
||||
ZPL_ASSERT(!(blocks_get_flags(bid) & BLOCK_FLAG_DEVICE));
|
||||
ZPL_ASSERT(!(blocks_get_flags(bid) & BLOCK_FLAG_ENTITY));
|
||||
world.block_mapping[id][block_idx] = bid;
|
||||
world_chunk_mark_dirty(world.chunk_mapping[id]);
|
||||
}
|
||||
|
||||
void world_chunk_replace_block(int64_t id, uint16_t block_idx, block_id bid) {
|
||||
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size));
|
||||
if (blocks_get_flags(bid) & BLOCK_FLAG_DEVICE) {
|
||||
if (blocks_get_flags(bid) & BLOCK_FLAG_ENTITY) {
|
||||
ecs_entity_t e = entity_spawn_id(blocks_get_asset(bid));
|
||||
world_block_lookup l = world_block_from_index(id, block_idx);
|
||||
entity_set_position(e, l.ox, l.oy);
|
||||
|
@ -579,7 +579,7 @@ void world_chunk_replace_block(int64_t id, uint16_t block_idx, block_id bid) {
|
|||
bool world_chunk_place_block(int64_t id, uint16_t block_idx, block_id bid) {
|
||||
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size));
|
||||
if (world.outer_block_mapping[id][block_idx] != 0 && bid != 0) return false;
|
||||
if (blocks_get_flags(bid) & BLOCK_FLAG_DEVICE) {
|
||||
if (blocks_get_flags(bid) & BLOCK_FLAG_ENTITY) {
|
||||
ecs_entity_t e = entity_spawn_id(blocks_get_asset(bid));
|
||||
world_block_lookup l = world_block_from_index(id, block_idx);
|
||||
entity_set_position(e, l.ox, l.oy);
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
void platform_init() {
|
||||
platform_create_window("eco2d");
|
||||
renderer_init();
|
||||
|
||||
target_zoom = 2.70f;
|
||||
}
|
||||
|
||||
inline static
|
||||
|
|
|
@ -177,7 +177,7 @@ void renderer_init(void) {
|
|||
render_camera.target = (Vector2){0.0f,0.0f};
|
||||
render_camera.offset = (Vector2){(float)(screenWidth >> 1), (float)(screenHeight >> 1)};
|
||||
render_camera.rotation = 0.0f;
|
||||
render_camera.zoom = 1.5f;
|
||||
render_camera.zoom = 2.9f;
|
||||
|
||||
// NOTE(zaklaus): Paint the screen before we load the game
|
||||
// TODO(zaklaus): Render a cool loading screen background maybe? :wink: :wink:
|
||||
|
|
Loading…
Reference in New Issue