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, 6 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

# User Rev Content
1 elmex 1.1 /*
2 root 1.20 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.33 *
4 root 1.36 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 root 1.34 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 root 1.26 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7     * Copyright (©) 1992 Frank Tore Johansen
8 root 1.33 *
9 root 1.25 * 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 root 1.33 *
14 root 1.12 * This program is distributed in the hope that it will be useful,
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 root 1.19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 root 1.12 * GNU General Public License for more details.
18 root 1.33 *
19 root 1.25 * 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 root 1.33 *
23 root 1.20 * The authors can be reached via e-mail to <support@deliantra.net>
24 root 1.12 */
25 elmex 1.1
26     #include <global.h>
27 root 1.30 #include <rmg.h>
28 elmex 1.1 #include <rproto.h>
29    
30     /* place some monsters into the map. */
31 root 1.3 void
32 root 1.29 place_monsters (maptile *map, const char *monsterstyle, int difficulty, random_map_params *RP)
33 root 1.3 {
34 elmex 1.1 int failed_placements;
35     sint64 exp_per_sq, total_experience;
36 root 1.3 int number_monsters = 0;
37 elmex 1.1 archetype *at;
38    
39 root 1.28 maptile *style_map = find_style ("/styles/monsterstyles", monsterstyle, difficulty);
40 root 1.13 if (!style_map)
41 root 1.3 return;
42 elmex 1.1
43 root 1.3 /* fill up the map with random monsters from the monster style */
44 elmex 1.1
45     total_experience = 0;
46     failed_placements = 0;
47     exp_per_sq = 0;
48 root 1.3 while (exp_per_sq <= level_exp (difficulty, 1.0) && failed_placements < 100 && number_monsters < (RP->Xsize * RP->Ysize) / 8)
49     {
50 root 1.24 object *this_monster = style_map->pick_random_object (rmg_rndm);
51 root 1.3 int x, y, freeindex;
52    
53     if (this_monster == NULL)
54     return; /* no monster?? */
55 root 1.12
56 root 1.24 x = rmg_rndm (RP->Xsize);
57     y = rmg_rndm (RP->Ysize);
58 root 1.3 freeindex = find_first_free_spot (this_monster, map, x, y);
59     if (freeindex != -1)
60     {
61 root 1.23 object *new_monster = this_monster->deep_clone ();
62 root 1.35 x += DIRX (freeindex);
63     y += DIRY (freeindex);
64 root 1.23 map->insert (new_monster, x, y, 0, INS_NO_MERGE | INS_NO_WALK_ON);
65 root 1.12
66 root 1.15 if (new_monster->is_alive ())
67     {
68     total_experience += this_monster->stats.exp;
69 root 1.12
70 root 1.18 for (at = new_monster->arch; at; at = (archetype *)at->more)
71 root 1.15 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 root 1.3 }
79     else
80 root 1.8 failed_placements++;
81    
82 root 1.6 exp_per_sq = (sint64) (((double) 1000 * total_experience) / (map->width * map->height + 1));
83 elmex 1.1 }
84     }