#include "walkthrough.h" #include #include "datatypes.h" #include "input.h" /* Copyright (c) 2013-2021 Devine Lu Linvega 2018 web port by rezmason 2021 C89 port by rezmason Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ static InputType (*steps)[] = NULL; static int numSteps; static int stepIndex; int Walkthrough_Init(char *data) { int i, j; stepIndex = 0; numSteps = strlen(data); steps = calloc(numSteps, sizeof(InputType)); j = 0; for(i = 0; i < numSteps; i++) { int found = 1; InputType step = INPUTTYPE_ACTION; switch(data[i]) { case 'l': step = INPUTTYPE_LEFT; break; case 'r': step = INPUTTYPE_RIGHT; break; case 'f': step = INPUTTYPE_FORWARD; break; case 'a': step = INPUTTYPE_ACTION; break; default: found = 0; break; } if(found) { (*steps)[j] = step; j++; } } for(; j < numSteps; j++) { (*steps)[j] = INPUTTYPE_ACTION; } return 1; } void Walkthrough_Quit() { free(steps); steps = NULL; } void Walkthrough_Reset() { stepIndex = 0; } InputType Walkthrough_Next() { InputType step = INPUTTYPE_ACTION; if(stepIndex < numSteps) { step = (*steps)[stepIndex]; } #ifdef DEBUG printf("STEP %d: %d\n", stepIndex, step); #endif stepIndex++; return step; }