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 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 std::string speaker =
"WFL";
272 if(args().
size() == 2) {
273 speaker = args()[0]->evaluate(variables, fdb).string_cast();
277 variant value = args()[i_value]->evaluate(variables, fdb);
280 LOG_SF << speaker <<
": " << str;
292 std::string speaker =
"WFL";
295 if(args().
size() == 2) {
296 speaker = args()[0]->evaluate(variables, fdb).string_cast();
300 const variant value = args()[i_value]->evaluate(variables, fdb);
301 const int run_count = 1000;
302 std::chrono::steady_clock::duration run_time;
304 for(
int i = 0;
i < run_count;
i++) {
305 const auto start = std::chrono::steady_clock::now();
306 args()[i_value]->evaluate(variables, fdb);
307 run_time += std::chrono::steady_clock::now() -
start;
311 auto average_ms = std::chrono::duration_cast<std::chrono::milliseconds>(run_time / run_count);
313 std::ostringstream str;
314 #ifdef __cpp_lib_format
315 str <<
"Evaluated in " << average_ms <<
" on average";
317 str <<
"Evaluated in " << average_ms.count() <<
" ms on average";
320 LOG_SF << speaker <<
": " << str.str();
332 const variant map = args()[0]->evaluate(variables, fdb);
338 const variant map = args()[0]->evaluate(variables, fdb);
344 const variant var = args()[0]->evaluate(variables, fdb);
346 std::vector<variant> tmp;
356 const variant var_1 = args()[0]->evaluate(variables, fdb);
358 std::map<variant, variant> tmp;
360 if(args().
size() == 2) {
361 const variant var_2 = args()[1]->evaluate(variables, fdb);
367 tmp[var_1[
i]] = var_2[
i];
372 tmp[kv->query_value(
"key")] = kv->query_value(
"value");
374 auto map_it = tmp.find(*it);
376 if(map_it == tmp.end()) {
379 map_it->second =
variant(map_it->second.as_int() + 1);
390 std::string result = args()[0]->evaluate(variables, fdb).as_string();
392 int offset = args()[1]->evaluate(variables, fdb).as_int();
394 offset += result.size();
400 if(
static_cast<std::size_t
>(offset) >= result.size()) {
405 if(args().
size() > 2) {
406 int size = args()[2]->evaluate(variables, fdb).as_int();
410 offset = std::max(0, offset -
size + 1);
416 return variant(result.substr(offset));
421 std::string result = args()[0]->evaluate(variables, fdb).as_string();
422 std::string replacement = args().back()->evaluate(variables, fdb).as_string();
424 int offset = args()[1]->evaluate(variables, fdb).as_int();
426 offset += result.size();
432 if(
static_cast<std::size_t
>(offset) >= result.size()) {
437 if(args().
size() > 3) {
438 int size = args()[2]->evaluate(variables, fdb).as_int();
442 offset = std::max(0, offset -
size + 1);
445 return variant(result.replace(offset,
size, replacement));
448 return variant(result.replace(offset, std::string::npos, replacement));
453 std::string result = args()[0]->evaluate(variables, fdb).as_string();
454 std::string needle = args()[1]->evaluate(variables, fdb).as_string();
455 std::string replacement = args().back()->evaluate(variables, fdb).as_string();
456 boost::replace_all(result, needle, replacement);
462 std::string str = args()[0]->evaluate(variables, fdb).as_string();
463 std::string prefix = args()[1]->evaluate(variables, fdb).as_string();
464 return variant(boost::starts_with(str, prefix));
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::ends_with(str, prefix));
476 std::string result = args()[0]->evaluate(variables, fdb).as_string();
477 std::string
insert = args().back()->evaluate(variables, fdb).as_string();
479 int offset = args()[1]->evaluate(variables, fdb).as_int();
481 offset += result.size();
486 }
else if(
static_cast<std::size_t
>(offset) >= result.size()) {
495 return variant(args()[0]->evaluate(variables, fdb).as_string().length());
502 result += arg->evaluate(variables, fdb).string_cast();
510 std::string str = args()[0]->evaluate(variables, fdb).as_string();
511 std::transform(str.begin(), str.end(), str.begin(),
static_cast<int (*)(
int)
>(std::toupper));
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::tolower));
524 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
525 const double result = std::sin(angle * pi<double>() / 180.0);
526 return variant(result, variant::DECIMAL_VARIANT);
531 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
532 const double result = std::cos(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::tan(angle * pi<double>() / 180.0);
540 if(std::isnan(result) || result <= std::numeric_limits<int>::min() || result >= std::numeric_limits<int>::max()) {
544 return variant(result, variant::DECIMAL_VARIANT);
549 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
550 const double result = std::asin(num) * 180.0 / pi<double>();
551 if(std::isnan(result)) {
555 return variant(result, variant::DECIMAL_VARIANT);
560 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
561 const double result = std::acos(num) * 180.0 / pi<double>();
562 if(std::isnan(result)) {
566 return variant(result, variant::DECIMAL_VARIANT);
571 if(args().
size() == 1) {
572 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
573 const double result = std::atan(num) * 180.0 / pi<double>();
574 return variant(result, variant::DECIMAL_VARIANT);
576 const double y = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
577 const double x = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
578 const double result = std::atan2(y, x) * 180.0 / pi<double>();
579 return variant(result, variant::DECIMAL_VARIANT);
585 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
586 const double result = std::sqrt(num);
587 if(std::isnan(result)) {
591 return variant(result, variant::DECIMAL_VARIANT);
596 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
597 const double result = num < 0 ? -std::pow(-num, 1.0 / 3.0) : std::pow(num, 1.0 / 3.0);
598 return variant(result, variant::DECIMAL_VARIANT);
603 const double base = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
604 const double root = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
605 const double result = base < 0 && std::fmod(root, 2) == 1 ? -std::pow(-base, 1.0 / root) : std::pow(base, 1.0 / root);
606 if(std::isnan(result)) {
610 return variant(result, variant::DECIMAL_VARIANT);
615 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
616 if(args().
size() == 1) {
617 const double result = std::log(num);
618 if(std::isnan(result)) {
622 return variant(result, variant::DECIMAL_VARIANT);
625 const double base = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
626 const double result = std::log(num) / std::log(base);
627 if(std::isnan(result)) {
631 return variant(result, variant::DECIMAL_VARIANT);
636 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
637 const double result = std::exp(num);
638 if(result == 0 || result >= std::numeric_limits<int>::max()) {
644 return variant(result, variant::DECIMAL_VARIANT);
649 return variant(pi<double>(), variant::DECIMAL_VARIANT);
654 const double x = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
655 const double y = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
656 return variant(std::hypot(x, y), variant::DECIMAL_VARIANT);
661 const variant value = args()[0]->evaluate(variables, fdb);
662 const variant list = args()[1]->evaluate(variables, fdb);
665 if(list[
i] == value) {
675 const variant items = args()[0]->evaluate(variables, fdb);
679 if(args().
size() == 2) {
690 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
693 self_callable.
add(
self, *it);
695 const variant val = args().back()->evaluate(
714 const int value = args()[0]->evaluate(variables, fdb).as_int() % 1000;
715 const double angle = 2.0 * pi<double>() * (
static_cast<double>(value) / 1000.0);
716 return variant(
static_cast<int>(std::sin(angle) * 1000.0));
721 const double lo = args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"lerp:lo")).as_decimal() / 1000.0;
722 const double hi = args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"lerp:hi")).as_decimal() / 1000.0;;
723 const double alpha = args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"lerp:alpha")).as_decimal() / 1000.0;;
724 return variant(
static_cast<int>((lo + alpha * (hi - lo)) * 1000.0), variant::DECIMAL_VARIANT);
729 const std::vector<variant> items = args()[0]->evaluate(variables, fdb).as_list();
730 if(items.empty())
return variant();
731 const double alpha = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
733 const double val_scaled = std::clamp(0.01 * alpha, 0.0, 1.0);
734 const int idx = int(std::nearbyint((items.size() - 1) * val_scaled));
740 const std::string name = args()[0]->evaluate(variables, fdb).as_string();
741 std::vector<color_t> colors;
742 if(name ==
"red_green_scale") {
744 }
else if(name ==
"red_green_scale_text") {
746 }
else if(name ==
"blue_white_scale") {
748 }
else if(name ==
"blue_white_scale_text") {
753 std::vector<variant> result;
754 result.reserve(colors.size());
755 for(
auto clr : colors) {
756 result.emplace_back(std::make_shared<color_callable>(clr));
785 bool operator()(
const variant& a,
const variant&
b)
const
789 return expr_->evaluate(*this).as_bool();
793 variant get_value(
const std::string& key)
const
797 }
else if(key ==
"b") {
817 variant list = args()[0]->evaluate(variables, fdb);
819 std::vector<variant> vars;
823 vars.push_back(list[
n]);
826 if(args().
size() == 1) {
827 std::sort(vars.begin(), vars.end());
829 std::sort(vars.begin(), vars.end(), variant_comparator(args()[1], variables));
837 const variant& arg = args()[0]->evaluate(variables, fdb);
840 std::string str = args()[0]->evaluate(variables, fdb).
as_string();
845 std::vector<variant> list = args()[0]->evaluate(variables, fdb).as_list();
856 std::string str = args()[0]->evaluate(variables, fdb).as_string();
857 std::string key = args()[1]->evaluate(variables, fdb).as_string();
859 return variant(str.find(key) != std::string::npos);
864 const std::string str = args()[0]->evaluate(variables, fdb).as_string();
865 const std::string key = args()[1]->evaluate(variables, fdb).as_string();
867 std::size_t pos = str.find(key);
868 return variant(
static_cast<int>(pos));
873 std::vector<variant> list_vars;
874 std::map<variant, variant> map_vars;
876 const variant items = args()[0]->evaluate(variables, fdb);
878 if(args().
size() == 2) {
884 map_vars[(*it).get_member(
"key")] = (*it).
get_member(
"value");
886 list_vars.push_back(*it);
892 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
895 self_callable.
add(
self, *it);
897 const variant val = args()[2]->evaluate(
902 map_vars[(*it).get_member(
"key")] = (*it).
get_member(
"value");
904 list_vars.push_back(*it);
919 const variant items = args()[0]->evaluate(variables, fdb);
921 if(args().
size() == 2) {
930 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
933 self_callable.
add(
self, *it);
935 const variant val = args().back()->evaluate(
949 std::vector<variant> list_vars;
950 std::map<variant, variant> map_vars;
951 const variant items = args()[0]->evaluate(variables, fdb);
953 if(args().
size() == 2) {
957 map_vars[(*it).get_member(
"key")] = val;
959 list_vars.push_back(val);
964 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
967 self_callable.
add(
self, *it);
969 const variant val = args().back()->evaluate(
973 map_vars[(*it).get_member(
"key")] = val;
975 list_vars.push_back(val);
989 const variant& items = args()[0]->evaluate(variables, fdb);
992 for(; it != items.
end(); ++it) {
1000 std::vector<variant> result(items.
begin(), it);
1008 explicit indexer(std::size_t
i)
1013 variant operator()(
const variant& v)
const
1015 if(
i >= v.num_elements()) {
1028 bool operator()(
const variant& a,
const variant&
b)
const
1030 return a.num_elements() <
b.num_elements();
1034 std::vector<variant> get_input(
1035 const function_expression::args_list& args,
1036 const formula_callable& variables,
1037 formula_debugger* fdb)
1039 if(args.size() == 1) {
1040 const variant list = args[0]->evaluate(variables, fdb);
1041 return std::vector<variant>(list.begin(), list.end());
1043 std::vector<variant> input;
1044 input.reserve(args.size());
1047 input.push_back(
expr->evaluate(variables, fdb));
1057 const std::vector<variant> input = get_input(args(), variables, fdb);
1058 std::vector<variant>
output;
1062 std::size_t max_i = std::max_element(input.begin(), input.end(), comparator())->num_elements();
1065 for(std::size_t
i = 0;
i < max_i;
i++) {
1066 std::vector<variant> elem(input.size());
1068 output.emplace_back(elem);
1076 const variant items = args()[0]->evaluate(variables, fdb);
1077 variant initial = args().size() == 2 ?
variant() : args()[1]->evaluate(variables, fdb);
1085 if(res != initial) {
1090 for(; it != items.
end(); ++it) {
1091 self_callable.
add(
"a", res);
1092 self_callable.
add(
"b", *it);
1093 res = args().back()->evaluate(
1103 const variant items = args()[0]->evaluate(variables, fdb);
1105 if(items[0].is_list()) {
1106 std::vector<variant> tmp;
1108 if(args().
size() >= 2) {
1109 res = args()[1]->evaluate(variables, fdb);
1113 }
else if(items[0].
is_map()) {
1114 std::map<variant, variant> tmp;
1116 if(args().
size() >= 2) {
1117 res = args()[1]->evaluate(variables, fdb);
1122 if(args().
size() >= 2) {
1123 res = args()[1]->evaluate(variables, fdb);
1129 res = res + items[
n];
1137 const variant items = args()[0]->evaluate(variables, fdb);
1139 if(it == items.
end()) {
1143 if(args().
size() == 1) {
1147 const int n = items.
num_elements(), req = args()[1]->evaluate(variables, fdb).as_int();
1148 const int count = req < 0 ?
n - std::min(-req,
n) : std::min(req,
n);
1151 std::advance(end, count);
1153 std::vector<variant> res;
1154 std::copy(it, end, std::back_inserter(res));
1160 const variant items = args()[0]->evaluate(variables, fdb);
1162 if(it == items.
begin()) {
1166 if(args().
size() == 1) {
1170 const int n = items.
num_elements(), req = args()[1]->evaluate(variables, fdb).as_int();
1171 const int count = req < 0 ?
n - std::min(-req,
n) : std::min(req,
n);
1173 std::advance(it, -count);
1174 std::vector<variant> res;
1176 std::copy(it, items.
end(), std::back_inserter(res));
1182 const variant items = args()[0]->evaluate(variables, fdb);
1188 if(!args().empty()) {
1189 for(std::size_t
i = 0;
i < args().size(); ++
i) {
1190 args()[
i]->evaluate(variables, fdb);
1199 variant decimal = args()[0]->evaluate(variables, fdb);
1200 int d = decimal.as_decimal();
1202 if((
d >= 0) && (
d % 1000 != 0)) {
1213 variant decimal = args()[0]->evaluate(variables, fdb);
1214 int d = decimal.as_decimal();
1220 }
else if(
f <= -500) {
1231 variant decimal = args()[0]->evaluate(variables, fdb);
1232 int d = decimal.as_decimal();
1234 if((
d < 0) && (
d % 1000 != 0)) {
1245 variant decimal = args()[0]->evaluate(variables, fdb);
1246 int d = decimal.as_int();
1253 variant decimal = args()[0]->evaluate(variables, fdb);
1254 int d = decimal.as_decimal();
1257 return variant(
d, variant::DECIMAL_VARIANT);
1262 variant decimal = args()[0]->evaluate(variables, fdb);
1263 int d = decimal.as_decimal();
1274 variant decimal = args()[0]->evaluate(variables, fdb);
1275 int d = decimal.as_decimal();
1277 return variant(
d, variant::DECIMAL_VARIANT);
1283 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"loc:x")).as_int(),
1290 return variant(std::make_shared<key_value_pair>(
1291 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"pair:key")),
1292 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"pair_value"))
1299 ->evaluate(variables,
add_debug_info(fdb, 0,
"distance_between:location_A"))
1304 ->evaluate(variables,
add_debug_info(fdb, 1,
"distance_between:location_B"))
1314 ->evaluate(variables,
add_debug_info(fdb, 0,
"adjacent_locs:location"))
1318 std::vector<variant> v;
1320 v.emplace_back(std::make_shared<location_callable>(adj));
1330 int range = args()[1]->evaluate(variables, fdb).as_int();
1337 return variant(std::make_shared<location_callable>(
loc));
1340 std::vector<map_location> res;
1344 std::vector<variant> v;
1345 v.reserve(res.size() + 1);
1346 v.emplace_back(std::make_shared<location_callable>(
loc));
1348 for(std::size_t
n = 0;
n != res.size(); ++
n) {
1349 v.emplace_back(std::make_shared<location_callable>(res[
n]));
1358 ->evaluate(variables,
add_debug_info(fdb, 0,
"are_adjacent:location_A"))
1363 ->evaluate(variables,
add_debug_info(fdb, 1,
"are_adjacent:location_B"))
1373 ->evaluate(variables,
add_debug_info(fdb, 0,
"relative_dir:location_A"))
1378 ->evaluate(variables,
add_debug_info(fdb, 1,
"relative_dir:location_B"))
1388 ->evaluate(variables,
add_debug_info(fdb, 0,
"direction_from:location"))
1392 const std::string dir_str =
1393 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"direction_from:dir")).as_string();
1395 int n = args().size() == 3
1396 ? args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"direction_from:count")).as_int()
1405 ->evaluate(variables,
add_debug_info(fdb, 0,
"direction_from:center"))
1410 ->evaluate(variables,
add_debug_info(fdb, 1,
"direction_from:location"))
1414 int n = args().size() == 3
1415 ? args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"direction_from:count")).as_int()
1423 const variant& v = args()[0]->evaluate(variables, fdb);
1433 const variant main = args()[0]->evaluate(variables, fdb);
1436 return variant(std::make_shared<safe_call_callable>(
main, backup_formula));
1441 return variant(std::make_shared<set_var_callable>(
1442 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"set_var:key")).as_string(),
1443 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"set_var:value"))));
1448 variant key_value_pair::get_value(
const std::string& key)
const
1452 }
else if(key ==
"value") {
1461 add_input(inputs,
"key");
1462 add_input(inputs,
"value");
1465 void key_value_pair::serialize_to_string(std::string& str)
const
1468 str += key_.serialize_to_string();
1470 str +=
value_.serialize_to_string();
1474 formula_function_expression::formula_function_expression(
const std::string& name,
1478 const std::vector<std::string>& arg_names)
1480 , formula_(std::move(
formula))
1481 , precondition_(std::move(precondition))
1482 , arg_names_(arg_names)
1496 static std::string
indent;
1501 const auto begin_time = std::chrono::steady_clock::now();
1515 DBG_NG <<
"FAILED function precondition for function '" <<
formula_->str() <<
"' with arguments: ";
1518 DBG_NG <<
" arg " << (
n + 1) <<
": " <<
args()[
n]->evaluate(variables, fdb).to_debug_string();
1525 const auto taken = std::chrono::steady_clock::now() - begin_time;
1534 const std::vector<expression_ptr>& args)
const
1540 : parent(parent ? parent : get_builtins())
1550 const std::string& fn,
const std::vector<expression_ptr>& args)
const
1554 return i->second->generate_function_expression(args);
1569 std::set<std::string> res;
1571 res =
parent->get_function_names();
1585 if(functions_table.
empty()) {
1586 functions_table.
parent =
nullptr;
1588 using namespace builtins;
std::unique_ptr< PangoAttribute, void(*)(PangoAttribute *)> value_
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