Crossfire Server, Branches 1.12  R18729
standalone.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_standalone_c =
3  * "$Id: standalone.c 11578 2009-02-23 22:02:27Z lalo $";
4  */
5 
6 /*
7  CrossFire, A Multiplayer game for X-windows
8 
9  Copyright (C) 2002-2006 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 #define LO_NEWFILE 2
30 
31 /* the main routine for making a standalone version. */
32 
33 #include <time.h>
34 #include <stdio.h>
35 #include <global.h>
36 #include <maze_gen.h>
37 #include <room_gen.h>
38 #include <random_map.h>
39 #include <rproto.h>
40 
41 int main(int argc, char *argv[]) {
42  char InFileName[1024], OutFileName[1024];
43  mapstruct *newMap;
44  RMParms rp;
45  FILE *fp;
46 
47  if (argc < 3) {
48  printf("\nUsage: %s inputfile outputfile\n", argv[0]);
49  exit(0);
50  }
51 
52  strcpy(InFileName, argv[1]);
53  strcpy(OutFileName, argv[2]);
54 
55  init_globals();
56  init_library();
59  init_formulae();
60  init_readable();
61 
62  init_gods();
63  memset(&rp, 0, sizeof(RMParms));
64  rp.Xsize = -1;
65  rp.Ysize = -1;
66  if ((fp = fopen(InFileName, "r")) == NULL) {
67  fprintf(stderr, "\nError: can not open %s\n", InFileName);
68  exit(1);
69  }
70  load_parameters(fp, LO_NEWFILE, &rp);
71  fclose(fp);
72  newMap = generate_random_map(OutFileName, &rp, NULL);
73  save_map(newMap, SAVE_MODE_INPLACE);
74  exit(0);
75 }
76 
77 void set_map_timeout(mapstruct *oldmap) {
78  /* doesn't need to do anything */
79 }
80 
81 #include <global.h>
82 
83 /* some plagarized code from apply.c--I needed just these two functions
84 without all the rest of the junk, so.... */
85 int auto_apply(object *op) {
86  object *tmp = NULL;
87  int i;
88 
89  switch (op->type) {
90  case SHOP_FLOOR:
91  if (!HAS_RANDOM_ITEMS(op))
92  return 0;
93  do {
94  i = 10; /* let's give it 10 tries */
95  while ((tmp = generate_treasure(op->randomitems, op->stats.exp ? op->stats.exp : 5)) == NULL && --i)
96  ;
97  if (tmp == NULL)
98  return 0;
99  if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) {
100  free_object(tmp);
101  tmp = NULL;
102  }
103  } while (!tmp);
104 
105  tmp->x = op->x,
106  tmp->y = op->y;
107  SET_FLAG(tmp, FLAG_UNPAID);
108  insert_ob_in_map(tmp, op->map, NULL, 0);
110  identify(tmp);
111  break;
112 
113  case TREASURE:
114  if (HAS_RANDOM_ITEMS(op))
115  while ((op->stats.hp--) > 0)
116  create_treasure(op->randomitems, op, GT_ENVIRONMENT, op->stats.exp ? op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0);
117  remove_ob(op);
118  free_object(op);
119  break;
120  }
121 
122  return tmp ? 1 : 0;
123 }
124 
125 /* fix_auto_apply goes through the entire map (only the first time
126  * when an original map is loaded) and performs special actions for
127  * certain objects (most initialization of chests and creation of
128  * treasures and stuff). Calls auto_apply if appropriate.
129  */
131  object *tmp, *above = NULL;
132  int x, y;
133 
134  for (x = 0; x < MAP_WIDTH(m); x++)
135  for (y = 0; y < MAP_HEIGHT(m); y++)
136  for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = above) {
137  above = tmp->above;
138 
139  if (QUERY_FLAG(tmp, FLAG_AUTO_APPLY))
140  auto_apply(tmp);
141  else if (tmp->type == TREASURE) {
142  if (HAS_RANDOM_ITEMS(tmp))
143  while ((tmp->stats.hp--) > 0)
144  create_treasure(tmp->randomitems, tmp, 0, m->difficulty, 0);
145  }
146  if (tmp && tmp->arch
147  && tmp->type != PLAYER
148  && tmp->type != TREASURE
149  && tmp->randomitems) {
150  if (tmp->type == CONTAINER) {
151  if (HAS_RANDOM_ITEMS(tmp))
152  while ((tmp->stats.hp--) > 0)
153  create_treasure(tmp->randomitems, tmp, 0, m->difficulty, 0);
154  } else if (HAS_RANDOM_ITEMS(tmp))
155  create_treasure(tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0);
156  }
157  }
158  for (x = 0; x < MAP_WIDTH(m); x++)
159  for (y = 0; y < MAP_HEIGHT(m); y++)
160  for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above)
161  if (tmp->above
162  && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL))
163  check_trigger(tmp, tmp->above);
164 }
165 
171 void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *txt, const char *txt2) {
172  fprintf(logfile, "%s\n", txt);
173 }
174 
175 void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format, ...) {
176  va_list ap;
177 
178  va_start(ap, old_format);
179  vfprintf(logfile, old_format, ap);
180  va_end(ap);
181 }
182 
183 
184 void ext_info_map(int color, const mapstruct *map, uint8 type, uint8 subtype, const char *str1, const char *str2) {
185  fprintf(logfile, "ext_info_map: %s\n", str2);
186 }
187 
188 void move_firewall(object *ob) {
189 }
190 
191 void emergency_save(int x) {
192 }
193 
194 void clean_tmp_files(void) {
195 }
196 
197 void esrv_send_item(object *ob, object *obx) {
198 }
199 
200 void esrv_update_item(int flags, object *pl, object *op) {
201 }
202 
203 void dragon_ability_gain(object *ob, int x, int y) {
204 }
205 
207 }
208 
209 object *find_skill_by_number(object *who, int skillno) {
210  return NULL;
211 }
212 
213 void esrv_del_item(player *pl, int tag) {
214 }
215 
217 }
218 
219 void monster_check_apply(object *ob, object *obt) {
220 }
221 
222 void trap_adjust(object *ob, int x) {
223 }
224 
225 int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix) {
226  return 0;
227 }
228 
229 int execute_global_event(int eventcode, ...) {
230  return 0;
231 }
EXTERN FILE * logfile
Definition: global.h:220
int execute_global_event(int eventcode,...)
Definition: standalone.c:229
Definition: player.h:146
#define FLAG_DAMNED
Definition: define.h:614
#define FLAG_UNPAID
Definition: define.h:532
void set_map_timeout(mapstruct *oldmap)
Definition: standalone.c:77
#define SET_FLAG(xyz, p)
Definition: define.h:510
int main(int argc, char *argv[])
Definition: standalone.c:41
void esrv_del_item(player *pl, int tag)
Definition: standalone.c:213
mapstruct * generate_random_map(const char *OutFileName, RMParms *RP, char **use_layout)
Definition: random_map.c:80
void esrv_update_spells(player *pl)
Definition: standalone.c:216
struct treasureliststruct * randomitems
Definition: object.h:236
#define MAP_HEIGHT(m)
Definition: map.h:99
void init_archetypes(void)
Definition: arch.c:195
void init_globals(void)
Definition: init.c:263
void dragon_ability_gain(object *ob, int x, int y)
Definition: standalone.c:203
void fix_auto_apply(mapstruct *m)
Definition: standalone.c:130
sint64 exp
Definition: living.h:88
struct obj * above
Definition: object.h:146
void init_library(void)
Definition: init.c:201
int auto_apply(object *op)
Definition: standalone.c:85
sint16 x
Definition: object.h:179
void ext_info_map(int color, const mapstruct *map, uint8 type, uint8 subtype, const char *str1, const char *str2)
Definition: standalone.c:184
#define PLAYER
Definition: define.h:113
sint16 hp
Definition: living.h:81
void init_formulae(void)
Definition: recipe.c:159
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:499
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: standalone.c:225
void remove_ob(object *op)
Definition: object.c:1515
#define SHOP_FLOOR
Definition: define.h:230
void esrv_send_item(object *ob, object *obx)
Definition: standalone.c:197
void monster_check_apply(object *ob, object *obt)
Definition: standalone.c:219
struct mapdef * map
Definition: object.h:155
void identify(object *op)
Definition: item.c:1447
uint16 difficulty
Definition: map.h:364
unsigned char uint8
Definition: global.h:75
void esrv_update_item(int flags, object *pl, object *op)
Definition: standalone.c:200
void set_darkness_map(mapstruct *m)
Definition: standalone.c:206
sint16 y
Definition: object.h:179
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *txt, const char *txt2)
Definition: standalone.c:171
#define TRIGGER_PEDESTAL
Definition: define.h:144
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define CLEAR_FLAG(xyz, p)
Definition: define.h:512
#define TRIGGER_BUTTON
Definition: define.h:142
void init_readable(void)
Definition: readable.c:952
#define SAVE_MODE_INPLACE
Definition: map.h:142
void move_firewall(object *ob)
Definition: standalone.c:188
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1992
int Ysize
Definition: random_map.h:60
object * find_skill_by_number(object *who, int skillno)
Definition: standalone.c:209
static const flag_definition flags[]
int Xsize
Definition: random_map.h:59
int save_map(mapstruct *m, int flag)
Definition: map.c:1453
#define FLAG_CURSED
Definition: define.h:613
void emergency_save(int x)
Definition: standalone.c:191
#define FLAG_AUTO_APPLY
Definition: define.h:546
int load_parameters(FILE *fp, int bufstate, RMParms *RP)
#define CONTAINER
Definition: define.h:306
living stats
Definition: object.h:219
struct archt * arch
Definition: object.h:263
#define MAP_WIDTH(m)
Definition: map.h:97
void init_gods(void)
Definition: holy.c:63
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
#define TREASURE
Definition: define.h:116
int check_trigger(object *op, object *cause)
Definition: button.c:525
#define LO_NEWFILE
Definition: standalone.c:29
object * generate_treasure(treasurelist *t, int difficulty)
Definition: treasure.c:524
void free_object(object *ob)
Definition: object.c:1238
void trap_adjust(object *ob, int x)
Definition: standalone.c:222
Definition: map.h:346
void clean_tmp_files(void)
Definition: standalone.c:194
#define HAS_RANDOM_ITEMS(op)
Definition: define.h:470
uint8 type
Definition: object.h:189
void init_artifacts(void)
Definition: treasure.c:1539
void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format,...)
Definition: standalone.c:175