ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/monster.C
Revision: 1.36
Committed: Sat Nov 17 23:40:02 2018 UTC (5 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.35: +1 -0 lines
Log Message:
copyright update 2018

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7 * Copyright (©) 1992 Frank Tore Johansen
8 *
9 * Deliantra is free software: you can redistribute it and/or modify it under
10 * the terms of the Affero GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the Affero GNU General Public License
20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * The authors can be reached via e-mail to <support@deliantra.net>
24 */
25
26 #include <global.h>
27 #include <rmg.h>
28 #include <rproto.h>
29
30 /* place some monsters into the map. */
31 void
32 place_monsters (maptile *map, const char *monsterstyle, int difficulty, random_map_params *RP)
33 {
34 int failed_placements;
35 sint64 exp_per_sq, total_experience;
36 int number_monsters = 0;
37 archetype *at;
38
39 maptile *style_map = find_style ("/styles/monsterstyles", monsterstyle, difficulty);
40 if (!style_map)
41 return;
42
43 /* fill up the map with random monsters from the monster style */
44
45 total_experience = 0;
46 failed_placements = 0;
47 exp_per_sq = 0;
48 while (exp_per_sq <= level_exp (difficulty, 1.0) && failed_placements < 100 && number_monsters < (RP->Xsize * RP->Ysize) / 8)
49 {
50 object *this_monster = style_map->pick_random_object (rmg_rndm);
51 int x, y, freeindex;
52
53 if (this_monster == NULL)
54 return; /* no monster?? */
55
56 x = rmg_rndm (RP->Xsize);
57 y = rmg_rndm (RP->Ysize);
58 freeindex = find_first_free_spot (this_monster, map, x, y);
59 if (freeindex != -1)
60 {
61 object *new_monster = this_monster->deep_clone ();
62 x += DIRX (freeindex);
63 y += DIRY (freeindex);
64 map->insert (new_monster, x, y, 0, INS_NO_MERGE | INS_NO_WALK_ON);
65
66 if (new_monster->is_alive ())
67 {
68 total_experience += this_monster->stats.exp;
69
70 for (at = new_monster->arch; at; at = (archetype *)at->more)
71 number_monsters++;
72
73 assert (new_monster->stats.hp >= 0);
74 RP->total_map_hp += new_monster->stats.hp; /* a global count */
75 }
76 else
77 failed_placements++;
78 }
79 else
80 failed_placements++;
81
82 exp_per_sq = (sint64) (((double) 1000 * total_experience) / (map->width * map->height + 1));
83 }
84 }