small improvements to pathfinding and unit underlying description name
This commit is contained in:
parent
c23559c3ab
commit
7df7de65ac
4 changed files with 55 additions and 28 deletions
|
@ -425,15 +425,20 @@ gamemap::location ai_interface::move_unit_partial(location from, location to,
|
|||
to = *(steps.end()-1);
|
||||
steps.pop_back();
|
||||
LOG_AI << "\tresetting to " << from << " -> " << to << '\n';
|
||||
|
||||
}
|
||||
|
||||
if(steps.empty() == false) {
|
||||
|
||||
unit_map::const_iterator utest=info_.units.find(*(steps.begin()+1));
|
||||
if(utest != info_.units.end() && current_team().is_enemy(utest->second.side())){
|
||||
LOG_STREAM(err, ai) << "AI tried to move onto existing enemy unit at"<<*(steps.begin())<<"\n";
|
||||
// return(from);
|
||||
}
|
||||
|
||||
//check if there are any invisible units that we uncover
|
||||
for(std::vector<location>::iterator i = steps.begin()+1; i != steps.end(); ++i) {
|
||||
location adj[6];
|
||||
get_adjacent_tiles(*i,adj);
|
||||
|
||||
size_t n;
|
||||
for(n = 0; n != 6; ++n) {
|
||||
|
||||
|
|
|
@ -212,7 +212,13 @@ namespace dfool {
|
|||
// unit_memory_.known_map(known_units, get_info().state.turn());
|
||||
unit_memory_.known_map(known_units, 0);
|
||||
|
||||
std::cout<<"known units:\n";
|
||||
for(unit_map::const_iterator uu = known_units.begin();uu!=known_units.end();uu++){
|
||||
std::cout<<"\t"<<uu->second.underlying_description()<<" "<<uu->first<<"\n";
|
||||
}
|
||||
|
||||
calculate_moves(known_units,possible_moves,srcdst,dstsrc,false,false,NULL,true);
|
||||
|
||||
int closest_distance = -1;
|
||||
std::pair<location,location> closest_move;
|
||||
|
||||
|
@ -221,13 +227,26 @@ namespace dfool {
|
|||
//must restrict move_map to only unit that is moving.
|
||||
if(i->second==m->first){
|
||||
const int distance = distance_between(target,i->first);
|
||||
// int distance=10000;
|
||||
// std::cout<<"got here\n";
|
||||
// const shortest_path_calculator calc(m->second, current_team(),known_units,get_info().teams,get_info().map);
|
||||
//std::cout<<"got here2\n";
|
||||
//paths::route route = a_star_search(m->first, target, 1000.0, &calc,
|
||||
//get_info().map.x(), get_info().map.y());
|
||||
// std::cout<<"got here3\n";
|
||||
|
||||
// distance = route_turns_to_complete(m->second, get_info().map, route, known_units, get_info().teams) + distance_between(target,i->first)/100;
|
||||
|
||||
if(closest_distance == -1 || distance < closest_distance) {
|
||||
closest_distance = distance;
|
||||
closest_move = *i;
|
||||
closest_distance = distance;
|
||||
closest_move = *i;
|
||||
}
|
||||
// LOG_STREAM(info, ai)<<"\tmoving: "<<distance<<" from ("<<i->first.x<<","<<i->first.y<<")"<<" to ("<<target.x<<","<<target.y<<")"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_STREAM(info, ai)<<"\tmoving : "<< m->second.underlying_description() <<" "<<" from ("<<closest_move.first.x<<","<<closest_move.first.y<<")"<<" to ("<<target.x<<","<<target.y<<")"<<std::endl;
|
||||
LOG_STREAM(info, ai)<<"\tdistance: "<<closest_distance<<"\n";
|
||||
|
||||
if(closest_distance != -1) {
|
||||
gamemap::location to = move_unit_partial(closest_move.second,closest_move.first,possible_moves);
|
||||
if(to != closest_move.second)
|
||||
|
|
|
@ -410,8 +410,11 @@ static void find_routes(const gamemap& map, const gamestatus& status,
|
|||
--new_turns_left;
|
||||
new_move_left = u.total_movement() - move_cost;
|
||||
}
|
||||
const bool skirmisher = force_ignore_zocs | u.get_ability_bool("skirmisher",currentloc);
|
||||
const bool zoc = !skirmisher && enemy_zoc(map,units,teams,currentloc, viewing_team,u.side(),see_all);
|
||||
|
||||
const int total_movement = new_turns_left * u.total_movement() + new_move_left;
|
||||
const int zoc_move_left = zoc ? 0 : new_move_left;
|
||||
const int total_movement = new_turns_left * u.total_movement() + zoc_move_left;
|
||||
|
||||
const std::map<gamemap::location,paths::route>::const_iterator
|
||||
rtit = routes.find(currentloc);
|
||||
|
@ -419,12 +422,9 @@ static void find_routes(const gamemap& map, const gamestatus& status,
|
|||
//if a better route to that tile has already been found
|
||||
if(rtit != routes.end() && rtit->second.move_left >= total_movement)
|
||||
continue;
|
||||
const bool skirmisher = force_ignore_zocs | u.get_ability_bool("skirmisher",currentloc);
|
||||
const bool zoc = !skirmisher && enemy_zoc(map,units,teams,currentloc, viewing_team,u.side(),see_all);
|
||||
paths::route new_route = routes[loc];
|
||||
new_route.steps.push_back(loc);
|
||||
|
||||
const int zoc_move_left = zoc ? 0 : new_move_left;
|
||||
new_route.move_left = u.total_movement() * new_turns_left + zoc_move_left;
|
||||
routes[currentloc] = new_route;
|
||||
|
||||
|
@ -552,7 +552,6 @@ double shortest_path_calculator::cost(const gamemap::location& src,const gamemap
|
|||
if (enemy_unit != units_end && team_.is_enemy(enemy_unit->second.side()))
|
||||
return getNoPathValue();
|
||||
|
||||
|
||||
//compute how many movement points are left in the game turn needed to
|
||||
//reach the previous hex
|
||||
//total_movement_ is not zero, thanks to the pathfinding heuristic
|
||||
|
@ -566,18 +565,18 @@ double shortest_path_calculator::cost(const gamemap::location& src,const gamemap
|
|||
int additional_cost = base_cost > remaining_movement ? remaining_movement : 0;
|
||||
|
||||
if (!isDst && !unit_.get_ability_bool("skirmisher",loc)) {
|
||||
gamemap::location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
|
||||
for (size_t i = 0; i != 6; ++i) {
|
||||
enemy_unit = find_visible_unit(units_, adj[i], map_, teams_, team_);
|
||||
|
||||
if (enemy_unit != units_end && team_.is_enemy(enemy_unit->second.side()) &&
|
||||
enemy_unit->second.emits_zoc())
|
||||
// return getNoPathValue();
|
||||
//should cost us all are remaining movement.
|
||||
return total_movement_ + additional_cost;
|
||||
}
|
||||
gamemap::location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
|
||||
for (size_t i = 0; i != 6; ++i) {
|
||||
enemy_unit = find_visible_unit(units_, adj[i], map_, teams_, team_);
|
||||
if (enemy_unit != units_end && team_.is_enemy(enemy_unit->second.side()) &&
|
||||
enemy_unit->second.emits_zoc()){
|
||||
//should cost us remaining movement.
|
||||
// return getNoPathValue();
|
||||
return total_movement_ + additional_cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return base_cost + additional_cost;
|
||||
|
|
16
src/unit.cpp
16
src/unit.cpp
|
@ -264,16 +264,18 @@ unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
|
|||
//units, so they shouldn't get a description either.
|
||||
custom_unit_description_ = generate_description();
|
||||
generate_traits();
|
||||
underlying_description_ = description_;
|
||||
}else{
|
||||
underlying_description_ = id();
|
||||
if (race_->name() == "undead") {
|
||||
generate_traits();
|
||||
}
|
||||
}
|
||||
if(underlying_description_.empty()){
|
||||
char buf[80];
|
||||
sprintf(buf,"%s-%d",type()->id().c_str(),(SDL_GetTicks()));
|
||||
if(custom_unit_description_.empty()){
|
||||
sprintf(buf,"%s-%d-%s",type()->id().c_str(),(SDL_GetTicks()), custom_unit_description_.c_str());
|
||||
}else{
|
||||
sprintf(buf,"%s-%d",type()->id().c_str(),(SDL_GetTicks()));
|
||||
}
|
||||
underlying_description_ = buf;
|
||||
}
|
||||
|
||||
|
@ -306,16 +308,18 @@ unit::unit(const unit_type* t, int side, bool use_traits, bool dummy_unit, unit_
|
|||
//units, so they shouldn't get a description either.
|
||||
custom_unit_description_ = generate_description();
|
||||
generate_traits();
|
||||
underlying_description_ = description_;
|
||||
}else{
|
||||
underlying_description_ = id();
|
||||
if (race_->name() == "undead") {
|
||||
generate_traits();
|
||||
}
|
||||
}
|
||||
if(underlying_description_.empty()){
|
||||
char buf[80];
|
||||
sprintf(buf,"%s-%d",type()->id().c_str(),(SDL_GetTicks()));
|
||||
if(custom_unit_description_.empty()){
|
||||
sprintf(buf,"%s-%d-%s",type()->id().c_str(),(SDL_GetTicks()), custom_unit_description_.c_str());
|
||||
}else{
|
||||
sprintf(buf,"%s-%d",type()->id().c_str(),(SDL_GetTicks()));
|
||||
}
|
||||
underlying_description_ = buf;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue