15 #include "formula/callable_objects.hpp" 28 #define LOG_SF LOG_STREAM(info, log_scripting_formula) 29 #define ERR_SF LOG_STREAM(err, log_scripting_formula) 38 }
else if(key ==
"y") {
54 if(loc_callable ==
nullptr) {
76 if(key ==
"id" || key ==
"name") {
78 }
else if(key ==
"description") {
80 }
else if(key ==
"type") {
82 }
else if(key ==
"icon") {
84 }
else if(key ==
"range") {
86 }
else if(key ==
"damage") {
88 }
else if(key ==
"number_of_attacks" || key ==
"number" || key ==
"num_attacks" || key ==
"attacks") {
90 }
else if(key ==
"attack_weight") {
92 }
else if(key ==
"defense_weight") {
94 }
else if(key ==
"accuracy") {
96 }
else if(key ==
"parry") {
98 }
else if(key ==
"movement_used") {
100 }
else if(key ==
"specials" || key ==
"special") {
101 std::vector<variant> res;
103 for(
const auto& special :
att_->specials().all_children_range()) {
104 if(!special.cfg[
"id"].empty()) {
105 res.emplace_back(special.cfg[
"id"].str());
134 if(att_callable ==
nullptr) {
138 if(
att_->damage() != att_callable->
att_->damage()) {
139 return att_->damage() - att_callable->
att_->damage();
142 if(
att_->num_attacks() != att_callable->
att_->num_attacks()) {
143 return att_->num_attacks() - att_callable->
att_->num_attacks();
146 if(
att_->id() != att_callable->
att_->id()) {
147 return att_->id().compare(att_callable->
att_->id());
150 if(
att_->type() != att_callable->
att_->type()) {
151 return att_->type().compare(att_callable->
att_->type());
154 if(
att_->range() != att_callable->
att_->range()) {
155 return att_->range().compare(att_callable->
att_->range());
158 return att_->weapon_specials().compare(att_callable->
att_->weapon_specials());
174 }
else if(key ==
"y") {
180 }
else if(key ==
"loc") {
185 return variant(std::make_shared<location_callable>(
loc_));
186 }
else if(key ==
"id") {
188 }
else if(key ==
"type") {
190 }
else if(key ==
"name") {
192 }
else if(key ==
"usage") {
194 }
else if(key ==
"leader" || key ==
"canrecruit") {
196 }
else if(key ==
"undead") {
198 }
else if(key ==
"attacks") {
199 std::vector<variant> res;
201 res.emplace_back(std::make_shared<attack_type_callable>(att));
205 }
else if(key ==
"abilities") {
207 }
else if(key ==
"hitpoints") {
209 }
else if(key ==
"max_hitpoints") {
211 }
else if(key ==
"experience") {
213 }
else if(key ==
"max_experience") {
215 }
else if(key ==
"level" || key ==
"full") {
218 }
else if(key ==
"total_movement" || key ==
"max_moves") {
220 }
else if(key ==
"movement_left" || key ==
"moves") {
222 }
else if(key ==
"attacks_left") {
224 }
else if(key ==
"max_attacks") {
226 }
else if(key ==
"traits") {
228 }
else if(key ==
"extra_recruit") {
230 }
else if(key ==
"advances_to") {
232 }
else if(key ==
"states" || key ==
"status") {
234 }
else if(key ==
"side") {
236 }
else if(key ==
"cost") {
238 }
else if(key ==
"upkeep") {
240 }
else if(key ==
"loyal") {
243 }
else if(key ==
"hidden") {
245 }
else if(key ==
"petrified") {
247 }
else if(key ==
"resting") {
249 }
else if(key ==
"role") {
251 }
else if(key ==
"race") {
253 }
else if(key ==
"gender") {
255 }
else if(key ==
"variation") {
257 }
else if(key ==
"zoc") {
259 }
else if(key ==
"alignment") {
261 }
else if(key ==
"facing") {
263 }
else if(key ==
"vars") {
269 }
else if(key ==
"wml_vars") {
271 }
else if(key ==
"n" || key ==
"s" || key ==
"ne" || key ==
"se" || key ==
"nw" || key ==
"sw" ||
272 key ==
"lawful" || key ==
"neutral" || key ==
"chaotic" || key ==
"liminal" ||
273 key ==
"male" || key ==
"female")
327 if(u_callable ==
nullptr) {
338 }
else if(key ==
"type") {
340 }
else if(key ==
"alignment") {
342 }
else if(key ==
"race") {
344 }
else if(key ==
"abilities") {
346 }
else if(key ==
"traits") {
347 std::vector<variant> res;
348 for(
const auto&
config :
u_.possible_traits()) {
349 res.emplace_back(
config[
"id"].str());
353 }
else if(key ==
"attacks") {
354 std::vector<variant> res;
356 res.emplace_back(std::make_shared<attack_type_callable>(att));
360 }
else if(key ==
"hitpoints" || key ==
"max_hitpoints") {
362 }
else if(key ==
"experience" || key ==
"max_experience") {
363 return variant(
u_.experience_needed(
true));
364 }
else if(key ==
"level") {
366 }
else if(key ==
"total_movement" || key ==
"max_moves" || key ==
"moves") {
368 }
else if(key ==
"unpoisonable") {
369 return variant(
u_.musthave_status(
"unpoisonable"));
370 }
else if(key ==
"undrainable") {
371 return variant(
u_.musthave_status(
"undrainable"));
372 }
else if(key ==
"unplagueable") {
373 return variant(
u_.musthave_status(
"unplagueable"));
374 }
else if(key ==
"cost") {
376 }
else if(key ==
"recall_cost") {
378 }
else if(key ==
"usage") {
407 if(u_callable ==
nullptr) {
411 return u_.
id().compare(u_callable->
u_.
id());
430 if(cfg_.has_attribute(key)) {
432 }
else if(cfg_.has_child(key)) {
433 std::vector<variant> result;
434 for(
const auto& child : cfg_.child_range(key)) {
435 result.emplace_back(std::make_shared<config_callable>(child));
439 }
else if(key ==
"__all_children") {
440 std::vector<variant> result;
441 for(
const auto& child : cfg_.all_children_range()) {
442 const variant cfg_child(std::make_shared<config_callable>(child.cfg));
443 const variant kv(std::make_shared<key_value_pair>(
variant(child.key), cfg_child));
444 result.push_back(kv);
448 }
else if(key ==
"__children") {
449 std::map<std::string, std::vector<variant>>
build;
450 for(
const auto& child : cfg_.all_children_range()) {
451 const variant cfg_child(std::make_shared<config_callable>(child.cfg));
452 build[child.key].push_back(cfg_child);
455 std::map<variant,variant> result;
456 for(
auto&
p : build) {
461 }
else if(key ==
"__attributes") {
462 std::map<variant,variant> result;
463 for(
const auto& val : cfg_.attribute_range()) {
479 for(
const auto& val : cfg_.attribute_range()) {
489 if(cfg_callable ==
nullptr) {
509 }
else if(key ==
"y") {
511 }
else if(key ==
"loc") {
512 return variant(std::make_shared<location_callable>(
loc_));
513 }
else if(key ==
"id") {
515 }
else if(key ==
"name") {
517 }
else if(key ==
"editor_name") {
519 }
else if(key ==
"description") {
521 }
else if(key ==
"icon") {
523 }
else if(key ==
"light") {
525 }
else if(key ==
"village") {
527 }
else if(key ==
"castle") {
529 }
else if(key ==
"keep") {
531 }
else if(key ==
"healing") {
533 }
else if(key ==
"owner") {
561 if(terr_callable ==
nullptr) {
583 if(key ==
"terrain") {
584 int w = get_gamemap().w();
585 int h = get_gamemap().h();
587 std::vector<variant> vars;
588 for(
int i = 0;
i <
w;
i++) {
589 for(
int j = 0; j <
h; j++) {
591 vars.emplace_back(std::make_shared<terrain_callable>(board_, loc));
596 }
else if(key ==
"w") {
598 }
else if(key ==
"h") {
631 add_input(inputs,
"carryover_percentage");
641 }
else if(key ==
"id") {
642 return variant(team_.save_id());
643 }
else if(key ==
"save_id") {
644 return variant(team_.save_id());
645 }
else if(key ==
"gold") {
647 }
else if(key ==
"start_gold") {
648 return variant(team_.start_gold());
649 }
else if(key ==
"base_income") {
650 return variant(team_.base_income());
651 }
else if(key ==
"total_income") {
652 return variant(team_.total_income());
653 }
else if(key ==
"village_gold") {
654 return variant(team_.village_gold());
655 }
else if(key ==
"village_support") {
656 return variant(team_.village_support());
657 }
else if(key ==
"recall_cost") {
658 return variant(team_.recall_cost());
659 }
else if(key ==
"is_human") {
660 return variant(team_.is_local_human());
661 }
else if(key ==
"is_ai") {
662 return variant(team_.is_local_ai());
663 }
else if(key ==
"is_network") {
664 return variant(team_.is_network());
665 }
else if(key ==
"fog") {
666 return variant(team_.uses_fog());
667 }
else if(key ==
"shroud") {
668 return variant(team_.uses_shroud());
669 }
else if(key ==
"hidden") {
670 return variant(team_.hidden());
671 }
else if(key ==
"flag") {
673 }
else if(key ==
"flag_icon") {
674 return variant(team_.flag_icon());
675 }
else if(key ==
"team_name") {
676 return variant(team_.team_name());
677 }
else if(key ==
"color") {
679 }
else if(key ==
"share_vision") {
680 return variant(team_.share_vision().to_string());
681 }
else if(key ==
"carryover_bonus") {
682 return variant(team_.carryover_bonus());
683 }
else if(key ==
"carryover_percentage") {
684 return variant(team_.carryover_percentage());
685 }
else if(key ==
"carryover_add") {
686 return variant(team_.carryover_add());
687 }
else if(key ==
"recruit") {
688 std::vector<variant> result;
689 for(
const auto& recruit : team_.recruits()) {
690 result.emplace_back(recruit);
694 }
else if(key ==
"wml_vars") {
695 return variant(std::make_shared<config_callable>(team_.variables()));
705 }
else if(key ==
"value") {
722 LOG_SF <<
"Setting variable: " << key_ <<
" -> " << value_.to_debug_string() <<
"\n";
723 obj->mutate_value(key_, value_);
728 ERR_SF <<
"ERROR #" << 5001 <<
" while executing 'set_var' formula function" << std::endl;
737 }
else if(key ==
"backup") {
754 res = action->execute_self(ctxt);
764 callable.
add(
"error", res);
769 backup_ = get_backup()->evaluate(callable);
777 if(key ==
"status") {
779 }
else if(key ==
"object") {
780 if(failed_callable_) {
781 return variant(failed_callable_);
785 }
else if(key ==
"current_loc" && current_unit_location_ !=
map_location()) {
786 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.
variant operator()(boost::blank) const
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.
variant get_value(const std::string &key) const override
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.
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 directin this unit is facing within its hex.
void get_inputs(formula_input_vector &inputs) const override
const std::string & type_id() const
The id of this unit's type.
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).
unit_type::ALIGNMENT alignment() const
The alignment of this unit.
int cost() const
How much gold is required to recruit this unit.
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
window * build(const builder_window::window_resolution *definition)
Builds a window.
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)
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.
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::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.
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