finish up crafting system v0

efd/v1
Dominik Madarász 2022-10-18 19:59:35 +02:00
parent 4c778d24ec
commit a3a75af9b5
11 changed files with 46 additions and 2 deletions

View File

@ -22,6 +22,7 @@ add_library(eco2d-foundation STATIC
src/models/prefabs/blueprint.c src/models/prefabs/blueprint.c
src/models/prefabs/splitter.c src/models/prefabs/splitter.c
src/models/prefabs/craftbench.c src/models/prefabs/craftbench.c
src/models/prefabs/assembler.c
src/pkt/packet.c src/pkt/packet.c

View File

@ -53,6 +53,7 @@ Texture2D texgen_build_sprite_fallback(asset_id id) {
case ASSET_FURNACE: return LoadTexEco("furnace-export"); case ASSET_FURNACE: return LoadTexEco("furnace-export");
case ASSET_CRAFTBENCH: return LoadTexEco("craftbench"); case ASSET_CRAFTBENCH: return LoadTexEco("craftbench");
case ASSET_SPLITTER: return LoadTexEco("item_splitter"); case ASSET_SPLITTER: return LoadTexEco("item_splitter");
case ASSET_ASSEMBLER: return LoadTexEco("assembler");
default: break; default: break;
} }

View File

@ -7,6 +7,7 @@
X(ASSET_THING)\ X(ASSET_THING)\
X(ASSET_CHEST)\ X(ASSET_CHEST)\
X(ASSET_SPLITTER)\ X(ASSET_SPLITTER)\
X(ASSET_ASSEMBLER)\
X(ASSET_FURNACE)\ X(ASSET_FURNACE)\
X(ASSET_CRAFTBENCH)\ X(ASSET_CRAFTBENCH)\
X(ASSET_BLUEPRINT_BEGIN)\ X(ASSET_BLUEPRINT_BEGIN)\

View File

@ -25,6 +25,7 @@ static asset assets[] = {
ASSET_TEX(ASSET_CHEST), ASSET_TEX(ASSET_CHEST),
ASSET_TEX(ASSET_FURNACE), ASSET_TEX(ASSET_FURNACE),
ASSET_TEX(ASSET_SPLITTER), ASSET_TEX(ASSET_SPLITTER),
ASSET_TEX(ASSET_ASSEMBLER),
ASSET_TEX(ASSET_CRAFTBENCH), ASSET_TEX(ASSET_CRAFTBENCH),
ASSET_TEX(ASSET_BLUEPRINT), ASSET_TEX(ASSET_BLUEPRINT),
ASSET_TEX(ASSET_BLUEPRINT_DEMO_HOUSE), ASSET_TEX(ASSET_BLUEPRINT_DEMO_HOUSE),

View File

@ -20,7 +20,7 @@ static recipe recipes[] = {
// NOTE(zaklaus): Belt // NOTE(zaklaus): Belt
RECIPE(ASSET_IRON_PLATES, ASSET_FURNACE, 4, R(ASSET_IRON_ORE, 1), {0}), RECIPE(ASSET_IRON_PLATES, ASSET_FURNACE, 4, R(ASSET_IRON_ORE, 1), {0}),
RECIPE(ASSET_SCREWS, ASSET_CRAFTBENCH, 8, R(ASSET_IRON_PLATES, 1), {0}), RECIPE(ASSET_SCREWS, ASSET_CRAFTBENCH, 8, R(ASSET_IRON_PLATES, 1), {0}),
RECIPE(ASSET_BELT, ASSET_CRAFTBENCH, 1, R(ASSET_FENCE, 1), R(ASSET_SCREWS, 4), R(ASSET_IRON_PLATES, 2), {0}), RECIPE(ASSET_BELT, ASSET_ASSEMBLER, 1, R(ASSET_FENCE, 1), R(ASSET_SCREWS, 4), R(ASSET_IRON_PLATES, 2), {0}),
}; };
#define MAX_RECIPES (sizeof(recipes)/sizeof(recipes[0])) #define MAX_RECIPES (sizeof(recipes)/sizeof(recipes[0]))

View File

@ -4,6 +4,7 @@
#include "models/prefabs/blueprint.h" #include "models/prefabs/blueprint.h"
#include "models/prefabs/craftbench.h" #include "models/prefabs/craftbench.h"
#include "models/prefabs/splitter.h" #include "models/prefabs/splitter.h"
#include "models/prefabs/assembler.h"
static struct { static struct {
asset_id id; asset_id id;
@ -14,6 +15,7 @@ static struct {
{ .id = ASSET_FURNACE, .proc = furnace_spawn }, { .id = ASSET_FURNACE, .proc = furnace_spawn },
{ .id = ASSET_CRAFTBENCH, .proc = craftbench_spawn }, { .id = ASSET_CRAFTBENCH, .proc = craftbench_spawn },
{ .id = ASSET_SPLITTER, .proc = splitter_spawn }, { .id = ASSET_SPLITTER, .proc = splitter_spawn },
{ .id = ASSET_ASSEMBLER, .proc = assembler_spawn },
{ .id = ASSET_BLUEPRINT, .proc_udata = blueprint_spawn_udata }, { .id = ASSET_BLUEPRINT, .proc_udata = blueprint_spawn_udata },
}; };

View File

@ -26,6 +26,7 @@ static item_desc items[] = {
ITEM_ENT(ASSET_CRAFTBENCH, 32, ASSET_CRAFTBENCH), ITEM_ENT(ASSET_CRAFTBENCH, 32, ASSET_CRAFTBENCH),
ITEM_ENT(ASSET_FURNACE, 32, ASSET_FURNACE), ITEM_ENT(ASSET_FURNACE, 32, ASSET_FURNACE),
ITEM_ENT(ASSET_SPLITTER, 32, ASSET_SPLITTER), ITEM_ENT(ASSET_SPLITTER, 32, ASSET_SPLITTER),
ITEM_ENT(ASSET_ASSEMBLER, 32, ASSET_ASSEMBLER),
ITEM_HOLD(ASSET_IRON_ORE, 64), ITEM_HOLD(ASSET_IRON_ORE, 64),
ITEM_HOLD(ASSET_IRON_INGOT, 64), ITEM_HOLD(ASSET_IRON_INGOT, 64),

View File

@ -0,0 +1,27 @@
#include "assembler.h"
#include "models/device.h"
#include "world/world.h"
#include "models/entity.h"
#include "models/components.h"
uint64_t assembler_spawn(void) {
ecs_entity_t e = device_spawn(ASSET_ASSEMBLER);
ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer);
*storage = (ItemContainer){0};
Producer *producer = ecs_get_mut(world_ecs(), e, Producer);
*producer = (Producer){0};
producer->energy_level = 69.0f;
producer->pending_task = PRODUCER_CRAFT_AUTO;
producer->push_filter = PRODUCER_PUSH_PRODUCT;
producer->target_item = ASSET_INVALID;
ecs_set(world_ecs(), e, ItemRouter, {1});
return (uint64_t)e;
}
void assembler_despawn(uint64_t ent_id) {
entity_despawn(ent_id);
}

View File

@ -0,0 +1,6 @@
#pragma once
#include "platform/system.h"
uint64_t assembler_spawn(void);
void assembler_despawn(uint64_t id);

View File

@ -61,7 +61,6 @@ void CraftItem(ecs_iter_t *it) {
for (int i = 0; i < it->count; i++) { for (int i = 0; i < it->count; i++) {
if (in[i].craft_item == 0) continue; if (in[i].craft_item == 0) continue;
zpl_printf("id: %d\n", in[i].craft_item);
if (world_entity_valid(in[i].storage_ent)){ if (world_entity_valid(in[i].storage_ent)){
Producer *ic = 0; Producer *ic = 0;
if ((ic = ecs_get_mut_if_ex(it->world, in[i].storage_ent, Producer))){ if ((ic = ecs_get_mut_if_ex(it->world, in[i].storage_ent, Producer))){

View File

@ -121,6 +121,11 @@ void PushItemsOnNodes(ecs_iter_t *it) {
item->quantity -= zpl_min(r->push_qty, item->quantity); item->quantity -= zpl_min(r->push_qty, item->quantity);
--num_nodes; --num_nodes;
++counter; ++counter;
if (item->quantity == 0) {
item_despawn(item_slot_ent);
storage[i].items[j] = 0;
}
} }
} }
} }