ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/standalone.C
Revision: 1.12
Committed: Sun Dec 31 19:02:24 2006 UTC (17 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.11: +33 -32 lines
Log Message:
reindent, minor changes

File Contents

# User Rev Content
1 root 1.12
2 elmex 1.1 /*
3     CrossFire, A Multiplayer game for X-windows
4    
5     Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6     Copyright (C) 1992 Frank Tore Johansen
7    
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your 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 GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21    
22 root 1.4 The authors can be reached via e-mail at <crossfire@schmorp.de>
23 elmex 1.1 */
24    
25     #define LO_NEWFILE 2
26    
27     /* the main routine for making a standalone version. */
28    
29     #include <time.h>
30     #include <stdio.h>
31     #include <global.h>
32     #include <maze_gen.h>
33     #include <room_gen.h>
34     #include <random_map.h>
35     #include <rproto.h>
36    
37 root 1.3 int
38     main (int argc, char *argv[])
39     {
40     char InFileName[1024], OutFileName[1024];
41 root 1.5 maptile *newMap;
42 root 1.11 random_map_params rp;
43 elmex 1.1 FILE *fp;
44    
45 root 1.3 if (argc < 3)
46     {
47     printf ("\nUsage: %s inputfile outputfile\n", argv[0]);
48     exit (0);
49     }
50     strcpy (InFileName, argv[1]);
51     strcpy (OutFileName, argv[2]);
52    
53     init_globals ();
54     init_library ();
55     init_archetypes ();
56     init_artifacts ();
57     init_formulae ();
58     init_readable ();
59    
60     init_gods ();
61 root 1.11 memset (&rp, 0, sizeof (random_map_params));
62 root 1.3 rp.Xsize = -1;
63     rp.Ysize = -1;
64     if ((fp = fopen (InFileName, "r")) == NULL)
65     {
66     fprintf (stderr, "\nError: can not open %s\n", InFileName);
67     exit (1);
68     }
69     load_parameters (fp, LO_NEWFILE, &rp);
70     fclose (fp);
71     newMap = generate_random_map (OutFileName, &rp);
72     new_save_map (newMap, 1);
73     exit (0);
74 elmex 1.1 }
75    
76 root 1.3 void
77 root 1.5 set_map_timeout (maptile *)
78 root 1.3 {
79     } /* doesn't need to do anything */
80 elmex 1.1
81     #include <global.h>
82    
83    
84     /* some plagarized code from apply.c--I needed just these two functions
85     without all the rest of the junk, so.... */
86 root 1.3 int
87     auto_apply (object *op)
88     {
89 elmex 1.1 object *tmp = NULL;
90     int i;
91    
92 root 1.3 switch (op->type)
93     {
94 root 1.12 case SHOP_FLOOR:
95     if (!op->has_random_items ())
96     return 0;
97     do
98     {
99     i = 10; /* let's give it 10 tries */
100     while ((tmp = generate_treasure (op->randomitems, op->stats.exp ? op->stats.exp : 5)) == NULL && --i);
101     if (tmp == NULL)
102     return 0;
103     if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
104     {
105     tmp->destroy ();
106     tmp = NULL;
107     }
108     }
109     while (!tmp);
110    
111     tmp->x = op->x, tmp->y = op->y;
112     SET_FLAG (tmp, FLAG_UNPAID);
113     insert_ob_in_map (tmp, op->map, NULL, 0);
114     CLEAR_FLAG (op, FLAG_AUTO_APPLY);
115     identify (tmp);
116     break;
117    
118     case TREASURE:
119     if (op->has_random_items ())
120     while ((op->stats.hp--) > 0)
121     create_treasure (op->randomitems, op, GT_ENVIRONMENT,
122     op->stats.exp ? op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0);
123     op->remove ();
124     op->destroy ();
125     break;
126 root 1.3 }
127 elmex 1.1
128     return tmp ? 1 : 0;
129     }
130    
131     /* fix_auto_apply goes through the entire map (only the first time
132     * when an original map is loaded) and performs special actions for
133     * certain objects (most initialization of chests and creation of
134     * treasures and stuff). Calls auto_apply if appropriate.
135     */
136    
137 root 1.3 void
138 root 1.5 fix_auto_apply (maptile *m)
139 root 1.3 {
140     object *tmp, *above = NULL;
141     int x, y;
142    
143 root 1.10 for (x = 0; x < m->width; x++)
144     for (y = 0; y < m->height; y++)
145 root 1.9 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above)
146 root 1.3 {
147     above = tmp->above;
148    
149     if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
150     auto_apply (tmp);
151     else if (tmp->type == TREASURE)
152     {
153 root 1.8 if (tmp->has_random_items ())
154 root 1.3 while ((tmp->stats.hp--) > 0)
155     create_treasure (tmp->randomitems, tmp, 0, m->difficulty, 0);
156     }
157     if (tmp && tmp->arch && tmp->type != PLAYER && tmp->type != TREASURE && tmp->randomitems)
158     {
159     if (tmp->type == CONTAINER)
160     {
161 root 1.8 if (tmp->has_random_items ())
162 root 1.3 while ((tmp->stats.hp--) > 0)
163     create_treasure (tmp->randomitems, tmp, 0, m->difficulty, 0);
164     }
165 root 1.8 else if (tmp->has_random_items ())
166 root 1.3 create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0);
167     }
168 elmex 1.1 }
169 root 1.10 for (x = 0; x < m->width; x++)
170     for (y = 0; y < m->height; y++)
171 root 1.9 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
172 root 1.3 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL))
173     check_trigger (tmp, tmp->above);
174 elmex 1.1 }
175    
176     /**
177     * Those are dummy functions defined to resolve all symboles.
178     * Added as part of glue cleaning.
179     * Ryo 2005-07-15
180     **/
181    
182 root 1.3 void
183     new_draw_info (int a, int b, const object *ob, const char *txt)
184     {
185     fprintf (logfile, "%s\n", txt);
186     }
187    
188     void
189 root 1.5 new_info_map (int color, maptile *map, const char *str)
190 root 1.3 {
191     fprintf (logfile, "new_info_map: %s\n", str);
192     }
193    
194     void
195     move_teleporter (object *ob)
196     {
197     }
198    
199     void
200     move_firewall (object *ob)
201     {
202     }
203    
204     void
205     move_duplicator (object *ob)
206     {
207     }
208    
209     void
210     move_marker (object *ob)
211     {
212     }
213    
214     void
215     move_creator (object *ob)
216     {
217     }
218    
219     void
220     emergency_save (int x)
221     {
222     }
223    
224     void
225     clean_tmp_files (void)
226     {
227     }
228    
229     void
230     esrv_send_item (object *ob, object *obx)
231     {
232     }
233    
234     void
235     dragon_ability_gain (object *ob, int x, int y)
236     {
237     }
238    
239     void
240     weather_effect (const char *c)
241     {
242     }
243    
244     void
245 root 1.5 set_darkness_map (maptile *m)
246 root 1.3 {
247     }
248    
249     void
250     move_apply (object *ob, object *obt, object *obx)
251     {
252     }
253    
254     object *
255     find_skill_by_number (object *ob, int x)
256     {
257     return NULL;
258     }
259    
260     void
261     esrv_del_item (player *pl, int tag)
262     {
263     }
264    
265     void
266     esrv_update_spells (player *pl)
267     {
268     }
269    
270     void
271     monster_check_apply (object *ob, object *obt)
272     {
273     }
274    
275     void
276     trap_adjust (object *ob, int x)
277     {
278     }