Skip to content

Commit

Permalink
Character code reorganization 27-nov-2022 (#2208)
Browse files Browse the repository at this point in the history
* Move is_hallucination(), underwater check

* Move dodge_roll()

* Move reach_attack()

* Get rid of melee_attack() overload, use default arg

* Fix melee_value() checking wrong item

* Move weapon_value() family, encapsulate cached_info

* Remove dead code

* Get rid of get_artifact_items()

* Move can_autolearn()

* Move is_dead_state()

* Move power_bionics(), get rid of bionic indexes

* Move power_mutations() and related definitions

* Move and rename calc_fatigue_cap()

* Move needs_rates

* Move sleep-related definitions, fix wrong pos usages

* Move avoid_trap()

* Move vomit_mod()

* Move update_body_wetness()

* Move omt_path member from bionics section

* Move can_interface_armor()

* Move has_mission_item()

* Move basic_symbol_color()

* Move pause() and search_surroundings()

* Move talk_skill() and intimidation()

* Move is_stealthy()

* Move stability_roll()

* Break up character_functions.cpp

* Move and merge turn processing functions

* Move and rename weapname()

* Move pain-related functions

* Fix clang build

* Remove unused static const variables
  • Loading branch information
olanti-p authored Dec 16, 2022
1 parent 30517b3 commit cc23abc
Show file tree
Hide file tree
Showing 50 changed files with 2,589 additions and 2,462 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3485,7 +3485,7 @@ void activity_handlers::socialize_finish( player_activity *act, player *p )
void activity_handlers::try_sleep_do_turn( player_activity *act, player *p )
{
if( !p->has_effect( effect_sleep ) ) {
if( p->can_sleep() ) {
if( character_funcs::roll_can_sleep( *p ) ) {
act->set_to_null();
p->fall_asleep();
p->remove_value( "sleep_query" );
Expand Down
12 changes: 9 additions & 3 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "cata_utility.h"
#include "catacharset.h"
#include "character.h"
#include "character_effects.h"
#include "character_id.h"
#include "character_functions.h"
#include "character_martial_arts.h"
Expand Down Expand Up @@ -992,11 +993,16 @@ void avatar::vomit()
Character::vomit();
}

bool avatar::is_hallucination() const
{
return false;
}

void avatar::disp_morale()
{
int equilibrium = calc_focus_equilibrium();
int equilibrium = character_effects::calc_focus_equilibrium( *this );

int fatigue_cap = calc_fatigue_cap( this->get_fatigue() );
int fatigue_cap = character_effects::calc_morale_fatigue_cap( this->get_fatigue() );

int pain_penalty = has_trait( trait_CENOBITE ) ? 0 : get_perceived_pain();

Expand Down Expand Up @@ -1203,7 +1209,7 @@ bool avatar::wield( item &target )
if( !unwield() ) {
return false;
}
cached_info.erase( "weapon_value" );
clear_npc_ai_info_cache( "weapon_value" );
if( target.is_null() ) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class avatar : public player
*/
void steal( npc &target );

bool is_hallucination() const override;

pimpl<teleporter_list> translocators;

int get_str_base() const override;
Expand Down
5 changes: 3 additions & 2 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "calendar.h"
#include "character.h"
#include "character_martial_arts.h"
#include "character_turn.h"
#include "creature.h"
#include "cursesdef.h"
#include "debug.h"
Expand Down Expand Up @@ -573,7 +574,7 @@ static float rate_critter( const Creature &c )
{
const npc *np = dynamic_cast<const npc *>( &c );
if( np != nullptr ) {
return np->weapon_value( np->weapon );
return npc_ai::weapon_value( *np, np->weapon );
}

const monster *m = dynamic_cast<const monster *>( &c );
Expand All @@ -593,7 +594,7 @@ void avatar_action::autoattack( avatar &you, map &m )
if( critters.empty() ) {
add_msg( m_info, _( "No hostile creature in reach. Waiting a turn." ) );
if( g->check_safe_mode_allowed() ) {
you.pause();
character_funcs::do_pause( you );
}
return;
}
Expand Down
152 changes: 152 additions & 0 deletions src/avatar_functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#include "avatar_functions.h"

#include "avatar.h"
#include "character_functions.h"
#include "field_type.h"
#include "map.h"
#include "mapdata.h"
#include "trap.h"
#include "vpart_position.h"
#include "vehicle.h"
#include "veh_type.h"

static const trait_id trait_CHLOROMORPH( "CHLOROMORPH" );
static const trait_id trait_M_SKIN3( "M_SKIN3" );
static const trait_id trait_SHELL2( "SHELL2" );
static const trait_id trait_THRESH_SPIDER( "THRESH_SPIDER" );
static const trait_id trait_WATERSLEEP( "WATERSLEEP" );
static const trait_id trait_WEB_SPINNER( "WEB_SPINNER" );
static const trait_id trait_WEB_WALKER( "WEB_WALKER" );
static const trait_id trait_WEB_WEAVER( "WEB_WEAVER" );

static const bionic_id bio_soporific( "bio_soporific" );

namespace avatar_funcs
{

void try_to_sleep( avatar &you, const time_duration &dur )
{
map &here = get_map();
const optional_vpart_position vp = here.veh_at( you.pos() );
const trap &trap_at_pos = here.tr_at( you.pos() );
const ter_id ter_at_pos = here.ter( you.pos() );
const furn_id furn_at_pos = here.furn( you.pos() );
bool plantsleep = false;
bool fungaloid_cosplay = false;
bool websleep = false;
bool webforce = false;
bool websleeping = false;
bool in_shell = false;
bool watersleep = false;
if( you.has_trait( trait_CHLOROMORPH ) ) {
plantsleep = true;
if( ( ter_at_pos == t_dirt || ter_at_pos == t_pit ||
ter_at_pos == t_dirtmound || ter_at_pos == t_pit_shallow ||
ter_at_pos == t_grass ) && !vp &&
furn_at_pos == f_null ) {
you.add_msg_if_player( m_good, _( "You relax as your roots embrace the soil." ) );
} else if( vp ) {
you.add_msg_if_player( m_bad, _( "It's impossible to sleep in this wheeled pot!" ) );
} else if( furn_at_pos != f_null ) {
you.add_msg_if_player( m_bad,
_( "The humans' furniture blocks your roots. You can't get comfortable." ) );
} else { // Floor problems
you.add_msg_if_player( m_bad, _( "Your roots scrabble ineffectively at the unyielding surface." ) );
}
} else if( you.has_trait( trait_M_SKIN3 ) ) {
fungaloid_cosplay = true;
if( here.has_flag_ter_or_furn( "FUNGUS", you.pos() ) ) {
you.add_msg_if_player( m_good,
_( "Our fibers meld with the ground beneath us. The gills on our neck begin to seed the air with spores as our awareness fades." ) );
}
}
if( you.has_trait( trait_WEB_WALKER ) ) {
websleep = true;
}
// Not sure how one would get Arachnid w/o web-making, but Just In Case
if( you.has_trait( trait_THRESH_SPIDER ) && ( you.has_trait( trait_WEB_SPINNER ) ||
( you.has_trait( trait_WEB_WEAVER ) ) ) ) {
webforce = true;
}
if( websleep || webforce ) {
int web = here.get_field_intensity( you.pos(), fd_web );
if( !webforce ) {
// At this point, it's kinda weird, but surprisingly comfy...
if( web >= 3 ) {
you.add_msg_if_player( m_good,
_( "These thick webs support your weight, and are strangely comfortable�" ) );
websleeping = true;
} else if( web > 0 ) {
you.add_msg_if_player( m_info,
_( "You try to sleep, but the webs get in the way. You brush them aside." ) );
here.remove_field( you.pos(), fd_web );
}
} else {
// Here, you're just not comfortable outside a nice thick web.
if( web >= 3 ) {
you.add_msg_if_player( m_good, _( "You relax into your web." ) );
websleeping = true;
} else {
you.add_msg_if_player( m_bad,
_( "You try to sleep, but you feel exposed and your spinnerets keep twitching." ) );
you.add_msg_if_player( m_info, _( "Maybe a nice thick web would help you sleep." ) );
}
}
}
if( you.has_active_mutation( trait_SHELL2 ) ) {
// Your shell's interior is a comfortable place to sleep.
in_shell = true;
}
if( you.has_trait( trait_WATERSLEEP ) ) {
if( you.is_underwater() ) {
you.add_msg_if_player( m_good,
_( "You lay beneath the waves' embrace, gazing up through the water's surface�" ) );
watersleep = true;
} else if( here.has_flag_ter( "SWIMMABLE", you.pos() ) ) {
you.add_msg_if_player( m_good, _( "You settle into the water and begin to drowse�" ) );
watersleep = true;
}
}
constexpr int confort_level_neutral = static_cast<int>( character_funcs::comfort_level::neutral );
if( !plantsleep && ( furn_at_pos.obj().comfort > confort_level_neutral ||
ter_at_pos == t_improvised_shelter ||
trap_at_pos.comfort > confort_level_neutral ||
in_shell || websleeping || watersleep ||
vp.part_with_feature( "SEAT", true ) ||
vp.part_with_feature( "BED", true ) ) ) {
you.add_msg_if_player( m_good, _( "This is a comfortable place to sleep." ) );
} else if( !plantsleep && !fungaloid_cosplay && !watersleep ) {
if( !vp && ter_at_pos != t_floor ) {
you.add_msg_if_player( ter_at_pos.obj().movecost <= 2 ?
_( "It's a little hard to get to sleep on this %s." ) :
_( "It's hard to get to sleep on this %s." ),
ter_at_pos.obj().name() );
} else if( vp ) {
if( vp->part_with_feature( VPFLAG_AISLE, true ) ) {
you.add_msg_if_player(
//~ %1$s: vehicle name, %2$s: vehicle part name
_( "It's a little hard to get to sleep on this %2$s in %1$s." ),
vp->vehicle().disp_name(),
vp->part_with_feature( VPFLAG_AISLE, true )->part().name( false ) );
} else {
you.add_msg_if_player(
//~ %1$s: vehicle name
_( "It's hard to get to sleep in %1$s." ),
vp->vehicle().disp_name() );
}
}
}
you.add_msg_if_player( _( "You start trying to fall asleep." ) );
if( you.has_active_bionic( bio_soporific ) ) {
you.bio_soporific_powered_at_last_sleep_check = you.has_power();
if( you.bio_soporific_powered_at_last_sleep_check ) {
// The actual bonus is applied in sleep_spot( p ).
you.add_msg_if_player( m_good, _( "Your soporific inducer starts working its magic." ) );
} else {
you.add_msg_if_player( m_bad, _( "Your soporific inducer doesn't have enough power to operate." ) );
}
}
you.assign_activity( activity_id( "ACT_TRY_SLEEP" ), to_moves<int>( dur ) );
}

} // namespace avatar_funcs
17 changes: 17 additions & 0 deletions src/avatar_functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#ifndef CATA_SRC_AVATAR_FUNCTIONS_H
#define CATA_SRC_AVATAR_FUNCTIONS_H

#include "calendar.h"

class avatar;

namespace avatar_funcs
{

/** Handles sleep attempts by the player, starts ACT_TRY_SLEEP activity */
void try_to_sleep( avatar &you, const time_duration &dur = 30_minutes );

} // namespace avatar_funcs

#endif // CATA_SRC_AVATAR_FUNCTIONS_H
Loading

0 comments on commit cc23abc

Please sign in to comment.