本文整理汇总了C++中unit_map::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ unit_map::begin方法的具体用法?C++ unit_map::begin怎么用?C++ unit_map::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit_map
的用法示例。
在下文中一共展示了unit_map::begin方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verify
static void verify(const unit_map& units, const config& cfg) {
std::stringstream errbuf;
LOG_REPLAY << "verifying unit structure...\n";
const size_t nunits = cfg["num_units"].to_size_t();
if(nunits != units.size()) {
errbuf << "SYNC VERIFICATION FAILED: number of units from data source differ: "
<< nunits << " according to data source. " << units.size() << " locally\n";
std::set<map_location> locs;
BOOST_FOREACH(const config &u, cfg.child_range("unit"))
{
const map_location loc(u);
locs.insert(loc);
if(units.count(loc) == 0) {
errbuf << "data source says there is a unit at "
<< loc << " but none found locally\n";
}
}
for(unit_map::const_iterator j = units.begin(); j != units.end(); ++j) {
if (locs.count(j->get_location()) == 0) {
errbuf << "local unit at " << j->get_location()
<< " but none in data source\n";
}
}
replay::process_error(errbuf.str());
errbuf.clear();
}
示例2:
unit_map::unit_map(const unit_map& that)
: umap_()
, lmap_()
{
for (const_unit_iterator i = that.begin(); i != that.end(); ++i) {
add(i->get_location(), *i);
}
}
示例3:
unit_map::unit_map(const unit_map& that) :
/* Initialize to silence compiler warnings. */
map_(),
lmap_(),
num_iters_(0),
num_invalid_(0)
{
for (const_unit_iterator i = that.begin(); i != that.end(); i++) {
add(i->first, i->second);
}
}
示例4: create_list
//-----------------------------------------------------------------//
unit_map_its create_list(const std::string& root)
{
unit_map_its list;
if(unit_map_.empty()) {
list.clear();
return list;
}
if(root.empty()) {
list.resize(unit_map_.size());
list.clear();
for(unit_map_it it = unit_map_.begin(); it != unit_map_.end(); ++it) {
list.push_back(it);
}
} else {
auto fpath = create_full_path(root);
if(fpath.empty()) {
list.clear();
return list;
}
unit_map_it it = unit_map_.find(fpath);
if(it != unit_map_.end()) {
const typename unit_t::childs& ch = it->second.get_childs();
list.resize(ch.size());
list.clear();
for(const auto& s : ch) {
auto path = create_full_path(s);
if(!path.empty()) {
it = unit_map_.find(path);
if(it != unit_map_.end()) {
list.push_back(it);
}
}
}
} else {
list.clear();
}
}
std::sort(list.begin(), list.end(), [] (unit_map_it l, unit_map_it r) {
return l->first < r->first; }
);
return list;
}
示例5: fill_object_list
void tmkwin_theme::fill_object_list(const unit_map& units)
{
tlistbox* list = dynamic_cast<tlistbox*>(get_object("object-list"));
list->clear();
const map_location& selected_hex = controller_.selected_hex();
std::stringstream ss;
int index = 0;
int cursel = 0;
for (unit_map::const_iterator it = units.begin(); it != units.end(); ++ it) {
unit& u = *dynamic_cast<unit*>(&*it);
if (u.type() != unit::WIDGET) {
continue;
}
if (u.get_location() == selected_hex) {
cursel = index;
}
string_map list_item;
std::map<std::string, string_map> list_item_item;
list_item["label"] = str_cast(index ++);
list_item_item.insert(std::make_pair("number", list_item));
list_item["label"] = u.cell().id;
list_item_item.insert(std::make_pair("id", list_item));
ss.str("");
const SDL_Rect& rect = u.get_rect();
// ss << rect.x << "," << rect.y << "," << rect.w << "," << rect.h;
ss << rect.x << "," << rect.y;
list_item["label"] = ss.str();
list_item_item.insert(std::make_pair("rect", list_item));
list->add_row(list_item_item);
tgrid* grid = list->get_row_grid(list->get_item_count() - 1);
grid->set_cookie(reinterpret_cast<void*>(&u));
}
if (list->get_item_count()) {
list->select_row(cursel);
}
list->invalidate_layout(true);
// window.invalidate_layout();
}
示例6: evaluate
void move_candidate_action::evaluate(ai::formula_ai* ai, unit_map& units)
{
score_ = 0;
candidate_action_filters::const_iterator me_filter = filter_map_.find("me");
std::vector<variant> unit_vector;
for(unit_map::unit_iterator i = units.begin() ; i != units.end() ; ++i)
{
if (i->side() == ai->get_side() && i->movement_left() > 0) {
unit_vector.push_back(variant(new unit_callable(*i)));
}
}
variant my_units(&unit_vector);
variant filtered_units;
try {
if(me_filter != filter_map_.end() )
filtered_units = do_filtering(ai, my_units, me_filter->second);
else
filtered_units=my_units;
}
catch(formula_error& e) {
ai->handle_exception(e, "Error while executing filter formula for '" + get_name() + "' Candidate Action");
return;
}
for(variant_iterator i = filtered_units.begin() ; i != filtered_units.end() ; ++i)
{
game_logic::map_formula_callable callable(static_cast<const formula_callable*>(ai));
callable.add("me", *i);
int res = execute_formula(eval_, callable, ai);
if(res > score_) {
score_ = res;
my_unit_ = *i;
}
}
}
示例7: verify
static void verify(const unit_map& units, const config& cfg) {
std::stringstream errbuf;
LOG_REPLAY << "verifying unit structure...\n";
const size_t nunits = cfg["num_units"].to_size_t();
if(nunits != units.size()) {
errbuf << "SYNC VERIFICATION FAILED: number of units from data source differ: "
<< nunits << " according to data source. " << units.size() << " locally\n";
std::set<map_location> locs;
for (const config &u : cfg.child_range("unit"))
{
const map_location loc(u);
locs.insert(loc);
if(units.count(loc) == 0) {
errbuf << "data source says there is a unit at "
<< loc << " but none found locally\n";
}
}
for(unit_map::const_iterator j = units.begin(); j != units.end(); ++j) {
if (locs.count(j->get_location()) == 0) {
errbuf << "local unit at " << j->get_location()
<< " but none in data source\n";
}
}
replay::process_error(errbuf.str());
errbuf.clear();
}
for (const config &un : cfg.child_range("unit"))
{
const map_location loc(un);
const unit_map::const_iterator u = units.find(loc);
if(u == units.end()) {
errbuf << "SYNC VERIFICATION FAILED: data source says there is a '"
<< un["type"] << "' (side " << un["side"] << ") at "
<< loc << " but there is no local record of it\n";
replay::process_error(errbuf.str());
errbuf.clear();
}
config u_cfg;
u->write(u_cfg);
bool is_ok = true;
static const std::string fields[] = {"type","hitpoints","experience","side",""};
for(const std::string* str = fields; str->empty() == false; ++str) {
if (u_cfg[*str] != un[*str]) {
errbuf << "ERROR IN FIELD '" << *str << "' for unit at "
<< loc << " data source: '" << un[*str]
<< "' local: '" << u_cfg[*str] << "'\n";
is_ok = false;
}
}
if(!is_ok) {
errbuf << "(SYNC VERIFICATION FAILED)\n";
replay::process_error(errbuf.str());
errbuf.clear();
}
}
LOG_REPLAY << "verification passed\n";
}