Load some of the action stuff

This commit is contained in:
Bill Rossi 2025-01-16 20:15:50 -05:00
parent 28077a0eeb
commit df0b65e097
9 changed files with 102 additions and 1 deletions

View File

@ -3,7 +3,7 @@ CFLAGS=-Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
.PHONY: clean run .PHONY: clean run
game: data/rooms.c data/transitions.c data/words.c data/flags.c *.c game: data/actions.c data/rooms.c data/transitions.c data/words.c data/flags.c *.c
$(CC) *.c $(CFLAGS) -o game $(CC) *.c $(CFLAGS) -o game
data/%.c: data/%.txt data/%.c: data/%.txt

View File

@ -0,0 +1,50 @@
#include <stdlib.h>
#include <string.h>
#include "action.h"
#include "game.h"
#include "util.h"
void load_action(Game *g, char *line) {
Action *action = &g->actions->actions[g->actions->count];
char *line_token_guy;
char *line_token = strtok_r(line, "|", &line_token_guy);
char command_buffer[200];
strcpy(command_buffer, line_token);
char *command_token_guy;
char *command_word = strtok_r(command_buffer, " ", &command_token_guy);
while (command_word != NULL) {
Word *word = find_word(g->words, command_word);
action->words[action->words_count++] = word;
command_word = strtok_r(NULL, " ", &command_token_guy);
}
line_token = strtok_r(NULL, "|", &line_token_guy);
// predicate bullshit
// char *command_predicate_strtok = strtok_r
line_token = strtok_r(NULL, "|", &line_token_guy);
action->priority = atoi(line_token);
line_token = strtok_r(NULL, "|", &line_token_guy);
action->description = malloc(strlen(line_token) + 1);
strcpy(action->description, line_token);
line_token = strtok_r(NULL, "|", &line_token_guy);
// action bullshit
g->actions->count++;
}
#include "data/actions.c"
void game_load_actions(Game *g) {
parse_multiline_string(g, data_actions_txt, &load_action);
}
Action *find_action(Actions *actions, char *command) {
return NULL;
}

View File

@ -0,0 +1,29 @@
#ifndef _FD_ACTION_
#define _FD_ACTION_
typedef struct Action Action;
typedef struct Actions Actions;
#include "game.h"
#include "word.h"
#include "predicate.h"
struct Action {
Word *words[4];
int words_count;
Predicate *predicates[10];
int predicates_count;
int priority;
char *description;
// Effect *effect;
};
struct Actions {
Action actions[1000];
int count;
};
void game_load_actions(Game *g);
Action *find_action(Actions *actions, char *command);
#endif

View File

@ -0,0 +1,4 @@
PULL|*|1|You don't see anything to pull|
PULL|IN(lever_room)|10|What do you want to pull?|
PULL LEVER|IN(lever_room)|100|You pull the lever. Nice.|ENABLE(lever_pulled)
PULL LEVER|IN(lever_room) & ENABLED(lever_pulled)|1000|You already pulled it.|

View File

@ -1,2 +1,3 @@
PULL|PULL,YANK,TUG PULL|PULL,YANK,TUG
ROPE|ROPE,CORD,STRING,CABLE ROPE|ROPE,CORD,STRING,CABLE
LEVER|LEVER

View File

@ -10,6 +10,7 @@
#include "word.h" #include "word.h"
#include "flag.h" #include "flag.h"
#include "predicate.h" #include "predicate.h"
#include "action.h"
Game *game_create(void) { Game *game_create(void) {
Game *g = malloc(sizeof(Game)); Game *g = malloc(sizeof(Game));
@ -39,6 +40,9 @@ Game *game_create(void) {
g->flags = malloc(sizeof(Flags)); g->flags = malloc(sizeof(Flags));
g->flags->count = 0; g->flags->count = 0;
g->actions = malloc(sizeof(Actions));
g->actions->count = 0;
return g; return g;
} }

View File

@ -20,6 +20,7 @@ typedef enum Command {
#include "log.h" #include "log.h"
#include "word.h" #include "word.h"
#include "flag.h" #include "flag.h"
#include "action.h"
struct Game { struct Game {
bool should_close; bool should_close;
@ -30,6 +31,7 @@ struct Game {
Transitions *transitions; Transitions *transitions;
Words *words; Words *words;
Flags *flags; Flags *flags;
Actions *actions;
}; };
Game *game_create(void); Game *game_create(void);

View File

@ -20,6 +20,16 @@ int main(void) {
game_load_transitions(g); game_load_transitions(g);
game_load_words(g); game_load_words(g);
game_load_flags(g); game_load_flags(g);
game_load_actions(g);
for (int i = 0; i < g->actions->count; i++) {
for (int j = 0; j < g->actions->actions[i].words_count; j++) {
printf("%s ", g->actions->actions[i].words[j]->word);
}
printf("|preds|%d|%s|effects", g->actions->actions[i].priority, g->actions->actions[i].description);
printf("\n");
}
game_run_until_close(g); game_run_until_close(g);
CloseWindow(); CloseWindow();

View File

@ -33,5 +33,6 @@ Word *find_word(Words *words, char *word_or_syn) {
} }
} }
printf("Can't find %s\n", word_or_syn);
return NULL; return NULL;
} }