Integrate item custody, checkpoint migration, order controls and legacy peers
This commit is contained in:
commit
22111440c9
33 files changed
+4038
-121
No files matched your search
+159
-1
@@ -72,6 +72,7 @@ constexpr int furnished_room_tool_id = 1045;
|
||||
constexpr int house_list_back_id = 1046;
|
||||
constexpr int carpenter_menu_id = 1047;
|
||||
constexpr int craft_door_id = 1048;
|
||||
constexpr int manage_orders_id = 1049;
|
||||
constexpr int first_furniture_craft_id = 1143;
|
||||
constexpr int first_work_choice_id = 1050;
|
||||
constexpr int resident_list_id = 1060;
|
||||
@@ -141,7 +142,7 @@ LanState displayed_lan_state = LanState::Offline;
|
||||
std::uint64_t lan_generation = 1;
|
||||
const auto local_worker_count = std::clamp<std::size_t>(
|
||||
std::thread::hardware_concurrency(), settlement::min_worker_count, 8);
|
||||
enum class PlacementMode { None, Building, Foraging, BerryField, FlaxField, TreePlot, Mine, Loom, Storage, Pantry, Move, Demolish, Room };
|
||||
enum class PlacementMode { None, Building, Foraging, BerryField, FlaxField, TreePlot, Mine, Loom, Storage, Pantry, Move, Demolish, Room, ManageOrders };
|
||||
PlacementMode placement_mode = PlacementMode::None;
|
||||
enum class WorkPanel { Farmer, Woodcutter, Miner, Builder, Gathering, Zones, Construction, Houses, Carpenter, None };
|
||||
WorkPanel work_panel = WorkPanel::None;
|
||||
@@ -886,6 +887,15 @@ bool can_give_orders() {
|
||||
return world && session && (lan->is_guest() ? lan->state() == LanState::GuestConnected : session->can_submit());
|
||||
}
|
||||
|
||||
bool can_manage_orders() {
|
||||
return !showing_title && can_give_orders() && !lan->is_guest() && !session->guest() &&
|
||||
!session->changing_world();
|
||||
}
|
||||
|
||||
bool manageable_order(const settlement::ProductionOrder& order) {
|
||||
return order.suspended || order.state != settlement::JobState::Completed;
|
||||
}
|
||||
|
||||
void update_roster_details() {
|
||||
const auto* resident = selected_agent();
|
||||
const auto role = resident ? profession_name(resident->profession) : L"";
|
||||
@@ -1482,6 +1492,9 @@ bool valid_edit_cell(settlement::GridPosition cell) {
|
||||
case PlacementMode::Move:
|
||||
return move_source ? world->can_place_storage(cell) : world->object_status(cell, true) == CommandStatus::Accepted;
|
||||
case PlacementMode::Demolish: return world->object_status(cell, false) == CommandStatus::Accepted;
|
||||
case PlacementMode::ManageOrders:
|
||||
return can_manage_orders() && std::any_of(world->production_orders().begin(), world->production_orders().end(),
|
||||
[cell](const auto& order) { return order.position == cell && manageable_order(order); });
|
||||
case PlacementMode::Building:
|
||||
return world->scenario_active() ? world->can_place_bed(cell) : world->can_place_cabin(cell);
|
||||
case PlacementMode::Room:
|
||||
@@ -1736,6 +1749,11 @@ void complete_command(std::uint64_t id, const settlement::SessionPayload& payloa
|
||||
}
|
||||
if (accepted) {
|
||||
placement_message = L"Команда выполнена.";
|
||||
if (std::holds_alternative<settlement::CancelProductionPayload>(payload)) {
|
||||
placement_message = L"Заказ отменён. Установленные части сохранены; груз вернут жители.";
|
||||
} else if (std::holds_alternative<settlement::ResumeProductionPayload>(payload)) {
|
||||
placement_message = L"Работа по заказу возобновлена.";
|
||||
}
|
||||
if (const auto* command = std::get_if<settlement::CommandPayload>(&payload)) {
|
||||
if (command->kind == settlement::CommandKind::MoveObject && move_source == command->cell) {
|
||||
move_source.reset();
|
||||
@@ -1747,6 +1765,13 @@ void complete_command(std::uint64_t id, const settlement::SessionPayload& payloa
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (std::holds_alternative<settlement::CancelProductionPayload>(payload) ||
|
||||
std::holds_alternative<settlement::ResumeProductionPayload>(payload)) {
|
||||
placement_message = status == settlement::CommandStatus::Busy
|
||||
? L"Заказ пока нельзя изменить. Дождитесь возврата материалов или повторите позже."
|
||||
: L"Заказ отклонён: работа уже завершена, удалена или изменилась.";
|
||||
return;
|
||||
}
|
||||
placement_message = status == settlement::CommandStatus::Busy
|
||||
? L"Объект занят. Дождитесь окончания работы или сна."
|
||||
: L"Команда отклонена. Проверьте клетку и доступ к ней. Чертёж сохранён.";
|
||||
@@ -1848,8 +1873,115 @@ void pump_session(HWND window) {
|
||||
invalidate_scene(window);
|
||||
}
|
||||
|
||||
const wchar_t* production_name(settlement::RecipeId recipe) {
|
||||
using settlement::RecipeId;
|
||||
switch (recipe) {
|
||||
case RecipeId::SawPlank: return L"Распилить доску";
|
||||
case RecipeId::CutStoneBlock: return L"Вытесать каменный блок";
|
||||
case RecipeId::BuildCabin: return L"Построить домик";
|
||||
case RecipeId::BuildBed: return L"Спальное место";
|
||||
case RecipeId::WeaveCloth: return L"Ткать ткань";
|
||||
case RecipeId::BuildFloor: return L"Пол";
|
||||
case RecipeId::BuildWall: return L"Стена";
|
||||
case RecipeId::BuildDoorAlongX:
|
||||
case RecipeId::BuildDoorAlongY: return L"Построить дверь";
|
||||
case RecipeId::BuildMedicineCabinet: return L"Построить аптечный шкаф";
|
||||
case RecipeId::BuildMiningRack: return L"Построить стойку шахтёра";
|
||||
case RecipeId::BuildLoom: return L"Построить ткацкий станок";
|
||||
case RecipeId::InstallDoorAlongX:
|
||||
case RecipeId::InstallDoorAlongY: return L"Установить дверь";
|
||||
case RecipeId::CraftWoodenDoor: return L"Изготовить дверь";
|
||||
case RecipeId::InstallMedicineCabinet: return L"Установить аптечный шкаф";
|
||||
case RecipeId::InstallMiningRack: return L"Установить стойку шахтёра";
|
||||
case RecipeId::InstallLoom: return L"Установить ткацкий станок";
|
||||
case RecipeId::CraftMedicineCabinet: return L"Изготовить аптечный шкаф";
|
||||
case RecipeId::CraftMiningRack: return L"Изготовить стойку шахтёра";
|
||||
case RecipeId::CraftLoom: return L"Изготовить ткацкий станок";
|
||||
}
|
||||
return L"Производственный заказ";
|
||||
}
|
||||
|
||||
void manage_orders_at_cell(HWND window, settlement::GridPosition cell) {
|
||||
if (!can_manage_orders()) return;
|
||||
// Popup menus pump nested messages. Keep every displayed order alive and
|
||||
// fence both replacement admission and completed world/session replacement.
|
||||
const auto opening = session->runtime().latest();
|
||||
const auto generation = session->generation();
|
||||
const auto* opening_session = session.get();
|
||||
const auto network_generation = lan_generation;
|
||||
const auto* connection = lan.get();
|
||||
const auto current_context = [&] {
|
||||
return can_manage_orders() && session.get() == opening_session && session->generation() == generation &&
|
||||
session->runtime().latest()->identity == opening->identity && network_generation == lan_generation &&
|
||||
connection == lan.get() && placement_mode == PlacementMode::ManageOrders;
|
||||
};
|
||||
constexpr std::size_t page_size = 16;
|
||||
constexpr UINT previous_page = 100;
|
||||
constexpr UINT next_page = 101;
|
||||
std::size_t offset = 0;
|
||||
POINT cursor{};
|
||||
GetCursorPos(&cursor);
|
||||
for (;;) {
|
||||
std::array<const settlement::ProductionOrder*, page_size> choices{};
|
||||
std::size_t count = 0, skipped = 0;
|
||||
bool more = false;
|
||||
for (const auto& order : opening->world->production_orders()) {
|
||||
if (order.position != cell || !manageable_order(order)) continue;
|
||||
if (skipped++ < offset) continue;
|
||||
if (count == page_size) { more = true; break; }
|
||||
choices[count++] = ℴ
|
||||
}
|
||||
if (count == 0) {
|
||||
placement_message = L"На этой клетке нет незавершённых или приостановленных заказов.";
|
||||
return;
|
||||
}
|
||||
const auto menu = CreatePopupMenu();
|
||||
if (!menu) return;
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
const auto& order = *choices[index];
|
||||
const auto title = std::wstring(order.suspended ? L"Возобновить: " : L"Отменить: ") +
|
||||
production_name(order.recipe) + L" №" + std::to_wstring(order.id) + L" [" +
|
||||
std::to_wstring(cell.x + 1) + L", " + std::to_wstring(cell.y + 1) + L"]";
|
||||
AppendMenuW(menu, MF_STRING, index + 1, title.c_str());
|
||||
}
|
||||
if (offset != 0 || more) AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
|
||||
if (offset != 0) AppendMenuW(menu, MF_STRING, previous_page, L"← Предыдущие заказы");
|
||||
if (more) AppendMenuW(menu, MF_STRING, next_page, L"Следующие заказы →");
|
||||
const auto selected = static_cast<UINT>(TrackPopupMenu(menu, TPM_RETURNCMD |
|
||||
TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, cursor.x, cursor.y, 0, window, nullptr));
|
||||
DestroyMenu(menu);
|
||||
if (!current_context()) {
|
||||
placement_message = L"Поселение или режим изменились. Выберите заказ заново.";
|
||||
return;
|
||||
}
|
||||
if (selected == previous_page) { offset -= page_size; continue; }
|
||||
if (selected == next_page) { offset += page_size; continue; }
|
||||
if (selected == 0 || selected > count) return;
|
||||
const auto& chosen = *choices[selected - 1];
|
||||
const auto current = session->runtime().latest();
|
||||
const auto* order = current->world->find_production(chosen.id);
|
||||
if (!order || order->position != chosen.position || order->recipe != chosen.recipe ||
|
||||
order->suspended != chosen.suspended || !manageable_order(*order)) {
|
||||
placement_message = L"Заказ изменился. Выберите его заново.";
|
||||
return;
|
||||
}
|
||||
const settlement::SessionPayload payload = chosen.suspended
|
||||
? settlement::SessionPayload{settlement::ResumeProductionPayload{chosen.id}}
|
||||
: settlement::SessionPayload{settlement::CancelProductionPayload{chosen.id}};
|
||||
placement_message = enqueue_command(payload) ? L"Изменение заказа ожидает подтверждения…"
|
||||
: L"Очередь занята. Попробуйте ещё раз.";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void edit_at_cell(HWND window, settlement::GridPosition cell) {
|
||||
if (!can_give_orders()) return;
|
||||
if (placement_mode == PlacementMode::ManageOrders) {
|
||||
manage_orders_at_cell(window, cell);
|
||||
update_status();
|
||||
invalidate_scene(window);
|
||||
return;
|
||||
}
|
||||
const auto held_world = world;
|
||||
const auto generation = session->generation();
|
||||
const auto installed_session = session->runtime().latest()->identity.session;
|
||||
@@ -1919,6 +2051,7 @@ HMENU create_work_menu() {
|
||||
role_choices[static_cast<std::size_t>(id - farmer_menu_id + 1)].title);
|
||||
}
|
||||
AppendMenuW(menu, MF_STRING, carpenter_menu_id, L"Плотник");
|
||||
if (can_manage_orders()) AppendMenuW(menu, MF_STRING, manage_orders_id, L"Управление заказами…");
|
||||
AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
|
||||
AppendMenuW(menu, MF_STRING, residents_button_id, L"Жители…\tC");
|
||||
return menu;
|
||||
@@ -2138,6 +2271,24 @@ std::wstring resident_details() {
|
||||
profession_name(resident->profession) + L" Голод " + std::to_wstring(hunger) + L"%";
|
||||
if (resident->state == settlement::AgentState::GoingToEat) text += L" Идёт к кладовой";
|
||||
else if (resident->state == settlement::AgentState::Eating) text += L" Ест";
|
||||
else if (resident->state == settlement::AgentState::Returning) {
|
||||
text += L" Возвращает материалы";
|
||||
if (resident->execution) {
|
||||
switch (resident->execution->blocked) {
|
||||
case settlement::CustodyStatus::NoDestination:
|
||||
text += L": нет доступного склада с местом"; break;
|
||||
case settlement::CustodyStatus::Capacity:
|
||||
text += L": на складе недостаточно места"; break;
|
||||
case settlement::CustodyStatus::Busy:
|
||||
text += L": ожидает освобождения склада"; break;
|
||||
case settlement::CustodyStatus::Exhausted:
|
||||
case settlement::CustodyStatus::Overflow:
|
||||
text += L": достигнут предел учёта запасов"; break;
|
||||
case settlement::CustodyStatus::Accepted: break;
|
||||
default: text += L": ожидает возможности сдать груз"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (world->find_production(resident->production_id) != nullptr &&
|
||||
settlement::is_carpentry_recipe(world->find_production(resident->production_id)->recipe)) {
|
||||
text += resident->state == settlement::AgentState::Working ? L" Работает за верстаком" :
|
||||
@@ -2237,6 +2388,8 @@ std::pair<std::wstring, std::wstring> prepare_hud() {
|
||||
L"Выберите кровать, склад, станок или посаженный участок.";
|
||||
} else if (placement_mode == PlacementMode::Demolish) {
|
||||
hint = L"Щёлкните по объекту, чтобы снести его. Правая кнопка — отмена.";
|
||||
} else if (placement_mode == PlacementMode::ManageOrders) {
|
||||
hint = L"Щёлкните по площадке или станку. Выберите заказ, чтобы отменить или возобновить работу.";
|
||||
} else if (placement_mode == PlacementMode::Room) {
|
||||
if (room_draft_move) {
|
||||
hint = L"Щёлкните по новой площадке. R поворачивает дом, правый щелчок отменяет перенос.";
|
||||
@@ -2793,6 +2946,11 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
||||
if (world) show_resident_roster(window);
|
||||
return 0;
|
||||
}
|
||||
if (LOWORD(wparam) == manage_orders_id && HIWORD(wparam) == BN_CLICKED) {
|
||||
if (can_manage_orders()) set_placement_mode(window, PlacementMode::ManageOrders);
|
||||
SetFocus(window);
|
||||
return 0;
|
||||
}
|
||||
if (HIWORD(wparam) == BN_CLICKED && LOWORD(wparam) == build_blueprint_id) {
|
||||
submit_blueprint(window);
|
||||
SetFocus(window);
|
||||
|
||||
Reference in new issue
Block a user