summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/grfio.cpp23
-rw-r--r--src/map/grfio.hpp2
-rw-r--r--src/map/magic-interpreter-lexer.lpp2
-rw-r--r--src/map/magic-interpreter-parser.ypp6
-rw-r--r--src/map/magic.hpp2
-rw-r--r--src/map/map.cpp5
-rw-r--r--src/map/script.cpp20
-rw-r--r--src/map/script.hpp2
8 files changed, 39 insertions, 23 deletions
diff --git a/src/map/grfio.cpp b/src/map/grfio.cpp
index c5a55f5..ff73c90 100644
--- a/src/map/grfio.cpp
+++ b/src/map/grfio.cpp
@@ -23,16 +23,18 @@
#include "../poison.hpp"
static
-std::map<MapName, FString> load_resnametable()
+std::map<MapName, FString> resnametable;
+
+bool load_resnametable(ZString filename)
{
- io::ReadFile in("data/resnametable.txt");
+ io::ReadFile in(filename);
if (!in.is_open())
{
- fprintf(stderr, "Missing data/resnametable.txt");
- abort();
+ FPRINTF(stderr, "Missing %s\n", filename);
+ return false;
}
- std::map<MapName, FString> out;
+ bool rv = true;
FString line;
while (in.getline(line))
{
@@ -40,19 +42,20 @@ std::map<MapName, FString> load_resnametable()
FString value;
if (!extract(line,
record<'#'>(&key, &value)))
+ {
+ PRINTF("Bad resnametable line: %s\n", line);
+ rv = false;
continue;
- out[key] = value;
+ }
+ resnametable[key] = value;
}
- return out;
+ return rv;
}
/// Change *.gat to *.wlk
static
FString grfio_resnametable(MapName rname)
{
- static
- std::map<MapName, FString> resnametable = load_resnametable();
-
return resnametable.at(rname);
}
diff --git a/src/map/grfio.hpp b/src/map/grfio.hpp
index 17acfb6..3fde76a 100644
--- a/src/map/grfio.hpp
+++ b/src/map/grfio.hpp
@@ -7,6 +7,8 @@
# include "../common/mmo.hpp"
+bool load_resnametable(ZString filename);
+
/// Load a resource into memory, subject to data/resnametable.txt.
/// Normally, resourcename is xxx-y.gat and the file is xxx-y.wlk.
/// Currently there is exactly one .wlk per .gat, but multiples are fine.
diff --git a/src/map/magic-interpreter-lexer.lpp b/src/map/magic-interpreter-lexer.lpp
index 83cb36f..38b7b1e 100644
--- a/src/map/magic-interpreter-lexer.lpp
+++ b/src/map/magic-interpreter-lexer.lpp
@@ -146,7 +146,7 @@
"#".*$ /* Ignore comments */
"//".*$ /* Ignore comments */
[ \n\t\r] /* ignore whitespace */
-. FPRINTF(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno);
+. FPRINTF(stderr, "%s: Unexpected character in line %d\n", current_magic_filename, magic_frontend_lineno);
%%
// nothing to see here, move along
diff --git a/src/map/magic-interpreter-parser.ypp b/src/map/magic-interpreter-parser.ypp
index 0e03afb..a86f1c8 100644
--- a/src/map/magic-interpreter-parser.ypp
+++ b/src/map/magic-interpreter-parser.ypp
@@ -1,6 +1,9 @@
%code requires
{
#include "magic-interpreter.hpp"
+
+extern
+FString current_magic_filename;
} // %code requires
%code
@@ -20,6 +23,8 @@
#include "itemdb.hpp"
#include "magic-expr.hpp"
+FString current_magic_filename;
+
// can't use src/warnings.hpp in generated code
#pragma GCC diagnostic warning "-Wall"
#pragma GCC diagnostic warning "-Wextra"
@@ -1411,6 +1416,7 @@ bool magic_init0()
// must be called after itemdb initialisation
bool magic_init1(ZString conffile)
{
+ current_magic_filename = conffile;
magic_frontend_in = fopen(conffile.c_str(), "r");
if (!magic_frontend_in)
{
diff --git a/src/map/magic.hpp b/src/map/magic.hpp
index 30c6e62..5d4e517 100644
--- a/src/map/magic.hpp
+++ b/src/map/magic.hpp
@@ -8,8 +8,6 @@
# include "map.hpp"
# include "skill.t.hpp"
-# define MAGIC_CONFIG_FILE "conf/magic.conf"
-
struct invocation; /* Spell invocation */
/**
diff --git a/src/map/map.cpp b/src/map/map.cpp
index e141ae1..d2b604f 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -1656,6 +1656,11 @@ bool map_confs(XString key, ZString value)
return skill_readdb(value);
if (key == "magic_conf")
return magic_init1(value);
+
+ if (key == "resnametable")
+ return load_resnametable(value);
+ if (key == "const_db")
+ return read_constdb(value);
PRINTF("unknown map conf key: %s\n", FString(key));
return false;
}
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 51f228f..279e541 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -689,20 +689,16 @@ void add_builtin_functions(void)
}
}
-/*==========================================
- * 定数データベースの読み込み
- *------------------------------------------
- */
-static
-void read_constdb(void)
+bool read_constdb(ZString filename)
{
- io::ReadFile in("db/const.txt");
+ io::ReadFile in(filename);
if (!in.is_open())
{
- PRINTF("can't read db/const.txt\n");
- return;
+ PRINTF("can't read %s\n", filename);
+ return false;
}
+ bool rv = true;
FString line;
while (in.getline(line))
{
@@ -714,11 +710,16 @@ void read_constdb(void)
int type = 0; // if not provided
// TODO get rid of SSCANF - this is the last serious use
if (SSCANF(line, "%m[A-Za-z0-9_] %i %i", &name, &val, &type) < 2)
+ {
+ PRINTF("Bad const line: %s\n", line);
+ rv = false;
continue;
+ }
str_data_t *n = add_strp(name);
n->type = type ? ByteCode::PARAM_ : ByteCode::INT;
n->val = val;
}
+ return rv;
}
std::unique_ptr<const ScriptBuffer> parse_script(ZString src, int line)
@@ -739,7 +740,6 @@ void ScriptBuffer::parse_script(ZString src, int line)
if (first)
{
add_builtin_functions();
- read_constdb();
}
first = 0;
LABEL_NEXTLINE_.type = ByteCode::NOP;
diff --git a/src/map/script.hpp b/src/map/script.hpp
index a05ecf6..ec52f65 100644
--- a/src/map/script.hpp
+++ b/src/map/script.hpp
@@ -166,4 +166,6 @@ extern FString mapreg_txt;
extern int script_errors;
+bool read_constdb(ZString filename);
+
#endif // SCRIPT_HPP