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 #pragma once 18 19 #include "tstring.hpp" 20 #include "utils/general.hpp" 21 22 #include <vector> 23 24 class config; 25 26 /** Small struct to store and manipulate ToD color adjusts. */ 27 // This is a color delta, so do not replace with color_t! 28 struct tod_color { tod_colortod_color29 explicit tod_color(int red = 0, int green = 0, int blue = 0) 30 : r(utils::clamp(red, -510, 510)) 31 , g(utils::clamp(green, -510, 510)) 32 , b(utils::clamp(blue, -510, 510)) 33 {} operator ==tod_color34 bool operator==(const tod_color& o) const { 35 return r == o.r && g == o.g && b == o.b; 36 } is_zerotod_color37 bool is_zero() const { 38 return r == 0 && g == 0 && b == 0; 39 } operator !=tod_color40 bool operator!=(const tod_color& o) const { 41 return !operator==(o); 42 } operator +tod_color43 tod_color operator+(const tod_color& o) const { 44 return tod_color(r + o.r, g + o.g, b + o.b); 45 } 46 47 int r,g,b; 48 }; 49 50 std::ostream &operator<<(std::ostream &s, const tod_color& tod); 51 52 53 /** 54 * Object which defines a time of day 55 * with associated bonuses, image, sounds etc. 56 */ 57 struct time_of_day 58 { 59 /** 60 * A default-constructed time of day object shouldn't really be used 61 * so this only loads some null values. Ideally, there should be 62 * getters for properties that would emit a warning when such an object 63 * is actually used, but it does not seem necessary at the moment. 64 */ 65 time_of_day(); 66 67 /** Construct a time of day from config */ 68 explicit time_of_day(const config& cfg); 69 operator ==time_of_day70 bool operator==(const time_of_day& o) const { 71 return lawful_bonus == o.lawful_bonus 72 && bonus_modified == o.bonus_modified 73 && image == o.image 74 && name == o.name 75 && id == o.id 76 && image_mask == o.image_mask 77 //&& color == o.color 78 && sounds == o.sounds; 79 } 80 81 void write(config& cfg) const; 82 83 /** The % bonus lawful units receive. Chaotics receive -lawful_bonus. */ 84 int lawful_bonus; 85 int bonus_modified; 86 87 /** The image to be displayed in the game status. */ 88 std::string image; 89 t_string name; 90 t_string description; 91 std::string id; 92 93 /** 94 * The image that is to be laid over all images 95 * while this time of day lasts. 96 */ 97 std::string image_mask; 98 99 /** 100 * The color modifications that should be made 101 * to the game board to reflect the time of day. 102 */ 103 tod_color color; 104 105 /** 106 * List of "ambient" sounds associated with this time_of_day, 107 * Played at the beginning of turn. 108 */ 109 std::string sounds; 110 111 /** 112 * Parse config and add time of day entries into passed vector 113 */ 114 static void parse_times(const config& cfg, std::vector<time_of_day>& normal_times); 115 }; 116