From 6567661e931213b03566f248353bb92bef75215a Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 5 Feb 2019 03:37:26 +0100 Subject: [PATCH] Handle transformation of worn items affecting morale --- src/iuse_actor.cpp | 1 + src/morale.cpp | 11 +++++++++++ src/morale.h | 1 + src/player.cpp | 4 ++++ src/player.h | 1 + 5 files changed, 18 insertions(+) diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index 3bddc06da974b..fec5f0a5ff96c 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -190,6 +190,7 @@ long iuse_transform::use( player &p, item &it, bool t, const tripoint &pos ) con if( p.is_worn( *obj ) ) { p.reset_encumbrance(); p.update_bodytemp(); + p.on_worn_item_transform( *obj ); } obj->item_counter = countdown > 0 ? countdown : obj->type->countdown_interval; obj->active = active || obj->item_counter; diff --git a/src/morale.cpp b/src/morale.cpp index 356645ead6194..85a71f6137204 100644 --- a/src/morale.cpp +++ b/src/morale.cpp @@ -11,6 +11,7 @@ #include "input.h" #include "item.h" #include "itype.h" +#include "iuse_actor.h" #include "morale_types.h" #include "options.h" #include "output.h" @@ -565,6 +566,16 @@ void player_morale::on_item_takeoff( const item &it ) set_worn( it, false ); } +void player_morale::on_worn_item_transform( const item &it ) +{ + item dummy = it; + dummy.convert( dynamic_cast( item::find_type( + it.typeId() )->get_use( "transform" )->get_actor_ptr() )->target ); + + set_worn( dummy, false ); + set_worn( it, true ); +} + void player_morale::on_worn_item_washed( const item &it ) { const auto update_body_part = [&]( body_part_data & bp_data ) { diff --git a/src/morale.h b/src/morale.h index 133459a3d3d54..64a8397e0e05a 100644 --- a/src/morale.h +++ b/src/morale.h @@ -57,6 +57,7 @@ class player_morale void on_stat_change( const std::string &stat, int value ); void on_item_wear( const item &it ); void on_item_takeoff( const item &it ); + void on_worn_item_transform( const item &it ); void on_worn_item_washed( const item &it ); void on_effect_int_change( const efftype_id &eid, int intensity, body_part bp = num_bp ); diff --git a/src/player.cpp b/src/player.cpp index 29c382ba1d12f..fcb5528e12b3c 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -6770,6 +6770,10 @@ void player::check_and_recover_morale() } } +void player::on_worn_item_transform( const item &it ) { + morale->on_worn_item_transform( it ); +} + void player::process_active_items() { if( weapon.needs_processing() && weapon.process( this, pos(), false ) ) { diff --git a/src/player.h b/src/player.h index 23ddb494b09c6..02615985de386 100644 --- a/src/player.h +++ b/src/player.h @@ -1228,6 +1228,7 @@ class player : public Character bool has_morale_to_read() const; /** Checks permanent morale for consistency and recovers it when an inconsistency is found. */ void check_and_recover_morale(); + void on_worn_item_transform( const item &it ); /** Get the formatted name of the currently wielded item (if any) */ std::string weapname() const;