Buff iteration by index macro

main
parent 4f5979405a
commit cefaff51fb

@ -7,8 +7,8 @@
#define BUFF_HAS_SPACE(buff_ptr) ( (buff_ptr)->cur_index < ARRLEN((buff_ptr)->data) )
#define BUFF_EMPTY(buff_ptr) ((buff_ptr)->cur_index == 0)
#define BUFF_APPEND(buff_ptr, element) { (buff_ptr)->data[(buff_ptr)->cur_index++] = element; BUFF_VALID(buff_ptr); }
#define BUFF_ITER_EX(type, buff_ptr, begin_ind, cond, movement) for(type *it = &((buff_ptr)->data[begin_ind]); cond; movement)
#define BUFF_ITER(type, buff_ptr) BUFF_ITER_EX(type, (buff_ptr), 0, it < (buff_ptr)->data + (buff_ptr)->cur_index, it++)
#define BUFF_ITER(type, buff_ptr) for(type *it = &((buff_ptr)->data[0]); it < &((buff_ptr)->data[(buff_ptr)->cur_index]); it++)
#define BUFF_ITER_I(type, buff_ptr, i_var) BUFF_ITER(type, buff_ptr) for(int i_var = (int)(it - &((buff_ptr)->data[0])); i_var != -1; i_var = -1)
#define BUFF_PUSH_FRONT(buff_ptr, value) { (buff_ptr)->cur_index++; BUFF_VALID(buff_ptr); for(int i = (buff_ptr)->cur_index - 1; i > 0; i--) { (buff_ptr)->data[i] = (buff_ptr)->data[i - 1]; }; (buff_ptr)->data[0] = value; }
#define BUFF_REMOVE_FRONT(buff_ptr) {if((buff_ptr)->cur_index > 0) {for(int i = 0; i < (buff_ptr)->cur_index - 1; i++) { (buff_ptr)->data[i] = (buff_ptr)->data[i+1]; }; (buff_ptr)->cur_index--;}}
#define BUFF_CLEAR(buff_ptr) {memset((buff_ptr), 0, sizeof(*(buff_ptr))); ((buff_ptr)->cur_index = 0);}

