mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-06-25 22:18:30 +02:00
This overhauls scriptclass::gamemode massively. The first change is that it now uses an enum, and enforces using that enum via using its type instead of an int. This is because whenever you're reading any calls to startgamemode, you have no idea what magic number actually corresponds to what unless you read startgamemode itself. And when you do read it, not every case is commented adequately, so you'd have to do more work to figure out what each case is. With the enum, it's obvious and self-evident, and that also removes the need for all the comments in the function too. Some math is still done on mode variables (to simplify time trial code), but it's okay, we can just cast between int and the enum as needed. The second is that common code is now de-duplicated. There was a lot of code that every case does, such as calling hardreset, setting Flip Mode, resetting the player, calling gotoroom and so on. Now some code may be duplicated between cases, so I've tried to group up similar cases where possible (most notable example is grouping up the main game and No Death Mode cases together). But some code still might be duplicated in the end. Which is okay - I could've tried to de-duplicate it further but that just results in logic relevant to a specific case that's located far from the actual case itself. It's much better to leave things like setting fademode or loading scripts in the case itself. This also fixes a bug since 2.3 where playing No Death Mode (and never opening and closing the options menu) and beating it would also give you the Flip Mode trophy, since turning on the flag to invalidate Flip Mode in startgamemode only happened for the main game cases and in previous versions the game relied upon this flag being set when using a teleporter for some reason (which I removed in 2.3). Now instead of specifying it per case, I just do a !map.custommode check instead so it covers every single case at once.
117 lines
2.4 KiB
C++
117 lines
2.4 KiB
C++
#ifndef SCRIPT_H
|
|
#define SCRIPT_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <SDL.h>
|
|
|
|
#define filllines(lines) commands.insert(commands.end(), lines, lines + SDL_arraysize(lines))
|
|
|
|
|
|
struct Script
|
|
{
|
|
std::string name;
|
|
std::vector<std::string> contents;
|
|
};
|
|
|
|
#define NUM_SCRIPT_ARGS 40
|
|
|
|
enum StartMode
|
|
{
|
|
Start_MAINGAME,
|
|
Start_MAINGAME_TELESAVE,
|
|
Start_MAINGAME_QUICKSAVE,
|
|
Start_TIMETRIAL_SPACESTATION1,
|
|
Start_TIMETRIAL_LABORATORY,
|
|
Start_TIMETRIAL_TOWER,
|
|
Start_TIMETRIAL_SPACESTATION2,
|
|
Start_TIMETRIAL_WARPZONE,
|
|
Start_TIMETRIAL_FINALLEVEL,
|
|
Start_NODEATHMODE_WITHCUTSCENES,
|
|
Start_NODEATHMODE_NOCUTSCENES,
|
|
Start_SECRETLAB,
|
|
Start_INTERMISSION1_VITELLARY,
|
|
Start_INTERMISSION1_VERMILION,
|
|
Start_INTERMISSION1_VERDIGRIS,
|
|
Start_INTERMISSION1_VICTORIA,
|
|
Start_INTERMISSION2_VITELLARY,
|
|
Start_INTERMISSION2_VERMILION,
|
|
Start_INTERMISSION2_VERDIGRIS,
|
|
Start_INTERMISSION2_VICTORIA,
|
|
Start_EDITOR,
|
|
Start_EDITORPLAYTESTING,
|
|
Start_CUSTOM,
|
|
Start_CUSTOM_QUICKSAVE,
|
|
Start_QUIT,
|
|
|
|
Start_FIRST_NODEATHMODE = Start_NODEATHMODE_WITHCUTSCENES,
|
|
Start_LAST_NODEATHMODE = Start_NODEATHMODE_NOCUTSCENES,
|
|
Start_FIRST_INTERMISSION1 = Start_INTERMISSION1_VITELLARY,
|
|
Start_LAST_INTERMISSION1 = Start_INTERMISSION1_VICTORIA,
|
|
Start_FIRST_INTERMISSION2 = Start_INTERMISSION2_VITELLARY,
|
|
Start_LAST_INTERMISSION2 = Start_INTERMISSION2_VICTORIA,
|
|
|
|
Start_FIRST_TIMETRIAL = Start_TIMETRIAL_SPACESTATION1
|
|
};
|
|
|
|
class scriptclass
|
|
{
|
|
public:
|
|
|
|
|
|
scriptclass(void);
|
|
|
|
void load(const std::string& name);
|
|
void loadother(const char* t);
|
|
void loadcustom(const std::string& t);
|
|
|
|
void inline add(const std::string& t)
|
|
{
|
|
commands.push_back(t);
|
|
}
|
|
|
|
void clearcustom(void);
|
|
|
|
void tokenize(const std::string& t);
|
|
|
|
void run(void);
|
|
|
|
void resetgametomenu(void);
|
|
|
|
void startgamemode(enum StartMode mode);
|
|
|
|
void teleport(void);
|
|
|
|
void hardreset(void);
|
|
|
|
//Script contents
|
|
std::vector<std::string> commands;
|
|
std::string words[NUM_SCRIPT_ARGS];
|
|
std::vector<std::string> txt;
|
|
std::string scriptname;
|
|
int position;
|
|
int looppoint, loopcount;
|
|
|
|
int scriptdelay;
|
|
bool running;
|
|
|
|
//Textbox stuff
|
|
int textx;
|
|
int texty;
|
|
int r,g,b;
|
|
bool textflipme;
|
|
|
|
//Misc
|
|
int i, j, k;
|
|
|
|
//Custom level stuff
|
|
std::vector<Script> customscripts;
|
|
};
|
|
|
|
#ifndef SCRIPT_DEFINITION
|
|
extern scriptclass script;
|
|
#endif
|
|
|
|
#endif /* SCRIPT_H */
|