thrive/01_text_adventure/transition.c
2025-01-19 08:39:00 -05:00

38 lines
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "transition.h"
#include "game.h"
#include "util.h"
void load_transition(Game *g, char *line) {
char *token = strtok(line, "|");
g->transitions->transitions[g->transitions->count].from = find_room(g->rooms, token);
token = strtok(NULL, "|");
g->transitions->transitions[g->transitions->count].via = command_from_string(token);
token = strtok(NULL, "|");
g->transitions->transitions[g->transitions->count].to = find_room(g->rooms, token);
token = strtok(NULL, "\n");
g->transitions->transitions[g->transitions->count].description = malloc(strlen(token) + 1);
strcpy(g->transitions->transitions[g->transitions->count].description, token);
g->transitions->count++;
}
#include "data/transitions.c"
void game_load_transitions(Game *g) {
parse_multiline_string(g, data_transitions_txt, &load_transition);
}
Transition *find_transition(Transitions *t, Room *from, CommandType via) {
for (int i = 0; i < t->count; i++) {
Transition *candidate = &t->transitions[i];
if (candidate->from == from && candidate->via == via) return candidate;
}
return NULL;
}