void move_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: "<< *this << std::endl; assert(is_success()); move_spectator_.set_unit(get_info().units.find(from_)); if (from_ != to_) { move_unit( /*move_unit_spectator* move_spectator*/ &move_spectator_, /*std::vector<map_location> route*/ route_.steps, /*replay* move_recorder*/ &recorder, /*undo_list* undo_stack*/ NULL, /*bool show_move*/ preferences::show_ai_moves(), /*map_location *next_unit*/ NULL, /*bool continue_move*/ true, //@todo: 1.9 set to false after implemeting interrupt awareness /*bool should_clear_shroud*/ true, /*bool is_replay*/ false); if ( move_spectator_.get_ambusher().valid() || !move_spectator_.get_seen_enemies().empty() || !move_spectator_.get_seen_friends().empty() ) { set_gamestate_changed(); } else if (move_spectator_.get_unit().valid()){ unit_location_ = move_spectator_.get_unit()->first; if (unit_location_ != from_) { set_gamestate_changed(); } } } else { assert(remove_movement_); } if (move_spectator_.get_unit().valid()){ unit_location_ = move_spectator_.get_unit()->first; if ( remove_movement_ && ( move_spectator_.get_unit()->second.movement_left() > 0 ) && (unit_location_==to_)) { stopunit_result_ptr stopunit_res = actions::execute_stopunit_action(get_side(),true,unit_location_,true,false); if (!stopunit_res->is_ok()) { set_error(stopunit_res->get_status()); } if (stopunit_res->is_gamestate_changed()) { set_gamestate_changed(); } } } else { unit_location_ = map_location(); } if (is_gamestate_changed()) { try { manager::raise_gamestate_changed(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } } }
void move_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: "<< *this << std::endl; assert(is_success()); move_spectator_.set_unit(resources::units->find(from_)); if (from_ != to_) { size_t num_steps = ::actions::move_unit_and_record( /*std::vector<map_location> steps*/ route_->steps, /*::actions::undo_list* undo_stack*/ NULL, /*bool continue_move*/ true, ///@todo 1.9 set to false after implemeting interrupt awareness /*bool show_move*/ preferences::show_ai_moves(), /*bool* interrupted*/ NULL, /*::actions::move_unit_spectator* move_spectator*/ &move_spectator_); if ( num_steps > 0 ) { set_gamestate_changed(); } else if ( move_spectator_.get_ambusher().valid() ) { // Unlikely, but some types of strange WML (or bad pathfinding) // could cause an ambusher to be found without moving. set_gamestate_changed(); } } else { assert(remove_movement_); } if (move_spectator_.get_unit().valid()){ unit_location_ = move_spectator_.get_unit()->get_location(); if (remove_movement_ && move_spectator_.get_unit()->movement_left() > 0 && unit_location_ == to_) { stopunit_result_ptr stopunit_res = actions::execute_stopunit_action(get_side(),true,unit_location_,true,false); if (!stopunit_res->is_ok()) { set_error(stopunit_res->get_status()); } if (stopunit_res->is_gamestate_changed()) { set_gamestate_changed(); } } } else { unit_location_ = map_location(); } if (is_gamestate_changed()) { try { manager::raise_gamestate_changed(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } } }
void move_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: "<< *this << std::endl; assert(is_success()); if(resources::simulation_){ bool gamestate_changed = false; if(from_ != to_){ int step = route_->steps.size(); gamestate_changed = simulated_move(get_side(), from_, to_, step, unit_location_); } else { assert(remove_movement_); } unit_map::const_iterator un = resources::gameboard->units().find(unit_location_); if(remove_movement_ && un->movement_left() > 0 && unit_location_ == to_){ gamestate_changed = simulated_stopunit(unit_location_, true, false); } sim_gamestate_changed(this, gamestate_changed); return; } ::actions::move_unit_spectator move_spectator(resources::gameboard->units()); move_spectator.set_unit(resources::gameboard->units().find(from_)); if (from_ != to_) { size_t num_steps = ::actions::move_unit_and_record( /*std::vector<map_location> steps*/ route_->steps, /*::actions::undo_list* undo_stack*/ nullptr, /*bool continue_move*/ true, ///@todo 1.9 set to false after implemeting interrupt awareness /*bool show_move*/ !preferences::skip_ai_moves(), /*bool* interrupted*/ nullptr, /*::actions::move_unit_spectator* move_spectator*/ &move_spectator); if ( num_steps > 0 ) { set_gamestate_changed(); } else if ( move_spectator.get_ambusher().valid() ) { // Unlikely, but some types of strange WML (or bad pathfinding) // could cause an ambusher to be found without moving. set_gamestate_changed(); } } else { assert(remove_movement_); } if (move_spectator.get_unit().valid()){ unit_location_ = move_spectator.get_unit()->get_location(); if (remove_movement_ && move_spectator.get_unit()->movement_left() > 0 && unit_location_ == to_) { stopunit_result_ptr stopunit_res = actions::execute_stopunit_action(get_side(),true,unit_location_,true,false); if (!stopunit_res->is_ok()) { set_error(stopunit_res->get_status()); } if (stopunit_res->is_gamestate_changed()) { set_gamestate_changed(); } } } else { unit_location_ = map_location(); } has_ambusher_ = move_spectator.get_ambusher().valid(); has_interrupted_teleport_ = move_spectator.get_failed_teleport().valid(); if (is_gamestate_changed()) { try { manager::raise_gamestate_changed(); } catch (...) { if (!is_ok()) { DBG_AI_ACTIONS << "Return value of AI ACTION was not checked." << std::endl; } //Demotes to DBG "unchecked result" warning throw; } } }