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 |
#define NR_DECOR_OPTIONS 1 |
31 |
|
32 |
/* return a simple count of objects in the map at x,y. */ |
33 |
|
34 |
static int |
35 |
obj_count_in_map (maptile *map, int x, int y) |
36 |
{ |
37 |
int count = 0; |
38 |
|
39 |
for (object *tmp = map->at (x, y).bot; tmp; tmp = tmp->above) |
40 |
++count; |
41 |
|
42 |
return count; |
43 |
} |
44 |
|
45 |
/* put the decor into the map. Right now, it's very primitive. */ |
46 |
|
47 |
void |
48 |
put_decor (maptile *map, layout &maze, const char *decorstyle, int decor_option, random_map_params *RP) |
49 |
{ |
50 |
maptile *decor_map = find_style ("/styles/decorstyles", decorstyle, RP->difficulty); |
51 |
if (!decor_map) |
52 |
return; |
53 |
|
54 |
/* pick a random option, only 1 option right now. */ |
55 |
if (decor_option == 0) |
56 |
decor_option = rmg_rndm (NR_DECOR_OPTIONS) + 1; |
57 |
|
58 |
switch (decor_option) |
59 |
{ |
60 |
case 0: |
61 |
break; |
62 |
|
63 |
case 1: |
64 |
{ /* random placement of decor objects. */ |
65 |
int number_to_place = rmg_rndm (RP->Xsize * RP->Ysize / 5); |
66 |
int failures = 0; |
67 |
|
68 |
while (failures < 100 && number_to_place > 0) |
69 |
{ |
70 |
//coroapi::cede_to_tick (); |
71 |
|
72 |
int x = rmg_rndm (RP->Xsize - 2) + 1; |
73 |
int y = rmg_rndm (RP->Ysize - 2) + 1; |
74 |
|
75 |
if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
76 |
{ |
77 |
object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); |
78 |
/* it screws things up if decor can stop people */ |
79 |
this_object->move_block = 0; |
80 |
map->insert (this_object, x, y, 0, 0); |
81 |
|
82 |
number_to_place--; |
83 |
} |
84 |
else |
85 |
failures++; |
86 |
} |
87 |
break; |
88 |
} |
89 |
|
90 |
default: |
91 |
{ |
92 |
/* place decor objects everywhere: tile the map. */ |
93 |
for (int i = 1; i < RP->Xsize - 1; i++) |
94 |
for (int j = 1; j < RP->Ysize - 1; j++) |
95 |
{ |
96 |
if (maze[i][j] == 0) |
97 |
{ |
98 |
object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); |
99 |
|
100 |
this_object->x = i; |
101 |
this_object->y = j; |
102 |
/* it screws things up if decor can stop people */ |
103 |
this_object->move_block = 0; |
104 |
|
105 |
insert_ob_in_map (this_object, map, 0, 0); |
106 |
} |
107 |
} |
108 |
|
109 |
break; |
110 |
} |
111 |
} |
112 |
} |
113 |
|