The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
callable_objects.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2017 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "formula/callable_objects.hpp"
16 
17 #include "config.hpp"
18 #include "formula/function.hpp"
19 #include "map/map.hpp"
20 #include "display_context.hpp"
21 #include "team.hpp"
22 #include "units/attack_type.hpp"
24 #include "units/unit.hpp"
25 #include "log.hpp"
26 
27 static lg::log_domain log_scripting_formula("scripting/formula");
28 #define LOG_SF LOG_STREAM(info, log_scripting_formula)
29 #define ERR_SF LOG_STREAM(err, log_scripting_formula)
30 
31 namespace wfl
32 {
33 
35 {
36  if(key == "x") {
37  return variant(loc_.wml_x());
38  } else if(key == "y") {
39  return variant(loc_.wml_y());
40  }
41 
42  return variant();
43 }
44 
46 {
47  add_input(inputs, "x");
48  add_input(inputs, "y");
49 }
50 
52 {
53  const location_callable* loc_callable = dynamic_cast<const location_callable*>(callable);
54  if(loc_callable == nullptr) {
55  return formula_callable::do_compare(callable);
56  }
57 
58  const map_location& other_loc = loc_callable->loc();
59  return loc_.do_compare(other_loc);
60 }
61 
63 {
64  std::ostringstream s;
65  s << "loc(" << (loc_.wml_x()) << "," << (loc_.wml_y()) << ")";
66  str += s.str();
67 }
68 
69 attack_type_callable::attack_type_callable(const attack_type& attack) : att_(attack.shared_from_this())
70 {
72 }
73 
75 {
76  if(key == "id" || key == "name") {
77  return variant(att_->id());
78  } else if(key == "description") {
79  return variant(att_->name());
80  } else if(key == "type") {
81  return variant(att_->type());
82  } else if(key == "icon") {
83  return variant(att_->icon());
84  } else if(key == "range") {
85  return variant(att_->range());
86  } else if(key == "damage") {
87  return variant(att_->damage());
88  } else if(key == "number_of_attacks" || key == "number" || key == "num_attacks" || key == "attacks") {
89  return variant(att_->num_attacks());
90  } else if(key == "attack_weight") {
91  return variant(att_->attack_weight(), variant::DECIMAL_VARIANT);
92  } else if(key == "defense_weight") {
93  return variant(att_->defense_weight(), variant::DECIMAL_VARIANT);
94  } else if(key == "accuracy") {
95  return variant(att_->accuracy());
96  } else if(key == "parry") {
97  return variant(att_->parry());
98  } else if(key == "movement_used") {
99  return variant(att_->movement_used());
100  } else if(key == "specials" || key == "special") {
101  std::vector<variant> res;
102 
103  for(const auto& special : att_->specials().all_children_range()) {
104  if(!special.cfg["id"].empty()) {
105  res.emplace_back(special.cfg["id"].str());
106  }
107  }
108  return variant(res);
109  }
110 
111  return variant();
112 }
113 
115 {
116  add_input(inputs, "name");
117  add_input(inputs, "type");
118  add_input(inputs, "description");
119  add_input(inputs, "icon");
120  add_input(inputs, "range");
121  add_input(inputs, "damage");
122  add_input(inputs, "number");
123  add_input(inputs, "accuracy");
124  add_input(inputs, "parry");
125  add_input(inputs, "movement_used");
126  add_input(inputs, "attack_weight");
127  add_input(inputs, "defense_weight");
128  add_input(inputs, "specials");
129 }
130 
132 {
133  const attack_type_callable* att_callable = dynamic_cast<const attack_type_callable*>(callable);
134  if(att_callable == nullptr) {
135  return formula_callable::do_compare(callable);
136  }
137 
138  if(att_->damage() != att_callable->att_->damage()) {
139  return att_->damage() - att_callable->att_->damage();
140  }
141 
142  if(att_->num_attacks() != att_callable->att_->num_attacks()) {
143  return att_->num_attacks() - att_callable->att_->num_attacks();
144  }
145 
146  if(att_->id() != att_callable->att_->id()) {
147  return att_->id().compare(att_callable->att_->id());
148  }
149 
150  if(att_->type() != att_callable->att_->type()) {
151  return att_->type().compare(att_callable->att_->type());
152  }
153 
154  if(att_->range() != att_callable->att_->range()) {
155  return att_->range().compare(att_callable->att_->range());
156  }
157 
158  return att_->weapon_specials().compare(att_callable->att_->weapon_specials());
159 }
160 
162 {
163  type_ = UNIT_C;
164 }
165 
167 {
168  if(key == "x") {
170  return variant();
171  }
172 
173  return variant(loc_.wml_x());
174  } else if(key == "y") {
176  return variant();
177  }
178 
179  return variant(loc_.wml_y());
180  } else if(key == "loc") {
182  return variant();
183  }
184 
185  return variant(std::make_shared<location_callable>(loc_));
186  } else if(key == "id") {
187  return variant(u_.id());
188  } else if(key == "type") {
189  return variant(u_.type_id());
190  } else if(key == "name") {
191  return variant(u_.name());
192  } else if(key == "usage") {
193  return variant(u_.usage());
194  } else if(key == "leader" || key == "canrecruit") {
195  return variant(u_.can_recruit());
196  } else if(key == "undead") {
197  return variant(u_.get_state("not_living") ? 1 : 0);
198  } else if(key == "attacks") {
199  std::vector<variant> res;
200  for(const attack_type& att : u_.attacks()) {
201  res.emplace_back(std::make_shared<attack_type_callable>(att));
202  }
203 
204  return variant(res);
205  } else if(key == "abilities") {
207  } else if(key == "hitpoints") {
208  return variant(u_.hitpoints());
209  } else if(key == "max_hitpoints") {
210  return variant(u_.max_hitpoints());
211  } else if(key == "experience") {
212  return variant(u_.experience());
213  } else if(key == "max_experience") {
214  return variant(u_.max_experience());
215  } else if(key == "level" || key == "full") {
216  // This allows writing "upkeep == full"
217  return variant(u_.level());
218  } else if(key == "total_movement" || key == "max_moves") {
219  return variant(u_.total_movement());
220  } else if(key == "movement_left" || key == "moves") {
221  return variant(u_.movement_left());
222  } else if(key == "attacks_left") {
223  return variant(u_.attacks_left());
224  } else if(key == "max_attacks") {
225  return variant(u_.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") {
235  return variant(u_.side()-1);
236  } else if(key == "cost") {
237  return variant(u_.cost());
238  } else if(key == "upkeep") {
239  return variant(u_.upkeep());
240  } else if(key == "loyal") {
241  // So we can write "upkeep == loyal"
242  return variant(0);
243  } else if(key == "hidden") {
244  return variant(u_.get_hidden());
245  } else if(key == "petrified") {
246  return variant(u_.incapacitated());
247  } else if(key == "resting") {
248  return variant(u_.resting());
249  } else if(key == "role") {
250  return variant(u_.get_role());
251  } else if(key == "race") {
252  return variant(u_.race()->id());
253  } else if(key == "gender") {
254  return variant(gender_string(u_.gender()));
255  } else if(key == "variation") {
256  return variant(u_.variation());
257  } else if(key == "zoc") {
258  return variant(u_.get_emit_zoc());
259  } else if(key == "alignment") {
260  return variant(u_.alignment().to_string());
261  } else if(key == "facing") {
263  } else if(key == "vars") {
266  }
267 
268  return variant();
269  } else if(key == "wml_vars") {
270  return variant(std::make_shared<config_callable>(u_.variables()));
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")
274  {
275  return variant(key);
276  }
277 
278  return variant();
279 }
280 
282 {
283  add_input(inputs, "x");
284  add_input(inputs, "y");
285  add_input(inputs, "loc");
286  add_input(inputs, "id");
287  add_input(inputs, "type");
288  add_input(inputs, "name");
289  add_input(inputs, "canrecruit");
290  add_input(inputs, "undead");
291  add_input(inputs, "traits");
292  add_input(inputs, "attacks");
293  add_input(inputs, "abilities");
294  add_input(inputs, "hitpoints");
295  add_input(inputs, "max_hitpoints");
296  add_input(inputs, "experience");
297  add_input(inputs, "max_experience");
298  add_input(inputs, "level");
299  add_input(inputs, "moves");
300  add_input(inputs, "max_moves");
301  add_input(inputs, "attacks_left");
302  add_input(inputs, "max_attacks");
303  add_input(inputs, "side");
304  add_input(inputs, "extra_recruit");
305  add_input(inputs, "advances_to");
306  add_input(inputs, "status");
307  add_input(inputs, "cost");
308  add_input(inputs, "usage");
309  add_input(inputs, "upkeep");
310  add_input(inputs, "hidden");
311  add_input(inputs, "petrified");
312  add_input(inputs, "resting");
313  add_input(inputs, "role");
314  add_input(inputs, "race");
315  add_input(inputs, "gender");
316  add_input(inputs, "variation");
317  add_input(inputs, "zoc");
318  add_input(inputs, "alignment");
319  add_input(inputs, "facing");
320  add_input(inputs, "vars");
321  add_input(inputs, "wml_vars");
322 }
323 
324 int unit_callable::do_compare(const formula_callable* callable) const
325 {
326  const unit_callable* u_callable = dynamic_cast<const unit_callable*>(callable);
327  if(u_callable == nullptr) {
328  return formula_callable::do_compare(callable);
329  }
330 
331  return u_.underlying_id() - u_callable->u_.underlying_id();
332 }
333 
335 {
336  if(key == "id") {
337  return variant(u_.id());
338  } else if(key == "type") {
339  return variant(u_.type_name());
340  } else if(key == "alignment") {
341  return variant(u_.alignment().to_string());
342  } else if(key == "race") {
343  return variant(u_.race_id());
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());
350  }
351 
352  return variant(res);
353  } else if(key == "attacks") {
354  std::vector<variant> res;
355  for(const attack_type& att : u_.attacks()) {
356  res.emplace_back(std::make_shared<attack_type_callable>(att));
357  }
358 
359  return variant(res);
360  } else if(key == "hitpoints" || key == "max_hitpoints") {
361  return variant(u_.hitpoints());
362  } else if(key == "experience" || key == "max_experience") {
363  return variant(u_.experience_needed(true));
364  } else if(key == "level") {
365  return variant(u_.level());
366  } else if(key == "total_movement" || key == "max_moves" || key == "moves") {
367  return variant(u_.movement());
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") {
375  return variant(u_.cost());
376  } else if(key == "recall_cost") {
377  return variant(u_.recall_cost());
378  } else if(key == "usage") {
379  return variant(u_.usage());
380  }
381 
382  return variant();
383 }
384 
386 {
387  add_input(inputs, "id");
388  add_input(inputs, "type");
389  add_input(inputs, "race");
390  add_input(inputs, "alignment");
391  add_input(inputs, "abilities");
392  add_input(inputs, "traits");
393  add_input(inputs, "attacks");
394  add_input(inputs, "hitpoints");
395  add_input(inputs, "experience");
396  add_input(inputs, "level");
397  add_input(inputs, "total_movement");
398  add_input(inputs, "undead");
399  add_input(inputs, "cost");
400  add_input(inputs, "recall_cost");
401  add_input(inputs, "usage");
402 }
403 
405 {
406  const unit_type_callable* u_callable = dynamic_cast<const unit_type_callable*>(callable);
407  if(u_callable == nullptr) {
408  return formula_callable::do_compare(callable);
409  }
410 
411  return u_.id().compare(u_callable->u_.id());
412 }
413 
414 struct fai_variant_visitor : public boost::static_visitor<variant>
415 {
416  variant operator()(bool b) const { return variant(b ? 1 : 0); }
417  variant operator()(int i) const { return variant(i); }
418  variant operator()(unsigned long long i) const { return variant(i); }
419  variant operator()(double i) const { return variant(i * 1000, variant::DECIMAL_VARIANT); }
420  // TODO: Should comma-separated lists of stuff be returned as a list?
421  // The challenge is to distinguish them from ordinary strings that happen to contain a comma
422  // (or should we assume that such strings will be translatable?).
423  variant operator()(const std::string& s) const { return variant(s); }
424  variant operator()(const t_string& s) const { return variant(s.str()); }
425  variant operator()(boost::blank) const { return variant(); }
426 };
427 
429 {
430  if(cfg_.has_attribute(key)) {
431  return cfg_[key].apply_visitor(fai_variant_visitor());
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));
436  }
437 
438  return variant(result);
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);
445  }
446 
447  return variant(result);
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);
453  }
454 
455  std::map<variant,variant> result;
456  for(auto& p : build) {
457  result[variant(p.first)] = variant(p.second);
458  }
459 
460  return variant(result);
461  } else if(key == "__attributes") {
462  std::map<variant,variant> result;
463  for(const auto& val : cfg_.attribute_range()) {
464  result[variant(val.first)] = val.second.apply_visitor(fai_variant_visitor());
465  }
466 
467  return variant(result);
468  }
469 
470  return variant();
471 }
472 
474 {
475  add_input(inputs, "__all_children");
476  add_input(inputs, "__children");
477  add_input(inputs, "__attributes");
478 
479  for(const auto& val : cfg_.attribute_range()) {
480  if(val.first.find_first_not_of(formula::id_chars) != std::string::npos) {
481  add_input(inputs, val.first);
482  }
483  }
484 }
485 
487 {
488  const config_callable* cfg_callable = dynamic_cast<const config_callable*>(callable);
489  if(cfg_callable == nullptr) {
490  return formula_callable::do_compare(callable);
491  }
492 
493  if(cfg_ == cfg_callable->get_config()) {
494  return 0;
495  }
496 
497  return cfg_.hash().compare(cfg_callable->get_config().hash());
498 }
499 
500 terrain_callable::terrain_callable(const display_context& dc, const map_location& loc) : loc_(loc), t_(dc.map().get_terrain_info(loc)), owner_(dc.village_owner(loc))
501 {
502  type_ = TERRAIN_C;
503 }
504 
506 {
507  if(key == "x") {
508  return variant(loc_.wml_x());
509  } else if(key == "y") {
510  return variant(loc_.wml_y());
511  } else if(key == "loc") {
512  return variant(std::make_shared<location_callable>(loc_));
513  } else if(key == "id") {
514  return variant(std::string(t_.id()));
515  } else if(key == "name") {
516  return variant(t_.name());
517  } else if(key == "editor_name") {
518  return variant(t_.editor_name());
519  } else if(key == "description") {
520  return variant(t_.description());
521  } else if(key == "icon") {
522  return variant(t_.icon_image());
523  } else if(key == "light") {
524  return variant(t_.light_bonus(0));
525  } else if(key == "village") {
526  return variant(t_.is_village());
527  } else if(key == "castle") {
528  return variant(t_.is_castle());
529  } else if(key == "keep") {
530  return variant(t_.is_keep());
531  } else if(key == "healing") {
532  return variant(t_.gives_healing());
533  } else if(key == "owner") {
534  return variant(owner_);
535  }
536 
537  return variant();
538 }
539 
541 {
542  add_input(inputs, "x");
543  add_input(inputs, "y");
544  add_input(inputs, "loc");
545  add_input(inputs, "id");
546  add_input(inputs, "name");
547  add_input(inputs, "editor_name");
548  add_input(inputs, "description");
549  add_input(inputs, "icon");
550  add_input(inputs, "light");
551  add_input(inputs, "village");
552  add_input(inputs, "castle");
553  add_input(inputs, "keep");
554  add_input(inputs, "healing");
555  add_input(inputs, "owner");
556 }
557 
559 {
560  const terrain_callable* terr_callable = dynamic_cast<const terrain_callable*>(callable);
561  if(terr_callable == nullptr) {
562  return formula_callable::do_compare(callable);
563  }
564 
565  const map_location& other_loc = terr_callable->loc_;
566  return loc_.do_compare(other_loc);
567 }
568 
570  return board_.map();
571 }
572 
574 {
575  add_input(inputs, "gamemap");
576  add_input(inputs, "terrain");
577  add_input(inputs, "w");
578  add_input(inputs, "h");
579 }
580 
582 {
583  if(key == "terrain") {
584  int w = get_gamemap().w();
585  int h = get_gamemap().h();
586 
587  std::vector<variant> vars;
588  for(int i = 0; i < w; i++) {
589  for(int j = 0; j < h; j++) {
590  const map_location loc(i, j);
591  vars.emplace_back(std::make_shared<terrain_callable>(board_, loc));
592  }
593  }
594 
595  return variant(vars);
596  } else if(key == "w") {
597  return variant(get_gamemap().w());
598  } else if(key == "h") {
599  return variant(get_gamemap().h());
600  } else {
601  return variant();
602  }
603 }
604 
606 {
607  add_input(inputs, "side");
608  add_input(inputs, "id");
609  add_input(inputs, "gold");
610  add_input(inputs, "start_gold");
611  add_input(inputs, "base_income");
612  add_input(inputs, "total_income");
613  add_input(inputs, "village_gold");
614  add_input(inputs, "village_support");
615  add_input(inputs, "recall_cost");
616  add_input(inputs, "name");
617  add_input(inputs, "is_human");
618  add_input(inputs, "is_ai");
619  add_input(inputs, "is_network");
620  add_input(inputs, "fog");
621  add_input(inputs, "shroud");
622  add_input(inputs, "hidden");
623  add_input(inputs, "flag");
624  add_input(inputs, "flag_icon");
625  add_input(inputs, "team_name");
626  add_input(inputs, "faction");
627  add_input(inputs, "faction_name");
628  add_input(inputs, "color");
629  add_input(inputs, "share_vision");
630  add_input(inputs, "carryover_bonus");
631  add_input(inputs, "carryover_percentage");
632  add_input(inputs, "carryover_add");
633  add_input(inputs, "recruit");
634  add_input(inputs, "wml_vars");
635 }
636 
638 {
639  if(key == "side") {
640  return variant(team_.side());
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") {
646  return variant(team_.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") {
672  return variant(team_.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") {
678  return variant(team_.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") {
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);
691  }
692 
693  return variant(result);
694  } else if(key == "wml_vars") {
695  return variant(std::make_shared<config_callable>(team_.variables()));
696  }
697 
698  return variant();
699 }
700 
702 {
703  if(key == "key") {
704  return variant(key_);
705  } else if(key == "value") {
706  return value_;
707  }
708 
709  return variant();
710 }
711 
713 {
714  add_input(inputs, "key");
715  add_input(inputs, "value");
716 }
717 
719 {
720  //if(infinite_loop_guardian_.set_var_check()) {
721  if(auto obj = ctxt.try_convert<formula_callable>()) {
722  LOG_SF << "Setting variable: " << key_ << " -> " << value_.to_debug_string() << "\n";
723  obj->mutate_value(key_, value_);
724  return variant(true);
725  }
726  //}
727  //too many calls in a row - possible infinite loop
728  ERR_SF << "ERROR #" << 5001 << " while executing 'set_var' formula function" << std::endl;
729 
730  return variant(std::make_shared<safe_call_result>(fake_ptr(), 5001));
731 }
732 
734 {
735  if(key == "main") {
736  return variant(main_);
737  } else if(key == "backup") {
738  return variant(backup_);
739  }
740 
741  return variant();
742 }
743 
745 {
746  add_input(inputs, "main");
747  add_input(inputs, "backup");
748 }
749 
751 {
752  variant res;
753  if(auto action = main_.try_convert<action_callable>()) {
754  res = action->execute_self(ctxt);
755  }
756 
757  if(res.try_convert<safe_call_result>()) {
758  /* If we have safe_call formula and either an error occurred, or the current action
759  * was not recognized, then evaluate backup formula from safe_call and execute it
760  * during the next loop
761  */
762 
763  map_formula_callable callable(ctxt.as_callable());
764  callable.add("error", res);
765 
766  /* Store the result in safe_call_callable in case we would like to display it to the user,
767  * for example if this formula was executed from the commandline.
768  */
769  backup_ = get_backup()->evaluate(callable);
770  ctxt.execute_variant(backup_);
771  }
772  return variant(true);
773 }
774 
776 {
777  if(key == "status") {
778  return variant(status_);
779  } else if(key == "object") {
780  if(failed_callable_) {
781  return variant(failed_callable_);
782  }
783 
784  return variant();
785  } else if(key == "current_loc" && current_unit_location_ != map_location()) {
786  return variant(std::make_shared<location_callable>(current_unit_location_));
787  }
788 
789  return variant();
790 }
791 
793 {
794  add_input(inputs, "status");
795  add_input(inputs, "object");
796 
798  add_input(inputs, "current_loc");
799  }
800 }
801 
802 } // namespace wfl
variant execute_variant(const variant &to_exec)
Definition: variant.cpp:659
variant get_value(const std::string &key) const override
bool uses_shroud() const
Definition: team.hpp:312
bool is_local_ai() const
Definition: team.hpp:265
bool is_network() const
Definition: team.hpp:259
const std::string & flag() const
Definition: team.hpp:298
const_formula_callable_ptr as_callable() const
Definition: variant.hpp:79
const std::string & get_role() const
Gets this unit's role.
Definition: unit.hpp:531
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1057
std::string usage() const
Gets this unit's usage.
Definition: unit.hpp:548
std::vector< char_t > string
bool incapacitated() const
Check if the unit has been petrified.
Definition: unit.hpp:763
int start_gold() const
Definition: team.hpp:189
void get_inputs(formula_input_vector &inputs) const override
const std::string & color() const
Definition: team.hpp:254
const t_string & type_name() const
The name of the unit in the current language setting.
Definition: types.hpp:137
void get_inputs(formula_input_vector &inputs) const override
This class represents a single unit of a specific type.
Definition: unit.hpp:100
variant get_value(const std::string &key) const override
int movement() const
Definition: types.hpp:153
const gamemap & get_gamemap() const
const std::string & variation() const
The ID of the variation of this unit's type.
Definition: unit.hpp:453
const std::set< std::string > & recruits() const
Definition: team.hpp:222
bool musthave_status(const std::string &status) const
Definition: types.cpp:694
variant get_value(const std::string &key) const override
const display_context & board_
bool hidden() const
Definition: team.hpp:341
int upkeep() const
Gets the amount of gold this unit costs a side per turn.
Definition: unit.cpp:1523
bool get_emit_zoc() const
Gets the raw zone-of-control flag, disregarding incapacitated.
Definition: unit.hpp:1129
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1067
bool get_hidden() const
Gets whether this unit is currently hidden on the map.
Definition: unit.hpp:580
const_attack_itors attacks() const
Definition: types.cpp:492
double carryover_bonus() const
Definition: team.hpp:353
child_itors child_range(config_key_type key)
Definition: config.cpp:343
config & variables()
Gets any user-defined variables this unit 'owns'.
Definition: unit.hpp:565
variant operator()(const std::string &s) const
const std::vector< std::string > & advances_to() const
Gets the possible types this unit can advance to on level-up.
Definition: unit.hpp:144
variant operator()(bool b) const
std::vector< std::string > get_ability_list() const
Definition: types.cpp:565
int level() const
The current level of this unit.
Definition: unit.hpp:441
const std::string & id() const
Definition: race.hpp:32
const std::vector< std::string > & recruits() const
The type IDs of the other units this unit may recruit, if possible.
Definition: unit.hpp:493
std::vector< formula_input > formula_input_vector
const t_string & name() const
Definition: terrain.hpp:33
void get_inputs(formula_input_vector &inputs) const override
const std::string & id() const
Definition: terrain.hpp:37
int attacks_left() const
Gets the remaining number of attacks this unit can perform this turn.
Definition: unit.hpp:844
static variant convert_set(const std::set< T > &input_set)
Definition: callable.hpp:114
#define h
#define ERR_SF
int wml_y() const
Definition: location.hpp:116
map_location::DIRECTION facing() const
The current directin this unit is facing within its hex.
Definition: unit.hpp:1157
void get_inputs(formula_input_vector &inputs) const override
variant operator()(int i) const
int light_bonus(int base) const
Returns the light (lawful) bonus for this terrain when the time of day gives a base bonus...
Definition: terrain.hpp:55
void get_inputs(formula_input_vector &inputs) const override
const std::string & type_id() const
The id of this unit's type.
Definition: unit.hpp:267
-file sdl_utils.hpp
int level() const
Definition: types.hpp:151
int cost() const
How much gold is required to recruit this unit.
Definition: unit.hpp:502
Definitions for the interface to Wesnoth Markup Language (WML).
const t_string & editor_name() const
Definition: terrain.hpp:34
virtual const gamemap & map() const =0
unit_formula_manager & formula_manager() const
Get the unit formula manager.
Definition: unit.hpp:1528
static lg::log_domain log_scripting_formula("scripting/formula")
variant operator()(boost::blank) const
const unit_race * race() const
Gets this unit's race.
Definition: unit.hpp:387
SHARE_VISION share_vision() const
Definition: team.hpp:387
map_location loc_
#define b
const_formula_callable_ptr failed_callable_
int max_experience() const
The max number of experience points this unit can have.
Definition: unit.hpp:417
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
variant execute_self(variant ctxt) override
int recall_cost() const
Definition: team.hpp:192
const std::string & flag_icon() const
Definition: team.hpp:299
int do_compare(const formula_callable *callable) const override
int wml_x() const
Definition: location.hpp:115
int gives_healing() const
Definition: terrain.hpp:61
attack_type_callable(const attack_type &attack)
int village_support() const
Definition: team.hpp:198
config & variables()
Definition: team.hpp:356
map_formula_callable & add(const std::string &key, const variant &value)
Definition: callable.hpp:252
const std::string & id() const
Gets this unit's id.
Definition: unit.hpp:284
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:393
int carryover_percentage() const
Definition: team.hpp:349
int base_income() const
Definition: team.hpp:190
int do_compare(const formula_callable *callable) const override
int w() const
Effective map width.
Definition: map.hpp:90
std::shared_ptr< T > try_convert() const
Definition: variant.hpp:86
size_t underlying_id() const
This unit's unique internal ID.
Definition: unit.hpp:296
const t_string & name() const
Gets this unit's translatable display name.
Definition: unit.hpp:307
unit_race::GENDER gender() const
The gender of this unit.
Definition: unit.hpp:360
Encapsulates the map of the game.
Definition: map.hpp:34
int do_compare(const formula_callable *callable) const override
const std::string & team_name() const
Definition: team.hpp:294
int max_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:399
bool is_local_human() const
Definition: team.hpp:264
int max_attacks() const
The maximum number of attacks this unit may perform per turn, usually 1.
Definition: unit.hpp:834
const config & get_config() const
virtual int do_compare(const formula_callable *callable) const
Definition: callable.hpp:145
void serialize_to_string(std::string &str) const override
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
Definition: abilities.cpp:219
static const map_location & null_location()
Definition: location.hpp:220
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:411
bool is_village() const
Definition: terrain.hpp:62
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
const std::string & save_id() const
Definition: team.hpp:230
std::string race_id() const
Returns the ID of this type's race without the need to build the type.
Definition: types.hpp:244
const map_location & loc_
variant get_value(const std::string &key) const override
const std::string & gender_string(unit_race::GENDER gender)
Definition: race.cpp:130
void get_inputs(formula_input_vector &inputs) const override
int cost() const
Definition: types.hpp:159
#define LOG_SF
const expression_ptr & get_backup() const
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
Definition: config.cpp:393
Encapsulates the map of the game.
Definition: location.hpp:40
bool has_attribute(config_key_type key) const
Definition: config.cpp:196
const std::string & usage() const
Definition: types.hpp:162
formula_callable_ptr fake_ptr()
Definition: callable.hpp:41
int h() const
Effective map height.
Definition: map.hpp:93
bool is_keep() const
Definition: terrain.hpp:64
mock_party p
static std::string get_location(const std::string &loc)
config::const_child_itors possible_traits() const
Definition: types.hpp:205
int do_compare(const formula_callable *callable) const override
const wfl::map_formula_callable_ptr & formula_vars() const
const_attr_itors attribute_range() const
Definition: config.cpp:736
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
bool get_state(const std::string &state) const
Check if the unit is affected by a status effect.
Definition: unit.cpp:1289
variant get_value(const std::string &key) const override
const map_location loc_
variant get_value(const std::string &key) const override
attack_itors attacks()
Gets an iterator over this unit's attacks.
Definition: unit.hpp:785
unit_callable(const map_location &loc, const unit &u)
const terrain_type & t_
size_t i
Definition: function.cpp:933
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
Definition: unit.hpp:481
int w
int side() const
Definition: team.hpp:187
variant get_value(const std::string &key) const override
variant operator()(double i) const
int hitpoints() const
Definition: types.hpp:148
int experience_needed(bool with_acceleration=true) const
Definition: types.cpp:526
std::string hash() const
Definition: config.cpp:1237
static const char *const id_chars
Definition: formula.hpp:74
int gold() const
Definition: team.hpp:188
variant operator()(unsigned long long i) const
Definition: contexts.hpp:42
int do_compare(const formula_callable *callable) const override
bool uses_fog() const
Definition: team.hpp:313
const map_location & loc() const
variant get_value(const std::string &key) const override
Standard logging facilities (interface).
unit_type::ALIGNMENT alignment() const
The alignment of this unit.
Definition: unit.hpp:370
static variant convert_vector(const std::vector< T > &input_vector)
Definition: callable.hpp:125
std::string to_debug_string(bool verbose=false, formula_seen_stack *seen=nullptr) const
Definition: variant.cpp:649
const std::set< std::string > get_states() const
Get the status effects currently affecting the unit.
Definition: unit.cpp:1272
variant execute_self(variant ctxt) override
int do_compare(const map_location &a) const
three-way comparator
Definition: location.hpp:88
bool carryover_add() const
Definition: team.hpp:351
terrain_callable(const display_context &m, const map_location &loc)
int total_income() const
Definition: team.hpp:195
static void add_input(formula_input_vector &inputs, const std::string &key, FORMULA_ACCESS_TYPE access_type=FORMULA_READ_ONLY)
Definition: callable.hpp:135
int recall_cost() const
Definition: types.hpp:152
const std::string & str() const
Definition: tstring.hpp:186
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
int village_gold() const
Definition: team.hpp:191
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
bool is_castle() const
Definition: terrain.hpp:63
bool resting() const
Checks whether this unit is 'resting'.
Definition: unit.hpp:1111
const map_location current_unit_location_
const t_string & description() const
Definition: terrain.hpp:35
static std::string write_direction(DIRECTION dir)
Definition: location.cpp:139
const_all_children_itors all_children_range() const
In-order iteration over all children.
Definition: config.cpp:848
int side() const
The side this unit belongs to.
Definition: unit.hpp:244
const std::string & icon_image() const
Definition: terrain.hpp:29
const std::string & id() const
The id for this unit_type.
Definition: types.hpp:140
std::vector< std::string > get_traits_list() const
Gets a list of the traits this unit currently has.
Definition: unit.cpp:862
variant operator()(const t_string &s) const