Search profile: session API and console commands (ShowSearchProfile, SuggestSearchProfile, SetSearchProfile)
CareerSession gets search_profile, suggest_search_profile and dispatch_search_profile (owner and modal-state checks, revision only when the stored profile changed). The console replaces the OpenSearch placeholder with three commands and documents them; with apply the matching listings are reported with the original's "Spieler ... ist interessant!" message. search_profile_valid separates a refused profile from a switched-off one. Part of #79 (the dialog in the graphical client is still open) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff4ad035a7
commit
b2484350d9
8 files changed
+145
-7
No files matched your search
@@ -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. |
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
@@ -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::SearchProfileDispatch> 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<uint64_t>::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) {
|
||||
|
||||
@@ -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<int(const GameState&, const TransferOfferListView&)>& 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<SearchProfileHit> hits;
|
||||
};
|
||||
std::optional<SearchProfileDispatch> 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;
|
||||
|
||||
@@ -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<std::vector<std::string>> 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"); });
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"});
|
||||
|
||||
Reference in new issue
Block a user