--- deliantra/server/random_maps/treasure.C 2007/08/26 15:31:04 1.31
+++ deliantra/server/random_maps/treasure.C 2008/05/02 21:01:53 1.37
@@ -1,11 +1,11 @@
/*
- * 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 (©) 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
*
- * Crossfire TRT is free software: you can redistribute it and/or modify
+ * 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.
@@ -18,7 +18,7 @@
* You should have received a copy of 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
*/
/* placing treasure in maps, where appropriate. */
@@ -120,7 +120,6 @@
/* all the treasure at one spot in the map. */
if (treasureoptions & CONCENTRATED)
{
-
/* map_layout_style global, and is previously set */
switch (RP->map_layout_style)
{
@@ -138,18 +137,20 @@
if (layout[i][j] == 'C' || layout[i][j] == '>')
{
int tdiv = RP->symmetry_used;
- object **doorlist;
object *chest;
if (tdiv == 3)
tdiv = 2; /* this symmetry uses a divisor of 2 */
+
/* don't put a chest on an exit. */
chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP);
+
if (!chest)
continue; /* if no chest was placed NEXT */
+
if (treasureoptions & (DOORED | HIDDEN))
{
- doorlist = find_doors_in_room (map, i, j, RP);
+ object **doorlist = find_doors_in_room (map, i, j, RP);
lock_and_hide_doors (doorlist, map, treasureoptions, RP);
free (doorlist);
}
@@ -158,6 +159,7 @@
}
break;
}
+
default:
{
int i, j, tries;
@@ -171,13 +173,18 @@
i = rndm (RP->Xsize - 2) + 1;
j = rndm (RP->Ysize - 2) + 1;
find_enclosed_spot (map, &i, &j, RP);
+
if (wall_blocked (map, i, j))
i = -1;
+
tries++;
}
+
chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP);
+
if (!chest)
return;
+
i = chest->x;
j = chest->y;
if (treasureoptions & (DOORED | HIDDEN))
@@ -205,7 +212,6 @@
/* put a chest into the map, near x and y, with the treasure style
determined (may be null, or may be a treasure list from lib/treasures,
if the global variable "treasurestyle" is set to that treasure list's name */
-
object *
place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP)
{
@@ -261,19 +267,18 @@
if (treasureoptions & TRAPPED)
{
maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1);
- object *the_trap;
if (trap_map)
{
- the_trap = trap_map->pick_random_object ();
+ object *the_trap = trap_map->pick_random_object ();
+
the_trap->stats.Cha = 10 + RP->difficulty;
the_trap->level = bc_random ((3 * RP->difficulty) / 2);
+
if (the_trap)
{
- object *new_trap;
+ object *new_trap = the_trap->arch->instance ();//TODO: why not clone?
- new_trap = arch_to_object (the_trap->arch);
- new_trap->copy_to (the_trap);
new_trap->x = x;
new_trap->y = y;
insert_ob_in_ob (new_trap, the_chest);
@@ -483,39 +488,29 @@
if (theMonsterToFind != NULL)
return theMonsterToFind;
}
+
return theMonsterToFind;
}
-
/* sets up some data structures: the _recursive form does the
real work. */
-
object *
find_monster_in_room (maptile *map, int x, int y, random_map_params *RP)
{
- char **layout2;
- int i, j;
+ Layout layout2 (RP);
+
+ layout2->clear ();
- theMonsterToFind = 0;
- layout2 = (char **) calloc (sizeof (char *), RP->Xsize);
/* allocate and copy the layout, converting C to 0. */
- for (i = 0; i < RP->Xsize; i++)
- {
- layout2[i] = (char *) calloc (sizeof (char), RP->Ysize);
- for (j = 0; j < RP->Ysize; j++)
- {
- if (wall_blocked (map, i, j))
- layout2[i][j] = '#';
- }
- }
+ for (int i = 0; i < layout2->w; i++)
+ for (int j = 0; j < layout2->h; j++)
+ if (wall_blocked (map, i, j))
+ layout2[i][j] = '#';
+
+ theMonsterToFind = 0;
theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP);
- /* deallocate the temp. layout */
- for (i = 0; i < RP->Xsize; i++)
- {
- free (layout2[i]);
- }
- free (layout2);
+ layout2.free ();
return theMonsterToFind;
}
@@ -748,7 +743,6 @@
return NULL;
}
-
/* the workhorse routine, which finds the doors in a room */
void
find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP)
@@ -772,6 +766,7 @@
if (door)
{
doorlist[*ndoors] = door;
+
if (*ndoors > 1022) /* eek! out of memory */
{
LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n");
@@ -797,41 +792,27 @@
object **
find_doors_in_room (maptile *map, int x, int y, random_map_params *RP)
{
- char **layout2;
- object **doorlist;
int i, j;
int ndoors = 0;
- doorlist = (object **) calloc (sizeof (int), 1024);
+ object **doorlist = (object **)calloc (sizeof (int), 1024);
+
+ LayoutData layout2 (RP->Xsize, RP->Ysize);
+ layout2.clear ();
- layout2 = (char **) calloc (sizeof (char *), RP->Xsize);
/* allocate and copy the layout, converting C to 0. */
for (i = 0; i < RP->Xsize; i++)
- {
- layout2[i] = (char *) calloc (sizeof (char), RP->Ysize);
- for (j = 0; j < RP->Ysize; j++)
- {
- if (wall_blocked (map, i, j))
- layout2[i][j] = '#';
- }
- }
+ for (j = 0; j < RP->Ysize; j++)
+ layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0;
/* setup num_free_spots and room_free_spots */
find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP);
- /* deallocate the temp. layout */
- for (i = 0; i < RP->Xsize; i++)
- free (layout2[i]);
-
- free (layout2);
return doorlist;
}
-
-
/* locks and/or hides all the doors in doorlist, or does nothing if
opts doesn't say to lock/hide doors. */
-
void
lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP)
{
@@ -876,9 +857,12 @@
retrofit_joined_wall (map, door->x + 1, door->y, 0, RP);
retrofit_joined_wall (map, door->x, door->y - 1, 0, RP);
retrofit_joined_wall (map, door->x, door->y + 1, 0, RP);
+
door->face = wallface->face;
+
if (!QUERY_FLAG (wallface, FLAG_REMOVED))
wallface->remove ();
+
wallface->destroy ();
}
}