19 #include "formula/callable_objects.hpp"
26 #include <boost/algorithm/string.hpp>
27 #include <boost/math/constants/constants.hpp>
33 using namespace boost::math::constants;
36 #define DBG_NG LOG_STREAM(debug, log_engine)
38 #define LOG_SF LOG_STREAM(info, log_scripting_formula)
39 #define WRN_SF LOG_STREAM(warn, log_scripting_formula)
40 #define ERR_SF LOG_STREAM(err, log_scripting_formula)
52 call_stack_manager::call_stack_manager(
const std::string& str)
57 call_stack_manager::~call_stack_manager()
64 std::ostringstream res;
67 res <<
" " << frame <<
"\n";
74 std::string function_expression::str()
const
79 bool first_arg =
true;
96 std::shared_ptr<formula_debugger> fdbp;
97 bool need_wrapper =
false;
105 if(args().
size() == 1) {
107 return args()[0]->evaluate(variables, fdb);
118 variant var = args()[0]->evaluate(variables, fdb);
123 std::vector<variant> res;
124 for(std::size_t
i = 0;
i < inputs.size(); ++
i) {
126 res.emplace_back(input.
name);
134 for(std::size_t
n = 0;
n < args().size() - 1;
n += 2) {
135 if(args()[
n]->evaluate(variables, fdb).as_bool()) {
136 return args()[
n + 1]->evaluate(variables, fdb);
140 if((args().
size() % 2) != 0) {
141 return args().back()->evaluate(variables, fdb);
149 variant var = args()[0]->evaluate(variables, fdb);
151 for(std::size_t
n = 1;
n < args().size() - 1;
n += 2) {
152 variant val = args()[
n]->evaluate(variables, fdb);
155 return args()[
n + 1]->evaluate(variables, fdb);
159 if((args().
size() % 2) == 0) {
160 return args().back()->evaluate(variables, fdb);
168 const variant input = args()[0]->evaluate(variables, fdb);
171 return variant(
n >= 0 ?
n : -
n, variant::DECIMAL_VARIANT);
180 variant res = args()[0]->evaluate(variables, fdb);
186 res = *std::min_element(res.
begin(), res.
end());
189 for(std::size_t
n = 1;
n < args().size(); ++
n) {
190 variant v = args()[
n]->evaluate(variables, fdb);
197 v = *std::min_element(v.
begin(), v.
end());
210 variant res = args()[0]->evaluate(variables, fdb);
216 res = *std::max_element(res.
begin(), res.
end());
219 for(std::size_t
n = 1;
n < args().size(); ++
n) {
220 variant v = args()[
n]->evaluate(variables, fdb);
227 v = *std::max_element(v.
begin(), v.
end());
240 void display_float(
const map_location& location,
const std::string& text)
248 const args_list& arguments = args();
249 const variant var0 = arguments[0]->evaluate(variables, fdb);
250 const variant var1 = arguments[1]->evaluate(variables, fdb);
255 if(arguments.size() == 2) {
257 display_float(location, text);
260 const variant var2 = arguments[2]->evaluate(variables, fdb);
262 display_float(location, text);
269 const variant var1 = args()[0]->evaluate(variables, fdb);
271 std::string str1, str2;
273 if(args().
size() == 1) {
287 const variant var2 = args()[1]->evaluate(variables, fdb);
290 LOG_SF << str1 <<
": " << str2;
303 std::string speaker =
"WFL";
306 if(args().
size() == 2) {
307 speaker = args()[0]->evaluate(variables, fdb).string_cast();
311 const variant value = args()[i_value]->evaluate(variables, fdb);
312 std::chrono::steady_clock::duration run_time;
314 for(
int i = 1;
i < 1000;
i++) {
315 const auto start = std::chrono::steady_clock::now();
316 args()[i_value]->evaluate(variables, fdb);
317 run_time += std::chrono::steady_clock::now() -
start;
320 std::ostringstream str;
321 #ifdef __cpp_lib_format
322 str <<
"Evaluated in " << std::chrono::duration_cast<std::chrono::milliseconds>(run_time) <<
" on average";
324 str <<
"Evaluated in " << std::chrono::duration_cast<std::chrono::milliseconds>(run_time).count() <<
" ms on average";
327 LOG_SF << speaker <<
": " << str.str();
339 const variant map = args()[0]->evaluate(variables, fdb);
345 const variant map = args()[0]->evaluate(variables, fdb);
351 const variant var = args()[0]->evaluate(variables, fdb);
353 std::vector<variant> tmp;
363 const variant var_1 = args()[0]->evaluate(variables, fdb);
365 std::map<variant, variant> tmp;
367 if(args().
size() == 2) {
368 const variant var_2 = args()[1]->evaluate(variables, fdb);
374 tmp[var_1[
i]] = var_2[
i];
379 tmp[kv->query_value(
"key")] = kv->query_value(
"value");
381 auto map_it = tmp.find(*it);
383 if(map_it == tmp.end()) {
386 map_it->second =
variant(map_it->second.as_int() + 1);
397 std::string result = args()[0]->evaluate(variables, fdb).as_string();
399 int offset = args()[1]->evaluate(variables, fdb).as_int();
401 offset += result.size();
407 if(
static_cast<std::size_t
>(offset) >= result.size()) {
412 if(args().
size() > 2) {
413 int size = args()[2]->evaluate(variables, fdb).as_int();
417 offset = std::max(0, offset -
size + 1);
423 return variant(result.substr(offset));
428 std::string result = args()[0]->evaluate(variables, fdb).as_string();
429 std::string replacement = args().back()->evaluate(variables, fdb).as_string();
431 int offset = args()[1]->evaluate(variables, fdb).as_int();
433 offset += result.size();
439 if(
static_cast<std::size_t
>(offset) >= result.size()) {
444 if(args().
size() > 3) {
445 int size = args()[2]->evaluate(variables, fdb).as_int();
449 offset = std::max(0, offset -
size + 1);
452 return variant(result.replace(offset,
size, replacement));
455 return variant(result.replace(offset, std::string::npos, replacement));
460 std::string result = args()[0]->evaluate(variables, fdb).as_string();
461 std::string needle = args()[1]->evaluate(variables, fdb).as_string();
462 std::string replacement = args().back()->evaluate(variables, fdb).as_string();
463 boost::replace_all(result, needle, replacement);
469 std::string str = args()[0]->evaluate(variables, fdb).as_string();
470 std::string prefix = args()[1]->evaluate(variables, fdb).as_string();
471 return variant(boost::starts_with(str, prefix));
476 std::string str = args()[0]->evaluate(variables, fdb).as_string();
477 std::string prefix = args()[1]->evaluate(variables, fdb).as_string();
478 return variant(boost::ends_with(str, prefix));
483 std::string result = args()[0]->evaluate(variables, fdb).as_string();
484 std::string
insert = args().back()->evaluate(variables, fdb).as_string();
486 int offset = args()[1]->evaluate(variables, fdb).as_int();
488 offset += result.size();
493 }
else if(
static_cast<std::size_t
>(offset) >= result.size()) {
502 return variant(args()[0]->evaluate(variables, fdb).as_string().length());
509 result += arg->evaluate(variables, fdb).string_cast();
517 std::string str = args()[0]->evaluate(variables, fdb).as_string();
518 std::transform(str.begin(), str.end(), str.begin(),
static_cast<int (*)(
int)
>(std::toupper));
524 std::string str = args()[0]->evaluate(variables, fdb).as_string();
525 std::transform(str.begin(), str.end(), str.begin(),
static_cast<int (*)(
int)
>(std::tolower));
531 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
532 const double result = std::sin(angle * pi<double>() / 180.0);
533 return variant(result, variant::DECIMAL_VARIANT);
538 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
539 const double result = std::cos(angle * pi<double>() / 180.0);
540 return variant(result, variant::DECIMAL_VARIANT);
545 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
546 const double result = std::tan(angle * pi<double>() / 180.0);
547 if(std::isnan(result) || result <= std::numeric_limits<int>::min() || result >= std::numeric_limits<int>::max()) {
551 return variant(result, variant::DECIMAL_VARIANT);
556 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
557 const double result = std::asin(num) * 180.0 / pi<double>();
558 if(std::isnan(result)) {
562 return variant(result, variant::DECIMAL_VARIANT);
567 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
568 const double result = std::acos(num) * 180.0 / pi<double>();
569 if(std::isnan(result)) {
573 return variant(result, variant::DECIMAL_VARIANT);
578 if(args().
size() == 1) {
579 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
580 const double result = std::atan(num) * 180.0 / pi<double>();
581 return variant(result, variant::DECIMAL_VARIANT);
583 const double y = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
584 const double x = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
585 const double result = std::atan2(y, x) * 180.0 / pi<double>();
586 return variant(result, variant::DECIMAL_VARIANT);
592 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
593 const double result = std::sqrt(num);
594 if(std::isnan(result)) {
598 return variant(result, variant::DECIMAL_VARIANT);
603 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
604 const double result = num < 0 ? -std::pow(-num, 1.0 / 3.0) : std::pow(num, 1.0 / 3.0);
605 return variant(result, variant::DECIMAL_VARIANT);
610 const double base = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
611 const double root = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
612 const double result = base < 0 && std::fmod(root, 2) == 1 ? -std::pow(-base, 1.0 / root) : std::pow(base, 1.0 / root);
613 if(std::isnan(result)) {
617 return variant(result, variant::DECIMAL_VARIANT);
622 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
623 if(args().
size() == 1) {
624 const double result = std::log(num);
625 if(std::isnan(result)) {
629 return variant(result, variant::DECIMAL_VARIANT);
632 const double base = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
633 const double result = std::log(num) / std::log(base);
634 if(std::isnan(result)) {
638 return variant(result, variant::DECIMAL_VARIANT);
643 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
644 const double result = std::exp(num);
645 if(result == 0 || result >= std::numeric_limits<int>::max()) {
651 return variant(result, variant::DECIMAL_VARIANT);
656 return variant(pi<double>(), variant::DECIMAL_VARIANT);
661 const double x = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
662 const double y = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
663 return variant(std::hypot(x, y), variant::DECIMAL_VARIANT);
668 const variant value = args()[0]->evaluate(variables, fdb);
669 const variant list = args()[1]->evaluate(variables, fdb);
672 if(list[
i] == value) {
682 const variant items = args()[0]->evaluate(variables, fdb);
686 if(args().
size() == 2) {
697 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
700 self_callable.
add(
self, *it);
702 const variant val = args().back()->evaluate(
721 const int value = args()[0]->evaluate(variables, fdb).as_int() % 1000;
722 const double angle = 2.0 * pi<double>() * (
static_cast<double>(value) / 1000.0);
723 return variant(
static_cast<int>(std::sin(angle) * 1000.0));
728 const double lo = args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"lerp:lo")).as_decimal() / 1000.0;
729 const double hi = args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"lerp:hi")).as_decimal() / 1000.0;;
730 const double alpha = args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"lerp:alpha")).as_decimal() / 1000.0;;
731 return variant(
static_cast<int>((lo + alpha * (hi - lo)) * 1000.0), variant::DECIMAL_VARIANT);
736 const std::vector<variant> items = args()[0]->evaluate(variables, fdb).as_list();
737 if(items.empty())
return variant();
738 const double alpha = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
740 const double val_scaled = std::clamp(0.01 * alpha, 0.0, 1.0);
741 const int idx = int(std::nearbyint((items.size() - 1) * val_scaled));
747 const std::string name = args()[0]->evaluate(variables, fdb).as_string();
748 std::vector<color_t> colors;
749 if(name ==
"red_green_scale") {
751 }
else if(name ==
"red_green_scale_text") {
753 }
else if(name ==
"blue_white_scale") {
755 }
else if(name ==
"blue_white_scale_text") {
760 std::vector<variant> result;
761 result.reserve(colors.size());
762 for(
auto clr : colors) {
763 result.emplace_back(std::make_shared<color_callable>(clr));
792 bool operator()(
const variant& a,
const variant&
b)
const
796 return expr_->evaluate(*this).as_bool();
800 variant get_value(
const std::string& key)
const
804 }
else if(key ==
"b") {
824 variant list = args()[0]->evaluate(variables, fdb);
826 std::vector<variant> vars;
830 vars.push_back(list[
n]);
833 if(args().
size() == 1) {
834 std::sort(vars.begin(), vars.end());
836 std::sort(vars.begin(), vars.end(), variant_comparator(args()[1], variables));
844 const variant& arg = args()[0]->evaluate(variables, fdb);
847 std::string str = args()[0]->evaluate(variables, fdb).
as_string();
848 std::reverse(str.begin(), str.end());
852 std::vector<variant> list = args()[0]->evaluate(variables, fdb).as_list();
853 std::reverse(list.begin(), list.end());
863 std::string str = args()[0]->evaluate(variables, fdb).as_string();
864 std::string key = args()[1]->evaluate(variables, fdb).as_string();
866 return variant(str.find(key) != std::string::npos);
871 const std::string str = args()[0]->evaluate(variables, fdb).as_string();
872 const std::string key = args()[1]->evaluate(variables, fdb).as_string();
874 std::size_t pos = str.find(key);
875 return variant(
static_cast<int>(pos));
880 std::vector<variant> list_vars;
881 std::map<variant, variant> map_vars;
883 const variant items = args()[0]->evaluate(variables, fdb);
885 if(args().
size() == 2) {
891 map_vars[(*it).get_member(
"key")] = (*it).
get_member(
"value");
893 list_vars.push_back(*it);
899 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
902 self_callable.
add(
self, *it);
904 const variant val = args()[2]->evaluate(
909 map_vars[(*it).get_member(
"key")] = (*it).
get_member(
"value");
911 list_vars.push_back(*it);
926 const variant items = args()[0]->evaluate(variables, fdb);
928 if(args().
size() == 2) {
937 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
940 self_callable.
add(
self, *it);
942 const variant val = args().back()->evaluate(
956 std::vector<variant> list_vars;
957 std::map<variant, variant> map_vars;
958 const variant items = args()[0]->evaluate(variables, fdb);
960 if(args().
size() == 2) {
964 map_vars[(*it).get_member(
"key")] = val;
966 list_vars.push_back(val);
971 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
974 self_callable.
add(
self, *it);
976 const variant val = args().back()->evaluate(
980 map_vars[(*it).get_member(
"key")] = val;
982 list_vars.push_back(val);
996 const variant& items = args()[0]->evaluate(variables, fdb);
999 for(; it != items.
end(); ++it) {
1007 std::vector<variant> result(items.
begin(), it);
1015 explicit indexer(std::size_t
i)
1020 variant operator()(
const variant& v)
const
1022 if(
i >= v.num_elements()) {
1035 bool operator()(
const variant& a,
const variant&
b)
const
1037 return a.num_elements() <
b.num_elements();
1041 std::vector<variant> get_input(
1042 const function_expression::args_list& args,
1043 const formula_callable& variables,
1044 formula_debugger* fdb)
1046 if(args.size() == 1) {
1047 const variant list = args[0]->evaluate(variables, fdb);
1048 return std::vector<variant>(list.begin(), list.end());
1050 std::vector<variant> input;
1051 input.reserve(args.size());
1054 input.push_back(
expr->evaluate(variables, fdb));
1064 const std::vector<variant> input = get_input(args(), variables, fdb);
1065 std::vector<variant>
output;
1069 std::size_t max_i = std::max_element(input.begin(), input.end(), comparator())->num_elements();
1072 for(std::size_t
i = 0;
i < max_i;
i++) {
1073 std::vector<variant> elem(input.size());
1074 std::transform(input.begin(), input.end(), elem.begin(), indexer(
i));
1075 output.emplace_back(elem);
1083 const variant items = args()[0]->evaluate(variables, fdb);
1084 const variant initial = args().size() == 2 ?
variant() : args()[1]->evaluate(variables, fdb);
1092 if(res != initial) {
1097 for(; it != items.
end(); ++it) {
1098 self_callable.
add(
"a", res);
1099 self_callable.
add(
"b", *it);
1100 res = args().back()->evaluate(
1110 const variant items = args()[0]->evaluate(variables, fdb);
1112 if(items[0].is_list()) {
1113 std::vector<variant> tmp;
1115 if(args().
size() >= 2) {
1116 res = args()[1]->evaluate(variables, fdb);
1120 }
else if(items[0].
is_map()) {
1121 std::map<variant, variant> tmp;
1123 if(args().
size() >= 2) {
1124 res = args()[1]->evaluate(variables, fdb);
1129 if(args().
size() >= 2) {
1130 res = args()[1]->evaluate(variables, fdb);
1136 res = res + items[
n];
1144 const variant items = args()[0]->evaluate(variables, fdb);
1146 if(it == items.
end()) {
1150 if(args().
size() == 1) {
1154 const int n = items.
num_elements(), req = args()[1]->evaluate(variables, fdb).as_int();
1155 const int count = req < 0 ?
n - std::min(-req,
n) : std::min(req,
n);
1158 std::advance(end, count);
1160 std::vector<variant> res;
1161 std::copy(it, end, std::back_inserter(res));
1167 const variant items = args()[0]->evaluate(variables, fdb);
1169 if(it == items.
begin()) {
1173 if(args().
size() == 1) {
1177 const int n = items.
num_elements(), req = args()[1]->evaluate(variables, fdb).as_int();
1178 const int count = req < 0 ?
n - std::min(-req,
n) : std::min(req,
n);
1180 std::advance(it, -count);
1181 std::vector<variant> res;
1183 std::copy(it, items.
end(), std::back_inserter(res));
1189 const variant items = args()[0]->evaluate(variables, fdb);
1195 if(!args().empty()) {
1196 for(std::size_t
i = 0;
i < args().size(); ++
i) {
1197 args()[
i]->evaluate(variables, fdb);
1206 variant decimal = args()[0]->evaluate(variables, fdb);
1207 int d = decimal.as_decimal();
1209 if((
d >= 0) && (
d % 1000 != 0)) {
1220 variant decimal = args()[0]->evaluate(variables, fdb);
1221 int d = decimal.as_decimal();
1227 }
else if(
f <= -500) {
1238 variant decimal = args()[0]->evaluate(variables, fdb);
1239 int d = decimal.as_decimal();
1241 if((
d < 0) && (
d % 1000 != 0)) {
1252 variant decimal = args()[0]->evaluate(variables, fdb);
1253 int d = decimal.as_int();
1260 variant decimal = args()[0]->evaluate(variables, fdb);
1261 int d = decimal.as_decimal();
1264 return variant(
d, variant::DECIMAL_VARIANT);
1269 variant decimal = args()[0]->evaluate(variables, fdb);
1270 int d = decimal.as_decimal();
1281 variant decimal = args()[0]->evaluate(variables, fdb);
1282 int d = decimal.as_decimal();
1284 return variant(
d, variant::DECIMAL_VARIANT);
1290 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"loc:x")).as_int(),
1297 return variant(std::make_shared<key_value_pair>(
1298 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"pair:key")),
1299 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"pair_value"))
1306 ->evaluate(variables,
add_debug_info(fdb, 0,
"distance_between:location_A"))
1311 ->evaluate(variables,
add_debug_info(fdb, 1,
"distance_between:location_B"))
1321 ->evaluate(variables,
add_debug_info(fdb, 0,
"adjacent_locs:location"))
1325 std::vector<variant> v;
1327 v.emplace_back(std::make_shared<location_callable>(adj));
1337 int range = args()[1]->evaluate(variables, fdb).as_int();
1344 return variant(std::make_shared<location_callable>(
loc));
1347 std::vector<map_location> res;
1351 std::vector<variant> v;
1352 v.reserve(res.size() + 1);
1353 v.emplace_back(std::make_shared<location_callable>(
loc));
1355 for(std::size_t
n = 0;
n != res.size(); ++
n) {
1356 v.emplace_back(std::make_shared<location_callable>(res[
n]));
1365 ->evaluate(variables,
add_debug_info(fdb, 0,
"are_adjacent:location_A"))
1370 ->evaluate(variables,
add_debug_info(fdb, 1,
"are_adjacent:location_B"))
1380 ->evaluate(variables,
add_debug_info(fdb, 0,
"relative_dir:location_A"))
1385 ->evaluate(variables,
add_debug_info(fdb, 1,
"relative_dir:location_B"))
1395 ->evaluate(variables,
add_debug_info(fdb, 0,
"direction_from:location"))
1399 const std::string dir_str =
1400 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"direction_from:dir")).as_string();
1402 int n = args().size() == 3
1403 ? args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"direction_from:count")).as_int()
1412 ->evaluate(variables,
add_debug_info(fdb, 0,
"direction_from:center"))
1417 ->evaluate(variables,
add_debug_info(fdb, 1,
"direction_from:location"))
1421 int n = args().size() == 3
1422 ? args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"direction_from:count")).as_int()
1430 const variant& v = args()[0]->evaluate(variables, fdb);
1440 const variant main = args()[0]->evaluate(variables, fdb);
1443 return variant(std::make_shared<safe_call_callable>(
main, backup_formula));
1448 return variant(std::make_shared<set_var_callable>(
1449 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"set_var:key")).as_string(),
1450 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"set_var:value"))));
1455 variant key_value_pair::get_value(
const std::string& key)
const
1459 }
else if(key ==
"value") {
1468 add_input(inputs,
"key");
1469 add_input(inputs,
"value");
1472 void key_value_pair::serialize_to_string(std::string& str)
const
1475 str += key_.serialize_to_string();
1477 str += value_.serialize_to_string();
1481 formula_function_expression::formula_function_expression(
const std::string& name,
1485 const std::vector<std::string>& arg_names)
1487 , formula_(std::move(
formula))
1488 , precondition_(std::move(precondition))
1489 , arg_names_(arg_names)
1503 static std::string
indent;
1508 const auto begin_time = std::chrono::steady_clock::now();
1522 DBG_NG <<
"FAILED function precondition for function '" <<
formula_->str() <<
"' with arguments: ";
1525 DBG_NG <<
" arg " << (
n + 1) <<
": " <<
args()[
n]->evaluate(variables, fdb).to_debug_string();
1532 const auto taken = std::chrono::steady_clock::now() - begin_time;
1541 const std::vector<expression_ptr>& args)
const
1547 : parent(parent ? parent : get_builtins())
1557 const std::string& fn,
const std::vector<expression_ptr>& args)
const
1561 return i->second->generate_function_expression(args);
1576 std::set<std::string> res;
1578 res =
parent->get_function_names();
1592 if(functions_table.
empty()) {
1593 functions_table.
parent =
nullptr;
1595 using namespace builtins;
void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
static game_display * get_singleton()
display_chat_manager & get_chat_manager()
void float_label(const map_location &loc, const std::string &text, const color_t &color)
Function to float a label above a tile.
action_function_symbol_table(const std::shared_ptr< function_symbol_table > &parent=nullptr)
const args_list & args() const
std::vector< expression_ptr > args_list
static std::shared_ptr< function_symbol_table > get_builtins()
expression_ptr create_function(const std::string &fn, const std::vector< expression_ptr > &args) const
function_symbol_table(const std::shared_ptr< function_symbol_table > &parent=nullptr)
void add_function(const std::string &name, formula_function_ptr &&fcn)
std::set< std::string > get_function_names() const
std::shared_ptr< function_symbol_table > parent
functions_map custom_formulas_
Iterator class for the variant.
int as_decimal() const
Returns variant's internal representation of decimal number: ie, 1.234 is represented as 1234.
variant_iterator begin() const
variant get_values() const
const_formula_callable_ptr as_callable() const
std::size_t num_elements() const
std::shared_ptr< T > convert_to() const
variant get_member(const std::string &name) const
const std::string & as_string() const
std::string string_cast() const
variant_iterator end() const
bool as_bool() const
Returns a boolean state of the variant value.
std::string type_string() const
Gets string name of the current value type.
std::string to_debug_string(bool verbose=false, formula_seen_stack *seen=nullptr) const
bool is_null() const
Functions to test the type of the internal value.
const formula_callable * fallback_
static lg::log_domain log_engine("engine")
static lg::log_domain log_scripting_formula("scripting/formula")
#define DEFINE_WFL_FUNCTION(name, min_args, max_args)
Helper macro to declare an associated class for a WFL function.
#define DECLARE_WFL_FUNCTION(name)
Declares a function name in the local function table functions_table.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
std::size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
static std::ostream & output()
Standard logging facilities (interface).
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
bool is_map(const std::string &filename)
Returns true if the file ends with the mapfile extension.
std::vector< color_t > red_green_scale_text
const std::vector< color_t > & tc_info(std::string_view name)
std::vector< color_t > blue_white_scale
std::vector< color_t > red_green_scale
std::vector< color_t > blue_white_scale_text
std::string & insert(std::string &str, const std::size_t pos, const std::string &insert)
Insert a UTF-8 string at the specified position.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
formula_debugger * add_debug_info(formula_debugger *fdb, int arg_number, const std::string &f_name)
std::vector< formula_input > formula_input_vector
std::shared_ptr< const formula > const_formula_ptr
std::shared_ptr< formula_expression > expression_ptr
static thread_local std::deque< std::string > call_stack
For printing error messages when WFL parsing or evaluation fails, this contains the names of the WFL ...
std::shared_ptr< function_expression > function_expression_ptr
std::shared_ptr< formula_function > formula_function_ptr
void get_tiles_in_radius(const map_location ¢er, const int radius, std::vector< map_location > &result)
Function that will add to result all locations within radius tiles of center (excluding center itself...
The basic class for representing 8-bit RGB or RGBA colour values.
Encapsulates the map of the game.
static std::string write_direction(direction dir)
map_location get_direction(direction dir, unsigned int n=1u) const
map_location rotate_right_around_center(const map_location ¢er, int k) const
direction get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
static direction parse_direction(const std::string &str)
static map_location::direction n
static map_location::direction s