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; }
bool monster::can_move_to( const tripoint &p ) const { const bool can_climb = has_flag( MF_CLIMBS ) || has_flag( MF_FLIES ); if( g->m.move_cost( p ) == 0 && !( can_climb && g->m.has_flag( "CLIMBABLE", p ) ) ) { return false; } if( !can_submerge() && g->m.has_flag( TFLAG_DEEP_WATER, p ) ) { return false; } if( has_flag( MF_DIGS ) && !g->m.has_flag( "DIGGABLE", p ) ) { return false; } if( has_flag( MF_AQUATIC ) && !g->m.has_flag( "SWIMMABLE", p ) ) { return false; } if( has_flag( MF_SUNDEATH ) && g->is_in_sunlight( p ) ) { return false; } // various animal behaviours if( has_flag( MF_ANIMAL ) ) { // don't enter sharp terrain unless tiny, or attacking if( g->m.has_flag( "SHARP", p ) && !( attitude( &( g->u ) ) == MATT_ATTACK || type->size == MS_TINY || has_flag( MF_FLIES )) ) { return false; } // Don't enter open pits ever unless tiny, can fly or climb well if( !( type->size == MS_TINY || can_climb ) && ( g->m.ter( p ) == t_pit || g->m.ter( p ) == t_pit_spiked || g->m.ter( p ) == t_pit_glass ) ) { return false; } // don't enter lava ever if( g->m.ter( p ) == t_lava ) { return false; } // don't enter fire or electricity ever const field &local_field = g->m.field_at( p ); if( local_field.findField( fd_fire ) || local_field.findField( fd_electricity ) ) { return false; } if( g->m.has_flag( TFLAG_NO_FLOOR, p ) && !has_flag( MF_FLIES ) ) { return false; } } return true; }
bool monster::can_move_to(int x, int y) { if (g->m.move_cost(x, y) == 0 && (!has_flag(MF_DESTROYS) || !g->m.is_destructable(x, y))) { return false; } if (!can_submerge() && g->m.has_flag(TFLAG_DEEP_WATER, x, y)) { return false; } if (has_flag(MF_DIGS) && !g->m.has_flag("DIGGABLE", x, y)) { return false; } if (has_flag(MF_AQUATIC) && !g->m.has_flag("SWIMMABLE", x, y)) { return false; } if (has_flag(MF_SUNDEATH) && g->is_in_sunlight(x, y)) { return false; } // various animal behaviours if (has_flag(MF_ANIMAL)) { // don't enter sharp terrain unless tiny, or attacking if (g->m.has_flag("SHARP", x, y) && !(attitude(&(g->u)) == MATT_ATTACK || type->size == MS_TINY)) return false; // don't enter open pits ever unless tiny or can fly if (!(type->size == MS_TINY || has_flag(MF_FLIES)) && (g->m.ter(x, y) == t_pit || g->m.ter(x, y) == t_pit_spiked)) return false; // don't enter lava ever if (g->m.ter(x, y) == t_lava) return false; // don't enter fire or electricity ever field &local_field = g->m.field_at(x, y); if (local_field.findField(fd_fire) || local_field.findField(fd_electricity)) return false; } return true; }
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; }
bool monster::is_underwater() const { return can_submerge(); }
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; }
bool monster::can_move_to( const tripoint &p ) const { const bool can_climb = has_flag( MF_CLIMBS ) || has_flag( MF_FLIES ); if( g->m.impassable( p ) && !( can_climb && g->m.has_flag( "CLIMBABLE", p ) ) ) { return false; } if( !can_submerge() && g->m.has_flag( TFLAG_DEEP_WATER, p ) ) { return false; } if( has_flag( MF_DIGS ) && !g->m.has_flag( "DIGGABLE", p ) ) { return false; } if( has_flag( MF_AQUATIC ) && !g->m.has_flag( "SWIMMABLE", p ) ) { return false; } if( has_flag( MF_SUNDEATH ) && g->is_in_sunlight( p ) ) { return false; } // Various avoiding behaviors if( has_flag( MF_AVOID_DANGER_1 ) || has_flag( MF_AVOID_DANGER_2 ) ) { const ter_id target = g->m.ter( p ); // Don't enter lava ever if( target == t_lava ) { return false; } // Don't ever throw ourselves off cliffs if( !g->m.has_floor( p ) && !has_flag( MF_FLIES ) ) { return false; } // Don't enter open pits ever unless tiny, can fly or climb well if( !( type->size == MS_TINY || can_climb ) && ( target == t_pit || target == t_pit_spiked || target == t_pit_glass ) ) { return false; } // The following behaviors are overridden when attacking if( attitude( &( g->u ) ) != MATT_ATTACK ) { if( g->m.has_flag( "SHARP", p ) && !( type->size == MS_TINY || has_flag( MF_FLIES ) ) ) { return false; } } const field &target_field = g->m.field_at( p ); // Differently handled behaviors if( has_flag( MF_AVOID_DANGER_2 ) ) { const trap &target_trap = g->m.tr_at( p ); // Don't enter any dangerous fields if( is_dangerous_fields( target_field ) ) { return false; } // Don't step on any traps (if we can see) if( has_flag( MF_SEES ) && !target_trap.is_benign() && g->m.has_floor( p ) ) { return false; } } else if( has_flag( MF_AVOID_DANGER_1 ) ) { // Don't enter fire or electricity ever (other dangerous fields are fine though) if( target_field.findField( fd_fire ) || target_field.findField( fd_electricity ) ) { return false; } } } return true; }