--- deliantra/server/random_maps/treasure.C 2006/09/14 21:16:12 1.5
+++ deliantra/server/random_maps/treasure.C 2007/08/26 15:31:04 1.31
@@ -1,36 +1,28 @@
-
/*
- * static char *rcsid_treasure_c =
- * "$Id: treasure.C,v 1.5 2006/09/14 21:16:12 root Exp $";
+ * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
+ *
+ * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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
+ * 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.
+ *
+ * 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 .
+ *
+ * The authors can be reached via e-mail to
*/
-/*
- CrossFire, A Multiplayer game for X-windows
-
- Copyright (C) 2001 Mark Wedel & Crossfire Development Team
- Copyright (C) 1992 Frank Tore Johansen
-
- This program 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- The authors can be reached via e-mail at crossfire-devel@real-time.com
-*/
-
/* placing treasure in maps, where appropriate. */
-
-
#include
#include
#include
@@ -50,21 +42,26 @@
#define NO_PASS_DOORS 0
#define PASS_DOORS 1
+/* a macro to get a strongly centered random distribution,
+ from 0 to x, centered at x/2 */
+static int
+bc_random (int x)
+{
+ return (rndm (x) + rndm (x) + rndm (x)) / 3;
+}
/* returns true if square x,y has P_NO_PASS set, which is true for walls
* and doors but not monsters.
* This function is not map tile aware.
*/
-
int
-wall_blocked (mapstruct *m, int x, int y)
+wall_blocked (maptile *m, int x, int y)
{
- int r;
-
if (OUT_OF_REAL_MAP (m, x, y))
return 1;
- r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT;
- return r;
+
+ m->at (x, y).update ();
+ return GET_MAP_MOVE_BLOCK (m, x, y) & MOVE_WALK;
}
/* place treasures in the map, given the
@@ -73,26 +70,26 @@
treasure style (may be empty or NULL, or "none" to cause no treasure.)
treasureoptions (may be 0 for random choices or positive)
*/
-
void
-place_treasure (mapstruct *map, char **layout, char *treasure_style, int treasureoptions, RMParms * RP)
+place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP)
{
- char styledirname[256];
- char stylefilepath[256];
- mapstruct *style_map = 0;
+ char styledirname[1024];
+ char stylefilepath[1024];
+ maptile *style_map = 0;
int num_treasures;
/* bail out if treasure isn't wanted. */
if (treasure_style)
if (!strcmp (treasure_style, "none"))
return;
+
if (treasureoptions <= 0)
- treasureoptions = RANDOM () % (2 * LAST_OPTION);
+ treasureoptions = rndm (2 * LAST_OPTION);
/* filter out the mutually exclusive options */
if ((treasureoptions & RICH) && (treasureoptions & SPARSE))
{
- if (RANDOM () % 2)
+ if (rndm (2))
treasureoptions -= 1;
else
treasureoptions -= 2;
@@ -100,11 +97,11 @@
/* pick the number of treasures */
if (treasureoptions & SPARSE)
- num_treasures = BC_RANDOM (RP->total_map_hp / 600 + RP->difficulty / 2 + 1);
+ num_treasures = bc_random (RP->total_map_hp / 600 + RP->difficulty / 2 + 1);
else if (treasureoptions & RICH)
- num_treasures = BC_RANDOM (RP->total_map_hp / 150 + 2 * RP->difficulty + 1);
+ num_treasures = bc_random (RP->total_map_hp / 150 + 2 * RP->difficulty + 1);
else
- num_treasures = BC_RANDOM (RP->total_map_hp / 300 + RP->difficulty + 1);
+ num_treasures = bc_random (RP->total_map_hp / 300 + RP->difficulty + 1);
if (num_treasures <= 0)
return;
@@ -114,6 +111,12 @@
sprintf (stylefilepath, "%s/%s", styledirname, treasure_style);
style_map = find_style (styledirname, treasure_style, -1);
+ if (!style_map)
+ {
+ LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style);
+ return;
+ }
+
/* all the treasure at one spot in the map. */
if (treasureoptions & CONCENTRATED)
{
@@ -121,69 +124,69 @@
/* map_layout_style global, and is previously set */
switch (RP->map_layout_style)
{
- case ONION_LAYOUT:
- case SPIRAL_LAYOUT:
- case SQUARE_SPIRAL_LAYOUT:
- {
- int i, j;
-
- /* search the onion for C's or '>', and put treasure there. */
- for (i = 0; i < RP->Xsize; i++)
- {
- for (j = 0; j < RP->Ysize; j++)
- {
- 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);
- lock_and_hide_doors (doorlist, map, treasureoptions, RP);
- free (doorlist);
- }
- }
- }
- }
- break;
- }
- default:
- {
- int i, j, tries;
- object *chest;
- object **doorlist;
-
- i = j = -1;
- tries = 0;
- while (i == -1 && tries < 100)
- {
- i = RANDOM () % (RP->Xsize - 2) + 1;
- j = RANDOM () % (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))
- {
- doorlist = surround_by_doors (map, layout, i, j, treasureoptions);
- lock_and_hide_doors (doorlist, map, treasureoptions, RP);
- free (doorlist);
- }
- }
+ case LAYOUT_ONION:
+ case LAYOUT_SPIRAL:
+ case LAYOUT_SQUARE_SPIRAL:
+ {
+ int i, j;
+
+ /* search the onion for C's or '>', and put treasure there. */
+ for (i = 0; i < RP->Xsize; i++)
+ {
+ for (j = 0; j < RP->Ysize; j++)
+ {
+ 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);
+ lock_and_hide_doors (doorlist, map, treasureoptions, RP);
+ free (doorlist);
+ }
+ }
+ }
+ }
+ break;
+ }
+ default:
+ {
+ int i, j, tries;
+ object *chest;
+ object **doorlist;
+
+ i = j = -1;
+ tries = 0;
+ while (i == -1 && tries < 100)
+ {
+ 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))
+ {
+ doorlist = surround_by_doors (map, layout, i, j, treasureoptions);
+ lock_and_hide_doors (doorlist, map, treasureoptions, RP);
+ free (doorlist);
+ }
+ }
}
}
else
@@ -192,21 +195,19 @@
for (ti = 0; ti < num_treasures; ti++)
{
- i = RANDOM () % (RP->Xsize - 2) + 1;
- j = RANDOM () % (RP->Ysize - 2) + 1;
+ i = rndm (RP->Xsize - 2) + 1;
+ j = rndm (RP->Ysize - 2) + 1;
place_chest (treasureoptions, i, j, map, style_map, 1, RP);
}
}
}
-
-
/* 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, mapstruct *map, mapstruct *style_map, int n_treasures, RMParms * RP)
+place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP)
{
object *the_chest;
int i, xl, yl;
@@ -217,9 +218,10 @@
i = find_first_free_spot (the_chest, map, x, y);
if (i == -1)
{
- free_object (the_chest);
+ the_chest->destroy ();
return NULL;
}
+
xl = x + freearr_x[i];
yl = y + freearr_y[i];
@@ -227,7 +229,6 @@
if (wall_blocked (map, xl, yl))
return 0;
-
/* put the treasures in the chest. */
/* if(style_map) { */
#if 0 /* don't use treasure style maps for now! */
@@ -239,7 +240,7 @@
if (tlist != NULL)
for (ti = 0; ti < n_treasures; ti++)
{ /* use the treasure list */
- object *new_treasure = pick_random_object (style_map);
+ object *new_treasure = style_map->pick_random_object ();
insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest);
}
@@ -249,9 +250,8 @@
the_chest->stats.hp = n_treasures;
}
#endif
- else
{ /* neither style_map no treasure list given */
- treasurelist *tlist = find_treasurelist ("chest");
+ treasurelist *tlist = treasurelist::find ("chest");
the_chest->randomitems = tlist;
the_chest->stats.hp = n_treasures;
@@ -260,20 +260,20 @@
/* stick a trap in the chest if required */
if (treasureoptions & TRAPPED)
{
- mapstruct *trap_map = find_style ("/styles/trapstyles", "traps", -1);
+ maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1);
object *the_trap;
if (trap_map)
{
- the_trap = pick_random_object (trap_map);
+ the_trap = trap_map->pick_random_object ();
the_trap->stats.Cha = 10 + RP->difficulty;
- the_trap->level = BC_RANDOM ((3 * RP->difficulty) / 2);
+ the_trap->level = bc_random ((3 * RP->difficulty) / 2);
if (the_trap)
{
object *new_trap;
new_trap = arch_to_object (the_trap->arch);
- copy_object (new_trap, the_trap);
+ new_trap->copy_to (the_trap);
new_trap->x = x;
new_trap->y = y;
insert_ob_in_ob (new_trap, the_chest);
@@ -284,12 +284,11 @@
/* set the chest lock code, and call the keyplacer routine with
the lockcode. It's not worth bothering to lock the chest if
there's only 1 treasure.... */
-
if ((treasureoptions & KEYREQUIRED) && n_treasures > 1)
{
- char keybuf[256];
+ char keybuf[1024];
- sprintf (keybuf, "%d", (int) RANDOM ());
+ sprintf (keybuf, "%d", rndm (1000000000));
the_chest->slaying = keybuf;
keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP);
}
@@ -305,7 +304,7 @@
/* finds the closest monster and returns him, regardless of doors
or walls */
object *
-find_closest_monster (mapstruct *map, int x, int y, RMParms * RP)
+find_closest_monster (maptile *map, int x, int y, random_map_params *RP)
{
int i;
@@ -320,7 +319,7 @@
/* don't bother searching this square unless the map says life exists. */
if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE)
{
- object *the_monster = get_map_ob (map, lx, ly);
+ object *the_monster = GET_MAP_OB (map, lx, ly);
for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_MONSTER)); the_monster = the_monster->above);
if (the_monster && QUERY_FLAG (the_monster, FLAG_MONSTER))
@@ -342,12 +341,11 @@
The idea is that you call keyplace on x,y where a door is, and it'll make
sure a key is placed on both sides of the door.
*/
-
int
-keyplace (mapstruct *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms * RP)
+keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP)
{
int i, j;
- int kx, ky;
+ int kx = 0, ky = 0;
object *the_keymaster; /* the monster that gets the key. */
object *the_key;
@@ -359,30 +357,33 @@
{
int tries = 0;
- the_keymaster = NULL;
- while (tries < 15 && the_keymaster == NULL)
+ the_keymaster = 0;
+ while (tries < 15 && !the_keymaster)
{
- i = (RANDOM () % (RP->Xsize - 2)) + 1;
- j = (RANDOM () % (RP->Ysize - 2)) + 1;
+ i = rndm (RP->Xsize - 2) + 1;
+ j = rndm (RP->Ysize - 2) + 1;
tries++;
the_keymaster = find_closest_monster (map, i, j, RP);
}
+
/* if we don't find a good keymaster, drop the key on the ground. */
- if (the_keymaster == NULL)
+ if (!the_keymaster)
{
int freeindex;
freeindex = -1;
for (tries = 0; tries < 15 && freeindex == -1; tries++)
{
- kx = (RANDOM () % (RP->Xsize - 2)) + 1;
- ky = (RANDOM () % (RP->Ysize - 2)) + 1;
- freeindex = find_first_free_spot (the_key, map, kx, ky);
+ kx = rndm (RP->Xsize - 2) + 1;
+ ky = rndm (RP->Ysize - 2) + 1;
+ freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1);
}
- if (freeindex != -1)
+
+ // can freeindex ever be < 0?
+ if (freeindex >= 0)
{
- kx += freearr_x[freeindex];
- ky += freearr_y[freeindex];
+ kx += freearr_x [freeindex];
+ ky += freearr_y [freeindex];
}
}
}
@@ -394,8 +395,9 @@
{
if (wall_blocked (map, x, y))
return 0;
+
the_keymaster = find_monster_in_room (map, x, y, RP);
- if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */
+ if (!the_keymaster) /* if fail, find a spot to drop the key. */
find_spot_in_room (map, x, y, &kx, &ky, RP);
}
else
@@ -407,18 +409,20 @@
sum += keyplace (map, x, y + 1, keycode, NO_PASS_DOORS, 1, RP);
sum += keyplace (map, x - 1, y, keycode, NO_PASS_DOORS, 1, RP);
sum += keyplace (map, x, y - 1, keycode, NO_PASS_DOORS, 1, RP);
+
if (sum < 2) /* we might have made a disconnected map-place more keys. */
- { /* diagnoally this time. */
+ { /* diagonally this time. */
keyplace (map, x + 1, y + 1, keycode, NO_PASS_DOORS, 1, RP);
keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP);
keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP);
keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP);
}
+
return 1;
}
}
- if (the_keymaster == NULL)
+ if (!the_keymaster)
{
the_key->x = kx;
the_key->y = ky;
@@ -426,7 +430,7 @@
return 1;
}
- insert_ob_in_ob (the_key, the_keymaster);
+ insert_ob_in_ob (the_key, the_keymaster->head_ ());
return 1;
}
@@ -440,7 +444,7 @@
it does a check-off on the layout, converting 0's to 1's */
object *
-find_monster_in_room_recursive (char **layout, mapstruct *map, int x, int y, RMParms * RP)
+find_monster_in_room_recursive (char **layout, maptile *map, int x, int y, random_map_params *RP)
{
int i, j;
@@ -461,7 +465,7 @@
layout[x][y] = 1;
if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE)
{
- object *the_monster = get_map_ob (map, x, y);
+ object *the_monster = GET_MAP_OB (map, x, y);
/* check off this point */
for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_ALIVE)); the_monster = the_monster->above);
@@ -473,7 +477,7 @@
}
/* now search all the 8 squares around recursively for a monster,in random order */
- for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++)
+ for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++)
{
theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP);
if (theMonsterToFind != NULL)
@@ -487,7 +491,7 @@
real work. */
object *
-find_monster_in_room (mapstruct *map, int x, int y, RMParms * RP)
+find_monster_in_room (maptile *map, int x, int y, random_map_params *RP)
{
char **layout2;
int i, j;
@@ -516,9 +520,6 @@
return theMonsterToFind;
}
-
-
-
/* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */
int *room_free_spots_x;
int *room_free_spots_y;
@@ -527,9 +528,8 @@
/* the workhorse routine, which finds the free spots in a room:
a datastructure of free points is set up, and a position chosen from
that datastructure. */
-
void
-find_spot_in_room_recursive (char **layout, int x, int y, RMParms * RP)
+find_spot_in_room_recursive (char **layout, int x, int y, random_map_params *RP)
{
int i, j;
@@ -548,17 +548,16 @@
room_free_spots_x[number_of_free_spots_in_room] = x;
room_free_spots_y[number_of_free_spots_in_room] = y;
number_of_free_spots_in_room++;
+
/* now search all the 8 squares around recursively for free spots,in random order */
- for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++)
- {
- find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP);
- }
+ for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++)
+ find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP);
}
/* find a random non-blocked spot in this room to drop a key. */
void
-find_spot_in_room (mapstruct *map, int x, int y, int *kx, int *ky, RMParms * RP)
+find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, random_map_params *RP)
{
char **layout2;
int i, j;
@@ -573,10 +572,8 @@
{
layout2[i] = (char *) calloc (sizeof (char), RP->Ysize);
for (j = 0; j < RP->Ysize; j++)
- {
- if (wall_blocked (map, i, j))
- layout2[i][j] = '#';
- }
+ if (wall_blocked (map, i, j))
+ layout2[i][j] = '#';
}
/* setup num_free_spots and room_free_spots */
@@ -584,16 +581,15 @@
if (number_of_free_spots_in_room > 0)
{
- i = RANDOM () % number_of_free_spots_in_room;
+ i = rndm (number_of_free_spots_in_room);
*kx = room_free_spots_x[i];
*ky = room_free_spots_y[i];
}
/* deallocate the temp. layout */
for (i = 0; i < RP->Xsize; i++)
- {
- free (layout2[i]);
- }
+ free (layout2[i]);
+
free (layout2);
free (room_free_spots_x);
free (room_free_spots_y);
@@ -603,9 +599,8 @@
/* searches the map for a spot with walls around it. The more
walls the better, but it'll settle for 1 wall, or even 0, but
it'll return 0 if no FREE spots are found.*/
-
void
-find_enclosed_spot (mapstruct *map, int *cx, int *cy, RMParms * RP)
+find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params *RP)
{
int x, y;
int i;
@@ -664,46 +659,47 @@
}
}
/* give up and return the closest free spot. */
- i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y);
- if (i != -1 && i <= SIZEOFFREE1)
+ i = find_free_spot (archetype::find ("chest"), map, x, y, 1, SIZEOFFREE1 + 1);
+
+ if (i != -1)
{
*cx = x + freearr_x[i];
*cy = y + freearr_y[i];
- return;
}
- /* indicate failure */
- *cx = *cy = -1;
+ else
+ {
+ /* indicate failure */
+ *cx = -1;
+ *cy = -1;
+ }
}
-
void
-remove_monsters (int x, int y, mapstruct *map)
+remove_monsters (int x, int y, maptile *map)
{
object *tmp;
- for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above)
+ for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above)
if (QUERY_FLAG (tmp, FLAG_ALIVE))
{
if (tmp->head)
tmp = tmp->head;
- remove_ob (tmp);
- free_object (tmp);
- tmp = get_map_ob (map, x, y);
+ tmp->remove ();
+ tmp->destroy ();
+ tmp = GET_MAP_OB (map, x, y);
if (tmp == NULL)
break;
};
}
-
/* surrounds the point x,y by doors, so as to enclose something, like
a chest. It only goes as far as the 8 squares surrounding, and
it'll remove any monsters it finds.*/
-
object **
-surround_by_doors (mapstruct *map, char **layout, int x, int y, int opts)
+surround_by_doors (maptile *map, char **layout, int x, int y, int opts)
{
int i;
- char *doors[2];
+ const char *doors[2];
object **doorlist;
int ndoors_made = 0;
doorlist = (object **) calloc (9, sizeof (object *)); /* 9 doors so we can hold termination null */
@@ -725,29 +721,28 @@
{
int x1 = x + freearr_x[i], y1 = y + freearr_y[i];
- if (!wall_blocked (map, x1, y1) || layout[x1][y1] == '>')
+ if (!wall_blocked (map, x1, y1) && layout[x1][y1] == '>')
{ /* place a door */
- object *new_door = get_archetype ((freearr_x[i] == 0) ? doors[1] : doors[0]);
+ remove_monsters (x1, y1, map);
- new_door->x = x + freearr_x[i];
- new_door->y = y + freearr_y[i];
- remove_monsters (new_door->x, new_door->y, map);
- insert_ob_in_map (new_door, map, NULL, 0);
+ object *new_door = get_archetype (freearr_x[i] == 0 ? doors[1] : doors[0]);
+ map->insert (new_door, x1, y1);
doorlist[ndoors_made] = new_door;
ndoors_made++;
}
}
+
return doorlist;
}
/* returns the first door in this square, or NULL if there isn't a door. */
object *
-door_in_square (mapstruct *map, int x, int y)
+door_in_square (maptile *map, int x, int y)
{
object *tmp;
- for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above)
+ for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above)
if (tmp->type == DOOR || tmp->type == LOCKED_DOOR)
return tmp;
return NULL;
@@ -756,7 +751,7 @@
/* the workhorse routine, which finds the doors in a room */
void
-find_doors_in_room_recursive (char **layout, mapstruct *map, int x, int y, object **doorlist, int *ndoors, RMParms * RP)
+find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP)
{
int i, j;
object *door;
@@ -774,39 +769,40 @@
{ /* there could be a door here */
layout[x][y] = 1;
door = door_in_square (map, x, y);
- if (door != NULL)
+ if (door)
{
doorlist[*ndoors] = door;
- if (*ndoors > 254) /* eek! out of memory */
+ if (*ndoors > 1022) /* eek! out of memory */
{
LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n");
return;
}
+
*ndoors = *ndoors + 1;
}
}
else
{
layout[x][y] = 1;
+
/* now search all the 8 squares around recursively for free spots,in random order */
- for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++)
- {
- find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP);
- }
+ for (i = rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++)
+ find_doors_in_room_recursive (layout, map,
+ x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1],
+ doorlist, ndoors, RP);
}
}
/* find a random non-blocked spot in this room to drop a key. */
object **
-find_doors_in_room (mapstruct *map, int x, int y, RMParms * RP)
+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), 256);
-
+ doorlist = (object **) calloc (sizeof (int), 1024);
layout2 = (char **) calloc (sizeof (char *), RP->Xsize);
/* allocate and copy the layout, converting C to 0. */
@@ -825,9 +821,8 @@
/* deallocate the temp. layout */
for (i = 0; i < RP->Xsize; i++)
- {
- free (layout2[i]);
- }
+ free (layout2[i]);
+
free (layout2);
return doorlist;
}
@@ -838,7 +833,7 @@
opts doesn't say to lock/hide doors. */
void
-lock_and_hide_doors (object **doorlist, mapstruct *map, int opts, RMParms * RP)
+lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP)
{
object *door;
int i;
@@ -850,17 +845,17 @@
for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++)
{
object *new_door = get_archetype ("locked_door1");
- char keybuf[256];
+ char keybuf[1024];
door = doorlist[i];
new_door->face = door->face;
new_door->x = door->x;
new_door->y = door->y;
- remove_ob (door);
- free_object (door);
+ door->remove ();
+ door->destroy ();
doorlist[i] = new_door;
insert_ob_in_map (new_door, map, NULL, 0);
- sprintf (keybuf, "%d", (int) RANDOM ());
+ sprintf (keybuf, "%d", rndm (1000000000));
new_door->slaying = keybuf;
keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP);
}
@@ -883,8 +878,8 @@
retrofit_joined_wall (map, door->x, door->y + 1, 0, RP);
door->face = wallface->face;
if (!QUERY_FLAG (wallface, FLAG_REMOVED))
- remove_ob (wallface);
- free_object (wallface);
+ wallface->remove ();
+ wallface->destroy ();
}
}
}