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

Move more body_part to bodypart_id in Character part1 #40144

Merged
merged 14 commits into from
May 11, 2020
Merged
Prev Previous commit
Next Next commit
no_cbm_on_bp,occupied_body_part,can_install_cbm_on_bp,get_occupied_bo…
…dyparts
  • Loading branch information
Fris0uman committed May 8, 2020
commit 3eb474124825a28e5ac0fcc43207705ab6ee7766
362 changes: 181 additions & 181 deletions data/json/bionics.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions data/json/obsolete.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "bionic",
"name": { "str": "Advanced Microreactor System" },
"description": "This stripped down mini-reactor is more efficient and safer than the base model due to integrated radiation cleansers. There is no way to shut it down once active, but you can toggle additional fuel intake.",
"occupied_bodyparts": [ [ "TORSO", 55 ] ],
"occupied_bodyparts": [ [ "torso", 55 ] ],
"flags": [ "BIONIC_POWER_SOURCE", "BIONIC_TOGGLED", "BIONIC_NPC_USABLE" ],
"included_bionics": [ "bio_plutdump" ],
"upgraded_bionic": "bio_reactor"
Expand All @@ -14,7 +14,7 @@
"type": "bionic",
"name": { "str": "Plutonium Filter" },
"description": "This set of tanks and filters allows you to extract plutonium from radioactive slurry.",
"occupied_bodyparts": [ [ "TORSO", 10 ] ],
"occupied_bodyparts": [ [ "torso", 10 ] ],
"flags": [ "BIONIC_TOGGLED", "BIONIC_NPC_USABLE" ],
"act_cost": 1,
"react_cost": 1,
Expand All @@ -33,7 +33,7 @@
"type": "bionic",
"name": { "str": "Microreactor System" },
"description": "This stripped down mini-reactor generates impressive amounts of bionic power. There is no way to shut it down, but you can toggle additional fuel intake. Irradiates your body when active.",
"occupied_bodyparts": [ [ "TORSO", 55 ] ],
"occupied_bodyparts": [ [ "torso", 55 ] ],
"flags": [ "BIONIC_POWER_SOURCE", "BIONIC_TOGGLED", "BIONIC_NPC_USABLE" ],
"available_upgrades": [ "bio_advreactor" ],
"included_bionics": [ "bio_plutdump" ]
Expand All @@ -43,15 +43,15 @@
"type": "bionic",
"name": { "str": "Internal Furnace" },
"description": "When this bionic is active, you can burn nearly any organic material as fuel (use 'E'), recharging your power level. Some materials will burn better than others.",
"occupied_bodyparts": [ [ "TORSO", 40 ] ],
"occupied_bodyparts": [ [ "torso", 40 ] ],
"flags": [ "BIONIC_POWER_SOURCE", "BIONIC_TOGGLED", "BIONIC_NPC_USABLE" ]
},
{
"id": "bio_storage",
"type": "bionic",
"name": { "str": "Internal Storage" },
"description": "Space inside your chest cavity has been surgically converted into a storage area. You may carry an extra 2 liters of volume.",
"occupied_bodyparts": [ [ "TORSO", 32 ] ],
"occupied_bodyparts": [ [ "torso", 32 ] ],
"flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ]
},
{
Expand Down Expand Up @@ -375,7 +375,7 @@
"type": "bionic",
"name": { "str": "Fusion Blaster Arm" },
"description": "Your left arm has been surgically replaced by a heavy-duty fusion blaster! You may use your energy banks to fire a damaging heat ray. However, you are unable to use or carry two-handed items, and your strength limits what you can use with your one hand.",
"occupied_bodyparts": [ [ "ARM_L", 20 ], [ "HAND_L", 5 ] ],
"occupied_bodyparts": [ [ "arm_l", 20 ], [ "hand_l", 5 ] ],
"act_cost": 50,
"fake_item": "bio_blaster_gun",
"flags": [ "BIONIC_GUN" ]
Expand Down Expand Up @@ -855,7 +855,7 @@
"type": "bionic",
"name": { "str": "Scent Vision" },
"description": "While this system is powered, you're able to visually sense your own scent, making it possible for you to recognize your surroundings even in complete darkness.",
"occupied_bodyparts": [ [ "HEAD", 3 ] ],
"occupied_bodyparts": [ [ "head", 3 ] ],
"flags": [ "BIONIC_TOGGLED" ],
"act_cost": "2 J",
"react_cost": "2 J",
Expand Down
12 changes: 6 additions & 6 deletions data/mods/Aftershock/player/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "bionic",
"name": { "str": "Solar Panels" },
"description": "Installed on your back is a set of retractable, reinforced solar panels resembling angular butterfly wings. When in direct sunlight, they will automatically deploy and slowly recharge your power level.",
"occupied_bodyparts": [ [ "TORSO", 10 ] ],
"occupied_bodyparts": [ [ "torso", 10 ] ],
"fuel_options": [ "sunlight" ],
"fuel_efficiency": 1.0,
"time": 1,
Expand All @@ -15,7 +15,7 @@
"type": "bionic",
"name": { "str": "Wind Turbines" },
"description": "Installed on your body is a set of small retractable wind turbines. When activated, they will deploy and slowly harvest wind power to recharge your power level.",
"occupied_bodyparts": [ [ "TORSO", 10 ] ],
"occupied_bodyparts": [ [ "torso", 10 ] ],
"fuel_options": [ "wind" ],
"fuel_efficiency": 0.25,
"time": 1,
Expand All @@ -26,7 +26,7 @@
"type": "bionic",
"name": { "str": "Precision Solderers" },
"description": "Your hands have been outfitted with precise soldering tools, wire cutters, and cable spools. They're too small to use in most crafting, but in the absence of proper machinery, they're essential for creating bionics without better tools.",
"occupied_bodyparts": [ [ "HAND_L", 1 ], [ "HAND_R", 1 ] ],
"occupied_bodyparts": [ [ "hand_l", 1 ], [ "hand_r", 1 ] ],
"fake_item": "afs_solderers_item"
},
{
Expand All @@ -35,7 +35,7 @@
"//": "Watch those wrist rockets!",
"name": { "str": "Deployable Grenade Launcher" },
"description": "Your right hand can fold inward to reveal a mechanism capable of igniting and firing 40mm grenades across medium distances.",
"occupied_bodyparts": [ [ "HAND_R", 3 ] ],
"occupied_bodyparts": [ [ "hand_r", 3 ] ],
"fake_item": "afs_bionic_rocket",
"flags": [ "BIONIC_TOGGLED", "BIONIC_WEAPON", "NO_UNWIELD" ],
"act_cost": 5
Expand All @@ -45,14 +45,14 @@
"type": "bionic",
"name": { "str": "Linguistic Coprocessor" },
"description": "The left hemisphere of your brain has been augmented with a microcomputer that moderately increases the speed that language and written words are processed, granting a 15% increase to reading speed.",
"occupied_bodyparts": [ [ "HEAD", 2 ] ]
"occupied_bodyparts": [ [ "head", 2 ] ]
},
{
"id": "afs_bio_dopamine_stimulators",
"type": "bionic",
"name": { "str": "Dopamine Stimulators" },
"description": "Tiny cybernetic stimulators have been installed throughout your ventral tegmental area, and trigger at set intervals using bionic power. This slowly releases a stream of reward chemicals and hormones into your brain, inducing a state of euphoria that notably elevates mood.",
"occupied_bodyparts": [ [ "HEAD", 5 ] ],
"occupied_bodyparts": [ [ "head", 5 ] ],
"flags": [ "BIONIC_TOGGLED", "BIONIC_SLEEP_FRIENDLY" ],
"act_cost": 5,
"react_cost": 5,
Expand Down
2 changes: 1 addition & 1 deletion data/mods/CrazyCataclysm/crazy_items.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"id": "bio_chest_gun",
"name": { "str": "Ionic Overload Generator" },
"description": "A powerful ion energy generator is implanted on your chest. Fires a powerful, ever-expanding energy blast. The resulting blast ignites oxygen creating fires as it moves and an explosion on impact. Close range use is highly discouraged.",
"occupied_bodyparts": [ [ "TORSO", 20 ] ],
"occupied_bodyparts": [ [ "torso", 20 ] ],
"act_cost": 500,
"fake_item": "bio_ion_gun",
"flags": [ "BIONIC_GUN" ]
Expand Down
2 changes: 1 addition & 1 deletion data/mods/Magiclysm/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "bionic",
"name": { "str": "Blood Power Generator CBM" },
"description": "Embedded into your back and connected to your bionic power supply is a powerfull spell focus able to consume blood from dead creatures to produce bionic power. It can store up to 100 mL of blood.",
"occupied_bodyparts": [ [ "TORSO", 8 ] ],
"occupied_bodyparts": [ [ "torso", 8 ] ],
"fuel_options": [ "blood", "dragon_blood", "tainted_blood", "mana_infused_blood" ],
"fuel_capacity": 100,
"fuel_efficiency": 0.6,
Expand Down
2 changes: 1 addition & 1 deletion data/mods/Magiclysm/items/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"type": "bionic",
"name": { "str": "Crystallized Mana Nose Replacement" },
"description": "A large gem made with crystallized mana and some other stabilizing metals. Comes with a specially designed power pack (installed into the skull) that does not interfere with your mana ley lines. WARNING: for Technomancer use only. By using this spell you are waiving all liability of Frikken Laser Beams Inc. and its subsidiaries.",
"occupied_bodyparts": [ [ "HEAD", 10 ], [ "MOUTH", 1 ] ],
"occupied_bodyparts": [ [ "head", 10 ], [ "mouth", 1 ] ],
"capacity": "500 kJ",
"learned_spells": { "overcharge_eyes": 4 },
"canceled_mutations": [ "EARTHSHAPER" ],
Expand Down
2 changes: 1 addition & 1 deletion data/mods/My_Sweet_Cataclysm/sweet_mutations.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"fat_to_max_hp": 0.1,
"anger_relations": [ [ "MARSHMALLOW", 20 ], [ "GUMMY", 5 ], [ "CHEWGUM", 20 ] ],
"allowed_category": [ "SUGAR" ],
"no_cbm_on_bp": [ "TORSO", "HEAD", "EYES", "MOUTH", "ARM_L", "ARM_R", "HAND_L", "HAND_R", "LEG_L", "LEG_R", "FOOT_L", "FOOT_R" ],
"no_cbm_on_bp": [ "torso", "head", "eyes", "mouth", "arm_l", "arm_r", "hand_l", "hand_r", "leg_l", "leg_r", "foot_l", "foot_r" ],
"armor": [ { "parts": "ALL", "cut": 10, "bash": 5 } ],
"flags": [ "NO_THIRST", "NO_DISEASE", "NO_RADIATION" ]
}
Expand Down
21 changes: 10 additions & 11 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3466,7 +3466,7 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )

