--- deliantra/server/random_maps/special.C 2007/07/01 05:00:19 1.24
+++ deliantra/server/random_maps/special.C 2011/04/23 04:56:53 1.61
@@ -1,114 +1,98 @@
/*
- * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
- * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
- * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
- * Copyright (©) 1992,2007 Frank Tore Johansen
+ * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
+ * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
+ * Copyright (©) 1992 Frank Tore Johansen
*
- * Crossfire TRT 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
+ * The authors can be reached via e-mail to
*/
/* Specials in this file:
included maps */
#include
-#include
+#include
#include
-#define NUM_OF_SPECIAL_TYPES 4
-#define NO_SPECIAL 0
-#define SPECIAL_SUBMAP 1
-#define SPECIAL_FOUNTAIN 2
-#define SPECIAL_EXIT 3
-
-#define GLORY_HOLE 1
-#define ORC_ZONE 2
-#define MINING_ZONE 3
-#define NR_OF_HOLE_TYPES 3
-
-/* clear map completely of all objects: a rectangular area of xsize, ysize
-is cleared with the top left corner at xstart, ystart */
-
-void
-nuke_map_region (maptile *map, int xstart, int ystart, int xsize, int ysize)
+enum {
+ NO_SPECIAL,
+ SPECIAL_SUBMAP,
+ SPECIAL_FOUNTAIN,
+ SPECIAL_EXIT,
+ NUM_OF_SPECIAL_TYPES
+};
+
+enum {
+ GLORY_HOLE = 1,
+ ORC_ZONE,
+ MINING_ZONE,
+ NR_OF_HOLE_TYPES
+};
+
+/* clear map completely of all !floor objects:
+ * a rectangular area of xsize, ysize
+ * is cleared with the top left corner at xstart, ystart
+ */
+static void
+nuke_map_region (maptile *map, layout &maze, int xstart, int ystart, int xsize, int ysize)
{
- int i, j;
- object *tmp;
-
- for (i = xstart; i < xstart + xsize; i++)
- for (j = ystart; j < ystart + ysize; j++)
+ for (int i = xstart; i < xstart + xsize; i++)
+ for (int j = ystart; j < ystart + ysize; j++)
{
- for (tmp = GET_MAP_OB (map, i, j); tmp != NULL; tmp = tmp->above)
- {
- if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR))
- {
- if (tmp->head)
- tmp = tmp->head;
- tmp->remove ();
- tmp->destroy ();
- tmp = GET_MAP_OB (map, i, j);
- }
- if (tmp == NULL)
- break;
- }
+ maze[i][j] = 'S';
+
+ for (object *tmp = map->at (i, j).bot; tmp; )
+ if (tmp->flag [FLAG_IS_FLOOR])
+ tmp = tmp->above;
+ else
+ {
+ object *head = tmp->head_ ();
+ tmp = tmp->above;
+ head->destroy ();
+ }
}
}
-
-
/* copy in_map into dest_map at point x,y */
-
-
-void
+static void
include_map_in_map (maptile *dest_map, maptile *in_map, int x, int y)
{
- int i, j;
- object *tmp;
- object *new_ob;
+ for (int i = 0; i < in_map->width; i++)
+ for (int j = 0; j < in_map->height; j++)
+ for (object *tmp = GET_MAP_OB (in_map, i, j); tmp; tmp = tmp->above)
+ {
+ /* don't copy tails: must be dealt with specially. */
+ if (!tmp->is_head ())
+ continue;
- /* First, splatter everything in the dest map at the location */
- nuke_map_region (dest_map, x, y, in_map->width, in_map->height);
+ object *new_ob = tmp->deep_clone ();
- for (i = 0; i < in_map->width; i++)
- for (j = 0; j < in_map->height; j++)
- {
- for (tmp = GET_MAP_OB (in_map, i, j); tmp != NULL; tmp = tmp->above)
- {
- /* don't copy things with multiple squares: must be dealt with
- specially. */
- if (tmp->head != NULL)
- continue;
- new_ob = arch_to_object (tmp->arch);
- copy_object_with_inv (tmp, new_ob);
- if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
- add_button_link (new_ob, dest_map, tmp->path_attuned);
- new_ob->x = i + x;
- new_ob->y = j + y;
- insert_multisquare_ob_in_map (new_ob, dest_map);
- }
- }
+ if (tmp->flag [FLAG_IS_LINKED])
+ new_ob->add_link (dest_map, tmp->find_link ()->id);
+
+ dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON);
+ }
}
-int
-find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize)
+static int
+find_spot_for_submap (maptile *map, layout &maze, int *ix, int *iy, int xsize, int ysize)
{
- int tries;
- int i = 0, j = 0; /* initialization may not be needed but prevents compiler warnings */
- int is_occupied = 0;
- int l, m;
+ int blocked, i, j;
/* don't even try to place a submap into a map if the big map isn't
sufficiently large. */
@@ -116,45 +100,56 @@
return 0;
/* search a bit for a completely free spot. */
- for (tries = 0; tries < 20; tries++)
+ for (int tries = 0; tries < 20; tries++)
{
- /* pick a random location in the layout */
- i = rndm (map->width - xsize - 2) + 1;
- j = rndm (map->height - ysize - 2) + 1;
- is_occupied = 0;
- for (l = i; l < i + xsize; l++)
- for (m = j; m < j + ysize; m++)
- is_occupied |= layout[l][m];
- if (!is_occupied)
+ blocked = 0;
+
+ /* pick a random location in the maze */
+ i = rmg_rndm (1, map->width - xsize - 2);
+ j = rmg_rndm (1, map->height - ysize - 2);
+
+ for (int l = i; l < i + xsize; l++)
+ for (int m = j; m < j + ysize; m++)
+ {
+ blocked = 1;
+ break;
+ }
+
+ if (!blocked)
break;
}
-
/* if we failed, relax the restrictions */
-
- if (is_occupied)
+ if (blocked)
{ /* failure, try a relaxed placer. */
- /* pick a random location in the layout */
- for (tries = 0; tries < 10; tries++)
+ /* pick a random location in the maze */
+ for (int tries = 0; tries < 10; tries++)
{
- i = rndm (map->width - xsize - 2) + 1;
- j = rndm (map->height - ysize - 2) + 1;
- is_occupied = 0;
- for (l = i; l < i + xsize; l++)
- for (m = j; m < j + ysize; m++)
- if (layout[l][m] == 'C' || layout[l][m] == '>' || layout[l][m] == '<')
- is_occupied |= 1;
+ i = rmg_rndm (1, map->width - xsize - 2);
+ j = rmg_rndm (1, map->height - ysize - 2);
+
+ blocked = 0;
+
+ for (int l = i; l < i + xsize; l++)
+ for (int m = j; m < j + ysize; m++)
+ if (maze[l][m] != '#' && maze[l][m] != 'D' && maze[l][m] != 0)
+ {
+ blocked = 1;
+ break;
+ }
}
}
- if (is_occupied)
+
+ if (blocked)
return 0;
+
*ix = i;
*iy = j;
+
return 1;
}
-
-void
+static void
place_fountain_with_specials (maptile *map)
{
int ix, iy, i = -1, tries = 0;
@@ -166,16 +161,14 @@
return;
}
- object *fountain = get_archetype ("fountain");
- object *potion = object::create ();
-
- fountain_style->pick_random_object ()->copy_to (potion);
+ object *fountain = archetype::get (shstr_fountain);
+ object *potion = fountain_style->pick_random_object (rmg_rndm)->clone ();
while (i < 0 && tries < 10)
{
- ix = rndm (map->width - 2) + 1;
- iy = rndm (map->height - 2) + 1;
- i = find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1);
+ ix = rmg_rndm (map->width - 2) + 1;
+ iy = rmg_rndm (map->height - 2) + 1;
+ i = rmg_find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1);
tries++;
}
@@ -189,81 +182,80 @@
ix += freearr_x[i];
iy += freearr_y[i];
potion->face = fountain->face;
- SET_FLAG (potion, FLAG_NO_PICK);
- SET_FLAG (potion, FLAG_IDENTIFIED);
- potion->name = potion->name_pl = "fountain";
+ potion->set_flag (FLAG_NO_PICK);
+ potion->set_flag (FLAG_IDENTIFIED);
+ potion->name = potion->name_pl = shstr_fountain;
potion->x = ix;
potion->y = iy;
- potion->materialname = "adamantium";
+ potion->material = name_to_material (shstr_adamantium);
fountain->x = ix;
fountain->y = iy;
insert_ob_in_map (fountain, map, NULL, 0);
insert_ob_in_map (potion, map, NULL, 0);
}
-void
+static void
place_special_exit (maptile *map, int hole_type, random_map_params *RP)
{
- int ix, iy, i = -1;
- char buf[16384];
- const char *style, *decor, *mon;
- maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1);
- int g_xsize, g_ysize;
-
+ maptile *exit_style = find_style ("/styles/misc", "obscure_exits", RP->difficulty);
if (!exit_style)
{
- LOG (llevError, "unabel to load stylemap /styles/misc obscure_exits\n");
+ LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n");
return;
}
- object *the_exit = object::create ();
-
if (!exit_style)
return;
- exit_style->pick_random_object ()->copy_to (the_exit);
+ object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone ();
- while (i < 0)
+ // put an upper bound here, just in case
+ for (int repeat = 8192; --repeat; )
{
- ix = rndm (map->width - 2) + 1;
- iy = rndm (map->height - 2) + 1;
- i = find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1);
- }
+ int ix = rmg_rndm (1, map->width - 2);
+ int iy = rmg_rndm (1, map->height - 2);
- ix += freearr_x[i];
- iy += freearr_y[i];
- the_exit->x = ix;
- the_exit->y = iy;
+ int i = rmg_find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1);
+ if (i >= 0)
+ {
+ the_exit->x = ix + freearr_x[i];
+ the_exit->y = iy + freearr_y[i];
+ break;
+ }
+ }
if (!hole_type)
- hole_type = rndm (NR_OF_HOLE_TYPES) + 1;
+ hole_type = rmg_rndm (1, NR_OF_HOLE_TYPES - 1);
+
+ const char *style, *decor, *mon;
+ int g_xsize, g_ysize;
switch (hole_type)
{
case GLORY_HOLE: /* treasures */
{
- g_xsize = rndm (3) + 4 + RP->difficulty / 4;
- g_ysize = rndm (3) + 4 + RP->difficulty / 4;
+ g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4;
+ g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4;
style = "onion";
- decor = "wealth2";
+ decor = "special_wealth";
mon = "none";
break;
}
case ORC_ZONE: /* hole with orcs in it. */
{
- g_xsize = rndm (3) + 4 + RP->difficulty / 4;
- g_ysize = rndm (3) + 4 + RP->difficulty / 4;
+ g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4;
+ g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4;
style = "onion";
- decor = "wealth2";
+ decor = "special_wealth";
mon = "orc";
break;
}
case MINING_ZONE: /* hole with orcs in it. */
{
- g_xsize = rndm (9) + 4 + RP->difficulty / 4;
- g_ysize = rndm (9) + 4 + RP->difficulty / 4;
+ g_xsize = rmg_rndm (9) + 4 + RP->difficulty / 4;
+ g_ysize = rmg_rndm (9) + 4 + RP->difficulty / 4;
style = "maze";
decor = "minerals2";
mon = "none";
@@ -273,48 +265,75 @@
default: /* undefined */
LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type);
return;
- break;
}
/* Need to be at least this size, otherwise the load
* code will generate new size values which are too large.
*/
- if (g_xsize < MIN_RANDOM_MAP_SIZE)
- g_xsize = MIN_RANDOM_MAP_SIZE;
- if (g_ysize < MIN_RANDOM_MAP_SIZE)
- g_ysize = MIN_RANDOM_MAP_SIZE;
-
- write_parameters_to_string (buf, g_xsize, g_ysize, RP->wallstyle, RP->floorstyle, mon,
- "none", style, decor, "none", RP->exitstyle, 0, 0, 0,
- RMOPT_WALLS_ONLY, 0, 0, 1, RP->dungeon_level, RP->dungeon_level,
- RP->difficulty, RP->difficulty, -1, 1, 0, 0, 0, 0, RP->difficulty_increase);
- the_exit->slaying = "/!";
- the_exit->msg = buf;
+ max_it (g_xsize, MIN_RANDOM_MAP_SIZE);
+ max_it (g_ysize, MIN_RANDOM_MAP_SIZE);
+
+ dynbuf_text buf;
+
+ {
+ random_map_params &rp = *new random_map_params; // for zero_intiialised to work...
+
+ rp.hv = (HV *)newHV ();
+
+ rp.xsize = g_xsize;
+ rp.ysize = g_ysize;
+
+ rp.set ("wallstyle" , RP->get_str ("wallstyle" , 0));
+ rp.set ("floorstyle" , RP->get_str ("floorstyle", 0));
+ rp.set ("exitstyle" , RP->get_str ("exitstyle" , 0));
+ rp.set ("region" , RP->get_str ("region" , 0));
+ rp.set ("monsterstyle" , mon);
+ rp.set ("treasurestyle", "none");
+ rp.set ("layoutstyle" , style);
+ rp.set ("decorstyle" , decor);
+ rp.set ("decoroptions" , (IV)-1);
+ rp.set ("symmetry" , (IV)SYMMETRY_NONE);
+ rp.set ("orientation" , (IV)1);
+ rp.set ("random_seed" , RP->get_uv ("random_seed") + 0xdeadbeefU);
+
+ rp.layoutoptions1 = RMOPT_WALLS_ONLY;
+ rp.dungeon_depth = RP->dungeon_level;
+ rp.dungeon_level = RP->dungeon_level;
+ rp.difficulty = RP->difficulty;
+ rp.difficulty_given = RP->difficulty;
+ rp.difficulty_increase = RP->difficulty_increase;
+
+ the_exit->slaying = shstr_random_map_exit;
+ the_exit->msg = rp.as_shstr ();
+
+ delete &rp;
+ }
insert_ob_in_map (the_exit, map, NULL, 0);
}
-
void
-place_specials_in_map (maptile *map, char **layout, random_map_params *RP)
+place_specials_in_map (maptile *map, layout &maze, random_map_params *RP)
{
- maptile *special_map;
- int ix, iy; /* map insertion locatons */
- int special_type; /* type of special to make */
-
- special_type = rndm (NUM_OF_SPECIAL_TYPES);
-
- switch (special_type)
+ switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) // can be NO_SPECIAL as well
{
case SPECIAL_SUBMAP:
- /* includes a special map into the random map being made. */
- special_map = find_style ("/styles/specialmaps", 0, RP->difficulty);
+ {
+ /* includes a special map into the random map being made. */
+ maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty, true);
- if (!special_map)
- return;
+ if (!special_map)
+ break;
- if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height))
- include_map_in_map (map, special_map, ix, iy);
+ int ix, iy; /* map insertion locatons */
+
+ if (find_spot_for_submap (map, maze, &ix, &iy, special_map->width, special_map->height))
+ {
+ /* First, splatter everything in the dest map at the location */
+ nuke_map_region (map, maze, ix, iy, special_map->width, special_map->height);
+ include_map_in_map (map, special_map, ix, iy);
+ }
+ }
break;
@@ -329,5 +348,5 @@
place_special_exit (map, 0, RP);
break;
}
-
}
+