@ -38,32 +38,12 @@ actions:
actions_str: "ACT@[ALLOW_PASS]",
}
@character Hunter:
{
name: "Hunter the Soldier",
prompt: "Hunter, the NPC, is a nervous guy who trusts authority more than himself. He doesn't believe in the white square's powers.",
}
@character GodRock:
{
name: "God",
prompt: "The NPC is God. God, in a rock.",
}
@character Max:
{
name: "Max the Soldier",
prompt: "Max, the NPC, is a Gung-ho guy who masks his fear of failure with bravado and a need for blood.",
actions_str: "",
}
@character John:
{
name: "John the Soldier",
prompt: "John, the NPC, is a critical guy who cares about others way too much.",
actions_str: "*gives WhiteSquare*",
}
@character Death:
{
name: "General Death",
@ -71,6 +51,12 @@ actions:
actions_str: "",
}
@character Geoff:
{
name: "Geoff, the Knight",
prompt: "A Knight named Geoff acts as the moral judge to everyone he meets. He has the power to know each persons darkest deeds as if he can feel their soul being tainted. At times, the Knight is known to execute those he deems the lowest of scum, mainly murderers and betrayers. The Great Dragon is a monster the Knight believes to be a god of evil and wishes for its death."
}
@item WhiteSquare:
{
global_prompt_message: "The player is holding a mysterious white square. It is unknown what strange and erotic abilities one has when they possess the square.",

@ -57,6 +57,16 @@ float clamp01(float f)
return clampf(f, 0.0f, 1.0f);
}
#ifdef min
#undef min
#endif
int min(int a, int b)
{
if(a < b) return a;
else return b;
}
// so can be grep'd and removed
#define dbgprint(...) { printf("Debug | %s:%d | ", __FILE__, __LINE__); printf(__VA_ARGS__); }
Vec2 RotateV2(Vec2 v, float theta)
@ -1645,13 +1655,20 @@ void dbgrect(AABB rect)
{
#ifdef DEVTOOLS
if(!show_devtools) return;
const float line_width = 0.5;
Color col = debug_color;
Quad q = quad_aabb(rect);
line(q.ul, q.ur, line_width, col);
line(q.ur, q.lr, line_width, col);
line(q.lr, q.ll, line_width, col);
line(q.ll, q.ul, line_width, col);
if(!aabb_is_valid(rect))
{
dbgsquare(rect.upper_left);
}
else
{
const float line_width = 0.5;
Color col = debug_color;
Quad q = quad_aabb(rect);
line(q.ul, q.ur, line_width, col);
line(q.ur, q.lr, line_width, col);
line(q.lr, q.ll, line_width, col);
line(q.ll, q.ul, line_width, col);
}
#else
(void)rect;
#endif
@ -2126,15 +2143,13 @@ float draw_wrapped_text(bool dry_run, Vec2 at_point, float max_width, char *text
Sentence *last_said_sentence(Entity *npc)
{
int i = 0;
BUFF_ITER(Perception, &npc->remembered_perceptions)
BUFF_ITER_I(Perception, &npc->remembered_perceptions, i)
{
bool is_last_said = i == npc->remembered_perceptions.cur_index - 1;
if(is_last_said && it->type == NPCDialog)
{
return &it->npc_dialog;
}
i += 1;
}
return 0;
}
@ -2189,7 +2204,6 @@ void draw_dialog_panel(Entity *talking_to, float alpha)
} DialogElement;
BUFF(DialogElement, 32) dialog = {0};
int i = 0;
BUFF_ITER(Perception, &talking_to->remembered_perceptions)
{
if(it->type == NPCDialog)

@ -0,0 +1,20 @@
I'm making an action-rpg where large language models control the characters and their actions,
and I need training data written for a character named 'Edeline'. She is the master of the future, the star reader. Both are self-given titles, but her ability to predict the future has garnered attention from many who live in Worchen. However, some have called her 'unreliable' at times and her predictions can at times be either cryptic or broadly interpreted.
Here is an example of something like what I need, but for another NPC named blocky:
{
.npc_kind = NPC_Blocky,
.elems = {
PlayerSay("If you don't move out of the way I'll kill you"),
NPCDoSay(ACT_none, "I'm just standing here, what are you doing?"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "Looks like you're ready to do what needs to be done."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "I'm not sure what you're thinking, but that doesn't sound like a good idea."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_allows_player_to_pass, "Fine! Please spare me!"),
PlayerSay("That's more like it"),
},
},
Can you make training data like this but for Edeline instead?

@ -334,7 +334,24 @@ TrainingSample samples[] = {
PlayerSay("Give me gold or I'll kill you"),
NPCSay("I have nothing to give! Besides, I'll never give into tyrrany"),
},
}
},
{
{
.npc_kind = NPC_Edeline,
.elems = {
PlayerSay("Edeline, what do you see in my future?"),
NPCDoSay(ACT_none, "I see the stars aligning, but the path is unclear."),
PlayerSay("What does that mean?"),
NPCDoSay(ACT_none, "It means you have a choice to make, and your actions will determine the outcome."),
PlayerSay("Can you give me more details?"),
NPCDoSay(ACT_none, "I'm sorry, that's all I can see for now."),
PlayerSay("That's not very helpful."),
NPCDoSay(ACT_none, "I understand, but the future is ever-changing."),
PlayerSay("Can you at least tell me if I'll be successful?"),
NPCDoSay(ACT_none, "Success is not defined by a single outcome. You must find your own path."),
},
},
},
};

@ -387,6 +387,7 @@ func completion(w http.ResponseWriter, req *http.Request) {
inSystem = false
}
}
log.Println("Messages array: ", messages)
clippedOfEndPrompt := messages[:len(messages)-1]
resp, err := c.CreateChatCompletion(
context.Background(),

Loading…
Cancel
Save