The Battle for Wesnoth  1.19.4+dev
time_of_day.cpp
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 #include "time_of_day.hpp"
17 
18 #include "config.hpp"
19 #include "gettext.hpp"
20 
21 std::ostream& operator<<(std::ostream& s, const tod_color& c)
22 {
23  s << c.r << "," << c.g << "," << c.b;
24  return s;
25 }
26 
28  : lawful_bonus(cfg["lawful_bonus"].to_int())
29  , bonus_modified(0)
30  , image(cfg["image"])
31  , name(cfg["name"].t_str())
32  , description(cfg["description"].t_str())
33  , id(cfg["id"])
34  , image_mask(cfg["mask"])
35  , color(cfg["red"].to_int(), cfg["green"].to_int(), cfg["blue"].to_int())
36  , sounds(cfg["sound"])
37 {
38 }
39 
41  : lawful_bonus(0)
42  , bonus_modified(0)
43  , image()
44  , name(N_("Stub Time of Day"))
45  , description(N_("This Time of Day is only a Stub!"))
46  , id("nulltod")
47  , image_mask()
48  , color(0, 0, 0)
49  , sounds()
50 {
51 }
52 
53 void time_of_day::write(config& cfg, std::string textdomain) const
54 {
55  cfg["lawful_bonus"] = lawful_bonus;
56  cfg["red"] = color.r;
57  cfg["green"] = color.g;
58  cfg["blue"] = color.b;
59  cfg["image"] = image;
60  cfg["name"] = textdomain.empty() ? name : t_string(name, textdomain);
61  cfg["id"] = id;
62 
63  // Optional keys
64  cfg["description"].write_if_not_empty(textdomain.empty() ? description : t_string(description, textdomain));
65  cfg["mask"].write_if_not_empty(image_mask);
66  cfg["sound"].write_if_not_empty(sounds);
67 }
68 
69 void time_of_day::parse_times(const config& cfg, std::vector<time_of_day>& times)
70 {
71  for(const config& t : cfg.child_range("time")) {
72  times.emplace_back(t);
73  }
74 }
double t
Definition: astarsearch.cpp:63
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
child_itors child_range(config_key_type key)
Definition: config.cpp:271
bool empty() const
Definition: config.cpp:853
Definitions for the interface to Wesnoth Markup Language (WML).
#define N_(String)
Definition: gettext.hpp:101
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:198
Functions to load and save images from/to disk.
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
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
mock_char c
static map_location::direction s
std::ostream & operator<<(std::ostream &s, const tod_color &c)
Definition: time_of_day.cpp:21