ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/decor.C
(Generate patch)

Comparing deliantra/server/random_maps/decor.C (file contents):
Revision 1.2 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.26 by root, Tue Apr 13 02:39:53 2010 UTC

1
2/* 1/*
3 * static char *rcsid_decor_ = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 * "$Id: decor.C,v 1.2 2006/09/10 16:06:37 root Exp $"; 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
5 */ 23 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28*/
29
30 24
31#include <global.h> 25#include <global.h>
32#include <random_map.h> 26#include <random_map.h>
33#include <rproto.h> 27#include <rproto.h>
34 28
35#define NR_DECOR_OPTIONS 1 29#define NR_DECOR_OPTIONS 1
36 30
37/* return a simple count of objects in the map at x,y. */ 31/* return a simple count of objects in the map at x,y. */
38 32
39int 33static int
40obj_count_in_map (mapstruct *map, int x, int y) 34obj_count_in_map (maptile *map, int x, int y)
41{ 35{
42 int count = 0; 36 int count = 0;
43 object *tmp;
44 37
45 for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) 38 for (object *tmp = map->at (x, y).bot; tmp; tmp = tmp->above)
46 count++; 39 ++count;
40
47 return count; 41 return count;
48} 42}
49 43
50/* put the decor into the map. Right now, it's very primitive. */ 44/* put the decor into the map. Right now, it's very primitive. */
51 45
52void 46void
53put_decor (mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms * RP) 47put_decor (maptile *map, char **maze, char *decorstyle, int decor_option, random_map_params *RP)
54{ 48{
55 mapstruct *decor_map; 49 maptile *decor_map = find_style ("/styles/decorstyles", decorstyle, RP->difficulty);
56 char style_name[256]; 50 if (!decor_map)
51 return;
57 52
58 sprintf (style_name, "/styles/decorstyles");
59
60 decor_map = find_style (style_name, decorstyle, -1);
61 if (decor_map == NULL)
62 return;
63 /* pick a random option, only 1 option right now. */ 53 /* pick a random option, only 1 option right now. */
64 if (decor_option == 0) 54 if (decor_option == 0)
65 decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; 55 decor_option = rmg_rndm (NR_DECOR_OPTIONS) + 1;
56
66 switch (decor_option) 57 switch (decor_option)
67 { 58 {
68 case 0: 59 case 0:
60 break;
61
62 case 1:
63 { /* random placement of decor objects. */
64 int number_to_place = rmg_rndm (RP->Xsize * RP->Ysize / 5);
65 int failures = 0;
66
67 while (failures < 100 && number_to_place > 0)
68 {
69 //coroapi::cede_to_tick ();
70
71 int x = rmg_rndm (RP->Xsize - 2) + 1;
72 int y = rmg_rndm (RP->Ysize - 2) + 1;
73
74 if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2)
75 {
76 object *this_object = decor_map->pick_random_object (rmg_rndm)->clone ();
77 /* it screws things up if decor can stop people */
78 this_object->move_block = 0;
79 map->insert (this_object, x, y, 0, 0);
80
81 number_to_place--;
82 }
83 else
84 failures++;
85 }
69 break; 86 break;
70 case 1: 87 }
71 { /* random placement of decor objects. */
72 int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5);
73 int failures = 0;
74 object *new_decor_object;
75 88
76 while (failures < 100 && number_to_place > 0) 89 default:
90 {
91 /* place decor objects everywhere: tile the map. */
92 for (int i = 1; i < RP->Xsize - 1; i++)
93 for (int j = 1; j < RP->Ysize - 1; j++)
77 { 94 {
78 int x, y; 95 if (maze[i][j] == 0)
96 {
97 object *this_object = decor_map->pick_random_object (rmg_rndm)->clone ();
79 98
80 x = RANDOM () % (RP->Xsize - 2) + 1;
81 y = RANDOM () % (RP->Ysize - 2) + 1;
82 if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2)
83 { /* empty */
84 object *this_object; 99 this_object->x = i;
100 this_object->y = j;
101 /* it screws things up if decor can stop people */
102 this_object->move_block = 0;
85 103
86 new_decor_object = pick_random_object (decor_map);
87 this_object = arch_to_object (new_decor_object->arch);
88 copy_object (new_decor_object, this_object);
89 this_object->x = x;
90 this_object->y = y;
91 /* it screws things up if decor can stop people */
92 this_object->move_block = MOVE_BLOCK_DEFAULT;
93 insert_ob_in_map (this_object, map, NULL, 0); 104 insert_ob_in_map (this_object, map, 0, 0);
94 number_to_place--;
95 } 105 }
96 else
97 failures++;
98 } 106 }
99 break;
100 }
101 default:
102 { /* place decor objects everywhere: tile the map. */
103 int i, j;
104 107
105 for (i = 1; i < RP->Xsize - 1; i++)
106 for (j = 1; j < RP->Ysize - 1; j++)
107 {
108 if (maze[i][j] == 0)
109 {
110 object *new_decor_object, *this_object;
111
112 new_decor_object = pick_random_object (decor_map);
113 this_object = arch_to_object (new_decor_object->arch);
114 copy_object (new_decor_object, this_object);
115 this_object->x = i;
116 this_object->y = j;
117 /* it screws things up if decor can stop people */
118 this_object->move_block = MOVE_BLOCK_DEFAULT;
119 insert_ob_in_map (this_object, map, NULL, 0);
120 }
121 }
122 break; 108 break;
123 } 109 }
124 } 110 }
125} 111}
112

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines