Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non-instant artifact colors without inteference for other objects #786

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cave-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
* player doesn't know it).
* - g->first_kind is set to the object_kind of the first object in a grid
* that the player knows about, or NULL for no objects.
* - g->first_art is set to the artifact pointer of the first object in a grid
* that the player knows about, or NULL if there are no objects or the first
* known object is not an artifact.
* - g->muliple_objects is true if there is more than one object in the
* grid that the player knows and cares about (to facilitate any special
* floor stack symbol that might be used).
Expand Down Expand Up @@ -88,6 +91,7 @@ void map_info(struct loc grid, struct grid_data *g)

/* Default "clear" values, others will be set later where appropriate. */
g->first_kind = NULL;
g->first_art = NULL;
g->trap = NULL;
g->multiple_objects = false;
g->glow = false;
Expand Down Expand Up @@ -152,6 +156,7 @@ void map_info(struct loc grid, struct grid_data *g)
/* Item stays hidden */
} else if (!g->first_kind) {
g->first_kind = obj->kind;
g->first_art = obj->artifact;
g->glow = weapon_glows(obj);
} else {
g->multiple_objects = true;
Expand Down
1 change: 1 addition & 0 deletions src/cave.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ struct grid_data {
uint32_t m_idx; /* Monster index */
uint32_t f_idx; /* Feature index */
struct object_kind *first_kind; /* The kind of the first item on the grid */
const struct artifact *first_art; /* Artifact pointer for first item on the grid */
struct trap *trap; /* Trap */
bool multiple_objects; /* Is there more than one item there? */

Expand Down
28 changes: 24 additions & 4 deletions src/obj-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static enum parser_error write_dummy_object_record(struct artifact *art, const c
/* Give the object default colours (these should be overwritten) */
dummy->d_char = '*';
dummy->d_attr = COLOUR_RED;
art->d_attr = dummy->d_attr;

/* Inherit the flags and element information of the tval */
of_copy(dummy->flags, kb_info[i].flags);
Expand Down Expand Up @@ -2284,6 +2285,9 @@ static enum parser_error parse_artifact_name(struct parser *p) {
a->el_info[i].flags |= EL_INFO_IGNORE;
}

/* Signal that the color has not been set */
a->d_attr = 255;

return PARSE_ERROR_NONE;
}

Expand All @@ -2307,6 +2311,10 @@ static enum parser_error parse_artifact_base_object(struct parser *p) {
return write_dummy_object_record(a, sval_name);
}
a->sval = sval;
/* Use the base object's display color unless overridden. */
if (a->d_attr == 255) {
a->d_attr = lookup_kind(a->tval, a->sval)->d_attr;
}

return PARSE_ERROR_NONE;
}
Expand All @@ -2319,12 +2327,16 @@ static enum parser_error parse_artifact_color(struct parser *p) {
if (!a) {
return PARSE_ERROR_MISSING_RECORD_HEADER;
}
k = lookup_kind(a->tval, a->sval);
assert(k);
if (strlen(color) > 1) {
k->d_attr = color_text_to_attr(color);
a->d_attr = color_text_to_attr(color);
} else {
k->d_attr = color_char_to_attr(color[0]);
a->d_attr = color_char_to_attr(color[0]);
}
k = lookup_kind(a->tval, a->sval);
assert(k);
if (kf_has(k->kind_flags, KF_INSTA_ART)) {
/* Align the color of the kind with that of the artifact. */
k->d_attr = a->d_attr;
}
return PARSE_ERROR_NONE;
}
Expand All @@ -2349,6 +2361,7 @@ static enum parser_error parse_artifact_graphics(struct parser *p) {
} else {
k->d_attr = color_char_to_attr(color[0]);
}
a->d_attr = k->d_attr;
return PARSE_ERROR_NONE;
}

Expand Down Expand Up @@ -2628,6 +2641,13 @@ static errr finish_parse_artifact(struct parser *p) {

memcpy(&a_info[aidx], a, sizeof(*a));
a_info[aidx].aidx = aidx;
if (a_info[aidx].d_attr == 255) {
/*
* The color was not set (no base object set). Use zero
* as the color index.
*/
a_info[aidx].d_attr = 0;
}
n = a->next;
a_info[aidx].next = (aidx < z_info->a_max) ?
&a_info[aidx + 1] : NULL;
Expand Down
1 change: 1 addition & 0 deletions src/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ struct artifact {

uint8_t level; /* Artefact level */
uint8_t rarity; /* Artefact rarity */
uint8_t d_attr; /**< Display color */
};

/**
Expand Down
4 changes: 3 additions & 1 deletion src/ui-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ void grid_data_as_text(struct grid_data *g, int *ap, wchar_t *cp, int *tap,
c = object_kind_char(pile_kind);
} else {
/* Normal attr and char, check for glowing */
a = g->glow ? COLOUR_L_BLUE : object_kind_attr(g->first_kind);
a = g->glow ? COLOUR_L_BLUE :
((g->first_art) ? g->first_art->d_attr :
object_kind_attr(g->first_kind));
c = object_kind_char(g->first_kind);
}
if (g->rage) a = COLOUR_RED;
Expand Down
4 changes: 2 additions & 2 deletions src/ui-obj-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ static void object_list_format_section(const object_list_t *list,
wchar_t c = L'*';

if (list->entries[entry_index].object->kind != NULL) {
a = object_kind_attr(list->entries[entry_index].object->kind);
c = object_kind_char(list->entries[entry_index].object->kind);
a = object_attr(list->entries[entry_index].object);
c = object_char(list->entries[entry_index].object);
}

textblock_append_pict(tb, a, c);
Expand Down
3 changes: 2 additions & 1 deletion src/ui-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ wchar_t object_kind_char(const struct object_kind *kind)
*/
uint8_t object_attr(const struct object *obj)
{
return object_kind_attr(obj->kind);
return obj->artifact ?
obj->artifact->d_attr : object_kind_attr(obj->kind);
}

/**
Expand Down