Best I can do to simplify the check(fmt::format)crap is to make a little macro to do the format part.
This commit is contained in:
parent
6710469ee1
commit
f0b04107ab
28 changed files with 108 additions and 108 deletions
|
|
@ -11,7 +11,8 @@ namespace ai {
|
|||
inline void validate_profile(nlohmann::json& profile) {
|
||||
for(auto& [name_key, value] : profile.items()) {
|
||||
check(value < STATE_MAX,
|
||||
fmt::format("profile field {} has value {} greater than STATE_MAX {}", (std::string)name_key, (int)value, STATE_MAX));
|
||||
$F("profile field {} has value {} greater than STATE_MAX {}",
|
||||
(std::string)name_key, (int)value, STATE_MAX));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -22,17 +23,17 @@ namespace ai {
|
|||
Action result(config["name"], config["cost"]);
|
||||
|
||||
check(config.contains("needs"),
|
||||
fmt::format("config_action: no 'needs' field", result.name));
|
||||
$F("config_action: no 'needs' field", result.name));
|
||||
check(config.contains("effects"),
|
||||
fmt::format("config_action: no 'effects' field", result.name));
|
||||
$F("config_action: no 'effects' field", result.name));
|
||||
|
||||
for(auto& [name_key, value] : config["needs"].items()) {
|
||||
check(profile.contains(name_key), fmt::format("config_action({}): profile does not have need named {}", result.name, name_key));
|
||||
check(profile.contains(name_key), $F("config_action({}): profile does not have need named {}", result.name, name_key));
|
||||
result.needs(profile.at(name_key), bool(value));
|
||||
}
|
||||
|
||||
for(auto& [name_key, value] : config["effects"].items()) {
|
||||
check(profile.contains(name_key), fmt::format("config_action({}): profile does not have effect named {}", result.name, name_key));
|
||||
check(profile.contains(name_key), $F("config_action({}): profile does not have effect named {}", result.name, name_key));
|
||||
|
||||
result.effect(profile.at(name_key), bool(value));
|
||||
}
|
||||
|
|
@ -44,7 +45,7 @@ namespace ai {
|
|||
State result;
|
||||
|
||||
for(auto& [name_key, value] : config.items()) {
|
||||
check(profile.contains(name_key), fmt::format("config_state: profile does not have name {}", name_key));
|
||||
check(profile.contains(name_key), $F("config_state: profile does not have name {}", name_key));
|
||||
|
||||
int name_id = profile.at(name_key);
|
||||
result[name_id] = bool(value);
|
||||
|
|
@ -95,7 +96,7 @@ namespace ai {
|
|||
|
||||
for(auto name : action_names) {
|
||||
check(AIMGR.actions.contains(name),
|
||||
fmt::format("ai::init(): script {} uses action {} that doesn't exist",
|
||||
$F("ai::init(): script {} uses action {} that doesn't exist",
|
||||
(std::string)script_name, (std::string)name));
|
||||
|
||||
the_script.push_back(AIMGR.actions.at(name));
|
||||
|
|
@ -111,14 +112,14 @@ namespace ai {
|
|||
|
||||
void check_valid_action(std::string name, std::string msg) {
|
||||
dbc::check(AIMGR.actions.contains(name),
|
||||
fmt::format("{} tried to access action that doesn't exist {}",
|
||||
$F("{} tried to access action that doesn't exist {}",
|
||||
msg, name));
|
||||
}
|
||||
|
||||
State load_state(std::string state_name) {
|
||||
check(initialized, "you forgot to initialize the AI first.");
|
||||
check(AIMGR.states.contains(state_name), fmt::format(
|
||||
"ai::load_state({}): state does not exist in config",
|
||||
check(AIMGR.states.contains(state_name),
|
||||
$F("ai::load_state({}): state does not exist in config",
|
||||
state_name));
|
||||
|
||||
return AIMGR.states.at(state_name);
|
||||
|
|
@ -126,15 +127,15 @@ namespace ai {
|
|||
|
||||
Action load_action(std::string action_name) {
|
||||
check(initialized, "you forgot to initialize the AI first.");
|
||||
check(AIMGR.actions.contains(action_name), fmt::format(
|
||||
"ai::load_action({}): action does not exist in config",
|
||||
check(AIMGR.actions.contains(action_name),
|
||||
$F("ai::load_action({}): action does not exist in config",
|
||||
action_name));
|
||||
return AIMGR.actions.at(action_name);
|
||||
}
|
||||
|
||||
std::vector<Action> load_script(std::string script_name) {
|
||||
check(AIMGR.scripts.contains(script_name), fmt::format(
|
||||
"ai::load_script(): no script named {} configured", script_name));
|
||||
check(AIMGR.scripts.contains(script_name),
|
||||
$F("ai::load_script(): no script named {} configured", script_name));
|
||||
return AIMGR.scripts.at(script_name);
|
||||
}
|
||||
|
||||
|
|
@ -148,9 +149,8 @@ namespace ai {
|
|||
}
|
||||
|
||||
int state_id(std::string name) {
|
||||
check(AIMGR.profile.contains(name), fmt::format(
|
||||
"ai::state_id({}): id is not configured in profile",
|
||||
name));
|
||||
check(AIMGR.profile.contains(name),
|
||||
$F("ai::state_id({}): id is not configured in profile", name));
|
||||
return AIMGR.profile.at(name);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue