ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/decor.C
Revision: 1.10
Committed: Sat Jan 6 14:42:30 2007 UTC (17 years, 5 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.9: +1 -0 lines
Log Message:
added some copyrights

File Contents

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