Implemented configurable randomization in the world builder, and then got the beginning of devices to work for the next part of going down a level through stairs.
This commit is contained in:
parent
7acbd0379f
commit
d2162910f6
10 changed files with 73 additions and 36 deletions
|
@ -6,7 +6,8 @@
|
|||
|
||||
},
|
||||
"worldgen": {
|
||||
"enemy_probability": 60,
|
||||
"empty_room_probability": 20
|
||||
"enemy_probability": 20,
|
||||
"empty_room_probability": 20,
|
||||
"device_probability": 20
|
||||
}
|
||||
}
|
||||
|
|
26
assets/devices.json
Normal file
26
assets/devices.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"STAIRS_DOWN": {
|
||||
"id": "STAIRS_DOWN",
|
||||
"name": "Stairs Down",
|
||||
"foreground": [24, 205, 189],
|
||||
"background": [24, 205, 189],
|
||||
"description": "Stairs that go down further into the dungeon.",
|
||||
"inventory_count": 0,
|
||||
"components": [
|
||||
{"type": "Tile", "config": {"chr": "\u2ac5"}},
|
||||
{"type": "Device", "config": {"active": true}}
|
||||
]
|
||||
},
|
||||
"STAIRS_UP": {
|
||||
"id": "STAIRS_UP",
|
||||
"name": "Stairs Up",
|
||||
"foreground": [24, 205, 189],
|
||||
"background": [24, 205, 189],
|
||||
"description": "Stairs that go up, for the weak.",
|
||||
"inventory_count": 0,
|
||||
"components": [
|
||||
{"type": "Tile", "config": {"chr": "\u2259"}},
|
||||
{"type": "Device", "config": {"active": true}}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -71,27 +71,5 @@
|
|||
{"type": "Tile", "config": {"chr": "\u03eb"}},
|
||||
{"type": "Curative", "config": {"hp": 20}}
|
||||
]
|
||||
},
|
||||
"STAIRS_DOWN": {
|
||||
"id": "STAIRS_DOWN",
|
||||
"name": "Stairs Down",
|
||||
"foreground": [24, 205, 189],
|
||||
"background": [24, 205, 189],
|
||||
"description": "Stairs that go down further into the dungeon.",
|
||||
"inventory_count": 0,
|
||||
"components": [
|
||||
{"type": "Tile", "config": {"chr": "\u2ac5"}}
|
||||
]
|
||||
},
|
||||
"STAIRS_UP": {
|
||||
"id": "STAIRS_UP",
|
||||
"name": "Stairs Up",
|
||||
"foreground": [24, 205, 189],
|
||||
"background": [24, 205, 189],
|
||||
"description": "Stairs that go up, for the weak.",
|
||||
"inventory_count": 0,
|
||||
"components": [
|
||||
{"type": "Tile", "config": {"chr": "\u2259"}}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
#include "config.hpp"
|
||||
|
||||
namespace components {
|
||||
struct Device {
|
||||
bool active = 0;
|
||||
};
|
||||
|
||||
struct Player {
|
||||
DinkyECS::Entity entity;
|
||||
DEFINE_SERIALIZABLE(Player, entity);
|
||||
|
@ -38,6 +42,7 @@ namespace components {
|
|||
Config enemies;
|
||||
Config items;
|
||||
Config tiles;
|
||||
Config devices;
|
||||
};
|
||||
|
||||
struct EnemyConfig {
|
||||
|
@ -77,6 +82,8 @@ namespace components {
|
|||
world.set<Curative>(entity, {config["hp"]});
|
||||
} else if(comp["type"] == "Motion") {
|
||||
world.set<Motion>(entity, {config["dx"], config["dy"], config["random"]});
|
||||
} else if(comp["type"] == "Device") {
|
||||
world.set<Device>(entity, {config["active"]});
|
||||
} else {
|
||||
dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
|
||||
std::string(comp["type"])));
|
||||
|
|
3
save.cpp
3
save.cpp
|
@ -88,8 +88,9 @@ void save::load_configs(DinkyECS::World &world) {
|
|||
Config enemies("./assets/enemies.json");
|
||||
Config items("./assets/items.json");
|
||||
Config tiles("./assets/tiles.json");
|
||||
Config devices("./assets/devices.json");
|
||||
|
||||
world.set_the<GameConfig>({
|
||||
game, enemies, items, tiles
|
||||
game, enemies, items, tiles, devices
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
TODAY'S GOAL:
|
||||
|
||||
* Linux on Arch catch2 fails with catch2-main missing and xwayland displays weird when small (gentoo plasma6 wayland).
|
||||
* Position needs three types of collision: full, false, and none.
|
||||
* Stairs \u2ac5 for stairs down, and \u2259 stairs up
|
||||
|
||||
* UNKNOWN COLLISION TYPE 6
|
||||
|
|
23
systems.cpp
23
systems.cpp
|
@ -56,15 +56,16 @@ void System::init_positions(DinkyECS::World &world) {
|
|||
|
||||
// BUG: instead of separate things maybe just one
|
||||
// BUG: Collision component that references what is collide
|
||||
world.query<Position, Combat>([&](const auto &ent, auto &pos, auto &combat) {
|
||||
if(!combat.dead) {
|
||||
world.query<Position>([&](const auto &ent, auto &pos) {
|
||||
if(world.has<Combat>(ent)) {
|
||||
const auto& combat = world.get<Combat>(ent);
|
||||
if(!combat.dead) {
|
||||
collider.insert(pos.location, ent);
|
||||
}
|
||||
} else {
|
||||
collider.insert(pos.location, ent);
|
||||
}
|
||||
});
|
||||
|
||||
world.query<Position>([&](const auto &ent, auto &pos) {
|
||||
collider.insert(pos.location, ent);
|
||||
});
|
||||
}
|
||||
|
||||
inline void move_entity(SpatialMap &collider, Map &game_map, Position &position, Motion &motion, DinkyECS::Entity ent) {
|
||||
|
@ -175,6 +176,8 @@ void System::collision(DinkyECS::World &world, Player &player) {
|
|||
world.remove<Tile>(entity);
|
||||
world.remove<InventoryItem>(entity);
|
||||
world.send<Events::GUI>(Events::GUI::LOOT, entity, item);
|
||||
} else if(world.has<Device>(entity)) {
|
||||
System::device(world, player.entity, entity);
|
||||
} else {
|
||||
println("UNKNOWN COLLISION TYPE {}", entity);
|
||||
}
|
||||
|
@ -211,3 +214,11 @@ void System::pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::En
|
|||
|
||||
inventory.add(invitem);
|
||||
}
|
||||
|
||||
void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) {
|
||||
auto& device = world.get<Device>(item);
|
||||
if(device.active) {
|
||||
println("entity {} INTERACTED WITH DEVICE {}", actor, item);
|
||||
device.active = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,5 @@ namespace System {
|
|||
void draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y);
|
||||
void init_positions(DinkyECS::World &world);
|
||||
void pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item);
|
||||
void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item);
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ TEST_CASE("random rectangle", "[matrix:rando_rect]") {
|
|||
}
|
||||
}
|
||||
|
||||
matrix::dump("WALLS FILLED", wall_copy);
|
||||
// matrix::dump("WALLS FILLED", wall_copy);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,6 +339,6 @@ TEST_CASE("standard rectangle", "[matrix:rectangle]") {
|
|||
}
|
||||
}
|
||||
|
||||
matrix::dump("WALLS FILLED", wall_copy);
|
||||
// matrix::dump("WALLS FILLED", wall_copy);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,17 +185,27 @@ DinkyECS::Entity configure_entity_in_map(DinkyECS::World &world, Map &game_map,
|
|||
return item;
|
||||
}
|
||||
|
||||
inline json &select_entity_type(GameConfig &config, json &gen_config) {
|
||||
int enemy_test = Random::uniform<int>(0,100);
|
||||
int device_test = Random::uniform<int>(0, 100);
|
||||
|
||||
if(enemy_test < gen_config["enemy_probability"]) {
|
||||
return config.enemies.json();
|
||||
} else if(device_test < gen_config["device_probability"]) {
|
||||
return config.devices.json();
|
||||
} else {
|
||||
return config.items.json();
|
||||
}
|
||||
}
|
||||
|
||||
void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config) {
|
||||
auto &gen_config = config.game["worldgen"];
|
||||
|
||||
|
||||
for(size_t room_num = $map.room_count() - 1; room_num > 0; room_num--) {
|
||||
int empty_room = Random::uniform<int>(0, 100);
|
||||
if(empty_room < gen_config["empty_room_probability"]) continue;
|
||||
|
||||
int rand_type = Random::uniform<int>(0,100);
|
||||
json& entity_db = rand_type < gen_config["enemy_probability"] ? config.enemies.json() : config.items.json();
|
||||
json& entity_db = select_entity_type(config, gen_config);
|
||||
|
||||
std::vector<std::string> keys;
|
||||
for(auto &el : entity_db.items()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue