本文整理汇总了C++中player::has_trait方法的典型用法代码示例。如果您正苦于以下问题:C++ player::has_trait方法的具体用法?C++ player::has_trait怎么用?C++ player::has_trait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类player
的用法示例。
在下文中一共展示了player::has_trait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: is_fleeing
bool monster::is_fleeing(player &u)
{
// fleefactor is by default the agressiveness of the animal, minus the
// percentage of remaining HP times four. So, aggresiveness of 5 has a
// fleefactor of 2 AT MINIMUM.
if (type->hp == 0) {
debugmsg("%s has type->hp of 0!", type->name.c_str());
return false;
}
if (friendly != 0)
return false;
int fleefactor = type->agro - ((4 * (type->hp - hp)) / type->hp);
if (u.has_trait(PF_ANIMALEMPATH) && has_flag(MF_ANIMAL)) {
if (type->agro > 0) // Agressive animals flee instead
fleefactor -= 5;
else // Scared animals approach you
return false;
}
if (u.has_trait(PF_TERRIFYING))
fleefactor -= 1;
if (fleefactor > 0)
return false;
return true;
}
示例2: attack_speed
int attack_speed(player &u, bool missed)
{
int move_cost = u.weapon.attack_time() + 20 * u.encumb(bp_torso);
if (u.has_trait(PF_LIGHT_BONES))
move_cost *= .9;
if (u.has_trait(PF_HOLLOW_BONES))
move_cost *= .8;
move_cost -= u.disease_intensity(DI_SPEED_BOOST);
if (move_cost < 25)
return 25;
return move_cost;
}
示例3: key
virtual bool key(int key, int entnum, uimenu *menu) {
if ( key == 't' && p->has_trait( vTraits[ entnum ] ) ) {
if ( p->has_base_trait( vTraits[ entnum ] ) ) {
p->toggle_trait( vTraits[ entnum ] );
p->toggle_mutation( vTraits[ entnum ] );
} else {
p->toggle_mutation( vTraits[ entnum ] );
p->toggle_trait( vTraits[ entnum ] );
}
menu->entries[ entnum ].text_color = ( p->has_trait( vTraits[ entnum ] ) ? c_green : menu->text_color );
menu->entries[ entnum ].extratxt.txt= ( p->has_base_trait( vTraits[ entnum ] ) ? "T" : "" );
return true;
}
return false;
}
示例4: detect_trap
bool trap::detect_trap(const player &p, int x, int y) const
{
// Some decisions are based around:
// * Starting, and thus average perception, is 8.
// * Buried landmines, the silent killer, has a visibility of 10.
// * There will always be a distance malus of 1 unless you're on top of the trap.
// * ...and an average character should at least have a minor chance of
// noticing a buried landmine if standing right next to it.
// Effective Perception...
return (p.per_cur - p.encumb(bp_eyes)) +
// ...small bonus from stimulants...
(p.stim > 10 ? rng(1, 2) : 0) +
// ...bonus from trap skill...
(const_cast<player &>(p).skillLevel("traps") * 2) +
// ...luck, might be good, might be bad...
rng(-4, 4) -
// ...malus if we are tired...
(p.has_disease("lack_sleep") ? rng(1, 5) : 0) -
// ...malus farther we are from trap...
rl_dist(p.posx, p.posy, x, y) +
// Police are trained to notice Something Wrong.
(p.has_trait("PROF_POLICE") ? 1 : 0) +
(p.has_trait("PROF_PD_DET") ? 2 : 0) >
// ...must all be greater than the trap visibility.
visibility;
}
示例5: detect_trap
bool trap::detect_trap( const tripoint &pos, const player &p ) const
{
// Some decisions are based around:
// * Starting, and thus average perception, is 8.
// * Buried landmines, the silent killer, has a visibility of 10.
// * There will always be a distance malus of 1 unless you're on top of the trap.
// * ...and an average character should at least have a minor chance of
// noticing a buried landmine if standing right next to it.
// Effective Perception...
///\EFFECT_PER increases chance of detecting a trap
return ( p.per_cur - ( p.encumb( bp_eyes ) / 10 ) ) +
// ...small bonus from stimulants...
( p.stim > 10 ? rng( 1, 2 ) : 0 ) +
// ...bonus from trap skill...
///\EFFECT_TRAPS increases chance of detecting a trap
( p.get_skill_level( skill_traps ) * 2 ) +
// ...luck, might be good, might be bad...
rng( -4, 4 ) -
// ...malus if we are tired...
( p.has_effect( effect_lack_sleep ) ? rng( 1, 5 ) : 0 ) -
// ...malus farther we are from trap...
rl_dist( p.pos(), pos ) +
// Police are trained to notice Something Wrong.
( p.has_trait( trait_id( "PROF_POLICE" ) ) ? 1 : 0 ) +
( p.has_trait( trait_id( "PROF_PD_DET" ) ) ? 2 : 0 ) >
// ...must all be greater than the trap visibility.
visibility;
}
示例6: addiction_text
std::string addiction_text(player const& u, addiction const &cur)
{
int const strpen = 1 + cur.intensity / 7;
switch (cur.type) {
case ADD_CIG:
return _("Intelligence - 1; Occasional cravings");
case ADD_CAFFEINE:
return _("Strength - 1; Slight sluggishness; Occasional cravings");
case ADD_ALCOHOL:
return _("Perception - 1; Intelligence - 1; Occasional Cravings;\n"
"Risk of delirium tremens");
case ADD_SLEEP:
return _("You may find it difficult to sleep without medication.");
case ADD_PKILLER: {
if (u.has_trait("NOPAIN")) {
return string_format(_( "Strength - %d; Perception - 1; Dexterity - 1;\n"
"Depression. Frequent cravings. Vomiting."), strpen);
} else {
return string_format(_( "Strength - %d; Perception - 1; Dexterity - 1;\n"
"Depression and physical pain to some degree. Frequent cravings. Vomiting."), strpen);
}
}
case ADD_SPEED:
return _("Strength - 1; Intelligence - 1;\n"
"Movement rate reduction. Depression. Weak immune system. Frequent cravings.");
case ADD_COKE:
return _("Perception - 1; Intelligence - 1; Frequent cravings.");
case ADD_CRACK:
return _("Perception - 2; Intelligence - 2; Frequent cravings.");
case ADD_MUTAGEN:
return _("You've gotten a taste for mutating and the chemicals that cause it. But you can stop, yeah, any time you want.");
case ADD_DIAZEPAM:
return _("Perception - 1; Intelligence - 1;\n"
"Anxiety, nausea, hallucinations, and general malaise.");
case ADD_MARLOSS_R:
return _("You should try some of those pink berries.");
case ADD_MARLOSS_B:
return _("You should try some of those cyan seeds.");
case ADD_MARLOSS_Y:
return _("You should try some of that golden gel.");
default:
return "";
}
}
示例7: stumble
int stumble(player &u)
{
int stumble_pen = 2 * u.weapon.volume() + u.weapon.weight();
if (u.has_trait(PF_DEFT))
stumble_pen = int(stumble_pen * .3) - 10;
if (stumble_pen < 0)
stumble_pen = 0;
// TODO: Reflect high strength bonus in newcharacter.cpp
if (stumble_pen > 0 && (u.str_cur >= 15 || u.dex_cur >= 21 ||
one_in(16 - u.str_cur) || one_in(22 - u.dex_cur)))
stumble_pen = rng(0, stumble_pen);
return stumble_pen;
}
示例8: addict_effect
//.........这里部分代码省略.........
u.mod_str_bonus( -1 );
u.mod_per_bonus( -1 );
u.mod_dex_bonus( -1 );
if( u.get_pain() < in * 2 ) {
u.mod_pain( 1 );
}
if( one_in( 1200 - 30 * in ) ) {
u.mod_healthy_mod( -1, -in * 30 );
}
if( one_in( 20 ) && dice( 2, 20 ) < in ) {
u.add_msg_if_player( m_bad, _( "Your hands start shaking... you need some painkillers." ) );
u.add_morale( MORALE_CRAVING_OPIATE, -40, -10 * in );
u.add_effect( effect_shakes, 20 + in * 5 );
} else if( one_in( 20 ) && dice( 2, 30 ) < in ) {
u.add_msg_if_player( m_bad, _( "You feel anxious. You need your painkillers!" ) );
u.add_morale( MORALE_CRAVING_OPIATE, -30, -10 * in );
} else if( one_in( 50 ) && dice( 3, 50 ) < in ) {
u.vomit();
}
break;
case ADD_SPEED: {
u.mod_int_bonus( -1 );
u.mod_str_bonus( -1 );
if( u.stim > -100 && x_in_y( in, 20 ) ) {
u.stim--;
}
if( rng( 0, 150 ) <= in ) {
u.mod_healthy_mod( -1, -in );
}
if( dice( 2, 100 ) < in ) {
u.add_msg_if_player( m_warning, _( "You feel depressed. Speed would help." ) );
u.add_morale( MORALE_CRAVING_SPEED, -25, -20 * in );
} else if( one_in( 10 ) && dice( 2, 80 ) < in ) {
u.add_msg_if_player( m_bad, _( "Your hands start shaking... you need a pick-me-up." ) );
u.add_morale( MORALE_CRAVING_SPEED, -25, -20 * in );
u.add_effect( effect_shakes, in * 20 );
} else if( one_in( 50 ) && dice( 2, 100 ) < in ) {
u.add_msg_if_player( m_bad, _( "You stop suddenly, feeling bewildered." ) );
u.moves -= 300;
} else if( !u.has_effect( effect_hallu ) && one_in( 20 ) && 8 + dice( 2, 80 ) < in ) {
u.add_effect( effect_hallu, 3600 );
}
}
break;
case ADD_COKE:
case ADD_CRACK: {
static const std::string coke_msg = _( "You feel like you need a bump." );
static const std::string crack_msg = _( "You're shivering, you need some crack." );
const std::string &cur_msg = add.type == ADD_COKE ? coke_msg : crack_msg;
const auto morale_type = add.type == ADD_COKE ? MORALE_CRAVING_COCAINE : MORALE_CRAVING_CRACK;
u.mod_int_bonus( -1 );
u.mod_per_bonus( -1 );
if( one_in( 900 - 30 * in ) ) {
u.add_msg_if_player( m_warning, cur_msg.c_str() );
u.add_morale( morale_type, -20, -15 * in );
}
if( dice( 2, 80 ) <= in ) {
u.add_msg_if_player( m_warning, cur_msg.c_str() );
u.add_morale( morale_type, -20, -15 * in );
if( u.stim > -150 ) {
u.stim -= 3;
}
}
break;
}
case ADD_MUTAGEN:
if( u.has_trait( "MUT_JUNKIE" ) ) {
if( one_in( 600 - 50 * in ) ) {
u.add_msg_if_player( m_warning, rng( 0,
6 ) < in ? _( "You so miss the exquisite rainbow of post-humanity." ) :
_( "Your body is SOO booorrrring. Just a little sip to liven things up?" ) );
u.add_morale( MORALE_CRAVING_MUTAGEN, -20, -200 );
}
if( u.focus_pool > 40 && one_in( 800 - 20 * in ) ) {
u.focus_pool -= ( in );
u.add_msg_if_player( m_warning,
_( "You daydream what it'd be like if you were *different*. Different is good." ) );
}
} else if( in > 5 || one_in( ( 500 - 15 * in ) ) ) {
u.add_msg_if_player( m_warning, rng( 0, 6 ) < in ? _( "You haven't had any mutagen lately." ) :
_( "You could use some new parts..." ) );
u.add_morale( MORALE_CRAVING_MUTAGEN, -5, -50 );
}
break;
case ADD_MARLOSS_R:
marloss_add( u, in, _( "You daydream about luscious pink berries as big as your fist." ) );
break;
case ADD_MARLOSS_B:
marloss_add( u, in, _( "You daydream about nutty cyan seeds as big as your hand." ) );
break;
case ADD_MARLOSS_Y:
marloss_add( u, in, _( "You daydream about succulent, pale golden gel, sweet but light." ) );
break;
case ADD_NULL:
break;
}
}
示例9: hit_player
//.........这里部分代码省略.........
body_part_name(bphit, side).c_str());
}
}
// Attempt defensive moves
if (!is_npc)
{
if (g->u.activity.type == ACT_RELOAD)
{
g->add_msg(_("You stop reloading."));
}
else if (g->u.activity.type == ACT_READ)
{
g->add_msg(_("You stop reading."));
}
else if (g->u.activity.type == ACT_CRAFT || g->u.activity.type == ACT_LONGCRAFT)
{
g->add_msg(_("You stop crafting."));
g->u.activity.type = ACT_NULL;
}
}
if (p.has_active_bionic("bio_ods"))
{
if (!is_npc) {
g->add_msg(_("Your offensive defense system shocks it!"),
p.name.c_str());
} else if (u_see) {
g->add_msg(_("%s's offensive defense system shocks it!"),
p.name.c_str());
}
hurt(rng(10, 40));
}
if (p.encumb(bphit) == 0 &&(p.has_trait("SPINES") || p.has_trait("QUILLS")))
{
int spine = rng(1, (p.has_trait("QUILLS") ? 20 : 8));
if (is_npc) {
if( u_see ) {
g->add_msg(_("%1$s's %2$s puncture it!"), p.name.c_str(),
(g->u.has_trait("QUILLS") ? _("quills") : _("spines")));
}
} else {
g->add_msg(_("Your %s puncture it!"),
(g->u.has_trait("QUILLS") ? _("quills") : _("spines")));
}
hurt(spine);
}
if (dam + cut <= 0)
{
return; // Defensive technique canceled damage.
}
//Hallucinations don't actually hurt the player, but do produce the message
if(is_hallucination()) {
//~14% chance of vanishing after hitting the player
if(one_in(7)) {
die(g);
return;
}
} else {
//Hurt the player
dam = p.hit(g, bphit, side, dam, cut);
示例10: fire
void game::fire(player &p, int tarx, int tary, std::vector<point> &trajectory,
bool burst)
{
item ammotmp;
item* gunmod = p.weapon.active_gunmod();
it_ammo *curammo = NULL;
item *weapon = NULL;
if (p.weapon.has_flag(IF_CHARGE)) { // It's a charger gun, so make up a type
// Charges maxes out at 8.
int charges = p.weapon.num_charges();
it_ammo *tmpammo = dynamic_cast<it_ammo*>(itypes["charge_shot"]);
tmpammo->damage = charges * charges;
tmpammo->pierce = (charges >= 4 ? (charges - 3) * 2.5 : 0);
tmpammo->range = 5 + charges * 5;
if (charges <= 4)
tmpammo->accuracy = 14 - charges * 2;
else // 5, 12, 21, 32
tmpammo->accuracy = charges * (charges - 4);
tmpammo->recoil = tmpammo->accuracy * .8;
tmpammo->ammo_effects = 0;
if (charges == 8)
tmpammo->ammo_effects |= mfb(AMMO_EXPLOSIVE_BIG);
else if (charges >= 6)
tmpammo->ammo_effects |= mfb(AMMO_EXPLOSIVE);
if (charges >= 5)
tmpammo->ammo_effects |= mfb(AMMO_FLAME);
else if (charges >= 4)
tmpammo->ammo_effects |= mfb(AMMO_INCENDIARY);
if (gunmod != NULL) {
weapon = gunmod;
} else {
weapon = &p.weapon;
}
curammo = tmpammo;
weapon->curammo = tmpammo;
weapon->active = false;
weapon->charges = 0;
} else if (gunmod != NULL) {
weapon = gunmod;
curammo = weapon->curammo;
} else {// Just a normal gun. If we're here, we know curammo is valid.
curammo = p.weapon.curammo;
weapon = &p.weapon;
}
ammotmp = item(curammo, 0);
ammotmp.charges = 1;
if (!weapon->is_gun() && !weapon->is_gunmod()) {
debugmsg("%s tried to fire a non-gun (%s).", p.name.c_str(),
weapon->tname().c_str());
return;
}
bool is_bolt = false;
unsigned int effects = curammo->ammo_effects;
// Bolts and arrows are silent
if (curammo->type == AT_BOLT || curammo->type == AT_ARROW)
is_bolt = true;
int x = p.posx, y = p.posy;
// Have to use the gun, gunmods don't have a type
it_gun* firing = dynamic_cast<it_gun*>(p.weapon.type);
if (p.has_trait(PF_TRIGGERHAPPY) && one_in(30))
burst = true;
if (burst && weapon->burst_size() < 2)
burst = false; // Can't burst fire a semi-auto
bool u_see_shooter = u_see(p.posx, p.posy);
// Use different amounts of time depending on the type of gun and our skill
p.moves -= time_to_fire(p, firing);
// Decide how many shots to fire
int num_shots = 1;
if (burst)
num_shots = weapon->burst_size();
if (num_shots > weapon->num_charges() && !weapon->has_flag(IF_CHARGE))
num_shots = weapon->num_charges();
if (num_shots == 0)
debugmsg("game::fire() - num_shots = 0!");
// Set up a timespec for use in the nanosleep function below
timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = BULLET_SPEED;
// Use up some ammunition
int trange = trig_dist(p.posx, p.posy, tarx, tary);
if (trange < int(firing->volume / 3) && firing->ammo != AT_SHOT)
trange = int(firing->volume / 3);
else if (p.has_bionic("bio_targeting")) {
if (trange > LONG_RANGE)
trange = int(trange * .65);
else
trange = int(trange * .8);
}
if (firing->skill_used == Skill::skill("rifle") && trange > LONG_RANGE)
//.........这里部分代码省略.........
示例11: select
virtual void select(int entnum, uimenu *menu) {
if ( ! started ) {
started = true;
padding = std::string(menu->pad_right - 1, ' ');
for (std::map<std::string, trait>::iterator iter = traits.begin(); iter != traits.end(); ++iter) {
vTraits.push_back(iter->first);
pTraits[iter->first] = ( p->has_trait( iter->first ) );
}
}
int startx = menu->w_width - menu->pad_right;
for ( int i = 1; i < lastlen; i++ ) {
mvwprintw(menu->window, i, startx, "%s", padding.c_str() );
}
mvwprintw(menu->window, 1, startx,
mutation_data[vTraits[ entnum ]].valid ? _("Valid") : _("Nonvalid"));
int line2 = 2;
if ( !mutation_data[vTraits[entnum]].prereqs.empty() ) {
line2++;
mvwprintz(menu->window, line2, startx, c_ltgray, _("Prereqs:"));
for (int j = 0; j < mutation_data[vTraits[ entnum ]].prereqs.size(); j++) {
std::string mstr = mutation_data[vTraits[ entnum ]].prereqs[j];
mvwprintz(menu->window, line2, startx + 11, mcolor(mstr), "%s", traits[ mstr ].name.c_str());
line2++;
}
}
if ( !mutation_data[vTraits[entnum]].prereqs2.empty() ) {
line2++;
mvwprintz(menu->window, line2, startx, c_ltgray, _("Prereqs, 2d:"));
for (int j = 0; j < mutation_data[vTraits[ entnum ]].prereqs2.size(); j++) {
std::string mstr = mutation_data[vTraits[ entnum ]].prereqs2[j];
mvwprintz(menu->window, line2, startx + 15, mcolor(mstr), "%s", traits[ mstr ].name.c_str());
line2++;
}
}
if ( !mutation_data[vTraits[entnum]].threshreq.empty() ) {
line2++;
mvwprintz(menu->window, line2, startx, c_ltgray, _("Thresholds required:"));
for (int j = 0; j < mutation_data[vTraits[ entnum ]].threshreq.size(); j++) {
std::string mstr = mutation_data[vTraits[ entnum ]].threshreq[j];
mvwprintz(menu->window, line2, startx + 21, mcolor(mstr), "%s", traits[ mstr ].name.c_str());
line2++;
}
}
if ( !mutation_data[vTraits[entnum]].cancels.empty() ) {
line2++;
mvwprintz(menu->window, line2, startx, c_ltgray, _("Cancels:"));
for (int j = 0; j < mutation_data[vTraits[ entnum ]].cancels.size(); j++) {
std::string mstr = mutation_data[vTraits[ entnum ]].cancels[j];
mvwprintz(menu->window, line2, startx + 11, mcolor(mstr), "%s", traits[ mstr ].name.c_str());
line2++;
}
}
if ( !mutation_data[vTraits[entnum]].replacements.empty() ) {
line2++;
mvwprintz(menu->window, line2, startx, c_ltgray, _("Becomes:"));
for (int j = 0; j < mutation_data[vTraits[ entnum ]].replacements.size(); j++) {
std::string mstr = mutation_data[vTraits[ entnum ]].replacements[j];
mvwprintz(menu->window, line2, startx + 11, mcolor(mstr), "%s", traits[ mstr ].name.c_str());
line2++;
}
}
if ( !mutation_data[vTraits[entnum]].additions.empty() ) {
line2++;
mvwprintz(menu->window, line2, startx, c_ltgray, _("Add-ons:"));
for (int j = 0; j < mutation_data[vTraits[ entnum ]].additions.size(); j++) {
std::string mstr = mutation_data[vTraits[ entnum ]].additions[j];
mvwprintz(menu->window, line2, startx + 11, mcolor(mstr), "%s", traits[ mstr ].name.c_str());
line2++;
}
}
if ( !mutation_data[vTraits[entnum]].category.empty() ) {
line2++;
mvwprintz(menu->window, line2, startx, c_ltgray, _("Category:"));
for (int j = 0; j < mutation_data[vTraits[ entnum ]].category.size(); j++) {
mvwprintw(menu->window, line2, startx + 11, "%s", mutation_data[vTraits[ entnum ]].category[j].c_str());
line2++;
}
}
line2 += 2;
mvwprintz(menu->window, line2, startx, c_ltgray, "pts: %d vis: %d ugly: %d",
traits[vTraits[entnum]].points,
traits[vTraits[entnum]].visibility,
traits[vTraits[entnum]].ugliness
);
line2 += 2;
std::vector<std::string> desc = foldstring( traits[vTraits[ entnum ]].description,
menu->pad_right - 1 );
for( size_t j = 0; j < desc.size(); ++j ) {
mvwprintz(menu->window, line2, startx, c_ltgray, "%s", desc[j].c_str() );
//.........这里部分代码省略.........
示例12: hit_player
void monster::hit_player(game *g, player &p)
{
if (type->melee_dice == 0) // We don't attack, so just return
return;
bool is_npc = p.is_npc();
int junk;
bool u_see = (!is_npc || g->u_see(p.posx, p.posy, junk));
std::string you = (is_npc ? p.name : "you");
std::string your = (is_npc ? p.name + "'s" : "your");
std::string Your = (is_npc ? p.name + "'s" : "Your");
body_part bphit;
int side = rng(0, 1);
int dam = hit(p, bphit);
if (dam == 0 && u_see)
g->add_msg("The %s misses %s.", name().c_str(), you.c_str());
else if (dam > 0) {
if (u_see)
g->add_msg("The %s hits %s %s.", name().c_str(), your.c_str(),
body_part_name(bphit, side).c_str());
if (!is_npc) {
if (g->u.activity.type == ACT_RELOAD)
g->add_msg("You stop reloading.");
else if (g->u.activity.type == ACT_READ)
g->add_msg("You stop reading.");
else if (g->u.activity.type == ACT_CRAFT)
g->add_msg("You stop crafting.");
g->u.activity.type = ACT_NULL;
}
if (p.has_active_bionic(bio_ods)) {
if (u_see)
g->add_msg("%s offensive defense system shocks it!", Your.c_str());
hurt(rng(10, 40));
}
if (p.encumb(bphit) == 0 &&
(p.has_trait(PF_SPINES) || p.has_trait(PF_QUILLS))) {
int spine = rng(1, (p.has_trait(PF_QUILLS) ? 20 : 8));
g->add_msg("%s %s puncture it!", Your.c_str(),
(g->u.has_trait(PF_QUILLS) ? "quills" : "spines"));
hurt(spine);
}
p.hit(g, bphit, side, dam, type->melee_cut);
if (has_flag(MF_VENOM)) {
if (!is_npc)
g->add_msg("You're poisoned!");
p.add_disease(DI_POISON, 30, g);
} else if (has_flag(MF_BADVENOM)) {
if (!is_npc)
g->add_msg("You feel poison flood your body, wracking you with pain...");
p.add_disease(DI_BADPOISON, 40, g);
}
}
if (is_npc) {
if (p.hp_cur[hp_head] <= 0 || p.hp_cur[hp_torso] <= 0) {
npc* tmp = dynamic_cast<npc*>(&p);
tmp->die(g);
int index = g->npc_at(p.posx, p.posy);
g->active_npc.erase(g->active_npc.begin() + index);
plans.clear();
}
}
}
示例13: hit_player
void monster::hit_player(game *g, player &p, bool can_grab)
{
moves -= 100;
if (type->melee_dice == 0) // We don't attack, so just return
{
return;
}
add_effect(ME_HIT_BY_PLAYER, 3); // Make us a valid target for a few turns
if (has_flag(MF_HIT_AND_RUN))
{
add_effect(ME_RUN, 4);
}
bool is_npc = p.is_npc();
bool u_see = (!is_npc || g->u_see(p.posx, p.posy));
std::string you = (is_npc ? p.name : "you");
std::string You = (is_npc ? p.name : "You");
std::string your = (is_npc ? p.name + "'s" : "your");
std::string Your = (is_npc ? p.name + "'s" : "Your");
body_part bphit;
int side = rng(0, 1);
int dam = hit(g, p, bphit), cut = type->melee_cut, stab = 0;
technique_id tech = p.pick_defensive_technique(g, this, NULL);
p.perform_defensive_technique(tech, g, this, NULL, bphit, side, dam, cut, stab);
//110*e^(-.3*[melee skill of monster]) = % chance to miss. *100 to track .01%'s
//Returns ~80% at 1, drops quickly to 33% at 4, then slowly to 5% at 10 and 1% at 16
if (rng(0, 10000) < 11000 * exp(-.3 * type->melee_skill))
{
g->add_msg("The %s misses.", name().c_str());
}
else
{
//Reduce player's ability to dodge by monster's ability to hit
int dodge_ii = p.dodge(g) - rng(0, type->melee_skill);
if (dodge_ii < 0)
{
dodge_ii = 0;
}
// 100/(1+99*e^(-.6*[dodge() return modified by monster's skill])) = % chance to dodge
// *100 to track .01%'s
// 1% minimum, scales slowly to 16% at 5, then rapidly to 80% at 10,
// then returns less with each additional point, reaching 99% at 16
if (rng(0, 10000) < 10000/(1 + 99 * exp(-.6 * dodge_ii)))
{
g->add_msg("%s dodge the %s.", You.c_str(), name().c_str());
p.practice(g->turn, "dodge", type->melee_skill * 2); //Better monster = more skill gained
}
//Successful hit with damage
else if (dam > 0)
{
p.practice(g->turn, "dodge", type->melee_skill);
if (u_see && tech != TEC_BLOCK)
{
g->add_msg("The %s hits %s %s.", name().c_str(), your.c_str(),
body_part_name(bphit, side).c_str());
}
// Attempt defensive moves
if (!is_npc)
{
if (g->u.activity.type == ACT_RELOAD)
{
g->add_msg("You stop reloading.");
}
else if (g->u.activity.type == ACT_READ)
{
g->add_msg("You stop reading.");
}
else if (g->u.activity.type == ACT_CRAFT || g->u.activity.type == ACT_LONGCRAFT)
{
g->add_msg("You stop crafting.");
g->u.activity.type = ACT_NULL;
}
}
if (p.has_active_bionic("bio_ods"))
{
if (u_see)
{
g->add_msg("%s offensive defense system shocks it!", Your.c_str());
}
if (hurt(rng(10, 40)))
die(g);
}
if (p.encumb(bphit) == 0 &&(p.has_trait(PF_SPINES) || p.has_trait(PF_QUILLS)))
{
int spine = rng(1, (p.has_trait(PF_QUILLS) ? 20 : 8));
g->add_msg("%s %s puncture it!", Your.c_str(),
(g->u.has_trait(PF_QUILLS) ? "quills" : "spines"));
if (hurt(spine))
die(g);
}
if (dam + cut <= 0)
{
return; // Defensive technique canceled damage.
}
//.........这里部分代码省略.........
示例14: select
void select( int entnum, uimenu *menu ) override {
if( ! started ) {
started = true;
padding = std::string( menu->pad_right - 1, ' ' );
for( auto &traits_iter : mutation_branch::get_all() ) {
vTraits.push_back( traits_iter.first );
pTraits[traits_iter.first] = ( p->has_trait( traits_iter.first ) );
}
}
const mutation_branch &mdata = vTraits[entnum].obj();
int startx = menu->w_width - menu->pad_right;
for( int i = 2; i < lastlen; i++ ) {
mvwprintw( menu->window, i, startx, padding );
}
mvwprintw( menu->window, 3, startx,
mdata.valid ? _( "Valid" ) : _( "Nonvalid" ) );
int line2 = 4;
if( !mdata.prereqs.empty() ) {
line2++;
mvwprintz( menu->window, line2, startx, c_light_gray, _( "Prereqs:" ) );
for( auto &j : mdata.prereqs ) {
mvwprintz( menu->window, line2, startx + 11, mcolor( j ),
mutation_branch::get_name( j ) );
line2++;
}
}
if( !mdata.prereqs2.empty() ) {
line2++;
mvwprintz( menu->window, line2, startx, c_light_gray, _( "Prereqs, 2d:" ) );
for( auto &j : mdata.prereqs2 ) {
mvwprintz( menu->window, line2, startx + 15, mcolor( j ),
mutation_branch::get_name( j ) );
line2++;
}
}
if( !mdata.threshreq.empty() ) {
line2++;
mvwprintz( menu->window, line2, startx, c_light_gray, _( "Thresholds required:" ) );
for( auto &j : mdata.threshreq ) {
mvwprintz( menu->window, line2, startx + 21, mcolor( j ),
mutation_branch::get_name( j ) );
line2++;
}
}
if( !mdata.cancels.empty() ) {
line2++;
mvwprintz( menu->window, line2, startx, c_light_gray, _( "Cancels:" ) );
for( auto &j : mdata.cancels ) {
mvwprintz( menu->window, line2, startx + 11, mcolor( j ),
mutation_branch::get_name( j ) );
line2++;
}
}
if( !mdata.replacements.empty() ) {
line2++;
mvwprintz( menu->window, line2, startx, c_light_gray, _( "Becomes:" ) );
for( auto &j : mdata.replacements ) {
mvwprintz( menu->window, line2, startx + 11, mcolor( j ),
mutation_branch::get_name( j ) );
line2++;
}
}
if( !mdata.additions.empty() ) {
line2++;
mvwprintz( menu->window, line2, startx, c_light_gray, _( "Add-ons:" ) );
for( auto &j : mdata.additions ) {
mvwprintz( menu->window, line2, startx + 11, mcolor( j ),
mutation_branch::get_name( j ) );
line2++;
}
}
if( !mdata.types.empty() ) {
line2++;
mvwprintz( menu->window, line2, startx, c_light_gray, _( "Type:" ) );
for( auto &j : mdata.types ) {
mvwprintw( menu->window, line2, startx + 11, j );
line2++;
}
}
if( !mdata.category.empty() ) {
line2++;
mvwprintz( menu->window, line2, startx, c_light_gray, _( "Category:" ) );
for( auto &j : mdata.category ) {
mvwprintw( menu->window, line2, startx + 11, j );
line2++;
}
}
line2 += 2;
mvwprintz( menu->window, line2, startx, c_light_gray, "pts: %d vis: %d ugly: %d",
//.........这里部分代码省略.........
示例15: hit_player
void monster::hit_player(game *g, player &p, bool can_grab)
{
if (type->melee_dice == 0) // We don't attack, so just return
return;
add_effect(ME_HIT_BY_PLAYER, 3); // Make us a valid target for a few turns
if (has_flag(MF_HIT_AND_RUN))
add_effect(ME_RUN, 4);
bool is_npc = p.is_npc();
int junk;
bool u_see = (!is_npc || g->u_see(p.posx, p.posy, junk));
std::string you = (is_npc ? p.name : "you");
std::string You = (is_npc ? p.name : "You");
std::string your = (is_npc ? p.name + "'s" : "your");
std::string Your = (is_npc ? p.name + "'s" : "Your");
body_part bphit;
int side = rng(0, 1);
int dam = hit(g, p, bphit), cut = type->melee_cut, stab = 0;
technique_id tech = p.pick_defensive_technique(g, this, NULL);
p.perform_defensive_technique(tech, g, this, NULL, bphit, side,
dam, cut, stab);
if (dam == 0 && u_see)
g->add_msg("The %s misses %s.", name().c_str(), you.c_str());
else if (dam > 0) {
if (u_see && tech != TEC_BLOCK)
g->add_msg("The %s hits %s %s.", name().c_str(), your.c_str(),
body_part_name(bphit, side).c_str());
// Attempt defensive moves
if (!is_npc) {
if (g->u.activity.type == ACT_RELOAD)
g->add_msg("You stop reloading.");
else if (g->u.activity.type == ACT_READ)
g->add_msg("You stop reading.");
else if (g->u.activity.type == ACT_CRAFT)
g->add_msg("You stop crafting.");
g->u.activity.type = ACT_NULL;
}
if (p.has_active_bionic(bio_ods)) {
if (u_see)
g->add_msg("%s offensive defense system shocks it!", Your.c_str());
hurt(rng(10, 40));
}
if (p.encumb(bphit) == 0 &&
(p.has_trait(PF_SPINES) || p.has_trait(PF_QUILLS))) {
int spine = rng(1, (p.has_trait(PF_QUILLS) ? 20 : 8));
g->add_msg("%s %s puncture it!", Your.c_str(),
(g->u.has_trait(PF_QUILLS) ? "quills" : "spines"));
hurt(spine);
}
if (dam + cut <= 0)
return; // Defensive technique canceled damage.
p.hit(g, bphit, side, dam, cut);
if (has_flag(MF_VENOM)) {
if (!is_npc)
g->add_msg("You're poisoned!");
p.add_disease(DI_POISON, 30, g);
} else if (has_flag(MF_BADVENOM)) {
if (!is_npc)
g->add_msg("You feel poison flood your body, wracking you with pain...");
p.add_disease(DI_BADPOISON, 40, g);
}
if (has_flag(MF_BLEED) && dam > 6 && cut > 0) {
if (!is_npc)
g->add_msg("You're Bleeding!");
p.add_disease(DI_BLEED, 30, g);
}
if (can_grab && has_flag(MF_GRABS) &&
dice(type->melee_dice, 10) > dice(p.dodge(g), 10)) {
if (!is_npc)
g->add_msg("The %s grabs you!", name().c_str());
if (p.weapon.has_technique(TEC_BREAK, &p) &&
dice(p.dex_cur + p.skillLevel("melee").level(), 12) > dice(type->melee_dice, 10)){
if (!is_npc)
g->add_msg("You break the grab!");
} else
hit_player(g, p, false);
}
if (tech == TEC_COUNTER && !is_npc) {
g->add_msg("Counter-attack!");
hurt( p.hit_mon(g, this) );
}
} // if dam > 0
if (is_npc) {
if (p.hp_cur[hp_head] <= 0 || p.hp_cur[hp_torso] <= 0) {
npc* tmp = dynamic_cast<npc*>(&p);
tmp->die(g);
int index = g->npc_at(p.posx, p.posy);
if (index != -1 && index < g->active_npc.size())
g->active_npc.erase(g->active_npc.begin() + index);
plans.clear();
}
}
// Adjust anger/morale of same-species monsters, if appropriate
int anger_adjust = 0, morale_adjust = 0;
for (unsigned int i = 0; i < type->anger.size(); i++) {
if (type->anger[i] == MTRIG_FRIEND_ATTACKED)
anger_adjust += 15;
//.........这里部分代码省略.........