bool u16_get_experience_i9(uint16_t* field, uint16_t inc_xp) { int integer; integer = fxptoi9(*field); if (*field + inc_xp < 65536) { *field += inc_xp; } else { *field = 65535; } return (fxptoi9(*field) > integer)? true: false; }
tduel::tduel(hero& left, hero& right) : left_(left) , right_(right) , turn_(0) , endturn_(NULL) , lskill0_(NULL) , lskill1_(NULL) , hp_(TOTAL_HP / 2) , finished_(false) { int larger_force, force_distance; setting_[0].force_ = fxptoi9(left.force_); setting_[1].force_ = fxptoi9(right.force_); if (setting_[0].force_ >= setting_[1].force_) { larger_force = 0; force_distance = setting_[0].force_ - setting_[1].force_; } else { larger_force = 1; force_distance = setting_[1].force_ - setting_[0].force_; } setting_[larger_force].count_ = MAX_CARDS; setting_[larger_force].min_point_ = LARGER_MIN_POINT; setting_[larger_force].max_point_ = LARGER_MAX_POINT; setting* t = setting_ + (larger_force ^ 1); if (force_distance == 0) { t->count_ = MAX_CARDS; t->min_point_ = LARGER_MIN_POINT; t->max_point_ = LARGER_MAX_POINT; } else { t->count_ = std::max(MIN_CARDS, MAX_CARDS - force_distance / 5); t->min_point_ = std::max(SMALLER_MIN_POINT, LARGER_MIN_POINT - (force_distance + 4) / 5); t->max_point_ = std::max(SMALLER_MAX_POINT, LARGER_MAX_POINT - (force_distance + 4) / 5); } for (int index = 0; index < 2; index ++) { if (index == 0) { setting_[index].skill_ = fxptoi12(left.skill_[hero_skill_hero]); } else { setting_[index].skill_ = fxptoi12(right.skill_[hero_skill_hero]); } if (!setting_[index].skill_) { setting_[index].skill_ = 1; } setting_[index].deadfight_ = false; setting_[index].fightback_ = false; } }
void set_hero(const hero_map& heros, hero& h) { config* ptr = NULL; if (config& cfg = prefs.child("hero")) { ptr = &cfg; } else { ptr = &prefs.add_child("hero"); } config& cfg = *ptr; std::stringstream str; cfg["name"] = h.name(); cfg["surname"] = h.surname(); cfg["biography"] = h.biography2(heros); cfg["leadership"] = fxptoi9(h.leadership_); cfg["force"] = fxptoi9(h.force_); cfg["intellect"] = fxptoi9(h.intellect_); cfg["spirit"] = fxptoi9(h.spirit_); cfg["charm"] = fxptoi9(h.charm_); cfg["gender"] = h.gender_; cfg["image"] = h.image_; for (int i = 0; i < HEROS_MAX_ARMS; i ++) { str.str(""); str << "arms" << i; cfg[str.str()] = fxptoi12(h.arms_[i]); } for (int i = 0; i < HEROS_MAX_SKILL; i ++) { str.str(""); str << "skill" << i; cfg[str.str()] = fxptoi12(h.skill_[i]); } cfg["base_catalog"] = h.base_catalog_; cfg["feature"] = h.feature_; cfg["side_feature"] = h.side_feature_; cfg["tactic"] = h.tactic_; cfg["utype"] = h.utype_; cfg["character"] = h.character_; write_preferences(); }
void fill_row(HWND hctl, hero& h) { std::stringstream strstr; char text[_MAX_PATH]; LVITEM lvi; int column = 0; lvi.mask = LVIF_TEXT | LVIF_PARAM; // 姓名 lvi.iItem = ListView_GetItemCount(hctl); lvi.iSubItem = column ++; int number = h.number_; strstr.str(""); strstr << std::setfill('0') << std::setw(3) << number << ": " << h.name(); strcpy(text, utf8_2_ansi(strstr.str().c_str())); lvi.pszText = text; lvi.lParam = (LPARAM)h.number_; ListView_InsertItem(hctl, &lvi); // 相性 lvi.mask = LVIF_TEXT; lvi.iSubItem = column ++; strstr.str(""); int value = h.base_catalog_; strstr << value; strcpy(text, strstr.str().c_str()); lvi.pszText = text; ListView_SetItem(hctl, &lvi); // 特技 lvi.mask = LVIF_TEXT; lvi.iSubItem = column ++; strcpy(text, utf8_2_ansi(hero::feature_str(h.feature_).c_str())); lvi.pszText = text; ListView_SetItem(hctl, &lvi); // 势力特技 lvi.mask = LVIF_TEXT; lvi.iSubItem = column ++; strcpy(text, utf8_2_ansi(hero::feature_str(h.side_feature_).c_str())); lvi.pszText = text; ListView_SetItem(hctl, &lvi); // 统帅 lvi.mask = LVIF_TEXT; lvi.iSubItem = column ++; sprintf(text, "%u.%u", fxptoi9(h.leadership_), fxpmod9(h.leadership_)); lvi.pszText = text; ListView_SetItem(hctl, &lvi); }
void trpg_detail::rpg_2_ui(twindow& window) { int value; std::stringstream str; const team& current_team = teams_[rpg::h->side_]; bool in_troop = !units_.find_unit(*rpg::h)->is_artifical(); // refresh to gui tlabel* label = find_widget<tlabel>(&window, "tip_name", false, true); str << _("Hero") << ": " << rpg::h->name(); label->set_label(str.str()); str.str(""); label = find_widget<tlabel>(&window, "tip_loyalty", false, true); int loyalty = rpg::h->loyalty(*teams_[rpg::h->side_].leader()); str << _("Loyalty") << ": " << loyalty; label->set_label(str.str()); // stratum str.str(""); label = find_widget<tlabel>(&window, "tip_stratum", false, true); str << _("Stratum") << ": " << hero::stratum_str(rpg::stratum); label->set_label(str.str()); // official str.str(""); label = find_widget<tlabel>(&window, "tip_official", false, true); str << dsgettext("wesnoth-hero", "official") << ": " << hero::official_str(rpg::h->official_); label->set_label(str.str()); // ownership str.str(""); str << _("Ownership") << ": "; str << units_.city_from_cityno(rpg::h->city_)->name(); label = find_widget<tlabel>(&window, "tip_ownership", false, true); label->set_label(str.str()); // meritorious str.str(""); value = rpg::h->meritorious_; str << dsgettext("wesnoth-hero", "meritorious") << ": " << value; label = find_widget<tlabel>(&window, "tip_meritorious", false, true); label->set_label(str.str()); str.str(""); if (rpg::stratum == hero_stratum_citizen) { utils::string_map symbols; std::string message; int statement_type = -1; if (!rpg::h->meritorious_ && !in_troop) { str << _("Wait, leader will order you to recruit"); } else if (rpg::h->meritorious_ < 1000) { symbols["meritorious"] = "1000"; statement_type = 0; } else if (rpg::h->meritorious_ < 2500) { symbols["meritorious"] = "2500"; statement_type = 0; } else if (rpg::h->meritorious_ < 5000) { symbols["meritorious"] = "5000"; statement_type = 0; } else if (rpg::h->meritorious_ < 8000) { symbols["meritorious"] = "8000"; statement_type = 1; } else { str << _("Get mroe meritorious, will be appointed mayor"); } if (statement_type == 0) { str << vgettext2("To $meritorious, will control more troops", symbols); } else if (statement_type == 1) { str << vgettext2("To $meritorious, will be appointed mayor", symbols); } } else if (rpg::stratum == hero_stratum_mayor) { if (current_team.holden_cities().size() < 2) { str << _("Capture more city, can be independent"); } else { str << _("Be independent will be to leader"); } } if (str.str().empty()) { str << _("---"); } label = find_widget<tlabel>(&window, "tip_meritorious2", false, true); label->set_label(str.str()); // leadership label = find_widget<tlabel>(&window, "tip_leadership", false, true); label->set_label(lexical_cast<std::string>(fxptoi9(rpg::h->leadership_))); // force label = find_widget<tlabel>(&window, "tip_force", false, true); label->set_label(lexical_cast<std::string>(fxptoi9(rpg::h->force_))); // intellect label = find_widget<tlabel>(&window, "tip_intellect", false, true); label->set_label(lexical_cast<std::string>(fxptoi9(rpg::h->intellect_))); // spirit label = find_widget<tlabel>(&window, "tip_spirit", false, true); label->set_label(lexical_cast<std::string>(fxptoi9(rpg::h->spirit_))); // charm label = find_widget<tlabel>(&window, "tip_charm", false, true); label->set_label(lexical_cast<std::string>(fxptoi9(rpg::h->charm_))); }
void ttactic2::pre_show(CVideo& /*video*/, twindow& window) { std::vector<hero*> captain; std::stringstream strstr; std::string color; const team& current_team = teams_[tactician_.side() - 1]; tlabel* title = find_widget<tlabel>(&window, "title", false, true); tbutton* ok = find_widget<tbutton>(&window, "ok", false, true); if (operate_ == CAST) { strstr.str(""); strstr << _("Cast tactic"); if (current_team.allow_intervene) { strstr << " (" << current_team.gold() << ")"; } title->set_label(strstr.str()); ok->set_label(_("tactic^Cast")); } else if (operate_ == ACTIVE) { title->set_label(_("Active tactic")); ok->set_label(_("tactic^Active")); } else { ok->set_visible(twidget::INVISIBLE); } tlistbox& tactic_list = find_widget<tlistbox>(&window, "tactic_list", false); std::map<int, std::vector<map_location> > touched; bool has_effect_unit; for (std::vector<hero*>::iterator it = candidate_.begin(); it != candidate_.end(); ++ it) { hero& h = **it; const ttactic& t = unit_types.tactic(h.tactic_); bool can_cast = tactician_.tactic_degree() >= t.point() * game_config::tactic_degree_per_point; if (!can_cast) { if (current_team.allow_intervene && (tactician_.hot_turns() || current_team.gold() >= t.cost())) { can_cast = true; } } std::map<std::string, string_map> data; string_map item; has_effect_unit = false; touched = t.touch_units(units_, tactician_); for (std::map<int, std::vector<map_location> >::const_iterator it2 = touched.begin(); it2 != touched.end(); ++ it2) { if (!it2->second.empty()) { has_effect_unit =true; break; } } strstr.str(""); strstr << h.image(); if (operate_ == CAST && (tactician_.provoked_turns() || !has_effect_unit)) { strstr << "~GS()"; } item["label"] = strstr.str(); data.insert(std::make_pair("icon", item)); strstr.str(""); if (!can_cast) { color = "red"; } else { color = ""; } if (operate_ != CAST) { strstr << "--/"; } strstr << tintegrate::generate_format(t.point(), color, 16, true); if (current_team.allow_intervene && tactician_.tactic_degree() < t.point() * game_config::tactic_degree_per_point && !tactician_.hot_turns()) { strstr << "\n"; strstr << tintegrate::generate_img("misc/gold.png"); strstr << tintegrate::generate_format(t.cost(), "", 16, true); } item["label"] = strstr.str(); data.insert(std::make_pair("point", item)); item["label"] = t.name(); data.insert(std::make_pair("name", item)); strstr.str(""); strstr << tintegrate::generate_format(ttactic::calculate_turn(fxptoi9(h.force_), fxptoi9(h.intellect_)), "blue", 16); item["label"] = strstr.str(); data.insert(std::make_pair("turn", item)); std::map<int, int> self_effect, friend_effect, enemy_effect; const std::vector<std::string>& atype_ids = unit_types.atype_ids(); const std::vector<const ttactic*>& parts = t.parts(); for (std::vector<const ttactic*>::const_iterator it2 = parts.begin(); it2 != parts.end(); ++ it2) { const ttactic& part = **it2; int range = part.range(); const config& effect_cfg = part.effect_cfg(); int apply_to = part.apply_to(); int level = 0; if (part.apply_to() == apply_to_tag::ATTACK) { level = effect_cfg["increase_damage"].to_int(); } else if (part.apply_to() == apply_to_tag::RESISTANCE) { const config& resistance_cfg = effect_cfg.child("resistance"); BOOST_FOREACH (const config::attribute &i, resistance_cfg.attribute_range()) { int resistance = i.second.to_int(); if (resistance == 35) { level = 3; } else if (resistance == 25) { level = 2; } else if (resistance == 15) { level = 1; } else if (resistance == -15) { level = -1; } else if (resistance == -25) { level = -2; } else { level = -3; } break; } } else if (part.apply_to() == apply_to_tag::MOVEMENT) { level = effect_cfg["increase"].to_int(); } else if (part.apply_to() == apply_to_tag::ENCOURAGE) { level = effect_cfg["increase"].to_int() / 2; } else if (part.apply_to() == apply_to_tag::DEMOLISH) { level = effect_cfg["increase"].to_int() / 2; } else if (part.apply_to() == apply_to_tag::DAMAGE) { std::vector<std::string>::const_iterator find = std::find(atype_ids.begin(), atype_ids.end(), effect_cfg["type"].str()); level = std::distance(atype_ids.begin(), find); } else if (part.apply_to() == apply_to_tag::ACTION) { level = effect_cfg["increase"].to_int(); if (level == -40) { level = -2; } else if (level == -20) { level = -1; } else if (level == 20) { level = 1; } else if (level == 40) { level = 2; } } if (range == ttactic::SELF) { self_effect.insert(std::make_pair(apply_to, level)); } else if (range == ttactic::FRIEND) { friend_effect.insert(std::make_pair(apply_to, level)); } else { enemy_effect.insert(std::make_pair(apply_to, level)); } } strstr.str(""); if (!self_effect.empty()) { strstr << tintegrate::generate_img("misc/range-self.png") << " " << generate_image_desc(self_effect); } if (!friend_effect.empty()) { if (!strstr.str().empty()) { strstr << "\n"; } strstr << tintegrate::generate_img("misc/range-friend.png") << " " << generate_image_desc(friend_effect); } if (!enemy_effect.empty()) { if (!strstr.str().empty()) { strstr << "\n"; } strstr << tintegrate::generate_img("misc/range-enemy.png") << " " << generate_image_desc(enemy_effect); } item["label"] = strstr.str(); data.insert(std::make_pair("effect", item)); if (cannot_valid_) { valid_.push_back(false); } else if (operate_ == CAST) { valid_.push_back(!tactician_.provoked_turns() && has_effect_unit && can_cast); } else if (operate_ != ACTIVE) { valid_.push_back(!tactician_.provoked_turns()); } else { valid_.push_back(true); } tactic_list.add_row(data); }
void trecruit::catalog_page(twindow& window, int catalog, bool swap) { if (catalog < MIN_PAGE || catalog > MAX_PAGE) { return; } int index = catalog - MIN_PAGE; if (window.alternate_index() == index) { // desired page is the displaying page, do nothing. return; } std::vector<int> features; std::stringstream str; int selected_row = 0; if (swap) { selected_row = hero_table_->get_selected_row(); } window.alternate_uh(hero_table_, index); const hero* rpg_hero = rpg::h; int hero_index = 0; int activity_ajdusted; const treasure_map& treasures = unit_types.treasures(); for (std::vector<hero*>::iterator itor = fresh_heros_.begin(); itor != fresh_heros_.end(); ++ itor, hero_index ++) { /*** Add list item ***/ string_map table_item; std::map<std::string, string_map> table_item_item; hero* h = *itor; if (catalog == ABILITY_PAGE) { table_item["use_markup"] = "true"; str.str(""); if (h->official_ == hero_official_commercial) { str << "<0,0,255>"; } else if (h->activity_ < HEROS_FULL_ACTIVITY) { str << "<255,0,0>"; } str << h->name(); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = lexical_cast<std::string>(h->loyalty(*teams_[h->side_].leader()));; table_item_item.insert(std::make_pair("loyalty", table_item)); table_item["label"] = hero::feature_str(h->feature_); table_item_item.insert(std::make_pair("feature", table_item)); str.str(""); if (h->activity_ < HEROS_FULL_ACTIVITY) { activity_ajdusted = 1 * h->leadership_ * h->activity_ / HEROS_FULL_ACTIVITY; str << fxptoi9(activity_ajdusted) << "/"; } str << fxptoi9(h->leadership_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("leadership", table_item)); str.str(""); if (h->activity_ < HEROS_FULL_ACTIVITY) { activity_ajdusted = 1 * h->force_ * h->activity_ / HEROS_FULL_ACTIVITY; str << fxptoi9(activity_ajdusted) << "/"; } str << fxptoi9(h->force_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("force", table_item)); str.str(""); if (h->activity_ < HEROS_FULL_ACTIVITY) { activity_ajdusted = 1 * h->intellect_ * h->activity_ / HEROS_FULL_ACTIVITY; str << fxptoi9(activity_ajdusted) << "/"; } str << fxptoi9(h->intellect_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("intellect", table_item)); str.str(""); if (h->activity_ < HEROS_FULL_ACTIVITY) { activity_ajdusted = 1 * h->politics_ * h->activity_ / HEROS_FULL_ACTIVITY; str << fxptoi9(activity_ajdusted) << "/"; } str << fxptoi9(h->politics_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("politics", table_item)); str.str(""); if (h->activity_ < HEROS_FULL_ACTIVITY) { activity_ajdusted = 1 * h->charm_ * h->activity_ / HEROS_FULL_ACTIVITY; str << fxptoi9(activity_ajdusted) << "/"; } str << fxptoi9(h->charm_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("charm", table_item)); str.str(""); str << 100 * h->activity_ / HEROS_FULL_ACTIVITY << "%"; table_item["label"] = str.str(); table_item_item.insert(std::make_pair("activity", table_item)); } else if (catalog == ADAPTABILITY_PAGE) { table_item["use_markup"] = "true"; str.str(""); if (h->official_ == hero_official_commercial) { str << "<0,0,255>"; } else if (h->activity_ < HEROS_FULL_ACTIVITY) { str << "<255,0,0>"; } str << h->name(); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[0]); table_item_item.insert(std::make_pair("arm0", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[1]); table_item_item.insert(std::make_pair("arm1", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[2]); table_item_item.insert(std::make_pair("arm2", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[3]); table_item_item.insert(std::make_pair("arm3", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[4]); table_item_item.insert(std::make_pair("arm4", table_item)); } else if (catalog == PERSONAL_PAGE) { table_item["use_markup"] = "true"; str.str(""); if (h->official_ == hero_official_commercial) { str << "<0,0,255>"; } else if (h->activity_ < HEROS_FULL_ACTIVITY) { str << "<255,0,0>"; } str << h->name(); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = hero::gender_str(h->gender_); table_item_item.insert(std::make_pair("gender", table_item)); str.str(""); str << hero::treasure_str(h->treasure_); if (h->treasure_ != HEROS_NO_TREASURE) { treasure_map::const_iterator it = treasures.find(h->treasure_); str << "("; if (it != treasures.end()) { for (std::vector<int>::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++ it2) { if (it2 == it->second.begin()) { str << hero::feature_str(*it2); } else { str << " " << hero::feature_str(*it2); } } } str << ")"; } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("treasure", table_item)); } else if (catalog == RELATION_PAGE) { table_item["use_markup"] = "true"; str.str(""); if (h->official_ == hero_official_commercial) { str << "<0,0,255>"; } else if (h->activity_ < HEROS_FULL_ACTIVITY) { str << "<255,0,0>"; } str << h->name(); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("name", table_item)); if (h->parent_[0].hero_ != HEROS_INVALID_NUMBER) { table_item["label"] = heros_[h->parent_[0].hero_].name(); } else { table_item["label"] = ""; } table_item_item.insert(std::make_pair("father", table_item)); if (h->parent_[1].hero_ != HEROS_INVALID_NUMBER) { table_item["label"] = heros_[h->parent_[1].hero_].name(); } else { table_item["label"] = ""; } table_item_item.insert(std::make_pair("mother", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_OATH; i ++) { if (h->oath_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h->oath_[i].hero_].name(); } else { str << " " << heros_[h->oath_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("oath", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_CONSORT; i ++) { if (h->consort_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h->consort_[i].hero_].name(); } else { str << " " << heros_[h->consort_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("consort", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_INTIMATE; i ++) { if (h->intimate_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h->intimate_[i].hero_].name(); } else { str << " " << heros_[h->intimate_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("intimate", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_HATE; i ++) { if (h->hate_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h->hate_[i].hero_].name(); } else { str << " " << heros_[h->hate_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("hate", table_item)); } hero_table_->add_row(table_item_item); tgrid* grid_ptr = hero_table_->get_row_grid(hero_index); ttoggle_button* toggle = dynamic_cast<ttoggle_button*>(grid_ptr->find("prefix", true)); toggle->set_callback_state_change(boost::bind(&trecruit::hero_toggled, this, _1)); toggle->set_data(hero_index); if (rpg_mode_ && h == rpg_hero) { toggle->set_active(false); toggle->set_value(true); if (!checked_heros_.count(hero_index)) { checked_heros_.insert(hero_index); } } else { if (checked_heros_.find(hero_index) != checked_heros_.end()) { toggle->set_value(true); } if (h->activity_ < game_config::minimal_activity) { toggle->set_active(false); } } } if (swap) { window.alternate_bh(hero_table_, index); hero_table_->select_row(selected_row); } }
void thero_selection::fill_table(tlistbox& list, int catalog) { std::vector<int> features; std::stringstream str; std::string color; hero& leader = *(*teams_)[side_ - 1].leader(); int hero_index = 0; for (std::vector<std::pair<int, unit*> >::iterator itor = pairs_.begin(); itor != pairs_.end(); ++ itor, hero_index ++) { /*** Add list item ***/ string_map table_item; std::map<std::string, string_map> table_item_item; hero& h = heros_[itor->first]; unit& u = *itor->second; int catalog_diff = posix_abs((int)leader.base_catalog_ - h.base_catalog_); if (catalog_diff > HERO_MAX_LOYALTY / 2) { catalog_diff = HERO_MAX_LOYALTY - catalog_diff; } if (catalog == OWNERSHIP_PAGE) { table_item["label"] = h.name(); table_item_item.insert(std::make_pair("name", table_item)); if (h.side_ != HEROS_INVALID_SIDE) { table_item["label"] = (*teams_)[h.side_].name(); } else { table_item["label"] = "---"; } table_item_item.insert(std::make_pair("side", table_item)); artifical* city = units_? units_->city_from_cityno(h.city_): NULL; if (city) { table_item["label"] = city->name(); } else { table_item["label"] = "---"; } table_item_item.insert(std::make_pair("city", table_item)); str.str(""); if (h.side_ != HEROS_INVALID_SIDE) { str << h.loyalty(leader); } else { str << "--"; } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("loyalty", table_item)); str.str(""); str << (int)h.base_catalog_; if (HERO_MAX_LOYALTY - catalog_diff >= game_config::move_loyalty_threshold) { color = "green"; } else if (HERO_MAX_LOYALTY - catalog_diff >= game_config::wander_loyalty_threshold) { color = "yellow"; } else { color = "red"; } str << "(" << tintegrate::generate_format(catalog_diff, color) << ")"; table_item["label"] = str.str(); table_item_item.insert(std::make_pair("hero_catalog", table_item)); str.str(""); if (!u.is_artifical()) { str << u.name() << _("name^Troop"); } else if (u.is_city()) { str << u.name(); } else { str << u.name() << u.type_name(); } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("position", table_item)); table_item["label"] = lexical_cast<std::string>(h.meritorious_); table_item_item.insert(std::make_pair("meritorious", table_item)); } else if (catalog == ABILITY_PAGE) { table_item["label"] = h.name(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = lexical_cast<std::string>(fxptoi9(h.leadership_)); table_item_item.insert(std::make_pair("leadership", table_item)); table_item["label"] = lexical_cast<std::string>(fxptoi9(h.force_)); table_item_item.insert(std::make_pair("force", table_item)); table_item["label"] = lexical_cast<std::string>(fxptoi9(h.intellect_)); table_item_item.insert(std::make_pair("intellect", table_item)); table_item["label"] = lexical_cast<std::string>(fxptoi9(h.spirit_)); table_item_item.insert(std::make_pair("spirit", table_item)); table_item["label"] = lexical_cast<std::string>(fxptoi9(h.charm_)); table_item_item.insert(std::make_pair("charm", table_item)); table_item["label"] = hero::status_str(h.status_); table_item_item.insert(std::make_pair("action", table_item)); } else if (catalog == FEATURE_PAGE) { table_item["label"] = h.name(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = hero::feature_str(h.feature_); table_item_item.insert(std::make_pair("feature", table_item)); table_item["label"] = hero::feature_desc_str(h.feature_); table_item_item.insert(std::make_pair("explain", table_item)); } else if (catalog == ADAPTABILITY_PAGE) { table_item["label"] = h.name(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = hero::adaptability_str2(h.arms_[0]); table_item_item.insert(std::make_pair("arm0", table_item)); table_item["label"] = hero::adaptability_str2(h.arms_[1]); table_item_item.insert(std::make_pair("arm1", table_item)); table_item["label"] = hero::adaptability_str2(h.arms_[2]); table_item_item.insert(std::make_pair("arm2", table_item)); table_item["label"] = hero::adaptability_str2(h.arms_[3]); table_item_item.insert(std::make_pair("arm3", table_item)); table_item["label"] = hero::adaptability_str2(h.arms_[4]); table_item_item.insert(std::make_pair("arm4", table_item)); } else if (catalog == COMMAND_PAGE) { table_item["label"] = h.name(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = "----"; table_item_item.insert(std::make_pair("command", table_item)); } else if (catalog == PERSONAL_PAGE) { table_item["label"] = h.name(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = hero::gender_str(h.gender_); table_item_item.insert(std::make_pair("gender", table_item)); } else if (catalog == RELATION_PAGE) { table_item["label"] = h.name(); table_item_item.insert(std::make_pair("name", table_item)); if (h.parent_[0].hero_ != HEROS_INVALID_NUMBER) { table_item["label"] = heros_[h.parent_[0].hero_].name(); } else { table_item["label"] = ""; } table_item_item.insert(std::make_pair("father", table_item)); if (h.parent_[1].hero_ != HEROS_INVALID_NUMBER) { table_item["label"] = heros_[h.parent_[1].hero_].name(); } else { table_item["label"] = ""; } table_item_item.insert(std::make_pair("mother", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_OATH; i ++) { if (h.oath_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h.oath_[i].hero_].name(); } else { str << " " << heros_[h.oath_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("oath", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_CONSORT; i ++) { if (h.consort_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h.consort_[i].hero_].name(); } else { str << " " << heros_[h.consort_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("consort", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_INTIMATE; i ++) { if (h.intimate_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h.intimate_[i].hero_].name(); } else { str << " " << heros_[h.intimate_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("intimate", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_HATE; i ++) { if (h.hate_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h.hate_[i].hero_].name(); } else { str << " " << heros_[h.hate_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("hate", table_item)); } list.add_row(table_item_item); twidget* grid_ptr = list.get_row_panel(hero_index); ttoggle_button* toggle = dynamic_cast<ttoggle_button*>(grid_ptr->find("prefix", true)); toggle->set_callback_state_change(boost::bind(&thero_selection::hero_toggled, this, _1)); toggle->set_data(hero_index); if (checked_pairs_.find(hero_index) != checked_pairs_.end()) { toggle->set_value(true); } bool enable = true; for (std::vector<std::string>::const_iterator it2 = disables_.begin(); it2 != disables_.end() && enable; ++ it2) { const std::string& tag = *it2; if (tag == "loyalty") { if (h.side_ != HEROS_INVALID_SIDE) { hero& ownership_leader = *(*teams_)[h.side_].leader(); if (ownership_leader.base_catalog_ == h.base_catalog_) { enable = false; } } } else if (tag == "hate") { if (leader.is_hate(h)) { enable = false; } } } if (enable && h.player_ == HEROS_INVALID_NUMBER && std::find(disables_.begin(), disables_.end(), "member") != disables_.end()) { if (runtime_groups::exist_member(h, leader)) { toggle->set_active(false); } } if (!enable) { // grid_ptr->set_active(false); toggle->set_active(false); } } }
void temploy::pre_show(CVideo& /*video*/, twindow& window) { std::stringstream strstr; int value; if (browse_) { tlabel* label = find_widget<tlabel>(&window, "flag", false, true); strstr.str(""); strstr << "(" << _("Browse") << ")"; label->set_label(strstr.str()); } tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true); for (std::vector<hero*>::const_iterator it = emploies_.begin(); it != emploies_.end(); ++ it) { hero& h = **it; /*** Add list item ***/ string_map list_item; std::map<std::string, string_map> list_item_item; strstr.str(""); strstr << h.image(); if (current_team_.gold() < h.cost_ * ratio_) { strstr << "~GS()"; } list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("icon", list_item)); // name strstr.str(""); if (h.utype_ != HEROS_NO_UTYPE) { const unit_type* ut = unit_types.keytype(h.utype_); strstr << tintegrate::generate_img(ut->icon()) << "\n"; } strstr << h.name(); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("name", list_item)); // cost strstr.str(""); value = h.cost_ * ratio_; strstr << value; list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("cost", list_item)); // leadership strstr.str(""); strstr << fxptoi9(h.leadership_); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("leadership", list_item)); // charm strstr.str(""); strstr << fxptoi9(h.charm_); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("charm", list_item)); // feature strstr.str(""); strstr << hero::feature_str(h.feature_); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("feature", list_item)); // tactic strstr.str(""); if (h.tactic_ != HEROS_NO_TACTIC) { strstr << unit_types.tactic(h.tactic_).name(); } list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("tactic", list_item)); list->add_row(list_item_item); tgrid* grid = list->get_row_grid(list->get_item_count() - 1); twidget* widget = grid->find("human", false); widget->set_visible(twidget::INVISIBLE); } list->set_callback_value_change(dialog_callback<temploy, &temploy::type_selected>); connect_signal_mouse_left_click( find_widget<tbutton>(&window, "detail", false) , boost::bind( &temploy::detail , this , boost::ref(window))); set_ok_active(window); refresh_tooltip(window); }
void tinterior::catalog_page(twindow& window, int catalog, bool swap) { if (catalog < MIN_PAGE || catalog > MAX_PAGE) { return; } int index = catalog - MIN_PAGE; if (window.alternate_index() == index) { // desired page is the displaying page, do nothing. return; } std::vector<int> features; std::stringstream str; int selected_row = 0; if (swap) { selected_row = hero_table_->get_selected_row(); } window.alternate_uh(hero_table_, index); int hero_index = 0; for (std::vector<hero*>::iterator itor = fresh_heros_.begin(); itor != fresh_heros_.end(); ++ itor, hero_index ++) { /*** Add list item ***/ string_map table_item; std::map<std::string, string_map> table_item_item; hero* h = *itor; if (catalog == ABILITY_PAGE) { str.str(""); str << "<format>"; if (h->official_ == hero_official_mayor) { str << "color=blue "; } else if (h->official_ != HEROS_NO_OFFICIAL) { str << "color=red "; } str << "text='" << h->name() << "'</format>"; table_item["label"] = str.str(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = lexical_cast<std::string>(h->loyalty(*teams_[h->side_].leader()));; table_item_item.insert(std::make_pair("loyalty", table_item)); str.str(""); str << fxptoi9(h->politics_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("politics", table_item)); str.str(""); str << hero::adaptability_str2(h->skill_[hero_skill_commercial]); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("commercial", table_item)); str.str(""); str << hero::adaptability_str2(h->skill_[hero_skill_invent]); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("technology", table_item)); table_item["label"] = hero::feature_str(h->feature_); table_item_item.insert(std::make_pair("feature", table_item)); str.str(""); str << fxptoi9(h->leadership_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("leadership", table_item)); str.str(""); str << fxptoi9(h->intellect_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("intellect", table_item)); str.str(""); str << fxptoi9(h->charm_); table_item["label"] = str.str(); table_item_item.insert(std::make_pair("charm", table_item)); } else if (catalog == ADAPTABILITY_PAGE) { str.str(""); str << "<format>"; if (h->official_ == hero_official_mayor) { str << "color=blue "; } else if (h->official_ != HEROS_NO_OFFICIAL) { str << "color=red "; } str << "text='" << h->name() << "'</format>"; table_item["label"] = str.str(); table_item_item.insert(std::make_pair("name", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[0]); table_item_item.insert(std::make_pair("arm0", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[1]); table_item_item.insert(std::make_pair("arm1", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[2]); table_item_item.insert(std::make_pair("arm2", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[3]); table_item_item.insert(std::make_pair("arm3", table_item)); table_item["label"] = hero::adaptability_str2(h->arms_[4]); table_item_item.insert(std::make_pair("arm4", table_item)); } else if (catalog == RELATION_PAGE) { str.str(""); str << "<format>"; if (h->official_ == hero_official_mayor) { str << "color=blue "; } else if (h->official_ != HEROS_NO_OFFICIAL) { str << "color=red "; } str << "text='" << h->name() << "'</format>"; table_item["label"] = str.str(); table_item_item.insert(std::make_pair("name", table_item)); if (h->parent_[0].hero_ != HEROS_INVALID_NUMBER) { table_item["label"] = heros_[h->parent_[0].hero_].name(); } else { table_item["label"] = ""; } table_item_item.insert(std::make_pair("father", table_item)); if (h->parent_[1].hero_ != HEROS_INVALID_NUMBER) { table_item["label"] = heros_[h->parent_[1].hero_].name(); } else { table_item["label"] = ""; } table_item_item.insert(std::make_pair("mother", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_OATH; i ++) { if (h->oath_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h->oath_[i].hero_].name(); } else { str << " " << heros_[h->oath_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("oath", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_CONSORT; i ++) { if (h->consort_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h->consort_[i].hero_].name(); } else { str << " " << heros_[h->consort_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("consort", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_INTIMATE; i ++) { if (h->intimate_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h->intimate_[i].hero_].name(); } else { str << " " << heros_[h->intimate_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("intimate", table_item)); str.str(""); for (uint32_t i = 0; i < HEROS_MAX_HATE; i ++) { if (h->hate_[i].hero_ != HEROS_INVALID_NUMBER) { if (i == 0) { str << heros_[h->hate_[i].hero_].name(); } else { str << " " << heros_[h->hate_[i].hero_].name(); } } } table_item["label"] = str.str(); table_item_item.insert(std::make_pair("hate", table_item)); } hero_table_->add_row(table_item_item); tgrid* grid_ptr = hero_table_->get_row_grid(hero_index); ttoggle_button* toggle = dynamic_cast<ttoggle_button*>(grid_ptr->find("prefix", true)); toggle->set_callback_state_change(boost::bind(&tinterior::hero_toggled, this, _1)); toggle->set_data(hero_index); if (checked_hero_ == hero_index) { toggle->set_value(true); } if (browse_) { toggle->set_active(false); } else if (h->official_ != HEROS_NO_OFFICIAL && h->official_ != hero_official_mayor) { toggle->set_active(false); } else if (h->loyalty(*current_team_.leader()) < game_config::wander_loyalty_threshold) { toggle->set_active(false); } } if (swap) { window.alternate_bh(hero_table_, index); hero_table_->select_row(selected_row); } }
void texile::fill_exile_table(twindow& window, int cursel) { std::stringstream strstr; int value; tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true); list->clear(); const std::vector<tgroup::tmember>& exiles = group_.exiles(); for (std::vector<tgroup::tmember>::const_iterator it = exiles.begin(); it != exiles.end(); ++ it) { const tgroup::tmember& m = *it; hero& h = *m.h; /*** Add list item ***/ string_map list_item; std::map<std::string, string_map> list_item_item; strstr.str(""); strstr << (std::distance(exiles.begin(), it) + 1); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("index", list_item)); strstr.str(""); strstr << h.image(); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("icon", list_item)); // name strstr.str(""); if (h.utype_ != HEROS_NO_UTYPE) { const unit_type* ut = unit_types.keytype(h.utype_); strstr << tintegrate::generate_img(ut->icon()) << "\n"; } strstr << h.name(); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("name", list_item)); // level strstr.str(""); if (m.level / game_config::levels_per_rank >= 2) { strstr << _("rank^Gold"); } else if (m.level / game_config::levels_per_rank >= 1) { strstr << _("rank^Silver"); } else { strstr << _("rank^Copper"); } strstr << "(" << (m.level % game_config::levels_per_rank + 1) << ")"; list_item["label"] = "--"; list_item_item.insert(std::make_pair("level", list_item)); // cost strstr.str(""); value = h.cost_; strstr << value; list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("cost", list_item)); // leadership strstr.str(""); strstr << fxptoi9(h.leadership_); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("leadership", list_item)); // charm strstr.str(""); strstr << fxptoi9(h.charm_); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("charm", list_item)); // feature strstr.str(""); strstr << hero::feature_str(h.feature_); list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("feature", list_item)); // tactic strstr.str(""); if (h.tactic_ != HEROS_NO_TACTIC) { strstr << unit_types.tactic(h.tactic_).name(); } else if (m.base->tactic_ != HEROS_NO_TACTIC) { strstr << tintegrate::generate_format(unit_types.tactic(m.base->tactic_).name(), "red"); } list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("tactic", list_item)); list->add_row(list_item_item); tgrid* grid = list->get_row_grid(list->get_item_count() - 1); ttoggle_panel* toggle = dynamic_cast<ttoggle_panel*>(grid->find("_toggle", true)); toggle->set_data(h.number_); } if (cursel >= (int)exiles.size()) { cursel = (int)exiles.size() - 1; } if (!exiles.empty()) { list->select_row(cursel); } selected_number_ = exiles.size()? exiles[cursel].h->number_: HEROS_INVALID_NUMBER; refresh_title_flag(window); set_2button_active(window); window.invalidate_layout(); }