const int difficulty = act->values.front();

const std::vector<body_part> bps = get_occupied_bodyparts( bid );
const std::vector<bodypart_id> bps = get_occupied_bodyparts( bid );

const time_duration half_op_duration = difficulty * 10_minutes;
const time_duration message_freq = difficulty * 2_minutes;
Expand All @@ -3488,17 +3488,16 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )
_( "The Autodoc's failure damages <npcname> greatly." ) );
}
if( !bps.empty() ) {
for( const body_part bp : bps ) {
const bodypart_id bpid = convert_bp( bp ).id();
p->make_bleed( bp, 1_turns, difficulty, true );
p->apply_damage( nullptr, bpid, 20 * difficulty );
for( const bodypart_id &bp : bps ) {
p->make_bleed( bp->token, 1_turns, difficulty, true );
p->apply_damage( nullptr, bp, 20 * difficulty );

if( u_see ) {
p->add_msg_player_or_npc( m_bad, _( "Your %s is ripped open." ),
_( "<npcname>'s %s is ripped open." ), body_part_name_accusative( bp ) );
_( "<npcname>'s %s is ripped open." ), body_part_name_accusative( bp->token ) );
}

if( bp == bp_eyes ) {
if( bp == bodypart_id( "eyes" ) ) {
p->add_effect( effect_blind, 1_hours, num_bp );
}
}
Expand All @@ -3511,12 +3510,12 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )

if( time_left > half_op_duration ) {
if( !bps.empty() ) {
for( const body_part bp : bps ) {
for( const bodypart_id &bp : bps ) {
if( calendar::once_every( message_freq ) && u_see && autodoc ) {
p->add_msg_player_or_npc( m_info,
_( "The Autodoc is meticulously cutting your %s open." ),
_( "The Autodoc is meticulously cutting <npcname>'s %s open." ),
body_part_name_accusative( bp ) );
body_part_name_accusative( bp->token ) );
}
}
} else {
Expand Down Expand Up @@ -3556,12 +3555,12 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )
}
} else if( act->values[1] > 0 ) {
if( !bps.empty() ) {
for( const body_part bp : bps ) {
for( const bodypart_id &bp : bps ) {
if( calendar::once_every( message_freq ) && u_see && autodoc ) {
p->add_msg_player_or_npc( m_info,
_( "The Autodoc is stitching your %s back up." ),
_( "The Autodoc is stitching <npcname>'s %s back up." ),
body_part_name_accusative( bp ) );
body_part_name_accusative( bp->token ) );
}
}
} else {
Expand Down
38 changes: 19 additions & 19 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ bool string_id<bionic_data>::is_valid() const
return bionic_factory.is_valid( *this );
}

std::vector<body_part> get_occupied_bodyparts( const bionic_id &bid )
std::vector<bodypart_id> get_occupied_bodyparts( const bionic_id &bid )
{
std::vector<body_part> parts;
for( const auto &element : bid->occupied_bodyparts ) {
std::vector<bodypart_id> parts;
for( const std::pair<bodypart_str_id, size_t> &element : bid->occupied_bodyparts ) {
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
if( element.second > 0 ) {
parts.push_back( element.first );
parts.push_back( element.first.id() );
}
}
return parts;
Expand Down Expand Up @@ -1466,8 +1466,8 @@ void Character::heat_emission( int b, int fuel_energy )
const int heat_spread = std::max( heat_prod / 10 - heat_level, 1 );
g->m.emit_field( pos(), hotness, heat_spread );
}
for( const std::pair<const body_part, size_t> &bp : bio.info().occupied_bodyparts ) {
add_effect( effect_heating_bionic, 2_seconds, bp.first, false, heat_prod );
for( const std::pair<const bodypart_str_id, size_t> &bp : bio.info().occupied_bodyparts ) {
add_effect( effect_heating_bionic, 2_seconds, bp.first->token, false, heat_prod );
}
}

Expand All @@ -1478,10 +1478,10 @@ float Character::get_effective_efficiency( int b, float fuel_efficiency )
float effective_efficiency = fuel_efficiency;
if( coverage_penalty ) {
int coverage = 0;
const std::map< body_part, size_t > &occupied_bodyparts = bio.info().occupied_bodyparts;
for( const std::pair< const body_part, size_t > &elem : occupied_bodyparts ) {
const std::map< bodypart_str_id, size_t > &occupied_bodyparts = bio.info().occupied_bodyparts;
for( const std::pair< const bodypart_str_id, size_t > &elem : occupied_bodyparts ) {
for( const item &i : worn ) {
if( i.covers( elem.first ) && !i.has_flag( flag_ALLOWS_NATURAL_ATTACKS ) &&
if( i.covers( elem.first->token ) && !i.has_flag( flag_ALLOWS_NATURAL_ATTACKS ) &&
!i.has_flag( flag_SEMITANGIBLE ) &&
!i.has_flag( flag_PERSONAL ) && !i.has_flag( flag_AURA ) ) {
coverage += i.get_coverage();
Expand Down Expand Up @@ -2096,8 +2096,8 @@ bool Character::uninstall_bionic( const bionic_id &b_id, player &installer, bool
} else {
activity.str_values.push_back( "false" );
}
for( const std::pair<const body_part, size_t> &elem : b_id->occupied_bodyparts ) {
add_effect( effect_under_op, difficulty * 20_minutes, elem.first, true, difficulty );
for( const std::pair<const bodypart_str_id, size_t> &elem : b_id->occupied_bodyparts ) {
add_effect( effect_under_op, difficulty * 20_minutes, elem.first->token, true, difficulty );
}

return true;
Expand Down Expand Up @@ -2365,8 +2365,8 @@ bool Character::install_bionics( const itype &type, player &installer, bool auto
} else {
activity.str_values.push_back( "false" );
}
for( const std::pair<const body_part, size_t> &elem : bioid->occupied_bodyparts ) {
add_effect( effect_under_op, difficulty * 20_minutes, elem.first, true, difficulty );
for( const std::pair<const bodypart_str_id, size_t> &elem : bioid->occupied_bodyparts ) {
add_effect( effect_under_op, difficulty * 20_minutes, elem.first->token, true, difficulty );
}

return true;
Expand Down Expand Up @@ -2518,11 +2518,11 @@ std::string list_occupied_bps( const bionic_id &bio_id, const std::string &intro
return "";
}
std::string desc = intro;
for( const auto &elem : bio_id->occupied_bodyparts ) {
for( const std::pair<bodypart_str_id, size_t> &elem : bio_id->occupied_bodyparts ) {
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
desc += ( each_bp_on_new_line ? "\n" : " " );
//~ <Bodypart name> (<number of occupied slots> slots);
desc += string_format( _( "%s (%i slots);" ),
body_part_name_as_heading( elem.first, 1 ),
body_part_name_as_heading( elem.first->token, 1 ),
elem.second );
}
return desc;
Expand All @@ -2532,7 +2532,7 @@ int Character::get_used_bionics_slots( const body_part bp ) const
{
int used_slots = 0;
for( const bionic_id &bid : get_bionics() ) {
auto search = bid->occupied_bodyparts.find( bp );
auto search = bid->occupied_bodyparts.find( convert_bp( bp ) );
if( search != bid->occupied_bodyparts.end() ) {
used_slots += search->second;
}
Expand All @@ -2547,10 +2547,10 @@ std::map<body_part, int> Character::bionic_installation_issues( const bionic_id
if( !get_option < bool >( "CBM_SLOTS_ENABLED" ) ) {
return issues;
}
for( auto &elem : bioid->occupied_bodyparts ) {
const int lacked_slots = elem.second - get_free_bionics_slots( elem.first );
for( const std::pair<bodypart_str_id, size_t> &elem : bioid->occupied_bodyparts ) {
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
const int lacked_slots = elem.second - get_free_bionics_slots( elem.first->token );
if( lacked_slots > 0 ) {
issues.emplace( elem.first, lacked_slots );
issues.emplace( elem.first->token, lacked_slots );
}
}
return issues;
Expand Down
4 changes: 2 additions & 2 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct bionic_data {
/**
* Body part slots used to install this bionic, mapped to the amount of space required.
*/
std::map<body_part, size_t> occupied_bodyparts;
std::map<bodypart_str_id, size_t> occupied_bodyparts;
/**
* Body part encumbered by this bionic, mapped to the amount of encumbrance caused.
*/
Expand Down Expand Up @@ -188,7 +188,7 @@ class bionic_collection : public std::vector<bionic>
};

/**List of bodyparts occupied by a bionic*/
std::vector<body_part> get_occupied_bodyparts( const bionic_id &bid );
std::vector<bodypart_id> get_occupied_bodyparts( const bionic_id &bid );

void reset_bionics();

Expand Down
8 changes: 4 additions & 4 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ static void draw_connectors( const catacurses::window &win, const int start_y, c
const int LIST_START_Y = 7;
// first: pos_y, second: occupied slots
std::vector<std::pair<int, size_t>> pos_and_num;
for( const auto &elem : bio_id->occupied_bodyparts ) {
pos_and_num.emplace_back( static_cast<int>( elem.first ) + LIST_START_Y, elem.second );
for( const std::pair<bodypart_str_id, size_t> &elem : bio_id->occupied_bodyparts ) {
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
pos_and_num.emplace_back( static_cast<int>( elem.first->token ) + LIST_START_Y, elem.second );
}
if( pos_and_num.empty() || !get_option < bool >( "CBM_SLOTS_ENABLED" ) ) {
return;
Expand Down Expand Up @@ -562,8 +562,8 @@ void player::power_bionics()
pos_x - 2, bio_id );

// redraw highlighted (occupied) body parts
for( auto &elem : bio_id->occupied_bodyparts ) {
const int i = static_cast<int>( elem.first );
for( const std::pair<bodypart_str_id, size_t> &elem : bio_id->occupied_bodyparts ) {
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
const int i = static_cast<int>( elem.first->token );
mvwprintz( wBio, point( pos_x, i + list_start_y ), c_yellow, bps[i] );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4422,8 +4422,8 @@ void Character::on_damage_of_type( int adjusted_damage, damage_type type, const
if( info.has_flag( "BIONIC_SHOCKPROOF" ) || info.has_flag( "BIONIC_FAULTY" ) ) {
continue;
}
const auto &bodyparts = info.occupied_bodyparts;
if( bodyparts.find( bp->token ) != bodyparts.end() ) {
const std::map<bodypart_str_id, size_t> &bodyparts = info.occupied_bodyparts;
if( bodyparts.find( bp.id() ) != bodyparts.end() ) {
const int bp_hp = hp_cur[bp_to_hp( bp->token )];
// The chance to incapacitate is as high as 50% if the attack deals damage equal to one third of the body part's current health.
if( x_in_y( adjusted_damage * 3, bp_hp ) && one_in( 2 ) ) {
Expand Down
Loading