Skip to content

Commit

Permalink
Replace global field_type_ids with inline defs
Browse files Browse the repository at this point in the history
Having this big list of global variables for the field types caused the
game to give an error when the game was loaded with the dda mod.
Replace all of these except the sentinel (fd_null) with inline
definitions.
  • Loading branch information
anothersimulacrum committed Aug 29, 2020
1 parent 37c0787 commit da3a1fe
Show file tree
Hide file tree
Showing 35 changed files with 327 additions and 468 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ void activity_handlers::oxytorch_finish( player_activity *act, player *p )
here.furn_set( pos, f_safe_o );
// 50% of starting a fire.
if( here.flammable_items_at( pos ) && rng( 1, 100 ) < 50 ) {
here.add_field( pos, fd_fire, 1, 10_minutes );
here.add_field( pos, field_type_id( "fd_fire" ), 1, 10_minutes );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ void activity_on_turn_move_loot( player_activity &act, player &p )
// (to prevent taking out wood off the lit brazier)
// and inaccessible furniture, like filled charcoal kiln
if( mgr.has( zone_type_LOOT_IGNORE, src ) ||
here.get_field( src_loc, fd_fire ) != nullptr ||
here.get_field( src_loc, field_type_id( "fd_fire" ) ) != nullptr ||
!here.can_put_items_ter_furn( src_loc ) ) {
continue;
}
Expand Down Expand Up @@ -2890,7 +2890,7 @@ static cata::optional<tripoint> find_best_fire( const std::vector<tripoint> &fro
time_duration best_fire_age = 1_days;
map &here = get_map();
for( const tripoint &pt : from ) {
field_entry *fire = here.get_field( pt, fd_fire );
field_entry *fire = here.get_field( pt, field_type_id( "fd_fire" ) );
if( fire == nullptr || fire->get_field_intensity() > 1 ||
!here.clear_path( center, pt, PICKUP_RANGE, 1, 100 ) ) {
continue;
Expand Down Expand Up @@ -3052,7 +3052,7 @@ void try_fuel_fire( player_activity &act, player &p, const bool starting_fire )
// Special case: fire containers allow burning logs, so use them as fuel if fire is contained
bool contained = here.has_flag_furn( TFLAG_FIRE_CONTAINER, *best_fire );
fire_data fd( 1, contained );
time_duration fire_age = here.get_field_age( *best_fire, fd_fire );
time_duration fire_age = here.get_field_age( *best_fire, field_type_id( "fd_fire" ) );

// Maybe TODO: - refueling in the rain could use more fuel
// First, simulate expected burn per turn, to see if we need more fuel
Expand Down
2 changes: 1 addition & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui )
const cata::optional<tripoint> pnt = choose_adjacent( _( "Start a fire where?" ) );
if( pnt && here.is_flammable( *pnt ) ) {
add_msg_activate();
here.add_field( *pnt, fd_fire, 1 );
here.add_field( *pnt, field_type_id( "fd_fire" ), 1 );
mod_moves( -100 );
} else {
refund_power();
Expand Down
2 changes: 1 addition & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int
auto field_at = [&]( const tripoint & q, const bool invis ) -> field_type_id {
const auto it = field_override.find( q );
return it != field_override.end() ? it->second :
( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : fd_null;
( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : field_type_id( "fd_null" );
};
// for rotation information
const int neighborhood[4] = {
Expand Down
18 changes: 9 additions & 9 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,22 +501,22 @@ void Character::randomize_blood()
field_type_id Character::bloodType() const
{
if( has_trait( trait_ACIDBLOOD ) ) {
return fd_acid;
return field_type_id( "fd_acid" );
}
if( has_trait( trait_THRESH_PLANT ) ) {
return fd_blood_veggy;
return field_type_id( "fd_blood_veggy" );
}
if( has_trait( trait_THRESH_INSECT ) || has_trait( trait_THRESH_SPIDER ) ) {
return fd_blood_insect;
return field_type_id( "fd_blood_insect" );
}
if( has_trait( trait_THRESH_CEPHALOPOD ) ) {
return fd_blood_invertebrate;
return field_type_id( "fd_blood_invertebrate" );
}
return fd_blood;
return field_type_id( "fd_blood" );
}
field_type_id Character::gibType() const
{
return fd_gibs_flesh;
return field_type_id( "fd_gibs_flesh" );
}

bool Character::in_species( const species_id &spec ) const
Expand Down Expand Up @@ -6251,7 +6251,7 @@ Character::comfort_response_t Character::base_comfort_value( const tripoint &p )
const ter_id ter_at_pos = tile.get_ter();
const furn_id furn_at_pos = tile.get_furn();

int web = here.get_field_intensity( p, fd_web );
int web = here.get_field_intensity( p, field_type_id( "fd_web" ) );

// Some mutants have different comfort needs
if( !plantsleep && !webforce ) {
Expand Down Expand Up @@ -8450,7 +8450,7 @@ void Character::vomit()

if( stomach.contains() != 0_ml ) {
stomach.empty();
get_map().add_field( adjacent_tile(), fd_bile, 1 );
get_map().add_field( adjacent_tile(), field_type_id( "fd_bile" ), 1 );
add_msg_player_or_npc( m_bad, _( "You throw up heavily!" ), _( "<npcname> throws up heavily!" ) );
}

Expand Down Expand Up @@ -9474,7 +9474,7 @@ void Character::blossoms()
sounds::sound( pos(), 10, sounds::sound_t::combat, _( "Pouf!" ), false, "misc", "puff" );
map &here = get_map();
for( const tripoint &tmp : here.points_in_radius( pos(), 2 ) ) {
here.add_field( tmp, fd_fungal_haze, rng( 1, 2 ) );
here.add_field( tmp, field_type_id( "fd_fungal_haze" ), rng( 1, 2 ) );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/computer_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ void computer_session::action_irradiator()
"alarm" );
here.i_rem( dest, it );
here.make_rubble( dest );
here.propagate_field( dest, fd_nuke_gas, 100, 3 );
here.propagate_field( dest, field_type_id( "fd_nuke_gas" ), 100, 3 );
here.translate_radius( t_water_pool, t_sewage, 8.0, dest, true );
here.adjust_radiation( dest, rng( 50, 500 ) );
for( const tripoint &radorigin : here.points_in_radius( dest, 5 ) ) {
Expand Down Expand Up @@ -1260,13 +1260,13 @@ void computer_session::action_deactivate_shock_vent()
bool has_generator = false;
map &here = get_map();
for( const tripoint &dest : here.points_in_radius( player_character.pos(), 10 ) ) {
if( here.get_field( dest, fd_shock_vent ) != nullptr ) {
if( here.get_field( dest, field_type_id( "fd_shock_vent" ) ) != nullptr ) {
has_vent = true;
}
if( here.ter( dest ) == t_plut_generator ) {
has_generator = true;
}
here.remove_field( dest, fd_shock_vent );
here.remove_field( dest, field_type_id( "fd_shock_vent" ) );
}
print_line( _( "Initiating POWER-DIAG ver.2.34…" ) );
if( has_vent ) {
Expand Down
14 changes: 7 additions & 7 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static void do_blast( const tripoint &p, const float power,
intensity++;
}

here.add_field( pt, fd_fire, intensity );
here.add_field( pt, field_type_id( "fd_fire" ), intensity );
}

if( const optional_vpart_position vp = here.veh_at( pt ) ) {
Expand Down Expand Up @@ -803,24 +803,24 @@ void resonance_cascade( const tripoint &p )
case 5:
for( int k = i - 1; k <= i + 1; k++ ) {
for( int l = j - 1; l <= j + 1; l++ ) {
field_type_id type = fd_null;
field_type_id type = field_type_id( "fd_null" );
switch( rng( 1, 7 ) ) {
case 1:
type = fd_blood;
type = field_type_id( "fd_blood" );
break;
case 2:
type = fd_bile;
type = field_type_id( "fd_bile" );
break;
case 3:
case 4:
type = fd_slime;
type = field_type_id( "fd_slime" );
break;
case 5:
type = fd_fire;
type = field_type_id( "fd_fire" );
break;
case 6:
case 7:
type = fd_nuke_gas;
type = field_type_id( "fd_nuke_gas" );
break;
}
if( !one_in( 3 ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ void field::remove_field( std::map<field_type_id, field_entry>::iterator const i
{
_field_type_list.erase( it );
if( _field_type_list.empty() ) {
_displayed_field_type = fd_null;
_displayed_field_type = field_type_id( "fd_null" );
} else {
_displayed_field_type = fd_null;
_displayed_field_type = field_type_id( "fd_null" );
for( auto &fld : _field_type_list ) {
if( fld.first.obj().priority >= _displayed_field_type.obj().priority ) {
_displayed_field_type = fld.first;
Expand Down
107 changes: 3 additions & 104 deletions src/field_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "json.h"
#include "string_id.h"

field_type_id fd_null;

namespace io
{

Expand Down Expand Up @@ -270,6 +272,7 @@ void field_type::finalize()
debugmsg( "Invalid mtype_id %s in immune_mtypes for field %s.", m_id.c_str(), id.c_str() );
}
}
fd_null = field_type_id( "fd_null" );
}

void field_type::check() const
Expand All @@ -295,7 +298,6 @@ void field_types::load( const JsonObject &jo, const std::string &src )

void field_types::finalize_all()
{
set_field_type_ids();
all_field_types.finalize();
for( const field_type &fd : all_field_types.get_all() ) {
const_cast<field_type &>( fd ).finalize();
Expand All @@ -317,109 +319,6 @@ const std::vector<field_type> &field_types::get_all()
return all_field_types.get_all();
}

field_type_id fd_null,
fd_blood,
fd_bile,
fd_extinguisher,
fd_gibs_flesh,
fd_gibs_veggy,
fd_web,
fd_slime,
fd_acid,
fd_sap,
fd_sludge,
fd_fire,
fd_smoke,
fd_toxic_gas,
fd_tear_gas,
fd_nuke_gas,
fd_gas_vent,
fd_fire_vent,
fd_flame_burst,
fd_electricity,
fd_fatigue,
fd_push_items,
fd_shock_vent,
fd_acid_vent,
fd_plasma,
fd_laser,
fd_dazzling,
fd_blood_veggy,
fd_blood_insect,
fd_blood_invertebrate,
fd_gibs_insect,
fd_gibs_invertebrate,
fd_bees,
fd_incendiary,
fd_relax_gas,
fd_fungal_haze,
fd_cold_air1,
fd_cold_air2,
fd_cold_air3,
fd_cold_air4,
fd_hot_air1,
fd_hot_air2,
fd_hot_air3,
fd_hot_air4,
fd_fungicidal_gas,
fd_insecticidal_gas,
fd_smoke_vent,
fd_tindalos_rift
;

void field_types::set_field_type_ids()
{
fd_null = field_type_id( "fd_null" );
fd_blood = field_type_id( "fd_blood" );
fd_bile = field_type_id( "fd_bile" );
fd_extinguisher = field_type_id( "fd_extinguisher" );
fd_gibs_flesh = field_type_id( "fd_gibs_flesh" );
fd_gibs_veggy = field_type_id( "fd_gibs_veggy" );
fd_web = field_type_id( "fd_web" );
fd_slime = field_type_id( "fd_slime" );
fd_acid = field_type_id( "fd_acid" );
fd_sap = field_type_id( "fd_sap" );
fd_sludge = field_type_id( "fd_sludge" );
fd_fire = field_type_id( "fd_fire" );
fd_smoke = field_type_id( "fd_smoke" );
fd_toxic_gas = field_type_id( "fd_toxic_gas" );
fd_tear_gas = field_type_id( "fd_tear_gas" );
fd_nuke_gas = field_type_id( "fd_nuke_gas" );
fd_gas_vent = field_type_id( "fd_gas_vent" );
fd_fire_vent = field_type_id( "fd_fire_vent" );
fd_flame_burst = field_type_id( "fd_flame_burst" );
fd_electricity = field_type_id( "fd_electricity" );
fd_fatigue = field_type_id( "fd_fatigue" );
fd_push_items = field_type_id( "fd_push_items" );
fd_shock_vent = field_type_id( "fd_shock_vent" );
fd_acid_vent = field_type_id( "fd_acid_vent" );
fd_plasma = field_type_id( "fd_plasma" );
fd_laser = field_type_id( "fd_laser" );
fd_dazzling = field_type_id( "fd_dazzling" );
fd_blood_veggy = field_type_id( "fd_blood_veggy" );
fd_blood_insect = field_type_id( "fd_blood_insect" );
fd_blood_invertebrate = field_type_id( "fd_blood_invertebrate" );
fd_gibs_insect = field_type_id( "fd_gibs_insect" );
fd_gibs_invertebrate = field_type_id( "fd_gibs_invertebrate" );
fd_bees = field_type_id( "fd_bees" );
fd_incendiary = field_type_id( "fd_incendiary" );
fd_relax_gas = field_type_id( "fd_relax_gas" );
fd_fungal_haze = field_type_id( "fd_fungal_haze" );
fd_cold_air1 = field_type_id( "fd_cold_air1" );
fd_cold_air2 = field_type_id( "fd_cold_air2" );
fd_cold_air3 = field_type_id( "fd_cold_air3" );
fd_cold_air4 = field_type_id( "fd_cold_air4" );
fd_hot_air1 = field_type_id( "fd_hot_air1" );
fd_hot_air2 = field_type_id( "fd_hot_air2" );
fd_hot_air3 = field_type_id( "fd_hot_air3" );
fd_hot_air4 = field_type_id( "fd_hot_air4" );
fd_fungicidal_gas = field_type_id( "fd_fungicidal_gas" );
fd_insecticidal_gas = field_type_id( "fd_insecticidal_gas" );
fd_smoke_vent = field_type_id( "fd_smoke_vent" );
fd_tindalos_rift = field_type_id( "fd_tindalos_rift" );

}

field_type field_types::get_field_type_by_legacy_enum( int legacy_enum_id )
{
for( const auto &ft : all_field_types.get_all() ) {
Expand Down
53 changes: 2 additions & 51 deletions src/field_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ struct field_intensity_level {
std::vector<field_effect> field_effects;
};

extern field_type_id fd_null;

struct field_type {
public:
void load( const JsonObject &jo, const std::string &src );
Expand Down Expand Up @@ -265,59 +267,8 @@ void check_consistency();
void reset();

const std::vector<field_type> &get_all();
void set_field_type_ids();
field_type get_field_type_by_legacy_enum( int legacy_enum_id );

} // namespace field_types

extern field_type_id fd_null,
fd_blood,
fd_bile,
fd_extinguisher,
fd_gibs_flesh,
fd_gibs_veggy,
fd_web,
fd_slime,
fd_acid,
fd_sap,
fd_sludge,
fd_fire,
fd_smoke,
fd_toxic_gas,
fd_tear_gas,
fd_nuke_gas,
fd_gas_vent,
fd_fire_vent,
fd_flame_burst,
fd_electricity,
fd_fatigue,
fd_push_items,
fd_shock_vent,
fd_acid_vent,
fd_plasma,
fd_laser,
fd_dazzling,
fd_blood_veggy,
fd_blood_insect,
fd_blood_invertebrate,
fd_gibs_insect,
fd_gibs_invertebrate,
fd_bees,
fd_incendiary,
fd_relax_gas,
fd_fungal_haze,
fd_cold_air1,
fd_cold_air2,
fd_cold_air3,
fd_cold_air4,
fd_hot_air1,
fd_hot_air2,
fd_hot_air3,
fd_hot_air4,
fd_fungicidal_gas,
fd_insecticidal_gas,
fd_smoke_vent,
fd_tindalos_rift
;

#endif // CATA_SRC_FIELD_TYPE_H
Loading

0 comments on commit da3a1fe

Please sign in to comment.