--- deliantra/server/random_maps/random_map.h 2008/04/14 22:41:17 1.18
+++ deliantra/server/random_maps/random_map.h 2010/07/02 03:40:14 1.33
@@ -1,22 +1,23 @@
/*
* This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
- * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
- * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
- * Copyright (©) 1992,2007 Frank Tore Johansen
+ * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
+ * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
+ * Copyright (©) 1992 Frank Tore Johansen
*
- * Deliantra is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * Deliantra is free software: you can redistribute it and/or modify it under
+ * the terms of the Affero GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
+ * You should have received a copy of the Affero GNU General Public License
+ * and the GNU General Public License along with this program. If not, see
+ * .
*
* The authors can be reached via e-mail to
*/
@@ -26,23 +27,17 @@
#include "util.h"
-struct random_map_params
+struct random_map_params : zero_initialised
{
- char wallstyle[512];
char wall_name[512];
- char floorstyle[512];
char monsterstyle[512];
- char treasurestyle[512];
char layoutstyle[512];
char doorstyle[512];
- char decorstyle[512];
shstr origin_map;
shstr final_map;
- char exitstyle[512];
shstr this_map;
char exit_on_final_map[512];
- char *custom;
-
+
int xsize, ysize;
int expand2x;
int layoutoptions1;
@@ -56,21 +51,41 @@
int dungeon_level;
int dungeon_depth;
- int decoroptions;
int orientation;
- int origin_y;
int origin_x;
+ int origin_y;
uint32_t random_seed;
uint64_t total_map_hp;
int map_layout_style;
- int treasureoptions;
int symmetry_used;
struct region *region;
+ HV *hv;
+ void hv_clone (); // replaces the hv by a clone'd copy (%new_hv = { %hv })
+
+ shstr_tmp as_shstr () const;
+
+ // fetch something from the options hash
+ SV *get_sv (const char *option) const;
+ const_utf8_string get_str (const char *option, const_utf8_string fallback = "") const;
+ IV get_iv (const char *option, IV fallback = 0) const;
+ UV get_uv (const char *option, UV fallback = 0) const;
+ NV get_nv (const char *option, NV fallback = 0) const;
+
+ void set (const char *option, SV *value) const;
+ void set (const char *option, const_utf8_string value) const;
+ void set (const char *option, IV value) const;
+ void set (const char *option, UV value) const;
+ void set (const char *option, NV value) const;
+
+ void set (const char *option, int value) const { set (option, (IV)value); }
+
// "private", adjusted sizes
int Xsize;
int Ysize;
+
+ ~random_map_params ();
};
enum {
@@ -81,6 +96,7 @@
LAYOUT_ROGUELIKE,
LAYOUT_SNAKE,
LAYOUT_SQUARE_SPIRAL,
+ LAYOUT_CAVE,
NROFLAYOUTS,
};
@@ -126,61 +142,157 @@
// needs a minimum size of at least 12
#define MIN_RANDOM_MAP_SIZE 12
-struct MazeData : zero_initialised
+// we often use signed chars for coordinates (and U8 for distances)
+#define MAX_RANDOM_MAP_SIZE 120
+
+// reference
+//
+// \0 floor only
+// # wall
+// D door
+// < up
+// > down
+// C "center" (of onion layout)
+// . ?? (rogue)
+//
+
+// use this in new code
+struct Layout
{
char **col;
int w, h;
- MazeData (int w, int h);
- ~MazeData ();
+ Layout (int w, int h);
+ ~Layout ();
- operator char **()
+ operator char **() const
{
return col;
}
- void clear (char fill = 0);
+ void swap (Layout &layout)
+ {
+ ::swap (layout.col, col);
+ ::swap (layout.w , w );
+ ::swap (layout.h , h );
+ }
+
+ // for debugging, print layout to stdout
+ void print () const;
+
+ // simple inpainting
+ void fill (char fill);
+ void clear () { fill (0); }
void border (char fill = '#');
+ void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive
+
+ void fill_rand (int perc);
+
+ // makes sure all areas are connected. dirty=true carves rounder but also
+ // more walls, dirty=false carves narrow corridors.
+ void isolation_remover (bool dirty = 0);
+
+ // generates a cave, subtype 0 is a rough cave, randomly open or closed
+ void gen_cave (int subtype);
+
+ // helper functions to modify the layout
+ void erode_1_2 (int c1, int c2 = -1, int repeat = 1);
+ void doorify ();
+ void roomify (); // make some rooms in it, works best on onions
+ void expand2x ();
+ void symmetrize (int symmetry);
+ void rotate (int rotation); // rotate by 1=90, 2=180, 3=270 degrees
+
+ void generate (random_map_params *RP);
};
-struct Maze
+// utility functions, to use rmg_rndm instead of rndm.
+static inline int
+rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop)
+{
+ swap (rmg_rndm, rndm);
+ int i = find_free_spot (ob, m, x, y, start, stop);
+ swap (rmg_rndm, rndm);
+ return i;
+}
+
+// a simple point helper struct
+struct point
{
- MazeData *ptr;
+ short x;
+ short y;
- Maze ()
+ point ()
{
}
- Maze (int xsize, int ysize)
- : ptr (new MazeData (xsize, ysize))
+ point (int x, int y)
+ : x(x), y(y)
{
}
+};
+
+// something like a vector or stack, but without
+// out of bounds checking
+template
+struct fixed_stack
+{
+ T *data;
+ int size;
+ int max;
+
+ fixed_stack ()
+ : size (0), data (0)
+ {
+ }
+
+ fixed_stack (int max)
+ : size (0), max (max)
+ {
+ data = salloc (max);
+ }
- Maze (random_map_params *RP)
- : ptr (new MazeData (RP->Xsize, RP->Ysize))
+ void reset (int new_max)
{
+ sfree (data, max);
+ size = 0;
+ max = new_max;
+ data = salloc (max);
}
void free ()
{
- delete ptr;
+ sfree (data, max);
+ data = 0;
}
- MazeData *operator ->() const
+ ~fixed_stack ()
{
- return ptr;
+ sfree (data, max);
}
- operator char **() const
+ T &operator[](int idx)
{
- return *ptr;
+ return data [idx];
}
- void swap (Maze &maze)
+ void push (T v)
{
- MazeData *p = maze.ptr;
- maze.ptr = ptr;
- ptr = p;
+ data [size++] = v;
+ }
+
+ T &pop ()
+ {
+ return data [--size];
+ }
+
+ T remove (int idx)
+ {
+ T v = data [idx];
+
+ data [idx] = data [--size];
+
+ return v;
}
};