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.18 by root, Fri Apr 11 21:09:53 2008 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your 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 GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <support@deliantra.net>
5 */ 22 */
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 23
31#include <global.h> 24#include <global.h>
32#include <random_map.h> 25#include <random_map.h>
33#include <rproto.h> 26#include <rproto.h>
34 27
35#define NR_DECOR_OPTIONS 1 28#define NR_DECOR_OPTIONS 1
36 29
37/* return a simple count of objects in the map at x,y. */ 30/* return a simple count of objects in the map at x,y. */
38 31
39int 32int
40obj_count_in_map (mapstruct *map, int x, int y) 33obj_count_in_map (maptile *map, int x, int y)
41{ 34{
42 int count = 0; 35 int count = 0;
43 object *tmp; 36 object *tmp;
44 37
45 for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) 38 for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above)
46 count++; 39 count++;
47 return count; 40 return count;
48} 41}
49 42
50/* put the decor into the map. Right now, it's very primitive. */ 43/* put the decor into the map. Right now, it's very primitive. */
51 44
52void 45void
53put_decor (mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms * RP) 46put_decor (maptile *map, char **maze, char *decorstyle, int decor_option, random_map_params *RP)
54{ 47{
55 mapstruct *decor_map; 48 maptile *decor_map;
56 char style_name[256]; 49 char style_name[1024];
57 50
58 sprintf (style_name, "/styles/decorstyles"); 51 sprintf (style_name, "/styles/decorstyles");
59 52
60 decor_map = find_style (style_name, decorstyle, -1); 53 decor_map = find_style (style_name, decorstyle, -1);
61 if (decor_map == NULL) 54 if (!decor_map)
62 return; 55 return;
56
63 /* pick a random option, only 1 option right now. */ 57 /* pick a random option, only 1 option right now. */
64 if (decor_option == 0) 58 if (decor_option == 0)
65 decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; 59 decor_option = rndm (NR_DECOR_OPTIONS) + 1;
60
66 switch (decor_option) 61 switch (decor_option)
67 { 62 {
68 case 0: 63 case 0:
64 break;
65 case 1:
66 { /* random placement of decor objects. */
67 int number_to_place = rndm (RP->Xsize * RP->Ysize / 5);
68 int failures = 0;
69 object *new_decor_object;
70
71 while (failures < 100 && number_to_place > 0)
72 {
73 int x, y;
74
75 x = rndm (RP->Xsize - 2) + 1;
76 y = rndm (RP->Ysize - 2) + 1;
77 if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2)
78 { /* empty */
79 object *this_object;
80
81 new_decor_object = decor_map->pick_random_object ();
82 this_object = arch_to_object (new_decor_object->arch);
83 new_decor_object->copy_to (this_object);
84 this_object->x = x;
85 this_object->y = y;
86 /* it screws things up if decor can stop people */
87 this_object->move_block = 0;
88 insert_ob_in_map (this_object, map, NULL, 0);
89 number_to_place--;
90 }
91 else
92 failures++;
93 }
69 break; 94 break;
70 case 1: 95 }
71 { /* random placement of decor objects. */ 96 default:
72 int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); 97 { /* place decor objects everywhere: tile the map. */
73 int failures = 0; 98 int i, j;
74 object *new_decor_object;
75 99
76 while (failures < 100 && number_to_place > 0) 100 for (i = 1; i < RP->Xsize - 1; i++)
101 for (j = 1; j < RP->Ysize - 1; j++)
77 { 102 {
78 int x, y; 103 if (maze[i][j] == 0)
104 {
105 object *new_decor_object, *this_object;
79 106
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;
85
86 new_decor_object = pick_random_object (decor_map); 107 new_decor_object = decor_map->pick_random_object ();
87 this_object = arch_to_object (new_decor_object->arch); 108 this_object = arch_to_object (new_decor_object->arch);
88 copy_object (new_decor_object, this_object); 109 new_decor_object->copy_to (this_object);
89 this_object->x = x; 110 this_object->x = i;
90 this_object->y = y; 111 this_object->y = j;
91 /* it screws things up if decor can stop people */ 112 /* it screws things up if decor can stop people */
92 this_object->move_block = MOVE_BLOCK_DEFAULT; 113 this_object->move_block = 0;
93 insert_ob_in_map (this_object, map, NULL, 0); 114 insert_ob_in_map (this_object, map, NULL, 0);
94 number_to_place--;
95 } 115 }
96 else
97 failures++;
98 } 116 }
99 break; 117 break;
100 } 118 }
101 default:
102 { /* place decor objects everywhere: tile the map. */
103 int i, j;
104
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;
123 }
124 } 119 }
125} 120}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines