本文整理汇总了C++中unit_type类的典型用法代码示例。如果您正苦于以下问题:C++ unit_type类的具体用法?C++ unit_type怎么用?C++ unit_type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了unit_type类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: draw_item
void unit_palette::draw_item(SDL_Rect& dstrect, const unit_type& u, std::stringstream& tooltip_text) {
surface screen = gui_.video().getSurface();
const std::string filename = u.image();
surface image(image::get_image(filename));
if(image == NULL) {
tooltip_text << "IMAGE NOT FOUND\n";
ERR_ED << "image for terrain: '" << filename << "' not found\n";
image = image::get_image(game_config::images::missing);
if (image == NULL) {
ERR_ED << "Placeholder image not found\n";
return;
}
}
if(image->w != item_size_ || image->h != item_size_) {
image.assign(scale_surface(image,
item_size_, item_size_));
}
sdl_blit(image, NULL, screen, &dstrect);
tooltip_text << u.type_name();
}
开发者ID:ehsan,项目名称:wesnoth,代码行数:25,代码来源:unit_palette.cpp
示例2: compare_unit_types
int ai_default_recruitment_stage::compare_unit_types(const unit_type& a, const unit_type& b) const
{
const int a_effectiveness_vs_b = average_resistance_against(b,a);
const int b_effectiveness_vs_a = average_resistance_against(a,b);
LOG_AI << "comparison of '" << a.id() << " vs " << b.id() << ": "
<< a_effectiveness_vs_b << " - " << b_effectiveness_vs_a << " = "
<< (a_effectiveness_vs_b - b_effectiveness_vs_a) << '\n';
return a_effectiveness_vs_b - b_effectiveness_vs_a;
}
开发者ID:rasata,项目名称:wesnoth,代码行数:10,代码来源:ai.cpp
示例3: test_enough_gold
bool recruit_result::test_enough_gold(const team &my_team, const unit_type &type, bool)
{
if (my_team.gold() < type.cost()) {
set_error(E_NO_GOLD);
return false;
}
return true;
}
开发者ID:Yossarian,项目名称:WesnothAddonServer,代码行数:8,代码来源:actions.cpp
示例4: set_unit_mouse_overlay
void mouse_action_unit::set_unit_mouse_overlay(editor_display& disp, const unit_type& u)
{
std::stringstream filename;
filename << u.image() << "~RC(" << u.flag_rgb() << '>'
<< team::get_side_color_index(disp.viewing_side()) << ')';
surface image(image::get_image(filename.str()));
Uint8 alpha = 196;
//TODO don't hardcode
int size = 72;
//int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
// Add the alpha factor and scale the image
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
disp.set_mouseover_hex_overlay(image);
}
开发者ID:8680-wesnoth,项目名称:wesnoth-fork-old,代码行数:18,代码来源:mouse_action_unit.cpp
示例5: generate_utype_tree_internal
void tcore::generate_utype_tree_internal(const unit_type& current, std::vector<node>& advances_to, bool& to_branch)
{
for (std::vector<node>::iterator it2 = advances_to.begin(); it2 != advances_to.end(); ++ it2) {
const std::vector<std::string>& advances_to = it2->current->advances_to();
if (std::find(advances_to.begin(), advances_to.end(), current.id()) != advances_to.end()) {
it2->advances_to.push_back(node(¤t));
to_branch = true;
}
generate_utype_tree_internal(current, it2->advances_to, to_branch);
}
}
开发者ID:,项目名称:,代码行数:11,代码来源:
示例6: VALIDATE
void ai_default_recruitment_stage::get_combat_score_vs(const unit_type& ut, const std::string &enemy_type_id, int &score, int &weighting, int hitpoints, int max_hitpoints) const
{
const unit_type *enemy_info = unit_types.find(enemy_type_id);
VALIDATE(enemy_info, "Unknown unit type : " + enemy_type_id + " while scoring units.");
int weight = ut.cost();
if ((hitpoints>0) && (max_hitpoints>0)) {
weight = weight * hitpoints / max_hitpoints;
}
weighting += weight;
score += compare_unit_types(ut, *enemy_info) * weight;
}
开发者ID:rasata,项目名称:wesnoth,代码行数:12,代码来源:ai.cpp
示例7: draw_item
void unit_palette::draw_item(const unit_type& u, surface& image, std::stringstream& tooltip_text) {
std::stringstream filename;
filename << u.image() << "~RC(" << u.flag_rgb() << '>'
<< team::get_side_color_id(gui_.viewing_side()) << ')';
image = image::get_image(filename.str());
if(image == nullptr) {
tooltip_text << "IMAGE NOT FOUND\n";
ERR_ED << "image for unit type: '" << filename.str() << "' not found" << std::endl;
image = image::get_image(game_config::images::missing);
if(image == nullptr) {
ERR_ED << "Placeholder image not found" << std::endl;
return;
}
}
if(image->w != item_size_ || image->h != item_size_) {
image.assign(scale_surface(image, item_size_, item_size_));
}
tooltip_text << u.type_name();
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:23,代码来源:unit_palette.cpp
示例8: add_advancement
void unit_type_data::add_advancement(unit_type& to_unit) const
{
const config& cfg = to_unit.get_cfg();
for (const config &af : cfg.child_range("advancefrom"))
{
const std::string &from = af["unit"];
int xp = af["experience"];
unit_type_data::unit_type_map::iterator from_unit = types_.find(from);
if (from_unit == types_.end()) {
std::ostringstream msg;
msg << "unit type '" << from << "' not found when resolving [advancefrom] tag for '"
<< to_unit.log_id() << "'";
throw config::error(msg.str());
}
// Fix up advance_from references
from_unit->second.add_advancement(to_unit, xp);
DBG_UT << "Added advancement ([advancefrom]) from " << from << " to " << to_unit.log_id() << "\n";
}
}
开发者ID:PoignardAzur,项目名称:wesnoth,代码行数:24,代码来源:types.cpp
示例9: show_unit_description
void show_unit_description(CVideo& video, const unit_type &t)
{
std::string var_id = t.get_cfg()["variation_id"].str();
if (var_id.empty())
var_id = t.get_cfg()["variation_name"].str();
bool hide_help = t.hide_help();
bool use_variation = false;
if (!var_id.empty()) {
const unit_type *parent = unit_types.find(t.id());
assert(parent);
if (hide_help) {
hide_help = parent->hide_help();
} else {
use_variation = true;
}
}
if (use_variation)
help::show_variation_help(video, t.id(), var_id, hide_help);
else
help::show_unit_help(video, t.id(), t.show_variations_in_help(), hide_help);
}
开发者ID:Wedge009,项目名称:wesnoth,代码行数:22,代码来源:help.cpp
示例10: log_id
void unit_type::add_advancement(const unit_type &to_unit,int xp)
{
const std::string &to_id = to_unit.id_;
// Add extra advancement path to this unit type
LOG_CONFIG << "adding advancement from " << log_id() << " to " << to_unit.log_id() << "\n";
if(std::find(advances_to_.begin(), advances_to_.end(), to_id) == advances_to_.end()) {
advances_to_.push_back(to_id);
} else {
LOG_CONFIG << "advancement from " << log_id() << " to "
<< to_unit.log_id() << " already known, ignoring.\n";
return;
}
if(xp > 0) {
//xp is 0 in case experience= wasn't given.
if(!in_advancefrom_) {
//This function is called for and only for an [advancefrom] tag in a unit_type referencing this unit_type.
in_advancefrom_ = true;
experience_needed_ = xp;
DBG_UT << "Changing experience_needed from " << experience_needed_
<< " to " << xp << " due to (first) [advancefrom] of "
<< to_unit.log_id() << "\n";
}
else if(experience_needed_ > xp) {
experience_needed_ = xp;
DBG_UT << "Lowering experience_needed from " << experience_needed_
<< " to " << xp << " due to (multiple, lower) [advancefrom] of "
<< to_unit.log_id() << "\n";
}
else
DBG_UT << "Ignoring experience_needed change from " << experience_needed_
<< " to " << xp << " due to (multiple, higher) [advancefrom] of "
<< to_unit.log_id() << "\n";
}
// Add advancements to gendered subtypes, if supported by to_unit
for(int gender=0; gender<=1; ++gender) {
if(gender_types_[gender] == nullptr) continue;
if(to_unit.gender_types_[gender] == nullptr) {
WRN_CF << to_unit.log_id() << " does not support gender " << gender << std::endl;
continue;
}
LOG_CONFIG << "gendered advancement " << gender << ": ";
gender_types_[gender]->add_advancement(*(to_unit.gender_types_[gender]),xp);
}
if ( cfg_.has_child("variation") ) {
// Make sure the variations are created.
unit_types.build_unit_type(*this, VARIATIONS);
// Add advancements to variation subtypes.
// Since these are still a rare and special-purpose feature,
// we assume that the unit designer knows what they're doing,
// and don't block advancements that would remove a variation.
for(variations_map::iterator v=variations_.begin();
v!=variations_.end(); ++v) {
LOG_CONFIG << "variation advancement: ";
v->second->add_advancement(to_unit,xp);
}
}
}
开发者ID:PoignardAzur,项目名称:wesnoth,代码行数:62,代码来源:types.cpp
示例11: average_resistance_against
int ai_default_recruitment_stage::average_resistance_against(const unit_type& a, const unit_type& b) const
{
int weighting_sum = 0, defense = 0;
const std::map<t_translation::t_terrain, size_t>& terrain =
resources::gameboard->map().get_weighted_terrain_frequencies();
for (std::map<t_translation::t_terrain, size_t>::const_iterator j = terrain.begin(),
j_end = terrain.end(); j != j_end; ++j)
{
// Use only reachable tiles when computing the average defense.
if (a.movement_type().movement_cost(j->first) < movetype::UNREACHABLE) {
defense += a.movement_type().defense_modifier(j->first) * j->second;
weighting_sum += j->second;
}
}
if (weighting_sum == 0) {
// This unit can't move on this map, so just get the average weighted
// of all available terrains. This still is a kind of silly
// since the opponent probably can't recruit this unit and it's a static unit.
for (std::map<t_translation::t_terrain, size_t>::const_iterator jj = terrain.begin(),
jj_end = terrain.end(); jj != jj_end; ++jj)
{
defense += a.movement_type().defense_modifier(jj->first) * jj->second;
weighting_sum += jj->second;
}
}
if(weighting_sum != 0) {
defense /= weighting_sum;
} else {
ERR_AI << "The weighting sum is 0 and is ignored." << std::endl;
}
LOG_AI << "average defense of '" << a.id() << "': " << defense << "\n";
int sum = 0, weight_sum = 0;
// calculation of the average damage taken
bool steadfast = a.has_ability_by_id("steadfast");
bool poisonable = !a.musthave_status("unpoisonable");
const std::vector<attack_type>& attacks = b.attacks();
for (std::vector<attack_type>::const_iterator i = attacks.begin(),
i_end = attacks.end(); i != i_end; ++i)
{
int resistance = a.movement_type().resistance_against(*i);
// Apply steadfast resistance modifier.
if (steadfast && resistance < 100)
resistance = std::max<int>(resistance * 2 - 100, 50);
// Do not look for filters or values, simply assume 70% if CTH is customized.
int cth = i->get_special_bool("chance_to_hit", true) ? 70 : defense;
int weight = i->damage() * i->num_attacks();
// if cth == 0 the division will do 0/0 so don't execute this part
if (poisonable && cth != 0 && i->get_special_bool("poison", true)) {
// Compute the probability of not poisoning the unit.
int prob = 100;
for (int j = 0; j < i->num_attacks(); ++j)
prob = prob * (100 - cth);
// Assume poison works one turn.
weight += game_config::poison_amount * (100 - prob) / 100;
}
sum += cth * resistance * weight * weight; // average damage * weight
weight_sum += weight;
}
// normalize by HP
sum /= std::max<int>(1,std::min<int>(a.hitpoints(),1000)); // avoid values really out of range
// Catch division by zero here if the attacking unit
// has zero attacks and/or zero damage.
// If it has no attack at all, the ai shouldn't prefer
// that unit anyway.
if (weight_sum == 0) {
return sum;
}
return sum/weight_sum;
}
开发者ID:rasata,项目名称:wesnoth,代码行数:77,代码来源:ai.cpp
示例12: build_unit_type
/// Makes sure the provided unit_type is built to the specified level.
void build_unit_type(const unit_type & ut, unit_type::BUILD_STATUS status) const
{ ut.build(status, movement_types_, races_, unit_cfg_->child_range("trait")); }
开发者ID:,项目名称:,代码行数:3,代码来源:
示例13: vgettext
void tunit_preview_pane::set_displayed_type(const unit_type& type)
{
// Sets the current type id for the profile button callback to use
current_type_ = type.id();
if(icon_type_) {
std::string mods;
if(resources::controller) {
mods = "~RC(" + type.flag_rgb() + ">" +
team::get_side_color_index(resources::controller->current_side())
+ ")";
}
mods += "~SCALE_INTO_SHARP(144,144)" + image_mods_;
icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods);
}
if(label_name_) {
label_name_->set_label("<big>" + type.type_name() + "</big>");
label_name_->set_use_markup(true);
}
if(label_level_) {
std::string l_str = vgettext("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
label_level_->set_label("<b>" + l_str + "</b>");
label_level_->set_use_markup(true);
}
if(icon_race_) {
icon_race_->set_label("icons/unit-groups/race_" + type.race_id() + "_30.png");
icon_race_->set_tooltip(type.race()->name(type.genders().front()));
}
if(icon_alignment_) {
const std::string& alignment_name = type.alignment().to_string();
icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
icon_alignment_->set_tooltip(unit_type::alignment_description(
type.alignment(),
type.genders().front()));
}
if(tree_details_) {
std::stringstream str;
str << "<small>";
str << "<span color='#21e100'>"
<< "<b>" << _("HP: ") << "</b>" << type.hitpoints() << "</span>" << " | ";
str << "<span color='#00a0e1'>"
<< "<b>" << _("XP: ") << "</b>" << type.experience_needed() << "</span>" << " | ";
str << "<b>" << _("MP: ") << "</b>"
<< type.movement();
str << "</small>";
tree_details_->clear();
add_name_tree_node(
tree_details_->get_root_node(),
"item",
str.str()
);
// Print trait details
{
ttree_view_node* header_node = nullptr;
for(const auto& tr : type.possible_traits()) {
t_string name = tr[type.genders().front() == unit_race::FEMALE ? "female_name" : "male_name"];
if (tr["availability"] != "musthave" || name.empty()) {
continue;
}
if (header_node == nullptr) {
header_node = &add_name_tree_node(
tree_details_->get_root_node(),
"header",
"<b>" + _("Traits") + "</b>"
);
}
add_name_tree_node(
*header_node,
"item",
name
);
}
}
// Print ability details
if(!type.abilities().empty()) {
auto& header_node = add_name_tree_node(
tree_details_->get_root_node(),
"header",
"<b>" + _("Abilities") + "</b>"
);
//.........这里部分代码省略.........
开发者ID:aquileia,项目名称:wesnoth,代码行数:101,代码来源:unit_preview_pane.cpp
示例14: show_unit_description
void show_unit_description(const unit_type &t)
{
help::show_unit_help(*resources::screen, t.id(), t.hide_help());
}
开发者ID:bjrnt,项目名称:littlebobbytables,代码行数:4,代码来源:dialogs.cpp
注:本文中的unit_type类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论