CivilWar/src/august19_demo.cpp

src / august19_demo.cpp

src/august19_demo.cpp · 38.4 KB

#include <algorithm>
#include <array>
#include <charconv>
#include <cstdint>
#include <iostream>
#include <random>
#include <string>
#include <string_view>

#include "combat_engine.hpp"

#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#endif

namespace {

struct Options {
    std::uint32_t seed = 19910819U;
    bool help = false;
};

bool parseOptions(int argc, char* argv[], Options& options) {
    for (int i = 1; i < argc; ++i) {
        const std::string arg = argv[i];
        if (arg == "--help" || arg == "-h") {
            options.help = true;
            continue;
        }
        if (arg == "--seed" && i + 1 < argc) {
            const std::string value = argv[++i];
            std::uint32_t seed = 0;
            const auto parsed = std::from_chars(value.data(),
                                                 value.data() + value.size(), seed);
            if (parsed.ec != std::errc{} || parsed.ptr != value.data() + value.size()) {
                return false;
            }
            options.seed = seed;
            continue;
        }
        if (arg.rfind("--seed=", 0) == 0) {
            const std::string value = arg.substr(7);
            std::uint32_t seed = 0;
            const auto parsed = std::from_chars(value.data(),
                                                 value.data() + value.size(), seed);
            if (parsed.ec != std::errc{} || parsed.ptr != value.data() + value.size()) {
                return false;
            }
            options.seed = seed;
            continue;
        }
        return false;
    }
    return true;
}

enum class Alignment { Undecided, AntiCommittee, Committee };

class Chapter {
public:
    Chapter(std::uint32_t seed, std::istream& input, std::ostream& output)
        : rng_(seed),
          eventRng_(seed ^ 0x8A9D1991U),
          input_(input),
          output_(output),
          seed_(seed) {
        generateCrewNames(seed);
        state_ = civil_war::makeDefaultCheckpoint(seed);
        for (std::size_t index = 0;
             index < crewNames_.size() && index < state_.friendly.size();
             ++index) {
            state_.friendly[index].name = crewNames_[index];
            state_.friendly[index].nationality = crewOrigins_[index];
        }
    }

    int run() {
        printIntro();
        fixedBriefing();
        fixedRoadEvent();
        checkpointNegotiation();
        fixedSmolenskEvent();
        whiteHouseChoice();
        assassinationTransition();
        afternoonEncounter();
        chapterEpilogue();
        return 0;
    }

private:
    std::mt19937 rng_;
    std::mt19937 eventRng_;
    std::istream& input_;
    std::ostream& output_;
    std::uint32_t seed_;
    std::array<std::string, 4> crewNames_{};
    std::array<std::string, 4> crewOrigins_{};
    Alignment alignment_ = Alignment::Undecided;
    int tension_ = 25;
    int checkpointMorale_ = 64;
    int commanderHealth_ = 100;
    int bmpCondition_ = 100;
    int roundsRemaining_ = 8;
    bool dismounted_ = false;
    bool inCover_ = false;
    bool checkpointCleared_ = false;
    bool stoppedForInjuredCivilian_ = false;
    bool sniperJoined_ = false;
    std::string passageResult_ = "尚未接触";
    std::string afternoonEventName_ = "未发生";
    std::string afternoonOutcome_ = "未结算";
    civil_war::GameState state_;

    template <std::size_t Size>
    std::string chooseName(const std::array<std::string_view, Size>& names,
                           std::mt19937& generator) {
        const auto index = std::uniform_int_distribution<std::size_t>(
            0, Size - 1)(generator);
        return std::string(names[index]);
    }

