Esempio n. 1
0
static enum parser_error parse_r_drop(struct parser *p) {
	struct monster_race *r = parser_priv(p);
	struct monster_drop *d;
	int tval, sval;

	if (!r)
		return PARSE_ERROR_MISSING_RECORD_HEADER;
	tval = tval_find_idx(parser_getsym(p, "tval"));
	if (tval < 0)
		return PARSE_ERROR_UNRECOGNISED_TVAL;
	sval = lookup_sval(tval, parser_getsym(p, "sval"));
	if (sval < 0)
		return PARSE_ERROR_UNRECOGNISED_SVAL;

	if (parser_getuint(p, "min") > 99 || parser_getuint(p, "max") > 99)
		return PARSE_ERROR_INVALID_ITEM_NUMBER;

	d = mem_zalloc(sizeof *d);
	d->kind = objkind_get(tval, sval);
	d->percent_chance = parser_getuint(p, "chance");
	d->min = parser_getuint(p, "min");
	d->max = parser_getuint(p, "max");
	d->next = r->drops;
	r->drops = d;
	return PARSE_ERROR_NONE;
}
Esempio n. 2
0
static enum parser_error parse_prefs_k(struct parser *p)
{
	int tvi, svi, idx;
	object_kind *kind;

	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass)
		return PARSE_ERROR_NONE;

	tvi = tval_find_idx(parser_getsym(p, "tval"));
	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->x_attr = (byte) parser_getint(p, "attr");
	kind->x_char = (wchar_t) parser_getint(p, "char");

	return PARSE_ERROR_NONE;
}
Esempio n. 3
0
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
static enum parser_error parse_prefs_m(struct parser *p)
{
	int a, msg_index;
	const char *attr;
	const char *type;

	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass)
		return PARSE_ERROR_NONE;

	type = parser_getsym(p, "type");
	attr = parser_getsym(p, "attr");

	msg_index = message_lookup_by_name(type);

	if (msg_index < 0)
		return PARSE_ERROR_GENERIC;

	if (strlen(attr) > 1)
		a = color_text_to_attr(attr);
	else
		a = color_char_to_attr(attr[0]);

	if (a < 0)
		return PARSE_ERROR_INVALID_COLOR;

	message_color_define(msg_index, (byte)a);

	return PARSE_ERROR_NONE;
}
Esempio n. 6
0
static enum parser_error parse_prefs_gf(struct parser *p)
{
	bool types[GF_MAX] = { 0 };
	const char *direction;
	int motion;

	char *s, *t;

	size_t i;

	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass)
		return PARSE_ERROR_NONE;

	/* Parse the type, which is a | seperated list of GF_ constants */
	s = string_make(parser_getsym(p, "type"));
	t = strtok(s, "| ");
	while (t) {
		if (streq(t, "*")) {
			memset(types, TRUE, sizeof types);
		} else {
			int idx = gf_name_to_idx(t);
			if (idx == -1)
				return PARSE_ERROR_INVALID_VALUE;

			types[idx] = TRUE;
		}

		t = strtok(NULL, "| ");
	}

	string_free(s);

	direction = parser_getsym(p, "direction");
	if (streq(direction, "static"))
		motion = BOLT_NO_MOTION;
	else if (streq(direction, "0"))
		motion = BOLT_0;
	else if (streq(direction, "45"))
		motion = BOLT_45;
	else if (streq(direction, "90"))
		motion = BOLT_90;
	else if (streq(direction, "135"))
		motion = BOLT_135;
	else
		return PARSE_ERROR_INVALID_VALUE;

	for (i = 0; i < GF_MAX; i++) {
		if (!types[i])
			continue;

		gf_to_attr[i][motion] = (byte) parser_getuint(p, "attr");
		gf_to_char[i][motion] = (wchar_t) parser_getuint(p, "char");
	}

	return PARSE_ERROR_NONE;
}
Esempio n. 7
0
static enum parser_error helper_sym1(struct parser *p) {
	const char *s = parser_getsym(p, "foo");
	const char *t = parser_getsym(p, "baz");
	int *wasok = parser_priv(p);
	if (!s || !t || strcmp(s, "bar") || strcmp(t, "quxx"))
		return PARSE_ERROR_GENERIC;
	*wasok = 1;
	return PARSE_ERROR_NONE;
}
Esempio n. 8
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;
}
Esempio n. 9
0
static enum parser_error parse_prefs_m(struct parser *p)
{
	int a, type;
	const char *attr;

	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass)
		return PARSE_ERROR_NONE;

	type = parser_getint(p, "type");
	attr = parser_getsym(p, "attr");

	if (strlen(attr) > 1)
		a = color_text_to_attr(attr);
	else
		a = color_char_to_attr(attr[0]);

	if (a < 0)
		return PARSE_ERROR_INVALID_COLOR;

	message_color_define((u16b) type, (byte) a);

	return PARSE_ERROR_NONE;
}
Esempio n. 10
0
static enum parser_error parse_r_mimic(struct parser *p) {
	struct monster_race *r = parser_priv(p);
	int tval, sval;
	object_kind *kind;

	if (!r)
		return PARSE_ERROR_MISSING_RECORD_HEADER;
	tval = tval_find_idx(parser_getsym(p, "tval"));
	if (tval < 0)
		return PARSE_ERROR_UNRECOGNISED_TVAL;
	sval = lookup_sval(tval, parser_getsym(p, "sval"));
	if (sval < 0)
		return PARSE_ERROR_UNRECOGNISED_SVAL;

	kind = objkind_get(tval, sval);
	if (!kind)
		return PARSE_ERROR_GENERIC;
	r->mimic_kind = kind;
	return PARSE_ERROR_NONE;
}
Esempio n. 11
0
static enum parser_error parse_room_tval(struct parser *p) {
	struct room_template *t = parser_priv(p);
	int tval;

	if (!t)
		return PARSE_ERROR_MISSING_RECORD_HEADER;
	tval = tval_find_idx(parser_getsym(p, "tval"));
	if (tval < 0)
		return PARSE_ERROR_UNRECOGNISED_TVAL;
	t->tval = tval;
	return PARSE_ERROR_NONE;
}
Esempio n. 12
0
static enum parser_error parse_always(struct parser *p) {
	struct store *s = parser_priv(p);
	int tval = tval_find_idx(parser_getsym(p, "tval"));
	int sval = lookup_sval(tval, parser_getsym(p, "sval"));

	object_kind *kind = lookup_kind(tval, sval);
	if (!kind)
		return PARSE_ERROR_UNRECOGNISED_SVAL;

	/* Expand if necessary */
	if (!s->always_num) {
		s->always_size = 8;
		s->always_table = mem_zalloc(s->always_size * sizeof *s->always_table);
	} else if (s->always_num >= s->always_size) {
		s->always_size += 8; 
		s->always_table = mem_realloc(s->always_table, s->always_size * sizeof *s->always_table);
	}

	s->always_table[s->always_num++] = kind;

	return PARSE_ERROR_NONE;
}
Esempio n. 13
0
static enum parser_error parse_summon_message_type(struct parser *p) {
	struct summon *s = parser_priv(p);
	int msg_index;
	const char *type;
	assert(s);
	type = parser_getsym(p, "type");
	msg_index = message_lookup_by_name(type);

	if (msg_index < 0)
		return PARSE_ERROR_INVALID_MESSAGE;

	s->message_type = msg_index;
	return PARSE_ERROR_NONE;
}
Esempio n. 14
0
static enum parser_error parse_summon_race_flag(struct parser *p) {
	struct summon *s = parser_priv(p);
	int flag;
	assert(s);

	flag = lookup_flag(mon_race_flags, parser_getsym(p, "flag"));

	if (flag == FLAG_END) {
		return PARSE_ERROR_INVALID_FLAG;
	} else {
		s->race_flag = flag;
	}
	return PARSE_ERROR_NONE;
}
Esempio n. 15
0
static enum parser_error parse_summon_base(struct parser *p) {
	struct summon *s = parser_priv(p);
	struct monster_base *base;
	struct monster_base_list *b = mem_zalloc(sizeof(*b));
	assert(s);
	base = lookup_monster_base(parser_getsym(p, "base"));
	if (base == NULL) {
		mem_free(b);
		return PARSE_ERROR_INVALID_MONSTER_BASE;
	}
	b->base = base;
	b->next = s->bases;
	s->bases = b;
	return PARSE_ERROR_NONE;
}
Esempio n. 16
0
static enum parser_error parse_r_t(struct parser *p) {
	struct monster_race *r = parser_priv(p);

	r->base = lookup_monster_base(parser_getsym(p, "base"));
	if (r->base == NULL)
		/* Todo: make new error for this */
		return PARSE_ERROR_UNRECOGNISED_TVAL;

	/* The template sets the default display character */
	r->d_char = r->base->d_char;

	/* Give the monster its default flags */
	rf_union(r->flags, r->base->flags);

	return PARSE_ERROR_NONE;
}
Esempio n. 17
0
static enum parser_error parse_r_c(struct parser *p) {
	struct monster_race *r = parser_priv(p);
	const char *color;
	int attr;

	if (!r)
		return PARSE_ERROR_MISSING_RECORD_HEADER;
		color = parser_getsym(p, "color");
	if (strlen(color) > 1)
		attr = color_text_to_attr(color);
	else
		attr = color_char_to_attr(color[0]);
	if (attr < 0)
		return PARSE_ERROR_INVALID_COLOR;
	r->d_attr = attr;
	return PARSE_ERROR_NONE;
}
Esempio n. 18
0
static enum parser_error parse_prefs_f(struct parser *p)
{
	int idx;
	feature_type *feature;

