Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_decor_ = 00003 * "$Id: decor.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* 00007 CrossFire, A Multiplayer game for X-windows 00008 00009 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 00010 Copyright (C) 1992 Frank Tore Johansen 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 00026 The authors can be reached via e-mail at crossfire-devel@real-time.com 00027 */ 00028 00034 #include <global.h> 00035 #include <random_map.h> 00036 #include <rproto.h> 00037 00039 #define NR_DECOR_OPTIONS 1 00040 00051 int obj_count_in_map(mapstruct *map, int x, int y) { 00052 int count = 0; 00053 object *tmp; 00054 00055 for (tmp = GET_MAP_OB(map, x, y); tmp != NULL; tmp = tmp->above) 00056 count++; 00057 return count; 00058 } 00059 00076 void put_decor(mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms *RP) { 00077 mapstruct *decor_map; 00078 char style_name[256]; 00079 00080 snprintf(style_name, sizeof(style_name), "/styles/decorstyles"); 00081 00082 decor_map = find_style(style_name, decorstyle, -1); 00083 if (decor_map == NULL) 00084 return; 00085 00086 /* pick a random option, only 1 option right now. */ 00087 if (decor_option == 0) 00088 decor_option = RANDOM()%NR_DECOR_OPTIONS+1; 00089 00090 switch (decor_option) { 00091 case 0: 00092 break; 00093 00094 case 1: { /* random placement of decor objects. */ 00095 int number_to_place = RANDOM()%((RP->Xsize*RP->Ysize)/5); 00096 int failures = 0; 00097 object *new_decor_object; 00098 00099 while (failures < 100 && number_to_place > 0) { 00100 int x, y; 00101 00102 x = RANDOM()%(RP->Xsize-2)+1; 00103 y = RANDOM()%(RP->Ysize-2)+1; 00104 if (maze[x][y] == 0 && obj_count_in_map(map, x, y) < 2) { /* empty */ 00105 object *this_object; 00106 00107 new_decor_object = pick_random_object(decor_map); 00108 this_object = arch_to_object(new_decor_object->arch); 00109 copy_object(new_decor_object, this_object); 00110 this_object->x = x; 00111 this_object->y = y; 00112 /* it screws things up if decor can stop people */ 00113 this_object->move_block = MOVE_BLOCK_DEFAULT; 00114 insert_ob_in_map(this_object, map, NULL, 0); 00115 number_to_place--; 00116 } else 00117 failures++; 00118 } 00119 break; 00120 } 00121 00122 default: { /* place decor objects everywhere: tile the map. */ 00123 int i, j; 00124 00125 for (i = 1; i < RP->Xsize-1; i++) 00126 for (j = 1; j < RP->Ysize-1; j++) { 00127 if (maze[i][j] == 0) { 00128 object *new_decor_object, *this_object; 00129 00130 new_decor_object = pick_random_object(decor_map); 00131 this_object = arch_to_object(new_decor_object->arch); 00132 copy_object(new_decor_object, this_object); 00133 this_object->x = i; 00134 this_object->y = j; 00135 /* it screws things up if decor can stop people */ 00136 this_object->move_block = MOVE_BLOCK_DEFAULT; 00137 insert_ob_in_map(this_object, map, NULL, 0); 00138 } 00139 } 00140 break; 00141 } 00142 } 00143 }