41 #define DBG_REPLAY LOG_STREAM(debug, log_replay)
42 #define LOG_REPLAY LOG_STREAM(info, log_replay)
43 #define WRN_REPLAY LOG_STREAM(warn, log_replay)
44 #define ERR_REPLAY LOG_STREAM(err, log_replay)
60 static map* instance =
new map();
68 team ¤t_team = (*resources::teams)[current_team_num - 1];
73 if ( !from.valid() ) {
77 error_handler(
"Missing leader location for recruitment.\n",
false);
81 std::stringstream errbuf;
82 errbuf <<
"Recruiting leader not found at " << from <<
".\n";
83 error_handler(errbuf.str(),
false);
88 if ( type_id.empty() ) {
89 error_handler(
"Recruitment is missing a unit type.",
true);
95 std::stringstream errbuf;
96 errbuf <<
"Recruiting illegal unit: '" << type_id <<
"'.\n";
97 error_handler(errbuf.str(),
true);
104 std::stringstream errbuf;
105 errbuf <<
"cannot recruit unit: " << res <<
"\n";
106 error_handler(errbuf.str(),
true);
110 const int beginning_gold = current_team.
gold();
114 if ( u_type->
cost() > beginning_gold ) {
115 std::stringstream errbuf;
116 errbuf <<
"unit '" << type_id <<
"' is too expensive to recruit: "
117 << u_type->
cost() <<
"/" << beginning_gold <<
"\n";
118 error_handler(errbuf.str(),
false);
123 LOG_REPLAY <<
"recruit: team=" << current_team_num <<
" '" << type_id <<
"' at (" << loc
124 <<
") cost=" << u_type->
cost() <<
" from gold=" << beginning_gold <<
' '
125 <<
"-> " << current_team.
gold() <<
"\n";
133 team ¤t_team = (*resources::teams)[current_team_num - 1];
140 error_handler(
"illegal recall: unit_id '" + unit_id +
"' could not be found within the recall list.\n",
true);
149 const config &destination = child.
child(
"destination");
154 error_handler(
"no destination found in attack\n",
true);
159 error_handler(
"no source found in attack \n",
true);
168 int weapon_num = child[
"weapon"];
174 int def_weapon_num = child[
"defender_weapon"].to_int(-2);
175 if (def_weapon_num == -2) {
177 LOG_REPLAY <<
"Old data, having to guess weapon\n";
183 error_handler(
"unfound location for source of attack\n",
true);
187 if (child.has_attribute(
"attacker_type")) {
188 const std::string &att_type_id = child[
"attacker_type"];
189 if (u->type_id() != att_type_id) {
190 WRN_REPLAY <<
"unexpected attacker type: " << att_type_id <<
"(game state gives: " << u->type_id() <<
")" << std::endl;
194 if (
size_t(weapon_num) >= u->attacks().size()) {
195 error_handler(
"illegal weapon type in attack\n",
true);
202 std::stringstream errbuf;
203 errbuf <<
"unfound defender for attack: " << src <<
" -> " << dst <<
'\n';
204 error_handler(errbuf.str(),
true);
208 if (child.has_attribute(
"defender_type")) {
209 const std::string &def_type_id = child[
"defender_type"];
210 if (tgt->type_id() != def_type_id) {
211 WRN_REPLAY <<
"unexpected defender type: " << def_type_id <<
"(game state gives: " << tgt->type_id() <<
")" << std::endl;
215 if (def_weapon_num >= static_cast<int>(tgt->attacks().size())) {
217 error_handler(
"illegal defender weapon type in attack\n",
true);
221 DBG_REPLAY <<
"Attacker XP (before attack): " << u->experience() <<
"\n";
232 team ¤t_team = (*resources::teams)[current_team_num - 1];
239 assert(dismissed_unit);
246 error_handler(
"illegal disband\n",
true);
255 team ¤t_team = (*resources::teams)[current_team_num - 1];
257 std::vector<map_location> steps;
262 WRN_REPLAY <<
"Warning: Path data contained something which could not be parsed to a sequence of locations:" <<
"\n config = " << child.debug() << std::endl;
268 WRN_REPLAY <<
"Warning: Missing path data found in [move]" << std::endl;
276 WRN_REPLAY <<
"Warning: Move with identical source and destination. Skipping..." << std::endl;
283 WRN_REPLAY <<
"Warning: Move destination " << dst <<
" appears occupied." << std::endl;
291 std::stringstream errbuf;
292 errbuf <<
"unfound location for source of movement: "
293 << src <<
" -> " << dst <<
'\n';
294 error_handler(errbuf.str(),
true);
297 bool skip_sighted =
false;
298 bool skip_ally_sighted =
false;
299 if(child[
"skip_sighted"] ==
"all")
303 else if(child[
"skip_sighted"] ==
"only_ally")
305 skip_ally_sighted =
true;
308 bool show_move =
show;
320 bool undoable =
true;
322 if(
const config &last_select = child.
child(
"last_select"))
358 bool active = child[
"active"].to_bool();
381 error_handler(
"Team has DSU disabled but we found an explicit shroud update",
false);
389 void debug_notification(
const char*
message)
401 debug_notification(
":unit debug command was used during turn of $player");
410 if (name ==
"advances" ) {
413 i->set_experience(i->max_experience());
421 }
else if (name ==
"status" ) {
428 if (status.length() >= 1 && status[0] ==
'-') {
430 status = status.substr(1);
432 if (status.empty()) {
435 statuses[status] = add;
437 unit new_u(cfg,
true);
444 unit new_u(cfg,
true);
447 if (name ==
"fail") {
461 debug_notification(
"A unit was created using debug command during turn of $player");
466 error_handler(
"Invalid unit type",
true);
474 unit created(*u_type, side_num,
true, gender);
490 clearer.fire_events();
491 if ( add_result.first.valid() )
502 debug_notification(
":lua debug command was used during turn of $player");
515 debug_notification(
":next_level debug command was used during turn of $player");
518 if (!next_level.empty())
539 debug_notification(
":turn_limit debug command was used during turn of $player");
552 debug_notification(
":turn debug command was used during turn of $player");
568 debug_notification(
":set_var debug command was used during turn of $player");
586 debug_notification(
":gold debug command was used during turn of $player");
600 debug_notification(
":throw debug command was used during turn of $player");
615 debug_notification(
":fog debug command was used during turn of $player");
634 debug_notification(
":shroud debug command was used during turn of $player");
void clear()
Clears the stack of undoable (and redoable) actions.
play_controller * controller
void read_locations(const config &cfg, std::vector< map_location > &locs)
Parse x,y keys of a config into a vector of locations.
static thandler * handler
::tod_manager * tod_manager
void set_shroud(bool shroud)
const std::string & current_player() const
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
bool clear_unit(const map_location &view_loc, team &view_team, size_t viewer_id, int sight_range, bool slowed, const movetype::terrain_costs &costs, const map_location &real_loc, const std::set< map_location > *known_units=nullptr, size_t *enemy_count=nullptr, size_t *friend_count=nullptr, move_unit_spectator *spectator=nullptr, bool instant=true)
Clears shroud (and fog) around the provided location for view_team based on sight_range, costs, and slowed.
bool get_village(const map_location &loc, int side, bool *action_timebonus, bool fire_event)
Makes it so the village at the given location is owned by the given side.
Various functions that implement attacks and attack calculations.
size_t size() const
Get the number of units on the list.
void advance_unit_at(const advance_unit_params ¶ms)
void set_turn(const int num, game_data *vars=nullptr, const bool increase_limit_if_needed=true)
Dynamically change the current turn number.
static map & registry()
using static function variable instead of static member variable to prevent static initialization fia...
config & child_or_add(const std::string &key)
Returns a reference to the first child with the given key.
void redraw_everything()
Invalidates entire screen, including all tiles and sidebar.
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
bool actor_sighted(const unit &target, const std::vector< int > *cache)
Fires sighted events for the sides that can see target.
synced_command(const std::string &tag, handler function)
unit_type_data unit_types
std::map< std::string, handler > map
bool prescenario_save
Should a prescenario be created the next game?
bool fire(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
Function to fire an event.
void flush_messages()
Flushes WML messages and errors.
To lexical_cast(From value)
Lexical cast converts one type to another.
const SDL_Color NORMAL_COLOR
void new_turn()
Update lighting settings.
std::vector< std::pair< const std::string *, const stats * > > levels
Stats (and name) for each scenario. The pointers are never nullptr.
game_events::t_pump & pump()
This class stores all the data for a single 'side' (in game nomenclature).
void recruit_unit(const unit_type &u_type, int side_num, const map_location &loc, const map_location &from, bool show, bool use_undo)
Recruits a unit of the given type for the given side.
bool linger_mode
Should linger mode be invoked?
std::map< std::string, t_string > string_map
bool auto_shroud_updates() const
unit_ptr find_if_matches_id(const std::string &unit_id)
Find a unit by id. Null pointer if not found.
int current_side() const
Returns the number of the side whose turn it is.
void recalculate_minimap()
Schedule the minimap for recalculation.
GLsizei const GLfloat * value
unit_race::GENDER string_gender(const std::string &str, unit_race::GENDER def)
void recalculate_fog(int side)
Function that recalculates the fog of war.
void set_variable(const std::string &varname, const t_string &value)
does nothing if varname is no valid variable name.
void spend_gold(const int amount)
bool carryover_report
Should a summary of the scenario outcome be displayed?
std::pair< unit_iterator, bool > replace(const map_location &l, const unit &u)
Works like unit_map::add; but l is emptied first, if needed.
void commit_vision()
Updates fog/shroud based on the undo stack, then updates stack as needed.
std::pair< unit_iterator, bool > add(const map_location &l, const unit &u)
Adds a copy of unit u at location l of the map.
game_events::manager * game_events
SYNCED_COMMAND_HANDLER_FUNCTION(recruit, child, use_undo, show, error_handler)
void erase_if_matches_id(const std::string &unit_id)
Erase any unit with this id.
advances the unit at loc if it has enough experience, maximum 20 times.
virtual void force_end_turn()=0
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
Encapsulates the map of the game.
Various functions related to moving units.
void run(char const *prog, int nArgs=0)
Runs a plain script.
Various functions related to the creation of units (recruits, recalls, and placed units)...
void set_end_level_data(const end_level_data &data)
void add_dismissal(const unit_const_ptr u)
Adds a dismissal to the undo stack.
transient_end_level transient
size_t move_unit_from_replay(const std::vector< map_location > &steps, undo_list *undo_stack, bool continued_move, bool skip_ally_sighted, bool show_move)
Moves a unit across the board.
void set_number_of_turns(int num)
Define the game's event mechanism.
Information on a WML variable.
bool proceed_to_next_level
whether to proceed to the next scenario, equals is_victory in sp.
Additional information on the game outcome which can be provided by WML.
bool fire_event(const tevent event, std::vector< std::pair< twidget *, tevent > > &event_chain, twidget *dispatcher, twidget *widget, F functor)
Helper function for fire_event.
game_events::t_pump & pump()
GLuint const GLchar * name
size_t erase(const map_location &l)
Erases the unit at location l, if any.
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
void add_update_shroud()
Adds a shroud update to the undo stack.
bool find(E event, F functor)
Tests whether an event handler is available.
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
void unit_recruited(const map_location &loc, const map_location &leader_loc)
Various functions that implement the undoing (and redoing) of in-game commands.
std::string find_recruit_location(const int side, map_location &recruit_location, map_location &recruited_from, const std::string &unit_type)
Finds a location on which to place a unit.
Standard logging facilities (interface).
bool is_network_ai() const
bool recall_unit(const std::string &id, team ¤t_team, const map_location &loc, const map_location &from, bool show, bool use_undo)
Recalls the unit with the indicated ID for the provided team.
void add_dummy()
Adds an auto-shroud toggle to the undo stack.
recall_list_manager & recall_list()
game_lua_kernel * lua_kernel
GLsizei GLenum GLuint GLuint GLsizei char * message
Class to encapsulate fog/shroud clearing and the resultant sighted events.
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
void set_auto_shroud_updates(bool value)
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
void add_auto_shroud(bool turned_on)
Adds an auto-shroud toggle to the undo stack.
actions::undo_list * undo_stack
static lg::log_domain log_replay("replay")
unit_iterator find(size_t id)
A config object defines a single node in a WML file, with access to child nodes.
void announce(const std::string &msg, const SDL_Color &color=font::GOOD_COLOR)
Announce a message prominently.
Thrown when a lexical_cast fails.
GLsizei const GLcharARB ** string
GLsizei GLsizei GLchar * source
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
Display units performing various actions: moving, attacking, and dying.
void attack_unit_and_advance(const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display, const ai::unit_advancements_aspect &ai_advancement)
Performs an attack, and advanced the units afterwards.