The Battle for Wesnoth  1.15.12+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 #pragma once
16 
17 #include "tstring.hpp"
18 
19 #include <algorithm>
20 #include <vector>
21 
22 class config;
23 
24 /** Small struct to store and manipulate ToD color adjusts. */
25 // This is a color delta, so do not replace with color_t!
26 struct tod_color {
27  explicit tod_color(int red = 0, int green = 0, int blue = 0)
28  : r(std::clamp(red, -510, 510))
29  , g(std::clamp(green, -510, 510))
30  , b(std::clamp(blue, -510, 510))
31  {}
32  bool operator==(const tod_color& o) const {
33  return r == o.r && g == o.g && b == o.b;
34  }
35  bool is_zero() const {
36  return r == 0 && g == 0 && b == 0;
37  }
38  bool operator!=(const tod_color& o) const {
39  return !operator==(o);
40  }
41  tod_color operator+(const tod_color& o) const {
42  return tod_color(r + o.r, g + o.g, b + o.b);
43  }
44 
45  int r,g,b;
46 };
47 
48 std::ostream &operator<<(std::ostream &s, const tod_color& tod);
49 
50 
51 /**
52  * Object which defines a time of day
53  * with associated bonuses, image, sounds etc.
54  */
56 {
57  /**
58  * A default-constructed time of day object shouldn't really be used
59  * so this only loads some null values. Ideally, there should be
60  * getters for properties that would emit a warning when such an object
61  * is actually used, but it does not seem necessary at the moment.
62  */
63  time_of_day();
64 
65  /** Construct a time of day from config */
66  explicit time_of_day(const config& cfg);
67 
68  bool operator==(const time_of_day& o) const {
69  return lawful_bonus == o.lawful_bonus
70  && bonus_modified == o.bonus_modified
71  && image == o.image
72  && name == o.name
73  && id == o.id
74  && image_mask == o.image_mask
75  //&& color == o.color
76  && sounds == o.sounds;
77  }
78 
79  void write(config& cfg) const;
80 
81  /** The % bonus lawful units receive. Chaotics receive -lawful_bonus. */
84 
85  /** The image to be displayed in the game status. */
86  std::string image;
89  std::string id;
90 
91  /**
92  * The image that is to be laid over all images
93  * while this time of day lasts.
94  */
95  std::string image_mask;
96 
97  /**
98  * The color modifications that should be made
99  * to the game board to reflect the time of day.
100  */
102 
103  /**
104  * List of "ambient" sounds associated with this time_of_day,
105  * Played at the beginning of turn.
106  */
107  std::string sounds;
108 
109  /**
110  * Parse config and add time of day entries into passed vector
111  */
112  static void parse_times(const config& cfg, std::vector<time_of_day>& normal_times);
113 };
tod_color(int red=0, int green=0, int blue=0)
Definition: time_of_day.hpp:27
Small struct to store and manipulate ToD color adjusts.
Definition: time_of_day.hpp:26
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:95
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:89
tod_color operator+(const tod_color &o) const
Definition: time_of_day.hpp:41
int lawful_bonus
The % bonus lawful units receive.
Definition: time_of_day.hpp:82
std::string image
The image to be displayed in the game status.
Definition: time_of_day.hpp:86
STL namespace.
std::ostream & operator<<(std::ostream &s, const tod_color &tod)
Definition: time_of_day.cpp:22
t_string name
Definition: time_of_day.hpp:87
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:55
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
Definition: parser.cpp:763
t_string description
Definition: time_of_day.hpp:88
static map_location::DIRECTION s
bool operator==(const tod_color &o) const
Definition: time_of_day.hpp:32
bool is_zero() const
Definition: time_of_day.hpp:35
bool operator!=(const tod_color &o) const
Definition: time_of_day.hpp:38
bool operator==(const time_of_day &o) const
Definition: time_of_day.hpp:68
Functions to load and save images from/to disk.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
int bonus_modified
Definition: time_of_day.hpp:83