    std::string generateName(int origin, std::mt19937& generator) {
        static constexpr std::array<std::string_view, 8> uaGiven = {
            "Іван", "Микола", "Андрій", "Олексій", "Петро", "Василь", "Богдан", "Тарас"};
        static constexpr std::array<std::string_view, 8> uaPatronymic = {
            "Іванович", "Миколайович", "Андрійович", "Олексійович", "Петрович", "Васильович", "Богданович", "Тарасович"};
        static constexpr std::array<std::string_view, 8> uaFamily = {
            "Мельник", "Шевченко", "Коваленко", "Бондаренко", "Ткаченко", "Кравченко", "Олійник", "Поліщук"};
        static constexpr std::array<std::string_view, 8> ruGiven = {
            "Александр", "Дмитрий", "Сергей", "Андрей", "Алексей", "Николай", "Владимир", "Михаил"};
        static constexpr std::array<std::string_view, 8> ruPatronymic = {
            "Сергеевич", "Иванович", "Николаевич", "Владимирович", "Андреевич", "Михайлович", "Алексеевич", "Петрович"};
        static constexpr std::array<std::string_view, 8> ruFamily = {
            "Иванов", "Петров", "Смирнов", "Кузнецов", "Попов", "Соколов", "Морозов", "Васильев"};
        static constexpr std::array<std::string_view, 8> byGiven = {
            "Іван", "Мікалай", "Андрэй", "Аляксей", "Павел", "Васіль", "Сяргей", "Дзмітрый"};
        static constexpr std::array<std::string_view, 8> byPatronymic = {
            "Іванавіч", "Мікалаевіч", "Андрэевіч", "Аляксеевіч", "Паўлавіч", "Васілевіч", "Сяргеевіч", "Дзмітрыевіч"};
        static constexpr std::array<std::string_view, 8> byFamily = {
            "Каваленка", "Мельнік", "Сідарэнка", "Казлоў", "Ганчар", "Сакалоўскі", "Бандарэнка", "Новік"};
        if (origin == 0) {
            return chooseName(uaGiven, generator) + " " +
                   chooseName(uaPatronymic, generator) + " " +
                   chooseName(uaFamily, generator);
        }
        if (origin == 2) {
            return chooseName(byGiven, generator) + " " +
                   chooseName(byPatronymic, generator) + " " +
                   chooseName(byFamily, generator);
        }
        return chooseName(ruGiven, generator) + " " +
               chooseName(ruPatronymic, generator) + " " +
               chooseName(ruFamily, generator);
    }

    void generateCrewNames(std::uint32_t seed) {
        std::mt19937 names(seed ^ 0x6A09E667U);
        const std::array<int, 4> origins = {
            0, 1, std::uniform_int_distribution<int>(0, 1)(names),
            std::uniform_int_distribution<int>(1, 2)(names)};
        const std::array<std::string, 3> labels = {"乌克兰", "俄罗斯", "白俄罗斯"};
        for (std::size_t i = 0; i < origins.size(); ++i) {
            crewNames_[i] = generateName(origins[i], names);
            crewOrigins_[i] = labels[static_cast<std::size_t>(origins[i])];
        }
    }

    int askChoice(std::string_view prompt, int low, int high) {
        while (true) {
            output_ << prompt;
            std::string line;
            if (!std::getline(input_, line)) {
                return high;
            }
            if (line == "q" || line == "Q") {
                return high;
            }
            int value = 0;
            const auto parsed = std::from_chars(line.data(),
                                                 line.data() + line.size(), value);
            if (parsed.ec == std::errc{} && parsed.ptr == line.data() + line.size() &&
                value >= low && value <= high) {
                return value;
            }
            output_ << "请输入 " << low << " 到 " << high << " 之间的编号。\n";
        }
    }

    void printIntro() {
        output_ << "============================================================\n"
                << "  《路障前的命令:八月十九日》\n"
                << "  莫斯科 · 1991 年 8 月 19 日 · 固定剧情章节\n"
                << "============================================================\n\n"
                << "你是乌克兰籍 BMP-2 车长,跟随塔曼师进入莫斯科城区巡逻。\n"
                << "妻子和女儿在基辅。政变消息刚传来,车组还没有选边。\n"
                << "今日路上的事件按固定顺序发生;阵营只会在白宫前的选择中确定。\n"
                << "随机种子: " << seed_
                << "(遇刺前固定;下午用独立事件流抽取双派冲突)\n\n";
        showCrewAndStatus();
    }

    void showCrewAndStatus() {
        static constexpr std::array<std::string_view, 4> ids = {"C1", "G1", "D1", "M1"};
        static constexpr std::array<std::string_view, 4> roles = {"车长", "炮手", "驾驶员", "机枪手"};
        output_ << "车组:\n";
        for (std::size_t i = 0; i < ids.size(); ++i) {
            output_ << "  " << ids[i] << " " << crewNames_[i] << "("
                    << crewOrigins_[i] << ")— " << roles[i] << '\n';
        }
        if (state_.friendly.size() > ids.size()) {
            for (std::size_t index = ids.size();
                 index < state_.friendly.size(); ++index) {
                const civil_war::FriendlyPerson& person = state_.friendly[index];
                output_ << "  " << person.id << " " << person.name
                        << "(" << person.nationality << ")— " << person.role
                        << '\n';
            }
        }
        output_ << "BMP-2 乘员 "
                << (sniperJoined_ ? "5/10" : "4/10")
                << " | 车况 " << bmpCondition_ << "/100\n"
                << "政治归属: " << alignmentLabel() << "\n";
    }

