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.6 by root, Wed Dec 20 09:14:22 2006 UTC vs.
Revision 1.10 by pippijn, Sat Jan 6 14:42:30 2007 UTC

1
1/* 2/*
2 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
3 4
5 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 6 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 7 Copyright (C) 1992 Frank Tore Johansen
6 8
7 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
8 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
42} 44}
43 45
44/* 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. */
45 47
46void 48void
47put_decor (maptile *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)
48{ 50{
49 maptile *decor_map; 51 maptile *decor_map;
50 char style_name[256]; 52 char style_name[1024];
51 53
52 sprintf (style_name, "/styles/decorstyles"); 54 sprintf (style_name, "/styles/decorstyles");
53 55
54 decor_map = find_style (style_name, decorstyle, -1); 56 decor_map = find_style (style_name, decorstyle, -1);
55 if (decor_map == NULL) 57 if (decor_map == NULL)
57 /* pick a random option, only 1 option right now. */ 59 /* pick a random option, only 1 option right now. */
58 if (decor_option == 0) 60 if (decor_option == 0)
59 decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; 61 decor_option = RANDOM () % NR_DECOR_OPTIONS + 1;
60 switch (decor_option) 62 switch (decor_option)
61 { 63 {
62 case 0: 64 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 }
63 break; 95 break;
64 case 1: 96 }
65 { /* random placement of decor objects. */ 97 default:
66 int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); 98 { /* place decor objects everywhere: tile the map. */
67 int failures = 0; 99 int i, j;
68 object *new_decor_object;
69 100
70 while (failures < 100 && number_to_place > 0) 101 for (i = 1; i < RP->Xsize - 1; i++)
102 for (j = 1; j < RP->Ysize - 1; j++)
71 { 103 {
72 int x, y; 104 if (maze[i][j] == 0)
73 105 {
74 x = RANDOM () % (RP->Xsize - 2) + 1;
75 y = RANDOM () % (RP->Ysize - 2) + 1;
76 if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2)
77 { /* empty */
78 object *this_object; 106 object *new_decor_object, *this_object;
79 107
80 new_decor_object = pick_random_object (decor_map); 108 new_decor_object = pick_random_object (decor_map);
81 this_object = arch_to_object (new_decor_object->arch); 109 this_object = arch_to_object (new_decor_object->arch);
82 new_decor_object->copy_to (this_object); 110 new_decor_object->copy_to (this_object);
83 this_object->x = x; 111 this_object->x = i;
84 this_object->y = y; 112 this_object->y = j;
85 /* it screws things up if decor can stop people */ 113 /* it screws things up if decor can stop people */
86 this_object->move_block = MOVE_BLOCK_DEFAULT; 114 this_object->move_block = MOVE_BLOCK_DEFAULT;
87 insert_ob_in_map (this_object, map, NULL, 0); 115 insert_ob_in_map (this_object, map, NULL, 0);
88 number_to_place--;
89 } 116 }
90 else
91 failures++;
92 } 117 }
93 break; 118 break;
94 } 119 }
95 default:
96 { /* place decor objects everywhere: tile the map. */
97 int i, j;
98
99 for (i = 1; i < RP->Xsize - 1; i++)
100 for (j = 1; j < RP->Ysize - 1; j++)
101 {
102 if (maze[i][j] == 0)
103 {
104 object *new_decor_object, *this_object;
105
106 new_decor_object = pick_random_object (decor_map);
107 this_object = arch_to_object (new_decor_object->arch);
108 new_decor_object->copy_to (this_object);
109 this_object->x = i;
110 this_object->y = j;
111 /* it screws things up if decor can stop people */
112 this_object->move_block = MOVE_BLOCK_DEFAULT;
113 insert_ob_in_map (this_object, map, NULL, 0);
114 }
115 }
116 break;
117 }
118 } 120 }
119} 121}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines