The Battle for Wesnoth  1.17.0-dev
time_of_day.cpp
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 #include "time_of_day.hpp"
16 
17 #include "config.hpp"
18 #include "gettext.hpp"
19 
20 #include <iostream>
21 
22 std::ostream& operator<<(std::ostream& s, const tod_color& c)
23 {
24  s << c.r << "," << c.g << "," << c.b;
25  return s;
26 }
27 
29  : lawful_bonus(cfg["lawful_bonus"])
30  , bonus_modified(0)
31  , image(cfg["image"])
32  , name(cfg["name"].t_str())
33  , description(cfg["description"].t_str())
34  , id(cfg["id"])
35  , image_mask(cfg["mask"])
36  , color(cfg["red"], cfg["green"], cfg["blue"])
37  , sounds(cfg["sound"])
38 {
39 }
40 
42  : lawful_bonus(0)
43  , bonus_modified(0)
44  , image()
45  , name(N_("Stub Time of Day"))
46  , description(N_("This Time of Day is only a Stub!"))
47  , id("nulltod")
48  , image_mask()
49  , color(0, 0, 0)
50  , sounds()
51 {
52 }
53 
54 void time_of_day::write(config& cfg) const
55 {
56  cfg["lawful_bonus"] = lawful_bonus;
57  cfg["red"] = color.r;
58  cfg["green"] = color.g;
59  cfg["blue"] = color.b;
60  cfg["image"] = image;
61  cfg["name"] = name;
62  cfg["id"] = id;
63 
64  // Optional keys
65  cfg["description"].write_if_not_empty(description);
66  cfg["mask"].write_if_not_empty(image_mask);
67  cfg["sound"].write_if_not_empty(sounds);
68 }
69 
70 void time_of_day::parse_times(const config& cfg, std::vector<time_of_day>& times)
71 {
72  for(const config& t : cfg.child_range("time")) {
73  times.emplace_back(t);
74  }
75 }
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...
child_itors child_range(config_key_type key)
Definition: config.cpp:360
std::string id
Definition: time_of_day.hpp:89
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
void write(config &cfg) const
Definition: time_of_day.cpp:54
Definitions for the interface to Wesnoth Markup Language (WML).
t_string name
Definition: time_of_day.hpp:87
t_string description
Definition: time_of_day.hpp:88
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:214
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:41
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:70
#define N_(String)
Definition: gettext.hpp:100
double t
Definition: astarsearch.cpp:64
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
mock_char c
int bonus_modified
Definition: time_of_day.hpp:83
std::ostream & operator<<(std::ostream &s, const tod_color &c)
Definition: time_of_day.cpp:22