Author: alink
Date: Sat Mar 22 23:55:07 2008
New Revision: 24995
URL: http://svn.gna.org/viewcvs/wesnoth?rev=24995&view=rev
Log:
Activate again the defense cache, because reading defense seems slow.
This make the previous defensive pathfinding feature much more cheap,
and probably helps the AI too, since it often use unit's defense.
Modified:
trunk/src/unit.cpp
trunk/src/unit.hpp
Modified: trunk/src/unit.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=24995&r1=24994&r2=24995&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Sat Mar 22 23:55:07 2008
@@ -124,6 +124,7 @@
max_movement_(o.max_movement_),
max_movement_b_(o.max_movement_b_),
movement_costs_(o.movement_costs_),
+ defense_mods_(o.defense_mods_),
hold_position_(o.hold_position_),
end_turn_(o.end_turn_),
resting_(o.resting_),
@@ -489,8 +490,9 @@
cfg_.clear_children("attack");
cfg_.clear_children("abilities");
- // Clear cache of movement costs
+ // Clear cache of movement costs and defense mods
movement_costs_.clear();
+ defense_mods_.clear();
if(t->movement_type().get_parent()) {
cfg_.merge_with(t->movement_type().get_parent()->get_cfg());
@@ -2113,10 +2115,10 @@
int unit::defense_modifier(t_translation::t_terrain terrain, int
recurse_count) const
{
-// const std::map<terrain_type::TERRAIN,int>::const_iterator i =
defense_mods_.find(terrain);
-// if(i != defense_mods_.end()) {
-// return i->second;
-// }
+ const std::map<t_translation::t_terrain,int>::const_iterator d =
defense_mods_.find(terrain);
+ if(d != defense_mods_.end()) {
+ return d->second;
+ }
assert(map_ != NULL);
// If this is an alias, then select the best of all underlying terrains
@@ -2149,8 +2151,7 @@
}
}
-//
defense_mods_.insert(std::pair<terrain_type::TERRAIN,int>(terrain,ret_value));
-
+
defense_mods_.insert(std::pair<t_translation::t_terrain,int>(terrain,ret_value));
return ret_value;
}
@@ -2176,7 +2177,7 @@
res = 0;
}
-// defense_mods_.insert(std::pair<terrain_type::TERRAIN,int>(terrain,res));
+
defense_mods_.insert(std::pair<t_translation::t_terrain,int>(terrain,res));
return res;
}
@@ -2619,6 +2620,7 @@
if (ap) {
mod_mdr_merge(*mv, *ap,
!utils::string_bool(replace));
}
+ defense_mods_.clear();
} else if (apply_to == "resistance") {
config *mv = cfg_.child("resistance");
config *ap =
(**i.first).child("resistance");
Modified: trunk/src/unit.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=24995&r1=24994&r2=24995&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Sat Mar 22 23:55:07 2008
@@ -337,6 +337,7 @@
int movement_;
int max_movement_, max_movement_b_;
mutable std::map<t_translation::t_terrain, int> movement_costs_; //
movement cost cache
+ mutable std::map<t_translation::t_terrain, int> defense_mods_; //
defense modifiers cache
bool hold_position_;
bool end_turn_;
bool resting_;
@@ -359,9 +360,6 @@
int unit_value_;
gamemap::location goto_, interrupted_move_;
bool flying_, is_fearless_, is_healthy_;
-
-// std::map<terrain_type::TERRAIN,int> movement_costs_,
movement_costs_b_;
-// std::map<terrain_type::TERRAIN,int> defense_mods_,
defense_mods_b_;
string_map modification_descriptions_;
// Animations:
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits