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.1 by elmex, Sun Aug 13 17:16:03 2006 UTC vs.
Revision 1.10 by pippijn, Sat Jan 6 14:42:30 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines