Skip to content

Commit

Permalink
Remove nuke launch and do some cleanup. (#35242)
Browse files Browse the repository at this point in the history
* Move internal computer methods out of header file

* Remove instances of miss_launch

* Skip loading of blacklisted computer options

* Deprecate nuke launch enum

* Kill nuke launch code.
  • Loading branch information
kevingranade authored and ZhilkinSerg committed Dec 24, 2019
1 parent 62c50b3 commit 1f3199e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 144 deletions.
2 changes: 1 addition & 1 deletion data/json/mapgen/missile_silo.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
"access_denied": "ERROR! Access denied! Unauthorized access will be met with lethal force!",
"security": 10,
"failures": [ { "action": "alarm" }, { "action": "damage" }, { "action": "secubots" } ],
"options": [ { "name": "Launch Missile", "action": "miss_launch" }, { "name": "Disarm Missile", "action": "miss_disarm" } ]
"options": [ { "name": "Disarm Missile", "action": "miss_disarm" } ]
}
},
"place_graffiti": [ { "text": "Warning! Automatic security measures engaged due to the lockdown order!", "x": 17, "y": 20 } ],
Expand Down
2 changes: 1 addition & 1 deletion data/mods/mapspecials_demo/missile_silo/silo_utrc_03.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"7": {
"name": "Missile Control",
"access_denied": "ERROR! Access denied! Unauthorized access will be met with lethal force!",
"options": [ { "name": "Launch Missile", "action": "miss_launch" }, { "name": "Disarm Missile", "action": "miss_disarm" } ],
"options": [ { "name": "Disarm Missile", "action": "miss_disarm" } ],
"failures": [ { "action": "secubots" }, { "action": "damage" } ]
}
}
Expand Down
102 changes: 21 additions & 81 deletions src/computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ std::string computer::save_data() const

void computer::load_data( const std::string &data )
{
static const std::set<std::string> blacklisted_options = {{ "Launch_Missile" }};
options.clear();
failures.clear();

Expand All @@ -340,7 +341,9 @@ void computer::load_data( const std::string &data )
int tmpsec;

dump >> tmpname >> tmpaction >> tmpsec;

if( blacklisted_options.find( tmpname ) != blacklisted_options.end() ) {
continue;
}
add_option( string_replace( tmpname, "_", " " ), static_cast<computer_action>( tmpaction ),
tmpsec );
}
Expand Down Expand Up @@ -631,69 +634,8 @@ void computer::activate_function( computer_action action )
}
break;

case COMPACT_MISS_LAUNCH: {
// Target Acquisition.
tripoint target = ui::omap::choose_point( 0 );
if( target == overmap::invalid_tripoint ) {
add_msg( m_info, _( "Target acquisition canceled." ) );
return;
}

// TODO: Z
target.z = 0;

if( query_yn( _( "Confirm nuclear missile launch." ) ) ) {
add_msg( m_info, _( "Nuclear missile launched!" ) );
//Remove the option to fire another missile.
options.clear();
} else {
add_msg( m_info, _( "Nuclear missile launch aborted." ) );
return;
}
g->refresh_all();

//Put some smoke gas and explosions at the nuke location.
const tripoint nuke_location = { g->u.pos() - point( 12, 0 ) };
for( const auto &loc : g->m.points_in_radius( nuke_location, 5, 0 ) ) {
if( one_in( 4 ) ) {
g->m.add_field( loc, fd_smoke, rng( 1, 9 ) );
}
}

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

//...ERASE MISSILE, OPEN SILO, DISABLE COMPUTER
// For each level between here and the surface, remove the missile
for( int level = g->get_levz(); level <= 0; level++ ) {
map tmpmap;
tmpmap.load( tripoint( g->get_levx(), g->get_levy(), level ), false );

if( level < 0 ) {
tmpmap.translate( t_missile, t_hole );
} else {
tmpmap.translate( t_metal_floor, t_hole );
}
tmpmap.save();
}

const oter_id oter = overmap_buffer.ter( target );
g->events().send<event_type::launches_nuke>( oter );
for( const tripoint &p : g->m.points_in_radius( target, 2 ) ) {
// give it a nice rounded shape
if( !( p.x == target.x - 2 && p.y == target.y - 2 ) &&
!( p.x == target.x - 2 && p.y == target.y + 2 ) &&
!( p.x == target.x + 2 && p.y == target.y - 2 ) &&
!( p.x == target.x + 2 && p.y == target.y + 2 ) ) {
// TODO: other Z-levels.
explosion_handler::nuke( tripoint( p.xy(), 0 ) );
}
}

activate_failure( COMPFAIL_SHUTDOWN );
}
break;

case COMPACT_OBSOLETE:
break;
case COMPACT_MISS_DISARM:
// TODO: stop the nuke from creating radioactive clouds.
if( query_yn( _( "Disarm missile." ) ) ) {
Expand Down Expand Up @@ -1659,21 +1601,7 @@ void computer::print_newline()
wprintz( w_terminal, c_green, "\n" );
}

computer_option computer_option::from_json( const JsonObject &jo )
{
std::string name = jo.get_string( "name" );
computer_action action = computer_action_from_string( jo.get_string( "action" ) );
int sec = jo.get_int( "security", 0 );
return computer_option( name, action, sec );
}

computer_failure computer_failure::from_json( const JsonObject &jo )
{
computer_failure_type type = computer_failure_type_from_string( jo.get_string( "action" ) );
return computer_failure( type );
}

computer_action computer_action_from_string( const std::string &str )
static computer_action computer_action_from_string( const std::string &str )
{
static const std::map<std::string, computer_action> actions = {{
{ "null", COMPACT_NULL },
Expand All @@ -1694,7 +1622,6 @@ computer_action computer_action_from_string( const std::string &str )
{ "maps", COMPACT_MAPS },
{ "map_sewer", COMPACT_MAP_SEWER },
{ "map_subway", COMPACT_MAP_SUBWAY },
{ "miss_launch", COMPACT_MISS_LAUNCH },
{ "miss_disarm", COMPACT_MISS_DISARM },
{ "list_bionics", COMPACT_LIST_BIONICS },
{ "elevator_on", COMPACT_ELEVATOR_ON },
Expand Down Expand Up @@ -1738,7 +1665,7 @@ computer_action computer_action_from_string( const std::string &str )
return COMPACT_NULL;
}

computer_failure_type computer_failure_type_from_string( const std::string &str )
static computer_failure_type computer_failure_type_from_string( const std::string &str )
{
static const std::map<std::string, computer_failure_type> fails = {{
{ "null", COMPFAIL_NULL },
Expand All @@ -1763,3 +1690,16 @@ computer_failure_type computer_failure_type_from_string( const std::string &str
debugmsg( "Invalid computer failure %s", str );
return COMPFAIL_NULL;
}
computer_option computer_option::from_json( const JsonObject &jo )
{
std::string name = jo.get_string( "name" );
computer_action action = computer_action_from_string( jo.get_string( "action" ) );
int sec = jo.get_int( "security", 0 );
return computer_option( name, action, sec );
}

computer_failure computer_failure::from_json( const JsonObject &jo )
{
computer_failure_type type = computer_failure_type_from_string( jo.get_string( "action" ) );
return computer_failure( type );
}
7 changes: 1 addition & 6 deletions src/computer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum computer_action {
COMPACT_MAPS,
COMPACT_MAP_SEWER,
COMPACT_MAP_SUBWAY,
COMPACT_MISS_LAUNCH,
COMPACT_OBSOLETE, // No longer used
COMPACT_MISS_DISARM,
COMPACT_LIST_BIONICS,
COMPACT_ELEVATOR_ON,
Expand Down Expand Up @@ -66,7 +66,6 @@ enum computer_action {
COMPACT_RADIO_ARCHIVE,
NUM_COMPUTER_ACTIONS
};

// Don't change those! They must stay in this specific order!
// TODO: Remove this enum
enum computer_failure_type {
Expand All @@ -84,10 +83,6 @@ enum computer_failure_type {
NUM_COMPUTER_FAILURES
};

// TODO: Turn the enum into id, get rid of this
computer_action computer_action_from_string( const std::string &str );
computer_failure_type computer_failure_type_from_string( const std::string &str );

struct computer_option {
std::string name;
computer_action action;
Expand Down
4 changes: 1 addition & 3 deletions src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ std::string enum_to_string<event_type>( event_type data )
case event_type::game_start: return "game_start";
case event_type::installs_cbm: return "installs_cbm";
case event_type::installs_faulty_cbm: return "installs_faulty_cbm";
case event_type::launches_nuke: return "launches_nuke";
case event_type::learns_martial_art: return "learns_martial_art";
case event_type::loses_addiction: return "loses_addiction";
case event_type::npc_becomes_hostile: return "npc_becomes_hostile";
Expand Down Expand Up @@ -92,7 +91,7 @@ constexpr std::array<std::pair<const char *, cata_variant_type>,
constexpr std::array<std::pair<const char *, cata_variant_type>,
event_spec_character::fields.size()> event_spec_character::fields;

static_assert( static_cast<int>( event_type::num_event_types ) == 62,
static_assert( static_cast<int>( event_type::num_event_types ) == 61,
"This static_assert is a reminder to add a definition below when you add a new "
"event_type. If your event_spec specialization inherits from another struct for "
"its fields definition then you probably don't need a definition here." );
Expand Down Expand Up @@ -129,7 +128,6 @@ DEFINE_EVENT_FIELDS( game_over )
DEFINE_EVENT_FIELDS( game_start )
DEFINE_EVENT_FIELDS( installs_cbm )
DEFINE_EVENT_FIELDS( installs_faulty_cbm )
DEFINE_EVENT_FIELDS( launches_nuke )
DEFINE_EVENT_FIELDS( learns_martial_art )
DEFINE_EVENT_FIELDS( loses_addiction )
DEFINE_EVENT_FIELDS( npc_becomes_hostile )
Expand Down
11 changes: 1 addition & 10 deletions src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ enum class event_type {
game_start,
installs_cbm,
installs_faulty_cbm,
launches_nuke,
learns_martial_art,
loses_addiction,
npc_becomes_hostile,
Expand Down Expand Up @@ -134,7 +133,7 @@ struct event_spec_character {
};
};

static_assert( static_cast<int>( event_type::num_event_types ) == 62,
static_assert( static_cast<int>( event_type::num_event_types ) == 61,
"This static_assert is to remind you to add a specialization for your new "
"event_type below" );

Expand Down Expand Up @@ -433,14 +432,6 @@ struct event_spec<event_type::installs_faulty_cbm> {
};
};

template<>
struct event_spec<event_type::launches_nuke> {
static constexpr std::array<std::pair<const char *, cata_variant_type>, 1> fields = {{
{ "target_terrain", cata_variant_type::oter_id },
}
};
};

template<>
struct event_spec<event_type::learns_martial_art> {
static constexpr std::array<std::pair<const char *, cata_variant_type>, 2> fields = {{
Expand Down
29 changes: 0 additions & 29 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,35 +825,6 @@ void resonance_cascade( const tripoint &p )
}
}

void nuke( const tripoint &p )
{
// TODO: nukes hit above surface, not critter = 0
// TODO: Z
tripoint p_surface( p.xy(), 0 );
tinymap tmpmap;
tmpmap.load( omt_to_sm_copy( p_surface ), false );
tripoint dest( 0, 0, p.z );
int &i = dest.x;
int &j = dest.y;
for( i = 0; i < SEEX * 2; i++ ) {
for( j = 0; j < SEEY * 2; j++ ) {
if( !one_in( 10 ) ) {
tmpmap.make_rubble( dest, f_rubble_rock, true, t_dirt, true );
}
if( one_in( 3 ) ) {
tmpmap.add_field( dest, fd_nuke_gas, 3 );
}
tmpmap.adjust_radiation( dest, rng( 20, 80 ) );
}
}
tmpmap.save();
overmap_buffer.ter_set( p_surface, oter_id( "crater" ) );
// Kill any npcs on that omap location.
for( const auto &npc : overmap_buffer.get_npcs_near_omt( p_surface, 0 ) ) {
npc->marked_for_death = true;
}
}

} // namespace explosion_handler

// This is only ever used to zero the cloud values, which is what makes it work.
Expand Down
2 changes: 0 additions & 2 deletions src/explosion.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ void resonance_cascade( const tripoint &p );
void scrambler_blast( const tripoint &p );
/** Triggers an EMP blast at p. */
void emp_blast( const tripoint &p );
/** Nuke the area at p - global overmap terrain coordinates! */
void nuke( const tripoint &p );
// shockwave applies knockback to all targets within radius of p
// parameters force, stun, and dam_mult are passed to knockback()
// ignore_player determines if player is affected, useful for bionic, etc.
Expand Down
8 changes: 0 additions & 8 deletions src/memorial_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,14 +878,6 @@ void memorial_logger::notify( const cata::event &e )
}
break;
}
case event_type::launches_nuke: {
oter_id oter = e.get<oter_id>( "target_terrain" );
//~ %s is terrain name
add( pgettext( "memorial_male", "Launched a nuke at a %s." ),
pgettext( "memorial_female", "Launched a nuke at a %s." ),
oter->get_name() );
break;
}
case event_type::learns_martial_art: {
character_id ch = e.get<character_id>( "character" );
if( ch == g->u.getID() ) {
Expand Down
3 changes: 0 additions & 3 deletions tests/memorial_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ TEST_CASE( "memorials" )
check_memorial<event_type::installs_faulty_cbm>(
m, b, "Installed bad bionic: Alarm System.", ch, cbm );

check_memorial<event_type::launches_nuke>(
m, b, "Launched a nuke at a garage.", oter_id( "s_garage_north" ) );

check_memorial<event_type::learns_martial_art>(
m, b, "Learned Aikido.", ch, matype_id( "style_aikido" ) );

Expand Down

0 comments on commit 1f3199e

Please sign in to comment.