The Battle for Wesnoth  1.15.2+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 /** @file */
16 
17 #include "config.hpp"
18 #include "time_of_day.hpp"
19 #include "gettext.hpp"
20 
21 #include <iostream>
22 
23 std::ostream &operator<<(std::ostream &s, const tod_color& c){
24  s << c.r << "," << c.g << "," << c.b;
25  return s;
26 }
27 
28 
30  lawful_bonus(cfg["lawful_bonus"]),
31  bonus_modified(0),
32  image(cfg["image"]), 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.push_back(time_of_day(t));
74  }
75 
76  if(times.empty())
77  {
78  // Make sure we have at least default time
79  times.push_back(time_of_day());
80  }
81 }
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...
child_itors child_range(config_key_type key)
Definition: config.cpp:362
std::string id
Definition: time_of_day.hpp:91
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
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:89
t_string description
Definition: time_of_day.hpp:90
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:99
double t
Definition: astarsearch.cpp:64
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
mock_char c
int bonus_modified
Definition: time_of_day.hpp:85
std::ostream & operator<<(std::ostream &s, const tod_color &c)
Definition: time_of_day.cpp:23