本文整理汇总了C++中unit_map::city_from_loc方法的典型用法代码示例。如果您正苦于以下问题:C++ unit_map::city_from_loc方法的具体用法?C++ unit_map::city_from_loc怎么用?C++ unit_map::city_from_loc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit_map
的用法示例。
在下文中一共展示了unit_map::city_from_loc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: can_up_treasure
bool can_up_treasure(unit_map& units, const hero& h)
{
if (tent::tower_mode()) {
return true;
}
unit* u = units.find_unit(h);
if (u->is_city()) {
return true;
}
artifical* city = units.city_from_loc(u->get_location());
if (city) {
return true;
}
return false;
}
示例2: add_modification
void hero::add_modification(unit_map& units, hero_map& heros, std::vector<team>& teams, const config& mod, unit* u, hero* leader)
{
foreach (const config &effect, mod.child_range("effect")) {
const std::string &apply_to = effect["apply_to"];
if (apply_to == "loyalty") {
int increase = effect["increase"].to_int();
if (increase) {
increase_catalog(-1 * increase, *leader);
if (!u->is_artifical()) {
u->adjust();
}
// play animation
std::stringstream str;
str << dgettext("wesnoth", "loyalty") << "\n";
std::vector<unit*> touchers;
if (artifical* city = units.city_from_loc(u->get_location())) {
touchers.push_back((unit*)(city));
} else {
touchers.push_back(u);
}
unit_display::unit_touching(u->get_location(), touchers, increase, str.str());
}
} else if (apply_to == "office") {
artifical* selected_city = unit_2_artifical(u);
status_ = hero_status_backing;
side_ = selected_city->side() - 1;
selected_city->finish_heros().push_back(this);
std::vector<hero*>& wander_heros = selected_city->wander_heros();
wander_heros.erase(std::find(wander_heros.begin(), wander_heros.end(), this));
std::string message = _("Let me join in. I will do my best to maintenance our honor.");
show_hero_message(this, selected_city, message, game_events::INCIDENT_RECOMMENDONESELF);
map_location loc2(MAGIC_HERO, number_);
game_events::fire("post_recommend", selected_city->get_location(), loc2);
} else if (apply_to == "wande") {
std::vector<hero*> captains;
if (artifical* city = units.city_from_loc(u->get_location())) {
// fresh/finish/reside troop
if (u->is_city()) {
for (int type = 0; type < 3; type ++) {
std::vector<hero*>* list;
if (type == 0) {
list = &city->fresh_heros();
} else if (type == 1) {
list = &city->finish_heros();
} else {
list = &city->wander_heros();
}
std::vector<hero*>::iterator i2 = std::find(list->begin(), list->end(), this);
if (i2 != list->end()) {
list->erase(i2);
break;
}
}
} else {
std::vector<unit*>& reside_troops = city->reside_troops();
int index = 0;
for (std::vector<unit*>::iterator i2 = reside_troops.begin(); i2 != reside_troops.end(); ++ i2, index ++) {
if (*i2 != u) {
continue;
}
u->replace_captains_internal(*this, captains);
if (captains.empty()) {
city->troop_go_out(index);
} else {
u->replace_captains(captains);
}
break;
}
}
} else {
// field troop
u->replace_captains_internal(*this, captains);
if (captains.empty()) {
units.erase(u);
} else {
u->replace_captains(captains);
}
}
// select one city in myself side
artifical* to_city = units.city_from_cityno(leader->city_);
to_city->wander_into(*this);
} else if (apply_to == "communicate") {
int increase = effect["increase"].to_int();
std::vector<std::pair<int, unit*> > pairs;
for (hero_map::iterator i = heros.begin(); i != heros.end(); ++ i) {
const hero& h = *i;
if (h.side_ != side_ || h.number_ == number_) {
continue;
}
unit* u = find_unit(units, h);
if (u->is_city() && h.number_ == u->master().number_) {
continue;
//.........这里部分代码省略.........