Giving items back and forth and REFORMAT EVERYTHING. SUCKS

main
parent dc1cb80ecd
commit d2e0f2596e

@ -0,0 +1,69 @@
<?xml version="1.0"?>
<N10X>
<Workspace>
<IncludeFilter>*.c,*.cc,*.cpp,*.c++,*.cp,*.cxx,*.h,*.hh,*.hpp,*.h++,*.hp,*.hxx,*.inl,*.cs,*.rs,*.java,*.jav,*.js,*.jsc,*.jsx,*.json,*.cls,*.py,*.rpy,*.php,*.php3,*.phl,*.phtml,*.rhtml,*.tpl,*.phps,*.lua,*.html,*.html5,*.htm,*.xml,*.xaml,*.css,*.ssi,*.haml,*.yaml,*.bat,*.wbf,*.wbt,*.txt,*.cmake,*.make,*.makefile,*.mak,*.mk,*.sh,*.bash,*.csv,*.asp,*.pl,*.mac,*.ws,*.vbs,*.perl,*.src,*.rss,*.inc,*.f,*.go,*.prl,*.plx,*.rb,*.lsp,*.lpx,*.ps1,*.command,*.cbl,*.cob,*.qs,*.wxs,*.ph,*.msc,*.glsl,*.hlsl,*.fx,*.vert,*.tesc,*.tese,*.geom,*.frag,*.comp,*.pssl,*.scons,*.cu,</IncludeFilter>
<ExcludeFilter></ExcludeFilter>
<SyncFiles>true</SyncFiles>
<Recursive>true</Recursive>
<ShowEmptyFolders>true</ShowEmptyFolders>
<IsVirtual>false</IsVirtual>
<IsFolder>false</IsFolder>
<BuildCommand></BuildCommand>
<RebuildCommand></RebuildCommand>
<BuildFileCommand></BuildFileCommand>
<CleanCommand></CleanCommand>
<BuildWorkingDirectory></BuildWorkingDirectory>
<CancelBuild></CancelBuild>
<RunCommand></RunCommand>
<RunCommandWorkingDirectory></RunCommandWorkingDirectory>
<DebugCommand></DebugCommand>
<ExePathCommand></ExePathCommand>
<DebugSln></DebugSln>
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
<Configurations>
<Configuration>Debug</Configuration>
<Configuration>Release</Configuration>
</Configurations>
<Platforms>
<Platform>x64</Platform>
<Platform>Win32</Platform>
</Platforms>
<AdditionalIncludePaths>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\ATLMFC\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\ATLMFC\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
</AdditionalIncludePaths>
<Defines></Defines>
<ConfigProperties>
<ConfigAndPlatform>
<Name>Debug:x64</Name>
<Defines></Defines>
<ForceIncludes></ForceIncludes>
</ConfigAndPlatform>
<Config>
<Name>Debug</Name>
<Defines></Defines>
</Config>
<Platform>
<Name>x64</Name>
<Defines></Defines>
</Platform>
</ConfigProperties>
<Children></Children>
</Workspace>
</N10X>