    std::string alignmentLabel() const {
        switch (alignment_) {
        case Alignment::Undecided: return "未选边";
        case Alignment::AntiCommittee: return "反紧急状态委员会";
        case Alignment::Committee: return "紧急状态委员会";
        }
        return "未选边";
    }

    void fixedBriefing() {
        output_ << "\n【07:20 · 加加林广场,列宁大街】\n"
                << "车队进入城区。命令要求保持巡逻、观察关键路口,不得擅自加入任何政治集会。\n"
                << "无线电里先后传来两条互相矛盾的消息:一条要求协助维持紧急状态,\n"
                << "另一条要求部队不要干预俄罗斯共和国机关。上级没有给出明确解释。\n"
                << "1. 复诵两条命令并记录来源\n"
                << "2. 暂不回复,继续巡逻\n";
        const int choice = askChoice("> ", 1, 2);
        if (choice == 1) {
            output_ << "你把两条命令都记在值勤簿上。车组知道命令冲突,但没有人被贴上阵营标签。\n";
        } else {
            output_ << "你保持无线电静默。两条命令都没有被正式接受,巡逻继续。\n";
        }
        output_ << "政治归属仍为“未选边”。\n";
    }

    void fixedRoadEvent() {
        output_ << "\n【09:10 · 克里米亚桥北侧】\n"
                << "一辆无轨电车斜停在车道上,旁边有一名被碎玻璃划伤的乘客。道路仍可绕行。\n"
                << "1. 停车,让 M1 和车长协助伤者(延误约二十分钟)\n"
                << "2. 保持巡逻路线,从旁边车道缓慢绕行\n";
        const int choice = askChoice("> ", 1, 2);
        if (choice == 1) {
            stoppedForInjuredCivilian_ = true;
            output_ << "你让驾驶员停车,车长和机枪手用急救包处理伤口。乘客能自行离开,\n"
                    << "几名围观者记住了这辆 BMP-2 没有把他们当成敌人。巡逻晚了二十分钟。\n";
        } else {
            output_ << "驾驶员慢速绕过电车。乘客由路边人群照料,车组没有停留。\n";
        }
        output_ << "无论如何,车组仍未选边。\n";
    }

    int clampTension(int delta) {
        tension_ = std::clamp(tension_ + delta, 0, 100);
        return tension_;
    }

    int negotiationChance(int actionBonus) const {
        const int calmBonus = (100 - tension_) / 5;
        const int moraleBonus = (100 - checkpointMorale_) / 5;
        return std::clamp(28 + calmBonus + moraleBonus + actionBonus, 12, 88);
    }

    bool attemptAgreement(int actionBonus) {
        const int chance = negotiationChance(actionBonus);
        const int roll = std::uniform_int_distribution<int>(0, 99)(rng_);
        output_ << "通行安排判定: " << chance << "%(当前紧张度 " << tension_
                << ",对方士气 " << checkpointMorale_ << "/100)。\n";
        if (roll < chance) {
            checkpointCleared_ = true;
            passageResult_ = "谈判通行";
            output_ << "警察班长让部下把枪口压低,接受你提出的低速通过与不追击安排。\n";
            return true;
        }
        output_ << "对方没有接受,但在紧张度未满时仍未开火;班长要求你保持原位。\n";
        return false;
    }

    void checkpointNegotiation() {
        output_ << "\n【10:05 · 花园环路,祖波夫广场检查点】\n"
                << "三名无防弹衣的警察/安全人员横在路口,两人持 AKM,一人持马卡洛夫手枪。\n"
                << "他们说正在执行封路命令,拒绝让 BMP-2 通过,但尚未射击。\n"
                << "这是一场固定教学遭遇,不是随机事件。你通过车载扩音器开始交涉。\n";

        while (!checkpointCleared_) {
            output_ << "\n【谈判回合 " << (9 - roundsRemaining_) << "】紧张度 "
                    << tension_ << "/100 | 警察班长士气 " << checkpointMorale_ << "/100\n"
                    << "1. 安抚:降低紧张度,争取对方相信车组无意伤人\n"
                    << "2. 施压:提高紧张度、压低对方士气,迫使其接受条件\n"
                    << "3. 威胁:向天鸣枪(紧张度 +25;可能压低士气或使其放弃抵抗)\n"
                    << "4. 下车接近检查点(提高紧张度)\n"
                    << "5. 移动 BMP-2 或徒步变换位置(提高紧张度)\n"
                    << "6. 寻找掩体(提高紧张度)\n"
                    << "7. 直接向对方射击(立即将紧张度打满并触发开火)\n"
                    << "8. 停止交涉,绕行离开\n";
            const int choice = askChoice("> ", 1, 8);
            --roundsRemaining_;
            int bonus = 0;
            switch (choice) {
            case 1:
                clampTension(-18);
                checkpointMorale_ = std::max(0, checkpointMorale_ - 3);
                bonus = 8;
                output_ << "你放低扩音器音量,说明车组只想通过。紧张度下降 18,对方士气 -3。\n";
                break;
            case 2:
                clampTension(12);
                checkpointMorale_ = std::max(0, checkpointMorale_ - 14);
                bonus = 12;
                output_ << "你要求他们立即让路,并指出继续阻拦会承担责任。紧张度 +12,对方士气 -14。\n";
                break;
            case 3:
                clampTension(25);
                output_ << "你朝天鸣枪警告。紧张度 +25(当前 " << tension_
                        << "/100);这次警告枪不等同于向对方开火。\n";
                {
                    const int intimidation = std::uniform_int_distribution<int>(0, 99)(rng_);
                    if (intimidation < 18) {
                        checkpointMorale_ = 0;
                        checkpointCleared_ = true;
                        passageResult_ = "警告后对方放弃抵抗";
                        output_ << "警察班长喝止部下并命令放下武器;对方直接放弃抵抗。\n";
                        return;
                    }
                    if (intimidation < 58) {
                        checkpointMorale_ = std::max(0, checkpointMorale_ - 18);
                        output_ << "枪声震住了路口人员,对方士气 -18(剩余 "
                                << checkpointMorale_ << "/100)。\n";
                    } else {
                        output_ << "对方没有被吓退,但暂时没有开火。\n";
                    }
                }
                break;
            case 4:
                if (dismounted_) {
                    output_ << "车长已经下车,不能重复下车。\n";
                    break;
                }
                dismounted_ = true;
                clampTension(18);
                output_ << "车长下车。路口警察把枪口转向你;紧张度 +18。\n";
                break;
            case 5:
                clampTension(16);
                output_ << "BMP-2 向前挪动,或车组徒步换位。紧张度 +16。\n";
                break;
            case 6:
                inCover_ = true;
                clampTension(10);
                output_ << "队员移向路边掩体。对方认为车组在准备战斗;紧张度 +10。\n";
                break;
            case 7:
                tension_ = 100;
                output_ << "第一声枪响让紧张度立即升至 100;谈判结束,检查点人员开火。\n";
                resolveEscalation();
                return;
            case 8:
                passageResult_ = "绕行离开";
                output_ << "你没有强行通过,驾驶员沿支路绕开检查点。警察没有追击。\n";
                return;
            default: break;
            }

            if (tension_ >= 100) {
                output_ << "紧张度达到 100;检查点人员立即开火。\n";
                resolveEscalation();
                return;
            }
            if ((choice == 1 || choice == 2) && attemptAgreement(bonus)) return;
            output_ << "警察班长举手示意部下暂缓,但不放下武器。紧张度未满 100,对方不射击。\n";
            if (roundsRemaining_ <= 0) {
                output_ << "交涉窗口已经耗尽,但警察仍未开火。\n"
                        << "1. 拒绝继续僵持,命令车组以战斗强行驶过\n"
                        << "2. 保持克制,沿支路绕行\n";
                const int finalChoice = askChoice("> ", 1, 2);
                if (finalChoice == 1) {
                    tension_ = 100;
                    passageResult_ = "谈判破裂后选择继续推进";
                    output_ << "你命令车组做好战斗准备;共享战斗引擎接管接触。\n";
                    enterCheckpointCombat();
                } else {
                    passageResult_ = "绕行离开";
                    output_ << "你没有把僵持升级为交火,驾驶员沿支路绕开检查点。\n";
                }
                return;
            }
        }
    }

    void resolveEscalation() {
        output_ << "\n【接触升级为交火】\n";
        output_ << "谈判紧张值已满,全部仍能行动的检查点人员和车组成员"
                << "转入同一套逐人命令、伤害、士气与结局规则。\n";
        enterCheckpointCombat();
    }

    void syncStateFromPrototype() {
        state_.tension = tension_;
        if (!state_.friendly.empty()) {
            state_.friendly[0].health = commanderHealth_;
            if (dismounted_) {
                state_.friendly[0].mounted = false;
                state_.friendly[0].location = civil_war::Location::Roadblock;
                if (inCover_) {
                    state_.friendly[0].coverId = "police_car";
                }
            }
        }
        state_.vehicle.condition = bmpCondition_;
    }

    void syncPrototypeFromState() {
        tension_ = state_.tension;
        commanderHealth_ = state_.friendly.empty()
                               ? 0
                               : state_.friendly.front().health;
        bmpCondition_ = state_.vehicle.condition;
        dismounted_ = !state_.friendly.empty() &&
                      !state_.friendly.front().mounted;
        inCover_ = !state_.friendly.empty() &&
                   !state_.friendly.front().coverId.empty();
    }

    void enterCheckpointCombat() {
        syncStateFromPrototype();
        civil_war::GameState checkpoint = state_;
        checkpoint.enemies.clear();
        auto addOfficer = [&checkpoint](std::string id, std::string name,
                                        std::string weapon, int morale,
                                        int stamina,
                                        civil_war::Location location) {
            checkpoint.enemies.push_back(
                {std::move(id), std::move(name),
                 civil_war::UnitProfile::MvdOfficer,
                 civil_war::FactionId::Mvd,
                 civil_war::Disposition::Hostile,
                 std::move(weapon), 100, morale, stamina, 0, 0, location,
                 false, false, civil_war::EnemyStatus::Active, false, ""});
        };
        addOfficer("MVD-1", "警察班长", "AKM",
                   std::max(1, checkpointMorale_), 62,
                   civil_war::Location::Roadblock);
        addOfficer("MVD-2", "持步枪警察", "AKM",
                   std::max(1, checkpointMorale_ - 8), 68,
                   civil_war::Location::Roadblock);
        addOfficer("MVD-3", "持手枪安全人员", "马卡洛夫手枪",
                   std::max(1, checkpointMorale_ - 5), 72,
                   civil_war::Location::Roadblock);
        checkpoint.mvdMorale = std::max(1, checkpointMorale_);
        checkpoint.mvdOrganization = std::max(30, checkpointMorale_);
        checkpoint.tension = 100;
        checkpoint.round = 1;
        checkpoint.completedRounds = 0;
        checkpoint.ending = civil_war::Ending::None;
        checkpoint.endingRound = 0;
        checkpoint.bystanders = 0;
        checkpoint.bystanderRisk = std::min(100, state_.bystanderRisk + 20);

        civil_war::EncounterConfig config;
        config.seed = seed_;
        config.state = checkpoint;
        config.roundLimit = 8;
        config.standardBriefing = false;
        config.standardEnding = false;
        config.allowCoverTargets = false;
        config.encounterTitle = "祖波夫广场 · 检查点交火";
        config.objective =
            "压制或迫使三名检查点人员退出;也可撤离,但绕行不再自动视为谈判成功。";
        config.sectorLabel = "车队所在车道";
        config.contactLabel = "检查点";
        config.exitLabel = "检查点之后";
        config.negotiatedPassageFactions = {civil_war::FactionId::Mvd};
        const civil_war::CombatResult result =
            civil_war::runEncounter(config, input_, output_);
        state_ = result.state;
        syncPrototypeFromState();
        checkpointCleared_ =
            state_.ending == civil_war::Ending::RoadblockResolved ||
            state_.ending == civil_war::Ending::ForcedPassage ||
            state_.ending == civil_war::Ending::NegotiatedPassage;
        passageResult_ = civil_war::endingName(state_.ending);
        output_ << "\n【检查点战斗返回章节】\n"
                << "结果: " << passageResult_
                << " | 车组与车辆状态、弹药和人员伤势已写回章节完整状态。\n";
    }

    void fixedSmolenskEvent() {
        output_ << "\n【11:35 · 斯摩棱斯克广场】\n"
                << "广播重复播放紧急状态委员会的公告,路边报纸却印着叶利钦要求部队不要服从非法命令的声明。\n"
                << "车组有人说应该听从军令,也有人提醒你:基辅的家人不在这场争权的地图上。\n"
                << "你只记录消息,没有发表立场。当前路口结果:" << passageResult_ << "。\n"
                << "政治归属仍为“未选边”。\n";
    }

