19 #include "formula/callable_objects.hpp"
26 #include <boost/algorithm/string.hpp>
27 #include <boost/math/constants/constants.hpp>
32 using namespace boost::math::constants;
35 #define DBG_NG LOG_STREAM(debug, log_engine)
37 #define LOG_SF LOG_STREAM(info, log_scripting_formula)
38 #define WRN_SF LOG_STREAM(warn, log_scripting_formula)
39 #define ERR_SF LOG_STREAM(err, log_scripting_formula)
51 call_stack_manager::call_stack_manager(
const std::string& str)
56 call_stack_manager::~call_stack_manager()
63 std::ostringstream res;
66 res <<
" " << frame <<
"\n";
73 std::string function_expression::str()
const
78 bool first_arg =
true;
95 std::shared_ptr<formula_debugger> fdbp;
96 bool need_wrapper =
false;
104 if(args().
size() == 1) {
106 return args()[0]->evaluate(variables, fdb);
117 variant var = args()[0]->evaluate(variables, fdb);
122 std::vector<variant> res;
123 for(std::size_t
i = 0;
i < inputs.size(); ++
i) {
125 res.emplace_back(input.
name);
133 for(std::size_t
n = 0;
n < args().size() - 1;
n += 2) {
134 if(args()[
n]->evaluate(variables, fdb).as_bool()) {
135 return args()[
n + 1]->evaluate(variables, fdb);
139 if((args().
size() % 2) != 0) {
140 return args().back()->evaluate(variables, fdb);
148 variant var = args()[0]->evaluate(variables, fdb);
150 for(std::size_t
n = 1;
n < args().size() - 1;
n += 2) {
151 variant val = args()[
n]->evaluate(variables, fdb);
154 return args()[
n + 1]->evaluate(variables, fdb);
158 if((args().
size() % 2) == 0) {
159 return args().back()->evaluate(variables, fdb);
167 const variant input = args()[0]->evaluate(variables, fdb);
170 return variant(
n >= 0 ?
n : -
n, variant::DECIMAL_VARIANT);
179 variant res = args()[0]->evaluate(variables, fdb);
185 res = *std::min_element(res.
begin(), res.
end());
188 for(std::size_t
n = 1;
n < args().size(); ++
n) {
189 variant v = args()[
n]->evaluate(variables, fdb);
196 v = *std::min_element(v.
begin(), v.
end());
209 variant res = args()[0]->evaluate(variables, fdb);
215 res = *std::max_element(res.
begin(), res.
end());
218 for(std::size_t
n = 1;
n < args().size(); ++
n) {
219 variant v = args()[
n]->evaluate(variables, fdb);
226 v = *std::max_element(v.
begin(), v.
end());
239 void display_float(
const map_location& location,
const std::string& text)
247 const args_list& arguments = args();
248 const variant var0 = arguments[0]->evaluate(variables, fdb);
249 const variant var1 = arguments[1]->evaluate(variables, fdb);
254 if(arguments.size() == 2) {
256 display_float(location, text);
259 const variant var2 = arguments[2]->evaluate(variables, fdb);
261 display_float(location, text);
268 const variant var1 = args()[0]->evaluate(variables, fdb);
270 std::string str1, str2;
272 if(args().
size() == 1) {
286 const variant var2 = args()[1]->evaluate(variables, fdb);
289 LOG_SF << str1 <<
": " << str2;
302 std::string speaker =
"WFL";
305 if(args().
size() == 2) {
306 speaker = args()[0]->evaluate(variables, fdb).string_cast();
310 const variant value = args()[i_value]->evaluate(variables, fdb);
311 std::chrono::steady_clock::duration run_time;
313 for(
int i = 1;
i < 1000;
i++) {
314 const auto start = std::chrono::steady_clock::now();
315 args()[i_value]->evaluate(variables, fdb);
316 run_time += std::chrono::steady_clock::now() -
start;
319 std::ostringstream str;
320 #ifdef __cpp_lib_format
321 str <<
"Evaluated in " << std::chrono::duration_cast<std::chrono::milliseconds>(run_time) <<
" on average";
323 str <<
"Evaluated in " << std::chrono::duration_cast<std::chrono::milliseconds>(run_time).count() <<
" ms on average";
326 LOG_SF << speaker <<
": " << str.str();
338 const variant map = args()[0]->evaluate(variables, fdb);
344 const variant map = args()[0]->evaluate(variables, fdb);
350 const variant var = args()[0]->evaluate(variables, fdb);
352 std::vector<variant> tmp;
362 const variant var_1 = args()[0]->evaluate(variables, fdb);
364 std::map<variant, variant> tmp;
366 if(args().
size() == 2) {
367 const variant var_2 = args()[1]->evaluate(variables, fdb);
373 tmp[var_1[
i]] = var_2[
i];
378 tmp[kv->query_value(
"key")] = kv->query_value(
"value");
380 auto map_it = tmp.find(*it);
382 if(map_it == tmp.end()) {
385 map_it->second =
variant(map_it->second.as_int() + 1);
396 std::string result = args()[0]->evaluate(variables, fdb).as_string();
398 int offset = args()[1]->evaluate(variables, fdb).as_int();
400 offset += result.size();
406 if(
static_cast<std::size_t
>(offset) >= result.size()) {
411 if(args().
size() > 2) {
412 int size = args()[2]->evaluate(variables, fdb).as_int();
416 offset = std::max(0, offset -
size + 1);
422 return variant(result.substr(offset));
427 std::string result = args()[0]->evaluate(variables, fdb).as_string();
428 std::string replacement = args().back()->evaluate(variables, fdb).as_string();
430 int offset = args()[1]->evaluate(variables, fdb).as_int();
432 offset += result.size();
438 if(
static_cast<std::size_t
>(offset) >= result.size()) {
443 if(args().
size() > 3) {
444 int size = args()[2]->evaluate(variables, fdb).as_int();
448 offset = std::max(0, offset -
size + 1);
451 return variant(result.replace(offset,
size, replacement));
454 return variant(result.replace(offset, std::string::npos, replacement));
459 std::string result = args()[0]->evaluate(variables, fdb).as_string();
460 std::string needle = args()[1]->evaluate(variables, fdb).as_string();
461 std::string replacement = args().back()->evaluate(variables, fdb).as_string();
462 boost::replace_all(result, needle, replacement);
468 std::string str = args()[0]->evaluate(variables, fdb).as_string();
469 std::string prefix = args()[1]->evaluate(variables, fdb).as_string();
470 return variant(boost::starts_with(str, prefix));
475 std::string str = args()[0]->evaluate(variables, fdb).as_string();
476 std::string prefix = args()[1]->evaluate(variables, fdb).as_string();
477 return variant(boost::ends_with(str, prefix));
482 std::string result = args()[0]->evaluate(variables, fdb).as_string();
483 std::string
insert = args().back()->evaluate(variables, fdb).as_string();
485 int offset = args()[1]->evaluate(variables, fdb).as_int();
487 offset += result.size();
492 }
else if(
static_cast<std::size_t
>(offset) >= result.size()) {
501 return variant(args()[0]->evaluate(variables, fdb).as_string().length());
508 result += arg->evaluate(variables, fdb).string_cast();
516 std::string str = args()[0]->evaluate(variables, fdb).as_string();
517 std::transform(str.begin(), str.end(), str.begin(),
static_cast<int (*)(
int)
>(std::toupper));
523 std::string str = args()[0]->evaluate(variables, fdb).as_string();
524 std::transform(str.begin(), str.end(), str.begin(),
static_cast<int (*)(
int)
>(std::tolower));
530 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
531 const double result = std::sin(angle * pi<double>() / 180.0);
532 return variant(result, variant::DECIMAL_VARIANT);
537 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
538 const double result = std::cos(angle * pi<double>() / 180.0);
539 return variant(result, variant::DECIMAL_VARIANT);
544 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
545 const double result = std::tan(angle * pi<double>() / 180.0);
546 if(std::isnan(result) || result <= std::numeric_limits<int>::min() || result >= std::numeric_limits<int>::max()) {
550 return variant(result, variant::DECIMAL_VARIANT);
555 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
556 const double result = std::asin(num) * 180.0 / pi<double>();
557 if(std::isnan(result)) {
561 return variant(result, variant::DECIMAL_VARIANT);
566 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
567 const double result = std::acos(num) * 180.0 / pi<double>();
568 if(std::isnan(result)) {
572 return variant(result, variant::DECIMAL_VARIANT);
577 if(args().
size() == 1) {
578 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
579 const double result = std::atan(num) * 180.0 / pi<double>();
580 return variant(result, variant::DECIMAL_VARIANT);
582 const double y = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
583 const double x = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
584 const double result = std::atan2(y, x) * 180.0 / pi<double>();
585 return variant(result, variant::DECIMAL_VARIANT);
591 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
592 const double result = std::sqrt(num);
593 if(std::isnan(result)) {
597 return variant(result, variant::DECIMAL_VARIANT);
602 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
603 const double result = num < 0 ? -std::pow(-num, 1.0 / 3.0) : std::pow(num, 1.0 / 3.0);
604 return variant(result, variant::DECIMAL_VARIANT);
609 const double base = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
610 const double root = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
611 const double result = base < 0 && std::fmod(root, 2) == 1 ? -std::pow(-base, 1.0 / root) : std::pow(base, 1.0 / root);
612 if(std::isnan(result)) {
616 return variant(result, variant::DECIMAL_VARIANT);
621 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
622 if(args().
size() == 1) {
623 const double result = std::log(num);
624 if(std::isnan(result)) {
628 return variant(result, variant::DECIMAL_VARIANT);
631 const double base = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
632 const double result = std::log(num) / std::log(base);
633 if(std::isnan(result)) {
637 return variant(result, variant::DECIMAL_VARIANT);
642 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
643 const double result = std::exp(num);
644 if(result == 0 || result >= std::numeric_limits<int>::max()) {
650 return variant(result, variant::DECIMAL_VARIANT);
655 return variant(pi<double>(), variant::DECIMAL_VARIANT);
660 const double x = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
661 const double y = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
662 return variant(std::hypot(x, y), variant::DECIMAL_VARIANT);
667 const variant value = args()[0]->evaluate(variables, fdb);
668 const variant list = args()[1]->evaluate(variables, fdb);
671 if(list[
i] == value) {
681 const variant items = args()[0]->evaluate(variables, fdb);
685 if(args().
size() == 2) {
696 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
699 self_callable.
add(
self, *it);
701 const variant val = args().back()->evaluate(
720 const int value = args()[0]->evaluate(variables, fdb).as_int() % 1000;
721 const double angle = 2.0 * pi<double>() * (
static_cast<double>(value) / 1000.0);
722 return variant(
static_cast<int>(std::sin(angle) * 1000.0));
727 const double lo = args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"lerp:lo")).as_decimal() / 1000.0;
728 const double hi = args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"lerp:hi")).as_decimal() / 1000.0;;
729 const double alpha = args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"lerp:alpha")).as_decimal() / 1000.0;;
730 return variant(
static_cast<int>((lo + alpha * (hi - lo)) * 1000.0), variant::DECIMAL_VARIANT);
735 const std::vector<variant> items = args()[0]->evaluate(variables, fdb).as_list();
736 if(items.empty())
return variant();
737 const double alpha = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
739 const double val_scaled = std::clamp(0.01 * alpha, 0.0, 1.0);
740 const int idx = int(std::nearbyint((items.size() - 1) * val_scaled));
746 const std::string name = args()[0]->evaluate(variables, fdb).as_string();
747 std::vector<color_t> colors;
748 if(name ==
"red_green_scale") {
750 }
else if(name ==
"red_green_scale_text") {
752 }
else if(name ==
"blue_white_scale") {
754 }
else if(name ==
"blue_white_scale_text") {
759 std::vector<variant> result;
760 result.reserve(colors.size());
761 for(
auto clr : colors) {
762 result.emplace_back(std::make_shared<color_callable>(clr));
791 bool operator()(
const variant& a,
const variant&
b)
const
795 return expr_->evaluate(*this).as_bool();
799 variant get_value(
const std::string& key)
const
803 }
else if(key ==
"b") {
823 variant list = args()[0]->evaluate(variables, fdb);
825 std::vector<variant> vars;
829 vars.push_back(list[
n]);
832 if(args().
size() == 1) {
833 std::sort(vars.begin(), vars.end());
835 std::sort(vars.begin(), vars.end(), variant_comparator(args()[1], variables));
843 const variant& arg = args()[0]->evaluate(variables, fdb);
846 std::string str = args()[0]->evaluate(variables, fdb).
as_string();
847 std::reverse(str.begin(), str.end());
851 std::vector<variant> list = args()[0]->evaluate(variables, fdb).as_list();
852 std::reverse(list.begin(), list.end());
862 std::string str = args()[0]->evaluate(variables, fdb).as_string();
863 std::string key = args()[1]->evaluate(variables, fdb).as_string();
865 return variant(str.find(key) != std::string::npos);
870 const std::string str = args()[0]->evaluate(variables, fdb).as_string();
871 const std::string key = args()[1]->evaluate(variables, fdb).as_string();
873 std::size_t pos = str.find(key);
874 return variant(
static_cast<int>(pos));
879 std::vector<variant> list_vars;
880 std::map<variant, variant> map_vars;
882 const variant items = args()[0]->evaluate(variables, fdb);
884 if(args().
size() == 2) {
890 map_vars[(*it).get_member(
"key")] = (*it).
get_member(
"value");
892 list_vars.push_back(*it);
898 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
901 self_callable.
add(
self, *it);
903 const variant val = args()[2]->evaluate(
908 map_vars[(*it).get_member(
"key")] = (*it).
get_member(
"value");
910 list_vars.push_back(*it);
925 const variant items = args()[0]->evaluate(variables, fdb);
927 if(args().
size() == 2) {
936 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
939 self_callable.
add(
self, *it);
941 const variant val = args().back()->evaluate(
955 std::vector<variant> list_vars;
956 std::map<variant, variant> map_vars;
957 const variant items = args()[0]->evaluate(variables, fdb);
959 if(args().
size() == 2) {
963 map_vars[(*it).get_member(
"key")] = val;
965 list_vars.push_back(val);
970 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
973 self_callable.
add(
self, *it);
975 const variant val = args().back()->evaluate(
979 map_vars[(*it).get_member(
"key")] = val;
981 list_vars.push_back(val);
995 const variant& items = args()[0]->evaluate(variables, fdb);
998 for(; it != items.
end(); ++it) {
1006 std::vector<variant> result(items.
begin(), it);
1014 explicit indexer(std::size_t
i)
1019 variant operator()(
const variant& v)
const
1021 if(
i >= v.num_elements()) {
1034 bool operator()(
const variant& a,
const variant&
b)
const
1036 return a.num_elements() <
b.num_elements();
1040 std::vector<variant> get_input(
1041 const function_expression::args_list& args,
1042 const formula_callable& variables,
1043 formula_debugger* fdb)
1045 if(args.size() == 1) {
1046 const variant list = args[0]->evaluate(variables, fdb);
1047 return std::vector<variant>(list.begin(), list.end());
1049 std::vector<variant> input;
1050 input.reserve(args.size());
1053 input.push_back(
expr->evaluate(variables, fdb));
1063 const std::vector<variant> input = get_input(args(), variables, fdb);
1064 std::vector<variant>
output;
1068 std::size_t max_i = std::max_element(input.begin(), input.end(), comparator())->num_elements();
1071 for(std::size_t
i = 0;
i < max_i;
i++) {
1072 std::vector<variant> elem(input.size());
1073 std::transform(input.begin(), input.end(), elem.begin(), indexer(
i));
1074 output.emplace_back(elem);
1082 const variant items = args()[0]->evaluate(variables, fdb);
1083 const variant initial = args().size() == 2 ?
variant() : args()[1]->evaluate(variables, fdb);
1091 if(res != initial) {
1096 for(; it != items.
end(); ++it) {
1097 self_callable.
add(
"a", res);
1098 self_callable.
add(
"b", *it);
1099 res = args().back()->evaluate(
1109 const variant items = args()[0]->evaluate(variables, fdb);
1111 if(items[0].is_list()) {
1112 std::vector<variant> tmp;
1114 if(args().
size() >= 2) {
1115 res = args()[1]->evaluate(variables, fdb);
1119 }
else if(items[0].
is_map()) {
1120 std::map<variant, variant> tmp;
1122 if(args().
size() >= 2) {
1123 res = args()[1]->evaluate(variables, fdb);
1128 if(args().
size() >= 2) {
1129 res = args()[1]->evaluate(variables, fdb);
1135 res = res + items[
n];
1143 const variant items = args()[0]->evaluate(variables, fdb);
1145 if(it == items.
end()) {
1149 if(args().
size() == 1) {
1153 const int n = items.
num_elements(), req = args()[1]->evaluate(variables, fdb).as_int();
1154 const int count = req < 0 ?
n - std::min(-req,
n) : std::min(req,
n);
1157 std::advance(end, count);
1159 std::vector<variant> res;
1160 std::copy(it, end, std::back_inserter(res));
1166 const variant items = args()[0]->evaluate(variables, fdb);
1168 if(it == items.
begin()) {
1172 if(args().
size() == 1) {
1176 const int n = items.
num_elements(), req = args()[1]->evaluate(variables, fdb).as_int();
1177 const int count = req < 0 ?
n - std::min(-req,
n) : std::min(req,
n);
1179 std::advance(it, -count);
1180 std::vector<variant> res;
1182 std::copy(it, items.
end(), std::back_inserter(res));
1188 const variant items = args()[0]->evaluate(variables, fdb);
1194 if(!args().empty()) {
1195 for(std::size_t
i = 0;
i < args().size(); ++
i) {
1196 args()[
i]->evaluate(variables, fdb);
1205 variant decimal = args()[0]->evaluate(variables, fdb);
1206 int d = decimal.as_decimal();
1208 if((
d >= 0) && (
d % 1000 != 0)) {
1219 variant decimal = args()[0]->evaluate(variables, fdb);
1220 int d = decimal.as_decimal();
1226 }
else if(
f <= -500) {
1237 variant decimal = args()[0]->evaluate(variables, fdb);
1238 int d = decimal.as_decimal();
1240 if((
d < 0) && (
d % 1000 != 0)) {
1251 variant decimal = args()[0]->evaluate(variables, fdb);
1252 int d = decimal.as_int();
1259 variant decimal = args()[0]->evaluate(variables, fdb);
1260 int d = decimal.as_decimal();
1263 return variant(
d, variant::DECIMAL_VARIANT);
1268 variant decimal = args()[0]->evaluate(variables, fdb);
1269 int d = decimal.as_decimal();
1280 variant decimal = args()[0]->evaluate(variables, fdb);
1281 int d = decimal.as_decimal();
1283 return variant(
d, variant::DECIMAL_VARIANT);
1289 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"loc:x")).as_int(),
1296 return variant(std::make_shared<key_value_pair>(
1297 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"pair:key")),
1298 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"pair_value"))
1305 ->evaluate(variables,
add_debug_info(fdb, 0,
"distance_between:location_A"))
1310 ->evaluate(variables,
add_debug_info(fdb, 1,
"distance_between:location_B"))
1320 ->evaluate(variables,
add_debug_info(fdb, 0,
"adjacent_locs:location"))
1324 std::vector<variant> v;
1326 v.emplace_back(std::make_shared<location_callable>(adj));
1336 int range = args()[1]->evaluate(variables, fdb).as_int();
1343 return variant(std::make_shared<location_callable>(loc));
1346 std::vector<map_location> res;
1350 std::vector<variant> v;
1351 v.reserve(res.size() + 1);
1352 v.emplace_back(std::make_shared<location_callable>(loc));
1354 for(std::size_t
n = 0;
n != res.size(); ++
n) {
1355 v.emplace_back(std::make_shared<location_callable>(res[
n]));
1364 ->evaluate(variables,
add_debug_info(fdb, 0,
"are_adjacent:location_A"))
1369 ->evaluate(variables,
add_debug_info(fdb, 1,
"are_adjacent:location_B"))
1379 ->evaluate(variables,
add_debug_info(fdb, 0,
"relative_dir:location_A"))
1384 ->evaluate(variables,
add_debug_info(fdb, 1,
"relative_dir:location_B"))
1394 ->evaluate(variables,
add_debug_info(fdb, 0,
"direction_from:location"))
1398 const std::string dir_str =
1399 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"direction_from:dir")).as_string();
1401 int n = args().size() == 3
1402 ? args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"direction_from:count")).as_int()
1411 ->evaluate(variables,
add_debug_info(fdb, 0,
"direction_from:center"))
1416 ->evaluate(variables,
add_debug_info(fdb, 1,
"direction_from:location"))
1420 int n = args().size() == 3
1421 ? args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"direction_from:count")).as_int()
1429 const variant& v = args()[0]->evaluate(variables, fdb);
1439 const variant main = args()[0]->evaluate(variables, fdb);
1442 return variant(std::make_shared<safe_call_callable>(
main, backup_formula));
1447 return variant(std::make_shared<set_var_callable>(
1448 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"set_var:key")).as_string(),
1449 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"set_var:value"))));
1454 variant key_value_pair::get_value(
const std::string& key)
const
1458 }
else if(key ==
"value") {
1467 add_input(inputs,
"key");
1468 add_input(inputs,
"value");
1471 void key_value_pair::serialize_to_string(std::string& str)
const
1474 str += key_.serialize_to_string();
1476 str += value_.serialize_to_string();
1480 formula_function_expression::formula_function_expression(
const std::string& name,
1484 const std::vector<std::string>& arg_names)
1487 , precondition_(precondition)
1488 , arg_names_(arg_names)
1502 static std::string
indent;
1507 const auto begin_time = std::chrono::steady_clock::now();
1521 DBG_NG <<
"FAILED function precondition for function '" <<
formula_->str() <<
"' with arguments: ";
1524 DBG_NG <<
" arg " << (
n + 1) <<
": " <<
args()[
n]->evaluate(variables, fdb).to_debug_string();
1531 const auto taken = std::chrono::steady_clock::now() - begin_time;
1540 const std::vector<expression_ptr>& args)
const
1546 : parent(parent ? parent : get_builtins())
1556 const std::string& fn,
const std::vector<expression_ptr>& args)
const
1560 return i->second->generate_function_expression(args);
1575 std::set<std::string> res;
1577 res =
parent->get_function_names();
1591 if(functions_table.
empty()) {
1592 functions_table.
parent =
nullptr;
1594 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(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
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_
function_symbol_table(std::shared_ptr< function_symbol_table > parent=nullptr)
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(const std::string &str)
Length in characters of a UTF-8 string.
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