1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
/* File: levels.c */
/* Purpose: Levels functions */
/*
* Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
*
* This software may be copied and distributed for educational, research, and
* not for profit purposes provided that this copyright and statement are
* included in all such copies.
*/
#include "angband.h"
/*
* Return the parameter of the given command in the given file
*/
static int start_line = 0;
bool_ get_command(const char *file, char comm, char *param)
{
char buf[1024];
int i = -1;
FILE *fp;
char *s;
/* Build the filename */
path_build(buf, 1024, ANGBAND_DIR_DNGN, file);
/* Open the file */
fp = my_fopen(buf, "r");
/* The file exists ? */
/* no ? then command not found */
if (!fp) return FALSE;
/* Parse to the end of the file or when the command is found */
while (0 == my_fgets(fp, buf, 1024))
{
/* Advance the line number */
i++;
/* Skip comments and blank lines */
if (!buf[0] || (buf[0] == '#')) continue;
/* Is it the command we are looking for ? */
if ((i > start_line) && (buf[0] == comm))
{
/* Acquire the text */
s = buf + 2;
start_line = i;
/* Get the parameter */
strcpy(param, s);
/* Close it */
my_fclose(fp);
return TRUE;
}
}
/* Close it */
my_fclose(fp);
/* Assume command not found */
return FALSE;
}
/*
* Return the dungeon branch starting form the current dungeon/level
*/
int get_branch()
{
char file[20], buf[5];
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
/* Get and return the branch */
start_line = -1;
if (get_command(file, 'B', buf)) return (atoi(buf));
/* No branch ? return 0 */
else return 0;
}
/*
* Return the father dungeon branch
*/
int get_fbranch()
{
char file[20], buf[5];
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
/* Get and return the branch */
start_line = -1;
if (get_command(file, 'A', buf)) return (atoi(buf));
/* No branch ? return 0 */
else return 0;
}
/*
* Return the father dungeon level
*/
int get_flevel()
{
char file[20], buf[5];
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
/* Get and return the level */
start_line = -1;
if (get_command(file, 'L', buf)) return (atoi(buf));
/* No level ? return 0 */
else return 0;
}
/*
* Return the extension of the savefile for the level
*/
bool_ get_dungeon_save(char *buf)
{
char file[20];
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
/* Get and return the level */
start_line = -1;
if (get_command(file, 'S', buf)) return (TRUE);
else return FALSE;
}
/*
* Return the level generator
*/
bool_ get_dungeon_generator(char *buf)
{
char file[20];
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
/* Get and return the level */
start_line = -1;
if (get_command(file, 'G', buf)) return (TRUE);
else return FALSE;
}
/*
* Return the special level
*/
bool_ get_dungeon_special(char *buf)
{
char file[20];
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
/* Get and return the level */
start_line = -1;
if (get_command(file, 'U', buf)) return (TRUE);
else return FALSE;
}
/*
* Return the special level name
*/
bool_ get_dungeon_name(char *buf)
{
char file[20];
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
/* Get and return the level */
start_line = -1;
if (get_command(file, 'N', buf)) return (TRUE);
else return FALSE;
}
/*
* Return the special level name
*/
void get_level_flags()
{
char file[20];
char buf[1024], *s, *t;
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
start_line = -1;
/* Parse until done */
while (get_command(file, 'F', buf))
{
/* Parse every entry textually */
for (s = buf; *s; )
{
/* Find the end of this entry */
for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
/* Nuke and skip any dividers */
if (*t)
{
*t++ = '\0';
while (*t == ' ' || *t == '|') t++;
}
/* Parse this entry */
if (0 != grab_one_dungeon_flag(&dungeon_flags1, &dungeon_flags2, s)) return;
/* Start the next entry */
s = t;
}
}
}
/*
* Return the special level desc
*/
bool_ get_level_desc(char *buf)
{
char file[20];
sprintf(file, "dun%d.%d", dungeon_type, dun_level - d_info[dungeon_type].mindepth);
/* Get and return the level */
start_line = -1;
if (get_command(file, 'D', buf)) return (TRUE);
else return FALSE;
}
|