16 #include "formula/callable_objects.hpp"
38 #define LOG_SF LOG_STREAM(info, log_scripting_formula)
39 #define ERR_SF LOG_STREAM(err, log_scripting_formula)
48 }
else if(key ==
"y") {
64 if(loc_callable ==
nullptr) {
86 if(key ==
"id" || key ==
"name") {
88 }
else if(key ==
"description") {
90 }
else if(key ==
"type") {
92 }
else if(key ==
"icon") {
94 }
else if(key ==
"range") {
96 }
else if(key ==
"damage") {
98 }
else if(key ==
"number_of_attacks" || key ==
"number" || key ==
"num_attacks" || key ==
"attacks") {
100 }
else if(key ==
"attack_weight") {
102 }
else if(key ==
"defense_weight") {
104 }
else if(key ==
"accuracy") {
106 }
else if(key ==
"parry") {
108 }
else if(key ==
"movement_used") {
110 }
else if(key ==
"attacks_used") {
112 }
else if(key ==
"specials" || key ==
"special") {
113 std::vector<variant> res;
115 for(
const auto special :
att_->specials().all_children_range()) {
116 if(!special.cfg[
"id"].empty()) {
117 res.emplace_back(special.cfg[
"id"].str());
147 if(att_callable ==
nullptr) {
151 if(
att_->damage() != att_callable->
att_->damage()) {
152 return att_->damage() - att_callable->
att_->damage();
155 if(
att_->num_attacks() != att_callable->
att_->num_attacks()) {
156 return att_->num_attacks() - att_callable->
att_->num_attacks();
159 if(
att_->id() != att_callable->
att_->id()) {
160 return att_->id().compare(att_callable->
att_->id());
163 if(
att_->type() != att_callable->
att_->type()) {
164 return att_->type().compare(att_callable->
att_->type());
167 if(
att_->range() != att_callable->
att_->range()) {
168 return att_->range().compare(att_callable->
att_->range());
171 const auto self_specials =
att_->specials().all_children_range();
172 const auto other_specials = att_callable->
att_->specials().all_children_range();
173 if(self_specials.size() != other_specials.size()) {
174 return self_specials.size() < other_specials.size() ? -1 : 1;
176 for(std::size_t
i = 0;
i < self_specials.size(); ++
i) {
177 const auto&
s = self_specials[
i].cfg[
"id"];
178 const auto& o = other_specials[
i].cfg[
"id"];
180 return s.str().compare(o.str());
200 }
else if(key ==
"y") {
206 }
else if(key ==
"loc") {
211 return variant(std::make_shared<location_callable>(
loc_));
212 }
else if(key ==
"terrain") {
217 }
else if(key ==
"id") {
219 }
else if(key ==
"type") {
221 }
else if(key ==
"name") {
223 }
else if(key ==
"usage") {
225 }
else if(key ==
"leader" || key ==
"canrecruit") {
227 }
else if(key ==
"undead") {
229 }
else if(key ==
"attacks") {
230 std::vector<variant> res;
232 res.emplace_back(std::make_shared<attack_type_callable>(att));
236 }
else if(key ==
"abilities") {
238 }
else if(key ==
"hitpoints") {
240 }
else if(key ==
"max_hitpoints") {
242 }
else if(key ==
"experience") {
244 }
else if(key ==
"max_experience") {
246 }
else if(key ==
"level" || key ==
"full") {
249 }
else if(key ==
"total_movement" || key ==
"max_moves") {
251 }
else if(key ==
"movement_left" || key ==
"moves") {
253 }
else if(key ==
"attacks_left") {
255 }
else if(key ==
"max_attacks") {
257 }
else if(key ==
"traits") {
259 }
else if(key ==
"extra_recruit") {
261 }
else if(key ==
"advances_to") {
263 }
else if(key ==
"states" || key ==
"status") {
265 }
else if(key ==
"side") {
268 }
else if(key ==
"side_number") {
270 }
else if(key ==
"cost") {
272 }
else if(key ==
"upkeep") {
274 }
else if(key ==
"loyal") {
277 }
else if(key ==
"hidden") {
279 }
else if(key ==
"petrified") {
281 }
else if(key ==
"resting") {
283 }
else if(key ==
"role") {
285 }
else if(key ==
"race") {
287 }
else if(key ==
"gender") {
289 }
else if(key ==
"variation") {
291 }
else if(key ==
"zoc") {
293 }
else if(key ==
"alignment") {
295 }
else if(key ==
"facing") {
297 }
else if(key ==
"resistance" || key ==
"movement_cost" || key ==
"vision_cost" || key ==
"jamming_cost" || key ==
"defense") {
300 bool needs_flip =
false;
301 if(key ==
"resistance") {
302 mt.get_resistances().write(cfg);
304 }
else if(key ==
"movement_cost") {
305 mt.get_movement().write(cfg);
306 }
else if(key ==
"vision_cost") {
307 mt.get_vision().write(cfg);
308 }
else if(key ==
"jamming_cost") {
309 mt.get_jamming().write(cfg);
310 }
else if(key ==
"defense") {
311 mt.get_defense().write(cfg);
314 std::map<variant, variant> res;
324 }
else if(key ==
"flying") {
326 }
else if(key ==
"vars") {
332 }
else if(key ==
"wml_vars") {
334 }
else if(key ==
"n" || key ==
"s" || key ==
"ne" || key ==
"se" || key ==
"nw" || key ==
"sw" ||
335 key ==
"lawful" || key ==
"neutral" || key ==
"chaotic" || key ==
"liminal" ||
336 key ==
"male" || key ==
"female")
397 if(u_callable ==
nullptr) {
408 }
else if(key ==
"type") {
410 }
else if(key ==
"alignment") {
412 }
else if(key ==
"race") {
414 }
else if(key ==
"abilities") {
416 }
else if(key ==
"traits") {
417 std::vector<variant> res;
419 res.emplace_back(
config[
"id"].str());
423 }
else if(key ==
"attacks") {
424 std::vector<variant> res;
426 res.emplace_back(std::make_shared<attack_type_callable>(att));
430 }
else if(key ==
"hitpoints" || key ==
"max_hitpoints") {
432 }
else if(key ==
"experience" || key ==
"max_experience") {
434 }
else if(key ==
"level") {
436 }
else if(key ==
"total_movement" || key ==
"max_moves" || key ==
"moves") {
438 }
else if(key ==
"undead") {
440 }
else if(key ==
"unpoisonable") {
442 }
else if(key ==
"unslowable") {
444 }
else if(key ==
"unpetrifiable") {
446 }
else if(key ==
"undrainable") {
448 }
else if(key ==
"unplagueable") {
450 }
else if(key ==
"cost") {
452 }
else if(key ==
"recall_cost") {
454 }
else if(key ==
"usage") {
483 if(u_callable ==
nullptr) {
487 return u_.
id().compare(u_callable->
u_.
id());
491 #ifdef USING_BOOST_VARIANT
492 :
public boost::static_visitor<variant>
512 std::vector<variant> result;
514 result.emplace_back(std::make_shared<config_callable>(child));
518 }
else if(key ==
"__all_children") {
519 std::vector<variant> result;
521 const variant cfg_child(std::make_shared<config_callable>(child.cfg));
522 const variant kv(std::make_shared<key_value_pair>(
variant(child.key), cfg_child));
523 result.push_back(kv);
527 }
else if(key ==
"__children") {
528 std::map<std::string, std::vector<variant>>
build;
530 const variant cfg_child(std::make_shared<config_callable>(child.cfg));
531 build[child.key].push_back(cfg_child);
534 std::map<variant,variant> result;
540 }
else if(key ==
"__attributes") {
541 std::map<variant,variant> result;
568 if(cfg_callable ==
nullptr) {
588 }
else if(key ==
"y") {
590 }
else if(key ==
"loc") {
591 return variant(std::make_shared<location_callable>(
loc_));
592 }
else if(key ==
"id") {
594 }
else if(key ==
"name") {
596 }
else if(key ==
"editor_name") {
598 }
else if(key ==
"description") {
600 }
else if(key ==
"icon") {
602 }
else if(key ==
"light") {
604 }
else if(key ==
"village") {
606 }
else if(key ==
"castle") {
608 }
else if(key ==
"keep") {
610 }
else if(key ==
"healing") {
612 }
else if(key ==
"owner") {
615 }
else if(key ==
"owner_side") {
643 if(terr_callable ==
nullptr) {
663 if(key ==
"terrain") {
667 std::vector<variant> vars;
668 for(
int i = 0;
i <
w;
i++) {
669 for(
int j = 0; j <
h; j++) {
671 vars.emplace_back(std::make_shared<terrain_callable>(
board_, loc));
676 }
else if(key ==
"gamemap") {
680 std::map<variant, variant> vars;
681 for(
int i = 0;
i <
w;
i++) {
682 for(
int j = 0; j <
h; j++) {
684 vars.emplace(std::make_shared<location_callable>(loc), std::make_shared<terrain_callable>(
board_, loc));
689 }
else if(key ==
"w") {
691 }
else if(key ==
"h") {
734 }
else if(key ==
"side_number") {
736 }
else if(key ==
"id") {
738 }
else if(key ==
"save_id") {
740 }
else if(key ==
"gold") {
742 }
else if(key ==
"start_gold") {
744 }
else if(key ==
"base_income") {
746 }
else if(key ==
"total_income") {
748 }
else if(key ==
"village_gold") {
750 }
else if(key ==
"village_support") {
752 }
else if(key ==
"recall_cost") {
754 }
else if(key ==
"is_human") {
756 }
else if(key ==
"is_ai") {
758 }
else if(key ==
"is_network") {
760 }
else if(key ==
"fog") {
762 }
else if(key ==
"shroud") {
764 }
else if(key ==
"hidden") {
766 }
else if(key ==
"flag") {
768 }
else if(key ==
"flag_icon") {
770 }
else if(key ==
"team_name") {
772 }
else if(key ==
"faction") {
774 }
else if(key ==
"faction_name") {
776 }
else if(key ==
"color") {
778 }
else if(key ==
"share_vision") {
780 }
else if(key ==
"carryover_bonus") {
782 }
else if(key ==
"carryover_percentage") {
784 }
else if(key ==
"carryover_add") {
786 }
else if(key ==
"recruit") {
787 std::vector<variant> result;
789 result.emplace_back(recruit);
792 }
else if(key ==
"recall") {
793 std::vector<variant> result;
795 result.push_back(std::make_shared<unit_callable>(*u));
798 }
else if(key ==
"wml_vars") {
809 }
else if(
key ==
"value") {
832 ERR_SF <<
"ERROR #" << 5001 <<
" while executing 'set_var' formula function";
841 }
else if(key ==
"backup") {
858 res = action->execute_self(ctxt);
868 callable.
add(
"error", res);
881 if(key ==
"status") {
883 }
else if(key ==
"object") {
918 if(key ==
"turn_number") {
920 }
else if(key ==
"time_of_day") {
922 }
else if(key ==
"side_number") {
924 }
else if(key ==
"sides") {
925 std::vector<variant> vars;
927 vars.emplace_back(std::make_shared<team_callable>(
team));
930 }
else if(key ==
"units") {
931 std::vector<variant> vars;
933 vars.emplace_back(std::make_shared<unit_callable>(
unit));
936 }
else if(key ==
"map") {
960 }
else if(key ==
"event_id") {
962 }
else if(key ==
"loc") {
964 }
else if(key ==
"second_loc") {
966 }
else if(key ==
"event_data") {
968 }
else if(key ==
"unit") {
970 return variant(std::make_shared<unit_callable>(*u1));
972 }
else if(key ==
"second_unit") {
974 return variant(std::make_shared<unit_callable>(*u2));
976 }
else if(key ==
"weapon") {
981 }
else if(key ==
"second_weapon") {
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
const_attr_itors attribute_range() const
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
bool has_attribute(config_key_type key) const
const_all_children_itors all_children_range() const
In-order iteration over all children.
child_itors child_range(config_key_type key)
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
virtual const gamemap & map() const =0
int w() const
Effective map width.
int h() const
Effective map height.
Encapsulates the map of the game.
This class stores all the data for a single 'side' (in game nomenclature).
const std::string & color() const
const std::string & faction() const
int village_support() const
const std::string & team_name() const
bool is_local_human() const
team_shared_vision::type share_vision() const
const t_string & faction_name() const
bool carryover_add() const
int carryover_percentage() const
const std::string & save_id() const
double carryover_bonus() const
const std::string & flag_icon() const
const std::string & flag() const
recall_list_manager & recall_list()
const std::set< std::string > & recruits() const
const std::string & icon_image() const
const t_string & name() const
const std::string & id() const
const t_string & description() const
int light_bonus(int base) const
Returns the light (lawful) bonus for this terrain when the time of day gives a base bonus.
const t_string & editor_name() const
int gives_healing() const
const std::string & id() const
std::string race_id() const
Returns the ID of this type's race without the need to build the type.
const std::string & id() const
The id for this unit_type.
const_attack_itors attacks() const
const std::string & usage() const
int experience_needed(bool with_acceleration=true) const
bool musthave_status(const std::string &status) const
std::vector< std::string > get_ability_list() const
const t_string & type_name() const
The name of the unit in the current language setting.
config::const_child_itors possible_traits() const
unit_alignments::type alignment() const
This class represents a single unit of a specific type.
Represents version numbers.
int do_compare(const formula_callable *callable) const override
variant get_value(const std::string &key) const override
attack_type_callable(const attack_type &attack)
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
int do_compare(const formula_callable *callable) const override
const config & get_config() const
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
std::shared_ptr< attack_type > second_weapon
const game_events::queued_event & event_info
std::shared_ptr< attack_type > first_weapon
const display_context & board_
const gamemap & get_gamemap() const
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
const map_location & loc() const
void serialize_to_string(std::string &str) const override
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
const expression_ptr & get_backup() const
variant execute_self(variant ctxt) override
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
const map_location current_unit_location_
void get_inputs(formula_input_vector &inputs) const override
const_formula_callable_ptr failed_callable_
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
const std::string & key() const
variant execute_self(variant ctxt) override
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
variant get_value(const std::string &key) const override
terrain_callable(const display_context &m, const map_location &loc)
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
const map_location & loc_
void get_inputs(formula_input_vector &inputs) const override
unit_callable(const map_location &loc, const unit &u)
int do_compare(const formula_callable *callable) const override
variant get_value(const std::string &key) const override
int do_compare(const formula_callable *callable) const override
void get_inputs(formula_input_vector &inputs) const override
variant execute_variant(const variant &to_exec)
std::shared_ptr< T > try_convert() const
const_formula_callable_ptr as_callable() const
std::string to_debug_string(bool verbose=false, formula_seen_stack *seen=nullptr) const
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
Interfaces for manipulating version numbers of engine, add-ons, etc.
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
unit_formula_manager & formula_manager() const
Get the unit formula manager.
int max_hitpoints() const
The max number of hitpoints this unit can have.
unit_alignments::type alignment() const
The alignment of this unit.
bool incapacitated() const
Check if the unit has been petrified.
int level() const
The current level of this unit.
std::string usage() const
Gets this unit's usage.
const std::string & get_role() const
Gets this unit's role.
const std::vector< std::string > & recruits() const
The type IDs of the other units this unit may recruit, if possible.
const std::string & variation() const
The ID of the variation of this unit's type.
int hitpoints() const
The current number of hitpoints this unit has.
int cost() const
How much gold is required to recruit this unit.
bool get_state(const std::string &state) const
Check if the unit is affected by a status effect.
const std::string & type_id() const
The id of this unit's type.
bool get_hidden() const
Gets whether this unit is currently hidden on the map.
const std::set< std::string > get_states() const
Get the status effects currently affecting the unit.
const unit_race * race() const
Gets this unit's race.
int experience() const
The current number of experience points this unit has.
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
const std::string & id() const
Gets this unit's id.
int side() const
The side this unit belongs to.
config & variables()
Gets any user-defined variables this unit 'owns'.
std::size_t underlying_id() const
This unit's unique internal ID.
int max_experience() const
The max number of experience points this unit can have.
unit_race::GENDER gender() const
The gender of this unit.
const t_string & name() const
Gets this unit's translatable display name.
const advances_to_t & advances_to() const
Gets the possible types this unit can advance to on level-up.
attack_itors attacks()
Gets an iterator over this unit's attacks.
int max_attacks() const
The maximum number of attacks this unit may perform per turn, usually 1.
int attacks_left() const
Gets the remaining number of attacks this unit can perform this turn.
bool get_emit_zoc() const
Gets the raw zone-of-control flag, disregarding incapacitated.
const movetype & movement_type() const
Get the unit's movement type.
map_location::DIRECTION facing() const
The current direction this unit is facing within its hex.
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
int total_movement() const
The maximum moves this unit has.
bool resting() const
Checks whether this unit is 'resting'.
bool is_flying() const
Check if the unit is a flying unit.
int upkeep() const
Gets the amount of gold this unit costs a side per turn.
std::vector< std::string > get_traits_list() const
Gets a list of the traits this unit currently has, including hidden traits.
Standard logging facilities (interface).
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
::tod_manager * tod_manager
play_controller * controller
std::vector< formula_input > formula_input_vector
static std::string get_location(const std::string &loc)
Define the game's event mechanism.
const std::string & gender_string(unit_race::GENDER gender)
unit_const_ptr get_unit() const
Encapsulates the map of the game.
static const map_location & null_location()
int do_compare(const map_location &a) const
three-way comparator
static std::string write_direction(DIRECTION dir)
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
variant operator()(utils::monostate) const
variant operator()(bool b) const
variant operator()(const std::string &s) const
variant operator()(int i) const
variant operator()(unsigned long long i) const
variant operator()(const t_string &s) const
variant operator()(double i) const
static map_location::DIRECTION s