Skip to content

Commit

Permalink
Handle transformation of worn items affecting morale
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund authored and kevingranade committed Feb 5, 2019
1 parent 8751619 commit 6567661
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/morale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<iuse_transform *>( 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 ) {
Expand Down
1 change: 1 addition & 0 deletions src/morale.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
4 changes: 4 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down
1 change: 1 addition & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6567661

Please sign in to comment.