Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fields (step 8) #32491

Merged
merged 5 commits into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions data/json/field_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
"decay_amount_factor": 5,
"gas_absorption_factor": 12,
"dirty_transparency_cache": true,
"percent_spread": 10,
"outdoor_age_speedup": "0 turns",
"immunity_data": { "body_part_env_resistance": [ [ "MOUTH", 12 ] ] },
"priority": 8,
"half_life": "2 minutes",
Expand All @@ -206,6 +208,8 @@
],
"decay_amount_factor": 5,
"gas_absorption_factor": 15,
"percent_spread": 30,
"outdoor_age_speedup": "3 minutes",
"dirty_transparency_cache": true,
"has_fume": true,
"immunity_data": { "body_part_env_resistance": [ [ "MOUTH", 15 ] ] },
Expand All @@ -226,6 +230,8 @@
],
"decay_amount_factor": 5,
"gas_absorption_factor": 15,
"percent_spread": 10,
"outdoor_age_speedup": "0 turns",
"dirty_transparency_cache": true,
"has_fume": true,
"immunity_data": { "body_part_env_resistance": [ [ "MOUTH", 15 ] ] },
Expand All @@ -240,11 +246,13 @@
"type": "field_type",
"legacy_enum_id": 15,
"intensity_levels": [
{ "name": "hazy cloud", "sym": "8", "dangerous": true, "translucency": 10 },
{ "name": "radioactive gas", "color": "light_green" },
{ "name": "thick radioactive gas", "color": "green", "transparent": false }
{ "name": "hazy cloud", "sym": "8", "dangerous": true, "translucency": 10, "extra_radiation_max": 1 },
{ "name": "radioactive gas", "color": "light_green", "extra_radiation_max": 2 },
{ "name": "thick radioactive gas", "color": "green", "transparent": false, "extra_radiation_max": 3 }
],
"decay_amount_factor": 5,
"percent_spread": 15,
"outdoor_age_speedup": "1 minutes",
"dirty_transparency_cache": true,
"has_fume": true,
"priority": 8,
Expand All @@ -258,6 +266,7 @@
"type": "field_type",
"legacy_enum_id": 16,
"intensity_levels": [ { "name": "gas vent" } ],
"wandering_field": "fd_toxic_gas",
"gas_absorption_factor": 15,
"dirty_transparency_cache": true,
"immunity_data": { "body_part_env_resistance": [ [ "MOUTH", 15 ] ] },
Expand Down Expand Up @@ -489,6 +498,8 @@
{ "name": "thick tobacco smoke", "color": "dark_gray" }
],
"decay_amount_factor": 5,
"percent_spread": 250,
"outdoor_age_speedup": "6 minutes",
"dirty_transparency_cache": true,
"priority": 8,
"half_life": "35 minutes",
Expand All @@ -505,7 +516,10 @@
{ "name": "pot smoke", "color": "light_gray" },
{ "name": "thick pot smoke", "color": "dark_gray" }
],
"npc_complain": { "chance": 20, "issue": "weed_smell", "duration": "10 minutes", "speech": "<weed_smell>" },
"decay_amount_factor": 5,
"percent_spread": 200,
"outdoor_age_speedup": "6 minutes",
"dirty_transparency_cache": true,
"priority": 8,
"half_life": "325 turns",
Expand All @@ -522,7 +536,10 @@
{ "name": "crack smoke", "color": "light_gray" },
{ "name": "thick crack smoke", "color": "dark_gray" }
],
"npc_complain": { "chance": 20, "issue": "crack_smell", "duration": "30 minutes", "speech": "<crack_smell>" },
"decay_amount_factor": 5,
"percent_spread": 175,
"outdoor_age_speedup": "8 minutes",
"dirty_transparency_cache": true,
"priority": 8,
"half_life": "225 turns",
Expand All @@ -539,7 +556,10 @@
{ "name": "meth smoke", "color": "light_gray" },
{ "name": "thick meth smoke", "color": "dark_gray" }
],
"npc_complain": { "chance": 20, "issue": "meth_smell", "duration": "30 minutes", "speech": "<meth_smell>" },
"decay_amount_factor": 5,
"percent_spread": 175,
"outdoor_age_speedup": "7 minutes",
"dirty_transparency_cache": true,
"priority": 8,
"half_life": "275 turns",
Expand All @@ -556,6 +576,8 @@
{ "name": "swarm of bees", "color": "light_gray" },
{ "name": "angry swarm of bees", "color": "dark_gray" }
],
"percent_spread": 5,
"outdoor_age_speedup": "0 turns",
"dirty_transparency_cache": true,
"priority": 8,
"half_life": "100 minutes",
Expand All @@ -577,6 +599,8 @@
"translucency": 0
}
],
"percent_spread": 66,
"outdoor_age_speedup": "4 minutes",
"dirty_transparency_cache": true,
"has_fire": true,
"priority": 8,
Expand All @@ -596,6 +620,8 @@
],
"decay_amount_factor": 5,
"gas_absorption_factor": 15,
"percent_spread": 15,
"outdoor_age_speedup": "5 minutes",
"dirty_transparency_cache": true,
"has_fume": true,
"immunity_data": { "body_part_env_resistance": [ [ "MOUTH", 15 ] ] },
Expand All @@ -616,6 +642,8 @@
],
"decay_amount_factor": 5,
"gas_absorption_factor": 15,
"percent_spread": 13,
"outdoor_age_speedup": "5 turns",
"dirty_transparency_cache": true,
"has_fume": true,
"immunity_data": { "traits": [ "M_IMMUNE" ], "body_part_env_resistance": [ [ "MOUTH", 15 ], [ "EYES", 15 ] ] },
Expand All @@ -635,6 +663,8 @@
{ "color": "cyan", "convection_temperature_mod": -6 }
],
"decay_amount_factor": 5,
"percent_spread": 100,
"outdoor_age_speedup": "100 minutes",
"priority": -1,
"half_life": "50 minutes",
"phase": "gas",
Expand All @@ -650,6 +680,8 @@
{ "color": "cyan", "convection_temperature_mod": -20 }
],
"decay_amount_factor": 5,
"percent_spread": 100,
"outdoor_age_speedup": "100 minutes",
"priority": -1,
"half_life": "50 minutes",
"phase": "gas",
Expand All @@ -665,6 +697,8 @@
{ "color": "cyan", "convection_temperature_mod": -70 }
],
"decay_amount_factor": 5,
"percent_spread": 100,
"outdoor_age_speedup": "100 minutes",
"priority": -1,
"half_life": "50 minutes",
"phase": "gas",
Expand All @@ -680,6 +714,8 @@
{ "color": "cyan", "convection_temperature_mod": -160 }
],
"decay_amount_factor": 5,
"percent_spread": 100,
"outdoor_age_speedup": "100 minutes",
"priority": -1,
"half_life": "50 minutes",
"phase": "gas",
Expand All @@ -695,6 +731,8 @@
{ "color": "red", "convection_temperature_mod": 10 }
],
"decay_amount_factor": 5,
"percent_spread": 100,
"outdoor_age_speedup": "100 minutes",
"priority": -1,
"half_life": "50 minutes",
"phase": "gas",
Expand All @@ -710,6 +748,8 @@
{ "color": "red", "convection_temperature_mod": 20 }
],
"decay_amount_factor": 5,
"percent_spread": 100,
"outdoor_age_speedup": "100 minutes",
"priority": -1,
"half_life": "50 minutes",
"phase": "gas",
Expand All @@ -725,6 +765,8 @@
{ "color": "red", "convection_temperature_mod": 70 }
],
"decay_amount_factor": 5,
"percent_spread": 100,
"outdoor_age_speedup": "100 minutes",
"priority": -1,
"half_life": "50 minutes",
"phase": "gas",
Expand All @@ -740,6 +782,8 @@
{ "color": "red", "convection_temperature_mod": 160 }
],
"decay_amount_factor": 5,
"percent_spread": 100,
"outdoor_age_speedup": "100 minutes",
"priority": -1,
"half_life": "50 minutes",
"phase": "gas",
Expand All @@ -755,6 +799,8 @@
{ "name": "thick fungicidal gas", "color": "dark_gray", "transparent": false }
],
"decay_amount_factor": 5,
"percent_spread": 120,
"outdoor_age_speedup": "1 minutes",
"dirty_transparency_cache": true,
"has_fume": true,
"priority": 8,
Expand All @@ -768,6 +814,7 @@
"type": "field_type",
"legacy_enum_id": 50,
"intensity_levels": [ { "name": "smoke vent", "dangerous": true } ],
"wandering_field": "fd_smoke",
"gas_absorption_factor": 15,
"dirty_transparency_cache": true,
"has_fume": true,
Expand Down
10 changes: 10 additions & 0 deletions src/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ int field_entry::move_cost() const
return type.obj().get_move_cost( intensity - 1 );
}

