1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_random_map_c = |
|
|
4 | * "$Id: random_map.C,v 1.3 2006/09/10 16:06:37 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | #include <time.h> |
24 | #include <time.h> |
31 | #include <stdio.h> |
25 | #include <stdio.h> |
32 | #include <global.h> |
26 | #include <global.h> |
… | |
… | |
55 | printf ("\n"); |
49 | printf ("\n"); |
56 | } |
50 | } |
57 | } |
51 | } |
58 | printf ("\n"); |
52 | printf ("\n"); |
59 | } |
53 | } |
60 | EXTERN FILE *logfile; |
54 | |
61 | mapstruct * |
55 | extern FILE *logfile; |
|
|
56 | |
|
|
57 | maptile * |
62 | generate_random_map (const char *OutFileName, RMParms * RP) |
58 | generate_random_map (const char *OutFileName, RMParms * RP) |
63 | { |
59 | { |
64 | char **layout, buf[HUGE_BUF]; |
60 | char **layout, buf[HUGE_BUF]; |
65 | mapstruct *theMap; |
61 | maptile *theMap; |
66 | int i; |
62 | int i; |
67 | |
63 | |
68 | /* pick a random seed, or use the one from the input file */ |
64 | /* pick a random seed, or use the one from the input file */ |
69 | if (RP->random_seed == 0) |
65 | if (RP->random_seed == 0) |
70 | RP->random_seed = time (0); |
66 | RP->random_seed = time (0); |
… | |
… | |
74 | write_map_parameters_to_string (buf, RP); |
70 | write_map_parameters_to_string (buf, RP); |
75 | |
71 | |
76 | if (RP->difficulty == 0) |
72 | if (RP->difficulty == 0) |
77 | { |
73 | { |
78 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
74 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
|
|
75 | |
79 | if (RP->difficulty_increase > 0.001) |
76 | if (RP->difficulty_increase > 0.001) |
80 | { |
|
|
81 | RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); |
77 | RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); |
|
|
78 | |
82 | if (RP->difficulty < 1) |
79 | if (RP->difficulty < 1) |
83 | RP->difficulty = 1; |
80 | RP->difficulty = 1; |
84 | } |
|
|
85 | } |
81 | } |
86 | else |
82 | else |
87 | RP->difficulty_given = 1; |
83 | RP->difficulty_given = 1; |
88 | |
84 | |
89 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
85 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
90 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
86 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
|
|
87 | |
91 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
88 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
92 | RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
89 | RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
93 | |
90 | |
94 | if (RP->expand2x > 0) |
91 | if (RP->expand2x > 0) |
95 | { |
92 | { |
… | |
… | |
116 | |
113 | |
117 | /* allocate the map and set the floor */ |
114 | /* allocate the map and set the floor */ |
118 | theMap = make_map_floor (layout, RP->floorstyle, RP); |
115 | theMap = make_map_floor (layout, RP->floorstyle, RP); |
119 | |
116 | |
120 | /* set the name of the map. */ |
117 | /* set the name of the map. */ |
121 | strcpy (theMap->path, OutFileName); |
118 | theMap->path = OutFileName; |
122 | |
119 | |
123 | /* set region */ |
120 | /* set region */ |
124 | theMap->region = RP->region; |
121 | theMap->region = RP->region; |
125 | |
122 | |
126 | /* create walls unless the wallstyle is "none" */ |
123 | /* create walls unless the wallstyle is "none" */ |
… | |
… | |
143 | /* create monsters unless the monsterstyle is "none" */ |
140 | /* create monsters unless the monsterstyle is "none" */ |
144 | if (strcmp (RP->monsterstyle, "none")) |
141 | if (strcmp (RP->monsterstyle, "none")) |
145 | place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); |
142 | place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); |
146 | |
143 | |
147 | /* treasures needs to have a proper difficulty set for the map. */ |
144 | /* treasures needs to have a proper difficulty set for the map. */ |
148 | theMap->difficulty = calculate_difficulty (theMap); |
145 | theMap->difficulty = theMap->estimate_difficulty (); |
149 | |
146 | |
150 | /* create treasure unless the treasurestyle is "none" */ |
147 | /* create treasure unless the treasurestyle is "none" */ |
151 | if (strcmp (RP->treasurestyle, "none")) |
148 | if (strcmp (RP->treasurestyle, "none")) |
152 | place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); |
149 | place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); |
153 | |
150 | |
… | |
… | |
163 | /* free the layout */ |
160 | /* free the layout */ |
164 | for (i = 0; i < RP->Xsize; i++) |
161 | for (i = 0; i < RP->Xsize; i++) |
165 | free (layout[i]); |
162 | free (layout[i]); |
166 | free (layout); |
163 | free (layout); |
167 | |
164 | |
168 | theMap->msg = strdup_local (buf); |
165 | theMap->msg = strdup (buf); |
169 | |
166 | |
170 | return theMap; |
167 | return theMap; |
171 | } |
168 | } |
172 | |
|
|
173 | |
169 | |
174 | /* function selects the layout function and gives it whatever |
170 | /* function selects the layout function and gives it whatever |
175 | arguments it needs. */ |
171 | arguments it needs. */ |
176 | char ** |
172 | char ** |
177 | layoutgen (RMParms * RP) |
173 | layoutgen (RMParms * RP) |
… | |
… | |
996 | void |
992 | void |
997 | copy_object_with_inv (object *src_ob, object *dest_ob) |
993 | copy_object_with_inv (object *src_ob, object *dest_ob) |
998 | { |
994 | { |
999 | object *walk, *tmp; |
995 | object *walk, *tmp; |
1000 | |
996 | |
1001 | copy_object (src_ob, dest_ob); |
997 | src_ob->copy_to (dest_ob); |
1002 | |
998 | |
1003 | for (walk = src_ob->inv; walk != NULL; walk = walk->below) |
999 | for (walk = src_ob->inv; walk != NULL; walk = walk->below) |
1004 | { |
1000 | { |
1005 | tmp = get_object (); |
1001 | tmp = object::create (); |
1006 | copy_object (walk, tmp); |
1002 | walk->copy_to (tmp); |
1007 | insert_ob_in_ob (tmp, dest_ob); |
1003 | insert_ob_in_ob (tmp, dest_ob); |
1008 | } |
1004 | } |
1009 | } |
1005 | } |