    void whiteHouseChoice() {
        output_ << "\n【12:20 · 卡利宁桥与俄罗斯白宫前场】\n"
                << "白宫外聚集了人群。叶利钦爬上坦克发表讲话。\n"
                << "你在经互会大楼一侧发现一名狙击手,枪口正朝白宫方向。\n"
                << "此刻的决定会被两边视为你的公开站队。\n"
                << "1. 命令车组控制并抓捕狙击手\n"
                << "2. 掩护狙击手完成射击并撤离\n";
        const int choice = askChoice("> ", 1, 2);
        if (choice == 1) {
            alignment_ = Alignment::AntiCommittee;
            output_ << "M1 从侧面压住枪管,D1 把 BMP-2 横在撤离路线上。狙击手被缴械拘押。\n"
                    << "紧急状态委员会的联络员在无线电里斥责你抗命;白宫守卫则把你视作盟友。\n"
                    << "你没有让眼前这名狙击手开枪。\n";
        } else {
            alignment_ = Alignment::Committee;
            sniperJoined_ = true;
            state_.friendly.push_back(
                {"S1", "狙击手", "援引临时入队 / 精确射手",
                 "狙击步枪、手枪", 100, 88, 0,
                 state_.vehicle.location, true,
                 false, false, false, "", false, "俄罗斯"});
            output_ << "你命令 M1 制造掩护、驾驶员挡住人群视线。狙击手完成射击后撤回 BMP-2。\n"
                    << "车组从此多了一名陌生射手。他被记作 S1;真实姓名和履历仍待核实。\n"
                    << "紧急状态委员会通过无线电认可了你的行动。\n";
        }
        output_ << "阵营确认:" << alignmentLabel() << "。\n";
    }

    void assassinationTransition() {
        output_ << "\n【固定剧情 · 叶利钦遇刺】\n";
        if (alignment_ == Alignment::AntiCommittee) {
            output_ << "你们沿卡利宁桥离开时,白宫另一侧传来枪声。无线电很快确认:叶利钦被另一处的狙击手击毙。\n"
                    << "抓捕眼前枪手没有改变这场死亡,却改变了你站在哪一边。委员会称你叛变;\n"
                    << "反委员会联络组要求你带车组守住白宫外围,协助撤出议员和平民。\n";
        } else {
            output_ << "狙击手的子弹击中白宫前场的叶利钦。人群骤然散开,电台开始播报“恢复秩序”的消息。\n"
                    << "委员会要求你把 S1 带去接受审查,但他已是车组成员;他的服从、忠诚与可靠性都还没有证明。\n";
        }
        output_ << "\n【过渡剧情 · 下午】\n"
                << "莫斯科的电话线持续占线。你尝试联系在基辅做医生的妻子,线路只传来断续忙音;\n"
                << "女儿所在学校也没有回应。各单位开始要求部队重新报到,街道上的路障正在增加。\n"
                << "\n下一阶段目标:带着车组离开白宫周边,找到仍可信的指挥链,并设法确认基辅家人的安全。\n"
                << "白宫周边已经出现亲叶利钦支持者与紧急状态委员会军队的武装接触。\n\n";
        showCrewAndStatus();
        output_ << "检查点结果: " << passageResult_
                << " | 民间援助: " << (stoppedForInjuredCivilian_ ? "已停下救助" : "绕行")
                << " | 车长生命: " << commanderHealth_ << "/100\n";
    }

    void printAfternoonStatus() {
        output_ << "\n下午状态: 车况 " << state_.vehicle.condition
                << "/100 | 30mm " << state_.ammo.cannon30mm
                << " | PKT " << state_.ammo.coaxialPkt
                << " | AKS 弹匣 " << state_.ammo.aksMagazines
                << " | PKM 弹链 " << state_.ammo.pkmBelts
                << " | 入队人数 " << state_.friendly.size() << '\n';
        for (const civil_war::FriendlyPerson& person : state_.friendly) {
            output_ << "  " << person.id << " " << person.name
                    << " 生命 " << person.health << "/100 | "
                    << (person.mounted ? "车内" : "车外") << '\n';
        }
    }

    civil_war::GameState buildAfternoonState(const std::string& supporterName,
                                             const std::string& committeeName,
                                             int eventIndex) {
        civil_war::GameState combat = state_;
        for (civil_war::FriendlyPerson& person : combat.friendly) {
            person.location = civil_war::Location::Approach;
            person.acted = false;
            person.reactionUsed = false;
            person.overwatch = false;
            if (person.mounted) {
                person.coverId.clear();
            }
        }
        combat.vehicle.location = civil_war::Location::Approach;
        combat.vehicle.moving = false;
        combat.policeCar.name =
            eventIndex == 0 ? "翻倒的邮政车" :
            (eventIndex == 1 ? "撤离车队中的面包车" : "停摆的无轨电车");
        combat.policeCar.location = civil_war::Location::Roadblock;
        combat.policeCar.condition = 70 + eventIndex * 8;
        combat.woodenCover.name =
            eventIndex == 0 ? "花园环路临时街垒" :
            (eventIndex == 1 ? "斯摩棱斯克广场花坛" : "新阿尔巴特报亭与铺路石");
        combat.woodenCover.location = civil_war::Location::Roadblock;
        combat.woodenCover.condition = 88 - eventIndex * 6;
        combat.woodenCover.burningRounds = 0;
        combat.bystanders = 5 + eventIndex;
        combat.bystanderInjuries = 0;
        combat.bystanderRisk = 55 + eventIndex * 5;
        combat.tension = std::max(60, tension_);
        combat.round = 1;
        combat.completedRounds = 0;
        combat.ending = civil_war::Ending::None;
        combat.endingRound = 0;
        combat.withdrawalOrdered = false;
        combat.enemies.clear();

        const bool supportersFriendly =
            alignment_ == Alignment::AntiCommittee;
        auto addFaction = [&combat, supportersFriendly](
                              const std::string& baseId,
                              const std::string& name,
                              civil_war::FactionId faction,
                              civil_war::UnitProfile profile,
                              bool armoured,
                              bool friendly) {
            combat.enemies.push_back(
                {baseId,
                 name,
                 profile,
                 faction,
                 friendly ? civil_war::Disposition::Friendly
                          : civil_war::Disposition::Hostile,
                 armoured ? "AK-74、班用机枪" : "猎枪、燃烧瓶或手枪",
                 armoured ? 100 : 92,
                 friendly ? 82 : 58,
                 78,
                 0,
                 armoured ? 0 : 1,
                 civil_war::Location::Roadblock,
                 armoured,
                 false,
                 civil_war::EnemyStatus::Active,
                 false,
                 baseId == "SUP-1" ? "wooden_barricade" : ""});
        };
        addFaction("SUP-1", supporterName + "甲",
                   civil_war::FactionId::YeltsinSupporters,
                   civil_war::UnitProfile::YeltsinSupporter, false,
                   supportersFriendly);
        addFaction("SUP-2", supporterName + "乙",
                   civil_war::FactionId::YeltsinSupporters,
                   civil_war::UnitProfile::YeltsinSupporter, false,
                   supportersFriendly);
        addFaction("COM-1", committeeName + "甲",
                   civil_war::FactionId::CommitteeArmy,
                   civil_war::UnitProfile::CommitteeSoldier, true,
                   !supportersFriendly);
        addFaction("COM-2", committeeName + "乙",
                   civil_war::FactionId::CommitteeArmy,
                   civil_war::UnitProfile::CommitteeSoldier, true,
                   !supportersFriendly);
        return combat;
    }

    void afternoonEncounter() {
        struct Event {
            const char* title;
            const char* scene;
            const char* supporter;
            const char* committee;
        };
        static constexpr std::array<Event, 3> events = {{
            {"花园环路临时路障",
             "支持者用卡车和铺路石封住花园环路,委员会军队沿着电车轨道展开。双方都要求你的车组让路。",
             "街垒志愿者", "委员会侦察排"},
            {"斯摩棱斯克撤离车队",
             "一支挂白旗的撤离车队被困在斯摩棱斯克一带;支持者护送平民,委员会士兵怀疑车里藏着武器。",
             "撤离护送员", "委员会装甲步兵"},
            {"新阿尔巴特通行点争夺",
             "两派在新阿尔巴特街争夺一个能俯瞰路口的报亭。广播车的高音喇叭压不住零散枪声。",
             "街区守卫", "委员会巡逻兵"}
        }};
        const int eventIndex = std::uniform_int_distribution<int>(
            0, static_cast<int>(events.size()) - 1)(eventRng_);
        const Event& event = events[static_cast<std::size_t>(eventIndex)];
        afternoonEventName_ = event.title;
        output_ << "\n【随机下午遭遇 · " << event.title << "】\n"
                << event.scene << "\n"
                << "这是叶利钦遇刺后才触发的随机事件;上午固定剧情没有抽取事件库。\n"
                << "亲叶利钦支持者 SUP-1/SUP-2 与紧急状态委员会军队 "
                << "COM-1/COM-2 会作为四名独立 NPC 在同一轮次中互相交战。\n"
                << "白宫分支:";
        if (alignment_ == Alignment::AntiCommittee) {
            output_ << "支持者与车组协同,委员会军队敌对。\n";
        } else {
            output_ << "委员会军队与车组协同,亲叶利钦支持者敌对。\n";
        }
        printAfternoonStatus();
        output_ << "\n1. 通过无线电要求敌对方停火并让出通道\n"
                << "2. 立即介入,使用共享逐人战斗规则\n"
                << "3. 倒车撤离/绕行,不加入冲突\n";
        int choice = askChoice("> ", 1, 3);
        if (choice == 1) {
            const int chance = 35 + (state_.discipline > 25 ? 15 : 0) +
                               (eventIndex == 0 ? 8 : 0);
            const int roll = std::uniform_int_distribution<int>(0, 99)(eventRng_);
            output_ << "无线电停火判定: " << chance << "%\n";
            if (roll < chance) {
                afternoonOutcome_ =
                    "C1 以“平民正在穿越火线”为条件促成分批停火,两派脱离接触。";
                output_ << afternoonOutcome_ << "\n";
                return;
            }
            output_ << "敌对方拒绝停火,但尚未把车组当作唯一目标。\n"
                    << "1. 升级交火,支援友方 NPC\n"
                    << "2. 保持克制,倒车撤离/绕行\n";
            choice = askChoice("> ", 1, 2);
            if (choice == 2) {
                afternoonOutcome_ =
                    "谈判失败后,车组倒车脱离路口,没有参加下午的阵营交火。";
                output_ << afternoonOutcome_ << "\n";
                return;
            }
        } else if (choice == 3) {
            afternoonOutcome_ =
                "车组从支路绕行,两派 NPC 的冲突由广播中的断续枪声记录。";
            output_ << afternoonOutcome_ << "\n";
            return;
        }

        civil_war::GameState combat =
            buildAfternoonState(event.supporter, event.committee, eventIndex);
        if (choice == 1) {
            for (civil_war::EnemyPerson& unit : combat.enemies) {
                if (unit.disposition == civil_war::Disposition::Hostile) {
                    unit.morale = std::max(15, unit.morale - 10);
                }
            }
        }
        civil_war::EncounterConfig config;
        config.seed = seed_;
        config.state = combat;
        config.roundLimit = 8;
        config.standardBriefing = false;
        config.standardEnding = false;
        config.allowCoverTargets = false;
        config.encounterTitle = event.title;
        config.objective =
            "由两派 NPC 自主互射;车组只攻击或谈判敌对派,"
            "可将其逐出、突破路口或撤离。";
        config.sectorLabel = "车组所在侧街";
        config.contactLabel = "冲突路口";
        config.exitLabel = "冲突区之后";
        config.negotiatedPassageFactions.clear();
        const civil_war::CombatResult result =
            civil_war::runEncounter(config, input_, output_);
        state_ = result.state;
        syncPrototypeFromState();
        afternoonOutcome_ =
            std::string("下午交火返回:") +
            civil_war::endingName(result.state.ending) +
            ",共享部队、车辆与弹药状态已回到章节。";
    }

    void chapterEpilogue() {
        output_ << "\n============================================================\n"
                << "【8 月 19 日章节结算】\n"
                << "============================================================\n"
                << "随机下午事件: " << afternoonEventName_ << '\n'
                << "结果: " << afternoonOutcome_ << '\n'
                << "政治归属: " << alignmentLabel()
                << " | 检查点: " << passageResult_ << '\n'
                << "车组: ";
        int able = 0;
        for (const civil_war::FriendlyPerson& person : state_.friendly) {
            if (person.health > 0) {
                ++able;
            }
        }
        output_ << able << '/' << state_.friendly.size() << " 人仍能行动"
                << " | BMP-2 车况 " << state_.vehicle.condition << "/100"
                << " | 30mm " << state_.ammo.cannon30mm
                << " | PKT " << state_.ammo.coaxialPkt << '\n'
                << "袭击者仍未找到,命令链仍然分裂。8 月 19 日到这里结束,"
                << "幸存车组必须自行决定下一站。\n"
                << "随机种子: " << seed_ << '\n';
    }
};

} // namespace

int main(int argc, char* argv[]) {
#ifdef _WIN32
    SetConsoleOutputCP(CP_UTF8);
    SetConsoleCP(CP_UTF8);
#endif
    Options options;
    if (!parseOptions(argc, argv, options)) {
        std::cerr << "用法: august19_demo.exe [--seed <整数>] [--help]\n";
        return 2;
    }
    if (options.help) {
        std::cout << "《路障前的命令:八月十九日》\n"
                  << "  --seed <整数>  设置谈判、下午事件和战斗的随机种子(默认 19910819)\n"
                  << "  --help         显示本说明\n"
                  << "遇刺前剧情固定;下午使用独立随机流抽取一处双派冲突。\n";
        return 0;
    }
    Chapter chapter(options.seed, std::cin, std::cout);
    return chapter.run();
}

← 返回文件树 · 在 GitHub 上查看