Convert several if() else assert(false) into switches so it warns and errors on compile time

main
parent 30b2755186
commit 0b2170efb9

@ -5,7 +5,8 @@
// @TODO allow AI to prefix out of character statemetns with [ooc], this is a well khnown thing on role playing forums so gpt would pick up on it. // @TODO allow AI to prefix out of character statemetns with [ooc], this is a well khnown thing on role playing forums so gpt would pick up on it.
const char *global_prompt = const char *global_prompt =
"You are a character in a simple western video game. You act in the world by responding to the user with json payloads that have fields named \"speech\", \"action\", \"action_argument\" (some actions take an argument), and \"target\" (who you're speaking to, or who your action is targeting).\n" "You are a character in a simple western video game. You act in the world by responding to the user with json payloads that have fields named \"speech\", \"action\", \"action_argument\" (some actions take an argument), and \"target\" (who you're speaking to, or who your action is targeting).\n"
"You speak only when you have something to say, or are responding to somebody, and use short, concise, punchy language. If you're just overhearing what other people are saying, you only say something when absolutely compelled to do so" "You speak only when you have something to say, or are responding to somebody, and use short, concise, punchy language. If you're just overhearing what other people are saying, you only say something when absolutely compelled to do so.\n"
"But if somebody talks directly to you, you usually say someting."
; ;
const char *top_of_header = "" const char *top_of_header = ""

@ -6606,44 +6606,40 @@ ISANERROR("Don't know how to do this stuff on this platform.")
float speed = 0.0f; float speed = 0.0f;
{ {
if(gs.player->killed) gs.player->state = CHARACTER_KILLED; if(gs.player->killed) gs.player->state = CHARACTER_KILLED;
if(gs.player->state == CHARACTER_WALKING)
switch(gs.player->state)
{ {
case CHARACTER_WALKING:
player_armature.go_to_animation = MD_S8Lit("Running"); player_armature.go_to_animation = MD_S8Lit("Running");
} break;
else if(gs.player->state == CHARACTER_IDLE) case CHARACTER_IDLE:
{
player_armature.go_to_animation = MD_S8Lit("Idle"); player_armature.go_to_animation = MD_S8Lit("Idle");
} break;
else if(gs.player->state == CHARACTER_KILLED) case CHARACTER_KILLED:
{
player_armature.go_to_animation = MD_S8Lit("Die Backwards"); player_armature.go_to_animation = MD_S8Lit("Die Backwards");
player_armature.next_animation_isnt_looping = true; player_armature.next_animation_isnt_looping = true;
break;
} }
else assert(false);
if (gs.player->state == CHARACTER_WALKING) switch (gs.player->state)
{ {
speed = PLAYER_SPEED; case CHARACTER_WALKING:
if (LenV2(movement) == 0.0) speed = PLAYER_SPEED;
{ if (LenV2(movement) == 0.0)
{
gs.player->state = CHARACTER_IDLE; gs.player->state = CHARACTER_IDLE;
} }
else else
{ {
} }
} break;
else if (gs.player->state == CHARACTER_IDLE) case CHARACTER_IDLE:
{ if (LenV2(movement) > 0.01)
if (LenV2(movement) > 0.01) gs.player->state = CHARACTER_WALKING; gs.player->state = CHARACTER_WALKING;
} break;
else if (gs.player->state == CHARACTER_KILLED) case CHARACTER_KILLED:
{ break;
}
else
{
assert(false); // unknown character state? not defined how to process
} }
} // not time stopped } // not time stopped

@ -427,27 +427,26 @@ MD_String8 generate_chatgpt_prompt(MD_Arena *arena, GameState *gs, Entity *e, Ca
// dump a human understandable sentence description of what happened in this memory // dump a human understandable sentence description of what happened in this memory
if(it->action_taken != ACT_none) if(it->action_taken != ACT_none)
{ {
if(it->action_taken == ACT_join) switch(it->action_taken)
{ {
case ACT_none:
break;
case ACT_join:
AddFmt("%s joined %s\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name); AddFmt("%s joined %s\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name);
} break;
else if(it->action_taken == ACT_leave) case ACT_leave:
{
// Needs better handling of when you leave, because the person you were following died. Maybe entities don't die anymore?
AddFmt("%s left their party\n", characters[it->context.author_npc_kind].name); AddFmt("%s left their party\n", characters[it->context.author_npc_kind].name);
} break;
else if(it->action_taken == ACT_aim_shotgun) case ACT_aim_shotgun:
{
AddFmt("%s aimed their shotgun at %s\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name); AddFmt("%s aimed their shotgun at %s\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name);
} break;
else if(it->action_taken == ACT_fire_shotgun) case ACT_fire_shotgun:
{
AddFmt("%s fired their shotgun at %s, brutally murdering them.\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name); AddFmt("%s fired their shotgun at %s, brutally murdering them.\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name);
} break;
else case ACT_put_shotgun_away:
{ AddFmt("%s holstered their shotgun, no longer threatening anybody\n", characters[it->context.author_npc_kind].name);
assert(false); break;
} }
} }
if(it->speech.text_length > 0) if(it->speech.text_length > 0)
{ {

Loading…
Cancel
Save