int field_entry::extra_radiation_min() const
{
return type.obj().get_extra_radiation_min( intensity - 1 );
}

int field_entry::extra_radiation_max() const
{
return type.obj().get_extra_radiation_max( intensity - 1 );
}

float field_entry::light_emitted() const
{
return type.obj().get_light_emitted( intensity - 1 );
Expand Down
7 changes: 7 additions & 0 deletions src/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class field_entry
//returns the move cost of this field
int move_cost() const;

int extra_radiation_min() const;
int extra_radiation_max() const;

float light_emitted() const;
float translucency() const;
bool is_transparent() const;
Expand Down Expand Up @@ -74,6 +77,10 @@ class field_entry
return is_alive;
}

bool gas_can_spread() {
return is_field_alive() && type.obj().phase == GAS && type.obj().percent_spread > 0;
}

time_duration get_underwater_age_speedup() const {
return type.obj().underwater_age_speedup;
}
Expand Down
28 changes: 28 additions & 0 deletions src/field_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ void field_type::load( JsonObject &jo, const std::string & )
fallback_intensity_level.dangerous );
optional( jao, was_loaded, "move_cost", intensity_level.move_cost,
fallback_intensity_level.move_cost );
optional( jao, was_loaded, "extra_radiation_min", intensity_level.extra_radiation_min,
fallback_intensity_level.extra_radiation_min );
optional( jao, was_loaded, "extra_radiation_max", intensity_level.extra_radiation_max,
fallback_intensity_level.extra_radiation_max );
optional( jao, was_loaded, "light_emitted", intensity_level.light_emitted,
fallback_intensity_level.light_emitted );
optional( jao, was_loaded, "translucency", intensity_level.translucency,
Expand All @@ -90,6 +94,20 @@ void field_type::load( JsonObject &jo, const std::string & )
fallback_intensity_level.convection_temperature_mod );
intensity_levels.emplace_back( intensity_level );
}

