reports.hpp

Go to the documentation of this file.
00001 /* $Id: reports.hpp 24743 2008-03-17 12:28:38Z esr $ */
00002 /*
00003    Copyright (C) 2003 - 2008 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 version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 #ifndef REPORTS_HPP_INCLUDED
00016 #define REPORTS_HPP_INCLUDED
00017 
00018 #include <set>
00019 #include <string>
00020 #include <vector>
00021 
00022 #include "image.hpp"
00023 #include "team.hpp"
00024 
00025 //this module is responsible for outputting textual reports of
00026 //various game and unit statistics
00027 namespace reports {
00028     enum TYPE { UNIT_NAME, UNIT_TYPE, UNIT_RACE, UNIT_LEVEL,
00029             UNIT_SIDE, UNIT_AMLA, UNIT_TRAITS, UNIT_STATUS,
00030             UNIT_ALIGNMENT, UNIT_ABILITIES, UNIT_HP, UNIT_XP,
00031             UNIT_ADVANCEMENT_OPTIONS, UNIT_MOVES, UNIT_WEAPONS,
00032             UNIT_IMAGE, UNIT_PROFILE, TIME_OF_DAY,
00033             TURN, GOLD, VILLAGES, NUM_UNITS, UPKEEP, EXPENSES,
00034             INCOME, TERRAIN, POSITION, SIDE_PLAYING, OBSERVERS,
00035             REPORT_COUNTDOWN, REPORT_CLOCK, SELECTED_TERRAIN,
00036             EDIT_LEFT_BUTTON_FUNCTION, NUM_REPORTS};
00037 
00038     enum { UNIT_REPORTS_BEGIN=UNIT_NAME, UNIT_REPORTS_END=UNIT_PROFILE+1 };
00039     enum { STATUS_REPORTS_BEGIN=TIME_OF_DAY, STATUS_REPORTS_END=NUM_REPORTS };
00040 
00041     const std::string& report_name(TYPE type);
00042 
00043     struct element {
00044     private:
00045         //! Shouldn't be used so only declared.
00046         element();
00047     public:     
00048         explicit element(const std::string& text) : 
00049                 image(),
00050                 text(text),
00051                 tooltip()
00052                 {}
00053 
00054         // Invariant: either text or image should be empty
00055         // It would be okay to create a class for this, but it's a pretty simple
00056         // invariant so I left it like the original report class.
00057         image::locator image;
00058         std::string text;
00059 
00060         std::string tooltip;
00061         element(const std::string& text, const std::string& image, const std::string& tooltip) :
00062             image(image), text(text), tooltip(tooltip) {}
00063 
00064         element(const std::string& text, const image::locator& image, const std::string& tooltip) :
00065             image(image), text(text), tooltip(tooltip) {}
00066         element(const std::string& text, const char* image, const std::string& tooltip) :
00067             image(image), text(text), tooltip(tooltip) {}
00068 
00069         bool operator==(const element& o) const {
00070             return o.text == text && o.image == image && o.tooltip == tooltip;
00071         }
00072         bool operator!=(const element& o) const { return !(o == *this); }
00073     };
00074     struct report : public std::vector<element> {
00075         report() {}
00076         explicit report(const std::string& text) { this->push_back(element(text)); }
00077         report(const std::string& text, const std::string& image, const std::string& tooltip) {
00078             this->push_back(element(text, image, tooltip));
00079         }
00080         report(const std::string& text, const char* image, const std::string& tooltip) {
00081             this->push_back(element(text, image, tooltip));
00082         }
00083         report(const std::string& text, const image::locator& image, const std::string& tooltip) {
00084             this->push_back(element(text, image, tooltip));
00085         }
00086 
00087         // Convenience functions
00088         void add_text(std::stringstream& text, std::stringstream& tooltip);
00089         void add_text(const std::string& text, const std::string& tooltip);
00090         void add_image(const std::string& image, const std::string& tooltip);
00091         void add_image(std::stringstream& image, std::stringstream& tooltip);
00092     };
00093 
00094     report generate_report(TYPE type,
00095                    std::map<reports::TYPE, std::string> report_contents,
00096                    const gamemap& map, unit_map& units,
00097                    const std::vector<team>& teams, const team& current_team,
00098                    unsigned int current_side, int unsigned active_side,
00099                    const gamemap::location& loc, const gamemap::location& mouseover, const gamemap::location& displayed_unit_hex,
00100                    const gamestatus& status, const std::set<std::string>& observers,
00101                    const config& level);
00102 }
00103 
00104 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs