/* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * * 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 * * 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 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 */ #include #include #include #define NR_DECOR_OPTIONS 1 /* return a simple count of objects in the map at x,y. */ static int obj_count_in_map (maptile *map, int x, int y) { int count = 0; for (object *tmp = map->at (x, y).bot; tmp; tmp = tmp->above) ++count; return count; } /* put the decor into the map. Right now, it's very primitive. */ void put_decor (maptile *map, layout &maze, const char *decorstyle, int decor_option, random_map_params *RP) { maptile *decor_map = find_style ("/styles/decorstyles", decorstyle, RP->difficulty); if (!decor_map) return; /* pick a random option, only 1 option right now. */ if (decor_option == 0) decor_option = rmg_rndm (NR_DECOR_OPTIONS) + 1; switch (decor_option) { case 0: break; case 1: { /* random placement of decor objects. */ int number_to_place = rmg_rndm (RP->Xsize * RP->Ysize / 5); int failures = 0; while (failures < 100 && number_to_place > 0) { //coroapi::cede_to_tick (); int x = rmg_rndm (RP->Xsize - 2) + 1; int y = rmg_rndm (RP->Ysize - 2) + 1; if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) { object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); /* it screws things up if decor can stop people */ this_object->move_block = 0; map->insert (this_object, x, y, 0, 0); number_to_place--; } else failures++; } break; } default: { /* place decor objects everywhere: tile the map. */ for (int i = 1; i < RP->Xsize - 1; i++) for (int j = 1; j < RP->Ysize - 1; j++) { if (maze[i][j] == 0) { object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); this_object->x = i; this_object->y = j; /* it screws things up if decor can stop people */ this_object->move_block = 0; insert_ob_in_map (this_object, map, 0, 0); } } break; } } }