16 #include "formula/callable_objects.hpp" 35 #define LOG_SF LOG_STREAM(info, log_scripting_formula) 36 #define ERR_SF LOG_STREAM(err, log_scripting_formula) 45 }
else if(key ==
"y") {
61 if(loc_callable ==
nullptr) {
83 if(key ==
"id" || key ==
"name") {
85 }
else if(key ==
"description") {
87 }
else if(key ==
"type") {
89 }
else if(key ==
"icon") {
91 }
else if(key ==
"range") {
93 }
else if(key ==
"damage") {
95 }
else if(key ==
"number_of_attacks" || key ==
"number" || key ==
"num_attacks" || key ==
"attacks") {
97 }
else if(key ==
"attack_weight") {
99 }
else if(key ==
"defense_weight") {
101 }
else if(key ==
"accuracy") {
103 }
else if(key ==
"parry") {
105 }
else if(key ==
"movement_used") {
107 }
else if(key ==
"specials" || key ==
"special") {
108 std::vector<variant> res;
110 for(
const auto special :
att_->specials().all_children_range()) {
111 if(!special.cfg[
"id"].empty()) {
112 res.emplace_back(special.cfg[
"id"].str());
141 if(att_callable ==
nullptr) {
145 if(
att_->damage() != att_callable->
att_->damage()) {
146 return att_->damage() - att_callable->
att_->damage();
149 if(
att_->num_attacks() != att_callable->
att_->num_attacks()) {
150 return att_->num_attacks() - att_callable->
att_->num_attacks();
153 if(
att_->id() != att_callable->
att_->id()) {
154 return att_->id().compare(att_callable->
att_->id());
157 if(
att_->type() != att_callable->
att_->type()) {
158 return att_->type().compare(att_callable->
att_->type());
161 if(
att_->range() != att_callable->
att_->range()) {
162 return att_->range().compare(att_callable->
att_->range());
165 const auto self_specials =
att_->specials().all_children_range();
166 const auto other_specials = att_callable->
att_->specials().all_children_range();
167 if(self_specials.size() != other_specials.size()) {
168 return self_specials.size() < other_specials.size() ? -1 : 1;
170 for(std::size_t
i = 0;
i < self_specials.size(); ++
i) {
171 const auto&
s = self_specials[
i].cfg[
"id"];
172 const auto& o = other_specials[
i].cfg[
"id"];
174 return s.str().compare(o.str());
194 }
else if(key ==
"y") {
200 }
else if(key ==
"loc") {
205 return variant(std::make_shared<location_callable>(
loc_));
206 }
else if(key ==
"terrain") {
211 }
else if(key ==
"id") {
213 }
else if(key ==
"type") {
215 }
else if(key ==
"name") {
217 }
else if(key ==
"usage") {
219 }
else if(key ==
"leader" || key ==
"canrecruit") {
221 }
else if(key ==
"undead") {
223 }
else if(key ==
"attacks") {
224 std::vector<variant> res;
226 res.emplace_back(std::make_shared<attack_type_callable>(att));
230 }
else if(key ==
"abilities") {
232 }
else if(key ==
"hitpoints") {
234 }
else if(key ==
"max_hitpoints") {
236 }
else if(key ==
"experience") {
238 }
else if(key ==
"max_experience") {
240 }
else if(key ==
"level" || key ==
"full") {
243 }
else if(key ==
"total_movement" || key ==
"max_moves") {
245 }
else if(key ==
"movement_left" || key ==
"moves") {
247 }
else if(key ==
"attacks_left") {
249 }
else if(key ==
"max_attacks") {
251 }
else if(key ==
"traits") {
253 }
else if(key ==
"extra_recruit") {
255 }
else if(key ==
"advances_to") {
257 }
else if(key ==
"states" || key ==
"status") {
259 }
else if(key ==
"side") {
262 }
else if(key ==
"side_number") {
264 }
else if(key ==
"cost") {
266 }
else if(key ==
"upkeep") {
268 }
else if(key ==
"loyal") {
271 }
else if(key ==
"hidden") {
273 }
else if(key ==
"petrified") {
275 }
else if(key ==
"resting") {
277 }
else if(key ==
"role") {
279 }
else if(key ==
"race") {
281 }
else if(key ==
"gender") {
283 }
else if(key ==
"variation") {
285 }
else if(key ==
"zoc") {
287 }
else if(key ==
"alignment") {
289 }
else if(key ==
"facing") {
291 }
else if(key ==
"resistance" || key ==
"movement_cost" || key ==
"vision_cost" || key ==
"jamming_cost" || key ==
"defense") {
294 bool needs_flip =
false;
295 if(key ==
"resistance") {
296 mt.get_resistances().write(cfg);
298 }
else if(key ==
"movement_cost") {
299 mt.get_movement().write(cfg);
300 }
else if(key ==
"vision_cost") {
301 mt.get_vision().write(cfg);
302 }
else if(key ==
"jamming_cost") {
303 mt.get_vision().write(cfg);
304 }
else if(key ==
"defense") {
305 mt.get_defense().write(cfg);
308 std::map<variant, variant> res;
318 }
else if(key ==
"flying") {
320 }
else if(key ==
"vars") {
326 }
else if(key ==
"wml_vars") {
328 }
else if(key ==
"n" || key ==
"s" || key ==
"ne" || key ==
"se" || key ==
"nw" || key ==
"sw" ||
329 key ==
"lawful" || key ==
"neutral" || key ==
"chaotic" || key ==
"liminal" ||
330 key ==
"male" || key ==
"female")
391 if(u_callable ==
nullptr) {
402 }
else if(key ==
"type") {
404 }
else if(key ==
"alignment") {
406 }
else if(key ==
"race") {
408 }
else if(key ==
"abilities") {
410 }
else if(key ==
"traits") {
411 std::vector<variant> res;
412 for(
const auto&
config :
u_.possible_traits()) {
413 res.emplace_back(
config[
"id"].str());
417 }
else if(key ==
"attacks") {
418 std::vector<variant> res;
420 res.emplace_back(std::make_shared<attack_type_callable>(att));
424 }
else if(key ==
"hitpoints" || key ==
"max_hitpoints") {
426 }
else if(key ==
"experience" || key ==
"max_experience") {
427 return variant(
u_.experience_needed(
true));
428 }
else if(key ==
"level") {
430 }
else if(key ==
"total_movement" || key ==
"max_moves" || key ==
"moves") {
432 }
else if(key ==
"unpoisonable") {
433 return variant(
u_.musthave_status(
"unpoisonable"));
434 }
else if(key ==
"unslowable") {
435 return variant(
u_.musthave_status(
"unslowable"));
436 }
else if(key ==
"unpetrifiable") {
437 return variant(
u_.musthave_status(
"unpetrifiable"));
438 }
else if(key ==
"undrainable") {
439 return variant(
u_.musthave_status(
"undrainable"));
440 }
else if(key ==
"unplagueable") {
441 return variant(
u_.musthave_status(
"unplagueable"));
442 }
else if(key ==
"cost") {
444 }
else if(key ==
"recall_cost") {
446 }
else if(key ==
"usage") {
475 if(u_callable ==
nullptr) {
479 return u_.
id().compare(u_callable->
u_.
id());
483 #ifdef USING_BOOST_VARIANT
484 :
public boost::static_visitor<variant>
501 if(cfg_.has_attribute(key)) {
503 }
else if(cfg_.has_child(key)) {
504 std::vector<variant> result;
505 for(
const auto& child : cfg_.child_range(key)) {
506 result.emplace_back(std::make_shared<config_callable>(child));
510 }
else if(key ==
"__all_children") {
511 std::vector<variant> result;
512 for(
const auto child : cfg_.all_children_range()) {
513 const variant cfg_child(std::make_shared<config_callable>(child.cfg));
514 const variant kv(std::make_shared<key_value_pair>(
variant(child.key), cfg_child));
515 result.push_back(kv);
519 }
else if(key ==
"__children") {
520 std::map<std::string, std::vector<variant>>
build;
521 for(
const auto child : cfg_.all_children_range()) {
522 const variant cfg_child(std::make_shared<config_callable>(child.cfg));
523 build[child.key].push_back(cfg_child);
526 std::map<variant,variant> result;
527 for(
auto&
p : build) {
532 }
else if(key ==
"__attributes") {
533 std::map<variant,variant> result;
534 for(
const auto& val : cfg_.attribute_range()) {
550 for(
const auto& val : cfg_.attribute_range()) {
560 if(cfg_callable ==
nullptr) {
580 }
else if(key ==
"y") {
582 }
else if(key ==
"loc") {
583 return variant(std::make_shared<location_callable>(
loc_));
584 }
else if(key ==
"id") {
586 }
else if(key ==
"name") {
588 }
else if(key ==
"editor_name") {
590 }
else if(key ==
"description") {
592 }
else if(key ==
"icon") {
594 }
else if(key ==
"light") {
596 }
else if(key ==
"village") {
598 }
else if(key ==
"castle") {
600 }
else if(key ==
"keep") {
602 }
else if(key ==
"healing") {
604 }
else if(key ==
"owner") {
607 }
else if(key ==
"owner_side") {
635 if(terr_callable ==
nullptr) {
655 if(key ==
"terrain") {
656 int w = get_gamemap().w();
657 int h = get_gamemap().h();
659 std::vector<variant> vars;
660 for(
int i = 0;
i <
w;
i++) {
661 for(
int j = 0; j <
h; j++) {
663 vars.emplace_back(std::make_shared<terrain_callable>(board_, loc));
668 }
else if(key ==
"gamemap") {
669 int w = get_gamemap().w();
670 int h = get_gamemap().h();
672 std::map<variant, variant> vars;
673 for(
int i = 0;
i <
w;
i++) {
674 for(
int j = 0; j <
h; j++) {
676 vars.emplace(std::make_shared<location_callable>(loc), std::make_shared<terrain_callable>(board_, loc));
681 }
else if(key ==
"w") {
683 }
else if(key ==
"h") {
716 add_input(inputs,
"carryover_percentage");
727 }
else if(key ==
"side_number") {
729 }
else if(key ==
"id") {
730 return variant(team_.save_id());
731 }
else if(key ==
"save_id") {
732 return variant(team_.save_id());
733 }
else if(key ==
"gold") {
735 }
else if(key ==
"start_gold") {
736 return variant(team_.start_gold());
737 }
else if(key ==
"base_income") {
738 return variant(team_.base_income());
739 }
else if(key ==
"total_income") {
740 return variant(team_.total_income());
741 }
else if(key ==
"village_gold") {
742 return variant(team_.village_gold());
743 }
else if(key ==
"village_support") {
744 return variant(team_.village_support());
745 }
else if(key ==
"recall_cost") {
746 return variant(team_.recall_cost());
747 }
else if(key ==
"is_human") {
748 return variant(team_.is_local_human());
749 }
else if(key ==
"is_ai") {
750 return variant(team_.is_local_ai());
751 }
else if(key ==
"is_network") {
752 return variant(team_.is_network());
753 }
else if(key ==
"fog") {
754 return variant(team_.uses_fog());
755 }
else if(key ==
"shroud") {
756 return variant(team_.uses_shroud());
757 }
else if(key ==
"hidden") {
758 return variant(team_.hidden());
759 }
else if(key ==
"flag") {
761 }
else if(key ==
"flag_icon") {
762 return variant(team_.flag_icon());
763 }
else if(key ==
"team_name") {
764 return variant(team_.team_name());
765 }
else if(key ==
"color") {
767 }
else if(key ==
"share_vision") {
769 }
else if(key ==
"carryover_bonus") {
771 }
else if(key ==
"carryover_percentage") {
772 return variant(team_.carryover_percentage());
773 }
else if(key ==
"carryover_add") {
774 return variant(team_.carryover_add());
775 }
else if(key ==
"recruit") {
776 std::vector<variant> result;
777 for(
const auto& recruit : team_.recruits()) {
778 result.emplace_back(recruit);
781 }
else if(key ==
"recall") {
782 std::vector<variant> result;
783 for(
const auto& u : team_.recall_list()) {
784 result.push_back(std::make_shared<unit_callable>(*u));
787 }
else if(key ==
"wml_vars") {
788 return variant(std::make_shared<config_callable>(team_.variables()));
798 }
else if(key ==
"value") {
815 LOG_SF <<
"Setting variable: " << key_ <<
" -> " << value_.to_debug_string() <<
"\n";
816 obj->mutate_value(key_, value_);
821 ERR_SF <<
"ERROR #" << 5001 <<
" while executing 'set_var' formula function" << std::endl;
830 }
else if(key ==
"backup") {
847 res = action->execute_self(ctxt);
857 callable.
add(
"error", res);
862 backup_ = get_backup()->evaluate(callable);
870 if(key ==
"status") {
872 }
else if(key ==
"object") {
873 if(failed_callable_) {
874 return variant(failed_callable_);
878 }
else if(key ==
"current_loc" && current_unit_location_ !=
map_location()) {
879 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
Interfaces for manipulating version numbers of engine, add-ons, etc.
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
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
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
unit_alignments::type alignment() const
The alignment of this unit.
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
static std::string get_string(typename T::type key)
Uses the int value of the provided enum to get the associated index of the values array in the implem...
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
Represents version numbers.
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::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