示例#1
0
文件: init.c 项目: jenschou/angband
static enum parser_error parse_r_b(struct parser *p) {
	struct monster_race *r = parser_priv(p);
	int i;
	struct random dam;

	if (!r)
		return PARSE_ERROR_MISSING_RECORD_HEADER;
	for (i = 0; i < MONSTER_BLOW_MAX; i++)
		if (!r->blow[i].method)
			break;
	if (i == MONSTER_BLOW_MAX)
		return PARSE_ERROR_TOO_MANY_ENTRIES;
	r->blow[i].method = find_blow_method(parser_getsym(p, "method"));
	if (!r_info_blow_method[r->blow[i].method])
		return PARSE_ERROR_UNRECOGNISED_BLOW;
	if (parser_hasval(p, "effect")) {
		r->blow[i].effect = find_blow_effect(parser_getsym(p, "effect"));
		if (!r_info_blow_effect[r->blow[i].effect])
			return PARSE_ERROR_INVALID_EFFECT;
	}
	if (parser_hasval(p, "damage")) {
		dam = parser_getrand(p, "damage");
		r->blow[i].d_dice = dam.dice;
		r->blow[i].d_side = dam.sides;
	}


	return PARSE_ERROR_NONE;
}
示例#2
0
static enum parser_error parse_prefs_q(struct parser *p)
{
	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass)
		return PARSE_ERROR_NONE;

	if (parser_hasval(p, "sval") && parser_hasval(p, "flag")) {
		object_kind *kind;
		int tvi, svi, idx;

		tvi = tval_find_idx(parser_getsym(p, "n"));
		if (tvi < 0)
			return PARSE_ERROR_UNRECOGNISED_TVAL;
	
		svi = lookup_sval(tvi, parser_getsym(p, "sval"));
		if (svi < 0)
			return PARSE_ERROR_UNRECOGNISED_SVAL;

		idx = lookup_kind(tvi, svi);
		if (idx < 0)
			return PARSE_ERROR_UNRECOGNISED_SVAL;

		kind = &k_info[idx];
		kind->squelch = parser_getint(p, "flag");
	}

	return PARSE_ERROR_NONE;
}
示例#3
0
int test_opt0(void *state) {
	int wasok = 0;
	errr r = parser_reg(state, "test-opt0 sym s0 ?sym s1", helper_opt0);
	eq(r, 0);
	parser_setpriv(state, &wasok);
	r = parser_parse(state, "test-opt0:foo");
	eq(r, 0);
	eq(wasok, 1);
	require(parser_hasval(state, "s0"));
	require(!parser_hasval(state, "s1"));
	r = parser_parse(state, "test-opt0:foo:bar");
	eq(r, 0);
	eq(wasok, 2);
	require(parser_hasval(state, "s0"));
	require(parser_hasval(state, "s1"));
	ok;
}
示例#4
0
static enum parser_error helper_opt0(struct parser *p) {
	const char *s0 = parser_getsym(p, "s0");
	const char *s1 = parser_hasval(p, "s1") ? parser_getsym(p, "s1") : NULL;
	int *wasok = parser_priv(p);
	if (!s0 || strcmp(s0, "foo"))
		return PARSE_ERROR_GENERIC;
	if (s1 && !strcmp(s1, "bar"))
		*wasok = 2;
	else
		*wasok = 1;
	return PARSE_ERROR_NONE;
}
示例#5
0
static enum parser_error parse_r_plural(struct parser *p)
{
	struct monster_race *r = parser_priv(p);

	if (r == NULL)
		return PARSE_ERROR_MISSING_RECORD_HEADER;

	if (parser_hasval(p, "plural")) {
		const char *plural = parser_getstr(p, "plural");

		if (strlen(plural) > 0)
			r->plural = string_make(plural);
		else
			r->plural = NULL;
	}

	return PARSE_ERROR_NONE;
}
示例#6
0
文件: init.c 项目: jenschou/angband
static enum parser_error parse_rb_s(struct parser *p) {
	struct monster_base *rb = parser_priv(p);
	char *flags;
	char *s;

	if (!rb)
		return PARSE_ERROR_MISSING_RECORD_HEADER;
	if (!parser_hasval(p, "spells"))
		return PARSE_ERROR_NONE;
	flags = string_make(parser_getstr(p, "spells"));
	s = strtok(flags, " |");
	while (s) {
		if (grab_flag(rb->spell_flags, RSF_SIZE, r_info_spell_flags, s)) {
			mem_free(flags);
			return PARSE_ERROR_INVALID_FLAG;
		}
		s = strtok(NULL, " |");
	}

	mem_free(flags);
	return PARSE_ERROR_NONE;
}
示例#7
0
static enum parser_error parse_r_mf(struct parser *p) {
	struct monster_race *r = parser_priv(p);
	char *flags;
	char *s;

	if (!r)
		return PARSE_ERROR_MISSING_RECORD_HEADER;
	if (!parser_hasval(p, "flags"))
		return PARSE_ERROR_NONE;
	flags = string_make(parser_getstr(p, "flags"));
	s = strtok(flags, " |");
	while (s) {
		if (remove_flag(r->flags, RF_SIZE, r_info_flags, s)) {
			mem_free(flags);
			quit_fmt("bad mf-flag: %s", s);
			return PARSE_ERROR_INVALID_FLAG;
		}
		s = strtok(NULL, " |");
	}

	mem_free(flags);
	return PARSE_ERROR_NONE;
}