--- deliantra/server/random_maps/wall.C 2006/12/12 20:53:03 1.8 +++ deliantra/server/random_maps/wall.C 2007/06/04 12:19:09 1.22 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The authors can be reached via e-mail at -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2002 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The authors can be reached via e-mail at + */ #include #include @@ -32,7 +33,7 @@ are occupied. */ int -surround_flag (char **layout, int i, int j, RMParms * RP) +surround_flag (char **layout, int i, int j, random_map_params *RP) { /* 1 = wall to left, 2 = wall to right, @@ -56,7 +57,7 @@ */ int -surround_flag2 (char **layout, int i, int j, RMParms * RP) +surround_flag2 (char **layout, int i, int j, random_map_params *RP) { /* 1 = wall to left, 2 = wall to right, @@ -82,7 +83,7 @@ * What is considered blocking and not is somewhat hard coded. */ int -surround_flag3 (maptile *map, sint16 i, sint16 j, RMParms * RP) +surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP) { /* * 1 = blocked to left, @@ -93,13 +94,19 @@ int surround_index = 0; - if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT)) + // don't forget to update the mapspace! + if (i > 0) map->at (i - 1, j ).update (); + if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); + if (j > 0) map->at (i , j - 1).update (); + if (j < RP->Ysize - 1) map->at (i , j + 1).update (); + + if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) surround_index |= 1; - if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) + if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) surround_index |= 2; - if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) + if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) surround_index |= 4; - if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT)) + if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8; return surround_index; @@ -108,7 +115,7 @@ /* like surround_flag2, except it checks a map, not a layout. */ int -surround_flag4 (maptile *map, int i, int j, RMParms * RP) +surround_flag4 (maptile *map, int i, int j, random_map_params *RP) { /* 1 = blocked to left, 2 = blocked to right, @@ -132,10 +139,10 @@ w_style) at '#' marks. */ void -make_map_walls (maptile *map, char **layout, char *w_style, RMParms * RP) +make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) { - char styledirname[256]; - char stylefilepath[256]; + char styledirname[1024]; + char stylefilepath[1024]; maptile *style_map = 0; object *the_wall; @@ -145,18 +152,18 @@ sprintf (styledirname, "%s", "/styles/wallstyles"); sprintf (stylefilepath, "%s/%s", styledirname, w_style); style_map = find_style (styledirname, w_style, -1); - if (style_map == 0) + if (!style_map) return; /* fill up the map with the given floor style */ - if ((the_wall = pick_random_object (style_map)) != NULL) + if ((the_wall = style_map->pick_random_object ())) { int i, j; char *cp; int joinedwalls = 0; object *thiswall; - sprintf (RP->wall_name, "%s", &the_wall->arch->name); + sprintf (RP->wall_name, "%s", &the_wall->arch->archname); if ((cp = strchr (RP->wall_name, '_')) != NULL) { *cp = 0; @@ -186,7 +193,7 @@ and have everything nicely joined. It uses the layout. */ object * -pick_joined_wall (object *the_wall, char **layout, int i, int j, RMParms * RP) +pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP) { /* 1 = wall to left, 2 = wall to right, @@ -194,10 +201,10 @@ 8 = wall below */ int surround_index = 0; int l; - char wall_name[64]; + char wall_name[1024]; archetype *wall_arch = 0; - strcpy (wall_name, the_wall->arch->name); + assign (wall_name, the_wall->arch->archname); /* conventionally, walls are named like this: wallname_wallcode, where wallcode indicates @@ -219,65 +226,58 @@ switch (surround_index) { - case 0: - strcat (wall_name, "_0"); - break; - case 1: - strcat (wall_name, "_1_3"); - break; - case 2: - strcat (wall_name, "_1_4"); - break; - case 3: - strcat (wall_name, "_2_1_2"); - break; - case 4: - strcat (wall_name, "_1_2"); - break; - case 5: - strcat (wall_name, "_2_2_4"); - break; - case 6: - strcat (wall_name, "_2_2_1"); - break; - case 7: - strcat (wall_name, "_3_1"); - break; - case 8: - strcat (wall_name, "_1_1"); - break; - case 9: - strcat (wall_name, "_2_2_3"); - break; - case 10: - strcat (wall_name, "_2_2_2"); - break; - case 11: - strcat (wall_name, "_3_3"); - break; - case 12: - strcat (wall_name, "_2_1_1"); - break; - case 13: - strcat (wall_name, "_3_4"); - break; - case 14: - strcat (wall_name, "_3_2"); - break; - case 15: - strcat (wall_name, "_4"); - break; + case 0: + strcat (wall_name, "_0"); + break; + case 1: + strcat (wall_name, "_1_3"); + break; + case 2: + strcat (wall_name, "_1_4"); + break; + case 3: + strcat (wall_name, "_2_1_2"); + break; + case 4: + strcat (wall_name, "_1_2"); + break; + case 5: + strcat (wall_name, "_2_2_4"); + break; + case 6: + strcat (wall_name, "_2_2_1"); + break; + case 7: + strcat (wall_name, "_3_1"); + break; + case 8: + strcat (wall_name, "_1_1"); + break; + case 9: + strcat (wall_name, "_2_2_3"); + break; + case 10: + strcat (wall_name, "_2_2_2"); + break; + case 11: + strcat (wall_name, "_3_3"); + break; + case 12: + strcat (wall_name, "_2_1_1"); + break; + case 13: + strcat (wall_name, "_3_4"); + break; + case 14: + strcat (wall_name, "_3_2"); + break; + case 15: + strcat (wall_name, "_4"); + break; } wall_arch = archetype::find (wall_name); - if (wall_arch) - return arch_to_object (wall_arch); - else - { - nroferrors--; - return arch_to_object (the_wall->arch); - } - + return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch); } @@ -290,7 +290,7 @@ */ object * -retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, RMParms * RP) +retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) { /* 1 = wall to left, * 2 = wall to right, @@ -304,7 +304,7 @@ archetype *wall_arch = 0; /* first find the wall */ - for (the_wall = get_map_ob (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) + for (the_wall = GET_MAP_OB (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) break; @@ -340,70 +340,73 @@ */ switch (surround_index) { - case 0: - strcat (RP->wall_name, "_0"); - break; - case 1: - strcat (RP->wall_name, "_1_3"); - break; - case 2: - strcat (RP->wall_name, "_1_4"); - break; - case 3: - strcat (RP->wall_name, "_2_1_2"); - break; - case 4: - strcat (RP->wall_name, "_1_2"); - break; - case 5: - strcat (RP->wall_name, "_2_2_4"); - break; - case 6: - strcat (RP->wall_name, "_2_2_1"); - break; - case 7: - strcat (RP->wall_name, "_3_1"); - break; - case 8: - strcat (RP->wall_name, "_1_1"); - break; - case 9: - strcat (RP->wall_name, "_2_2_3"); - break; - case 10: - strcat (RP->wall_name, "_2_2_2"); - break; - case 11: - strcat (RP->wall_name, "_3_3"); - break; - case 12: - strcat (RP->wall_name, "_2_1_1"); - break; - case 13: - strcat (RP->wall_name, "_3_4"); - break; - case 14: - strcat (RP->wall_name, "_3_2"); - break; - case 15: - strcat (RP->wall_name, "_4"); - break; + case 0: + strcat (RP->wall_name, "_0"); + break; + case 1: + strcat (RP->wall_name, "_1_3"); + break; + case 2: + strcat (RP->wall_name, "_1_4"); + break; + case 3: + strcat (RP->wall_name, "_2_1_2"); + break; + case 4: + strcat (RP->wall_name, "_1_2"); + break; + case 5: + strcat (RP->wall_name, "_2_2_4"); + break; + case 6: + strcat (RP->wall_name, "_2_2_1"); + break; + case 7: + strcat (RP->wall_name, "_3_1"); + break; + case 8: + strcat (RP->wall_name, "_1_1"); + break; + case 9: + strcat (RP->wall_name, "_2_2_3"); + break; + case 10: + strcat (RP->wall_name, "_2_2_2"); + break; + case 11: + strcat (RP->wall_name, "_3_3"); + break; + case 12: + strcat (RP->wall_name, "_2_1_1"); + break; + case 13: + strcat (RP->wall_name, "_3_4"); + break; + case 14: + strcat (RP->wall_name, "_3_2"); + break; + case 15: + strcat (RP->wall_name, "_4"); + break; } + wall_arch = archetype::find (RP->wall_name); - if (wall_arch != NULL) + + if (!wall_arch) { new_wall = arch_to_object (wall_arch); new_wall->x = i; new_wall->y = j; + if (the_wall && the_wall->map) { the_wall->remove (); - the_wall->destroy (0); + the_wall->destroy (); } + the_wall->move_block = MOVE_ALL; insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); } - else - nroferrors--; /* it's OK not to find an arch. */ + return new_wall; }