	const char *lighting;
	int light_idx;

	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass)
		return PARSE_ERROR_NONE;

	idx = parser_getuint(p, "idx");
	if (idx >= z_info->f_max)
		return PARSE_ERROR_OUT_OF_BOUNDS;

	lighting = parser_getsym(p, "lighting");
	if (streq(lighting, "torch"))
		light_idx = FEAT_LIGHTING_TORCH;
	else if (streq(lighting, "los"))
		light_idx = FEAT_LIGHTING_LOS;
	else if (streq(lighting, "lit"))
		light_idx = FEAT_LIGHTING_LIT;
	else if (streq(lighting, "dark"))
		light_idx = FEAT_LIGHTING_DARK;
	else if (streq(lighting, "all"))
		light_idx = FEAT_LIGHTING_MAX;
	else
		return PARSE_ERROR_GENERIC; /* xxx fixme */

	if (light_idx < FEAT_LIGHTING_MAX) {
		feature = &f_info[idx];
		feature->x_attr[light_idx] = (byte) parser_getint(p, "attr");
		feature->x_char[light_idx] = (wchar_t) parser_getint(p, "char");
	} else {
		for (light_idx = 0; light_idx < FEAT_LIGHTING_MAX; light_idx++) {
			feature = &f_info[idx];
			feature->x_attr[light_idx] = (byte) parser_getint(p, "attr");
			feature->x_char[light_idx] =
				(wchar_t) parser_getint(p, "char");
		}
	}

	return PARSE_ERROR_NONE;
}
Esempio n. 19
0
static enum parser_error parse_prefs_e(struct parser *p)
{
	int tvi, a;

	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass) return PARSE_ERROR_NONE;

	tvi = tval_find_idx(parser_getsym(p, "tval"));
	if (tvi < 0 || tvi >= (long)N_ELEMENTS(tval_to_attr))
		return PARSE_ERROR_UNRECOGNISED_TVAL;

	a = parser_getint(p, "attr");
	if (a) tval_to_attr[tvi] = (byte) a;

	return PARSE_ERROR_NONE;
}
Esempio n. 20
0
static enum parser_error parse_buy_flag(struct parser *p) {
	struct store *s = parser_priv(p);
	struct object_buy *buy;
	char *t;
	int flag;

	if (!s)
		return PARSE_ERROR_MISSING_RECORD_HEADER;

	buy = mem_zalloc(sizeof(*buy));
	t = string_make(parser_getsym(p, "flag"));
	flag = lookup_flag(obj_flags, t);
	if (flag == FLAG_END)
		return PARSE_ERROR_INVALID_FLAG;
	buy->flag = flag;
	buy->tval = tval_find_idx(parser_getstr(p, "base"));
	buy->next = s->buy;
	s->buy = buy;
	return PARSE_ERROR_NONE;
}
Esempio n. 21
0
enum parser_error parse_prefs_sound(struct parser *p)
{
	int msg_index;
	const char *type;
	const char *sounds_local;

	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass) return PARSE_ERROR_NONE;

	type = parser_getsym(p, "type");
	sounds_local = parser_getstr(p, "sounds");

	msg_index = message_lookup_by_name(type);

	if (msg_index < 0)
		return PARSE_ERROR_INVALID_MESSAGE;

	message_sound_define(msg_index, sounds_local);

	return PARSE_ERROR_NONE;
}
Esempio n. 22
0
static enum parser_error parse_profile_room(struct parser *p) {
    struct cave_profile *c = parser_priv(p);
	struct room_profile *r = c->room_profiles;
	size_t i;

	if (!c)
		return PARSE_ERROR_MISSING_RECORD_HEADER;

	/* Go to the last valid room profile, then allocate a new one */
	if (!r) {
		c->room_profiles = mem_zalloc(sizeof(struct room_profile));
		r = c->room_profiles;
	} else {
		while (r->next)
			r = r->next;
		r->next = mem_zalloc(sizeof(struct room_profile));
		r = r->next;
	}

	/* Now read the data */
	r->name = string_make(parser_getsym(p, "name"));
	for (i = 0; i < N_ELEMENTS(room_builders); i++)
		if (streq(r->name, room_builders[i].name))
			break;

	if (i == N_ELEMENTS(room_builders))
		return PARSE_ERROR_NO_ROOM_FOUND;
	r->builder = room_builders[i].builder;
    r->height = parser_getint(p, "height");
    r->width = parser_getint(p, "width");
    r->level = parser_getint(p, "level");
    r->pit = (parser_getint(p, "pit") == 1);
    r->rarity = parser_getint(p, "rarity");
    r->cutoff = parser_getint(p, "cutoff");
	return PARSE_ERROR_NONE;
}