15 #include "formula/callable_objects.hpp" 29 #define LOG_SF LOG_STREAM(info, log_scripting_formula) 30 #define ERR_SF LOG_STREAM(err, log_scripting_formula) 39 }
else if(key ==
"y") {
55 if(loc_callable ==
nullptr) {
77 if(key ==
"id" || key ==
"name") {
79 }
else if(key ==
"description") {
81 }
else if(key ==
"type") {
83 }
else if(key ==
"icon") {
85 }
else if(key ==
"range") {
87 }
else if(key ==
"damage") {
89 }
else if(key ==
"number_of_attacks" || key ==
"number" || key ==
"num_attacks" || key ==
"attacks") {
91 }
else if(key ==
"attack_weight") {
93 }
else if(key ==
"defense_weight") {
95 }
else if(key ==
"accuracy") {
97 }
else if(key ==
"parry") {
99 }
else if(key ==
"movement_used") {
101 }
else if(key ==
"specials" || key ==
"special") {
102 std::vector<variant> res;
104 for(
const auto& special :
att_->specials().all_children_range()) {
105 if(!special.cfg[
"id"].empty()) {
106 res.emplace_back(special.cfg[
"id"].str());
135 if(att_callable ==
nullptr) {
139 if(
att_->damage() != att_callable->
att_->damage()) {
140 return att_->damage() - att_callable->
att_->damage();
143 if(
att_->num_attacks() != att_callable->
att_->num_attacks()) {
144 return att_->num_attacks() - att_callable->
att_->num_attacks();
147 if(
att_->id() != att_callable->
att_->id()) {
148 return att_->id().compare(att_callable->
att_->id());
151 if(
att_->type() != att_callable->
att_->type()) {
152 return att_->type().compare(att_callable->
att_->type());
155 if(
att_->range() != att_callable->
att_->range()) {
156 return att_->range().compare(att_callable->
att_->range());
159 return att_->weapon_specials().compare(att_callable->
att_->weapon_specials());
175 }
else if(key ==
"y") {
181 }
else if(key ==
"loc") {
186 return variant(std::make_shared<location_callable>(
loc_));
187 }
else if(key ==
"id") {
189 }
else if(key ==
"type") {
191 }
else if(key ==
"name") {
193 }
else if(key ==
"usage") {
195 }
else if(key ==
"leader" || key ==
"canrecruit") {
197 }
else if(key ==
"undead") {
199 }
else if(key ==
"attacks") {
200 std::vector<variant> res;
202 res.emplace_back(std::make_shared<attack_type_callable>(att));
206 }
else if(key ==
"abilities") {
208 }
else if(key ==
"hitpoints") {
210 }
else if(key ==
"max_hitpoints") {
212 }
else if(key ==
"experience") {
214 }
else if(key ==
"max_experience") {
216 }
else if(key ==
"level" || key ==
"full") {
219 }
else if(key ==
"total_movement" || key ==
"max_moves") {
221 }
else if(key ==
"movement_left" || key ==
"moves") {
223 }
else if(key ==
"attacks_left") {
225 }
else if(key ==
"max_attacks") {
227 }
else if(key ==
"traits") {
229 }
else if(key ==
"extra_recruit") {
231 }
else if(key ==
"advances_to") {
233 }
else if(key ==
"states" || key ==
"status") {
235 }
else if(key ==
"side") {
237 }
else if(key ==
"cost") {
239 }
else if(key ==
"upkeep") {
241 }
else if(key ==
"loyal") {
244 }
else if(key ==
"hidden") {
246 }
else if(key ==
"petrified") {
248 }
else if(key ==
"resting") {
250 }
else if(key ==
"role") {
252 }
else if(key ==
"race") {
254 }
else if(key ==
"gender") {
256 }
else if(key ==
"variation") {
258 }
else if(key ==
"zoc") {
260 }
else if(key ==
"alignment") {
262 }
else if(key ==
"facing") {
264 }
else if(key ==
"resistance" || key ==
"movement_cost" || key ==
"vision_cost" || key ==
"jamming_cost" || key ==
"defense") {
267 bool needs_flip =
false;
268 if(key ==
"resistance") {
269 mt.get_resistances().write(cfg);
271 }
else if(key ==
"movement_cost") {
272 mt.get_movement().write(cfg);
273 }
else if(key ==
"vision_cost") {
274 mt.get_vision().write(cfg);
275 }
else if(key ==
"jamming_cost") {
276 mt.get_vision().write(cfg);
277 }
else if(key ==
"defense") {
278 mt.get_defense().write(cfg);
281 std::map<variant, variant> res;
291 }
else if(key ==
"flying") {
293 }
else if(key ==
"vars") {
299 }
else if(key ==
"wml_vars") {
301 }
else if(key ==
"n" || key ==
"s" || key ==
"ne" || key ==
"se" || key ==
"nw" || key ==
"sw" ||
302 key ==
"lawful" || key ==
"neutral" || key ==
"chaotic" || key ==
"liminal" ||
303 key ==
"male" || key ==
"female")
363 if(u_callable ==
nullptr) {
374 }
else if(key ==
"type") {
376 }
else if(key ==
"alignment") {
378 }
else if(key ==
"race") {
380 }
else if(key ==
"abilities") {
382 }
else if(key ==
"traits") {
383 std::vector<variant> res;
384 for(
const auto&
config :
u_.possible_traits()) {
385 res.emplace_back(
config[
"id"].str());
389 }
else if(key ==
"attacks") {
390 std::vector<variant> res;
392 res.emplace_back(std::make_shared<attack_type_callable>(att));
396 }
else if(key ==
"hitpoints" || key ==
"max_hitpoints") {
398 }
else if(key ==
"experience" || key ==
"max_experience") {
399 return variant(
u_.experience_needed(
true));
400 }
else if(key ==
"level") {
402 }
else if(key ==
"total_movement" || key ==
"max_moves" || key ==
"moves") {
404 }
else if(key ==
"unpoisonable") {
405 return variant(
u_.musthave_status(
"unpoisonable"));
406 }
else if(key ==
"undrainable") {
407 return variant(
u_.musthave_status(
"undrainable"));
408 }
else if(key ==
"unplagueable") {
409 return variant(
u_.musthave_status(
"unplagueable"));
410 }
else if(key ==
"cost") {
412 }
else if(key ==
"recall_cost") {
414 }
else if(key ==
"usage") {
443 if(u_callable ==
nullptr) {
447 return u_.
id().compare(u_callable->
u_.
id());
451 #ifdef USING_BOOST_VARIANT
452 :
public boost::static_visitor<variant>
469 if(cfg_.has_attribute(key)) {
471 }
else if(cfg_.has_child(key)) {
472 std::vector<variant> result;
473 for(
const auto& child : cfg_.child_range(key)) {
474 result.emplace_back(std::make_shared<config_callable>(child));
478 }
else if(key ==
"__all_children") {
479 std::vector<variant> result;
480 for(
const auto& child : cfg_.all_children_range()) {
481 const variant cfg_child(std::make_shared<config_callable>(child.cfg));
482 const variant kv(std::make_shared<key_value_pair>(
variant(child.key), cfg_child));
483 result.push_back(kv);
487 }
else if(key ==
"__children") {
488 std::map<std::string, std::vector<variant>>
build;
489 for(
const auto& child : cfg_.all_children_range()) {
490 const variant cfg_child(std::make_shared<config_callable>(child.cfg));
491 build[child.key].push_back(cfg_child);
494 std::map<variant,variant> result;
495 for(
auto&
p : build) {
500 }
else if(key ==
"__attributes") {
501 std::map<variant,variant> result;
502 for(
const auto& val : cfg_.attribute_range()) {
518 for(
const auto& val : cfg_.attribute_range()) {
528 if(cfg_callable ==
nullptr) {
548 }
else if(key ==
"y") {
550 }
else if(key ==
"loc") {
551 return variant(std::make_shared<location_callable>(
loc_));
552 }
else if(key ==
"id") {
554 }
else if(key ==
"name") {
556 }
else if(key ==
"editor_name") {
558 }
else if(key ==
"description") {
560 }
else if(key ==
"icon") {
562 }
else if(key ==
"light") {
564 }
else if(key ==
"village") {
566 }
else if(key ==
"castle") {
568 }
else if(key ==
"keep") {
570 }
else if(key ==
"healing") {
572 }
else if(key ==
"owner") {
600 if(terr_callable ==
nullptr) {
620 if(key ==
"terrain") {
621 int w = get_gamemap().w();
622 int h = get_gamemap().h();
624 std::vector<variant> vars;
625 for(
int i = 0;
i <
w;
i++) {
626 for(
int j = 0; j <
h; j++) {
628 vars.emplace_back(std::make_shared<terrain_callable>(board_, loc));
633 }
else if(key ==
"gamemap") {
634 int w = get_gamemap().w();
635 int h = get_gamemap().h();
637 std::map<variant, variant> vars;
638 for(
int i = 0;
i <
w;
i++) {
639 for(
int j = 0; j <
h; j++) {
641 vars.emplace(std::make_shared<location_callable>(loc), std::make_shared<terrain_callable>(board_, loc));
646 }
else if(key ==
"w") {
648 }
else if(key ==
"h") {
681 add_input(inputs,
"carryover_percentage");
691 }
else if(key ==
"id") {
692 return variant(team_.save_id());
693 }
else if(key ==
"save_id") {
694 return variant(team_.save_id());
695 }
else if(key ==
"gold") {
697 }
else if(key ==
"start_gold") {
698 return variant(team_.start_gold());
699 }
else if(key ==
"base_income") {
700 return variant(team_.base_income());
701 }
else if(key ==
"total_income") {
702 return variant(team_.total_income());
703 }
else if(key ==
"village_gold") {
704 return variant(team_.village_gold());
705 }
else if(key ==
"village_support") {
706 return variant(team_.village_support());
707 }
else if(key ==
"recall_cost") {
708 return variant(team_.recall_cost());
709 }
else if(key ==
"is_human") {
710 return variant(team_.is_local_human());
711 }
else if(key ==
"is_ai") {
712 return variant(team_.is_local_ai());
713 }
else if(key ==
"is_network") {
714 return variant(team_.is_network());
715 }
else if(key ==
"fog") {
716 return variant(team_.uses_fog());
717 }
else if(key ==
"shroud") {
718 return variant(team_.uses_shroud());
719 }
else if(key ==
"hidden") {
720 return variant(team_.hidden());
721 }
else if(key ==
"flag") {
723 }
else if(key ==
"flag_icon") {
724 return variant(team_.flag_icon());
725 }
else if(key ==
"team_name") {
726 return variant(team_.team_name());
727 }
else if(key ==
"color") {
729 }
else if(key ==
"share_vision") {
730 return variant(team_.share_vision().to_string());
731 }
else if(key ==
"carryover_bonus") {
733 }
else if(key ==
"carryover_percentage") {
734 return variant(team_.carryover_percentage());
735 }
else if(key ==
"carryover_add") {
736 return variant(team_.carryover_add());
737 }
else if(key ==
"recruit") {
738 std::vector<variant> result;
739 for(
const auto& recruit : team_.recruits()) {
740 result.emplace_back(recruit);
744 }
else if(key ==
"wml_vars") {
745 return variant(std::make_shared<config_callable>(team_.variables()));
755 }
else if(key ==
"value") {
772 LOG_SF <<
"Setting variable: " << key_ <<
" -> " << value_.to_debug_string() <<
"\n";
773 obj->mutate_value(key_, value_);
778 ERR_SF <<
"ERROR #" << 5001 <<
" while executing 'set_var' formula function" << std::endl;
787 }
else if(key ==
"backup") {
804 res = action->execute_self(ctxt);
814 callable.
add(
"error", res);
819 backup_ = get_backup()->evaluate(callable);
827 if(key ==
"status") {
829 }
else if(key ==
"object") {
830 if(failed_callable_) {
831 return variant(failed_callable_);
835 }
else if(key ==
"current_loc" && current_unit_location_ !=
map_location()) {
836 return variant(std::make_shared<location_callable>(current_unit_location_));
const map_location & loc() const
variant execute_variant(const variant &to_exec)
variant get_value(const std::string &key) const override
int attacks_left() const
Gets the remaining number of attacks this unit can perform this turn.
void get_inputs(formula_input_vector &inputs) const override
const t_string & description() const
void get_inputs(formula_input_vector &inputs) const override
This class represents a single unit of a specific type.
const std::string & type_id() const
The id of this unit's type.
variant get_value(const std::string &key) const override
bool is_flying() const
Check if the unit is a flying unit.
const std::string & id() const
bool get_state(const std::string &state) const
Check if the unit is affected by a status effect.
variant get_value(const std::string &key) const override
unit_race::GENDER gender() const
The gender of this unit.
const movetype & movement_type() const
Get the unit's movement type.
int hitpoints() const
The current number of hitpoints this unit has.
config & variables()
Gets any user-defined variables this unit 'owns'.
int do_compare(const map_location &a) const
three-way comparator
const std::string & variation() const
The ID of the variation of this unit's type.
std::vector< formula_input > formula_input_vector
map_location::DIRECTION facing() const
The current direction this unit is facing within its hex.
void get_inputs(formula_input_vector &inputs) const override
void get_inputs(formula_input_vector &inputs) const override
bool resting() const
Checks whether this unit is 'resting'.
void get_inputs(formula_input_vector &inputs) const override
bool get_emit_zoc() const
Gets the raw zone-of-control flag, disregarding incapacitated.
bool get_hidden() const
Gets whether this unit is currently hidden on the map.
Definitions for the interface to Wesnoth Markup Language (WML).
int cost() const
How much gold is required to recruit this unit.
const_attr_itors attribute_range() const
variant operator()(const t_string &s) const
variant operator()(int i) const
variant get_value(const std::string &key) const override
int light_bonus(int base) const
Returns the light (lawful) bonus for this terrain when the time of day gives a base bonus...
void get_inputs(formula_input_vector &inputs) const override
variant execute_self(variant ctxt) override
const t_string & editor_name() const
const std::string & id() const
Gets this unit's id.
int do_compare(const formula_callable *callable) const override
const config & get_config() const
attack_type_callable(const attack_type &attack)
int do_compare(const formula_callable *callable) const override
Encapsulates the map of the game.
int do_compare(const formula_callable *callable) const override
const t_string & name() const
Gets this unit's translatable display name.
int upkeep() const
Gets the amount of gold this unit costs a side per turn.
int max_experience() const
The max number of experience points this unit can have.
int level() const
The current level of this unit.
const std::string & id() const
The id for this unit_type.
void serialize_to_string(std::string &str) const override
const t_string & type_name() const
Gets the translatable name of this unit's type.
int gives_healing() const
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
const map_location & loc_
variant get_value(const std::string &key) const override
const std::string & gender_string(unit_race::GENDER gender)
void get_inputs(formula_input_vector &inputs) const override
Encapsulates the map of the game.
const_formula_callable_ptr as_callable() const
const gamemap & get_gamemap() const
variant operator()(bool b) const
int max_hitpoints() const
The max number of hitpoints this unit can have.
const std::string & get_role() const
Gets this unit's role.
variant operator()(double i) const
static std::string get_location(const std::string &loc)
int do_compare(const formula_callable *callable) const override
static map_location::DIRECTION s
void get_inputs(formula_input_vector &inputs) const override
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
variant operator()(const std::string &s) const
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
std::string usage() const
Gets this unit's usage.
variant get_value(const std::string &key) const override
attack_itors attacks()
Gets an iterator over this unit's attacks.
unit_callable(const map_location &loc, const unit &u)
variant operator()(utils::monostate) const
std::vector< std::string > get_traits_list() const
Gets a list of the traits this unit currently has.
const unit_race * race() const
Gets this unit's race.
variant get_value(const std::string &key) const override
const t_string & name() const
const std::vector< std::string > & recruits() const
The type IDs of the other units this unit may recruit, if possible.
unit_formula_manager & formula_manager() const
Get the unit formula manager.
std::shared_ptr< T > try_convert() const
int experience() const
The current number of experience points this unit has.
UNIT_ALIGNMENT alignment() const
The alignment of this unit.
int do_compare(const formula_callable *callable) const override
variant get_value(const std::string &key) const override
Standard logging facilities (interface).
const std::string & id() const
variant execute_self(variant ctxt) override
static const map_location & null_location()
bool incapacitated() const
Check if the unit has been petrified.
int total_movement() const
The maximum moves this unit has.
terrain_callable(const display_context &m, const map_location &loc)
int side() const
The side this unit belongs to.
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
void get_inputs(formula_input_vector &inputs) const override
int do_compare(const formula_callable *callable) const override
variant get_value(const std::string &key) const override
A config object defines a single node in a WML file, with access to child nodes.
const std::string & str() const
const std::set< std::string > get_states() const
Get the status effects currently affecting the unit.
const advances_to_t & advances_to() const
Gets the possible types this unit can advance to on level-up.
int recall_cost() const
How much gold it costs to recall this unit, or -1 if the side's default recall cost is used...
static std::string write_direction(DIRECTION dir)
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
std::size_t underlying_id() const
This unit's unique internal ID.
variant operator()(unsigned long long i) const
int max_attacks() const
The maximum number of attacks this unit may perform per turn, usually 1.
const std::string & icon_image() const