if( jo.has_object( "npc_complain" ) ) {
JsonObject joc = jo.get_object( "npc_complain" );
int chance;
std::string issue;
time_duration duration;
std::string speech;
optional( joc, was_loaded, "chance", chance, 0 );
optional( joc, was_loaded, "issue", issue );
optional( joc, was_loaded, "duration", duration, 0_turns );
optional( joc, was_loaded, "speech", speech );
npc_complain_data = std::make_tuple( chance, issue, duration, speech );
}

JsonObject jid = jo.get_object( "immunity_data" );
JsonArray jidt = jid.get_array( "traits" );
while( jidt.has_more() ) {
Expand All @@ -102,7 +120,9 @@ void field_type::load( JsonObject &jo, const std::string & )
jao.get_string( 0 ) ), jao.get_int( 1 ) ) );
}
optional( jo, was_loaded, "underwater_age_speedup", underwater_age_speedup, 0_turns );
optional( jo, was_loaded, "outdoor_age_speedup", outdoor_age_speedup, 0_turns );
optional( jo, was_loaded, "decay_amount_factor", decay_amount_factor, 0 );
optional( jo, was_loaded, "percent_spread", percent_spread, 0 );
optional( jo, was_loaded, "apply_slime_factor", apply_slime_factor, 0 );
optional( jo, was_loaded, "gas_absorption_factor", gas_absorption_factor, 0 );
optional( jo, was_loaded, "is_splattering", is_splattering, false );
Expand All @@ -119,6 +139,13 @@ void field_type::load( JsonObject &jo, const std::string & )
optional( jo, was_loaded, "accelerated_decay", accelerated_decay, false );
optional( jo, was_loaded, "display_items", display_items, true );
optional( jo, was_loaded, "display_field", display_field, false );
optional( jo, was_loaded, "wandering_field_id", wandering_field_id, "fd_null" );
}

void field_type::finalize()
{
wandering_field = field_type_id( wandering_field_id );
wandering_field_id.empty();
}

void field_type::check() const
Expand Down Expand Up @@ -148,6 +175,7 @@ void field_types::load( JsonObject &jo, const std::string &src )
void field_types::finalize_all()
{
set_field_type_ids();
all_field_types.finalize();
}

void field_types::check_consistency()
Expand Down
18 changes: 18 additions & 0 deletions src/field_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct field_intensity_level {
bool dangerous = false;
bool transparent = true;
int move_cost = 0;
int extra_radiation_min = 0;
int extra_radiation_max = 0;
float light_emitted = 0.0f;
float translucency = 0.0f;
int convection_temperature_mod = 0.0f;
Expand All @@ -37,20 +39,26 @@ struct field_intensity_level {
struct field_type {
public:
void load( JsonObject &jo, const std::string &src );
void finalize();
void check() const;

public:
// Used by generic_factory
field_type_str_id id;
bool was_loaded = false;

// Used only during loading
std::string wandering_field_id = "fd_null";

public:
int legacy_enum_id = -1;

std::vector<field_intensity_level> intensity_levels;

time_duration underwater_age_speedup = 0_turns;
time_duration outdoor_age_speedup = 0_turns;
int decay_amount_factor = 0;
int percent_spread = 0;
int apply_slime_factor = 0;
int gas_absorption_factor = 0;
bool is_splattering = false;
Expand All @@ -60,6 +68,9 @@ struct field_type {
bool has_elec = false;
bool has_fume = false;

// chance, issue, duration, speech
std::tuple<int, std::string, time_duration, std::string> npc_complain_data;

std::vector<trait_id> immunity_data_traits;
std::vector<std::pair<body_part, int>> immunity_data_body_part_env_resistance;

Expand All @@ -69,6 +80,7 @@ struct field_type {
bool accelerated_decay = false;
bool display_items = true;
bool display_field = false;
field_type_id wandering_field;

public:
std::string get_name( int level = 0 ) const {
Expand All @@ -92,6 +104,12 @@ struct field_type {
int get_move_cost( int level = 0 ) const {
return intensity_levels[level].move_cost;
}
int get_extra_radiation_min( int level = 0 ) const {
return intensity_levels[level].extra_radiation_min;
}
int get_extra_radiation_max( int level = 0 ) const {
return intensity_levels[level].extra_radiation_max;
}
float get_light_emitted( int level = 0 ) const {
return intensity_levels[level].light_emitted;
}
Expand Down
Loading