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