The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
time_of_day.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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["description"] = description;
63  cfg["id"] = id;
64  cfg["mask"] = image_mask;
65  cfg["sound"] = sounds;
66 }
67 
68 void time_of_day::parse_times(const config& cfg, std::vector<time_of_day>& times)
69 {
70  for(const config &t : cfg.child_range("time")) {
71  times.push_back(time_of_day(t));
72  }
73 
74  if(times.empty())
75  {
76  // Make sure we have at least default time
77  times.push_back(time_of_day());
78  }
79 }
80 
child_itors child_range(const std::string &key)
Definition: config.cpp:613
Small struct to store and manipulate ToD colors.
Definition: time_of_day.hpp:30
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:83
const GLfloat * c
Definition: glew.h:12741
std::string sounds
List of "ambient" sounds associated with this time_of_day, Played at the beginning of turn...
Definition: time_of_day.hpp:95
std::string id
Definition: time_of_day.hpp:77
int lawful_bonus
The % bonus lawful units receive.
Definition: time_of_day.hpp:70
std::string image
The image to be displayed in the game status.
Definition: time_of_day.hpp:74
GLdouble GLdouble t
Definition: glew.h:1366
Definitions for the interface to Wesnoth Markup Language (WML).
t_string name
Definition: time_of_day.hpp:75
GLuint id
Definition: glew.h:1647
t_string description
Definition: time_of_day.hpp:76
GLuint color
Definition: glew.h:5801
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:41
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:68
#define N_(String)
Definition: gettext.hpp:90
GLuint const GLchar * name
Definition: glew.h:1782
this module manages the cache of images.
Definition: image.cpp:75
void write(config &cfg) const
Definition: time_of_day.cpp:54
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLdouble s
Definition: glew.h:1358
std::ostream & operator<<(std::ostream &s, const tod_color &c)
Definition: time_of_day.cpp:23