28 #define ERR_NG LOG_STREAM(err, log_engine)
30 using namespace std::chrono_literals;
34 std::chrono::steady_clock::time_point get_next_idle_tick()
37 return std::chrono::steady_clock::time_point::max();
40 const double rate = std::pow(2.0, -
prefs::get().idle_anim_rate() / 10.0);
51 std::vector<const unit_animation*> options;
54 int matching = anim.matches(
loc,second_loc,u_.shared_from_this(),event,value,hit,attack,second_attack,swing_num);
56 options.push_back(&anim);
57 }
else if(matching > max_val) {
60 options.push_back(&anim);
72 if (
prefs::get().show_standing_animations()&& !u_.incapacitated()) {
73 start_animation(std::chrono::milliseconds::max(), choose_animation(u_.loc_,
"standing"),
74 with_bars,
"", {0,0,0}, STATE_STANDING);
76 start_animation(std::chrono::milliseconds::max(), choose_animation(u_.loc_,
"_disabled_"),
77 with_bars,
"", {0,0,0}, STATE_STANDING);
83 start_animation(std::chrono::milliseconds::max(), choose_animation(u_.loc_,
"_ghosted_"),
85 anim_->pause_animation();
90 start_animation(std::chrono::milliseconds::max(), choose_animation(u_.loc_,
"_disabled_ghosted_"),
96 start_animation(std::chrono::milliseconds::max(), choose_animation(u_.loc_,
"idling"),
97 true,
"", {0,0,0}, STATE_FORGET);
102 if (
prefs::get().show_standing_animations() && !u_.incapacitated()) {
103 start_animation(std::chrono::milliseconds::max(), choose_animation(u_.loc_,
"selected"),
104 true,
"", {0,0,0}, STATE_FORGET);
106 start_animation(std::chrono::milliseconds::max(), choose_animation(u_.loc_,
"_disabled_selected_"),
107 true,
"", {0,0,0}, STATE_FORGET);
112 bool with_bars,
const std::string &text,
color_t text_color,
STATE state)
115 if (state == STATE_STANDING)
117 if (!anim_ && state_ != STATE_STANDING)
118 set_standing(with_bars);
123 bool accelerate = (state != STATE_FORGET && state != STATE_STANDING);
124 draw_bars_ = with_bars;
126 const auto real_start_time = start_time == std::chrono::milliseconds::max() ? anim_->get_begin_time() : start_time;
127 anim_->start_animation(real_start_time, u_.loc_, u_.loc_.get_direction(u_.facing_),
128 text, text_color, accelerate);
129 frame_begin_time_ = anim_->get_begin_time() - 1ms;
130 next_idling_ = get_next_idle_tick();
135 if (state_ == STATE_FORGET && anim_ && anim_->animation_finished_potential())
149 next_idling_ = get_next_idle_tick();
159 abil_halos_ref_.clear();
160 if(anim_ ) anim_->clear_haloes();
168 if(get_animation()) {
175 if (u_.is_flying() && height_adjust < 0) {
178 params.
y -= height_adjust;
179 params.
halo_y -= height_adjust;
181 params.
halo_mod = u_.TC_image_mods();
182 params.
image= u_.default_anim_image();
184 result |= get_animation()->invalidate(params);
203 bool affect_adjacent =
false;
204 for(
const auto [key, cfg] : u_.abilities().all_children_view()) {
205 bool image_or_hides = (key ==
"hides" || cfg.has_attribute(
"halo_image") || cfg.has_attribute(
"overlay_image"));
206 if(image_or_hides && cfg.has_child(
"affect_adjacent")){
207 affect_adjacent =
true;
211 if(affect_adjacent) {
213 for(
unsigned i = 0;
i < adjacent.size(); ++
i) {
215 if (it == units.
end() || it->incapacitated()){
219 ERR_NG <<
"Impossible situation: the unit is adjacent to itself.";
222 it->anim_comp().set_standing();
228 if(effect[
"id"].empty()) {
231 static std::map< std::string, std::vector<unit_animation>> animation_cache;
232 std::vector<unit_animation> &built = animation_cache[effect[
"id"]];
236 animations_.insert(animations_.end(),built.begin(),built.end());
241 std::set<std::string> result;
242 for(
const auto& anim : animations_) {
243 const std::vector<std::string>& flags = anim.get_flags();
244 std::copy_if(flags.begin(), flags.end(), std::inserter(result, result.begin()), [](
const std::string&
flag) {
245 return !(flag.empty() || (flag.front() ==
'_' && flag.back() ==
'_'));
248 return std::vector<std::string>(result.begin(), result.end());
std::chrono::steady_clock::time_point get_current_animation_tick()
static lg::log_domain log_engine("engine")
A config object defines a single node in a WML file, with access to child nodes.
virtual const gamemap & map() const =0
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
static double get_zoom_factor()
Returns the current zoom factor.
bool tile_nearly_on_screen(const map_location &loc) const
Checks if location loc or one of the adjacent tiles is visible on screen.
const display_context & context() const
static display * get_singleton()
Returns the display object if a display object exists.
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Encapsulates the map of the game.
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
static rng & default_instance()
int get_random_int(int min, int max)
int unit_height_adjust() const
void set_idling()
Sets the animation state to idling.
void apply_new_animation_effect(const config &effect)
Adds an animation described by a config.
bool invalidate(const display &disp)
Invalidates an animation with respect to a display object, preparing it for redraw.
void set_ghosted(bool with_bars=true)
Sets the animation state to ghosted.
void refresh()
Intermittently activates the idling animations in place of the standing animations.
void reset_after_advance(const unit_type *newtype=nullptr)
Resets the animations list after the unit is advanced.
void reset_affect_adjacent(const unit_map &units)
Refresh map around unit if has ability with [affect_adjacent/distant] tag.
std::vector< std::string > get_flags()
Get the flags of all registered animations.
void set_standing(bool with_bars=true)
Sets the animation state to standing.
STATE
States for animation.
void set_selecting()
Sets the animation state to that when the unit is selected.
void clear_haloes()
Clear the haloes associated to the unit.
void set_disabled_ghosted(bool with_bars=true)
Whiteboard related somehow.
const unit_animation * choose_animation(const map_location &loc, const std::string &event, const map_location &second_loc=map_location::null_location(), const int damage=0, const strike_result::type hit_type=strike_result::type::invalid, const const_attack_ptr &attack=nullptr, const const_attack_ptr &second_attack=nullptr, int swing_num=0)
Chooses an appropriate animation from the list of known animations.
void start_animation(const std::chrono::milliseconds &start_time, const unit_animation *animation, bool with_bars, const std::string &text="", color_t text_color={}, STATE state=STATE_ANIM)
Begin an animation.
static void add_anims(std::vector< unit_animation > &animations, const config &cfg)
Container associating units to locations.
unit_iterator find(std::size_t id)
A single unit type that the player may recruit.
const std::vector< unit_animation > & animations() const
Definitions for the interface to Wesnoth Markup Language (WML).
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
Standard logging facilities (interface).
std::shared_ptr< const attack_type > const_attack_ptr
The basic class for representing 8-bit RGB or RGBA colour values.
All parameters from a frame at a given instant.
Encapsulates the map of the game.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...