19 #include "formula/callable_objects.hpp"
26 #include <boost/algorithm/string.hpp>
27 #include <boost/math/constants/constants.hpp>
31 using namespace boost::math::constants;
34 #define DBG_NG LOG_STREAM(debug, log_engine)
36 #define LOG_SF LOG_STREAM(info, log_scripting_formula)
37 #define WRN_SF LOG_STREAM(warn, log_scripting_formula)
38 #define ERR_SF LOG_STREAM(err, log_scripting_formula)
50 call_stack_manager::call_stack_manager(
const std::string& str)
55 call_stack_manager::~call_stack_manager()
62 std::ostringstream res;
65 res <<
" " << frame <<
"\n";
72 std::string function_expression::str()
const
77 bool first_arg =
true;
94 std::shared_ptr<formula_debugger> fdbp;
95 bool need_wrapper =
false;
103 if(args().
size() == 1) {
105 return args()[0]->evaluate(variables, fdb);
116 variant var = args()[0]->evaluate(variables, fdb);
121 std::vector<variant> res;
122 for(std::size_t
i = 0;
i < inputs.size(); ++
i) {
124 res.emplace_back(input.
name);
132 for(std::size_t
n = 0;
n < args().size() - 1;
n += 2) {
133 if(args()[
n]->evaluate(variables, fdb).as_bool()) {
134 return args()[
n + 1]->evaluate(variables, fdb);
138 if((args().
size() % 2) != 0) {
139 return args().back()->evaluate(variables, fdb);
147 variant var = args()[0]->evaluate(variables, fdb);
149 for(std::size_t
n = 1;
n < args().size() - 1;
n += 2) {
150 variant val = args()[
n]->evaluate(variables, fdb);
153 return args()[
n + 1]->evaluate(variables, fdb);
157 if((args().
size() % 2) == 0) {
158 return args().back()->evaluate(variables, fdb);
166 const variant input = args()[0]->evaluate(variables, fdb);
169 return variant(
n >= 0 ?
n : -
n, variant::DECIMAL_VARIANT);
178 variant res = args()[0]->evaluate(variables, fdb);
184 res = *std::min_element(res.
begin(), res.
end());
187 for(std::size_t
n = 1;
n < args().size(); ++
n) {
188 variant v = args()[
n]->evaluate(variables, fdb);
195 v = *std::min_element(v.
begin(), v.
end());
208 variant res = args()[0]->evaluate(variables, fdb);
214 res = *std::max_element(res.
begin(), res.
end());
217 for(std::size_t
n = 1;
n < args().size(); ++
n) {
218 variant v = args()[
n]->evaluate(variables, fdb);
225 v = *std::max_element(v.
begin(), v.
end());
238 void display_float(
const map_location& location,
const std::string& text)
246 const args_list& arguments = args();
247 const variant var0 = arguments[0]->evaluate(variables, fdb);
248 const variant var1 = arguments[1]->evaluate(variables, fdb);
253 if(arguments.size() == 2) {
255 display_float(location, text);
258 const variant var2 = arguments[2]->evaluate(variables, fdb);
260 display_float(location, text);
267 const variant var1 = args()[0]->evaluate(variables, fdb);
269 std::string str1, str2;
271 if(args().
size() == 1) {
285 const variant var2 = args()[1]->evaluate(variables, fdb);
288 LOG_SF << str1 <<
": " << str2;
301 std::string speaker =
"WFL";
304 if(args().
size() == 2) {
305 speaker = args()[0]->evaluate(variables, fdb).string_cast();
309 const variant value = args()[i_value]->evaluate(variables, fdb);
312 for(
int i = 1;
i < 1000;
i++) {
313 const long start = SDL_GetTicks();
314 args()[i_value]->evaluate(variables, fdb);
315 run_time += SDL_GetTicks() -
start;
318 std::ostringstream str;
319 str <<
"Evaluated in " << (run_time / 1000.0) <<
" ms on average";
321 LOG_SF << speaker <<
": " << str.str();
333 const variant map = args()[0]->evaluate(variables, fdb);
339 const variant map = args()[0]->evaluate(variables, fdb);
345 const variant var = args()[0]->evaluate(variables, fdb);
347 std::vector<variant> tmp;
357 const variant var_1 = args()[0]->evaluate(variables, fdb);
359 std::map<variant, variant> tmp;
361 if(args().
size() == 2) {
362 const variant var_2 = args()[1]->evaluate(variables, fdb);
368 tmp[var_1[
i]] = var_2[
i];
373 tmp[kv->query_value(
"key")] = kv->query_value(
"value");
375 auto map_it = tmp.find(*it);
377 if(map_it == tmp.end()) {
380 map_it->second =
variant(map_it->second.as_int() + 1);
391 std::string result = args()[0]->evaluate(variables, fdb).as_string();
393 int offset = args()[1]->evaluate(variables, fdb).as_int();
395 offset += result.size();
401 if(
static_cast<std::size_t
>(offset) >= result.size()) {
406 if(args().
size() > 2) {
407 int size = args()[2]->evaluate(variables, fdb).as_int();
411 offset = std::max(0, offset -
size + 1);
417 return variant(result.substr(offset));
422 std::string result = args()[0]->evaluate(variables, fdb).as_string();
423 std::string replacement = args().back()->evaluate(variables, fdb).as_string();
425 int offset = args()[1]->evaluate(variables, fdb).as_int();
427 offset += result.size();
433 if(
static_cast<std::size_t
>(offset) >= result.size()) {
438 if(args().
size() > 3) {
439 int size = args()[2]->evaluate(variables, fdb).as_int();
443 offset = std::max(0, offset -
size + 1);
446 return variant(result.replace(offset,
size, replacement));
449 return variant(result.replace(offset, std::string::npos, replacement));
454 std::string result = args()[0]->evaluate(variables, fdb).as_string();
455 std::string needle = args()[1]->evaluate(variables, fdb).as_string();
456 std::string replacement = args().back()->evaluate(variables, fdb).as_string();
457 boost::replace_all(result, needle, replacement);
463 std::string str = args()[0]->evaluate(variables, fdb).as_string();
464 std::string prefix = args()[1]->evaluate(variables, fdb).as_string();
465 return variant(boost::starts_with(str, prefix));
470 std::string str = args()[0]->evaluate(variables, fdb).as_string();
471 std::string prefix = args()[1]->evaluate(variables, fdb).as_string();
472 return variant(boost::ends_with(str, prefix));
477 std::string result = args()[0]->evaluate(variables, fdb).as_string();
478 std::string
insert = args().back()->evaluate(variables, fdb).as_string();
480 int offset = args()[1]->evaluate(variables, fdb).as_int();
482 offset += result.size();
487 }
else if(
static_cast<std::size_t
>(offset) >= result.size()) {
496 return variant(args()[0]->evaluate(variables, fdb).as_string().length());
503 result += arg->evaluate(variables, fdb).string_cast();
511 std::string str = args()[0]->evaluate(variables, fdb).as_string();
512 std::transform(str.begin(), str.end(), str.begin(),
static_cast<int (*)(
int)
>(std::toupper));
518 std::string str = args()[0]->evaluate(variables, fdb).as_string();
519 std::transform(str.begin(), str.end(), str.begin(),
static_cast<int (*)(
int)
>(std::tolower));
525 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
526 const double result = std::sin(angle * pi<double>() / 180.0);
527 return variant(result, variant::DECIMAL_VARIANT);
532 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
533 const double result = std::cos(angle * pi<double>() / 180.0);
534 return variant(result, variant::DECIMAL_VARIANT);
539 const double angle = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
540 const double result = std::tan(angle * pi<double>() / 180.0);
541 if(std::isnan(result) || result <= std::numeric_limits<int>::min() || result >= std::numeric_limits<int>::max()) {
545 return variant(result, variant::DECIMAL_VARIANT);
550 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
551 const double result = std::asin(num) * 180.0 / pi<double>();
552 if(std::isnan(result)) {
556 return variant(result, variant::DECIMAL_VARIANT);
561 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
562 const double result = std::acos(num) * 180.0 / pi<double>();
563 if(std::isnan(result)) {
567 return variant(result, variant::DECIMAL_VARIANT);
572 if(args().
size() == 1) {
573 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
574 const double result = std::atan(num) * 180.0 / pi<double>();
575 return variant(result, variant::DECIMAL_VARIANT);
577 const double y = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
578 const double x = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
579 const double result = std::atan2(y, x) * 180.0 / pi<double>();
580 return variant(result, variant::DECIMAL_VARIANT);
586 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
587 const double result = std::sqrt(num);
588 if(std::isnan(result)) {
592 return variant(result, variant::DECIMAL_VARIANT);
597 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
598 const double result = num < 0 ? -std::pow(-num, 1.0 / 3.0) : std::pow(num, 1.0 / 3.0);
599 return variant(result, variant::DECIMAL_VARIANT);
604 const double base = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
605 const double root = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
606 const double result = base < 0 && std::fmod(root, 2) == 1 ? -std::pow(-base, 1.0 / root) : std::pow(base, 1.0 / root);
607 if(std::isnan(result)) {
611 return variant(result, variant::DECIMAL_VARIANT);
616 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
617 if(args().
size() == 1) {
618 const double result = std::log(num);
619 if(std::isnan(result)) {
623 return variant(result, variant::DECIMAL_VARIANT);
626 const double base = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
627 const double result = std::log(num) / std::log(base);
628 if(std::isnan(result)) {
632 return variant(result, variant::DECIMAL_VARIANT);
637 const double num = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
638 const double result = std::exp(num);
639 if(result == 0 || result >= std::numeric_limits<int>::max()) {
645 return variant(result, variant::DECIMAL_VARIANT);
650 return variant(pi<double>(), variant::DECIMAL_VARIANT);
655 const double x = args()[0]->evaluate(variables, fdb).as_decimal() / 1000.0;
656 const double y = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
657 return variant(std::hypot(x, y), variant::DECIMAL_VARIANT);
662 const variant value = args()[0]->evaluate(variables, fdb);
663 const variant list = args()[1]->evaluate(variables, fdb);
666 if(list[
i] == value) {
676 const variant items = args()[0]->evaluate(variables, fdb);
680 if(args().
size() == 2) {
691 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
694 self_callable.
add(
self, *it);
696 const variant val = args().back()->evaluate(
715 const int value = args()[0]->evaluate(variables, fdb).as_int() % 1000;
716 const double angle = 2.0 * pi<double>() * (
static_cast<double>(value) / 1000.0);
717 return variant(
static_cast<int>(std::sin(angle) * 1000.0));
722 const double lo = args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"lerp:lo")).as_decimal() / 1000.0;
723 const double hi = args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"lerp:hi")).as_decimal() / 1000.0;;
724 const double alpha = args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"lerp:alpha")).as_decimal() / 1000.0;;
725 return variant(
static_cast<int>((lo + alpha * (hi - lo)) * 1000.0), variant::DECIMAL_VARIANT);
730 const std::vector<variant> items = args()[0]->evaluate(variables, fdb).as_list();
731 if(items.empty())
return variant();
732 const double alpha = args()[1]->evaluate(variables, fdb).as_decimal() / 1000.0;
734 const double val_scaled = std::clamp(0.01 * alpha, 0.0, 1.0);
735 const int idx = int(std::nearbyint((items.size() - 1) * val_scaled));
741 const std::string name = args()[0]->evaluate(variables, fdb).as_string();
742 std::vector<color_t> colors;
743 if(name ==
"red_green_scale") {
745 }
else if(name ==
"red_green_scale_text") {
747 }
else if(name ==
"blue_white_scale") {
749 }
else if(name ==
"blue_white_scale_text") {
754 std::vector<variant> result;
755 result.reserve(colors.size());
756 for(
auto clr : colors) {
757 result.emplace_back(std::make_shared<color_callable>(clr));
786 bool operator()(
const variant& a,
const variant&
b)
const
790 return expr_->evaluate(*this).as_bool();
794 variant get_value(
const std::string& key)
const
798 }
else if(key ==
"b") {
818 variant list = args()[0]->evaluate(variables, fdb);
820 std::vector<variant> vars;
824 vars.push_back(list[
n]);
827 if(args().
size() == 1) {
828 std::sort(vars.begin(), vars.end());
830 std::sort(vars.begin(), vars.end(), variant_comparator(args()[1], variables));
838 const variant& arg = args()[0]->evaluate(variables, fdb);
841 std::string str = args()[0]->evaluate(variables, fdb).
as_string();
842 std::reverse(str.begin(), str.end());
846 std::vector<variant> list = args()[0]->evaluate(variables, fdb).as_list();
847 std::reverse(list.begin(), list.end());
857 std::string str = args()[0]->evaluate(variables, fdb).as_string();
858 std::string key = args()[1]->evaluate(variables, fdb).as_string();
860 return variant(str.find(key) != std::string::npos);
865 const std::string str = args()[0]->evaluate(variables, fdb).as_string();
866 const std::string key = args()[1]->evaluate(variables, fdb).as_string();
868 std::size_t pos = str.find(key);
869 return variant(
static_cast<int>(pos));
874 std::vector<variant> list_vars;
875 std::map<variant, variant> map_vars;
877 const variant items = args()[0]->evaluate(variables, fdb);
879 if(args().
size() == 2) {
885 map_vars[(*it).get_member(
"key")] = (*it).
get_member(
"value");
887 list_vars.push_back(*it);
893 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
896 self_callable.
add(
self, *it);
898 const variant val = args()[2]->evaluate(
903 map_vars[(*it).get_member(
"key")] = (*it).
get_member(
"value");
905 list_vars.push_back(*it);
920 const variant items = args()[0]->evaluate(variables, fdb);
922 if(args().
size() == 2) {
931 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
934 self_callable.
add(
self, *it);
936 const variant val = args().back()->evaluate(
950 std::vector<variant> list_vars;
951 std::map<variant, variant> map_vars;
952 const variant items = args()[0]->evaluate(variables, fdb);
954 if(args().
size() == 2) {
958 map_vars[(*it).get_member(
"key")] = val;
960 list_vars.push_back(val);
965 const std::string
self = args()[1]->evaluate(variables, fdb).as_string();
968 self_callable.
add(
self, *it);
970 const variant val = args().back()->evaluate(
974 map_vars[(*it).get_member(
"key")] = val;
976 list_vars.push_back(val);
990 const variant& items = args()[0]->evaluate(variables, fdb);
993 for(; it != items.
end(); ++it) {
1001 std::vector<variant> result(items.
begin(), it);
1009 explicit indexer(std::size_t
i)
1014 variant operator()(
const variant& v)
const
1016 if(
i >= v.num_elements()) {
1029 bool operator()(
const variant& a,
const variant&
b)
const
1031 return a.num_elements() <
b.num_elements();
1035 std::vector<variant> get_input(
1036 const function_expression::args_list& args,
1037 const formula_callable& variables,
1038 formula_debugger* fdb)
1040 if(args.size() == 1) {
1041 const variant list = args[0]->evaluate(variables, fdb);
1042 return std::vector<variant>(list.begin(), list.end());
1044 std::vector<variant> input;
1045 input.reserve(args.size());
1048 input.push_back(
expr->evaluate(variables, fdb));
1058 const std::vector<variant> input = get_input(args(), variables, fdb);
1059 std::vector<variant>
output;
1063 std::size_t max_i = std::max_element(input.begin(), input.end(), comparator())->num_elements();
1066 for(std::size_t
i = 0;
i < max_i;
i++) {
1067 std::vector<variant> elem(input.size());
1068 std::transform(input.begin(), input.end(), elem.begin(), indexer(
i));
1069 output.emplace_back(elem);
1077 const variant items = args()[0]->evaluate(variables, fdb);
1078 const variant initial = args().size() == 2 ?
variant() : args()[1]->evaluate(variables, fdb);
1086 if(res != initial) {
1091 for(; it != items.
end(); ++it) {
1092 self_callable.
add(
"a", res);
1093 self_callable.
add(
"b", *it);
1094 res = args().back()->evaluate(
1104 const variant items = args()[0]->evaluate(variables, fdb);
1106 if(items[0].is_list()) {
1107 std::vector<variant> tmp;
1109 if(args().
size() >= 2) {
1110 res = args()[1]->evaluate(variables, fdb);
1114 }
else if(items[0].
is_map()) {
1115 std::map<variant, variant> tmp;
1117 if(args().
size() >= 2) {
1118 res = args()[1]->evaluate(variables, fdb);
1123 if(args().
size() >= 2) {
1124 res = args()[1]->evaluate(variables, fdb);
1130 res = res + items[
n];
1138 const variant items = args()[0]->evaluate(variables, fdb);
1140 if(it == items.
end()) {
1144 if(args().
size() == 1) {
1148 const int n = items.
num_elements(), req = args()[1]->evaluate(variables, fdb).as_int();
1149 const int count = req < 0 ?
n - std::min(-req,
n) : std::min(req,
n);
1152 std::advance(end, count);
1154 std::vector<variant> res;
1155 std::copy(it, end, std::back_inserter(res));
1161 const variant items = args()[0]->evaluate(variables, fdb);
1163 if(it == items.
begin()) {
1167 if(args().
size() == 1) {
1171 const int n = items.
num_elements(), req = args()[1]->evaluate(variables, fdb).as_int();
1172 const int count = req < 0 ?
n - std::min(-req,
n) : std::min(req,
n);
1174 std::advance(it, -count);
1175 std::vector<variant> res;
1177 std::copy(it, items.
end(), std::back_inserter(res));
1183 const variant items = args()[0]->evaluate(variables, fdb);
1189 if(!args().empty()) {
1190 for(std::size_t
i = 0;
i < args().size(); ++
i) {
1191 args()[
i]->evaluate(variables, fdb);
1200 variant decimal = args()[0]->evaluate(variables, fdb);
1201 int d = decimal.as_decimal();
1203 if((
d >= 0) && (
d % 1000 != 0)) {
1214 variant decimal = args()[0]->evaluate(variables, fdb);
1215 int d = decimal.as_decimal();
1221 }
else if(
f <= -500) {
1232 variant decimal = args()[0]->evaluate(variables, fdb);
1233 int d = decimal.as_decimal();
1235 if((
d < 0) && (
d % 1000 != 0)) {
1246 variant decimal = args()[0]->evaluate(variables, fdb);
1247 int d = decimal.as_int();
1254 variant decimal = args()[0]->evaluate(variables, fdb);
1255 int d = decimal.as_decimal();
1258 return variant(
d, variant::DECIMAL_VARIANT);
1263 variant decimal = args()[0]->evaluate(variables, fdb);
1264 int d = decimal.as_decimal();
1275 variant decimal = args()[0]->evaluate(variables, fdb);
1276 int d = decimal.as_decimal();
1278 return variant(
d, variant::DECIMAL_VARIANT);
1284 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"loc:x")).as_int(),
1291 return variant(std::make_shared<key_value_pair>(
1292 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"pair:key")),
1293 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"pair_value"))
1300 ->evaluate(variables,
add_debug_info(fdb, 0,
"distance_between:location_A"))
1305 ->evaluate(variables,
add_debug_info(fdb, 1,
"distance_between:location_B"))
1315 ->evaluate(variables,
add_debug_info(fdb, 0,
"adjacent_locs:location"))
1319 std::vector<variant> v;
1321 v.emplace_back(std::make_shared<location_callable>(adj));
1331 int range = args()[1]->evaluate(variables, fdb).as_int();
1338 return variant(std::make_shared<location_callable>(loc));
1341 std::vector<map_location> res;
1345 std::vector<variant> v;
1346 v.reserve(res.size() + 1);
1347 v.emplace_back(std::make_shared<location_callable>(loc));
1349 for(std::size_t
n = 0;
n != res.size(); ++
n) {
1350 v.emplace_back(std::make_shared<location_callable>(res[
n]));
1359 ->evaluate(variables,
add_debug_info(fdb, 0,
"are_adjacent:location_A"))
1364 ->evaluate(variables,
add_debug_info(fdb, 1,
"are_adjacent:location_B"))
1374 ->evaluate(variables,
add_debug_info(fdb, 0,
"relative_dir:location_A"))
1379 ->evaluate(variables,
add_debug_info(fdb, 1,
"relative_dir:location_B"))
1389 ->evaluate(variables,
add_debug_info(fdb, 0,
"direction_from:location"))
1393 const std::string dir_str =
1394 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"direction_from:dir")).as_string();
1396 int n = args().size() == 3
1397 ? args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"direction_from:count")).as_int()
1406 ->evaluate(variables,
add_debug_info(fdb, 0,
"direction_from:center"))
1411 ->evaluate(variables,
add_debug_info(fdb, 1,
"direction_from:location"))
1415 int n = args().size() == 3
1416 ? args()[2]->evaluate(variables,
add_debug_info(fdb, 2,
"direction_from:count")).as_int()
1424 const variant& v = args()[0]->evaluate(variables, fdb);
1434 const variant main = args()[0]->evaluate(variables, fdb);
1437 return variant(std::make_shared<safe_call_callable>(
main, backup_formula));
1442 return variant(std::make_shared<set_var_callable>(
1443 args()[0]->evaluate(variables,
add_debug_info(fdb, 0,
"set_var:key")).as_string(),
1444 args()[1]->evaluate(variables,
add_debug_info(fdb, 1,
"set_var:value"))));
1449 variant key_value_pair::get_value(
const std::string& key)
const
1453 }
else if(key ==
"value") {
1462 add_input(inputs,
"key");
1463 add_input(inputs,
"value");
1466 void key_value_pair::serialize_to_string(std::string& str)
const
1469 str += key_.serialize_to_string();
1471 str += value_.serialize_to_string();
1475 formula_function_expression::formula_function_expression(
const std::string& name,
1479 const std::vector<std::string>& arg_names)
1482 , precondition_(precondition)
1483 , arg_names_(arg_names)
1497 static std::string
indent;
1502 const int begin_time = SDL_GetTicks();
1516 DBG_NG <<
"FAILED function precondition for function '" <<
formula_->str() <<
"' with arguments: ";
1519 DBG_NG <<
" arg " << (
n + 1) <<
": " <<
args()[
n]->evaluate(variables, fdb).to_debug_string();
1526 const int taken = SDL_GetTicks() - begin_time;
1535 const std::vector<expression_ptr>& args)
const
1541 : parent(parent ? parent : get_builtins())
1551 const std::string& fn,
const std::vector<expression_ptr>& args)
const
1555 return i->second->generate_function_expression(args);
1570 std::set<std::string> res;
1572 res =
parent->get_function_names();
1586 if(functions_table.
empty()) {
1587 functions_table.
parent =
nullptr;
1589 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