/* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 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. * * 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 */ #include #include #include /* place some monsters into the map. */ void place_monsters (maptile *map, char *monsterstyle, int difficulty, random_map_params *RP) { char styledirname[1024]; maptile *style_map = 0; int failed_placements; sint64 exp_per_sq, total_experience; int number_monsters = 0; archetype *at; sprintf (styledirname, "%s", "/styles/monsterstyles"); style_map = find_style (styledirname, monsterstyle, difficulty); if (!style_map) return; /* fill up the map with random monsters from the monster style */ total_experience = 0; failed_placements = 0; exp_per_sq = 0; while (exp_per_sq <= level_exp (difficulty, 1.0) && failed_placements < 100 && number_monsters < (RP->Xsize * RP->Ysize) / 8) { object *this_monster = style_map->pick_random_object (rmg_rndm); int x, y, freeindex; if (this_monster == NULL) return; /* no monster?? */ x = rmg_rndm (RP->Xsize); y = rmg_rndm (RP->Ysize); freeindex = find_first_free_spot (this_monster, map, x, y); if (freeindex != -1) { object *new_monster = this_monster->deep_clone (); x += freearr_x[freeindex]; y += freearr_y[freeindex]; map->insert (new_monster, x, y, 0, INS_NO_MERGE | INS_NO_WALK_ON); if (new_monster->is_alive ()) { total_experience += this_monster->stats.exp; for (at = new_monster->arch; at; at = (archetype *)at->more) number_monsters++; assert (new_monster->stats.hp >= 0); RP->total_map_hp += new_monster->stats.hp; /* a global count */ } else failed_placements++; } else failed_placements++; exp_per_sq = (sint64) (((double) 1000 * total_experience) / (map->width * map->height + 1)); } }