time_of_day.cpp

Go to the documentation of this file.
00001 /* $Id: time_of_day.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /** @file */
00017 
00018 #include "config.hpp"
00019 #include "foreach.hpp"
00020 #include "time_of_day.hpp"
00021 
00022 
00023 std::ostream &operator<<(std::ostream &s, const tod_color& c){
00024     s << c.r << "," << c.g << "," << c.b;
00025     return s;
00026 }
00027 
00028 
00029 time_of_day::time_of_day(const config& cfg):
00030     lawful_bonus(cfg["lawful_bonus"]),
00031     bonus_modified(0),
00032     image(cfg["image"]), name(cfg["name"].t_str()), id(cfg["id"]),
00033     image_mask(cfg["mask"]),
00034     color(cfg["red"], cfg["green"], cfg["blue"]),
00035     sounds(cfg["sound"])
00036 {
00037 }
00038 
00039 time_of_day::time_of_day()
00040 : lawful_bonus(0)
00041 , bonus_modified(0)
00042 , image()
00043 , name("NULL_TOD")
00044 , id("nulltod")
00045 , image_mask()
00046 , color(0,0,0)
00047 , sounds()
00048 {
00049 }
00050 
00051 void time_of_day::write(config& cfg) const
00052 {
00053     cfg["lawful_bonus"] = lawful_bonus;
00054     cfg["red"] = color.r;
00055     cfg["green"] = color.g;
00056     cfg["blue"] = color.b;
00057     cfg["image"] = image;
00058     cfg["name"] = name;
00059     cfg["id"] = id;
00060     cfg["mask"] = image_mask;
00061 }
00062 
00063 void time_of_day::parse_times(const config& cfg, std::vector<time_of_day>& normal_times)
00064 {
00065     foreach (const config &t, cfg.child_range("time")) {
00066         normal_times.push_back(time_of_day(t));
00067     }
00068 
00069     if(normal_times.empty())
00070     {
00071         // Make sure we have at least default time
00072         config dummy_cfg;
00073         normal_times.push_back(time_of_day(dummy_cfg));
00074     }
00075 }
00076 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:12 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs