Fixed bug in evaluate_for_position function
This commit is contained in:
parent
2f4de7871b
commit
ecc0d37506
2 changed files with 23 additions and 4 deletions
|
@ -576,6 +576,7 @@ public:
|
|||
private:
|
||||
variant execute(const formula_callable& variables) const {
|
||||
variant position = args()[0]->evaluate(variables);
|
||||
ai_.store_outcome_position(position);
|
||||
position_callable* pos = convert_variant<position_callable>(position);
|
||||
position_callable::swapper swapper(ai_, *pos);
|
||||
return args()[1]->evaluate(variables);
|
||||
|
@ -1796,10 +1797,14 @@ std::string formula_ai::evaluate(const std::string& formula_str)
|
|||
|
||||
const variant v = f.execute(callable);
|
||||
|
||||
if ( execute_variant(v, true ) )
|
||||
return "Made move: " + v.to_debug_string();
|
||||
//first read info about move, then clear outcome_positions
|
||||
std::string move_info = v.to_debug_string();
|
||||
outcome_positions_.clear();
|
||||
|
||||
return v.to_debug_string();
|
||||
if ( execute_variant(v, true ) )
|
||||
return "Made move: " + move_info;
|
||||
|
||||
return move_info;
|
||||
}
|
||||
catch(formula_error& e) {
|
||||
e.line = 0;
|
||||
|
@ -1808,6 +1813,11 @@ std::string formula_ai::evaluate(const std::string& formula_str)
|
|||
}
|
||||
}
|
||||
|
||||
void formula_ai::store_outcome_position(const variant& var)
|
||||
{
|
||||
outcome_positions_.push_back(var);
|
||||
}
|
||||
|
||||
void formula_ai::swap_move_map(move_map_backup& backup)
|
||||
{
|
||||
std::swap(move_maps_valid_, backup.move_maps_valid);
|
||||
|
@ -1866,7 +1876,12 @@ bool formula_ai::make_move(game_logic::const_formula_ptr formula_, const game_lo
|
|||
LOG_AI << "do move...\n";
|
||||
const variant var = formula_->execute(variables);
|
||||
|
||||
return execute_variant(var);
|
||||
bool res = execute_variant(var);
|
||||
|
||||
//remove outcome_positions
|
||||
outcome_positions_.clear();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
paths::route formula_ai::shortest_path_calculator(const map_location& src, const map_location& dst, unit_map::iterator& unit_it, std::set<map_location>& allowed_teleports) const {
|
||||
|
|
|
@ -170,6 +170,8 @@ public:
|
|||
|
||||
void invalidate_move_maps() const { move_maps_valid_ = false; }
|
||||
|
||||
void store_outcome_position(const variant& var);
|
||||
|
||||
/** Create a new formula from the string, using the symbol table which is stored in the AI.
|
||||
*
|
||||
* @param formula_string the string from which a formula should be created
|
||||
|
@ -190,6 +192,8 @@ private:
|
|||
game_logic::const_formula_ptr recruit_formula_;
|
||||
game_logic::const_formula_ptr move_formula_;
|
||||
|
||||
std::vector<variant> outcome_positions_;
|
||||
|
||||
mutable std::map<location,paths> possible_moves_;
|
||||
|
||||
void prepare_move() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue