Skip to content

Commit

Permalink
typified character, npc and explosion stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell committed Dec 19, 2024
1 parent 438b5e4 commit 40bae5d
Show file tree
Hide file tree
Showing 30 changed files with 142 additions and 155 deletions.
9 changes: 0 additions & 9 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,11 @@ void explosion_handler::draw_explosion( const tripoint_bub_ms &p, const int r, c
}
}

void explosion_handler::draw_explosion( const tripoint &p, const int r, const nc_color &col )
{
explosion_handler::draw_explosion( tripoint_bub_ms( p ), r, col );
}
#else
void explosion_handler::draw_explosion( const tripoint_bub_ms &p, const int r, const nc_color &col )
{
draw_explosion_curses( *g, p, r, col );
}

void explosion_handler::draw_explosion( const tripoint &p, const int r, const nc_color &col )
{
draw_explosion_curses( *g, tripoint_bub_ms( p ), r, col );
}
#endif

void explosion_handler::draw_custom_explosion(
Expand Down
2 changes: 1 addition & 1 deletion src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg,
apply_ammo_effects( null_source ? nullptr : origin, tp, proj.proj_effects, dealt_damage );
const explosion_data &expl = proj.get_custom_explosion();
if( expl.power > 0.0f ) {
explosion_handler::explosion( null_source ? nullptr : origin, tp.raw(),
explosion_handler::explosion( null_source ? nullptr : origin, tp,
proj.get_custom_explosion() );
}

Expand Down
7 changes: 4 additions & 3 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,8 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
set_rad( 0 );
}
} else if( bio.id == bio_emp ) {
if( const std::optional<tripoint> pnt = choose_adjacent( _( "Create an EMP where?" ) ) ) {
if( const std::optional<tripoint_bub_ms> pnt = choose_adjacent_bub(
_( "Create an EMP where?" ) ) ) {
add_msg_activate();
explosion_handler::emp_blast( *pnt );
mod_moves( -100 );
Expand Down Expand Up @@ -1049,11 +1050,11 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
}
} else if( bio.id == bio_flashbang ) {
add_msg_activate();
explosion_handler::flashbang( pos(), true );
explosion_handler::flashbang( pos_bub(), true );
mod_moves( -100 );
} else if( bio.id == bio_shockwave ) {
add_msg_activate();
explosion_handler::shockwave( pos(), 3, 4, 2, 8, true );
explosion_handler::shockwave( pos_bub(), 3, 4, 2, 8, true );
add_msg_if_player( m_neutral, _( "You unleash a powerful shockwave!" ) );
mod_moves( -100 );
} else if( bio.id == bio_meteorologist ) {
Expand Down
10 changes: 4 additions & 6 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,14 +1101,14 @@ double Character::aim_factor_from_volume( const item &gun ) const
return std::max( factor, 0.2 ) ;
}

static bool is_obstacle( tripoint pos )
static bool is_obstacle( tripoint_bub_ms pos )
{
return get_map().coverage( pos ) >= 50;
}

double Character::aim_factor_from_length( const item &gun ) const
{
tripoint cur_pos = pos();
tripoint_bub_ms cur_pos = pos_bub();
bool nw_to_se = is_obstacle( cur_pos + tripoint::south_east ) &&
is_obstacle( cur_pos + tripoint::north_west );
bool w_to_e = is_obstacle( cur_pos + tripoint::west ) &&
Expand Down Expand Up @@ -10474,7 +10474,7 @@ void Character::echo_pulse()
sounds::sound( origin, 5, sounds::sound_t::sensory, _( "clack." ), true,
"none", "none" );
// This only counts obstacles which can be moved through, so the echo is pretty quiet.
} else if( is_obstacle( origin.raw() ) && here.sees( pos_bub(), origin, pulse_range, false ) ) {
} else if( is_obstacle( origin ) && here.sees( pos_bub(), origin, pulse_range, false ) ) {
sounds::sound( origin, 1, sounds::sound_t::sensory, _( "click." ), true,
"none", "none" );
}
Expand Down Expand Up @@ -11433,12 +11433,10 @@ bool Character::defer_move( const tripoint_bub_ms &next )
return false;
}
// next must be adjacent to subsequent move in any preexisting automove route
// TODO: fix point types
if( has_destination() && square_dist( auto_move_route.front(), next ) != 1 ) {
return false;
}
// TODO: fix point types
auto_move_route.insert( auto_move_route.begin(), tripoint_bub_ms( next ) );
auto_move_route.insert( auto_move_route.begin(), next );
next_expected_position = pos_bub();
return true;
}
Expand Down
22 changes: 12 additions & 10 deletions src/computer_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,13 @@ void computer_session::action_cascade()
get_event_bus().send<event_type::causes_resonance_cascade>();
tripoint_bub_ms player_pos = get_player_character().pos_bub();
map &here = get_map();
std::vector<tripoint> cascade_points;
std::vector<tripoint_bub_ms> cascade_points;
for( const tripoint_bub_ms &dest : here.points_in_radius( player_pos, 10 ) ) {
if( here.ter( dest ) == ter_t_radio_tower ) {
cascade_points.push_back( dest.raw() );
cascade_points.push_back( dest );
}
}
explosion_handler::resonance_cascade( random_entry( cascade_points, player_pos.raw() ) );
explosion_handler::resonance_cascade( random_entry( cascade_points, player_pos ) );
}

void computer_session::action_research()
Expand Down Expand Up @@ -771,7 +771,7 @@ void computer_session::action_miss_launch()
}

//Only explode once. But make it large.
explosion_handler::explosion( &get_player_character(), nuke_location.raw(), 2000, 0.7, true );
explosion_handler::explosion( &get_player_character(), nuke_location, 2000, 0.7, true );

//...ERASE MISSILE, OPEN SILO, DISABLE COMPUTER
// For each level between here and the surface, remove the missile
Expand Down Expand Up @@ -1234,13 +1234,13 @@ void computer_session::action_srcf_seal()
const ter_id &t = here.ter( p );
if( t == ter_t_elevator || t == ter_t_vat ) {
here.make_rubble( p, furn_f_rubble_rock, true );
explosion_handler::explosion( &get_player_character(), p.raw(), 40, 0.7, true );
explosion_handler::explosion( &get_player_character(), p, 40, 0.7, true );
} else if( t == ter_t_wall_glass || t == ter_t_sewage_pipe ||
t == ter_t_sewage || t == ter_t_grate ) {
here.make_rubble( p, furn_f_rubble_rock, true );
} else if( t == ter_t_sewage_pump ) {
here.make_rubble( p, furn_f_rubble_rock, true );
explosion_handler::explosion( &get_player_character(), p.raw(), 50, 0.7, true );
explosion_handler::explosion( &get_player_character(), p, 50, 0.7, true );
}
}
comp.options.clear(); // Disable the terminal.
Expand Down Expand Up @@ -1340,7 +1340,7 @@ void computer_session::action_irradiator()
// critical failure - radiation spike sets off electronic detonators
if( it->typeId() == itype_mininuke || it->typeId() == itype_mininuke_act ||
it->typeId() == itype_c4 ) {
explosion_handler::explosion( &get_player_character(), dest.raw(), 40 );
explosion_handler::explosion( &get_player_character(), dest, 40 );
reset_terminal();
print_error( _( "WARNING [409]: Primary sensors offline!" ) );
print_error( _( " >> Initialize secondary sensors: Geiger profiling…" ) );
Expand Down Expand Up @@ -1664,7 +1664,7 @@ void computer_session::failure_pump_explode()
for( const tripoint_bub_ms &p : here.points_on_zlevel() ) {
if( here.ter( p ) == ter_t_sewage_pump ) {
here.make_rubble( p );
explosion_handler::explosion( &get_player_character(), p.raw(), 10 );
explosion_handler::explosion( &get_player_character(), p, 10 );
}
}
}
Expand Down Expand Up @@ -1706,9 +1706,11 @@ void computer_session::failure_amigara()
get_player_character().add_effect( effect_amigara, 2_minutes );
map &here = get_map();
explosion_handler::explosion( &get_player_character(),
tripoint( rng( 0, MAPSIZE_X ), rng( 0, MAPSIZE_Y ), here.get_abs_sub().z() ), 10, 0.7, false, 10 );
tripoint_bub_ms( rng( 0, MAPSIZE_X ), rng( 0, MAPSIZE_Y ), here.get_abs_sub().z() ), 10, 0.7, false,
10 );
explosion_handler::explosion( &get_player_character(),
tripoint( rng( 0, MAPSIZE_X ), rng( 0, MAPSIZE_Y ), here.get_abs_sub().z() ), 10, 0.7, false, 10 );
tripoint_bub_ms( rng( 0, MAPSIZE_X ), rng( 0, MAPSIZE_Y ), here.get_abs_sub().z() ), 10, 0.7, false,
10 );
comp.remove_option( COMPACT_AMIGARA_START );
}

Expand Down
10 changes: 5 additions & 5 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,12 @@ static int creature_uilist()

static void monster_edit_menu()
{
std::vector<tripoint> locations;
std::vector<tripoint_bub_ms> locations;
uilist monster_menu;
int charnum = 0;
for( const monster &mon : g->all_monsters() ) {
monster_menu.addentry( charnum++, true, MENU_AUTOASSIGN, mon.disp_name() );
locations.emplace_back( mon.pos() );
locations.emplace_back( mon.pos_bub() );
}

if( locations.empty() ) {
Expand Down Expand Up @@ -2284,16 +2284,16 @@ static faction *select_faction()

static void character_edit_menu()
{
std::vector< tripoint > locations;
std::vector< tripoint_bub_ms > locations;
uilist charmenu;
charmenu.title = _( "Edit which character?" );
int charnum = 0;
avatar &player_character = get_avatar();
charmenu.addentry( charnum++, true, MENU_AUTOASSIGN, "%s", _( "You" ) );
locations.emplace_back( player_character.pos() );
locations.emplace_back( player_character.pos_bub() );
for( const npc &guy : g->all_npcs() ) {
charmenu.addentry( charnum++, true, MENU_AUTOASSIGN, guy.get_name() );
locations.emplace_back( guy.pos() );
locations.emplace_back( guy.pos_bub() );
}

pointmenu_cb callback( locations );
Expand Down
69 changes: 34 additions & 35 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ static std::vector<tripoint_bub_ms> shrapnel( map *m, const Creature *source,
return distrib;
}

void explosion( const Creature *source, const tripoint &p, float power, float factor, bool fire,
void explosion( const Creature *source, const tripoint_bub_ms &p, float power, float factor,
bool fire,
int casing_mass, float frag_mass )
{
explosion_data data;
Expand All @@ -532,7 +533,7 @@ bool explosion_processing_active()
return process_explosions_in_progress;
}

void explosion( const Creature *source, const tripoint &p, const explosion_data &ex )
void explosion( const Creature *source, const tripoint_bub_ms &p, const explosion_data &ex )
{
_explosions.emplace_back( source, get_map().getglobal( p ), ex );
}
Expand Down Expand Up @@ -595,18 +596,18 @@ void _make_explosion( map *m, const Creature *source, const tripoint_bub_ms &p,
}
}

void flashbang( const tripoint &p, bool player_immune )
void flashbang( const tripoint_bub_ms &p, bool player_immune )
{
draw_explosion( p, 8, c_white );
Character &player_character = get_player_character();
int dist = rl_dist( player_character.pos(), p );
int dist = rl_dist( player_character.pos_bub(), p );
map &here = get_map();
if( dist <= 8 && !player_immune ) {
if( !player_character.has_flag( STATIC( json_character_flag( "IMMUNE_HEARING_DAMAGE" ) ) ) &&
!player_character.is_wearing( itype_rm13_armor_on ) ) {
player_character.add_effect( effect_deaf, time_duration::from_turns( 40 - dist * 4 ) );
}
if( here.sees( player_character.pos(), p, 8 ) ) {
if( here.sees( player_character.pos_bub(), p, 8 ) ) {
int flash_mod = 0;
if( player_character.has_trait( trait_PER_SLIME ) ) {
if( one_in( 2 ) ) {
Expand All @@ -630,12 +631,12 @@ void flashbang( const tripoint &p, bool player_immune )
continue;
}
// TODO: can the following code be called for all types of creatures
dist = rl_dist( critter.pos(), p );
dist = rl_dist( critter.pos_bub(), p );
if( dist <= 8 ) {
if( dist <= 4 ) {
critter.add_effect( effect_stunned, time_duration::from_turns( 10 - dist ) );
}
if( critter.has_flag( mon_flag_SEES ) && here.sees( critter.pos(), p, 8 ) ) {
if( critter.has_flag( mon_flag_SEES ) && here.sees( critter.pos_bub(), p, 8 ) ) {
critter.add_effect( effect_blind, time_duration::from_turns( 18 - dist ) );
}
if( critter.has_flag( mon_flag_HEARS ) ) {
Expand All @@ -647,44 +648,43 @@ void flashbang( const tripoint &p, bool player_immune )
// TODO: Blind/deafen NPC
}

void shockwave( const tripoint &p, int radius, int force, int stun, int dam_mult,
void shockwave( const tripoint_bub_ms &p, int radius, int force, int stun, int dam_mult,
bool ignore_player )
{
const tripoint_bub_ms pos{p}; // TODO: Remove when operation is typified
draw_explosion( pos, radius, c_blue );
draw_explosion( p, radius, c_blue );

sounds::sound( pos, force * force * dam_mult / 2, sounds::sound_t::combat, _( "Crack!" ), false,
sounds::sound( p, force * force * dam_mult / 2, sounds::sound_t::combat, _( "Crack!" ), false,
"misc", "shockwave" );

for( monster &critter : g->all_monsters() ) {
if( critter.posz() != pos.z() ) {
if( critter.posz() != p.z() ) {
continue;
}
if( rl_dist( critter.pos_bub(), pos ) <= radius ) {
if( rl_dist( critter.pos_bub(), p ) <= radius ) {
add_msg( _( "%s is caught in the shockwave!" ), critter.name() );
g->knockback( pos, critter.pos_bub(), force, stun, dam_mult );
g->knockback( p, critter.pos_bub(), force, stun, dam_mult );
}
}
// TODO: combine the two loops and the case for avatar using all_creatures()
for( npc &guy : g->all_npcs() ) {
if( guy.posz() != pos.z() ) {
if( guy.posz() != p.z() ) {
continue;
}
if( rl_dist( guy.pos_bub(), pos ) <= radius ) {
if( rl_dist( guy.pos_bub(), p ) <= radius ) {
add_msg( _( "%s is caught in the shockwave!" ), guy.get_name() );
g->knockback( pos, guy.pos_bub(), force, stun, dam_mult );
g->knockback( p, guy.pos_bub(), force, stun, dam_mult );
}
}
Character &player_character = get_player_character();
if( rl_dist( player_character.pos_bub(), pos ) <= radius && !ignore_player &&
if( rl_dist( player_character.pos_bub(), p ) <= radius && !ignore_player &&
( !player_character.has_trait( trait_LEG_TENT_BRACE ) ||
!player_character.is_barefoot() ) ) {
add_msg( m_bad, _( "You're caught in the shockwave!" ) );
g->knockback( pos, player_character.pos_bub(), force, stun, dam_mult );
g->knockback( p, player_character.pos_bub(), force, stun, dam_mult );
}
}

void scrambler_blast( const tripoint &p )
void scrambler_blast( const tripoint_bub_ms &p )
{
if( monster *const mon_ptr = get_creature_tracker().creature_at<monster>( p ) ) {
monster &critter = *mon_ptr;
Expand All @@ -696,7 +696,7 @@ void scrambler_blast( const tripoint &p )
}
}

void emp_blast( const tripoint &p )
void emp_blast( const tripoint_bub_ms &p )
{
Character &player_character = get_player_character();
const bool sight = player_character.sees( p );
Expand All @@ -723,7 +723,7 @@ void emp_blast( const tripoint &p )
if( sight ) {
add_msg( _( "The nearby doors slide open!" ) );
}
for( const tripoint &pos : here.points_in_radius( p, 3 ) ) {
for( const tripoint_bub_ms &pos : here.points_in_radius( p, 3 ) ) {
if( here.ter( pos ) == ter_t_door_metal_locked ) {
here.ter_set( pos, ter_t_floor );
}
Expand Down Expand Up @@ -795,8 +795,7 @@ void emp_blast( const tripoint &p )
add_msg( _( "The %s is unaffected by the EMP blast." ), critter.name() );
}
}
if( player_character.posx() == p.x && player_character.posy() == p.y &&
player_character.posz() == p.z ) {
if( player_character.pos_bub() == p ) {
if( player_character.get_power_level() > 0_kJ &&
!player_character.has_flag( json_flag_EMP_IMMUNE ) &&
!player_character.has_flag( json_flag_EMP_ENERGYDRAIN_IMMUNE ) ) {
Expand Down Expand Up @@ -843,28 +842,28 @@ void emp_blast( const tripoint &p )
// TODO: Drain NPC energy reserves
}

void resonance_cascade( const tripoint &p )
void resonance_cascade( const tripoint_bub_ms &p )
{
Character &player_character = get_player_character();
const time_duration maxglow = time_duration::from_turns( 100 - 5 * trig_dist( p,
player_character.pos() ) );
player_character.pos_bub() ) );
if( maxglow > 0_turns ) {
const time_duration minglow = std::max( 0_turns, time_duration::from_turns( 60 - 5 * trig_dist( p,
player_character.pos() ) ) );
player_character.pos_bub() ) ) );
player_character.add_effect( effect_teleglow, rng( minglow, maxglow ) * 100 );
}
int startx = p.x < 8 ? 0 : p.x - 8;
int endx = p.x + 8 >= SEEX * 3 ? SEEX * 3 - 1 : p.x + 8;
int starty = p.y < 8 ? 0 : p.y - 8;
int endy = p.y + 8 >= SEEY * 3 ? SEEY * 3 - 1 : p.y + 8;
tripoint_bub_ms dest( startx, starty, p.z );
int startx = p.x() < 8 ? 0 : p.x() - 8;
int endx = p.x() + 8 >= SEEX * 3 ? SEEX * 3 - 1 : p.x() + 8;
int starty = p.y() < 8 ? 0 : p.y() - 8;
int endy = p.y() + 8 >= SEEY * 3 ? SEEY * 3 - 1 : p.y() + 8;
tripoint_bub_ms dest( startx, starty, p.z() );
map &here = get_map();
for( int &i = dest.x(); i <= endx; i++ ) {
for( int &j = dest.y(); j <= endy; j++ ) {
switch( rng( 1, 80 ) ) {
case 1:
case 2:
emp_blast( dest.raw() );
emp_blast( dest );
break;
case 3:
case 4:
Expand Down Expand Up @@ -893,7 +892,7 @@ void resonance_cascade( const tripoint &p )
}
if( !one_in( 3 ) ) {
// TODO: fix point types
here.add_field( tripoint_bub_ms{ k, l, p.z }, type, 3 );
here.add_field( tripoint_bub_ms{ k, l, p.z()}, type, 3 );
}
}
}
Expand Down Expand Up @@ -925,7 +924,7 @@ void resonance_cascade( const tripoint &p )
here.destroy( dest );
break;
case 19:
explosion( &player_character, dest.raw(), rng( 1, 10 ), rng( 0, 1 ) * rng( 0, 6 ), one_in( 4 ) );
explosion( &player_character, dest, rng( 1, 10 ), rng( 0, 1 ) * rng( 0, 6 ), one_in( 4 ) );
break;
default:
break;
Expand Down
Loading

0 comments on commit 40bae5d

Please sign in to comment.