1 | /* |
1 | /* |
2 | * static char *rcsid_wall_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * "$Id: wall.C,v 1.3 2006/09/03 00:18:42 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 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 | |
|
|
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 | |
24 | |
29 | #include <global.h> |
25 | #include <global.h> |
30 | #include <random_map.h> |
26 | #include <random_map.h> |
31 | #include <rproto.h> |
27 | #include <rproto.h> |
32 | |
28 | |
33 | /* Put in the walls and autojoin them. */ |
29 | /* Put in the walls and autojoin them. */ |
34 | |
30 | |
35 | |
|
|
36 | /* given a layout and a coordinate, tell me which squares up/down/right/left |
31 | /* given a layout and a coordinate, tell me which squares up/down/right/left |
37 | are occupied. */ |
32 | are occupied. */ |
38 | |
33 | int |
39 | int surround_flag(char **layout,int i,int j,RMParms *RP){ |
34 | surround_flag (const Layout &layout, int i, int j) |
|
|
35 | { |
40 | /* 1 = wall to left, |
36 | /* 1 = wall to left, |
41 | 2 = wall to right, |
37 | 2 = wall to right, |
42 | 4 = wall above |
38 | 4 = wall above |
43 | 8 = wall below */ |
39 | 8 = wall below */ |
44 | int surround_index = 0; |
40 | int surround_index = 0; |
|
|
41 | |
45 | if((i > 0) && layout[i-1][j]!=0) surround_index |=1; |
42 | if (i > 0 && layout[i - 1][j] != 0) surround_index |= 1; |
46 | if((i < RP->Xsize-1) && layout[i+1][j]!=0) surround_index |=2; |
43 | if (i < layout.w - 1 && layout[i + 1][j] != 0) surround_index |= 2; |
47 | if((j > 0) && layout[i][j-1]!=0) surround_index |=4; |
44 | if (j > 0 && layout[i][j - 1] != 0) surround_index |= 4; |
48 | if((j < RP->Ysize-1) && layout[i][j+1]!=0) surround_index |=8; |
45 | if (j < layout.h - 1 && layout[i][j + 1] != 0) surround_index |= 8; |
|
|
46 | |
49 | return surround_index; |
47 | return surround_index; |
50 | } |
48 | } |
51 | |
49 | |
52 | |
|
|
53 | /* like surround_flag, but only walls count. |
50 | /* like surround_flag, but only walls count. */ |
54 | */ |
51 | int |
55 | |
52 | surround_flag2 (const Layout &layout, int i, int j) |
56 | int surround_flag2(char **layout,int i,int j,RMParms *RP){ |
53 | { |
57 | /* 1 = wall to left, |
54 | /* 1 = wall to left, |
58 | 2 = wall to right, |
55 | 2 = wall to right, |
59 | 4 = wall above |
56 | 4 = wall above |
60 | 8 = wall below */ |
57 | 8 = wall below */ |
61 | int surround_index = 0; |
58 | int surround_index = 0; |
|
|
59 | |
62 | if((i > 0) && layout[i-1][j]=='#') surround_index |=1; |
60 | if (i > 0 && layout[i - 1][j] == '#') surround_index |= 1; |
63 | if((i < RP->Xsize-1) && layout[i+1][j]=='#') surround_index |=2; |
61 | if (i < layout.w - 1 && layout[i + 1][j] == '#') surround_index |= 2; |
64 | if((j > 0) && layout[i][j-1]=='#') surround_index |=4; |
62 | if (j > 0 && layout[i][j - 1] == '#') surround_index |= 4; |
65 | if((j < RP->Ysize-1) && layout[i][j+1]=='#') surround_index |=8; |
63 | if (j < layout.h - 1 && layout[i][j + 1] == '#') surround_index |= 8; |
|
|
64 | |
66 | return surround_index; |
65 | return surround_index; |
67 | } |
66 | } |
68 | |
|
|
69 | |
67 | |
70 | /* like surround_flag, except it checks a map, not a layout. |
68 | /* like surround_flag, except it checks a map, not a layout. |
71 | * Since this is part of the random map code, presumption |
69 | * Since this is part of the random map code, presumption |
72 | * is that this is not a tiled map. |
70 | * is that this is not a tiled map. |
73 | * What is considered blocking and not is somewhat hard coded. |
71 | * What is considered blocking and not is somewhat hard coded. |
74 | */ |
72 | */ |
75 | int surround_flag3(mapstruct *map,sint16 i,sint16 j,RMParms *RP){ |
73 | int |
|
|
74 | surround_flag3 (maptile *map, int i, int j) |
|
|
75 | { |
76 | /* |
76 | /* |
77 | * 1 = blocked to left, |
77 | * 1 = blocked to left, |
78 | * 2 = blocked to right, |
78 | * 2 = blocked to right, |
79 | * 4 = blocked above |
79 | * 4 = blocked above |
80 | * 8 = blocked below |
80 | * 8 = blocked below |
81 | */ |
81 | */ |
82 | |
|
|
83 | int surround_index = 0; |
82 | int surround_index = 0; |
84 | |
83 | |
85 | if((i > 0) && (GET_MAP_MOVE_BLOCK(map, i-1,j) & ~MOVE_BLOCK_DEFAULT)) |
84 | // don't forget to update the mapspace! |
86 | surround_index |=1; |
85 | if (i > 0) map->at (i - 1, j ).update (); |
87 | if((i < RP->Xsize-1) && (GET_MAP_MOVE_BLOCK(map, i+1,j) & ~MOVE_BLOCK_DEFAULT)) |
86 | if (i < map->width - 1) map->at (i + 1, j ).update (); |
88 | surround_index |=2; |
87 | if (j > 0) map->at (i , j - 1).update (); |
89 | if((j > 0) && (GET_MAP_MOVE_BLOCK(map, i,j-1) & ~MOVE_BLOCK_DEFAULT)) |
88 | if (j < map->height - 1) map->at (i , j + 1).update (); |
90 | surround_index |=4; |
|
|
91 | if((j < RP->Ysize-1) && (GET_MAP_MOVE_BLOCK(map,i,j+1) & ~MOVE_BLOCK_DEFAULT)) |
|
|
92 | surround_index |=8; |
|
|
93 | |
89 | |
94 | return surround_index; |
90 | if (i > 0 && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) surround_index |= 1; |
95 | } |
91 | if (i < map->width - 1 && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) surround_index |= 2; |
96 | |
92 | if (j > 0 && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) surround_index |= 4; |
97 | /* like surround_flag2, except it checks a map, not a layout. */ |
93 | if (j < map->height - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8; |
98 | |
|
|
99 | int surround_flag4(mapstruct *map,int i,int j,RMParms *RP){ |
|
|
100 | /* 1 = blocked to left, |
|
|
101 | 2 = blocked to right, |
|
|
102 | 4 = blocked above |
|
|
103 | 8 = blocked below */ |
|
|
104 | int surround_index = 0; |
|
|
105 | |
|
|
106 | if((i > 0) && wall_blocked(map,i-1,j)) surround_index |=1; |
|
|
107 | if((i < RP->Xsize-1) && wall_blocked(map,i+1,j)) surround_index |=2; |
|
|
108 | if((j > 0) && wall_blocked(map,i,j-1)) surround_index |=4; |
|
|
109 | if((j < RP->Ysize-1) && wall_blocked(map,i,j+1)) surround_index |=8; |
|
|
110 | |
94 | |
111 | return surround_index; |
95 | return surround_index; |
|
|
96 | } |
|
|
97 | |
|
|
98 | /* like surround_flag2, except it checks a map, not a layout. */ |
|
|
99 | static int |
|
|
100 | surround_flag4 (maptile *map, int i, int j) |
|
|
101 | { |
|
|
102 | /* 1 = blocked to left, |
|
|
103 | 2 = blocked to right, |
|
|
104 | 4 = blocked above |
|
|
105 | 8 = blocked below */ |
|
|
106 | int surround_index = 0; |
|
|
107 | |
|
|
108 | if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1; |
|
|
109 | if (i < map->width - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2; |
|
|
110 | if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4; |
|
|
111 | if (j < map->height - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8; |
|
|
112 | |
|
|
113 | return surround_index; |
|
|
114 | } |
|
|
115 | |
|
|
116 | /* picks the right wall type for this square, to make it look nice, |
|
|
117 | and have everything nicely joined. It uses the layout. */ |
|
|
118 | static object * |
|
|
119 | pick_joined_wall (object *the_wall, const Layout &layout, int i, int j, random_map_params *RP) |
|
|
120 | { |
|
|
121 | /* 1 = wall to left, |
|
|
122 | 2 = wall to right, |
|
|
123 | 4 = wall above |
|
|
124 | 8 = wall below */ |
|
|
125 | int surround_index = 0; |
|
|
126 | int l; |
|
|
127 | char wall_name[1024]; |
|
|
128 | archetype *wall_arch = 0; |
|
|
129 | |
|
|
130 | assign (wall_name, the_wall->arch->archname); |
|
|
131 | |
|
|
132 | /* conventionally, walls are named like this: |
|
|
133 | wallname_wallcode, where wallcode indicates |
|
|
134 | a joinedness, and wallname is the wall. |
|
|
135 | this code depends on the convention for |
|
|
136 | finding the right wall. */ |
|
|
137 | |
|
|
138 | /* extract the wall name, which is the text up to the leading _ */ |
|
|
139 | for (l = 0; l < 64; l++) |
|
|
140 | { |
|
|
141 | if (wall_name[l] == '_') |
|
|
142 | { |
|
|
143 | wall_name[l] = 0; |
|
|
144 | break; |
|
|
145 | } |
|
|
146 | } |
|
|
147 | |
|
|
148 | surround_index = surround_flag2 (layout, i, j); |
|
|
149 | |
|
|
150 | switch (surround_index) |
|
|
151 | { |
|
|
152 | case 0: |
|
|
153 | strcat (wall_name, "_0"); |
|
|
154 | break; |
|
|
155 | case 1: |
|
|
156 | strcat (wall_name, "_1_3"); |
|
|
157 | break; |
|
|
158 | case 2: |
|
|
159 | strcat (wall_name, "_1_4"); |
|
|
160 | break; |
|
|
161 | case 3: |
|
|
162 | strcat (wall_name, "_2_1_2"); |
|
|
163 | break; |
|
|
164 | case 4: |
|
|
165 | strcat (wall_name, "_1_2"); |
|
|
166 | break; |
|
|
167 | case 5: |
|
|
168 | strcat (wall_name, "_2_2_4"); |
|
|
169 | break; |
|
|
170 | case 6: |
|
|
171 | strcat (wall_name, "_2_2_1"); |
|
|
172 | break; |
|
|
173 | case 7: |
|
|
174 | strcat (wall_name, "_3_1"); |
|
|
175 | break; |
|
|
176 | case 8: |
|
|
177 | strcat (wall_name, "_1_1"); |
|
|
178 | break; |
|
|
179 | case 9: |
|
|
180 | strcat (wall_name, "_2_2_3"); |
|
|
181 | break; |
|
|
182 | case 10: |
|
|
183 | strcat (wall_name, "_2_2_2"); |
|
|
184 | break; |
|
|
185 | case 11: |
|
|
186 | strcat (wall_name, "_3_3"); |
|
|
187 | break; |
|
|
188 | case 12: |
|
|
189 | strcat (wall_name, "_2_1_1"); |
|
|
190 | break; |
|
|
191 | case 13: |
|
|
192 | strcat (wall_name, "_3_4"); |
|
|
193 | break; |
|
|
194 | case 14: |
|
|
195 | strcat (wall_name, "_3_2"); |
|
|
196 | break; |
|
|
197 | case 15: |
|
|
198 | strcat (wall_name, "_4"); |
|
|
199 | break; |
|
|
200 | } |
|
|
201 | wall_arch = archetype::find (wall_name); |
|
|
202 | |
|
|
203 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
112 | } |
204 | } |
113 | |
205 | |
114 | /* takes a map and a layout, and puts walls in the map (picked from |
206 | /* takes a map and a layout, and puts walls in the map (picked from |
115 | w_style) at '#' marks. */ |
207 | w_style) at '#' marks. */ |
116 | |
208 | void |
117 | void make_map_walls(mapstruct *map,char **layout, char *w_style,RMParms *RP) { |
209 | make_map_walls (maptile *map, Layout &layout, const char *w_style, const char *m_style, random_map_params *RP) |
118 | char styledirname[256]; |
210 | { |
119 | char stylefilepath[256]; |
|
|
120 | mapstruct *style_map=0; |
|
|
121 | object *the_wall; |
211 | object *the_wall; |
122 | |
212 | |
123 | /* get the style map */ |
213 | /* get the style map */ |
124 | if(!strcmp(w_style,"none")) return; |
214 | if (!strcmp (w_style, "none")) |
125 | sprintf(styledirname,"%s","/styles/wallstyles"); |
215 | return; |
126 | sprintf(stylefilepath,"%s/%s",styledirname,w_style); |
|
|
127 | style_map = find_style(styledirname,w_style,-1); |
|
|
128 | if(style_map == 0) return; |
|
|
129 | |
216 | |
130 | /* fill up the map with the given floor style */ |
217 | maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty); |
131 | if((the_wall=pick_random_object(style_map))!=NULL) { |
218 | if (!style_map) |
|
|
219 | return; |
|
|
220 | |
|
|
221 | maptile *mining_map = m_style && *m_style |
|
|
222 | ? find_style ("/styles/miningstyles", m_style, RP->difficulty) |
|
|
223 | : 0; |
|
|
224 | |
|
|
225 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
|
|
226 | { |
132 | int i,j; |
227 | int i, j; |
133 | char *cp; |
228 | char *cp; |
134 | int joinedwalls=0; |
229 | int joinedwalls = 0; |
135 | object *thiswall; |
230 | object *thiswall; |
136 | |
231 | |
137 | sprintf(RP->wall_name,"%s", &the_wall->arch->name); |
232 | sprintf (RP->wall_name, "%s", &the_wall->arch->archname); |
138 | if ((cp=strchr(RP->wall_name,'_'))!=NULL) { |
233 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
|
|
234 | { |
139 | *cp=0; |
235 | *cp = 0; |
140 | joinedwalls=1; |
236 | joinedwalls = 1; |
141 | } |
237 | } |
142 | |
238 | |
143 | for(i=0;i<RP->Xsize;i++) |
239 | for (i = 0; i < RP->Xsize; i++) |
144 | for(j=0;j<RP->Ysize;j++) { |
240 | for (j = 0; j < RP->Ysize; j++) |
|
|
241 | { |
145 | if(layout[i][j]=='#') { |
242 | if (layout[i][j] == '#') |
|
|
243 | { |
146 | if(joinedwalls) |
244 | if (joinedwalls) |
147 | thiswall=pick_joined_wall(the_wall,layout,i,j,RP); |
245 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
148 | else |
246 | else |
149 | thiswall=arch_to_object(the_wall->arch); |
247 | thiswall = the_wall->arch->instance (); |
150 | thiswall->x = i; |
248 | |
151 | thiswall->y = j; |
|
|
152 | thiswall->move_block = MOVE_ALL; |
249 | thiswall->move_block = MOVE_ALL; |
153 | insert_ob_in_map(thiswall,map,thiswall,INS_NO_MERGE | INS_NO_WALK_ON); |
250 | map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
251 | |
|
|
252 | if (mining_map) |
|
|
253 | if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot) |
|
|
254 | map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
154 | } |
255 | } |
155 | } |
|
|
156 | } |
|
|
157 | } |
|
|
158 | |
|
|
159 | |
|
|
160 | /* picks the right wall type for this square, to make it look nice, |
|
|
161 | and have everything nicely joined. It uses the layout. */ |
|
|
162 | |
|
|
163 | object *pick_joined_wall(object *the_wall,char **layout,int i,int j,RMParms *RP) { |
|
|
164 | /* 1 = wall to left, |
|
|
165 | 2 = wall to right, |
|
|
166 | 4 = wall above |
|
|
167 | 8 = wall below */ |
|
|
168 | int surround_index=0; |
|
|
169 | int l; |
|
|
170 | char wall_name[64]; |
|
|
171 | archetype *wall_arch=0; |
|
|
172 | |
|
|
173 | strcpy(wall_name,the_wall->arch->name); |
|
|
174 | |
|
|
175 | /* conventionally, walls are named like this: |
|
|
176 | wallname_wallcode, where wallcode indicates |
|
|
177 | a joinedness, and wallname is the wall. |
|
|
178 | this code depends on the convention for |
|
|
179 | finding the right wall. */ |
|
|
180 | |
|
|
181 | /* extract the wall name, which is the text up to the leading _ */ |
|
|
182 | for(l=0;l<64;l++) { |
|
|
183 | if(wall_name[l]=='_') { |
|
|
184 | wall_name[l] = 0; |
|
|
185 | break; |
|
|
186 | } |
256 | } |
187 | } |
257 | } |
188 | |
|
|
189 | surround_index = surround_flag2(layout,i,j,RP); |
|
|
190 | |
|
|
191 | switch(surround_index) { |
|
|
192 | case 0: |
|
|
193 | strcat(wall_name,"_0"); |
|
|
194 | break; |
|
|
195 | case 1: |
|
|
196 | strcat(wall_name,"_1_3"); |
|
|
197 | break; |
|
|
198 | case 2: |
|
|
199 | strcat(wall_name,"_1_4"); |
|
|
200 | break; |
|
|
201 | case 3: |
|
|
202 | strcat(wall_name,"_2_1_2"); |
|
|
203 | break; |
|
|
204 | case 4: |
|
|
205 | strcat(wall_name,"_1_2"); |
|
|
206 | break; |
|
|
207 | case 5: |
|
|
208 | strcat(wall_name,"_2_2_4"); |
|
|
209 | break; |
|
|
210 | case 6: |
|
|
211 | strcat(wall_name,"_2_2_1"); |
|
|
212 | break; |
|
|
213 | case 7: |
|
|
214 | strcat(wall_name,"_3_1"); |
|
|
215 | break; |
|
|
216 | case 8: |
|
|
217 | strcat(wall_name,"_1_1"); |
|
|
218 | break; |
|
|
219 | case 9: |
|
|
220 | strcat(wall_name,"_2_2_3"); |
|
|
221 | break; |
|
|
222 | case 10: |
|
|
223 | strcat(wall_name,"_2_2_2"); |
|
|
224 | break; |
|
|
225 | case 11: |
|
|
226 | strcat(wall_name,"_3_3"); |
|
|
227 | break; |
|
|
228 | case 12: |
|
|
229 | strcat(wall_name,"_2_1_1"); |
|
|
230 | break; |
|
|
231 | case 13: |
|
|
232 | strcat(wall_name,"_3_4"); |
|
|
233 | break; |
|
|
234 | case 14: |
|
|
235 | strcat(wall_name,"_3_2"); |
|
|
236 | break; |
|
|
237 | case 15: |
|
|
238 | strcat(wall_name,"_4"); |
|
|
239 | break; |
|
|
240 | } |
|
|
241 | wall_arch = find_archetype(wall_name); |
|
|
242 | if(wall_arch) return arch_to_object(wall_arch); |
|
|
243 | else { |
|
|
244 | nroferrors--; |
|
|
245 | return arch_to_object(the_wall->arch); |
|
|
246 | } |
|
|
247 | |
|
|
248 | |
|
|
249 | } |
258 | } |
250 | |
|
|
251 | |
259 | |
252 | /* this takes a map, and changes an existing wall to match what's blocked |
260 | /* this takes a map, and changes an existing wall to match what's blocked |
253 | * around it, counting only doors and walls as blocked. If insert_flag is |
261 | * around it, counting only doors and walls as blocked. If insert_flag is |
254 | * 1, it will go ahead and insert the wall into the map. If not, it |
262 | * 1, it will go ahead and insert the wall into the map. If not, it |
255 | * will only return the wall which would belong there, and doesn't |
263 | * will only return the wall which would belong there, and doesn't |
256 | * remove anything. It depends on the |
264 | * remove anything. It depends on the |
257 | * global, previously-set variable, "wall_name" |
265 | * global, previously-set variable, "wall_name" |
258 | */ |
266 | */ |
259 | |
267 | object * |
260 | object * retrofit_joined_wall(mapstruct *the_map,int i,int j,int insert_flag,RMParms *RP) { |
268 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
|
|
269 | { |
261 | /* 1 = wall to left, |
270 | /* 1 = wall to left, |
262 | * 2 = wall to right, |
271 | * 2 = wall to right, |
263 | * 4 = wall above |
272 | * 4 = wall above |
264 | * 8 = wall below |
273 | * 8 = wall below |
265 | */ |
274 | */ |
266 | int surround_index=0; |
275 | int surround_index = 0; |
267 | int l; |
276 | int l; |
268 | object *the_wall=0; |
277 | object *the_wall = 0; |
269 | object *new_wall=0; |
278 | object *new_wall = 0; |
270 | archetype * wall_arch=0; |
279 | archetype *wall_arch = 0; |
271 | |
280 | |
272 | /* first find the wall */ |
281 | /* first find the wall */ |
273 | for(the_wall = get_map_ob(the_map,i,j);the_wall!=NULL;the_wall=the_wall->above) |
282 | for (the_wall = GET_MAP_OB (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) |
274 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type!=EXIT && the_wall->type!=TELEPORTER) |
283 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
275 | break; |
284 | break; |
276 | |
285 | |
277 | |
286 | |
278 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
287 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
279 | * signal that later. |
288 | * signal that later. |
280 | */ |
289 | */ |
281 | if(the_wall && (the_wall->type==DOOR || the_wall->type==LOCKED_DOOR) ) { |
290 | if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR)) |
|
|
291 | { |
282 | the_wall=NULL; |
292 | the_wall = NULL; |
283 | /* if we're not supposed to insert a new wall where there wasn't one, |
293 | /* if we're not supposed to insert a new wall where there wasn't one, |
284 | * we've gotta leave. |
294 | * we've gotta leave. |
285 | */ |
295 | */ |
286 | if(insert_flag==0) return 0; |
296 | if (insert_flag == 0) |
|
|
297 | return 0; |
287 | } |
298 | } |
288 | else if(the_wall==NULL) return NULL; |
299 | else if (the_wall == NULL) |
|
|
300 | return NULL; |
289 | |
301 | |
290 | /* canonicalize the wall name */ |
302 | /* canonicalize the wall name */ |
291 | for(l=0;l<64;l++) { |
303 | for (l = 0; l < 64; l++) |
|
|
304 | { |
292 | if(RP->wall_name[l]=='_') { |
305 | if (RP->wall_name[l] == '_') |
|
|
306 | { |
293 | RP->wall_name[l] = 0; |
307 | RP->wall_name[l] = 0; |
294 | break; |
308 | break; |
295 | } |
309 | } |
296 | } |
310 | } |
297 | |
311 | |
298 | surround_index = surround_flag4(the_map,i,j,RP); |
312 | surround_index = surround_flag4 (the_map, i, j); |
299 | /* This would be a lot cleaner to just us a lookup table, |
313 | /* This would be a lot cleaner to just us a lookup table, |
300 | * eg, wall_suffix[surround_index] |
314 | * eg, wall_suffix[surround_index] |
301 | */ |
315 | */ |
302 | switch(surround_index) { |
316 | switch (surround_index) |
|
|
317 | { |
303 | case 0: |
318 | case 0: |
304 | strcat(RP->wall_name,"_0"); |
319 | strcat (RP->wall_name, "_0"); |
305 | break; |
320 | break; |
306 | case 1: |
321 | case 1: |
307 | strcat(RP->wall_name,"_1_3"); |
322 | strcat (RP->wall_name, "_1_3"); |
308 | break; |
323 | break; |
309 | case 2: |
324 | case 2: |
310 | strcat(RP->wall_name,"_1_4"); |
325 | strcat (RP->wall_name, "_1_4"); |
311 | break; |
326 | break; |
312 | case 3: |
327 | case 3: |
313 | strcat(RP->wall_name,"_2_1_2"); |
328 | strcat (RP->wall_name, "_2_1_2"); |
314 | break; |
329 | break; |
315 | case 4: |
330 | case 4: |
316 | strcat(RP->wall_name,"_1_2"); |
331 | strcat (RP->wall_name, "_1_2"); |
317 | break; |
332 | break; |
318 | case 5: |
333 | case 5: |
319 | strcat(RP->wall_name,"_2_2_4"); |
334 | strcat (RP->wall_name, "_2_2_4"); |
320 | break; |
335 | break; |
321 | case 6: |
336 | case 6: |
322 | strcat(RP->wall_name,"_2_2_1"); |
337 | strcat (RP->wall_name, "_2_2_1"); |
323 | break; |
338 | break; |
324 | case 7: |
339 | case 7: |
325 | strcat(RP->wall_name,"_3_1"); |
340 | strcat (RP->wall_name, "_3_1"); |
326 | break; |
341 | break; |
327 | case 8: |
342 | case 8: |
328 | strcat(RP->wall_name,"_1_1"); |
343 | strcat (RP->wall_name, "_1_1"); |
329 | break; |
344 | break; |
330 | case 9: |
345 | case 9: |
331 | strcat(RP->wall_name,"_2_2_3"); |
346 | strcat (RP->wall_name, "_2_2_3"); |
332 | break; |
347 | break; |
333 | case 10: |
348 | case 10: |
334 | strcat(RP->wall_name,"_2_2_2"); |
349 | strcat (RP->wall_name, "_2_2_2"); |
335 | break; |
350 | break; |
336 | case 11: |
351 | case 11: |
337 | strcat(RP->wall_name,"_3_3"); |
352 | strcat (RP->wall_name, "_3_3"); |
338 | break; |
353 | break; |
339 | case 12: |
354 | case 12: |
340 | strcat(RP->wall_name,"_2_1_1"); |
355 | strcat (RP->wall_name, "_2_1_1"); |
341 | break; |
356 | break; |
342 | case 13: |
357 | case 13: |
343 | strcat(RP->wall_name,"_3_4"); |
358 | strcat (RP->wall_name, "_3_4"); |
344 | break; |
359 | break; |
345 | case 14: |
360 | case 14: |
346 | strcat(RP->wall_name,"_3_2"); |
361 | strcat (RP->wall_name, "_3_2"); |
347 | break; |
362 | break; |
348 | case 15: |
363 | case 15: |
349 | strcat(RP->wall_name,"_4"); |
364 | strcat (RP->wall_name, "_4"); |
350 | break; |
365 | break; |
351 | } |
366 | } |
|
|
367 | |
352 | wall_arch = find_archetype(RP->wall_name); |
368 | wall_arch = archetype::find (RP->wall_name); |
353 | if(wall_arch!=NULL) { |
369 | |
354 | new_wall=arch_to_object(wall_arch); |
370 | if (!wall_arch) |
|
|
371 | { |
|
|
372 | new_wall = wall_arch->instance (); |
355 | new_wall->x = i; |
373 | new_wall->x = i; |
356 | new_wall->y = j; |
374 | new_wall->y = j; |
|
|
375 | |
357 | if(the_wall && the_wall->map) { |
376 | if (the_wall && the_wall->map) |
358 | remove_ob(the_wall); |
377 | the_wall->destroy (); |
359 | free_object(the_wall); |
378 | |
360 | } |
|
|
361 | the_wall->move_block = MOVE_ALL; |
379 | the_wall->move_block = MOVE_ALL; |
362 | insert_ob_in_map(new_wall,the_map,new_wall,INS_NO_MERGE | INS_NO_WALK_ON); |
380 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
363 | } |
381 | } |
364 | else |
382 | |
365 | nroferrors--; /* it's OK not to find an arch. */ |
|
|
366 | return new_wall; |
383 | return new_wall; |
367 | } |
384 | } |
368 | |
|
|
369 | |
|
|