// footsteps will determine how loud a monster's normal movement is // and create a sound in the monsters location when they move void monster::footsteps(int x, int y) { if (made_footstep) return; if (has_flag(MF_FLIES)) return; // Flying monsters don't have footsteps! made_footstep = true; int volume = 6; // same as player's footsteps if (digging()) volume = 10; switch (type->size) { case MS_TINY: return; // No sound for the tinies case MS_SMALL: volume /= 3; break; case MS_MEDIUM: break; case MS_LARGE: volume *= 1.5; break; case MS_HUGE: volume *= 2; break; default: break; } int dist = rl_dist(x, y, g->u.posx, g->u.posy); g->add_footstep(x, y, volume, dist, this); return; }
// footsteps will determine how loud a monster's normal movement is // and create a sound in the monsters location when they move void monster::footsteps( const tripoint &p ) { if( made_footstep ) { return; } if( has_flag( MF_FLIES ) ) { return; // Flying monsters don't have footsteps! } made_footstep = true; int volume = 6; // same as player's footsteps if( digging() ) { volume = 10; } switch( type->size ) { case MS_TINY: return; // No sound for the tinies case MS_SMALL: volume /= 3; break; case MS_MEDIUM: break; case MS_LARGE: volume *= 1.5; break; case MS_HUGE: volume *= 2; break; default: break; } int dist = rl_dist( p, g->u.pos() ); sounds::add_footstep( p, volume, dist, this ); return; }
int monster::hit(game *g, player &p, body_part &bp_hit) { int ret = 0; int highest_hit = 0; //If the player is knocked down or the monster can fly, any body part is a valid target if(p.is_on_ground() || has_flag(MF_FLIES)){ highest_hit = 20; } else { switch (type->size) { case MS_TINY: highest_hit = 3; break; case MS_SMALL: highest_hit = 12; break; case MS_MEDIUM: highest_hit = 20; break; case MS_LARGE: highest_hit = 28; break; case MS_HUGE: highest_hit = 35; break; } if (digging()){ highest_hit -= 8; } if (highest_hit <= 1){ highest_hit = 2; } } if (highest_hit > 20){ highest_hit = 20; } int bp_rand = rng(0, highest_hit - 1); if (bp_rand <= 2){ bp_hit = bp_legs; } else if (bp_rand <= 10){ bp_hit = bp_torso; } else if (bp_rand <= 14){ bp_hit = bp_arms; } else if (bp_rand <= 16){ bp_hit = bp_mouth; } else if (bp_rand == 17){ bp_hit = bp_eyes; } else{ bp_hit = bp_head; } ret += dice(type->melee_dice, type->melee_sides); return ret; }
int monster::calc_movecost( const tripoint &f, const tripoint &t ) const { int movecost = 0; float diag_mult = ( trigdist && f.x != t.x && f.y != t.y ) ? 1.41 : 1; // Digging and flying monsters ignore terrain cost if( has_flag( MF_FLIES ) || ( digging() && g->m.has_flag( "DIGGABLE", t ) ) ) { movecost = 100 * diag_mult; // Swimming monsters move super fast in water } else if( has_flag( MF_SWIMS ) ) { if( g->m.has_flag( "SWIMMABLE", f ) ) { movecost += 25; } else { movecost += 50 * g->m.move_cost( f ); } if( g->m.has_flag( "SWIMMABLE", t ) ) { movecost += 25; } else { movecost += 50 * g->m.move_cost( t ); } movecost *= diag_mult; } else if( can_submerge() ) { // No-breathe monsters have to walk underwater slowly if( g->m.has_flag( "SWIMMABLE", f ) ) { movecost += 150; } else { movecost += 50 * g->m.move_cost( f ); } if( g->m.has_flag( "SWIMMABLE", t ) ) { movecost += 150; } else { movecost += 50 * g->m.move_cost( t ); } movecost *= diag_mult / 2; } else if( has_flag(MF_CLIMBS) ) { if( g->m.has_flag( "CLIMBABLE", f ) ) { movecost += 150; } else { movecost += 50 * g->m.move_cost( f ); } if( g->m.has_flag( "CLIMBABLE", t ) ) { movecost += 150; } else { movecost += 50 * g->m.move_cost( t ); } movecost *= diag_mult / 2; } else { // All others use the same calculation as the player movecost = ( g->m.combined_movecost( f, t ) ); } return movecost; }
int monster::calc_movecost( const tripoint &f, const tripoint &t ) const { int movecost = 0; const int source_cost = g->m.move_cost( f ); const int dest_cost = g->m.move_cost( t ); // Digging and flying monsters ignore terrain cost if( has_flag( MF_FLIES ) || ( digging() && g->m.has_flag( "DIGGABLE", t ) ) ) { movecost = 100; // Swimming monsters move super fast in water } else if( has_flag( MF_SWIMS ) ) { if( g->m.has_flag( "SWIMMABLE", f ) ) { movecost += 25; } else { movecost += 50 * g->m.move_cost( f ); } if( g->m.has_flag( "SWIMMABLE", t ) ) { movecost += 25; } else { movecost += 50 * g->m.move_cost( t ); } } else if( can_submerge() ) { // No-breathe monsters have to walk underwater slowly if( g->m.has_flag( "SWIMMABLE", f ) ) { movecost += 150; } else { movecost += 50 * g->m.move_cost( f ); } if( g->m.has_flag( "SWIMMABLE", t ) ) { movecost += 150; } else { movecost += 50 * g->m.move_cost( t ); } movecost /= 2; } else if( has_flag( MF_CLIMBS ) ) { if( g->m.has_flag( "CLIMBABLE", f ) ) { movecost += 150; } else { movecost += 50 * g->m.move_cost( f ); } if( g->m.has_flag( "CLIMBABLE", t ) ) { movecost += 150; } else { movecost += 50 * g->m.move_cost( t ); } movecost /= 2; } else { movecost = ( ( 50 * source_cost ) + ( 50 * dest_cost ) ) / 2.0; } return movecost; }
int monster::calc_movecost(int x1, int y1, int x2, int y2) { int movecost = 0; float diag_mult = (trigdist && x1 != x2 && y1 != y2) ? 1.41 : 1; // Digging and flying monsters ignore terrain cost if (has_flag(MF_FLIES) || (digging() && g->m.has_flag("DIGGABLE", x2, y2))) { movecost = 100 * diag_mult; // Swimming monsters move super fast in water } else if (has_flag(MF_SWIMS)) { if (g->m.has_flag("SWIMMABLE", x1, y1)) { movecost += 25; } else { movecost += 50 * g->m.move_cost(x1, y1); } if (g->m.has_flag("SWIMMABLE", x2, y2)) { movecost += 25; } else { movecost += 50 * g->m.move_cost(x2, y2); } movecost *= diag_mult; // No-breathe monsters have to walk underwater slowly } else if (can_submerge()) { if (g->m.has_flag("SWIMMABLE", x1, y1)) { movecost += 150; } else { movecost += 50 * g->m.move_cost(x1, y1); } if (g->m.has_flag("SWIMMABLE", x2, y2)) { movecost += 150; } else { movecost += 50 * g->m.move_cost(x2, y2); } movecost *= diag_mult / 2; // All others use the same calculation as the player } else { movecost = (g->m.combined_movecost(x1, y1, x2, y2)); } return movecost; }
int monster::move_to(int x, int y, bool force) { // Make sure that we can move there, unless force is true. if(!force) if(!g->is_empty(x, y) || !can_move_to(x, y)) { return 0; } if (has_effect("beartrap")) { moves = 0; return 0; } if (plans.size() > 0) { plans.erase(plans.begin()); } if (!force) { moves -= calc_movecost(posx(), posy(), x, y); } //Check for moving into/out of water bool was_water = g->m.is_divable(posx(), posy()); bool will_be_water = g->m.is_divable(x, y); if(was_water && !will_be_water && g->u_see(x, y)) { //Use more dramatic messages for swimming monsters g->add_msg(_("A %s %s from the %s!"), name().c_str(), has_flag(MF_SWIMS) || has_flag(MF_AQUATIC) ? _("leaps") : _("emerges"), g->m.tername(posx(), posy()).c_str()); } else if(!was_water && will_be_water && g->u_see(x, y)) { g->add_msg(_("A %s %s into the %s!"), name().c_str(), has_flag(MF_SWIMS) || has_flag(MF_AQUATIC) ? _("dives") : _("sinks"), g->m.tername(x, y).c_str()); } setpos(x, y); footsteps(x, y); if(is_hallucination()) { //Hallucinations don't do any of the stuff after this point return 1; } if (type->size != MS_TINY && g->m.has_flag("SHARP", posx(), posy()) && !one_in(4)) { hurt(rng(2, 3)); } if (type->size != MS_TINY && g->m.has_flag("ROUGH", posx(), posy()) && one_in(6)) { hurt(rng(1, 2)); } if (!digging() && !has_flag(MF_FLIES) && g->m.tr_at(posx(), posy()) != tr_null) { // Monster stepped on a trap! trap* tr = g->traps[g->m.tr_at(posx(), posy())]; if (dice(3, type->sk_dodge + 1) < dice(3, tr->avoidance)) { trapfuncm f; (f.*(tr->actm))(this, posx(), posy()); } } // Diggers turn the dirt into dirtmound if (digging()) { int factor = 0; switch (type->size) { case MS_TINY: factor = 100; break; case MS_SMALL: factor = 30; break; case MS_MEDIUM: factor = 6; break; case MS_LARGE: factor = 3; break; case MS_HUGE: factor = 1; break; } if (has_flag(MF_VERMIN)) { factor *= 100; } if (one_in(factor)) { g->m.ter_set(posx(), posy(), t_dirtmound); } } // Acid trail monsters leave... a trail of acid if (has_flag(MF_ACIDTRAIL)) { g->m.add_field(posx(), posy(), fd_acid, 3); } if (has_flag(MF_SLUDGETRAIL)) { for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { const int fstr = 3 - (abs(dx) + abs(dy)); if (fstr >= 2) { g->m.add_field(posx() + dx, posy() + dy, fd_sludge, fstr); } } } } return 1; }
int monster::move_to(int x, int y, bool force) { // Make sure that we can move there, unless force is true. if(!force) if(!g->is_empty(x, y) || !can_move_to(x, y)) { return 0; } if (!plans.empty()) { plans.erase(plans.begin()); } if (!force) { moves -= calc_movecost(posx(), posy(), x, y); } //Check for moving into/out of water bool was_water = g->m.is_divable(posx(), posy()); bool will_be_water = !has_flag( MF_FLIES ) && can_submerge() && g->m.is_divable(x, y); if(was_water && !will_be_water && g->u.sees(x, y)) { //Use more dramatic messages for swimming monsters add_msg(m_warning, _("A %s %s from the %s!"), name().c_str(), has_flag(MF_SWIMS) || has_flag(MF_AQUATIC) ? _("leaps") : _("emerges"), g->m.tername(posx(), posy()).c_str()); } else if(!was_water && will_be_water && g->u.sees(x, y)) { add_msg(m_warning, _("A %s %s into the %s!"), name().c_str(), has_flag(MF_SWIMS) || has_flag(MF_AQUATIC) ? _("dives") : _("sinks"), g->m.tername(x, y).c_str()); } setpos(x, y); footsteps(x, y); underwater = will_be_water; if(is_hallucination()) { //Hallucinations don't do any of the stuff after this point return 1; } if (type->size != MS_TINY && g->m.has_flag("SHARP", posx(), posy()) && !one_in(4)) { apply_damage( nullptr, bp_torso, rng( 2, 3 ) ); } if (type->size != MS_TINY && g->m.has_flag("ROUGH", posx(), posy()) && one_in(6)) { apply_damage( nullptr, bp_torso, rng( 1, 2 ) ); } if (g->m.has_flag("UNSTABLE", x, y)) { add_effect("bouldering", 1, num_bp, true); } else if (has_effect("bouldering")) { remove_effect("bouldering"); } if (!digging() && !has_flag(MF_FLIES) && g->m.tr_at(posx(), posy()) != tr_null) { // Monster stepped on a trap! trap* tr = traplist[g->m.tr_at(posx(), posy())]; if (dice(3, type->sk_dodge + 1) < dice(3, tr->get_avoidance())) { tr->trigger(this, posx(), posy()); } } if( !will_be_water && ( has_flag(MF_DIGS) || has_flag(MF_CAN_DIG) ) ) { underwater = g->m.has_flag("DIGGABLE", posx(), posy() ); } // Diggers turn the dirt into dirtmound if (digging()){ int factor = 0; switch (type->size) { case MS_TINY: factor = 100; break; case MS_SMALL: factor = 30; break; case MS_MEDIUM: factor = 6; break; case MS_LARGE: factor = 3; break; case MS_HUGE: factor = 1; break; } if (has_flag(MF_VERMIN)) { factor *= 100; } if (one_in(factor)) { g->m.ter_set(posx(), posy(), t_dirtmound); } } // Acid trail monsters leave... a trail of acid if (has_flag(MF_ACIDTRAIL)){ g->m.add_field(posx(), posy(), fd_acid, 3); } if (has_flag(MF_SLUDGETRAIL)) { for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { const int fstr = 3 - (abs(dx) + abs(dy)); if (fstr >= 2) { g->m.add_field(posx() + dx, posy() + dy, fd_sludge, fstr); } } } } if (has_flag(MF_LEAKSGAS)){ if (one_in(6)){ g->m.add_field(posx() + rng(-1,1), posy() + rng(-1, 1), fd_toxic_gas, 3); } } return 1; }
bool monster::move_to( const tripoint &p, bool force, const float stagger_adjustment ) { const bool digs = digging(); const bool flies = has_flag( MF_FLIES ); const bool on_ground = !digs && !flies; const bool climbs = has_flag( MF_CLIMBS ) && g->m.has_flag( TFLAG_NO_FLOOR, p ); // Allows climbing monsters to move on terrain with movecost <= 0 Creature *critter = g->critter_at( p, is_hallucination() ); if( g->m.has_flag( "CLIMBABLE", p ) ) { if( g->m.impassable( p ) && critter == nullptr ) { if( flies ) { moves -= 100; force = true; if( g->u.sees( *this ) ) { add_msg( _( "The %1$s flies over the %2$s." ), name().c_str(), g->m.has_flag_furn( "CLIMBABLE", p ) ? g->m.furnname( p ).c_str() : g->m.tername( p ).c_str() ); } } else if( has_flag( MF_CLIMBS ) ) { moves -= 150; force = true; if( g->u.sees( *this ) ) { add_msg( _( "The %1$s climbs over the %2$s." ), name().c_str(), g->m.has_flag_furn( "CLIMBABLE", p ) ? g->m.furnname( p ).c_str() : g->m.tername( p ).c_str() ); } } } } if( critter != nullptr && !force ) { return false; } // Make sure that we can move there, unless force is true. if( !force && !can_move_to( p ) ) { return false; } if( !force ) { // This adjustment is to make it so that monster movement speed relative to the player // is consistent even if the monster stumbles, // and the same regardless of the distance measurement mode. const int cost = stagger_adjustment * ( float )( climbs ? calc_climb_cost( pos(), p ) : calc_movecost( pos(), p ) ); if( cost > 0 ) { moves -= cost; } else { return false; } } //Check for moving into/out of water bool was_water = g->m.is_divable( pos() ); bool will_be_water = on_ground && can_submerge() && g->m.is_divable( p ); if( was_water && !will_be_water && g->u.sees( p ) ) { //Use more dramatic messages for swimming monsters add_msg( m_warning, _( "A %1$s %2$s from the %3$s!" ), name().c_str(), has_flag( MF_SWIMS ) || has_flag( MF_AQUATIC ) ? _( "leaps" ) : _( "emerges" ), g->m.tername( pos() ).c_str() ); } else if( !was_water && will_be_water && g->u.sees( p ) ) { add_msg( m_warning, _( "A %1$s %2$s into the %3$s!" ), name().c_str(), has_flag( MF_SWIMS ) || has_flag( MF_AQUATIC ) ? _( "dives" ) : _( "sinks" ), g->m.tername( p ).c_str() ); } setpos( p ); footsteps( p ); underwater = will_be_water; if( is_hallucination() ) { //Hallucinations don't do any of the stuff after this point return true; } // TODO: Make tanks stop taking damage from rubble, because it's just silly if( type->size != MS_TINY && on_ground ) { if( g->m.has_flag( "SHARP", pos() ) && !one_in( 4 ) ) { apply_damage( nullptr, bp_torso, rng( 1, 10 ) ); } if( g->m.has_flag( "ROUGH", pos() ) && one_in( 6 ) ) { apply_damage( nullptr, bp_torso, rng( 1, 2 ) ); } } if( g->m.has_flag( "UNSTABLE", p ) && on_ground ) { add_effect( effect_bouldering, 1, num_bp, true ); } else if( has_effect( effect_bouldering ) ) { remove_effect( effect_bouldering ); } g->m.creature_on_trap( *this ); if( !will_be_water && ( has_flag( MF_DIGS ) || has_flag( MF_CAN_DIG ) ) ) { underwater = g->m.has_flag( "DIGGABLE", pos() ); } // Diggers turn the dirt into dirtmound if( digging() ) { int factor = 0; switch( type->size ) { case MS_TINY: factor = 100; break; case MS_SMALL: factor = 30; break; case MS_MEDIUM: factor = 6; break; case MS_LARGE: factor = 3; break; case MS_HUGE: factor = 1; break; } if( one_in( factor ) ) { g->m.ter_set( pos(), t_dirtmound ); } } // Acid trail monsters leave... a trail of acid if( has_flag( MF_ACIDTRAIL ) ) { g->m.add_field( pos(), fd_acid, 3, 0 ); } if( has_flag( MF_SLUDGETRAIL ) ) { for( const tripoint &sludge_p : g->m.points_in_radius( pos(), 1 ) ) { const int fstr = 3 - ( abs( sludge_p.x - posx() ) + abs( sludge_p.y - posy() ) ); if( fstr >= 2 ) { g->m.add_field( sludge_p, fd_sludge, fstr, 0 ); } } } return true; }
int monster::sight_range( const int light_level ) const { // Non-aquatic monsters can't see much when submerged if( !can_see() || ( underwater && !has_flag( MF_SWIMS ) && !has_flag( MF_AQUATIC ) && !digging() ) ) { return 1; } int range = ( light_level * type->vision_day ) + ( ( DAYLIGHT_LEVEL - light_level ) * type->vision_night ); range /= DAYLIGHT_LEVEL; return range; }