Add a live interface scale slider and room blueprints
This commit is contained in:
1 parent
2a71ed6242
commit
85547b00b9
12 files changed
+553
-96
No files matched your search
+105
-5
@@ -35,6 +35,10 @@ bool is_production_object(RecipeId recipe) noexcept {
|
||||
return is_construction(recipe) || recipe == RecipeId::WeaveCloth;
|
||||
}
|
||||
|
||||
bool is_finished_floor(const ProductionOrder& order) noexcept {
|
||||
return order.recipe == RecipeId::BuildFloor && order.state == JobState::Completed;
|
||||
}
|
||||
|
||||
bool can_take_work(const Agent& agent, Profession profession) noexcept {
|
||||
return agent.profession == Profession::Generalist || agent.profession == profession;
|
||||
}
|
||||
@@ -62,12 +66,19 @@ const Recipe& recipe_for(RecipeId id) {
|
||||
ItemType::None, 28};
|
||||
static constexpr Recipe bed{{ItemStack{ItemType::Plank, 1}, {}}, ItemType::None, 14};
|
||||
static constexpr Recipe weave{{ItemStack{ItemType::Flax, 1}, {}}, ItemType::Cloth, 12};
|
||||
static constexpr Recipe floor{{ItemStack{ItemType::Wood, 1}, {}}, ItemType::None, 6};
|
||||
static constexpr Recipe wall{{ItemStack{ItemType::Wood, 1}, {}}, ItemType::None, 9};
|
||||
static constexpr Recipe door{{ItemStack{ItemType::Wood, 2}, {}}, ItemType::None, 12};
|
||||
switch (id) {
|
||||
case RecipeId::SawPlank: return saw;
|
||||
case RecipeId::CutStoneBlock: return cut;
|
||||
case RecipeId::BuildCabin: return cabin;
|
||||
case RecipeId::BuildBed: return bed;
|
||||
case RecipeId::WeaveCloth: return weave;
|
||||
case RecipeId::BuildFloor: return floor;
|
||||
case RecipeId::BuildWall: return wall;
|
||||
case RecipeId::BuildDoorAlongX:
|
||||
case RecipeId::BuildDoorAlongY: return door;
|
||||
}
|
||||
throw std::invalid_argument("unknown production recipe");
|
||||
}
|
||||
@@ -124,6 +135,38 @@ struct OpenNodeLater {
|
||||
|
||||
} // namespace
|
||||
|
||||
RoomPlan make_room_plan(GridPosition first, GridPosition last) noexcept {
|
||||
return {{std::min(first.x, last.x), std::min(first.y, last.y)},
|
||||
{std::max(first.x, last.x), std::max(first.y, last.y)}};
|
||||
}
|
||||
|
||||
bool RoomPlan::valid_size() const noexcept {
|
||||
const auto width = static_cast<std::int64_t>(last.x) - first.x + 1;
|
||||
const auto height = static_cast<std::int64_t>(last.y) - first.y + 1;
|
||||
return width >= 3 && width <= 12 && height >= 3 && height <= 12 && entrance <= RoomSide::West;
|
||||
}
|
||||
|
||||
bool RoomPlan::contains(GridPosition cell) const noexcept {
|
||||
return cell.x >= first.x && cell.x <= last.x && cell.y >= first.y && cell.y <= last.y;
|
||||
}
|
||||
|
||||
RecipeId RoomPlan::recipe_at(GridPosition cell) const noexcept {
|
||||
const auto middle_x = std::midpoint(first.x, last.x), middle_y = std::midpoint(first.y, last.y);
|
||||
if (cell.y == first.y || cell.y == last.y) {
|
||||
if (cell.x == middle_x && (cell.y == first.y ? entrance == RoomSide::North : entrance == RoomSide::South)) {
|
||||
return RecipeId::BuildDoorAlongX;
|
||||
}
|
||||
return RecipeId::BuildWall;
|
||||
}
|
||||
if (cell.x == first.x || cell.x == last.x) {
|
||||
if (cell.y == middle_y && (cell.x == first.x ? entrance == RoomSide::West : entrance == RoomSide::East)) {
|
||||
return RecipeId::BuildDoorAlongY;
|
||||
}
|
||||
return RecipeId::BuildWall;
|
||||
}
|
||||
return RecipeId::BuildFloor;
|
||||
}
|
||||
|
||||
std::uint32_t Inventory::item_count(ItemType type) const noexcept {
|
||||
const auto index = static_cast<std::size_t>(type);
|
||||
return index != 0 && index <= counts_.size() ? counts_[index - 1] : 0;
|
||||
@@ -318,7 +361,7 @@ void World::queue_production(GridPosition position, RecipeId recipe) {
|
||||
throw std::invalid_argument("the production site is occupied");
|
||||
}
|
||||
for (const ProductionOrder& order : production_orders_) {
|
||||
if (is_production_object(order.recipe) && order.position == position) {
|
||||
if (is_production_object(order.recipe) && order.position == position && !is_finished_floor(order)) {
|
||||
throw std::invalid_argument("a building occupies the production site");
|
||||
}
|
||||
}
|
||||
@@ -334,7 +377,32 @@ bool World::can_place_cabin(GridPosition position) const noexcept {
|
||||
return std::none_of(storages_.begin(), storages_.end(), occupies_cell) &&
|
||||
std::none_of(resource_nodes_.begin(), resource_nodes_.end(), occupies_cell) &&
|
||||
std::none_of(jobs_.begin(), jobs_.end(), occupies_cell) &&
|
||||
std::none_of(production_orders_.begin(), production_orders_.end(), occupies_cell);
|
||||
std::none_of(production_orders_.begin(), production_orders_.end(),
|
||||
[&](const auto& order) { return occupies_cell(order) && !is_finished_floor(order); });
|
||||
}
|
||||
|
||||
bool World::can_place_room(const RoomPlan& plan) const noexcept {
|
||||
if (!plan.valid_size() || !is_walkable(plan.first) || !is_walkable(plan.last)) return false;
|
||||
const int middle_x = std::midpoint(plan.first.x, plan.last.x);
|
||||
const int middle_y = std::midpoint(plan.first.y, plan.last.y);
|
||||
const GridPosition exits[] = {{middle_x, plan.first.y - 1}, {plan.last.x + 1, middle_y},
|
||||
{middle_x, plan.last.y + 1}, {plan.first.x - 1, middle_y}};
|
||||
if (!is_walkable(exits[static_cast<std::size_t>(plan.entrance)]) ||
|
||||
(scenario_active_ && plan.contains(scenario_sawmill_))) return false;
|
||||
for (int y = plan.first.y; y <= plan.last.y; ++y) {
|
||||
for (int x = plan.first.x; x <= plan.last.x; ++x) {
|
||||
if (!is_walkable({x, y})) return false;
|
||||
}
|
||||
}
|
||||
const auto inside = [&](const auto& entity) { return plan.contains(entity.position); };
|
||||
return std::none_of(production_orders_.begin(), production_orders_.end(), inside) &&
|
||||
std::none_of(resource_nodes_.begin(), resource_nodes_.end(), inside) &&
|
||||
std::none_of(storages_.begin(), storages_.end(), inside) &&
|
||||
std::none_of(jobs_.begin(), jobs_.end(), inside) &&
|
||||
std::none_of(agents_.begin(), agents_.end(), [&](const Agent& agent) {
|
||||
return (agent.state == AgentState::Sleeping && inside(agent)) ||
|
||||
(agent.state == AgentState::GoingToSleep && !agent.route.empty() && plan.contains(agent.route.back()));
|
||||
});
|
||||
}
|
||||
|
||||
std::array<ItemStack, 2> World::construction_materials(RecipeId recipe, BedBase base) const {
|
||||
@@ -416,6 +484,8 @@ CommandStatus World::object_status(GridPosition position, bool moving) const noe
|
||||
constexpr auto ready = CommandStatus::Accepted;
|
||||
for (const auto& order : production_orders_) {
|
||||
if (order.position != position || !is_production_object(order.recipe)) continue;
|
||||
if (is_finished_floor(order)) continue;
|
||||
if (moving && order.recipe >= RecipeId::BuildFloor) return CommandStatus::InvalidTarget;
|
||||
return order.state == JobState::InProgress || resting_at(position) ? busy : ready;
|
||||
}
|
||||
for (std::size_t i = 0; i < storages_.size(); ++i) {
|
||||
@@ -436,6 +506,8 @@ CommandStatus World::object_status(GridPosition position, bool moving) const noe
|
||||
}
|
||||
return node.reserved_workers != 0 ? busy : ready;
|
||||
}
|
||||
if (!moving && !resting_at(position) && std::any_of(production_orders_.begin(), production_orders_.end(),
|
||||
[position](const auto& order) { return order.position == position && is_finished_floor(order); })) return ready;
|
||||
return CommandStatus::InvalidTarget;
|
||||
}
|
||||
|
||||
@@ -450,7 +522,7 @@ CommandStatus World::edit_object(GridPosition position, const GridPosition* dest
|
||||
if (index != no_entity_index && index > removed) --index;
|
||||
};
|
||||
const auto order = std::find_if(production_orders_.begin(), production_orders_.end(), [&](const auto& entry) {
|
||||
return is_production_object(entry.recipe) && at_position(entry);
|
||||
return is_production_object(entry.recipe) && !is_finished_floor(entry) && at_position(entry);
|
||||
});
|
||||
if (order != production_orders_.end()) {
|
||||
if (destination) order->position = *destination;
|
||||
@@ -476,7 +548,15 @@ CommandStatus World::edit_object(GridPosition position, const GridPosition* dest
|
||||
return CommandStatus::Accepted;
|
||||
}
|
||||
const auto source = std::find_if(resource_nodes_.begin(), resource_nodes_.end(), at_position);
|
||||
if (source == resource_nodes_.end()) return CommandStatus::InvalidTarget;
|
||||
if (source == resource_nodes_.end()) {
|
||||
const auto floor = std::find_if(production_orders_.begin(), production_orders_.end(),
|
||||
[&](const auto& entry) { return is_finished_floor(entry) && at_position(entry); });
|
||||
if (floor == production_orders_.end() || destination) return CommandStatus::InvalidTarget;
|
||||
const auto removed = static_cast<std::size_t>(floor - production_orders_.begin());
|
||||
production_orders_.erase(floor);
|
||||
for (auto& agent : agents_) shift_index(agent.production_index, removed);
|
||||
return CommandStatus::Accepted;
|
||||
}
|
||||
if (destination) source->position = *destination;
|
||||
else {
|
||||
const auto removed = static_cast<std::size_t>(source - resource_nodes_.begin());
|
||||
@@ -495,7 +575,8 @@ std::uint64_t World::next_command_sequence(std::uint8_t player) const noexcept {
|
||||
CommandReceipt World::apply_command(const PlayerCommand& command) {
|
||||
const auto receipt = [&](CommandStatus status) { return CommandReceipt{status, tick_, command_revision_}; };
|
||||
const bool object_command = (command.kind >= CommandKind::PlaceBerryField && command.kind <= CommandKind::PlaceStorage) ||
|
||||
command.kind == CommandKind::PlaceFlaxField || command.kind == CommandKind::PlaceLoom;
|
||||
command.kind == CommandKind::PlaceFlaxField || command.kind == CommandKind::PlaceLoom ||
|
||||
command.kind == CommandKind::PlaceRoom;
|
||||
if (!scenario_active_ && !object_command && command.kind != CommandKind::AssignProfession &&
|
||||
command.kind != CommandKind::SetForaging) return receipt(CommandStatus::Unavailable);
|
||||
if (command.player < colony_host || command.player > colony_player_slots) {
|
||||
@@ -580,6 +661,25 @@ CommandReceipt World::apply_command(const PlayerCommand& command) {
|
||||
}
|
||||
queue_production(command.cell, RecipeId::WeaveCloth);
|
||||
break;
|
||||
case CommandKind::PlaceRoom: {
|
||||
const RoomPlan plan{command.cell, command.destination, static_cast<RoomSide>(command.value)};
|
||||
if (!can_place_room(plan) || !can_reach_object_cell(plan.first)) {
|
||||
return receipt(CommandStatus::InvalidTarget);
|
||||
}
|
||||
const auto width = static_cast<std::size_t>(plan.last.x - plan.first.x + 1);
|
||||
const auto height = static_cast<std::size_t>(plan.last.y - plan.first.y + 1);
|
||||
production_orders_.reserve(production_orders_.size() + width * height);
|
||||
for (int y = plan.first.y; y <= plan.last.y; ++y) {
|
||||
for (int x = plan.first.x; x <= plan.last.x; ++x) {
|
||||
const GridPosition cell{x, y};
|
||||
ProductionOrder order{};
|
||||
order.position = cell;
|
||||
order.recipe = plan.recipe_at(cell);
|
||||
production_orders_.push_back(std::move(order));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CommandKind::PlaceStorage:
|
||||
if (command.value > static_cast<std::uint8_t>(StorageKind::Pantry) ||
|
||||
!can_place_storage(command.cell) || !can_reach_object_cell(command.cell)) {
|
||||
|
||||
Reference in new issue
Block a user