allow animation filtering on secondary unit

This commit is contained in:
Jérémy Rosen 2006-09-10 17:55:15 +00:00
parent c889b4364e
commit 87e8ffe410
4 changed files with 24 additions and 3 deletions

View file

@ -56,6 +56,7 @@ Version 1.3-svn:
* units now have levelin animations when they level into this unit
* units now have levelout animations when they level out of this unit
* animations can now use standard unit filters
* animations can now use standard unit filters on the secondary unit
* multiplayer game management
* client now tells the server if a game ended in victory or defeat
* configurable castle size for random map generator (patch #598, FR #3232)

View file

@ -288,6 +288,7 @@ public:
const std::vector<team>& get_teams() {return teams_;};
unit_map& get_units() {return units_;};
const unit_map& get_const_units() const {return units_;};
//compat methods to be dropped after full migration
void lock_updates(bool value) {screen_.lock_updates(value); };

View file

@ -117,6 +117,10 @@ unit_animation::unit_animation(const config& cfg,const std::string frame_string
unit_filter_.push_back(**itor);
}
for(itor = cfg.child_range("secondary_unit_filter").first; itor <cfg.child_range("secondary_unit_filter").second;itor++) {
secondary_unit_filter_.push_back(**itor);
}
/* warn on deprecated WML */
if(cfg.child("sound")) {
LOG_STREAM(err, config) << "an animation uses the deprecated [sound] tag, please include sound in the [frame] tag\n";
@ -146,12 +150,26 @@ int unit_animation::matches(const display& disp, const gamemap::location& loc,co
}
std::vector<config>::const_iterator myitor;
for(myitor = unit_filter_.begin(); myitor != unit_filter_.end(); myitor++) {
printf("trying\n");
myitor->debug();
if(!my_unit->matches_filter(*myitor,loc)) return -1;
printf("done\n");
result++;
}
if(!secondary_unit_filter_.empty()) {
const gamemap::location facing_loc = loc.get_direction(my_unit->facing());
unit_map::const_iterator unit;
for(unit=disp.get_const_units().begin() ; unit != disp.get_const_units().end() ; unit++) {
if(unit->first == facing_loc) {
std::vector<config>::const_iterator second_itor;
for(second_itor = secondary_unit_filter_.begin(); second_itor != secondary_unit_filter_.end(); second_itor++) {
if(!my_unit->matches_filter(*second_itor,facing_loc)) return -1;
result++;
}
break;
}
}
if(unit == disp.get_const_units().end()) return -1;
}
} else if (!unit_filter_.empty()) return -1;
return result;

View file

@ -40,6 +40,7 @@ class unit_animation:public animated<unit_frame>
private:
std::vector<std::string> terrain_types;
std::vector<config> unit_filter_;
std::vector<config> secondary_unit_filter_;
std::vector<gamemap::location::DIRECTION> directions;
};