cavegen.hpp

Go to the documentation of this file.
00001 /* $Id: cavegen.hpp 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 #ifndef CAVEGEN_HPP_INCLUDED
00019 #define CAVEGEN_HPP_INCLUDED
00020 
00021 #include "config.hpp"
00022 #include "mapgen.hpp"
00023 #include "terrain_translation.hpp"
00024 
00025 #include <set>
00026 
00027 class cave_map_generator : public map_generator
00028 {
00029 public:
00030     cave_map_generator(const config &game_config);
00031 
00032     bool allow_user_config() const { return true; }
00033     // This is a pure virtual function in the base class, so must be here
00034     void user_config(display& /* disp*/) { return; }
00035 
00036     std::string name() const { return "cave"; }
00037 
00038     std::string config_name() const;
00039 
00040     std::string create_map(const std::vector<std::string>& args);
00041     config create_scenario(const std::vector<std::string>& args);
00042 
00043 private:
00044 
00045     struct chamber {
00046         chamber() :
00047             center(),
00048             locs(),
00049             items(0)
00050         {
00051         }
00052 
00053         map_location center;
00054         std::set<map_location> locs;
00055         const config *items;
00056     };
00057 
00058     struct passage {
00059         passage(map_location s, map_location d, const config& c)
00060             : src(s), dst(d), cfg(c)
00061         {}
00062         map_location src, dst;
00063         config cfg;
00064     };
00065 
00066     void generate_chambers();
00067     void build_chamber(map_location loc, std::set<map_location>& locs, size_t size, size_t jagged);
00068 
00069     void place_chamber(const chamber& c);
00070 
00071     void place_passage(const passage& p);
00072 
00073     bool on_board(const map_location& loc) const
00074     {
00075         return loc.x >= 0 && loc.y >= 0 && loc.x < width_ && loc.y < height_;
00076     }
00077 
00078     void set_terrain(map_location loc, t_translation::t_terrain t);
00079     void place_castle(int starting_position, const map_location &loc);
00080 
00081     t_translation::t_terrain wall_, clear_, village_, castle_, keep_;
00082     t_translation::t_map map_;
00083     std::map<int, t_translation::coordinate> starting_positions_;
00084 
00085     std::map<std::string,size_t> chamber_ids_;
00086     std::vector<chamber> chambers_;
00087     std::vector<passage> passages_;
00088 
00089     config res_;
00090     config cfg_;
00091     int width_, height_, village_density_;
00092 
00093     // The scenario may have a chance to flip all x values or y values
00094     // to make the scenario appear all random. This is kept track of here.
00095     bool flipx_, flipy_;
00096 
00097     size_t translate_x(size_t x) const;
00098     size_t translate_y(size_t y) const;
00099 };
00100 
00101 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:34 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs