cavegen.hpp

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

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