The Battle for Wesnoth  1.15.2+dev
Classes | Namespaces | Macros | Functions | Variables
unit.cpp File Reference

Routines to manage units. More...

#include "units/unit.hpp"
#include "color.hpp"
#include "deprecation.hpp"
#include "display.hpp"
#include "formatter.hpp"
#include "formula/string_utils.hpp"
#include "game_board.hpp"
#include "game_config.hpp"
#include "game_data.hpp"
#include "game_errors.hpp"
#include "game_events/manager.hpp"
#include "preferences/game.hpp"
#include "gettext.hpp"
#include "lexical_cast.hpp"
#include "log.hpp"
#include "map/map.hpp"
#include "random.hpp"
#include "resources.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "side_filter.hpp"
#include "synced_context.hpp"
#include "team.hpp"
#include "terrain/filter.hpp"
#include "units/abilities.hpp"
#include "units/animation.hpp"
#include "units/animation_component.hpp"
#include "units/filter.hpp"
#include "units/formula_manager.hpp"
#include "units/id.hpp"
#include "units/map.hpp"
#include "variable.hpp"
#include "game_version.hpp"
#include "utils/functional.hpp"
#include <boost/dynamic_bitset.hpp>
#include <boost/function_output_iterator.hpp>
#include <boost/range/algorithm.hpp>
#include <array>
#include <cassert>
#include <cstdlib>
#include <exception>
#include <iterator>
#include <new>
#include <ostream>
Include dependency graph for unit.cpp:

Go to the source code of this file.

Classes

struct  ptr_vector_pushback
 

Namespaces

 t_translation
 

Macros

#define DBG_UT   LOG_STREAM(debug, log_unit)
 
#define LOG_UT   LOG_STREAM(info, log_unit)
 
#define WRN_UT   LOG_STREAM(warn, log_unit)
 
#define ERR_UT   LOG_STREAM(err, log_unit)
 

Functions

void intrusive_ptr_add_ref (const unit *u)
 Intrusive Pointer interface. More...
 
void intrusive_ptr_release (const unit *u)
 
static const unit_typeget_unit_type (const std::string &type_id)
 Converts a string ID to a unit_type. More...
 
static unit_race::GENDER generate_gender (const unit_type &type, bool random_gender)
 
static unit_race::GENDER generate_gender (const unit_type &u_type, const config &cfg)
 
static color_t hp_color_impl (int hitpoints, int max_hitpoints)
 
bool mod_duration_match (const std::string &mod_dur, const std::string &goal_dur)
 Determines if mod_dur "matches" goal_dur. More...
 
std::string get_checksum (const unit &u)
 Gets a checksum for a unit. More...
 
void swap (unit &lhs, unit &rhs)
 Implement non-member swap function for std::swap (calls unit::swap). More...
 

Variables

static lg::log_domain log_unit ("unit")
 

Detailed Description

Routines to manage units.

Definition in file unit.cpp.

Macro Definition Documentation

◆ DBG_UT

#define DBG_UT   LOG_STREAM(debug, log_unit)

◆ ERR_UT

#define ERR_UT   LOG_STREAM(err, log_unit)

Definition at line 81 of file unit.cpp.

Referenced by unit::~unit().

◆ LOG_UT

#define LOG_UT   LOG_STREAM(info, log_unit)

◆ WRN_UT

#define WRN_UT   LOG_STREAM(warn, log_unit)

Function Documentation

◆ generate_gender() [1/2]

static unit_race::GENDER generate_gender ( const unit_type type,
bool  random_gender 
)
static

◆ generate_gender() [2/2]

static unit_race::GENDER generate_gender ( const unit_type u_type,
const config cfg 
)
static

Definition at line 274 of file unit.cpp.

References generate_gender(), and string_gender().

◆ get_checksum()

std::string get_checksum ( const unit u)

Gets a checksum for a unit.

In MP games the descriptions are locally generated and might differ, so it should be possible to discard them. Not sure whether replays suffer the same problem.

Parameters
uthis unit
Returns
the checksum for a unit

Definition at line 2683 of file unit.cpp.

References config::add_child(), c, config::child_range(), DBG_UT, config::hash(), config::recursive_clear_value(), and unit::write().

Referenced by replay::add_unit_checksum(), and actions::find_recruit_location().

◆ get_unit_type()

static const unit_type& get_unit_type ( const std::string &  type_id)
static

Converts a string ID to a unit_type.

Throws a game_error exception if the string does not correspond to a type.

Definition at line 245 of file unit.cpp.

References unit_type::check_id(), error(), unit_type_data::find(), i, and unit_types.

Referenced by unit::expire_modifications(), wfl::gamestate_function_symbol_table::gamestate_function_symbol_table(), and unit::init().

◆ hp_color_impl()

static color_t hp_color_impl ( int  hitpoints,
int  max_hitpoints 
)
static

Definition at line 1086 of file unit.cpp.

References unit::hitpoints(), and color_t::r.

Referenced by unit::hp_color().

◆ intrusive_ptr_add_ref()

void intrusive_ptr_add_ref ( const unit u)

Intrusive Pointer interface.

Definition at line 215 of file unit.cpp.

References LOG_UT, and unit::ref_count_.

Referenced by unit::ref_count().

◆ intrusive_ptr_release()

void intrusive_ptr_release ( const unit u)

Definition at line 230 of file unit.cpp.

References DBG_UT, unit::id(), unit::ref_count_, and unit::underlying_id().

Referenced by unit::ref_count().

◆ mod_duration_match()

bool mod_duration_match ( const std::string &  mod_dur,
const std::string &  goal_dur 
)
inline

Determines if mod_dur "matches" goal_dur.

If goal_dur is not empty, they match if they are equal. If goal_dur is empty, they match if mod_dur is neither empty nor "forever". Helper function for expire_modifications().

Definition at line 1224 of file unit.cpp.

Referenced by unit::expire_modifications().

◆ swap()

void swap ( unit lhs,
unit rhs 
)

Implement non-member swap function for std::swap (calls unit::swap).

Definition at line 2778 of file unit.cpp.

References unit::swap().

Referenced by unit::clear_visibility_cache(), unit::shared_from_this(), and unit::swap().

Variable Documentation

◆ log_unit

lg::log_domain log_unit("unit")
static