ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/monster.C
Revision: 1.24
Committed: Sun May 4 14:12:37 2008 UTC (16 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_80, rel-2_6, rel-2_7, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_54, rel-2_55, rel-2_56, rel-2_79, rel-2_53, rel-2_78, rel-2_61
Changes since 1.23: +3 -3 lines
Log Message:
lotsa

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