ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/decor.c
Revision: 1.2
Committed: Sun Aug 13 17:16:03 2006 UTC (17 years, 9 months ago) by elmex
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
State: FILE REMOVED
Log Message:
Made server compile with C++.
Removed cfanim plugin and crossedit.
C++ here we come.

File Contents

# Content
1 /*
2 * static char *rcsid_decor_ =
3 * "$Id$";
4 */
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
29
30 #include <global.h>
31 #include <random_map.h>
32 #include <rproto.h>
33
34 #define NR_DECOR_OPTIONS 1
35
36 /* return a simple count of objects in the map at x,y. */
37
38 int obj_count_in_map(mapstruct *map,int x,int y) {
39 int count=0;
40 object *tmp;
41 for(tmp=get_map_ob(map,x,y);tmp!=NULL;tmp=tmp->above)
42 count++;
43 return count;
44 }
45 /* put the decor into the map. Right now, it's very primitive. */
46
47 void put_decor(mapstruct *map,char **maze,char *decorstyle,int decor_option,RMParms *RP) {
48 mapstruct *decor_map;
49 char style_name[256];
50
51 sprintf(style_name,"/styles/decorstyles");
52
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 };
59 switch(decor_option) {
60 case 0: break;
61 case 1: /* random placement of decor objects. */
62 {
63 int number_to_place = RANDOM() % ( (RP->Xsize *RP->Ysize) / 5);
64 int failures=0;
65 object *new_decor_object;
66 while(failures < 100 && number_to_place > 0) {
67 int x,y;
68 x = RANDOM() % (RP->Xsize-2) +1;
69 y = RANDOM() % (RP->Ysize-2) +1;
70 if(maze[x][y]==0 && obj_count_in_map(map,x,y)<2) /* empty */
71 {
72 object *this_object;
73 new_decor_object = pick_random_object(decor_map);
74 this_object = arch_to_object(new_decor_object->arch);
75 copy_object(new_decor_object,this_object);
76 this_object->x = x;
77 this_object->y = y;
78 /* it screws things up if decor can stop people */
79 this_object->move_block = MOVE_BLOCK_DEFAULT;
80 insert_ob_in_map(this_object,map,NULL,0);
81 number_to_place--;
82 }
83 else failures++;
84 }
85 break;
86 default: /* place decor objects everywhere: tile the map. */
87 {
88 int i,j;
89 for(i=1;i<RP->Xsize-1;i++) for(j=1;j<RP->Ysize-1;j++) {
90 if(maze[i][j]==0) {
91 object *new_decor_object, *this_object;
92
93 new_decor_object = pick_random_object(decor_map);
94 this_object = arch_to_object(new_decor_object->arch);
95 copy_object(new_decor_object,this_object);
96 this_object->x = i;
97 this_object->y = j;
98 /* it screws things up if decor can stop people */
99 this_object->move_block = MOVE_BLOCK_DEFAULT;
100 insert_ob_in_map(this_object,map,NULL,0);
101 }
102 }
103
104 }
105 break;
106
107 }
108 }
109 }