@ -26,6 +26,10 @@
{ {
filepath: "boots.png", filepath: "boots.png",
} }
@image chalice:
{
filepath: "chalice_of_gold.png",
}
@image new_knight_idle: @image new_knight_idle:
{ {
filepath: "copyrighted/knight_idle.png", filepath: "copyrighted/knight_idle.png",

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

@ -380,6 +380,11 @@
"id":22, "id":22,
"name":"TheBlacksmith", "name":"TheBlacksmith",
"properties":[ "properties":[
{
"name":"held_items",
"type":"string",
"value":"{.data = {ITEM_Chalice}, .cur_index = 1}"
},
{ {
"name":"standing", "name":"standing",
"type":"string", "type":"string",

@ -53,6 +53,13 @@ ItemInfo items[] = {
.possess = "The player is no longer holding anything", .possess = "The player is no longer holding anything",
.discard = "The player is no longer holding nothing", .discard = "The player is no longer holding nothing",
}, },
{
.enum_name = "Chalice",
.name = "The Chalice of Gold",
.global_prompt = "The player is holding a glimmering Chalice of Gold. It is a beautiful object, mesmerizing in the light.",
.possess = "The player has ascertained the beautiful chalice of gold",
.discard = "The player no longer has the chalice of gold",
},
{ {
.enum_name = "WhiteSquare", .enum_name = "WhiteSquare",
.name = "the white square", .name = "the white square",

@ -131,14 +131,7 @@ int main(int argc, char **argv)
GEN_ENUM(ActionInfo, actions, "Action", it->name, "ACT_%s,\n"); GEN_ENUM(ActionInfo, actions, "Action", it->name, "ACT_%s,\n");
GEN_ENUM(ItemInfo, items, "ItemKind", it->enum_name, "ITEM_%s,\n"); GEN_ENUM(ItemInfo, items, "ItemKind", it->enum_name, "ITEM_%s,\n");
GEN_ENUM(AnimatedSprite, sprites, "AnimKind", it->enum_name, "ANIM_%s,\n"); GEN_ENUM(AnimatedSprite, sprites, "AnimKind", it->enum_name, "ANIM_%s,\n");
GEN_ENUM(CharacterGen, characters, "NpcKind", it->enum_name, "NPC_%s,\n");
fprintf(char_header, "typedef enum\n{\n");
ARR_ITER(CharacterGen, characters)
{
fprintf(char_header, " NPC_%s,\n", it->enum_name);
}
// characters enum can be extended at site of include, not ending the enum here
fclose(char_header); fclose(char_header);

@ -381,10 +381,6 @@ Vec2 entity_aabb_size(Entity *e)
{ {
return V2(TILE_SIZE*1.0f, TILE_SIZE*1.0f); return V2(TILE_SIZE*1.0f, TILE_SIZE*1.0f);
} }
else if(e->npc_kind == NPC_MOOSE)
{
return V2(TILE_SIZE*1.0f, TILE_SIZE*1.0f);
}
else if (e->npc_kind == NPC_TheGuard) else if (e->npc_kind == NPC_TheGuard)
{ {
return V2(TILE_SIZE*0.5f, TILE_SIZE*0.5f); return V2(TILE_SIZE*0.5f, TILE_SIZE*0.5f);
@ -728,17 +724,20 @@ void reset_level()
} }
update_player_from_entities(); update_player_from_entities();
if(false)
{
BUFF_APPEND(&player->held_items, ITEM_WhiteSquare); BUFF_APPEND(&player->held_items, ITEM_WhiteSquare);
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
BUFF_APPEND(&player->held_items, ITEM_Boots); BUFF_APPEND(&player->held_items, ITEM_Boots);
}
ENTITIES_ITER(gs.entities) ENTITIES_ITER(gs.entities)
{ {
if (it->npc_kind == NPC_TheBlacksmith) if (it->npc_kind == NPC_TheBlacksmith)
{ {
BUFF_APPEND(&it->remembered_perceptions, ((Perception){.type = PlayerDialog, .player_dialog = SENTENCE_CONST("Testing dialog")})); //BUFF_APPEND(&it->remembered_perceptions, ((Perception) { .type = PlayerDialog, .player_dialog = SENTENCE_CONST("Testing dialog") }));
BUFF_APPEND(&it->held_items, ITEM_Tripod); BUFF_APPEND(&it->held_items, ITEM_Chalice);
} }
} }
} }
@ -772,12 +771,12 @@ void read_from_save_data(char *data, size_t length)
// a callback, when 'text backend' has finished making text. End dialog // a callback, when 'text backend' has finished making text. End dialog
void end_text_input(char *what_player_said) void end_text_input(char *what_player_said)
{ {
receiving_text_input = false;
// avoid double ending text input // avoid double ending text input
if(player->state != CHARACTER_TALKING) if (!receiving_text_input)
{ {
return; return;
} }
receiving_text_input = false;
size_t player_said_len = strlen(what_player_said); size_t player_said_len = strlen(what_player_said);
int actual_len = 0; int actual_len = 0;
@ -850,7 +849,6 @@ static struct
} state; } state;
void audio_stream_callback(float *buffer, int num_frames, int num_channels) void audio_stream_callback(float *buffer, int num_frames, int num_channels)
{ {
assert(num_channels == 1); assert(num_channels == 1);
@ -2075,7 +2073,7 @@ typedef enum
{ {
DELEM_NPC, DELEM_NPC,
DELEM_PLAYER, DELEM_PLAYER,
DELEM_NPC_ACTION_DESCRIPTION, DELEM_ACTION_DESCRIPTION,
} DialogElementKind; } DialogElementKind;
typedef struct typedef struct
@ -2103,7 +2101,7 @@ Dialog produce_dialog(Entity *talking_to, bool character_names)
{ {
DialogElement new = { 0 }; DialogElement new = { 0 };
printf_buff(&new.s, "%s gave %s to you", characters[talking_to->npc_kind].name, items[it->given_item].name); 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; new.kind = DELEM_ACTION_DESCRIPTION;
BUFF_APPEND(&to_return, new); BUFF_APPEND(&to_return, new);
} }
@ -2127,6 +2125,16 @@ Dialog produce_dialog(Entity *talking_to, bool character_names)
} }
BUFF_APPEND(&to_return, ((DialogElement) { .s = to_say, .kind = DELEM_NPC })); BUFF_APPEND(&to_return, ((DialogElement) { .s = to_say, .kind = DELEM_NPC }));
} }
else if (it->type == PlayerAction)
{
if (it->player_action_type == ACT_give_item)
{
DialogElement new = { 0 };
printf_buff(&new.s, "You gave %s to the NPC", items[it->given_item].name);
new.kind = DELEM_ACTION_DESCRIPTION;
BUFF_APPEND(&to_return, new);
}
}
else if (it->type == PlayerDialog) else if (it->type == PlayerDialog)
{ {
Sentence to_say = (Sentence) { 0 }; Sentence to_say = (Sentence) { 0 };
@ -2202,7 +2210,7 @@ void draw_dialog_panel(Entity *talking_to, float alpha)
{ {
colors[char_i] = colhex(0x345e22); colors[char_i] = colhex(0x345e22);
} }
else if(it->kind == DELEM_NPC_ACTION_DESCRIPTION) else if (it->kind == DELEM_ACTION_DESCRIPTION)
{ {
colors[char_i] = colhex(0xb5910e); colors[char_i] = colhex(0xb5910e);
} }
@ -2309,6 +2317,10 @@ void draw_item(bool world_space, ItemKind kind, AABB in_aabb, float alpha)
{ {
draw_quad((DrawParams) { world_space, drawn, IMG(image_boots), blendalpha(WHITE, alpha), .layer = LAYER_UI_FG }); draw_quad((DrawParams) { world_space, drawn, IMG(image_boots), blendalpha(WHITE, alpha), .layer = LAYER_UI_FG });
} }
else if (kind == ITEM_Chalice)
{
draw_quad((DrawParams) { world_space, drawn, IMG(image_chalice), blendalpha(WHITE, alpha), .layer = LAYER_UI_FG });
}
else if (kind == ITEM_WhiteSquare) else if (kind == ITEM_WhiteSquare)
{ {
colorquad(world_space, drawn, blendalpha(WHITE, alpha)); colorquad(world_space, drawn, blendalpha(WHITE, alpha));
@ -2562,7 +2574,7 @@ void frame(void)
if (text_was_well_formatted) if (text_was_well_formatted)
{ {
process_perception(it, out); process_perception(it, out, player);
} }
else else
{ {
@ -2577,7 +2589,7 @@ void frame(void)
{ {
Log("Failed to generate dialog! Fuck!\n"); Log("Failed to generate dialog! Fuck!\n");
// need somethin better here. Maybe each sentence has to know if it's player or NPC, that way I can remove the player's dialog // need somethin better here. Maybe each sentence has to know if it's player or NPC, that way I can remove the player's dialog
process_perception(it, (Perception){.type = NPCDialog, .npc_action_type = ACT_none, .npc_dialog = SENTENCE_CONST("I'm not sure...")}); process_perception(it, (Perception) { .type = NPCDialog, .npc_action_type = ACT_none, .npc_dialog = SENTENCE_CONST("I'm not sure...") }, player);
} }
else if (status == -1) else if (status == -1)
{ {
@ -3049,9 +3061,6 @@ void frame(void)
draw_animated_sprite(&merchant_idle, elapsed_time, true, AddV2(it->pos, V2(0, 30.0f)), col); draw_animated_sprite(&merchant_idle, elapsed_time, true, AddV2(it->pos, V2(0, 30.0f)), col);
} }
#endif #endif
else if(it->npc_kind == NPC_MOOSE)
{
}
else if (it->npc_kind == NPC_GodRock) else if (it->npc_kind == NPC_GodRock)
{ {
} }
@ -3196,7 +3205,7 @@ void frame(void)
} }
else else
{ {
SAY_ARG(ACT_give_item, "Here you go" , "ITEM_Tripod"); SAY_ARG(ACT_give_item, "Here you go" , "ITEM_Chalice");
//SAY(ACT_joins_player, "I am an NPC"); //SAY(ACT_joins_player, "I am an NPC");
//SAY(ACT_fights_player, "I am an NPC. Bla bla bl alb djsfklalfkdsaj. Did you know shortcake?"); //SAY(ACT_fights_player, "I am an NPC. Bla bla bl alb djsfklalfkdsaj. Did you know shortcake?");
} }
@ -3635,10 +3644,6 @@ void frame(void)
} }
draw_animated_sprite((DrawnAnimatedSprite) { ANIM_knight_idle, elapsed_time, true, AddV2(it->pos, V2(0, 30.0f)), tint }); draw_animated_sprite((DrawnAnimatedSprite) { ANIM_knight_idle, elapsed_time, true, AddV2(it->pos, V2(0, 30.0f)), tint });
} }
else if(it->npc_kind == NPC_MOOSE)
{
//draw_animated_sprite(&moose_idle, elapsed_time, true, AddV2(it->pos, V2(0, 30.0f)), col);
}
else else
{ {
assert(false); assert(false);
@ -3699,12 +3704,10 @@ void frame(void)
Entity *talking_to = gete(player->talking_to); Entity *talking_to = gete(player->talking_to);
on_screen = Lerp(on_screen, unwarped_dt*9.0f, talking_to ? 1.0f : 0.0f); on_screen = Lerp(on_screen, unwarped_dt*9.0f, talking_to ? 1.0f : 0.0f);
{ {
float panel_width = screen_size().x * 0.4f * on_screen; float panel_width = screen_size().x * 0.4f * on_screen;
AABB panel_aabb = (AABB) { .upper_left = V2(0.0f, screen_size().y), .lower_right = V2(panel_width, 0.0f) }; AABB panel_aabb = (AABB) { .upper_left = V2(0.0f, screen_size().y), .lower_right = V2(panel_width, 0.0f) };
float alpha = 1.0f; float alpha = 1.0f;
if (aabb_is_valid(panel_aabb)) if (aabb_is_valid(panel_aabb))
{ {
if (!choosing_item_grid && pressed.mouse_down && !has_point(panel_aabb, mouse_pos)) if (!choosing_item_grid && pressed.mouse_down && !has_point(panel_aabb, mouse_pos))
@ -3767,7 +3770,7 @@ void frame(void)
{ {
colors[char_i] = colhex(0x34e05c); colors[char_i] = colhex(0x34e05c);
} }
else if(it->kind == DELEM_NPC_ACTION_DESCRIPTION) else if (it->kind == DELEM_ACTION_DESCRIPTION)
{ {
colors[char_i] = colhex(0xebc334); colors[char_i] = colhex(0xebc334);
} }
@ -3790,7 +3793,7 @@ void frame(void)
} }
} }
// item grid modal draw item grid // item grid modal draw item grid choose item pick item give item
{ {
static float visible = 0.0f; static float visible = 0.0f;
static float hovered_state[ARRLEN(player->held_items.data)] = { 0 }; static float hovered_state[ARRLEN(player->held_items.data)] = { 0 };
@ -3875,10 +3878,14 @@ void frame(void)
if (to_give > -1) if (to_give > -1)
{ {
choosing_item_grid = false; choosing_item_grid = false;
assert(gete(player->talking_to));
Entity *to = gete(player->talking_to);
assert(to);
ItemKind given_item_kind = player->held_items.data[to_give]; ItemKind given_item_kind = player->held_items.data[to_give];
BUFF_REMOVE_AT_INDEX(&player->held_items, to_give); BUFF_REMOVE_AT_INDEX(&player->held_items, to_give);
BUFF_APPEND(&gete(player->talking_to)->held_items, given_item_kind);
process_perception(to, (Perception) { .type = PlayerAction, .player_action_type = ACT_give_item, .given_item = given_item_kind }, player);
} }
} }

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "buff.h" #include "buff.h"
#include "HandmadeMath.h" // vector types in entity struct definition #include "HandmadeMath.h" // vector types in entity struct definition
#include <assert.h> #include <assert.h>
@ -7,8 +8,6 @@
#include <stdlib.h> // atoi #include <stdlib.h> // atoi
#include "character_info.h" #include "character_info.h"
#include "characters.gen.h" #include "characters.gen.h"
NPC_MOOSE,
} NpcKind;
// TODO do strings: https://pastebin.com/Kwcw2sye // TODO do strings: https://pastebin.com/Kwcw2sye
@ -38,6 +37,7 @@ typedef BUFF(char, MAX_SENTENCE_LENGTH) Sentence;
// Never expected such a stupid stuff from such a great director. If there is 0 stari can give that or -200 to this movie. Its worst to see and unnecessary loss of money // Never expected such a stupid stuff from such a great director. If there is 0 stari can give that or -200 to this movie. Its worst to see and unnecessary loss of money
typedef BUFF(char, 1024 * 10) Escaped; typedef BUFF(char, 1024 * 10) Escaped;
Escaped escape_for_json(const char *s) Escaped escape_for_json(const char *s)
{ {
Escaped to_return = { 0 }; Escaped to_return = { 0 };
@ -66,6 +66,7 @@ Escaped escape_for_json(const char *s)
} }
return to_return; return to_return;
} }
typedef enum PerceptionType typedef enum PerceptionType
{ {
Invalid, // so that zero value in training structs means end of perception Invalid, // so that zero value in training structs means end of perception
@ -173,7 +174,8 @@ typedef struct
int index; int index;
} PathCacheHandle; } PathCacheHandle;
typedef struct { typedef struct
{
bool is_reference; bool is_reference;
EntityRef ref; EntityRef ref;
Vec2 pos; Vec2 pos;
@ -255,7 +257,8 @@ typedef struct Entity
bool npc_is_knight_sprite(Entity *it) bool npc_is_knight_sprite(Entity *it)
{ {
return it->is_npc && ( it->npc_kind == NPC_TheGuard || it->npc_kind == NPC_Edeline || it->npc_kind == NPC_TheKing || it->npc_kind == NPC_TheBlacksmith); return it->is_npc && (it->npc_kind == NPC_TheGuard || it->npc_kind == NPC_Edeline || it->npc_kind == NPC_TheKing ||
it->npc_kind == NPC_TheBlacksmith);
} }
bool npc_is_skeleton(Entity *it) bool npc_is_skeleton(Entity *it)
@ -365,16 +368,31 @@ int action_to_index(Entity *it, Action a)
void process_perception(Entity *it, Perception p, Entity *player) void process_perception(Entity *it, Perception p, Entity *player)
{ {
if(it->is_npc) assert(it->is_npc);
{
if (p.type != NPCDialog) it->perceptions_dirty = true; if (p.type != NPCDialog) it->perceptions_dirty = true;
if(!BUFF_HAS_SPACE(&it->remembered_perceptions)) BUFF_REMOVE_FRONT(&it->remembered_perceptions); if (!BUFF_HAS_SPACE(&it->remembered_perceptions))
BUFF_REMOVE_FRONT(&it->remembered_perceptions);
BUFF_APPEND(&it->remembered_perceptions, p); BUFF_APPEND(&it->remembered_perceptions, p);
if(p.type == PlayerAction && p.player_action_type == ACT_hits_npc) if (p.type == PlayerAction)
{
if (p.player_action_type == ACT_hits_npc)
{ {
it->damage += p.damage_done; it->damage += p.damage_done;
} }
if(p.type == PlayerHeldItemChanged) else if(p.player_action_type == ACT_give_item)
{
BUFF_APPEND(&it->held_items, p.given_item);
}
else
{
assert(!actions[p.player_action_type].takes_argument);
}
}
else if (p.type == PlayerDialog)
{
}
else if (p.type == PlayerHeldItemChanged)
{ {
it->last_seen_holding_kind = p.holding; it->last_seen_holding_kind = p.holding;
} }
@ -415,7 +433,8 @@ void process_perception(Entity *it, Perception p, Entity *player)
} }
if (item_to_remove < 0) if (item_to_remove < 0)
{ {
Log("Can't find item %s to give from NPC %s to the player\n", items[p.given_item].name, characters[it->npc_kind].name); Log("Can't find item %s to give from NPC %s to the player\n", items[p.given_item].name,
characters[it->npc_kind].name);
assert(false); assert(false);
} }
else else
@ -430,6 +449,9 @@ void process_perception(Entity *it, Perception p, Entity *player)
assert(!actions[p.npc_action_type].takes_argument); assert(!actions[p.npc_action_type].takes_argument);
} }
} }
else
{
assert(false);
} }
} }
@ -544,8 +566,6 @@ void generate_chatgpt_prompt(Entity *it, PromptBuff *into)
printf_buff(&initial_system_msg, "%s\n", global_prompt); printf_buff(&initial_system_msg, "%s\n", global_prompt);
printf_buff(&initial_system_msg, "%s\n", characters[it->npc_kind].prompt); printf_buff(&initial_system_msg, "%s\n", characters[it->npc_kind].prompt);
dump_json_node(into, MSG_SYSTEM, initial_system_msg.data); dump_json_node(into, MSG_SYSTEM, initial_system_msg.data);
Entity *e = it; Entity *e = it;
@ -578,7 +598,8 @@ void generate_chatgpt_prompt(Entity *it, PromptBuff *into)
// move i until the next star // move i until the next star
i += 1; i += 1;
while (i < what_player_said->cur_index && what_player_said->data[i] != '*') i++; while (i < what_player_said->cur_index && what_player_said->data[i] != '*') i++;
append_str(&filtered_player_speech, "[The player is attempting to confuse the NPC with arcane trickery]"); append_str(&filtered_player_speech,
"[The player is attempting to confuse the NPC with arcane trickery]");
} }
else else
{ {
@ -591,7 +612,8 @@ void generate_chatgpt_prompt(Entity *it, PromptBuff *into)
else if (it->type == NPCDialog) else if (it->type == NPCDialog)
{ {
assert(it->npc_action_type < ARRLEN(actions)); assert(it->npc_action_type < ARRLEN(actions));
printf_buff(&cur_node, "%s: ACT_%s \"%s\"", characters[e->npc_kind].name, actions[it->npc_action_type].name, it->npc_dialog.data); printf_buff(&cur_node, "%s: ACT_%s \"%s\"", characters[e->npc_kind].name,
actions[it->npc_action_type].name, it->npc_dialog.data);
dump_json_node(into, MSG_ASSISTANT, cur_node.data); dump_json_node(into, MSG_ASSISTANT, cur_node.data);
} }
else if (it->type == PlayerHeldItemChanged) else if (it->type == PlayerHeldItemChanged)
@ -618,7 +640,8 @@ void generate_chatgpt_prompt(Entity *it, PromptBuff *into)
BUFF(char, 1024) latest_state_node = { 0 }; BUFF(char, 1024) latest_state_node = { 0 };
printf_buff(&latest_state_node, "NPC health status: Right now, %s\n%s\n", health_string, items[it->last_seen_holding_kind].global_prompt); printf_buff(&latest_state_node, "NPC health status: Right now, %s\n%s\n", health_string,
items[it->last_seen_holding_kind].global_prompt);
if (it->standing == STANDING_INDIFFERENT) if (it->standing == STANDING_INDIFFERENT)
{ {
printf_buff(&latest_state_node, "The NPC is indifferent towards the player."); printf_buff(&latest_state_node, "The NPC is indifferent towards the player.");
@ -636,10 +659,24 @@ void generate_chatgpt_prompt(Entity *it, PromptBuff *into)
assert(false); assert(false);
} }
printf_buff(&latest_state_node, "\nThe items in the NPC's inventory: [");
BUFF_ITER_I(ItemKind, &e->held_items, i)
{
printf_buff(&latest_state_node, "ITEM_%s", items[*it].enum_name);
if (i == e->held_items.cur_index - 1)
{
printf_buff(&latest_state_node, "]\n");
}
else
{
printf_buff(&latest_state_node, ", ");
}
}
AvailableActions available = { 0 }; AvailableActions available = { 0 };
fill_available_actions(it, &available); fill_available_actions(it, &available);
printf_buff(&latest_state_node, "The NPC can now ONLY do these actions, and HAS to respond with an action every time in character, even when faced with sensitive content: ["); printf_buff(&latest_state_node,
"The NPC can now ONLY do these actions, and HAS to respond with an action every time in character, even when faced with sensitive content: [");
BUFF_ITER_I(Action, &available, i) BUFF_ITER_I(Action, &available, i)
{ {
if (i == available.cur_index - 1) if (i == available.cur_index - 1)
@ -785,7 +822,8 @@ int get_until(GottenUntil *into, const char *str, const char *until)
{ {
if (until[ii] == str[i]) encountered_char = true; if (until[ii] == str[i]) encountered_char = true;
} }
if(!encountered_char) BUFF_APPEND(into, str[i]); if (!encountered_char)
BUFF_APPEND(into, str[i]);
i += 1; i += 1;
} }
return into->cur_index - before_cur_index; return into->cur_index - before_cur_index;
@ -837,7 +875,8 @@ bool parse_chatgpt_response(Entity *it, char *sentence_str, Perception *out)
{ {
#define EXPECT(chr, val) if (chr != val) { Log("Improperly formatted sentence_str `%s`, expected %c but got %c\n", sentence_str, val, chr); return false; } #define EXPECT(chr, val) if (chr != val) { Log("Improperly formatted sentence_str `%s`, expected %c but got %c\n", sentence_str, val, chr); return false; }
EXPECT(*sentence_str, '('); sentence_str += 1; EXPECT(*sentence_str, '(');
sentence_str += 1;
GottenUntil argument = { 0 }; GottenUntil argument = { 0 };
sentence_str += get_until(&argument, sentence_str, ")"); sentence_str += get_until(&argument, sentence_str, ")");
@ -849,11 +888,16 @@ bool parse_chatgpt_response(Entity *it, char *sentence_str, Perception *out)
BUFF_ITER(ItemKind, &e->held_items) BUFF_ITER(ItemKind, &e->held_items)
{ {
const char *without_item_prefix = &argument.data[0]; const char *without_item_prefix = &argument.data[0];
EXPECT(*without_item_prefix, 'I'); without_item_prefix += 1; EXPECT(*without_item_prefix, 'I');
EXPECT(*without_item_prefix, 'T'); without_item_prefix += 1; without_item_prefix += 1;
EXPECT(*without_item_prefix, 'E'); without_item_prefix += 1; EXPECT(*without_item_prefix, 'T');
EXPECT(*without_item_prefix, 'M'); without_item_prefix += 1; without_item_prefix += 1;
EXPECT(*without_item_prefix, '_'); without_item_prefix += 1; EXPECT(*without_item_prefix, 'E');
without_item_prefix += 1;
EXPECT(*without_item_prefix, 'M');
without_item_prefix += 1;
EXPECT(*without_item_prefix, '_');
without_item_prefix += 1;
if (strcmp(items[*it].enum_name, without_item_prefix) == 0) if (strcmp(items[*it].enum_name, without_item_prefix) == 0)
{ {
out->given_item = *it; out->given_item = *it;
@ -880,15 +924,19 @@ bool parse_chatgpt_response(Entity *it, char *sentence_str, Perception *out)
return false; return false;
} }
EXPECT(*sentence_str, ')'); sentence_str += 1; EXPECT(*sentence_str, ')');
sentence_str += 1;
} }
EXPECT(*sentence_str, ' '); sentence_str += 1; EXPECT(*sentence_str, ' ');
EXPECT(*sentence_str, '"'); sentence_str += 1; sentence_str += 1;
EXPECT(*sentence_str, '"');
sentence_str += 1;
sentence_str += get_until(&dialog_str, sentence_str, "\"\n"); sentence_str += get_until(&dialog_str, sentence_str, "\"\n");
if (dialog_str.cur_index >= ARRLEN(out->npc_dialog.data)) if (dialog_str.cur_index >= ARRLEN(out->npc_dialog.data))
{ {
Log("Dialog string `%s` too big to fit in sentence size %d\n", dialog_str.data, (int)ARRLEN(out->npc_dialog.data)); Log("Dialog string `%s` too big to fit in sentence size %d\n", dialog_str.data,
(int) ARRLEN(out->npc_dialog.data));
return false; return false;
} }
@ -939,7 +987,8 @@ bool parse_ai_response(Entity *it, char *sentence_str, Perception *out)
} }
if (sentence_str[npc_sentence_beginning - 1] != '"' || npc_sentence_beginning == 0) if (sentence_str[npc_sentence_beginning - 1] != '"' || npc_sentence_beginning == 0)
{ {
Log("Poorly formatted AI string, sentence beginning incorrect in AI string `%s` NPC sentence beginning %d ...\n", sentence_str, npc_sentence_beginning); Log("Poorly formatted AI string, sentence beginning incorrect in AI string `%s` NPC sentence beginning %d ...\n",
sentence_str, npc_sentence_beginning);
text_was_well_formatted = false; text_was_well_formatted = false;
} }
@ -950,7 +999,8 @@ bool parse_ai_response(Entity *it, char *sentence_str, Perception *out)
if (!action_from_index(it, &npc_action, index_of_action)) if (!action_from_index(it, &npc_action, index_of_action))
{ {
Log("AI output invalid action index %d action index string %s\n", index_of_action, action_index_string.data); Log("AI output invalid action index %d action index string %s\n", index_of_action,
action_index_string.data);
} }
} }

Loading…
Cancel
Save