From d1b523300db8fabe6313c28a76df620eec41af36 Mon Sep 17 00:00:00 2001 From: scarf Date: Thu, 31 Aug 2023 11:31:38 +0900 Subject: [PATCH] refactor: extract `vehicle_part` to header --- src/action.cpp | 1 + src/active_tile_data.cpp | 1 + src/activity_actor.cpp | 1 + src/activity_handlers.cpp | 1 + src/activity_item_handling.cpp | 1 + src/advanced_inv.cpp | 1 + src/advanced_inv_area.cpp | 1 + src/advanced_inv_pane.cpp | 1 + src/avatar.cpp | 1 + src/avatar_action.cpp | 1 + src/avatar_functions.cpp | 1 + src/bionics.cpp | 1 + src/cata_tiles.cpp | 1 + src/character.cpp | 1 + src/character_effects.cpp | 1 + src/character_functions.cpp | 1 + src/character_turn.cpp | 1 + src/clzones.cpp | 1 + src/condition.cpp | 1 + src/construction.cpp | 1 + src/crafting.cpp | 1 + src/creature.cpp | 1 + src/debug_menu.cpp | 1 + src/distribution_grid.cpp | 1 + src/dump.cpp | 1 + src/editmap.cpp | 1 + src/explosion.cpp | 1 + src/faction_camp.cpp | 1 + src/game.cpp | 1 + src/gates.cpp | 1 + src/grab.cpp | 1 + src/handle_action.cpp | 1 + src/handle_liquid.cpp | 1 + src/iexamine.cpp | 1 + src/inventory.cpp | 1 + src/inventory_ui.cpp | 1 + src/item.cpp | 1 + src/item_location.cpp | 1 + src/iuse.cpp | 1 + src/iuse_actor.cpp | 1 + src/lightmap.cpp | 1 + src/magic_spell_effect.cpp | 1 + src/map.cpp | 1 + src/map_extras.cpp | 1 + src/map_field.cpp | 1 + src/mapgen.cpp | 1 + src/mattack_actors.cpp | 1 + src/melee.cpp | 1 + src/monmove.cpp | 1 + src/npc.cpp | 1 + src/npcmove.cpp | 1 + src/npctalk.cpp | 1 + src/overmap_ui.cpp | 1 + src/overmapbuffer.cpp | 1 + src/panels.cpp | 1 + src/pathfinding.cpp | 1 + src/pickup.cpp | 1 + src/pixel_minimap.cpp | 1 + src/player.cpp | 1 + src/ranged.cpp | 1 + src/ranged_aoe.cpp | 1 + src/rot.cpp | 1 + src/savegame_json.cpp | 1 + src/sdltiles.cpp | 1 + src/sounds.cpp | 1 + src/submap.cpp | 1 + src/turret.cpp | 3 +- src/veh_interact.cpp | 1 + src/veh_type.cpp | 1 + src/veh_utils.cpp | 1 + src/vehicle.cpp | 3 +- src/vehicle.h | 297 +--------------------------- src/vehicle_autodrive.cpp | 3 +- src/vehicle_display.cpp | 3 +- src/vehicle_export.cpp | 1 + src/vehicle_group.cpp | 1 + src/vehicle_move.cpp | 3 +- src/vehicle_part.cpp | 3 +- src/vehicle_part.h | 312 ++++++++++++++++++++++++++++++ src/vehicle_use.cpp | 3 +- src/visitable.cpp | 1 + tests/electric_grid_test.cpp | 1 + tests/explosion_balance_test.cpp | 1 + tests/find_auto_consume_test.cpp | 1 + tests/npc_test.cpp | 1 + tests/ranged_aiming_test.cpp | 1 + tests/reading_test.cpp | 1 + tests/reload_on_location_test.cpp | 1 + tests/vehicle_drag_test.cpp | 1 + tests/vehicle_efficiency_test.cpp | 1 + tests/vehicle_interact_test.cpp | 1 + tests/vehicle_power_test.cpp | 1 + tests/vehicle_rails_test.cpp | 1 + tests/vehicle_ramp_test.cpp | 1 + tests/vehicle_split_test.cpp | 1 + tests/vehicle_test.cpp | 1 + tests/vehicle_turrets_test.cpp | 1 + tests/vision_test.cpp | 1 + tests/visitable_remove_test.cpp | 1 + 99 files changed, 418 insertions(+), 302 deletions(-) create mode 100644 src/vehicle_part.h diff --git a/src/action.cpp b/src/action.cpp index b23d194315de..be4be14c7ae2 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -37,6 +37,7 @@ #include "ui.h" #include "ui_manager.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const quality_id qual_BUTCHER( "BUTCHER" ); diff --git a/src/active_tile_data.cpp b/src/active_tile_data.cpp index d61c8208e633..a44a3acd34e2 100644 --- a/src/active_tile_data.cpp +++ b/src/active_tile_data.cpp @@ -11,6 +11,7 @@ #include "mapbuffer.h" #include "rng.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_range.h" #include "weather.h" diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index d69da962c440..f42ec0ede9ca 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -48,6 +48,7 @@ #include "uistate.h" #include "units.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const itype_id itype_bone_human( "bone_human" ); diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index b44978b21e92..27d46c9e6c8d 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -103,6 +103,7 @@ #include "value_ptr.h" #include "veh_interact.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const activity_id ACT_ADV_INVENTORY( "ACT_ADV_INVENTORY" ); diff --git a/src/activity_item_handling.cpp b/src/activity_item_handling.cpp index 54bda0fcebcc..d4b04d33d70b 100644 --- a/src/activity_item_handling.cpp +++ b/src/activity_item_handling.cpp @@ -70,6 +70,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "vpart_position.h" #include "weather.h" diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index 4faf33b99ff5..a2120e996a0f 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -55,6 +55,7 @@ #include "units.h" #include "units_utility.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #if defined(__ANDROID__) diff --git a/src/advanced_inv_area.cpp b/src/advanced_inv_area.cpp index e02e96e0adeb..f847f27215bc 100644 --- a/src/advanced_inv_area.cpp +++ b/src/advanced_inv_area.cpp @@ -29,6 +29,7 @@ #include "uistate.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" int advanced_inv_area::get_item_count() const diff --git a/src/advanced_inv_pane.cpp b/src/advanced_inv_pane.cpp index 997751deed47..f172d230ca74 100644 --- a/src/advanced_inv_pane.cpp +++ b/src/advanced_inv_pane.cpp @@ -18,6 +18,7 @@ #include "uistate.h" #include "units.h" #include "vehicle.h" +#include "vehicle_part.h" #if defined(__ANDROID__) # include diff --git a/src/avatar.cpp b/src/avatar.cpp index d8c18ac98453..03c7b49f1ab2 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -74,6 +74,7 @@ #include "ui.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const activity_id ACT_READ( "ACT_READ" ); diff --git a/src/avatar_action.cpp b/src/avatar_action.cpp index 685056c3b5d8..cc59497834ce 100644 --- a/src/avatar_action.cpp +++ b/src/avatar_action.cpp @@ -59,6 +59,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" class player; diff --git a/src/avatar_functions.cpp b/src/avatar_functions.cpp index a35d7e92d930..c9beefd03c2d 100644 --- a/src/avatar_functions.cpp +++ b/src/avatar_functions.cpp @@ -20,6 +20,7 @@ #include "trap.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const trait_id trait_CHLOROMORPH( "CHLOROMORPH" ); diff --git a/src/bionics.cpp b/src/bionics.cpp index adfaac64894e..78827e780d78 100644 --- a/src/bionics.cpp +++ b/src/bionics.cpp @@ -80,6 +80,7 @@ #include "units_utility.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather.h" #include "weather_gen.h" diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index f85cf21ef390..3e98a9421b2e 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -74,6 +74,7 @@ #include "type_id.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather.h" #include "weighted_list.h" diff --git a/src/character.cpp b/src/character.cpp index cb2dec4555c6..6cb104617917 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -98,6 +98,7 @@ #include "veh_interact.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "vitamin.h" #include "vpart_position.h" diff --git a/src/character_effects.cpp b/src/character_effects.cpp index af61be4bdb2d..91eb9fe2d661 100644 --- a/src/character_effects.cpp +++ b/src/character_effects.cpp @@ -16,6 +16,7 @@ #include "trap.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather_gen.h" #include "weather.h" diff --git a/src/character_functions.cpp b/src/character_functions.cpp index 68c9821cb638..08629cb2ffb1 100644 --- a/src/character_functions.cpp +++ b/src/character_functions.cpp @@ -24,6 +24,7 @@ #include "uistate.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "vpart_position.h" #include "weather_gen.h" diff --git a/src/character_turn.cpp b/src/character_turn.cpp index 829fb2ce7099..028e74020a35 100644 --- a/src/character_turn.cpp +++ b/src/character_turn.cpp @@ -23,6 +23,7 @@ #include "trap.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather_gen.h" #include "weather.h" diff --git a/src/clzones.cpp b/src/clzones.cpp index aabab668283a..0b815885896c 100644 --- a/src/clzones.cpp +++ b/src/clzones.cpp @@ -36,6 +36,7 @@ #include "ui.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const std::string flag_FIREWOOD( "FIREWOOD" ); diff --git a/src/condition.cpp b/src/condition.cpp index 5fe862e12e4c..acac62bf6005 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -39,6 +39,7 @@ #include "string_id.h" #include "type_id.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" class basecamp; diff --git a/src/construction.cpp b/src/construction.cpp index 26b03c355ede..141b7d247578 100644 --- a/src/construction.cpp +++ b/src/construction.cpp @@ -62,6 +62,7 @@ #include "units_serde.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const activity_id ACT_BUILD( "ACT_BUILD" ); diff --git a/src/crafting.cpp b/src/crafting.cpp index 1717f19d805c..a4addfc4185c 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -74,6 +74,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "vpart_position.h" diff --git a/src/creature.cpp b/src/creature.cpp index e0fdede7ac7e..0d69db54329d 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -45,6 +45,7 @@ #include "translations.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const ammo_effect_str_id ammo_effect_APPLY_SAP( "APPLY_SAP" ); diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index c59b920f9b00..8a881155fa44 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -101,6 +101,7 @@ #include "units_utility.h" #include "url_utility.h" #include "vehicle.h" +#include "vehicle_part.h" #include "veh_type.h" #include "vitamin.h" #include "vpart_position.h" diff --git a/src/distribution_grid.cpp b/src/distribution_grid.cpp index ec101e270bc4..d04ce15484b7 100644 --- a/src/distribution_grid.cpp +++ b/src/distribution_grid.cpp @@ -68,6 +68,7 @@ void distribution_grid::update( time_point to ) // TODO: Shouldn't be here #include "vehicle.h" +#include "vehicle_part.h" static itype_id itype_battery( "battery" ); int distribution_grid::mod_resource( int amt, bool recurse ) { diff --git a/src/dump.cpp b/src/dump.cpp index 52f2a0ae4df1..b6889a334766 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -32,6 +32,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vitamin.h" static const std::string flag_VARSIZE( "VARSIZE" ); diff --git a/src/editmap.cpp b/src/editmap.cpp index a05868ee44ab..d28aa7fd3259 100644 --- a/src/editmap.cpp +++ b/src/editmap.cpp @@ -54,6 +54,7 @@ #include "ui_manager.h" #include "uistate.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static constexpr tripoint editmap_boundary_min( 0, 0, -OVERMAP_DEPTH ); diff --git a/src/explosion.cpp b/src/explosion.cpp index 52829ca77032..e41adc2293b1 100644 --- a/src/explosion.cpp +++ b/src/explosion.cpp @@ -64,6 +64,7 @@ #include "units.h" #include "ui_manager.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const ammo_effect_str_id ammo_effect_NULL_SOURCE( "NULL_SOURCE" ); diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index f494d1adbb21..a03e859ca58f 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -73,6 +73,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" #include "weather.h" diff --git a/src/game.cpp b/src/game.cpp index e271bfb5e5aa..9a95a53d9f0b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -172,6 +172,7 @@ #include "veh_interact.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" #include "wcwidth.h" diff --git a/src/gates.cpp b/src/gates.cpp index 3115295b016e..e387c7ba9ac1 100644 --- a/src/gates.cpp +++ b/src/gates.cpp @@ -33,6 +33,7 @@ #include "type_id.h" #include "units.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" // Gates namespace diff --git a/src/grab.cpp b/src/grab.cpp index 7c377bd1114a..bd7738475025 100644 --- a/src/grab.cpp +++ b/src/grab.cpp @@ -14,6 +14,7 @@ #include "point.h" #include "sounds.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "debug.h" #include "rng.h" diff --git a/src/handle_action.cpp b/src/handle_action.cpp index ad4c45d37d6d..443a8b838297 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -86,6 +86,7 @@ #include "units.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" #include "weather.h" diff --git a/src/handle_liquid.cpp b/src/handle_liquid.cpp index 36ccbe8f597c..e6a2e5f6bbe0 100644 --- a/src/handle_liquid.cpp +++ b/src/handle_liquid.cpp @@ -36,6 +36,7 @@ #include "type_id.h" #include "ui.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/iexamine.cpp b/src/iexamine.cpp index ae0fd466304c..bda915798869 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -106,6 +106,7 @@ #include "units_utility.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather.h" diff --git a/src/inventory.cpp b/src/inventory.cpp index 201a100320be..41430975a740 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -24,6 +24,7 @@ #include "options.h" #include "translations.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "calendar.h" #include "character.h" diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index 8580836193c3..91c660bb0987 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -28,6 +28,7 @@ #include "ui_manager.h" #include "units_utility.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "visitable.h" #include "vpart_position.h" diff --git a/src/item.cpp b/src/item.cpp index 10f9c46324d1..a1cb81ab4478 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -98,6 +98,7 @@ #include "units_utility.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vitamin.h" #include "vpart_position.h" #include "weather.h" diff --git a/src/item_location.cpp b/src/item_location.cpp index 6d2112188a9d..c05857bb9f9b 100644 --- a/src/item_location.cpp +++ b/src/item_location.cpp @@ -29,6 +29,7 @@ #include "string_formatter.h" #include "translations.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "visitable.h" #include "vpart_position.h" diff --git a/src/iuse.cpp b/src/iuse.cpp index b5888d3586ba..2179db03ea63 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -114,6 +114,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "visitable.h" #include "vpart_position.h" diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index feba98829f30..a0d6e66b7dc0 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -80,6 +80,7 @@ #include "units_utility.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "visitable.h" #include "vitamin.h" diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 86f69aa12863..02d64076ac8a 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -38,6 +38,7 @@ #include "type_id.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" #include "weather.h" diff --git a/src/magic_spell_effect.cpp b/src/magic_spell_effect.cpp index 1f6d1421962c..b02f71769beb 100644 --- a/src/magic_spell_effect.cpp +++ b/src/magic_spell_effect.cpp @@ -51,6 +51,7 @@ #include "type_id.h" #include "units.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const ammo_effect_str_id ammo_effect_magic( "magic" ); diff --git a/src/map.cpp b/src/map.cpp index e5b71d5436eb..71af8ae026fe 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -94,6 +94,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "visitable.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/map_extras.cpp b/src/map_extras.cpp index 4c5f383e6c43..1f3f70f10cf8 100644 --- a/src/map_extras.cpp +++ b/src/map_extras.cpp @@ -55,6 +55,7 @@ #include "units.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_group.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/map_field.cpp b/src/map_field.cpp index 904657a51671..2d2ec68954bf 100644 --- a/src/map_field.cpp +++ b/src/map_field.cpp @@ -58,6 +58,7 @@ #include "type_id.h" #include "units.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather.h" diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 0d94b2d47fd8..7ed1b5b98df1 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -70,6 +70,7 @@ #include "trap.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_group.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/mattack_actors.cpp b/src/mattack_actors.cpp index 2bf7cccf00e0..2fd194a790ae 100644 --- a/src/mattack_actors.cpp +++ b/src/mattack_actors.cpp @@ -30,6 +30,7 @@ #include "sounds.h" #include "translations.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_range.h" static const efftype_id effect_badpoison( "badpoison" ); diff --git a/src/melee.cpp b/src/melee.cpp index 1ea17223dacd..ee35f40e8acc 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -61,6 +61,7 @@ #include "type_id.h" #include "units.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weighted_list.h" diff --git a/src/monmove.cpp b/src/monmove.cpp index 29a53f4c843b..f2e96201be3f 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -46,6 +46,7 @@ #include "translations.h" #include "trap.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" static const efftype_id effect_ai_waiting( "ai_waiting" ); diff --git a/src/npc.cpp b/src/npc.cpp index 740da685c53f..36b63dd2bb46 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -71,6 +71,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "visitable.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/npcmove.cpp b/src/npcmove.cpp index b3047cfb0caa..41a674f91456 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -67,6 +67,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "visitable.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/npctalk.cpp b/src/npctalk.cpp index 3dc1c1890ca3..47f3424c046a 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -79,6 +79,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 704ee9976f9c..c8c9b4306afd 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -71,6 +71,7 @@ #include "uistate.h" #include "units.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather.h" #include "weather_gen.h" diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index 550f5575a943..a7f4d3d3e741 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -42,6 +42,7 @@ #include "string_utils.h" #include "translations.h" #include "vehicle.h" +#include "vehicle_part.h" class map_extra; diff --git a/src/panels.cpp b/src/panels.cpp index 2e6f87b09974..41983b82ae58 100644 --- a/src/panels.cpp +++ b/src/panels.cpp @@ -57,6 +57,7 @@ #include "units.h" #include "units_utility.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather.h" diff --git a/src/pathfinding.cpp b/src/pathfinding.cpp index 515f0327fe11..d9a7941459d2 100644 --- a/src/pathfinding.cpp +++ b/src/pathfinding.cpp @@ -19,6 +19,7 @@ #include "trap.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "line.h" #include "type_id.h" diff --git a/src/pickup.cpp b/src/pickup.cpp index b1f589513650..53836922f173 100644 --- a/src/pickup.cpp +++ b/src/pickup.cpp @@ -58,6 +58,7 @@ #include "units.h" #include "units_utility.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "vpart_position.h" diff --git a/src/pixel_minimap.cpp b/src/pixel_minimap.cpp index 810ff48e1fea..6f8bb554c02f 100644 --- a/src/pixel_minimap.cpp +++ b/src/pixel_minimap.cpp @@ -33,6 +33,7 @@ #include "pixel_minimap_projectors.h" #include "sdl_utils.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" extern void set_displaybuffer_rendertarget(); diff --git a/src/player.cpp b/src/player.cpp index 794cf58c6fd7..7a8f6ed12ed1 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -81,6 +81,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "visitable.h" #include "vitamin.h" #include "vpart_position.h" diff --git a/src/ranged.cpp b/src/ranged.cpp index 93e9f2e10be3..fd4d2c7b8ff4 100644 --- a/src/ranged.cpp +++ b/src/ranged.cpp @@ -70,6 +70,7 @@ #include "units_utility.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" struct ammo_effect; diff --git a/src/ranged_aoe.cpp b/src/ranged_aoe.cpp index d827124fcfab..30ad0651aa66 100644 --- a/src/ranged_aoe.cpp +++ b/src/ranged_aoe.cpp @@ -7,6 +7,7 @@ #include "ranged.h" #include "shape.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "explosion.h" diff --git a/src/rot.cpp b/src/rot.cpp index 43a40ae1296f..f6cd25157aae 100644 --- a/src/rot.cpp +++ b/src/rot.cpp @@ -3,6 +3,7 @@ #include "item_location.h" #include "map.h" #include "vehicle.h" +#include "vehicle_part.h" #include "units.h" #include "veh_type.h" #include "vpart_position.h" diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index c9f4bb3f1734..e5fba4bfba3e 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -110,6 +110,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vitamin.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 0079f1f318ce..53a2d83f0ed1 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -91,6 +91,7 @@ #include "inventory.h" #include "map.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "worldfactory.h" #endif diff --git a/src/sounds.cpp b/src/sounds.cpp index 5c5b75ab9960..bf5b8486c97f 100644 --- a/src/sounds.cpp +++ b/src/sounds.cpp @@ -46,6 +46,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "weather.h" diff --git a/src/submap.cpp b/src/submap.cpp index dc78ba493b54..f3a6d87eee18 100644 --- a/src/submap.cpp +++ b/src/submap.cpp @@ -12,6 +12,7 @@ #include "tileray.h" #include "trap.h" #include "vehicle.h" +#include "vehicle_part.h" template void maptile_soa::swap_soa_tile( point p1, point p2 ) diff --git a/src/turret.cpp b/src/turret.cpp index b37158e235a4..5498c045b7cb 100644 --- a/src/turret.cpp +++ b/src/turret.cpp @@ -1,4 +1,5 @@ -#include "vehicle.h" // IWYU pragma: associated +#include "vehicle.h" +#include "vehicle_part.h" // IWYU pragma: associated #include #include diff --git a/src/veh_interact.cpp b/src/veh_interact.cpp index 57a8a1ebe3b8..8fcb57ee047e 100644 --- a/src/veh_interact.cpp +++ b/src/veh_interact.cpp @@ -66,6 +66,7 @@ #include "veh_type.h" #include "veh_utils.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/veh_type.cpp b/src/veh_type.cpp index 7775885c1961..a4f8010cd46a 100644 --- a/src/veh_type.cpp +++ b/src/veh_type.cpp @@ -32,6 +32,7 @@ #include "units_utility.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_group.h" class npc; diff --git a/src/veh_utils.cpp b/src/veh_utils.cpp index ece9e5e2b30a..20480ec9afd0 100644 --- a/src/veh_utils.cpp +++ b/src/veh_utils.cpp @@ -16,6 +16,7 @@ #include "player.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_range.h" #include "character.h" #include "enums.h" diff --git a/src/vehicle.cpp b/src/vehicle.cpp index b67bc5701947..4d5f2170687b 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1,4 +1,5 @@ -#include "vehicle.h" // IWYU pragma: associated +#include "vehicle.h" +#include "vehicle_part.h" // IWYU pragma: associated #include "vpart_position.h" // IWYU pragma: associated #include "vpart_range.h" // IWYU pragma: associated diff --git a/src/vehicle.h b/src/vehicle.h index 71461c7fce7c..82f054f485bb 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -17,20 +17,17 @@ #include "active_item_cache.h" #include "calendar.h" -#include "character_id.h" #include "clzones.h" #include "colony.h" #include "coordinates.h" #include "damage.h" #include "game_constants.h" #include "item.h" -#include "item_group.h" #include "item_location.h" #include "item_stack.h" #include "point.h" #include "tileray.h" #include "type_id.h" -#include "units.h" class avatar; class Character; @@ -43,6 +40,7 @@ class nc_color; class npc; class player; class vehicle; +struct vehicle_part; class vehicle_cursor; class vehicle_part_range; class vpart_info; @@ -180,297 +178,6 @@ double vmiph_to_mps( int vmiph ); int cmps_to_vmiph( int cmps ); int vmiph_to_cmps( int vmiph ); -/** - * Structure, describing vehicle part (i.e., wheel, seat) - */ -struct vehicle_part { - friend vehicle; - friend class veh_interact; - friend visitable; - friend item_location; - friend class turret_data; - - enum : int { passenger_flag = 1, - animal_flag = 2, - carried_flag = 4, - carrying_flag = 8, - tracked_flag = 16, //carried vehicle part with tracking enabled - targets_grid = 32, // Jumper cable is to grid, not vehicle - }; - - vehicle_part(); /** DefaultConstructible */ - - vehicle_part( const vpart_id &vp, point dp, item &&obj ); - - /** Check this instance is non-null (not default constructed) */ - explicit operator bool() const; - - // TODO: Make all of those use the above enum - bool has_flag( const int flag ) const noexcept { - return flag & flags; - } - int set_flag( const int flag ) noexcept { - return flags |= flag; - } - int remove_flag( const int flag ) noexcept { - return flags &= ~flag; - } - - /** - * Translated name of a part inclusive of any current status effects - * with_prefix as true indicates the durability symbol should be prepended - */ - std::string name( bool with_prefix = true ) const; - - static constexpr int name_offset = 7; - /** Stack of the containing vehicle's name, when it it stored as part of another vehicle */ - std::stack > carry_names; - - /** Specific type of fuel, charges or ammunition currently contained by a part */ - itype_id ammo_current() const; - - /** Maximum amount of fuel, charges or ammunition that can be contained by a part */ - int ammo_capacity() const; - - /** Amount of fuel, charges or ammunition currently contained by a part */ - int ammo_remaining() const; - - /** Type of fuel used by an engine */ - itype_id fuel_current() const; - /** Set an engine to use a different type of fuel */ - bool fuel_set( const itype_id &fuel ); - /** - * Set fuel, charges or ammunition for this part removing any existing ammo - * @param ammo specific type of ammo (must be compatible with vehicle part) - * @param qty maximum ammo (capped by part capacity) or negative to fill to capacity - * @return amount of ammo actually set or negative on failure - */ - int ammo_set( const itype_id &ammo, int qty = -1 ); - - /** Remove all fuel, charges or ammunition (if any) from this part */ - void ammo_unset(); - - /** - * Consume fuel, charges or ammunition (if available) - * @param qty maximum amount of ammo that should be consumed - * @param pos current global location of part from which ammo is being consumed - * @return amount consumed which will be between 0 and specified qty - */ - int ammo_consume( int qty, const tripoint &pos ); - - /** - * Consume fuel by energy content. - * @param ftype Type of fuel to consume - * @param energy_j Energy to consume, in J - * @return Energy actually consumed, in J - */ - double consume_energy( const itype_id &ftype, double energy_j ); - - /* @retun true if part in current state be reloaded optionally with specific itype_id */ - bool can_reload( const item &obj = item() ) const; - - /** - * If this part is capable of wholly containing something, process the - * items in there. - * @param pos Position of this part for item::process - * @param e_heater Engine has a heater and is on - */ - void process_contents( const tripoint &pos, bool e_heater ); - - /** - * Try adding @param liquid to tank optionally limited by @param qty - * @return whether any of the liquid was consumed (which may be less than qty) - */ - bool fill_with( item &liquid, int qty = INT_MAX ); - - /** Current faults affecting this part (if any) */ - const std::set &faults() const; - - /** Faults which could potentially occur with this part (if any) */ - std::set faults_potential() const; - - /** Try to set fault returning false if specified fault cannot occur with this item */ - bool fault_set( const fault_id &f ); - - /** Get wheel diameter times wheel width (inches^2) or return 0 if part is not wheel */ - int wheel_area() const; - - /** Get wheel diameter (inches) or return 0 if part is not wheel */ - int wheel_diameter() const; - - /** Get wheel width (inches) or return 0 if part is not wheel */ - int wheel_width() const; - - /** - * Get NPC currently assigned to this part (seat, turret etc)? - * @note checks crew member is alive and currently allied to the player - * @return nullptr if no valid crew member is currently assigned - */ - npc *crew() const; - - /** Set crew member for this part (seat, turret etc) who must be a player ally) - * @return true if part can have crew members and passed npc was suitable - */ - bool set_crew( const npc &who ); - - /** Remove any currently assigned crew member for this part */ - void unset_crew(); - - /** Reset the target for this part. */ - void reset_target( const tripoint &pos ); - - /** - * @name Part capabilities - * - * A part can provide zero or more capabilities. Some capabilities are mutually - * exclusive, for example a part cannot be both a fuel tank and battery - */ - /*@{*/ - - /** Can this part provide power or propulsion? */ - bool is_engine() const; - - /** Is this any type of vehicle light? */ - bool is_light() const; - - /** Can this part store fuel of any type - * @skip_broke exclude broken parts - */ - bool is_fuel_store( bool skip_broke = true ) const; - - /** Can this part contain liquid fuels? */ - bool is_tank() const; - - /** Can this part store electrical charge? */ - bool is_battery() const; - - /** Is this part a reactor? */ - bool is_reactor() const; - - /** is this part currently unable to retain to fluid/charge? - * this doesn't take into account whether or not the part has any contents - * remaining to leak - */ - bool is_leaking() const; - - /** Can this part function as a turret? */ - bool is_turret() const; - - /** Can a player or NPC use this part as a seat? */ - bool is_seat() const; - - /* if this is a carried part, what is the name of the carried vehicle */ - std::string carried_name() const; - /*@}*/ - - public: - /** mount point: x is on the forward/backward axis, y is on the left/right axis */ - point mount; - - /** mount translated to face.dir [0] and turn_dir [1] */ - // NOLINTNEXTLINE(cata-use-named-point-constants) - std::array precalc = { { tripoint( -1, -1, 0 ), tripoint( -1, -1, 0 ) } }; - - /** current part health with range [0,durability] */ - int hp() const; - - /** Current part damage in same units as item::damage. */ - int damage() const; - /** max damage of part base */ - int max_damage() const; - - /** Current part damage level in same units as item::damage_level */ - int damage_level( int max ) const; - - /** Current part damage as a percentage of maximum, with 0.0 being perfect condition */ - double damage_percent() const; - /** Current part health as a percentage of maximum, with 1.0 being perfect condition */ - double health_percent() const; - - /** parts are considered broken at zero health */ - bool is_broken() const; - - /** parts are unavailable if broken or if carried is true, if they have the CARRIED flag */ - bool is_unavailable( bool carried = true ) const; - /** parts are available if they aren't unavailable */ - bool is_available( bool carried = true ) const; - - /** how much blood covers part (in turns). */ - int blood = 0; - - /** - * if tile provides cover. - * WARNING: do not read it directly, use vpart_position::is_inside() instead - */ - bool inside = false; - - /** - * true if this part is removed. The part won't disappear until the end of the turn - * so our indices can remain consistent. - */ - bool removed = false; - bool enabled = true; - int flags = 0; - - /** ID of player passenger */ - character_id passenger_id; - - /** door is open */ - bool open = false; - - /** direction the part is facing */ - units::angle direction = 0_degrees; - - - vpart_id proxy_part_id = vpart_id::NULL_ID(); - char proxy_sym = '\0'; - /** - * Coordinates for some kind of target; jumper cables and turrets use this - * Two coordinate pairs are stored: actual target point, and target vehicle center. - * Both cases use absolute coordinates (relative to world origin) - */ - std::pair target = { tripoint_min, tripoint_min }; - - private: - /** What type of part is this? */ - vpart_id id; - - /** As a performance optimization we cache the part information here on first lookup */ - mutable const vpart_info *info_cache = nullptr; - - item base; - cata::colony items; // inventory - - /** Preferred ammo type when multiple are available */ - itype_id ammo_pref = itype_id::NULL_ID(); - - /** - * What NPC (if any) is assigned to this part (seat, turret etc)? - * @see vehicle_part::crew() accessor which excludes dead and non-allied NPC's - */ - character_id crew_id; - - public: - /** Get part definition common to all parts of this type */ - const vpart_info &info() const; - - void serialize( JsonOut &json ) const; - void deserialize( JsonIn &jsin ); - - const item &get_base() const; - void set_base( const item &new_base ); - /** - * Generate the corresponding item from this vehicle part. It includes - * the hp (item damage), fuel charges (battery or liquids), aspect, ... - */ - item properties_to_item() const; - /** - * Returns an ItemList of the pieces that should arise from breaking - * this part. - */ - item_group::ItemList pieces_for_broken_part() const; -}; - class turret_data { friend vehicle; @@ -2042,6 +1749,6 @@ class vehicle namespace rot { temperature_flag temperature_flag_for_part( const vehicle &veh, size_t part ); -} +} // namespace rot #endif // CATA_SRC_VEHICLE_H diff --git a/src/vehicle_autodrive.cpp b/src/vehicle_autodrive.cpp index 6c29ca66feed..2cdee6941869 100644 --- a/src/vehicle_autodrive.cpp +++ b/src/vehicle_autodrive.cpp @@ -1,4 +1,5 @@ -#include "vehicle.h" // IWYU pragma: associated +#include "vehicle.h" +#include "vehicle_part.h" // IWYU pragma: associated #include #include diff --git a/src/vehicle_display.cpp b/src/vehicle_display.cpp index 4f206c4fcd61..3b391e3af896 100644 --- a/src/vehicle_display.cpp +++ b/src/vehicle_display.cpp @@ -1,4 +1,5 @@ -#include "vehicle.h" // IWYU pragma: associated +#include "vehicle.h" +#include "vehicle_part.h" // IWYU pragma: associated #include #include diff --git a/src/vehicle_export.cpp b/src/vehicle_export.cpp index 497e06734ae5..72155b2ef0cc 100644 --- a/src/vehicle_export.cpp +++ b/src/vehicle_export.cpp @@ -4,6 +4,7 @@ #include "type_id.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "json_export.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/src/vehicle_group.cpp b/src/vehicle_group.cpp index 4420bd8f02a4..ccb1f4d43ff5 100644 --- a/src/vehicle_group.cpp +++ b/src/vehicle_group.cpp @@ -14,6 +14,7 @@ #include "translations.h" #include "units_angle.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" using vplacement_id = string_id; diff --git a/src/vehicle_move.cpp b/src/vehicle_move.cpp index 14cdda9e932e..3e9b1baacbd1 100644 --- a/src/vehicle_move.cpp +++ b/src/vehicle_move.cpp @@ -1,4 +1,5 @@ -#include "vehicle.h" // IWYU pragma: associated +#include "vehicle.h" +#include "vehicle_part.h" // IWYU pragma: associated #include "vehicle_move.h" // IWYU pragma: associated #include diff --git a/src/vehicle_part.cpp b/src/vehicle_part.cpp index 42df6ec12270..7a2985411bc1 100644 --- a/src/vehicle_part.cpp +++ b/src/vehicle_part.cpp @@ -1,4 +1,5 @@ -#include "vehicle.h" // IWYU pragma: associated +#include "vehicle.h" +#include "vehicle_part.h" // IWYU pragma: associated #include #include diff --git a/src/vehicle_part.h b/src/vehicle_part.h new file mode 100644 index 000000000000..9eb5eb075489 --- /dev/null +++ b/src/vehicle_part.h @@ -0,0 +1,312 @@ +#pragma once + +#ifndef CATA_SRC_VEHICLE_PART_H +#define CATA_SRC_VEHICLE_PART_H + +#include +#include + +#include "character_id.h" +#include "colony.h" +#include "item.h" +#include "item_group.h" +#include "point.h" +#include "visitable.h" + +class vehicle; +class item_location; +class vehicle_cursor; +class npc; + +/** + * Structure, describing vehicle part (i.e., wheel, seat) + */ +struct vehicle_part { + friend vehicle; + friend class veh_interact; + friend visitable; + friend item_location; + friend class turret_data; + + enum : int { passenger_flag = 1, + animal_flag = 2, + carried_flag = 4, + carrying_flag = 8, + tracked_flag = 16, //carried vehicle part with tracking enabled + targets_grid = 32, // Jumper cable is to grid, not vehicle + }; + + vehicle_part(); /** DefaultConstructible */ + + vehicle_part( const vpart_id &vp, point dp, item &&obj ); + + /** Check this instance is non-null (not default constructed) */ + explicit operator bool() const; + + // TODO: Make all of those use the above enum + bool has_flag( const int flag ) const noexcept { + return flag & flags; + } + int set_flag( const int flag ) noexcept { + return flags |= flag; + } + int remove_flag( const int flag ) noexcept { + return flags &= ~flag; + } + + /** + * Translated name of a part inclusive of any current status effects + * with_prefix as true indicates the durability symbol should be prepended + */ + std::string name( bool with_prefix = true ) const; + + static constexpr int name_offset = 7; + /** Stack of the containing vehicle's name, when it it stored as part of another vehicle */ + std::stack > carry_names; + + /** Specific type of fuel, charges or ammunition currently contained by a part */ + itype_id ammo_current() const; + + /** Maximum amount of fuel, charges or ammunition that can be contained by a part */ + int ammo_capacity() const; + + /** Amount of fuel, charges or ammunition currently contained by a part */ + int ammo_remaining() const; + + /** Type of fuel used by an engine */ + itype_id fuel_current() const; + /** Set an engine to use a different type of fuel */ + bool fuel_set( const itype_id &fuel ); + /** + * Set fuel, charges or ammunition for this part removing any existing ammo + * @param ammo specific type of ammo (must be compatible with vehicle part) + * @param qty maximum ammo (capped by part capacity) or negative to fill to capacity + * @return amount of ammo actually set or negative on failure + */ + int ammo_set( const itype_id &ammo, int qty = -1 ); + + /** Remove all fuel, charges or ammunition (if any) from this part */ + void ammo_unset(); + + /** + * Consume fuel, charges or ammunition (if available) + * @param qty maximum amount of ammo that should be consumed + * @param pos current global location of part from which ammo is being consumed + * @return amount consumed which will be between 0 and specified qty + */ + int ammo_consume( int qty, const tripoint &pos ); + + /** + * Consume fuel by energy content. + * @param ftype Type of fuel to consume + * @param energy_j Energy to consume, in J + * @return Energy actually consumed, in J + */ + double consume_energy( const itype_id &ftype, double energy_j ); + + /* @retun true if part in current state be reloaded optionally with specific itype_id */ + bool can_reload( const item &obj = item() ) const; + + /** + * If this part is capable of wholly containing something, process the + * items in there. + * @param pos Position of this part for item::process + * @param e_heater Engine has a heater and is on + */ + void process_contents( const tripoint &pos, bool e_heater ); + + /** + * Try adding @param liquid to tank optionally limited by @param qty + * @return whether any of the liquid was consumed (which may be less than qty) + */ + bool fill_with( item &liquid, int qty = INT_MAX ); + + /** Current faults affecting this part (if any) */ + const std::set &faults() const; + + /** Faults which could potentially occur with this part (if any) */ + std::set faults_potential() const; + + /** Try to set fault returning false if specified fault cannot occur with this item */ + bool fault_set( const fault_id &f ); + + /** Get wheel diameter times wheel width (inches^2) or return 0 if part is not wheel */ + int wheel_area() const; + + /** Get wheel diameter (inches) or return 0 if part is not wheel */ + int wheel_diameter() const; + + /** Get wheel width (inches) or return 0 if part is not wheel */ + int wheel_width() const; + + /** + * Get NPC currently assigned to this part (seat, turret etc)? + * @note checks crew member is alive and currently allied to the player + * @return nullptr if no valid crew member is currently assigned + */ + npc *crew() const; + + /** Set crew member for this part (seat, turret etc) who must be a player ally) + * @return true if part can have crew members and passed npc was suitable + */ + bool set_crew( const npc &who ); + + /** Remove any currently assigned crew member for this part */ + void unset_crew(); + + /** Reset the target for this part. */ + void reset_target( const tripoint &pos ); + + /** + * @name Part capabilities + * + * A part can provide zero or more capabilities. Some capabilities are mutually + * exclusive, for example a part cannot be both a fuel tank and battery + */ + /*@{*/ + + /** Can this part provide power or propulsion? */ + bool is_engine() const; + + /** Is this any type of vehicle light? */ + bool is_light() const; + + /** Can this part store fuel of any type + * @skip_broke exclude broken parts + */ + bool is_fuel_store( bool skip_broke = true ) const; + + /** Can this part contain liquid fuels? */ + bool is_tank() const; + + /** Can this part store electrical charge? */ + bool is_battery() const; + + /** Is this part a reactor? */ + bool is_reactor() const; + + /** is this part currently unable to retain to fluid/charge? + * this doesn't take into account whether or not the part has any contents + * remaining to leak + */ + bool is_leaking() const; + + /** Can this part function as a turret? */ + bool is_turret() const; + + /** Can a player or NPC use this part as a seat? */ + bool is_seat() const; + + /* if this is a carried part, what is the name of the carried vehicle */ + std::string carried_name() const; + /*@}*/ + + public: + /** mount point: x is on the forward/backward axis, y is on the left/right axis */ + point mount; + + /** mount translated to face.dir [0] and turn_dir [1] */ + // NOLINTNEXTLINE(cata-use-named-point-constants) + std::array precalc = { { tripoint( -1, -1, 0 ), tripoint( -1, -1, 0 ) } }; + + /** current part health with range [0,durability] */ + int hp() const; + + /** Current part damage in same units as item::damage. */ + int damage() const; + /** max damage of part base */ + int max_damage() const; + + /** Current part damage level in same units as item::damage_level */ + int damage_level( int max ) const; + + /** Current part damage as a percentage of maximum, with 0.0 being perfect condition */ + double damage_percent() const; + /** Current part health as a percentage of maximum, with 1.0 being perfect condition */ + double health_percent() const; + + /** parts are considered broken at zero health */ + bool is_broken() const; + + /** parts are unavailable if broken or if carried is true, if they have the CARRIED flag */ + bool is_unavailable( bool carried = true ) const; + /** parts are available if they aren't unavailable */ + bool is_available( bool carried = true ) const; + + /** how much blood covers part (in turns). */ + int blood = 0; + + /** + * if tile provides cover. + * WARNING: do not read it directly, use vpart_position::is_inside() instead + */ + bool inside = false; + + /** + * true if this part is removed. The part won't disappear until the end of the turn + * so our indices can remain consistent. + */ + bool removed = false; + bool enabled = true; + int flags = 0; + + /** ID of player passenger */ + character_id passenger_id; + + /** door is open */ + bool open = false; + + /** direction the part is facing */ + units::angle direction = 0_degrees; + + + vpart_id proxy_part_id = vpart_id::NULL_ID(); + char proxy_sym = '\0'; + /** + * Coordinates for some kind of target; jumper cables and turrets use this + * Two coordinate pairs are stored: actual target point, and target vehicle center. + * Both cases use absolute coordinates (relative to world origin) + */ + std::pair target = { tripoint_min, tripoint_min }; + + private: + /** What type of part is this? */ + vpart_id id; + + /** As a performance optimization we cache the part information here on first lookup */ + mutable const vpart_info *info_cache = nullptr; + + item base; + cata::colony items; // inventory + + /** Preferred ammo type when multiple are available */ + itype_id ammo_pref = itype_id::NULL_ID(); + + /** + * What NPC (if any) is assigned to this part (seat, turret etc)? + * @see vehicle_part::crew() accessor which excludes dead and non-allied NPC's + */ + character_id crew_id; + + public: + /** Get part definition common to all parts of this type */ + const vpart_info &info() const; + + void serialize( JsonOut &json ) const; + void deserialize( JsonIn &jsin ); + + const item &get_base() const; + void set_base( const item &new_base ); + /** + * Generate the corresponding item from this vehicle part. It includes + * the hp (item damage), fuel charges (battery or liquids), aspect, ... + */ + item properties_to_item() const; + /** + * Returns an ItemList of the pieces that should arise from breaking + * this part. + */ + item_group::ItemList pieces_for_broken_part() const; +}; + +#endif diff --git a/src/vehicle_use.cpp b/src/vehicle_use.cpp index 09ac7e1e74a0..2ac372dc89bd 100644 --- a/src/vehicle_use.cpp +++ b/src/vehicle_use.cpp @@ -1,5 +1,6 @@ #include "character.h" -#include "vehicle.h" // IWYU pragma: associated +#include "vehicle.h" +#include "vehicle_part.h" // IWYU pragma: associated #include #include diff --git a/src/visitable.cpp b/src/visitable.cpp index 73e569f78ab8..3cb37db1b591 100644 --- a/src/visitable.cpp +++ b/src/visitable.cpp @@ -29,6 +29,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" static const itype_id itype_apparatus( "apparatus" ); diff --git a/tests/electric_grid_test.cpp b/tests/electric_grid_test.cpp index ff5f2086634b..4ae7fc2368f3 100644 --- a/tests/electric_grid_test.cpp +++ b/tests/electric_grid_test.cpp @@ -16,6 +16,7 @@ #include "state_helpers.h" #include "stringmaker.h" #include "vehicle.h" +#include "vehicle_part.h" static furn_str_id f_battery( "f_battery" ); static furn_str_id f_cable_connector( "f_cable_connector" ); diff --git a/tests/explosion_balance_test.cpp b/tests/explosion_balance_test.cpp index 7a2b6d8980a5..9ce884872e96 100644 --- a/tests/explosion_balance_test.cpp +++ b/tests/explosion_balance_test.cpp @@ -25,6 +25,7 @@ #include "type_id.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/tests/find_auto_consume_test.cpp b/tests/find_auto_consume_test.cpp index 88f7ab864caf..c513dfc6d29c 100644 --- a/tests/find_auto_consume_test.cpp +++ b/tests/find_auto_consume_test.cpp @@ -13,6 +13,7 @@ #include "player_helpers.h" #include "state_helpers.h" #include "vehicle.h" +#include "vehicle_part.h" #include "type_id.h" #include "catch/catch.hpp" diff --git a/tests/npc_test.cpp b/tests/npc_test.cpp index edcac3f641f0..a3bff49bd8fa 100644 --- a/tests/npc_test.cpp +++ b/tests/npc_test.cpp @@ -30,6 +30,7 @@ #include "type_id.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" class Creature; diff --git a/tests/ranged_aiming_test.cpp b/tests/ranged_aiming_test.cpp index 72ed4d73e2e0..fa6717c10bec 100644 --- a/tests/ranged_aiming_test.cpp +++ b/tests/ranged_aiming_test.cpp @@ -23,6 +23,7 @@ #include "ranged.h" #include "state_helpers.h" #include "vehicle.h" +#include "vehicle_part.h" extern bool can_fire_turret( avatar &you, const map &m, const turret_data &turret ); diff --git a/tests/reading_test.cpp b/tests/reading_test.cpp index 06e516e82b48..63d51e20255e 100644 --- a/tests/reading_test.cpp +++ b/tests/reading_test.cpp @@ -26,6 +26,7 @@ #include "type_id.h" #include "value_ptr.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" class player; diff --git a/tests/reload_on_location_test.cpp b/tests/reload_on_location_test.cpp index b37b2d9131bd..e029c2b1baa3 100644 --- a/tests/reload_on_location_test.cpp +++ b/tests/reload_on_location_test.cpp @@ -16,6 +16,7 @@ #include "state_helpers.h" #include "type_id.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "veh_type.h" diff --git a/tests/vehicle_drag_test.cpp b/tests/vehicle_drag_test.cpp index fa9755720f64..4e92f988df81 100644 --- a/tests/vehicle_drag_test.cpp +++ b/tests/vehicle_drag_test.cpp @@ -18,6 +18,7 @@ #include "test_statistics.h" #include "type_id.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/tests/vehicle_efficiency_test.cpp b/tests/vehicle_efficiency_test.cpp index 685b30b9f4bb..61c95cab5098 100644 --- a/tests/vehicle_efficiency_test.cpp +++ b/tests/vehicle_efficiency_test.cpp @@ -30,6 +30,7 @@ #include "units.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/tests/vehicle_interact_test.cpp b/tests/vehicle_interact_test.cpp index 67c016c97668..1da88adc6c85 100644 --- a/tests/vehicle_interact_test.cpp +++ b/tests/vehicle_interact_test.cpp @@ -18,6 +18,7 @@ #include "type_id.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" static void test_repair( const std::vector &tools, bool expect_craftable ) { diff --git a/tests/vehicle_power_test.cpp b/tests/vehicle_power_test.cpp index 4f67026cbfe4..4498a8091344 100644 --- a/tests/vehicle_power_test.cpp +++ b/tests/vehicle_power_test.cpp @@ -18,6 +18,7 @@ #include "state_helpers.h" #include "type_id.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "weather.h" diff --git a/tests/vehicle_rails_test.cpp b/tests/vehicle_rails_test.cpp index 2667b34042d1..9e93c62c9b4d 100644 --- a/tests/vehicle_rails_test.cpp +++ b/tests/vehicle_rails_test.cpp @@ -16,6 +16,7 @@ #include "veh_type.h" #include "vehicle_move.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/tests/vehicle_ramp_test.cpp b/tests/vehicle_ramp_test.cpp index 96e5ccfe0926..075ec7ef1108 100644 --- a/tests/vehicle_ramp_test.cpp +++ b/tests/vehicle_ramp_test.cpp @@ -19,6 +19,7 @@ #include "map_iterator.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_range.h" #include "bodypart.h" #include "calendar.h" diff --git a/tests/vehicle_split_test.cpp b/tests/vehicle_split_test.cpp index 18979f6d7f58..88c7959dbcfa 100644 --- a/tests/vehicle_split_test.cpp +++ b/tests/vehicle_split_test.cpp @@ -7,6 +7,7 @@ #include "character.h" #include "map.h" #include "vehicle.h" +#include "vehicle_part.h" #include "type_id.h" #include "point.h" #include "state_helpers.h" diff --git a/tests/vehicle_test.cpp b/tests/vehicle_test.cpp index 196371e2b168..2fb64ef4fb5d 100644 --- a/tests/vehicle_test.cpp +++ b/tests/vehicle_test.cpp @@ -15,6 +15,7 @@ #include "state_helpers.h" #include "type_id.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "veh_type.h" diff --git a/tests/vehicle_turrets_test.cpp b/tests/vehicle_turrets_test.cpp index 18d59f465b40..3a909ebd0c62 100644 --- a/tests/vehicle_turrets_test.cpp +++ b/tests/vehicle_turrets_test.cpp @@ -21,6 +21,7 @@ #include "value_ptr.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_part.h" static std::vector turret_types() { diff --git a/tests/vision_test.cpp b/tests/vision_test.cpp index 209a641d015a..1183730a312d 100644 --- a/tests/vision_test.cpp +++ b/tests/vision_test.cpp @@ -26,6 +26,7 @@ #include "type_id.h" #include "weather.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vpart_position.h" #include "vpart_range.h" diff --git a/tests/visitable_remove_test.cpp b/tests/visitable_remove_test.cpp index f01264915c39..78e9fdc5c4d7 100644 --- a/tests/visitable_remove_test.cpp +++ b/tests/visitable_remove_test.cpp @@ -23,6 +23,7 @@ #include "state_helpers.h" #include "type_id.h" #include "vehicle.h" +#include "vehicle_part.h" #include "vehicle_selector.h" #include "visitable.h" #include "vpart_position.h"