ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/standalone.C
Revision: 1.3
Committed: Sun Sep 10 16:06:37 2006 UTC (17 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.2: +210 -177 lines
Log Message:
indent

File Contents

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