no item merging for now
parent
9ed12e35f6
commit
98adee996c
|
@ -18,6 +18,7 @@ uint64_t item_spawn(item_kind kind, uint32_t qty) {
|
||||||
*d = (ItemDrop){
|
*d = (ItemDrop){
|
||||||
.kind = kind,
|
.kind = kind,
|
||||||
.quantity = qty,
|
.quantity = qty,
|
||||||
|
.merger_time = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (uint64_t)e;
|
return (uint64_t)e;
|
||||||
|
|
|
@ -91,6 +91,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t kind;
|
uint16_t kind;
|
||||||
uint32_t quantity;
|
uint32_t quantity;
|
||||||
|
float merger_time;
|
||||||
} ItemDrop;
|
} ItemDrop;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -161,6 +161,7 @@ void SystemsImport(ecs_world_t *ecs) {
|
||||||
ECS_SYSTEM(ecs, PickItem, EcsPostUpdate, components.Input, components.Position, components.Inventory, !components.IsInVehicle);
|
ECS_SYSTEM(ecs, PickItem, EcsPostUpdate, components.Input, components.Position, components.Inventory, !components.IsInVehicle);
|
||||||
ECS_SYSTEM(ecs, DropItem, EcsPostUpdate, components.Input, components.Position, components.Inventory, !components.IsInVehicle);
|
ECS_SYSTEM(ecs, DropItem, EcsPostUpdate, components.Input, components.Position, components.Inventory, !components.IsInVehicle);
|
||||||
ECS_SYSTEM(ecs, SwapItems, EcsPostUpdate, components.Input, components.Inventory);
|
ECS_SYSTEM(ecs, SwapItems, EcsPostUpdate, components.Input, components.Inventory);
|
||||||
|
//ECS_SYSTEM(ecs, MergeItems, EcsPostUpdate, components.Position, components.ItemDrop);
|
||||||
ECS_SYSTEM(ecs, UseItem, EcsPostUpdate, components.Input, components.Position, components.Inventory, !components.IsInVehicle);
|
ECS_SYSTEM(ecs, UseItem, EcsPostUpdate, components.Input, components.Position, components.Inventory, !components.IsInVehicle);
|
||||||
|
|
||||||
ECS_SYSTEM(ecs, UpdateTrackerPos, EcsPostUpdate, components.Position, components.Velocity);
|
ECS_SYSTEM(ecs, UpdateTrackerPos, EcsPostUpdate, components.Position, components.Velocity);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "items.h"
|
#include "items.h"
|
||||||
|
|
||||||
#define ITEM_PICK_RADIUS 25.0f
|
#define ITEM_PICK_RADIUS 25.0f
|
||||||
|
#define ITEM_MERGER_RADIUS 75.0f
|
||||||
#define ITEM_ATTRACT_RADIUS 75.0f
|
#define ITEM_ATTRACT_RADIUS 75.0f
|
||||||
#define ITEM_ATTRACT_FORCE 0.63f
|
#define ITEM_ATTRACT_FORCE 0.63f
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ void PickItem(ecs_iter_t *it) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ITEM_DROP_PICKUP_TIME 2.5f
|
#define ITEM_DROP_PICKUP_TIME 2.5f
|
||||||
|
#define ITEM_DROP_MERGER_TIME 6.5f
|
||||||
|
|
||||||
void DropItem(ecs_iter_t *it) {
|
void DropItem(ecs_iter_t *it) {
|
||||||
Input *in = ecs_column(it, Input, 1);
|
Input *in = ecs_column(it, Input, 1);
|
||||||
|
@ -60,62 +62,69 @@ void DropItem(ecs_iter_t *it) {
|
||||||
if (item->quantity <= 0)
|
if (item->quantity <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool is_item_nearby = false;
|
uint32_t dropped_count = item->quantity;
|
||||||
|
if (in[i].sprint) {
|
||||||
|
dropped_count /= 2;
|
||||||
|
} else if (in[i].ctrl) {
|
||||||
|
dropped_count = dropped_count > 0 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dropped_count == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ecs_entity_t te = item_spawn(item->kind, dropped_count);
|
||||||
|
item->quantity -= dropped_count;
|
||||||
|
|
||||||
|
ItemDrop *d = ecs_get_mut(world_ecs(), te, ItemDrop, NULL);
|
||||||
|
*d = (ItemDrop){
|
||||||
|
.kind = item->kind,
|
||||||
|
.quantity = dropped_count,
|
||||||
|
.merger_time = game_time() + ITEM_DROP_MERGER_TIME,
|
||||||
|
};
|
||||||
|
|
||||||
|
Position *ipos = ecs_get_mut(it->world, te, Position, NULL);
|
||||||
|
*ipos = p[i];
|
||||||
|
|
||||||
|
Velocity *v = ecs_get_mut(it->world, te, Velocity, NULL);
|
||||||
|
v->x = in[i].mx * 800.0f;
|
||||||
|
v->y = in[i].my * 800.0f;
|
||||||
|
|
||||||
|
inv[i].pickup_time = game_time() + ITEM_DROP_PICKUP_TIME;
|
||||||
|
in[i].drop = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MergeItems(ecs_iter_t *it) {
|
||||||
|
Position *p = ecs_column(it, Position, 1);
|
||||||
|
ItemDrop *id = ecs_column(it, ItemDrop, 2);
|
||||||
|
|
||||||
|
for (int i = 0; i < it->count; i += 1) {
|
||||||
|
ItemDrop *item = &id[i];
|
||||||
|
|
||||||
|
if (item->merger_time < game_time())
|
||||||
|
continue;
|
||||||
|
|
||||||
size_t ents_count;
|
size_t ents_count;
|
||||||
int64_t *ents = world_chunk_query_entities(it->entities[i], &ents_count, 2);
|
int64_t *ents = world_chunk_query_entities(it->entities[i], &ents_count, 1);
|
||||||
|
|
||||||
for (size_t j = 0; j < ents_count; j++) {
|
for (size_t j = 0; j < ents_count; j++) {
|
||||||
ItemDrop *drop = 0;
|
ItemDrop *drop = 0;
|
||||||
if ((drop = ecs_get_mut_if(it->world, ents[j], ItemDrop))) {
|
if ((drop = ecs_get_mut_if(it->world, ents[j], ItemDrop))) {
|
||||||
|
if (drop->kind != item->kind || (ecs_entity_t)ents[j] == it->entities[i] || drop->quantity == 0 || item->quantity == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
Position const* p2 = ecs_get(it->world, ents[j], Position);
|
Position const* p2 = ecs_get(it->world, ents[j], Position);
|
||||||
|
|
||||||
float dx = p2->x - p[i].x;
|
float dx = p2->x - (p[i].x);
|
||||||
float dy = p2->y - p[i].y;
|
float dy = p2->y - (p[i].y);
|
||||||
float range = zpl_sqrt(dx*dx + dy*dy);
|
float range = zpl_sqrt(dx*dx + dy*dy);
|
||||||
if (range <= ITEM_PICK_RADIUS) {
|
if (range <= ITEM_MERGER_RADIUS) {
|
||||||
if (item->kind == drop->kind) {
|
drop->quantity += item->quantity;
|
||||||
uint32_t dropped_count = item->quantity;
|
item_despawn(it->entities[i]);
|
||||||
if (in[i].sprint) {
|
break;
|
||||||
dropped_count /= 2;
|
|
||||||
} else if (in[i].ctrl) {
|
|
||||||
dropped_count = 1;
|
|
||||||
}
|
|
||||||
drop->quantity += dropped_count;
|
|
||||||
item->quantity -= dropped_count;
|
|
||||||
is_item_nearby = true;
|
|
||||||
inv[i].pickup_time = game_time() + ITEM_DROP_PICKUP_TIME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_item_nearby) {
|
|
||||||
uint32_t dropped_count = item->quantity;
|
|
||||||
if (in[i].sprint) {
|
|
||||||
dropped_count /= 2;
|
|
||||||
} else if (in[i].ctrl) {
|
|
||||||
dropped_count = dropped_count > 0 ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dropped_count == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ecs_entity_t te = item_spawn(item->kind, dropped_count);
|
|
||||||
item->quantity -= dropped_count;
|
|
||||||
|
|
||||||
Position *ipos = ecs_get_mut(it->world, te, Position, NULL);
|
|
||||||
*ipos = p[i];
|
|
||||||
|
|
||||||
Velocity *v = ecs_get_mut(it->world, te, Velocity, NULL);
|
|
||||||
v->x = in[i].mx * 800.0f;
|
|
||||||
v->y = in[i].my * 800.0f;
|
|
||||||
|
|
||||||
inv[i].pickup_time = game_time() + ITEM_DROP_PICKUP_TIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
in[i].drop = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue