Author: suokko
Date: Mon Sep 1 14:53:23 2008
New Revision: 29165
URL: http://svn.gna.org/viewcvs/wesnoth?rev=29165&view=rev
Log:
Fixed crash when ai moves units next to level 0 hiden unit (bug #12252)
Modified:
branches/1.4/changelog
branches/1.4/src/ai.cpp
branches/1.4/src/unit.cpp
branches/1.4/src/unit.hpp
Modified: branches/1.4/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/changelog?rev=29165&r1=29164&r2=29165&view=diff
==============================================================================
--- branches/1.4/changelog (original)
+++ branches/1.4/changelog Mon Sep 1 14:53:23 2008
@@ -13,6 +13,7 @@
* fonts: DejaVuSans 2.26
* miscellaneous and bug fixes:
* Fixed OOS bug when giving control and having move in undo stack.
+ * Fixed crash when ai moves units next to level 0 hiden unit (bug #12252)
Version 1.4.4:
* language and i18n:
Modified: branches/1.4/src/ai.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/ai.cpp?rev=29165&r1=29164&r2=29165&view=diff
==============================================================================
--- branches/1.4/src/ai.cpp (original)
+++ branches/1.4/src/ai.cpp Mon Sep 1 14:53:23 2008
@@ -461,11 +461,11 @@
}
if(steps.size()>1) { // First step is starting hex
- 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);
- }
+ 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) {
@@ -481,27 +481,29 @@
// Or would it? If it doesn't
cheat, it might...
const unit_map::const_iterator
u = info_.units.find(adj[n]);
- if (u != info_.units.end() &&
u->second.emits_zoc()
- &&
current_team().is_enemy(u->second.side())) {
+ // If level 0 is invisible it
ambush us too
+ if (u != info_.units.end() &&
(u->second.emits_zoc()||u->second.invisible(adj[n], info_.units, info_.teams))
+ &&
current_team().is_enemy(u->second.side())) {
if
(u->second.invisible(adj[n], info_.units, info_.teams)) {
to = *i;
+
u->second.ambush(adj[n]);
steps.erase(i,steps.end());
break;
} else {
- if
(!u_it->second.get_ability_bool("skirmisher",*i)){
- LOG_STREAM(err, ai)
<< "AI tried to skirmish with non-skirmisher\n";
- LOG_AI <<
"\tresetting destination from " <<to;
- to = *i;
- LOG_AI << " to " <<
to;
-
steps.erase(i,steps.end());
- while(steps.empty()
== false && (!(info_.units.find(to) == info_.units.end() || from == to))){
- to =
*(steps.end()-1);
-
steps.pop_back();
- LOG_AI <<
"\tresetting to " << from << " -> " << to << '\n';
- }
-
- break;
- }
+ if
(!u_it->second.get_ability_bool("skirmisher",*i)){
+
LOG_STREAM(err, ai) << "AI tried to skirmish with non-skirmisher\n";
+ LOG_AI
<< "\tresetting destination from " <<to;
+ to = *i;
+ LOG_AI
<< " to " << to;
+
steps.erase(i,steps.end());
+
while(steps.empty() == false && (!(info_.units.find(to) == info_.units.end() ||
from == to))){
+
to = *(steps.end()-1);
+
steps.pop_back();
+
LOG_AI << "\tresetting to " << from << " -> " << to << '\n';
+ }
+
+ break;
+ }
}
}
}
Modified: branches/1.4/src/unit.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/unit.cpp?rev=29165&r1=29164&r2=29165&view=diff
==============================================================================
--- branches/1.4/src/unit.cpp (original)
+++ branches/1.4/src/unit.cpp Mon Sep 1 14:53:23 2008
@@ -2784,6 +2784,18 @@
}
}
+void unit::ambush(const gamemap::location& loc) const
+{
+ invisibility_cache_.find(loc);
+ std::vector<const unit *>::iterator itor =
+ std::find(units_with_cache.begin(), units_with_cache.end(), this);
+
+ if(itor != units_with_cache.end()) {
+ units_with_cache.erase(itor);
+ }
+
+}
+
bool unit::invisible(const gamemap::location& loc,
const unit_map& units,const std::vector<team>& teams, bool
see_all) const
{
Modified: branches/1.4/src/unit.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/unit.hpp?rev=29165&r1=29164&r2=29165&view=diff
==============================================================================
--- branches/1.4/src/unit.hpp (original)
+++ branches/1.4/src/unit.hpp Mon Sep 1 14:53:23 2008
@@ -269,6 +269,11 @@
// Only see_all=true use caching
bool invisible(const gamemap::location& loc,
const unit_map& units,const std::vector<team>& teams, bool
see_all=true) const;
+ /**
+ * Make sure that invisibility cache is revalidate
+ * after ambush;
+ **/
+ void ambush(const gamemap::location& loc) const;
unit_race::GENDER generate_gender(const unit_type& type, bool gen,
game_state* state = 0);
std::string image_mods() const;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits