diff --git a/docs/CLI_CONCEPT/06-verein.md b/docs/CLI_CONCEPT/06-verein.md index 0ae0f48..f4a5a70 100644 --- a/docs/CLI_CONCEPT/06-verein.md +++ b/docs/CLI_CONCEPT/06-verein.md @@ -146,7 +146,9 @@ This index includes registered and reserved names. `ListOptions` and `Help` from | `BuyPlayer` | player:Player | VER-KAUFEN on a market player: the offer editor | | `HirePlayer` | player:Player, months:int(12\|24) | VER-LEIHEN on a market player: the loan offer | | `OpenOffers` | player:Player | Open Offers. See current Help for behaviour and bounds. | -| `OpenSearch` | – | Open Search. See current Help for behaviour and bounds. | +| `ShowSearchProfile` | – | SUCHEN: your search profile as 18 values (positions, age, strength, attributes, sides, price classes) | +| `SuggestSearchProfile` | [whole:bool], [apply:bool] | VORSCHLAG: the profile your squad asks for; `apply` stores it and lists the matching players | +| `SetSearchProfile` | values:[18 numbers], [apply:bool] | SUCHEN: store the profile; all values 0 or all 1 count as no search; `apply` lists the players on the transfer list that fit (the original's "Spieler ... ist interessant!" boxes) | | `OpenPoach` | – | ABWERBEN: pick a player of another club (Transfer.Poach) | | `ShowTransferNews` | [count:int] | Show Transfer News. See current Help for behaviour and bounds. | | `ShowTeamInfo` | – | Show Team Info. See current Help for behaviour and bounds. | diff --git a/docs/CLI_CONCEPT/commands.csv b/docs/CLI_CONCEPT/commands.csv index b7f4797..8d79f29 100644 --- a/docs/CLI_CONCEPT/commands.csv +++ b/docs/CLI_CONCEPT/commands.csv @@ -209,7 +209,9 @@ "Transfer";"BuyPlayer";"player:Player";"VER-KAUFEN on a market player: the offer editor";"E_RULE";"";"";"partial";"06-verein.md" "Transfer";"HirePlayer";"player:Player, months:int(12|24)";"VER-LEIHEN on a market player: the loan offer";"E_RULE";"";"";"ready";"06-verein.md" "Transfer";"OpenOffers";"player:Player";"Open Offers. See current Help for behaviour and bounds.";"—";"";"";"partial";"06-verein.md" -"Transfer";"OpenSearch";"–";"Open Search. See current Help for behaviour and bounds.";"—";"";"";"partial";"06-verein.md" +"Transfer";"ShowSearchProfile";"–";"SUCHEN: your search profile as 18 values";"";"";"";"partial";"06-verein.md" +"Transfer";"SuggestSearchProfile";"[whole:bool], [apply:bool]";"VORSCHLAG: the profile your squad asks for; apply stores it and lists the matches";"E_RULE";"";"";"partial";"06-verein.md" +"Transfer";"SetSearchProfile";"values:[18 numbers], [apply:bool]";"SUCHEN: store the search profile; apply lists the matching players";"E_BAD_ARGUMENT";"";"";"partial";"06-verein.md" "Transfer";"OpenPoach";"–";"ABWERBEN: pick a player of another club (Transfer.Poach)";"—";"";"";"ready";"06-verein.md" "Transfer";"ShowTransferNews";"[count:int]";"Show Transfer News. See current Help for behaviour and bounds.";"—";"";"";"partial";"06-verein.md" "Transfer";"ShowTeamInfo";"–";"Show Team Info. See current Help for behaviour and bounds.";"—";"";"";"partial";"06-verein.md" diff --git a/src/app/career_session.cpp b/src/app/career_session.cpp index 408f0b7..9716204 100644 --- a/src/app/career_session.cpp +++ b/src/app/career_session.cpp @@ -6026,6 +6026,38 @@ bool CareerSession::apply_desk_setting(int manager, bool price, int index, int v return true; } +// The stored search profile of a manager slot (all zero for an invalid slot). +SearchProfile CareerSession::search_profile(int manager) const { return bmh::search_profile(g_, manager); } + +// The profile "Vorschlag" proposes for the manager's squad; nothing is stored. +SearchProfile CareerSession::suggest_search_profile(int manager, bool whole_squad) const { + return bmh::suggest_search_profile(g_, manager, whole_squad); +} + +// Stores an edited search profile like the closing dialog does and, with `apply`, returns the transfer-list entries +// that fit it. Only the active manager of a club with a transfer market may do this, and not while another window +// owns the session. The revision rises only when the stored bytes changed. +std::optional CareerSession::dispatch_search_profile(int manager, + const SearchProfile& profile, bool cancelled, bool apply, uint64_t& revision, std::string& error) { + if (balance_draft_ || balance_dispatch_active_ || strengths_owner_ || strengths_dispatch_active_ || + top_scorers_owner_ || top_scorers_dispatch_active_ || stadium_.block_expansion || other_games_owner_ || + other_games_dispatch_active_ || transfer_offer_editor_ || market_dispatch_active_ || + pending_offer_dispatch_active_ || calendar_advance_active_) { error = "search_profile_blocked"; return std::nullopt; } + if (manager < 0 || size_t(manager) >= g_.manager_teams.size() || g_.manager_teams[size_t(manager)] == kNoTeam || + !g_.memory.has(::bmh::layout::ActiveManager) || g_.memory.u8(::bmh::layout::ActiveManager) != manager || + revision == std::numeric_limits::max()) { error = "invalid_search_profile_owner"; return std::nullopt; } + if (!search_profile_valid(profile)) { error = "invalid_search_profile"; return std::nullopt; } + const auto before = bmh::search_profile(g_, manager); + SearchProfileDispatch result; + result.active = set_search_profile(g_, manager, profile, cancelled); + const auto stored = bmh::search_profile(g_, manager); + result.profile = stored; + if (stored != before) ++revision; + if (apply) result.hits = search_profile_hits(g_, manager); + error.clear(); + return result; +} + // Validates the owner and the price range (8-25) and applies the ticket price; revision plus one. bool CareerSession::dispatch_ticket_price(const TicketPriceRequest& request, uint64_t& revision, std::string& error) { diff --git a/src/app/career_session.hpp b/src/app/career_session.hpp index 808c752..51d6b13 100644 --- a/src/app/career_session.hpp +++ b/src/app/career_session.hpp @@ -38,6 +38,7 @@ #include "game/pending_offer.hpp" #include "game/poach.hpp" #include "game/human_buyer_sale.hpp" +#include "game/search_profile.hpp" #include "game/weekly.hpp" #include "ui/flow.hpp" #include "ui/desk_state.hpp" @@ -178,6 +179,21 @@ public: uint64_t& revision, std::string& error, const std::function& review = {}); + // The search profile of a human manager (transfer market buttons "Suchen" and "Vorschlag", game/search_profile.hpp). + // `search_profile` is the stored profile, `suggest_search_profile` the one the squad asks for (nothing is stored). + // `dispatch_search_profile` stores an edited profile the way the closing dialog does (`cancelled` = left by right + // click, which switches the profile off) and, with `apply`, lists the transfer-list entries that fit it right now. + // The revision rises only when the stored profile changed. + SearchProfile search_profile(int manager) const; + SearchProfile suggest_search_profile(int manager, bool whole_squad) const; + struct SearchProfileDispatch { + SearchProfile profile{}; + bool active = false; + std::vector hits; + }; + std::optional dispatch_search_profile(int manager, const SearchProfile& profile, bool cancelled, + bool apply, uint64_t& revision, std::string& error); + struct TransferMarketPreviewDispatch { ui::PreparationState preparation; ui::TransferMarketPreview quote; diff --git a/src/cli/console/windows_transfer.cpp b/src/cli/console/windows_transfer.cpp index 07d8abf..751dce9 100644 --- a/src/cli/console/windows_transfer.cpp +++ b/src/cli/console/windows_transfer.cpp @@ -516,8 +516,74 @@ void Console::register_transfer_commands() { show_offer(); }); + // --- the search profile (buttons Suchen / Vorschlag of the market, game/search_profile.hpp) --------------- + // The 18 values of the profile in the order of the original dialog; the console shows and takes them as a list. + static const char* const kProfileLabels[18] = { + "Goalkeeper", "Defender", "Midfielder", "Forward", "AgeMin(16+)", "AgeMax(16+)", "StrengthMin", "StrengthMax", + "AttrCondition", "AttrTechnique", "AttrForm", "Side1", "Side2", "Side3", "Side4", "PriceLow", "PriceMid", "PriceHigh"}; + auto show_profile = [this](const SearchProfile& p, const char* heading) { + std::vector> rows; + for (size_t i = 0; i < p.size(); ++i) + rows.push_back({kProfileLabels[i], std::to_string(i == 0 ? p[i] & ~kSearchProfileOff : p[i])}); + emit_table({heading, "Value"}, rows); + std::string list; + for (size_t i = 0; i < p.size(); ++i) list += (i ? "," : "") + std::to_string(i == 0 ? p[i] & ~kSearchProfileOff : p[i]); + emit('i', std::string("profile ") + (p[0] & kSearchProfileOff ? "OFF" : "active") + "; as SetSearchProfile([" + list + "])"); + }; + auto manager_slot = [market] { return market().manager_slot; }; + add({"Transfer", "ShowSearchProfile", {}, "SUCHEN: your search profile (18 values; positions, age, strength, attributes, sides, price classes)", false}, + [this, manager_slot, show_profile](const Values&) { show_profile(session_->search_profile(manager_slot()), "Search profile"); }); + add({"Transfer", "SuggestSearchProfile", {boolean("whole", true), boolean("apply", true)}, + "VORSCHLAG: the profile your squad asks for (whole = count the substitutes); apply = store it and list the matches", false}, + [this, manager_slot, show_profile, flush_notices](const Values& v) { + const int manager = manager_slot(); + const auto suggestion = session_->suggest_search_profile(manager, v.boolean("whole", false)); + show_profile(suggestion, "Suggestion"); + if (v.boolean("apply", false)) { + std::string error; + const auto result = session_->dispatch_search_profile(manager, suggestion, false, true, revision_, error); + if (!result) require_engine(false, "search profile", error); + emit('+', std::to_string(result->hits.size()) + " listed player(s) fit the profile"); + for (const auto& hit : result->hits) emit('i', utf8(hit.message)); + } + }); + Param profile_values = detail::text("values"); + profile_values.display = "values:[18 numbers] (see ShowSearchProfile)"; + add({"Transfer", "SetSearchProfile", {profile_values, boolean("apply", true)}, + "SUCHEN: store the search profile (the 18 values of ShowSearchProfile, switches 0/1, age 0..24 = 16..40, strength 0..99); apply = list the matches now", false}, + [this, manager_slot, show_profile](const Values& v) { + std::string list = v.text("values"); + if (list.size() >= 2 && list.front() == '[' && list.back() == ']') list = list.substr(1, list.size() - 2); + SearchProfile profile{}; + size_t count = 0, start = 0; + while (start <= list.size()) { + const size_t comma = list.find(',', start); + std::string item = list.substr(start, comma == std::string::npos ? std::string::npos : comma - start); + item.erase(0, item.find_first_not_of(' ')); + item.erase(item.find_last_not_of(' ') + 1); + if (item.empty() || item.find_first_not_of("0123456789") != std::string::npos || item.size() > 3) + fail("E_BAD_ARGUMENT", "the profile values are numbers separated by commas"); + if (count >= profile.size()) fail("E_BAD_ARGUMENT", "the profile has 18 values"); + profile[count++] = uint8_t(std::min(255, std::stoi(item))); + if (comma == std::string::npos) break; + start = comma + 1; + } + if (count != profile.size()) fail("E_BAD_ARGUMENT", "the profile has 18 values, not " + std::to_string(count)); + if (!search_profile_valid(profile)) + fail("E_BAD_ARGUMENT", "switches are 0 or 1, the age values 0..24 and the strength values 0..99"); + std::string error; + const auto result = session_->dispatch_search_profile(manager_slot(), profile, false, v.boolean("apply", true), revision_, error); + if (!result) require_engine(false, "search profile", error); + emit('+', result->active ? "search profile stored" + : "search profile stored but switched off (all values 0 or all 1 count as no search)"); + if (v.boolean("apply", true)) { + emit('+', std::to_string(result->hits.size()) + " listed player(s) fit the profile"); + for (const auto& hit : result->hits) emit('i', utf8(hit.message)); + } + }); + // the rest of the market (06-verein 5): later steps of stage 3 or engine gaps - for (const char* name : {"SetSquadView", "SetSquadSheet", "SetMarketVisible", "ShowPlayer", "OpenOffers", "OpenSearch", + for (const char* name : {"SetSquadView", "SetSquadSheet", "SetMarketVisible", "ShowPlayer", "OpenOffers", "ShowTransferNews", "ShowTeamInfo"}) add({"Transfer", name, {}, "not in the console yet", false}, [name](const Values&) { fail("E_ENGINE_GAP", std::string(name) + " is not in the console yet"); }); diff --git a/src/game/search_profile.cpp b/src/game/search_profile.cpp index f1cc494..f1caaf3 100644 --- a/src/game/search_profile.cpp +++ b/src/game/search_profile.cpp @@ -45,9 +45,7 @@ SearchProfile search_profile(const GameState& g, int manager) { return profile; } -bool set_search_profile(GameState& g, int manager, SearchProfile profile, bool cancelled) { - if (manager < 0 || size_t(manager) >= g.manager_teams.size() || - (size_t(manager) + 1) * kRecord > g.manager_records.size()) return false; +bool search_profile_valid(SearchProfile profile) { profile[0] &= 0x3F; // the dialog starts from the stored profile without the "off" bit for (size_t i = 0; i < profile.size(); ++i) { const bool range = i >= 4 && i <= 7; @@ -55,6 +53,13 @@ bool set_search_profile(GameState& g, int manager, SearchProfile profile, bool c if (i >= 4 && i <= 5 && profile[i] > 24) return false; // age bar: 25 cells if (i >= 6 && i <= 7 && profile[i] > 99) return false; // strength bar: 100 cells } + return true; +} + +bool set_search_profile(GameState& g, int manager, SearchProfile profile, bool cancelled) { + if (manager < 0 || size_t(manager) >= g.manager_teams.size() || + (size_t(manager) + 1) * kRecord > g.manager_records.size() || !search_profile_valid(profile)) return false; + profile[0] &= 0x3F; int sum = 0; for (uint8_t value : profile) sum += value; if (sum == 0 || sum == 18 || cancelled) profile[0] |= kSearchProfileOff; diff --git a/src/game/search_profile.hpp b/src/game/search_profile.hpp index 6ff1205..3308d81 100644 --- a/src/game/search_profile.hpp +++ b/src/game/search_profile.hpp @@ -24,10 +24,15 @@ constexpr uint8_t kSearchProfileOff = 0x40; // The stored profile of a manager slot (all zero for an invalid slot). SearchProfile search_profile(const GameState& g, int manager); +// Whether the values can come out of the dialog: bytes 0..3 and 8..17 are switches (0 or 1, the "off" bit is +// ignored in byte 0), the age bar has 25 cells (bytes 4 and 5 are 0..24) and the strength bar 100 (bytes 6 and 7 are 0..99). +bool search_profile_valid(SearchProfile profile); + // Stores the profile the way the original dialog does when it is closed: a profile with every value 0 or // every value 1 is switched off (bit 0x40), and so is any profile that was left by right click // (`cancelled`). Returns whether the stored profile is active. Fails (false, nothing stored) for an -// invalid manager slot or a value above 1 where the original has only switches. +// invalid manager slot or invalid values (see search_profile_valid) - check these first to tell +// "refused" from "switched off". bool set_search_profile(GameState& g, int manager, SearchProfile profile, bool cancelled); // Average strengths per position class of the manager's own squad (original sub_19A38): index 0..3 diff --git a/tests/cli_console_tests.cpp b/tests/cli_console_tests.cpp index 15ca37e..8e696a9 100644 --- a/tests/cli_console_tests.cpp +++ b/tests/cli_console_tests.cpp @@ -1420,6 +1420,16 @@ void coverage_tests(const std::filesystem::path& data, const std::filesystem::pa block({"SellPlayer(row:19)", "BuyPlayer(" + id + ")", "ShowNegotiation", "SetOfferField(Fee, 100000)", "SetOfferField(Salary, 20000)", "ShowTeamInfo", "ShowPlayerInfo", "SubmitOffer", "GoBack", "GoBack"}); } + { + // the search profile (buttons SUCHEN and VORSCHLAG): the suggestion, storing a profile, a refused value + check(contains(block({"Key(M)", "SuggestSearchProfile"}), "profile active"), "coverage: the suggestion is a profile"); + block({"SetSearchProfile([1,1,0,0,0,24,0,99,0,0,0,0,0,0,0,0,0,0], false)", "ShowSearchProfile"}); + check(contains(block({"SetSearchProfile([1,1,1,1,0,24,0,99,0,0,0,0,0,0,0,0,0,0])"}), "search profile stored"), + "coverage: a profile is stored"); + check(contains(block({"SetSearchProfile([2,1,1,1,0,24,0,99,0,0,0,0,0,0,0,0,0,0])"}, true), "E_BAD_ARGUMENT"), + "coverage: a switch above 1 is refused"); + block({"GoBack"}); + } block({"Key(T)", "ShowTable(0)", "OpenTeamInfo(club:0)", "ShowTeamSquad", "ShowPlayer(row:0)", "CloseTeamInfo", "ShowTable(1)", "GoBack", "Open(HighScore)", "ShowHighScore", "GoBack", "Open(TopScorers)", "ShowScorers(Assists, League)", "SetList(Score)", "SetScope(Managers)", "GoBack", "Open(Fixtures)", "NextMatchday", "GoBack", "OpenMailbox", "ListMessages", "GoBack"}); block({"Open(SaveGame)", "Save(COVER)", "GoBack"});