Fix printf buff bug, when given item appears in dialog box

main
parent 7a20b26db8
commit 530f929376

@ -371,8 +371,8 @@
"rotation":0,
"visible":true,
"width":32,
"x":1938.66666666667,
"y":2269.33333333333
"x":1934.66666666667,
"y":2257.33333333333
},
{
"class":"",

@ -41,30 +41,35 @@ typedef struct
{
char *global_prompt;
char *enum_name;
char *name; // talked about like 'The Player gave `item.name` to the NPC'
char *possess;
char *discard;
} ItemInfo;
ItemInfo items[] = {
{
.enum_name = "none",
.name = "Nothing",
.global_prompt = "The player isn't holding anything",
.possess = "The player is no longer holding anything",
.discard = "The player is no longer holding nothing",
},
{
.enum_name = "WhiteSquare",
.name = "the white square",
.global_prompt = "The player is holding a mysterious white square. It is unknown what strange and erotic abilities one has when they possess the square.",
.possess = "The player is now holding the white square",
.discard = "The player is no longer holding the white square.",
},
{
.enum_name = "Boots",
.name = "some boots",
.global_prompt = "The player is holding the boots of speed. He is a force to be recogned with in this state, he has great speed while holding the boots.",
.possess = "The player is now holding the boots of speed",
.discard = "The player is no longer holding the boots of speed",
},
{
.enum_name = "Tripod",
.name = "the tripod",
.global_prompt = "The player is holding a tripod used for holding things up. It's got an odd construction, but Block really likes it for some reason.",
.possess = "The player is now holding the tripod",
.discard = "The player is no longer holding the tripod.",

@ -2085,13 +2085,24 @@ Sentence *last_said_sentence(Entity *npc)
return 0;
}
typedef enum
{
DELEM_NPC,
DELEM_PLAYER,
DELEM_NPC_ACTION_DESCRIPTION,
} DialogElementKind;
typedef struct
{
Sentence s;
bool is_player;
DialogElementKind kind;
} DialogElement;
typedef BUFF(DialogElement, REMEMBERED_PERCEPTIONS) Dialog;
// Some perceptions can have multiple dialog elements.
// Like item give perceptions that have an action with both dialog
// and an argument. So worst case every perception has 2 dialog
// elements right now is why it's *2
typedef BUFF(DialogElement, REMEMBERED_PERCEPTIONS*2) Dialog;
Dialog produce_dialog(Entity *talking_to, bool character_names)
{
assert(talking_to->is_npc);
@ -2101,6 +2112,14 @@ Dialog produce_dialog(Entity *talking_to, bool character_names)
if(it->type == NPCDialog)
{
Sentence to_say = (Sentence){0};
if(it->npc_action_type == ACT_give_item)
{
DialogElement new = {0};
printf_buff(&new.s, "%s gave %s to you", characters[talking_to->npc_kind].name, items[it->given_item].name);
new.kind = DELEM_NPC_ACTION_DESCRIPTION;
BUFF_APPEND(&to_return, new);
}
if(character_names)
{
@ -2120,7 +2139,7 @@ Dialog produce_dialog(Entity *talking_to, bool character_names)
{
append_str(&to_say, it->npc_dialog.data);
}
BUFF_APPEND(&to_return, ((DialogElement){ .s = to_say, .is_player = false }) );
BUFF_APPEND(&to_return, ((DialogElement){ .s = to_say, .kind = DELEM_NPC }) );
}
else if(it->type == PlayerDialog)
{
@ -2130,7 +2149,7 @@ Dialog produce_dialog(Entity *talking_to, bool character_names)
append_str(&to_say, "Player: ");
}
append_str(&to_say, it->player_dialog.data);
BUFF_APPEND(&to_return, ((DialogElement){ .s = to_say, .is_player = true }) );
BUFF_APPEND(&to_return, ((DialogElement){ .s = to_say, .kind = DELEM_PLAYER }) );
}
}
return to_return;
@ -2189,14 +2208,22 @@ void draw_dialog_panel(Entity *talking_to, float alpha)
Color *colors = calloc(sizeof(*colors), it->s.cur_index);
for(int char_i = 0; char_i < it->s.cur_index; char_i++)
{
if(it->is_player)
if(it->kind == DELEM_PLAYER)
{
colors[char_i] = BLACK;
}
else
else if(it->kind == DELEM_NPC)
{
colors[char_i] = colhex(0x345e22);
}
else if(it->kind == DELEM_NPC_ACTION_DESCRIPTION)
{
colors[char_i] = colhex(0xb5910e);
}
else
{
assert(false);
}
colors[char_i] = blendalpha(colors[char_i], alpha);
}
float measured_line_height = draw_wrapped_text((WrappedTextParams){true, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->s.data, colors, 0.5f, dialog_panel});
@ -3745,14 +3772,22 @@ F cost: G + H
Color *colors = calloc(sizeof(*colors), it->s.cur_index);
for(int char_i = 0; char_i < it->s.cur_index; char_i++)
{
if(it->is_player)
if(it->kind == DELEM_PLAYER)
{
colors[char_i] = WHITE;
}
else
else if(it->kind == DELEM_NPC)
{
colors[char_i] = colhex(0x34e05c);
}
else if(it->kind == DELEM_NPC_ACTION_DESCRIPTION)
{
colors[char_i] = colhex(0xebc334);
}
else
{
assert(false);
}
colors[char_i] = blendalpha(colors[char_i], alpha);
}
float measured_line_height = draw_wrapped_text((WrappedTextParams){true, V2(dialog_text_aabb.upper_left.X, new_line_height), dialog_text_aabb.lower_right.X - dialog_text_aabb.upper_left.X, it->s.data, colors, dialog_text_scale, dialog_text_aabb, .screen_space = true});

@ -412,8 +412,16 @@ bool printf_buff_impl(BuffRef into, const char *format, ...)
assert(into.data_elem_size == 1); // characters
va_list args;
va_start (args, format);
int n = info.max_data_elems - *info.cur_index;
int written = vsnprintf((char*)into.data + *info.cur_index, n, format, args);
size_t n = into.max_data_elems - *into.cur_index;
int written = vsnprintf((char*)into.data + *into.cur_index, n, format, args);
if(written < 0)
{
}
else
{
*into.cur_index += written;
}
// https://cplusplus.com/reference/cstdio/vsnprintf/
bool succeeded = true;

Loading…
Cancel
Save