The Battle for Wesnoth  1.19.1+dev
time_of_day.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "tstring.hpp"
19 
20 #include <algorithm>
21 #include <vector>
22 
23 class config;
24 
25 /** Small struct to store and manipulate ToD color adjusts. */
26 // This is a color delta, so do not replace with color_t!
27 struct tod_color {
28  explicit tod_color(int red = 0, int green = 0, int blue = 0)
29  : r(std::clamp(red, -510, 510))
30  , g(std::clamp(green, -510, 510))
31  , b(std::clamp(blue, -510, 510))
32  {}
33  bool operator==(const tod_color& o) const {
34  return r == o.r && g == o.g && b == o.b;
35  }
36  bool is_zero() const {
37  return r == 0 && g == 0 && b == 0;
38  }
39  bool operator!=(const tod_color& o) const {
40  return !operator==(o);
41  }
42  tod_color operator+(const tod_color& o) const {
43  return tod_color(r + o.r, g + o.g, b + o.b);
44  }
45 
46  int r,g,b;
47 };
48 
49 std::ostream &operator<<(std::ostream &s, const tod_color& tod);
50 
51 
52 /**
53  * Object which defines a time of day
54  * with associated bonuses, image, sounds etc.
55  */
57 {
58  /**
59  * A default-constructed time of day object shouldn't really be used
60  * so this only loads some null values. Ideally, there should be
61  * getters for properties that would emit a warning when such an object
62  * is actually used, but it does not seem necessary at the moment.
63  */
64  time_of_day();
65 
66  /** Construct a time of day from config */
67  explicit time_of_day(const config& cfg);
68 
69  bool operator==(const time_of_day& o) const {
70  return lawful_bonus == o.lawful_bonus
72  && image == o.image
73  && name == o.name
74  && id == o.id
75  && image_mask == o.image_mask
76  //&& color == o.color
77  && sounds == o.sounds;
78  }
79 
80  void write(config& cfg, std::string textdomain = "") const;
81 
82  /** The % bonus lawful units receive. Chaotics receive -lawful_bonus. */
85 
86  /** The image to be displayed in the game status. */
87  std::string image;
90  std::string id;
91 
92  /**
93  * The image that is to be laid over all images
94  * while this time of day lasts.
95  */
96  std::string image_mask;
97 
98  /**
99  * The color modifications that should be made
100  * to the game board to reflect the time of day.
101  */
103 
104  /**
105  * List of "ambient" sounds associated with this time_of_day,
106  * Played at the beginning of turn.
107  */
108  std::string sounds;
109 
110  /**
111  * Parse config and add time of day entries into passed vector
112  */
113  static void parse_times(const config& cfg, std::vector<time_of_day>& normal_times);
114 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
Functions to load and save images from/to disk.
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
int bonus_modified
Definition: time_of_day.hpp:84
std::string id
Definition: time_of_day.hpp:90
static void parse_times(const config &cfg, std::vector< time_of_day > &normal_times)
Parse config and add time of day entries into passed vector.
Definition: time_of_day.cpp:69
tod_color color
The color modifications that should be made to the game board to reflect the time of day.
void write(config &cfg, std::string textdomain="") const
Definition: time_of_day.cpp:53
int lawful_bonus
The % bonus lawful units receive.
Definition: time_of_day.hpp:83
t_string description
Definition: time_of_day.hpp:89
t_string name
Definition: time_of_day.hpp:88
std::string image
The image to be displayed in the game status.
Definition: time_of_day.hpp:87
time_of_day()
A default-constructed time of day object shouldn't really be used so this only loads some null values...
Definition: time_of_day.cpp:40
bool operator==(const time_of_day &o) const
Definition: time_of_day.hpp:69
std::string sounds
List of "ambient" sounds associated with this time_of_day, Played at the beginning of turn.
std::string image_mask
The image that is to be laid over all images while this time of day lasts.
Definition: time_of_day.hpp:96
Small struct to store and manipulate ToD color adjusts.
Definition: time_of_day.hpp:27
bool operator!=(const tod_color &o) const
Definition: time_of_day.hpp:39
bool is_zero() const
Definition: time_of_day.hpp:36
tod_color operator+(const tod_color &o) const
Definition: time_of_day.hpp:42
tod_color(int red=0, int green=0, int blue=0)
Definition: time_of_day.hpp:28
bool operator==(const tod_color &o) const
Definition: time_of_day.hpp:33
static map_location::DIRECTION s
constexpr uint32_t red
Definition: test_sdl.cpp:24
constexpr uint32_t green
Definition: test_sdl.cpp:25
constexpr uint32_t blue
Definition: test_sdl.cpp:26
std::ostream & operator<<(std::ostream &s, const tod_color &tod)
Definition: time_of_day.cpp:21