Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/15459'
Browse files Browse the repository at this point in the history
* origin/pr/15459:
  Finally decouple 'player_morale' from 'player' (g->u)
  Extend unit tests to test body temp morale
  Transfer body temp morale (except comfy bonus)
  Add unit tests for the 'player_morale'
  Track effects
  Track mutations and worn items
  Clean up morale headers
  Rewrite 'player_morale' to observer-like shape
  Use references instead of pointers
  Nested 'morale_point' and a some cleanup
  Partly decouple temper. morale
  Hide 'morale_mult'
  Make 'player' use 'player_morale'
  Introduce 'player_morale' class
  Fix morale decay rate
  • Loading branch information
kevingranade committed Mar 8, 2016
2 parents 0386b56 + 1647914 commit c1afdce
Show file tree
Hide file tree
Showing 33 changed files with 1,152 additions and 497 deletions.
2 changes: 1 addition & 1 deletion CataclysmWin.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
<Unit filename="src/monstergenerator.h" />
<Unit filename="src/morale.cpp" />
<Unit filename="src/morale.h" />
<Unit filename="src/moraledata.h" />
<Unit filename="src/morale_types.h" />
<Unit filename="src/mtype.cpp" />
<Unit filename="src/mtype.h" />
<Unit filename="src/mutation.cpp" />
Expand Down
3 changes: 2 additions & 1 deletion astyled_whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ src/debug.h
src/dependency_tree.h
src/drawing_primitives.h
src/editmap.h
src/explosion.h
src/event.h
src/explosion.h
src/faction.h
src/filesystem.h
src/game_constants.h
Expand Down Expand Up @@ -132,6 +132,7 @@ src/mondefense.h
src/monfaction.h
src/mongroup.h
src/morale.h
src/morale_types.h
src/mutation.h
src/name.h
src/npc_favor.h
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ SET (CATACLYSM_DDA_HEADERS
${CMAKE_SOURCE_DIR}/src/computer.h
${CMAKE_SOURCE_DIR}/src/veh_interact.h
${CMAKE_SOURCE_DIR}/src/morale.h
${CMAKE_SOURCE_DIR}/src/morale_types.h
${CMAKE_SOURCE_DIR}/src/game.h
${CMAKE_SOURCE_DIR}/src/generic_factory.h
${CMAKE_SOURCE_DIR}/src/help.h
Expand Down
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "iuse_actor.h"
#include "rng.h"
#include "mongroup.h"
#include "morale.h"
#include "morale_types.h"
#include "messages.h"
#include "martialarts.h"
#include "itype.h"
Expand Down
2 changes: 1 addition & 1 deletion src/addiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "debug.h"
#include "pldata.h"
#include "player.h"
#include "morale.h"
#include "morale_types.h"
#include "rng.h"
#include "translations.h"

Expand Down
2 changes: 1 addition & 1 deletion src/catalua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "ui.h"
#include "mongroup.h"
#include "itype.h"
#include "morale.h"
#include "morale_types.h"
#include "trap.h"
#include "overmap.h"
#include "mtype.h"
Expand Down
6 changes: 6 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,12 @@ class Character : public Creature, public visitable<Character>

std::vector<bionic> my_bionics;

protected:
virtual void on_mutation_gain( const std::string & ) {};
virtual void on_mutation_loss( const std::string & ) {};
virtual void on_item_wear( const item & ) {};
virtual void on_item_takeoff( const item & ) {};

protected:
Character();
Character(const Character &) = default;
Expand Down
3 changes: 1 addition & 2 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "json.h"
#include "map.h"
#include "messages.h"
#include "morale.h"
#include "npc.h"
#include "options.h"
#include "output.h"
Expand Down Expand Up @@ -205,7 +204,7 @@ bool player::crafting_allowed( const std::string &rec_name )

bool player::crafting_allowed( const recipe &rec )
{
if( !has_morale_to_craft() ) { // See morale.h
if( !has_morale_to_craft() ) {
add_msg( m_info, _( "Your morale is too low to craft..." ) );
return false;
}
Expand Down
23 changes: 22 additions & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ void Creature::add_effect( const efftype_id &eff_id, int dur, body_part bp,
if (found_effect != bodyparts.end()) {
found = true;
effect &e = found_effect->second;
const int prev_int = e.get_intensity();
// If we do, mod the duration, factoring in the mod value
e.mod_duration(dur * e.get_dur_add_perc() / 100);
// Limit to max duration
Expand All @@ -832,6 +833,9 @@ void Creature::add_effect( const efftype_id &eff_id, int dur, body_part bp,
} else if (e.get_intensity() > e.get_max_intensity()) {
e.set_intensity(e.get_max_intensity());
}
if( e.get_intensity() != prev_int ) {
on_effect_int_change( eff_id, e.get_intensity(), bp );
}
}
}

Expand Down Expand Up @@ -881,6 +885,7 @@ void Creature::add_effect( const efftype_id &eff_id, int dur, body_part bp,
pgettext("memorial_female",
type.get_apply_memorial_log().c_str()));
}
on_effect_int_change( eff_id, e.get_intensity(), bp );
// Perform any effect addition effects.
bool reduced = resists_effect(e);
add_eff_effects(e, reduced);
Expand All @@ -904,6 +909,12 @@ bool Creature::add_env_effect( const efftype_id &eff_id, body_part vector, int s
}
void Creature::clear_effects()
{
for( auto &elem : effects ) {
for( auto &_effect_it : elem.second ) {
const effect &e = _effect_it.second;
on_effect_int_change( e.get_id(), 0, e.get_bp() );
}
}
effects.clear();
}
bool Creature::remove_effect( const efftype_id &eff_id, body_part bp )
Expand All @@ -928,9 +939,13 @@ bool Creature::remove_effect( const efftype_id &eff_id, body_part bp )

// num_bp means remove all of a given effect id
if (bp == num_bp) {
for( auto &it : effects[eff_id] ) {
on_effect_int_change( eff_id, 0, it.first );
}
effects.erase(eff_id);
} else {
effects[eff_id].erase(bp);
on_effect_int_change( eff_id, 0, bp );
// If there are no more effects of a given type remove the type map
if (effects[eff_id].empty()) {
effects.erase(eff_id);
Expand Down Expand Up @@ -1005,8 +1020,14 @@ void Creature::process_effects()
rem_ids.push_back( removed_effect );
rem_bps.push_back(num_bp);
}
effect &e = _it.second;
const int prev_int = e.get_intensity();
// Run decay effects, marking effects for removal as necessary.
_it.second.decay( rem_ids, rem_bps, calendar::turn, is_player() );
e.decay( rem_ids, rem_bps, calendar::turn, is_player() );

if( e.get_intensity() != prev_int && e.get_duration() > 0 ) {
on_effect_int_change( e.get_id(), e.get_intensity(), e.get_bp() );
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ class Creature
Creature &operator=(const Creature &) = default;
Creature &operator=(Creature &&) = default;

protected:
virtual void on_effect_int_change( const efftype_id &, int, body_part ) {};

public:
body_part select_body_part(Creature *source, int hit_roll) const;
protected:
Expand Down
1 change: 0 additions & 1 deletion src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "overmapbuffer.h"
#include "compatibility.h"
#include "translations.h"
#include "morale.h"
#include "coordinates.h"
#include "npc.h"
#include "vehicle.h"
Expand Down
2 changes: 1 addition & 1 deletion src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "overmapbuffer.h"
#include "messages.h"
#include "sounds.h"
#include "morale.h"
#include "morale_types.h"
#include "mapdata.h"

#include <climits>
Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#include "mission.h"
#include "compatibility.h"
#include "mongroup.h"
#include "morale.h"
#include "morale_types.h"
#include "worldfactory.h"
#include "material.h"
#include "martialarts.h"
Expand Down
1 change: 0 additions & 1 deletion src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "translations.h"
#include "options.h"
#include "messages.h"
#include "morale.h"
#include "input.h"
#include "catacharset.h"
#include "item_location.h"
Expand Down
7 changes: 4 additions & 3 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "mtype.h"
#include "field.h"
#include "weather.h"
#include "morale.h"
#include "catacharset.h"
#include "cata_utility.h"
#include "input.h"
Expand Down Expand Up @@ -1628,7 +1627,7 @@ std::string item::info( bool showtext, std::vector<iteminfo> &info ) const
}
}
}

if( is_gun() && has_flag( "FIRE_TWOHAND" ) ) {
info.push_back( iteminfo( "DESCRIPTION",
_( "* This weapon needs <info>two free hands</info> to fire." ) ) );
Expand Down Expand Up @@ -2024,11 +2023,13 @@ void item::on_wear( player &p )
if( &p == &g->u && type->artifact ) {
g->add_artifact_messages( type->artifact->effects_worn );
}

p.on_item_wear( *this );
}

void item::on_takeoff (player &p)
{
(void) p; // suppress unused variable warning
p.on_item_takeoff( *this );

if (is_sided()) {
set_side(BOTH);
Expand Down
5 changes: 2 additions & 3 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "iuse_actor.h" // For firestarter
#include "mongroup.h"
#include "translations.h"
#include "morale.h"
#include "morale_types.h"
#include "input.h"
#include "npc.h"
#include "event.h"
Expand Down Expand Up @@ -1000,7 +1000,6 @@ int iuse::prozac(player *p, item *it, bool, const tripoint& )
{
if( !p->has_effect( effect_took_prozac) && p->get_morale_level() < 0 ) {
p->add_effect( effect_took_prozac, 7200);
p->invalidate_morale_level();
} else {
p->stim += 3;
}
Expand Down Expand Up @@ -8098,7 +8097,7 @@ int iuse::multicooker(player *p, item *it, bool t, const tripoint &pos)

if (mc_upgrade == choice) {

if( !p->has_morale_to_craft() ) { // See morale.h
if( !p->has_morale_to_craft() ) {
add_msg(m_info, _("Your morale is too low to craft..."));
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "overmapbuffer.h"
#include "sounds.h"
#include "translations.h"
#include "morale.h"
#include "morale_types.h"
#include "messages.h"
#include "material.h"
#include "event.h"
Expand Down
1 change: 0 additions & 1 deletion src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "filesystem.h"
#include "path_info.h"
#include "mapsharing.h"
#include "morale.h"
#include "sounds.h"

#include <fstream>
Expand Down
3 changes: 1 addition & 2 deletions src/mission_companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "catacharset.h"
#include "messages.h"
#include "mission.h"
#include "morale.h"
#include "ammo.h"
#include "overmapbuffer.h"
#include "json.h"
Expand Down Expand Up @@ -1254,7 +1253,7 @@ bool talk_function::forage_return(npc *p)
} else {
popup(_("%s was caught unaware and was forced to fight the creature at close range!"), comp->name.c_str());
// the following doxygen aliases do not yet exist. this is marked for future reference

///\EFFECT_MELEE_NPC affects forage mission results

///\EFFECT_SURVIVAL_NPC affects forage mission results
Expand Down
8 changes: 4 additions & 4 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "weighted_list.h"
#include "mongroup.h"
#include "translations.h"
#include "morale.h"
#include "morale_types.h"
#include "npc.h"
#include "event.h"
#include "ui.h"
Expand Down Expand Up @@ -3851,9 +3851,9 @@ bool mattack::longswipe(monster *z)
!z->sees( *target ) ) {
return false; // Out of range
}

z->moves -= 150;

if (target->uncanny_dodge()) {
return true;
}
Expand Down Expand Up @@ -3893,7 +3893,7 @@ bool mattack::longswipe(monster *z)

// Can we dodge the attack? Uses player dodge function % chance (melee.cpp)
if (dodge_check(z, target)) {
target->add_msg_player_or_npc( _("The %s slashes at your neck! You duck!"),
target->add_msg_player_or_npc( _("The %s slashes at your neck! You duck!"),
_("The %s slashes at <npcname>'s neck! They duck!"), z->name().c_str() );
target->on_dodge( z, z->type->melee_skill * 2 );
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/mondeath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "mondeath.h"
#include "iuse_actor.h"
#include "translations.h"
#include "morale.h"
#include "morale_types.h"
#include "event.h"
#include "itype.h"
#include "mtype.h"
Expand Down
Loading

0 comments on commit c1afdce

Please sign in to comment.