Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_standalone_c = 00003 * "$Id: standalone.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* 00007 CrossFire, A Multiplayer game for X-windows 00008 00009 Copyright (C) 2002-2006 Mark Wedel & Crossfire Development Team 00010 Copyright (C) 1992 Frank Tore Johansen 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 00026 The authors can be reached via e-mail at crossfire-devel@real-time.com 00027 */ 00028 00029 #define LO_NEWFILE 2 00030 00031 /* the main routine for making a standalone version. */ 00032 00033 #include <time.h> 00034 #include <stdio.h> 00035 #include <global.h> 00036 #include <maze_gen.h> 00037 #include <room_gen.h> 00038 #include <random_map.h> 00039 #include <rproto.h> 00040 00041 int main(int argc, char *argv[]) { 00042 char InFileName[1024], OutFileName[1024]; 00043 mapstruct *newMap; 00044 RMParms rp; 00045 FILE *fp; 00046 00047 if (argc < 3) { 00048 printf("\nUsage: %s inputfile outputfile\n", argv[0]); 00049 exit(0); 00050 } 00051 00052 strcpy(InFileName, argv[1]); 00053 strcpy(OutFileName, argv[2]); 00054 00055 init_globals(); 00056 init_library(); 00057 init_archetypes(); 00058 init_artifacts(); 00059 init_formulae(); 00060 init_readable(); 00061 00062 init_gods(); 00063 memset(&rp, 0, sizeof(RMParms)); 00064 rp.Xsize = -1; 00065 rp.Ysize = -1; 00066 if ((fp = fopen(InFileName, "r")) == NULL) { 00067 fprintf(stderr, "\nError: can not open %s\n", InFileName); 00068 exit(1); 00069 } 00070 load_parameters(fp, LO_NEWFILE, &rp); 00071 fclose(fp); 00072 newMap = generate_random_map(OutFileName, &rp, NULL); 00073 save_map(newMap, SAVE_MODE_INPLACE); 00074 exit(0); 00075 } 00076 00077 void set_map_timeout(mapstruct *oldmap) { 00078 /* doesn't need to do anything */ 00079 } 00080 00081 #include <global.h> 00082 00083 /* some plagarized code from apply.c--I needed just these two functions 00084 without all the rest of the junk, so.... */ 00085 int auto_apply(object *op) { 00086 object *tmp = NULL; 00087 int i; 00088 00089 switch (op->type) { 00090 case SHOP_FLOOR: 00091 if (!HAS_RANDOM_ITEMS(op)) 00092 return 0; 00093 do { 00094 i = 10; /* let's give it 10 tries */ 00095 while ((tmp = generate_treasure(op->randomitems, op->stats.exp ? op->stats.exp : 5)) == NULL && --i) 00096 ; 00097 if (tmp == NULL) 00098 return 0; 00099 if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) { 00100 free_object(tmp); 00101 tmp = NULL; 00102 } 00103 } while (!tmp); 00104 00105 tmp->x = op->x, 00106 tmp->y = op->y; 00107 SET_FLAG(tmp, FLAG_UNPAID); 00108 insert_ob_in_map(tmp, op->map, NULL, 0); 00109 CLEAR_FLAG(op, FLAG_AUTO_APPLY); 00110 identify(tmp); 00111 break; 00112 00113 case TREASURE: 00114 if (HAS_RANDOM_ITEMS(op)) 00115 while ((op->stats.hp--) > 0) 00116 create_treasure(op->randomitems, op, GT_ENVIRONMENT, op->stats.exp ? op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); 00117 remove_ob(op); 00118 free_object(op); 00119 break; 00120 } 00121 00122 return tmp ? 1 : 0; 00123 } 00124 00125 /* fix_auto_apply goes through the entire map (only the first time 00126 * when an original map is loaded) and performs special actions for 00127 * certain objects (most initialization of chests and creation of 00128 * treasures and stuff). Calls auto_apply if appropriate. 00129 */ 00130 void fix_auto_apply(mapstruct *m) { 00131 object *tmp, *above = NULL; 00132 int x, y; 00133 00134 for (x = 0; x < MAP_WIDTH(m); x++) 00135 for (y = 0; y < MAP_HEIGHT(m); y++) 00136 for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = above) { 00137 above = tmp->above; 00138 00139 if (QUERY_FLAG(tmp, FLAG_AUTO_APPLY)) 00140 auto_apply(tmp); 00141 else if (tmp->type == TREASURE) { 00142 if (HAS_RANDOM_ITEMS(tmp)) 00143 while ((tmp->stats.hp--) > 0) 00144 create_treasure(tmp->randomitems, tmp, 0, m->difficulty, 0); 00145 } 00146 if (tmp && tmp->arch 00147 && tmp->type != PLAYER 00148 && tmp->type != TREASURE 00149 && tmp->randomitems) { 00150 if (tmp->type == CONTAINER) { 00151 if (HAS_RANDOM_ITEMS(tmp)) 00152 while ((tmp->stats.hp--) > 0) 00153 create_treasure(tmp->randomitems, tmp, 0, m->difficulty, 0); 00154 } else if (HAS_RANDOM_ITEMS(tmp)) 00155 create_treasure(tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0); 00156 } 00157 } 00158 for (x = 0; x < MAP_WIDTH(m); x++) 00159 for (y = 0; y < MAP_HEIGHT(m); y++) 00160 for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above) 00161 if (tmp->above 00162 && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) 00163 check_trigger(tmp, tmp->above); 00164 } 00165 00171 void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *txt, const char *txt2) { 00172 fprintf(logfile, "%s\n", txt); 00173 } 00174 00175 void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format, ...) { 00176 va_list ap; 00177 00178 va_start(ap, old_format); 00179 vfprintf(logfile, old_format, ap); 00180 va_end(ap); 00181 } 00182 00183 00184 void ext_info_map(int color, const mapstruct *map, uint8 type, uint8 subtype, const char *str1, const char *str2) { 00185 fprintf(logfile, "ext_info_map: %s\n", str2); 00186 } 00187 00188 void move_firewall(object *ob) { 00189 } 00190 00191 void emergency_save(int x) { 00192 } 00193 00194 void clean_tmp_files(void) { 00195 } 00196 00197 void esrv_send_item(object *ob, object *obx) { 00198 } 00199 00200 void esrv_update_item(int flags, object *pl, object *op) { 00201 } 00202 00203 void dragon_ability_gain(object *ob, int x, int y) { 00204 } 00205 00206 void set_darkness_map(mapstruct *m) { 00207 } 00208 00209 object *find_skill_by_number(object *who, int skillno) { 00210 return NULL; 00211 } 00212 00213 void esrv_del_item(player *pl, int tag) { 00214 } 00215 00216 void esrv_update_spells(player *pl) { 00217 } 00218 00219 void monster_check_apply(object *ob, object *obt) { 00220 } 00221 00222 void trap_adjust(object *ob, int x) { 00223 } 00224 00225 int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix) { 00226 return 0; 00227 } 00228 00229 int execute_global_event(int eventcode, ...) { 00230 return 0; 00231 }