X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Ffiles.c;h=d78389ff4da1ea5d7038d5eb93ace9be11695d39;hb=HEAD;hp=704ca271b9f3c40f6fae889dec624f7ad6533f64;hpb=9df860ab2839447c7143bbe705a573df152d7734;p=flatwaifu.git diff --git a/src/files.c b/src/files.c deleted file mode 100644 index 704ca27..0000000 --- a/src/files.c +++ /dev/null @@ -1,191 +0,0 @@ -/* Copyright (C) 1996-1997 Aleksey Volynskov - * Copyright (C) 2011 Rambo - * Copyright (C) 2020 SovietPony - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3 of the License ONLY. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "glob.h" -#include -#include -#include -#include -#ifdef UNIX -# include -#endif -#include "files.h" -#include "map.h" -#include "my.h" -#include "game.h" -#include "view.h" -#include "dots.h" -#include "smoke.h" -#include "fx.h" -#include "items.h" -#include "monster.h" -#include "player.h" -#include "switch.h" -#include "weapons.h" -#include "error.h" -#include "cp866.h" - -#include "common/streams.h" -#include "common/files.h" -#include "common/wadres.h" - -int d_start, d_end; -static int m_start, m_end; -static int s_start, s_end; - -void F_startup (void) { - logo("F_startup: setup file system\n"); -} - -void F_addwad (const char *fn) { - static int i = 0; - static FILE_Reader wadh[MAX_WADS]; - if (i < MAX_WADS) { - if (FILE_OpenReader(&wadh[i], fn)) { - if (WADRES_addwad(&wadh[i].base)) { - i += 1; - } else { - ERR_failinit("Invalid WAD %s", fn); - } - } else { - ERR_failinit("Unable to add WAD %s", fn); - } - } else { - ERR_failinit("Too many wads"); - } -} - -void F_initwads (void) { - if (!WADRES_rehash()) { - ERR_failinit("F_initwads: failed rehash"); - } -} - -void F_allocres (void) { - d_start = F_getresid("D_START"); - d_end = F_getresid("D_END"); - m_start = F_getresid("M_START"); - m_end = F_getresid("M_END"); - s_start = F_getresid("S_START"); - s_end = F_getresid("S_END"); -} - -void F_loadres (int r, void *p) { - WADRES_getdata(r, p); -} - -int F_findres (const char n[8]) { - return WADRES_find(n); -} - -int F_getresid (const char n[8]) { - int i = F_findres(n); - if (i == -1) { - ERR_fatal("F_getresid: resource %.8s not found", n); - } - return i; -} - -void F_getresname (char n[8], int r) { - WADRES_getname(r, n); -} - -int F_getsprid (const char n[4], int s, int d, char *dir) { - s += 'A'; - d += '0'; - for (int i = s_start + 1; i < s_end; i++) { - char wn[8]; - byte a, b; - WADRES_getname(i, wn); - if (cp866_strncasecmp(wn, n, 4) == 0 && (wn[4] == s || wn[6] == s)) { - a = wn[4] == s ? wn[5] : 0; - b = wn[6] == s ? wn[7] : 0; - if (a == '0' || b == '0' || a == d || b == d) { - if (dir != NULL) { - *dir = (a != '0' && b == '0') || (a != d && b == d); - } - return i; - } - } - } - ERR_fatal("F_getsprid: image %.4s%c%c not found", n, s, d); - return -1; -} - -int F_getreslen (int r) { - return WADRES_getsize(r); -} - -void F_nextmus (char *s) { - int i = F_findres(s); - if (i <= m_start || i >= m_end) { - i = m_start; - } - for (++i; ; ++i) { - if (i >= m_end) { - i = m_start + 1; - } - WADRES_getname(i, s); - if (cp866_strcasecmp(s, "MENU") == 0 || - cp866_strcasecmp(s, "INTERMUS") == 0 || - cp866_strcasecmp(s, "\x8a\x8e\x8d\x85\x96\x0") == 0) { - continue; - } - if (cp866_strncasecmp(s, "DMI", 3) != 0) { - break; - } - } -} - -void F_randmus (char *s) { - int i; - int n = myrand(10); - for (i = 0; i < n; i++) { - F_nextmus(s); - } -} - -// reads bytes from file until CR -void F_readstr (FILE* h, char *s, int m) { - int i = 0; - size_t len = 0; - static char c = 0; - while (i < m) { - c = 13; - len = myfreadc(&c, 1, 1, h); - if (len == 0 || c == 13 || c == 10) { - break; - } - s[i] = c; - i++; - } - s[i] = 0; -} - -void F_loadmap (char n[8]) { - int id = F_getresid(n); - if (id != -1) { - Reader *r = WADRES_getbasereader(id); - long offset = WADRES_getoffset(id); - r->setpos(r, offset); - if (!MAP_load(r)) { - ERR_fatal("Failed to load map"); - } - } else { - ERR_fatal("Failed to load map: resource %.8s not found", n); - } -}