1 | /* |
1 | /* |
2 | * static char *rcsid_decor_ = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * "$Id: decor.C,v 1.1 2006/08/13 17:16:03 elmex Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 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> |
4 | */ |
23 | */ |
5 | |
24 | |
6 | /* |
|
|
7 | CrossFire, A Multiplayer game for X-windows |
|
|
8 | |
|
|
9 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
|
|
10 | Copyright (C) 1992 Frank Tore Johansen |
|
|
11 | |
|
|
12 | 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 |
|
|
14 | the Free Software Foundation; either version 2 of the License, or |
|
|
15 | (at your option) any later version. |
|
|
16 | |
|
|
17 | This program is distributed in the hope that it will be useful, |
|
|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20 | GNU General Public License for more details. |
|
|
21 | |
|
|
22 | You should have received a copy of the GNU General Public License |
|
|
23 | along with this program; if not, write to the Free Software |
|
|
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
25 | |
|
|
26 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
27 | */ |
|
|
28 | |
|
|
29 | |
|
|
30 | #include <global.h> |
25 | #include <global.h> |
31 | #include <random_map.h> |
26 | #include <rmg.h> |
32 | #include <rproto.h> |
27 | #include <rproto.h> |
33 | |
28 | |
34 | #define NR_DECOR_OPTIONS 1 |
29 | #define NR_DECOR_OPTIONS 1 |
35 | |
30 | |
36 | /* 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. */ |
37 | |
32 | |
|
|
33 | static int |
38 | int obj_count_in_map(mapstruct *map,int x,int y) { |
34 | obj_count_in_map (maptile *map, int x, int y) |
|
|
35 | { |
39 | int count=0; |
36 | int count = 0; |
40 | object *tmp; |
37 | |
41 | 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) |
42 | count++; |
39 | ++count; |
|
|
40 | |
43 | return count; |
41 | return count; |
44 | } |
42 | } |
|
|
43 | |
45 | /* 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. */ |
46 | |
45 | |
47 | void put_decor(mapstruct *map,char **maze,char *decorstyle,int decor_option,RMParms *RP) { |
46 | void |
48 | mapstruct *decor_map; |
47 | put_decor (maptile *map, layout &maze, const char *decorstyle, int decor_option, random_map_params *RP) |
49 | char style_name[256]; |
48 | { |
|
|
49 | maptile *decor_map = find_style ("/styles/decorstyles", decorstyle, RP->difficulty); |
|
|
50 | if (!decor_map) |
|
|
51 | return; |
50 | |
52 | |
51 | sprintf(style_name,"/styles/decorstyles"); |
53 | /* pick a random option, only 1 option right now. */ |
|
|
54 | if (decor_option == 0) |
|
|
55 | decor_option = rmg_rndm (NR_DECOR_OPTIONS) + 1; |
52 | |
56 | |
53 | decor_map = find_style(style_name,decorstyle,-1); |
|
|
54 | if(decor_map == NULL) return; |
|
|
55 | /* pick a random option, only 1 option right now. */ |
|
|
56 | if(decor_option==0) |
|
|
57 | decor_option = RANDOM() % NR_DECOR_OPTIONS +1; |
|
|
58 | switch(decor_option) { |
57 | switch (decor_option) |
59 | case 0: break; |
58 | { |
60 | case 1: { /* random placement of decor objects. */ |
59 | case 0: |
|
|
60 | break; |
|
|
61 | |
|
|
62 | case 1: |
|
|
63 | { /* random placement of decor objects. */ |
61 | int number_to_place = RANDOM() % ( (RP->Xsize *RP->Ysize) / 5); |
64 | int number_to_place = rmg_rndm (RP->Xsize * RP->Ysize / 5); |
62 | int failures=0; |
65 | int failures = 0; |
63 | object *new_decor_object; |
66 | |
64 | while(failures < 100 && number_to_place > 0) { |
67 | while (failures < 100 && number_to_place > 0) |
65 | int x,y; |
68 | { |
66 | x = RANDOM() % (RP->Xsize-2) +1; |
69 | //coroapi::cede_to_tick (); |
67 | y = RANDOM() % (RP->Ysize-2) +1; |
70 | |
|
|
71 | int x = rmg_rndm (RP->Xsize - 2) + 1; |
|
|
72 | int y = rmg_rndm (RP->Ysize - 2) + 1; |
|
|
73 | |
68 | if(maze[x][y]==0 && obj_count_in_map(map,x,y)<2) { /* empty */ |
74 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
69 | object *this_object; |
75 | { |
70 | new_decor_object = pick_random_object(decor_map); |
76 | object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); |
71 | this_object = arch_to_object(new_decor_object->arch); |
|
|
72 | copy_object(new_decor_object,this_object); |
|
|
73 | this_object->x = x; |
|
|
74 | this_object->y = y; |
|
|
75 | /* it screws things up if decor can stop people */ |
77 | /* it screws things up if decor can stop people */ |
76 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
78 | this_object->move_block = 0; |
77 | insert_ob_in_map(this_object,map,NULL,0); |
79 | map->insert (this_object, x, y, 0, 0); |
|
|
80 | |
78 | number_to_place--; |
81 | number_to_place--; |
|
|
82 | } |
|
|
83 | else |
|
|
84 | failures++; |
79 | } |
85 | } |
80 | else |
86 | break; |
81 | failures++; |
|
|
82 | } |
87 | } |
|
|
88 | |
|
|
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++) |
|
|
94 | { |
|
|
95 | if (maze[i][j] == 0) |
|
|
96 | { |
|
|
97 | object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); |
|
|
98 | |
|
|
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; |
|
|
103 | |
|
|
104 | insert_ob_in_map (this_object, map, 0, 0); |
|
|
105 | } |
|
|
106 | } |
|
|
107 | |
83 | break; |
108 | break; |
|
|
109 | } |
84 | } |
110 | } |
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 | } |
111 | } |
|
|
112 | |