The Battle for Wesnoth  1.17.0-dev
time_of_day.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
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 #include "time_of_day.hpp"
17 
18 #include "config.hpp"
19 #include "gettext.hpp"
20 
21 #include <iostream>
22 
23 std::ostream& operator<<(std::ostream& s, const tod_color& c)
24 {
25  s << c.r << "," << c.g << "," << c.b;
26  return s;
27 }
28 
30  : lawful_bonus(cfg["lawful_bonus"])
31  , bonus_modified(0)
32  , image(cfg["image"])
33  , name(cfg["name"].t_str())
34  , description(cfg["description"].t_str())
35  , id(cfg["id"])
36  , image_mask(cfg["mask"])
37  , color(cfg["red"], cfg["green"], cfg["blue"])
38  , sounds(cfg["sound"])
39 {
40 }
41 
43  : lawful_bonus(0)
44  , bonus_modified(0)
45  , image()
46  , name(N_("Stub Time of Day"))
47  , description(N_("This Time of Day is only a Stub!"))
48  , id("nulltod")
49  , image_mask()
50  , color(0, 0, 0)
51  , sounds()
52 {
53 }
54 
55 void time_of_day::write(config& cfg) const
56 {
57  cfg["lawful_bonus"] = lawful_bonus;
58  cfg["red"] = color.r;
59  cfg["green"] = color.g;
60  cfg["blue"] = color.b;
61  cfg["image"] = image;
62  cfg["name"] = name;
63  cfg["id"] = id;
64 
65  // Optional keys
66  cfg["description"].write_if_not_empty(description);
67  cfg["mask"].write_if_not_empty(image_mask);
68  cfg["sound"].write_if_not_empty(sounds);
69 }
70 
71 void time_of_day::parse_times(const config& cfg, std::vector<time_of_day>& times)
72 {
73  for(const config& t : cfg.child_range("time")) {
74  times.emplace_back(t);
75  }
76 }
Small struct to store and manipulate ToD color adjusts.
Definition: time_of_day.hpp:27
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
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...
child_itors child_range(config_key_type key)
Definition: config.cpp:344
std::string id
Definition: time_of_day.hpp:90
int lawful_bonus
The % bonus lawful units receive.
Definition: time_of_day.hpp:83
std::string image
The image to be displayed in the game status.
Definition: time_of_day.hpp:87
void write(config &cfg) const
Definition: time_of_day.cpp:55
Definitions for the interface to Wesnoth Markup Language (WML).
t_string name
Definition: time_of_day.hpp:88
t_string description
Definition: time_of_day.hpp:89
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
time_of_day()
A default-constructed time of day object shouldn&#39;t really be used so this only loads some null values...
Definition: time_of_day.cpp:42
static map_location::DIRECTION s
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:71
#define N_(String)
Definition: gettext.hpp:101
double t
Definition: astarsearch.cpp:65
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:61
mock_char c
int bonus_modified
Definition: time_of_day.hpp:84
std::ostream & operator<<(std::ostream &s, const tod_color &c)
Definition: time_of_day.cpp:23