void stopunit_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); unit_map::iterator un = resources::gameboard->units().find(unit_location_); if(resources::simulation_){ bool gamestate_changed = simulated_stopunit(unit_location_, remove_movement_, remove_attacks_); sim_gamestate_changed(this, gamestate_changed); return; } try { if (remove_movement_){ un->remove_movement_ai(); set_gamestate_changed(); manager::raise_gamestate_changed(); } if (remove_attacks_){ un->remove_attacks_ai(); set_gamestate_changed(); manager::raise_gamestate_changed();//to be on the safe side } } catch (...) { if (!is_ok()) { DBG_AI_ACTIONS << "Return value of AI ACTION was not checked." << std::endl; } //Demotes to DBG "unchecked result" warning throw; } }
void recall_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); const events::command_disabler disable_commands; // Assert that recall_location_ has been validated. // This should be implied by is_success() once check_before() has been // called, so this is a guard against future breakage. assert(location_checked_); // Do the actual recalling. //we ignore possible erros (=unit doesnt exist on the recall list) //becasue that was the previous behaviour. synced_context::run_in_synced_context("recall", replay_helper::get_recall(unit_id_, recall_location_, recall_from_), false, preferences::show_ai_moves(), true, synced_context::ignore_error_function); set_gamestate_changed(); try { manager::raise_gamestate_changed(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } }
void recruit_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); const unit_type *u = unit_types.find(unit_name_); const events::command_disabler disable_commands; // Assert that recruit_location_ has been validated. // This should be implied by is_success() once check_before() has been // called, so this is a guard against future breakage. assert(location_checked_ && u != nullptr); if(resources::simulation_){ bool gamestate_changed = simulated_recruit(get_side(), u, recruit_location_); sim_gamestate_changed(this, gamestate_changed); return; } synced_context::run_in_synced_context_if_not_already("recruit", replay_helper::get_recruit(u->id(), recruit_location_, recruit_from_), false, !preferences::skip_ai_moves()); //TODO: should we do something to pass use_undo = false in replays and ai moves ? //::actions::recruit_unit(*u, get_side(), recruit_location_, recruit_from_, // !preferences::skip_ai_moves(), false); set_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; } }
static int Bank_Process(char *type , TRUSERID *handle,ST_PACK *rPack,int *pRetCode,char *szMsg) { char bank_ip[20]={0}; // 银行IP int bank_port=0; Message send_Msg={"0005",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; Message recv_Msg={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; char send_buf[MAX]={0}; char recv_buf[MAX]={0}; CTcpSocket SockNode; int bank_delay = 40000; // 对账请求,时间需要可能较长 initialize(type,bank_ip,&bank_port,&send_Msg,rPack,send_buf); //初始化发送数据 //生成包头 GenMsgHead(msghead,rPack); //生成查询包体 GenMsgBodyQuery(msgbody,rPack); // 生成查询报文 GenTransReqMSG(msg,QUERY_BALA,msghead,msgbody); if(connect(&SockNode,bank_ip,bank_port,bank_delay,szMsg)==false){return E_TRANS_BANK_NETERR;}; //连接银行 if(send(&SockNode,send_buf,szMsg)==false){return E_TRANS_BANK_NETERR;} //发送数据到银行 if(receive(&SockNode,recv_buf,sizeof(recv_buf),bank_delay,szMsg)==false){return E_TRANS_BANK_NOANSWER;} //接收银行返回信息 if(is_success(recv_buf,&recv_Msg,szMsg)==false){return E_TRANS_BANK_RECVERR;} //判断银行返回交易是否成功 if(result(type,&recv_Msg,handle,pRetCode,szMsg)==false){return E_TRANS_FUNC_NONSUPPORT;} //返回结果 return 0; }
/* * Update ni->in_txrate. */ void ieee80211_amrr_choose(struct ieee80211_amrr *amrr, struct ieee80211_node *ni, struct ieee80211_amrr_node *amn) { int need_change = 0; uint8_t rate; if (is_success(amn) && is_enough(amn)) { amn->amn_success++; if (amn->amn_success >= amn->amn_success_threshold && !is_max_rate(ni)) { amn->amn_recovery = 1; amn->amn_success = 0; increase_rate(ni); rate = ni->in_rates.ir_rates[ni->in_txrate] & IEEE80211_RATE_VAL; ieee80211_dbg(IEEE80211_MSG_XRATE, "AMRR increasing rate %d (txcnt=%d retrycnt=%d)", rate, amn->amn_txcnt, amn->amn_retrycnt); DTRACE_PROBE4(amrr__increase__rate, struct ieee80211_node *, ni, uint8_t, rate, uint_t, amn->amn_txcnt, uint_t, amn->amn_retrycnt); need_change = 1; } else {
void synced_command_result::do_execute() { if(resources::simulation_){ bool gamestate_changed = simulated_synced_command(); sim_gamestate_changed(this, gamestate_changed); return; } LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); std::stringstream s; if (location_ != map_location::null_location()){ s << "local x1 = " << location_.x << " local y1 = " << location_.y << " "; } s << lua_code_; synced_context::run_in_synced_context_if_not_already("lua_ai", replay_helper::get_lua_ai(s.str())); try { set_gamestate_changed(); manager::raise_gamestate_changed(); } catch (...) { if (!is_ok()) { DBG_AI_ACTIONS << "Return value of AI ACTION was not checked. This may cause bugs! " << std::endl; } //Demotes to DBG "unchecked result" warning throw; } }
void recruit_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); const unit_type *u = unit_types.find(unit_name_); const events::command_disabler disable_commands; // Assert that recruit_location_ has been validated. // This should be implied by is_success() once check_before() has been // called, so this is a guard against future breakage. assert(location_checked_ && u != NULL); synced_context::run_in_synced_context("recruit", replay_helper::get_recruit(u->id(), recruit_location_, recruit_from_), false, preferences::show_ai_moves()); //TODO: should we do something to pass use_undo = false in replays and ai moves ? //::actions::recruit_unit(*u, get_side(), recruit_location_, recruit_from_, // preferences::show_ai_moves(), false); set_gamestate_changed(); try { manager::raise_gamestate_changed(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } }
void action_result::execute() { is_execution_ = true; init_for_execution(); check_before(); if (is_success()){ try { do_execute(); } catch (return_to_play_side_exception&) { if (!is_ok()) { DBG_AI_ACTIONS << "Return value of AI ACTION was not checked." << std::endl; } //Demotes to DBG "unchecked result" warning throw; } } if (is_success()){ check_after(); } is_execution_ = false; }
void action_result::execute() { is_execution_ = true; init_for_execution(); check_before(); if (is_success()){ do_execute(); try { resources::controller->check_victory(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } } if (is_success()){ check_after(); } is_execution_ = false; }
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; } } }
static int amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn, struct ieee80211_node *ni) { int rix = amn->amn_rix; KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt)); if (is_success(amn)) { amn->amn_success++; if (amn->amn_success >= amn->amn_success_threshold && rix + 1 < ni->ni_rates.rs_nrates) { amn->amn_recovery = 1; amn->amn_success = 0; rix++; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "AMRR increasing rate %d (txcnt=%d retrycnt=%d)", ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); } else { amn->amn_recovery = 0; } } else if (is_failure(amn)) { amn->amn_success = 0; if (rix > 0) { if (amn->amn_recovery) { amn->amn_success_threshold *= 2; if (amn->amn_success_threshold > amrr->amrr_max_success_threshold) amn->amn_success_threshold = amrr->amrr_max_success_threshold; } else { amn->amn_success_threshold = amrr->amrr_min_success_threshold; } rix--; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "AMRR decreasing rate %d (txcnt=%d retrycnt=%d)", ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); } amn->amn_recovery = 0; } /* reset counters */ amn->amn_txcnt = 0; amn->amn_retrycnt = 0; return rix; }
void recall_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); game_info& info = get_info(); team& my_team = get_my_team(info); const events::command_disabler disable_commands; std::vector<unit>::iterator rec = std::find_if(my_team.recall_list().begin(), my_team.recall_list().end(), boost::bind(&unit::matches_id, _1, unit_id_)); assert(rec != my_team.recall_list().end()); const std::string &err = find_recruit_location(get_side(), recall_location_); if(!err.empty()) { set_error(AI_ACTION_FAILURE); return; } else { unit &un = *rec; recorder.add_recall(un.id(), recall_location_); un.set_game_context(&info.units); place_recruit(un, recall_location_, true, true); statistics::recall_unit(un); my_team.spend_gold(game_config::recall_cost); my_team.recall_list().erase(rec); if (resources::screen!=NULL) { resources::screen->invalidate_game_status(); resources::screen->invalidate_all(); } recorder.add_checksum_check(recall_location_); set_gamestate_changed(); try { manager::raise_gamestate_changed(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } } }
void synced_command_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); std::stringstream s; if (location_ != map_location::null_location){ s << "local x1 = " << location_.x << " local y1 = " << location_.y << " "; } s << lua_code_; synced_context::run_in_synced_context("lua_ai", replay_helper::get_lua_ai(s.str())); try { set_gamestate_changed(); manager::raise_gamestate_changed(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } }
void stopunit_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); unit_map::iterator un = resources::units->find(unit_location_); try { if (remove_movement_){ un->remove_movement_ai(); set_gamestate_changed(); manager::raise_gamestate_changed(); } if (remove_attacks_){ un->remove_attacks_ai(); set_gamestate_changed(); manager::raise_gamestate_changed();//to be on the safe side } } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } }
void recall_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); const events::command_disabler disable_commands; // Assert that recall_location_ has been validated. // This should be implied by is_success() once check_before() has been // called, so this is a guard against future breakage. assert(location_checked_); if(resources::simulation_){ bool gamestate_changed = simulated_recall(get_side(), unit_id_, recall_location_); sim_gamestate_changed(this, gamestate_changed); return; } // Do the actual recalling. // We ignore possible errors (=unit doesn't exist on the recall list) // because that was the previous behavior. synced_context::run_in_synced_context_if_not_already("recall", replay_helper::get_recall(unit_id_, recall_location_, recall_from_), false, !preferences::skip_ai_moves(), synced_context::ignore_error_function); set_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; } }
void recruit_result::do_execute() { LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl; assert(is_success()); game_info& info = get_info(); // We have to add the recruit command now, because when the unit // is created it has to have the recruit command in the recorder // to be able to put random numbers into to generate unit traits. // However, we're not sure if the transaction will be successful, // so use a replay_undo object to cancel it if we don't get // a confirmation for the transaction. recorder.add_recruit(num_,recruit_location_); replay_undo replay_guard(recorder); const unit_type *u = unit_types.find(unit_name_); const events::command_disabler disable_commands; const std::string recruit_err = find_recruit_location(get_side(), recruit_location_); if(recruit_err.empty()) { const unit new_unit(&info.units, u, get_side(), true); place_recruit(new_unit, recruit_location_, false, preferences::show_ai_moves()); statistics::recruit_unit(new_unit); get_my_team(info).spend_gold(u->cost()); // Confirm the transaction - i.e. don't undo recruitment replay_guard.confirm_transaction(); set_gamestate_changed(); try { manager::raise_gamestate_changed(); } catch (...) { is_ok(); //Silences "unchecked result" warning throw; } } else { set_error(AI_ACTION_FAILURE); } }
/* * Examine and potentially adjust the transmit rate. */ static void ath_rate_ctl(void *arg, struct ieee80211_node *ni) { struct ath_softc *sc = arg; struct amrr_node *amn = ATH_NODE_AMRR(ATH_NODE (ni)); int rix; #define is_success(amn) \ (amn->amn_tx_try1_cnt < (amn->amn_tx_try0_cnt/10)) #define is_enough(amn) \ (amn->amn_tx_try0_cnt > 10) #define is_failure(amn) \ (amn->amn_tx_try1_cnt > (amn->amn_tx_try0_cnt/3)) rix = amn->amn_rix; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "cnt0: %d cnt1: %d cnt2: %d cnt3: %d -- threshold: %d", amn->amn_tx_try0_cnt, amn->amn_tx_try1_cnt, amn->amn_tx_try2_cnt, amn->amn_tx_try3_cnt, amn->amn_success_threshold); if (is_success (amn) && is_enough (amn)) { amn->amn_success++; if (amn->amn_success == amn->amn_success_threshold && rix + 1 < ni->ni_rates.rs_nrates) { amn->amn_recovery = 1; amn->amn_success = 0; rix++; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "increase rate to %d", rix); } else { amn->amn_recovery = 0; } } else if (is_failure (amn)) { amn->amn_success = 0; if (rix > 0) { if (amn->amn_recovery) { /* recovery failure. */ amn->amn_success_threshold *= 2; amn->amn_success_threshold = min (amn->amn_success_threshold, (u_int)ath_rate_max_success_threshold); IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "decrease rate recovery thr: %d", amn->amn_success_threshold); } else { /* simple failure. */ amn->amn_success_threshold = ath_rate_min_success_threshold; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "decrease rate normal thr: %d", amn->amn_success_threshold); } amn->amn_recovery = 0; rix--; } else { amn->amn_recovery = 0; } } if (is_enough (amn) || rix != amn->amn_rix) { /* reset counters. */ amn->amn_tx_try0_cnt = 0; amn->amn_tx_try1_cnt = 0; amn->amn_tx_try2_cnt = 0; amn->amn_tx_try3_cnt = 0; amn->amn_tx_failure_cnt = 0; } if (rix != amn->amn_rix) { ath_rate_update(sc, ni, rix); } }
static int amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn, struct ieee80211_node *ni) { int rix = amn->amn_rix; const struct ieee80211_rateset *rs = NULL; KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt)); rs = ieee80211_ratectl_get_rateset(ni); IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "%s: AMRR: current rate %d, txcnt=%d, retrycnt=%d", __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); /* * XXX This is totally bogus for 11n, as although high MCS * rates for each stream may be failing, the next stream * should be checked. * * Eg, if MCS5 is ok but MCS6/7 isn't, and we can go up to * MCS23, we should skip 6/7 and try 8 onwards. */ if (is_success(amn)) { amn->amn_success++; if (amn->amn_success >= amn->amn_success_threshold && rix + 1 < rs->rs_nrates) { amn->amn_recovery = 1; amn->amn_success = 0; rix++; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "%s: AMRR increasing rate %d (txcnt=%d retrycnt=%d)", __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); } else { amn->amn_recovery = 0; } } else if (is_failure(amn)) { amn->amn_success = 0; if (rix > 0) { if (amn->amn_recovery) { amn->amn_success_threshold *= 2; if (amn->amn_success_threshold > amrr->amrr_max_success_threshold) amn->amn_success_threshold = amrr->amrr_max_success_threshold; } else { amn->amn_success_threshold = amrr->amrr_min_success_threshold; } rix--; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "%s: AMRR decreasing rate %d (txcnt=%d retrycnt=%d)", __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); } amn->amn_recovery = 0; } /* reset counters */ amn->amn_txcnt = 0; amn->amn_retrycnt = 0; return rix; }
/* * Examine and potentially adjust the transmit rate. */ static void ath_rate_ctl(void *arg, struct ieee80211_node *ni) { struct ath_softc *sc = arg; struct amrr_node *amn = ATH_NODE_AMRR(ATH_NODE (ni)); int old_rate; #define is_success(amn) \ (amn->amn_tx_try1_cnt < (amn->amn_tx_try0_cnt/10)) #define is_enough(amn) \ (amn->amn_tx_try0_cnt > 10) #define is_failure(amn) \ (amn->amn_tx_try1_cnt > (amn->amn_tx_try0_cnt/3)) #define is_max_rate(ni) \ ((ni->ni_txrate + 1) >= ni->ni_rates.rs_nrates) #define is_min_rate(ni) \ (ni->ni_txrate == 0) old_rate = ni->ni_txrate; DPRINTF (sc, "cnt0: %d cnt1: %d cnt2: %d cnt3: %d -- threshold: %d\n", amn->amn_tx_try0_cnt, amn->amn_tx_try1_cnt, amn->amn_tx_try2_cnt, amn->amn_tx_try3_cnt, amn->amn_success_threshold); if (is_success (amn) && is_enough (amn)) { amn->amn_success++; if (amn->amn_success == amn->amn_success_threshold && !is_max_rate (ni)) { amn->amn_recovery = 1; amn->amn_success = 0; ni->ni_txrate++; DPRINTF (sc, "increase rate to %d\n", ni->ni_txrate); } else { amn->amn_recovery = 0; } } else if (is_failure (amn)) { amn->amn_success = 0; if (!is_min_rate (ni)) { if (amn->amn_recovery) { /* recovery failure. */ amn->amn_success_threshold *= 2; amn->amn_success_threshold = min (amn->amn_success_threshold, (u_int)ath_rate_max_success_threshold); DPRINTF (sc, "decrease rate recovery thr: %d\n", amn->amn_success_threshold); } else { /* simple failure. */ amn->amn_success_threshold = ath_rate_min_success_threshold; DPRINTF (sc, "decrease rate normal thr: %d\n", amn->amn_success_threshold); } amn->amn_recovery = 0; ni->ni_txrate--; } else { amn->amn_recovery = 0; } } if (is_enough (amn) || old_rate != ni->ni_txrate) { /* reset counters. */ amn->amn_tx_try0_cnt = 0; amn->amn_tx_try1_cnt = 0; amn->amn_tx_try2_cnt = 0; amn->amn_tx_try3_cnt = 0; amn->amn_tx_failure_cnt = 0; } if (old_rate != ni->ni_txrate) { ath_rate_update(sc, ni, ni->ni_txrate); } }
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; } } }
bool action_result::is_ok() { return_value_checked_ = true; return is_success(); }