1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-25 05:58:30 +02:00

Turn crew rescued/mood vectors into arrays

Since they're always fixed-size, they don't need to be dynamically-sized
vectors.

entityclass::customcrewmoods is now a proper bool instead of an int now,
and I replaced the hardcoded constant 6 with a static const int Game
attribute to make it easier to change.
This commit is contained in:
Misa 2020-07-02 18:10:52 -07:00 committed by Ethan Lee
parent cd3869f974
commit 1258eb7bf4
5 changed files with 30 additions and 102 deletions

View File

@ -67,10 +67,7 @@ void entityclass::init()
altstates = 0;
for (int i = 0; i < 6; i++)
{
customcrewmoods[i]=1;
}
SDL_memset(customcrewmoods, true, sizeof(customcrewmoods));
flags.resize(100);
collect.resize(100);

View File

@ -207,7 +207,7 @@ public:
int customplatformtile;
bool customwarpmode, customwarpmodevon, customwarpmodehon;
std::string customscript;
int customcrewmoods[6];
bool customcrewmoods[Game::numcrew];
};
extern entityclass obj;

View File

@ -209,9 +209,9 @@ void Game::init(void)
}
customcol=0;
crewstats.resize(6);
tele_crewstats.resize(6);
quick_crewstats.resize(6);
SDL_memset(crewstats, false, sizeof(crewstats));
SDL_memset(tele_crewstats, false, sizeof(tele_crewstats));
SDL_memset(quick_crewstats, false, sizeof(quick_crewstats));
SDL_memset(besttimes, -1, sizeof(besttimes));
SDL_memset(bestframes, -1, sizeof(bestframes));
SDL_memset(besttrinkets, -1, sizeof(besttrinkets));
@ -4589,20 +4589,22 @@ void Game::unlocknum( int t )
savestats();
}
#define LOAD_ARRAY(ARRAY_NAME) \
#define LOAD_ARRAY_RENAME(ARRAY_NAME, DEST) \
if (pKey == #ARRAY_NAME) \
{ \
std::string TextString = pText; \
if (TextString.length()) \
{ \
std::vector<std::string> values = split(TextString, ','); \
for (size_t i = 0; i < SDL_min(SDL_arraysize(ARRAY_NAME), values.size()); i++) \
for (size_t i = 0; i < SDL_min(SDL_arraysize(DEST), values.size()); i++) \
{ \
ARRAY_NAME[i] = atoi(values[i].c_str()); \
DEST[i] = atoi(values[i].c_str()); \
} \
} \
}
#define LOAD_ARRAY(ARRAY_NAME) LOAD_ARRAY_RENAME(ARRAY_NAME, ARRAY_NAME)
void Game::loadstats()
{
tinyxml2::XMLDocument doc;
@ -5377,19 +5379,7 @@ void Game::loadquick()
}
}
if (pKey == "crewstats")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
crewstats.push_back(atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY(crewstats)
if (pKey == "collect")
{
@ -5604,32 +5594,9 @@ void Game::customloadquick(std::string savfile)
}
}
if (pKey == "moods")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
for(size_t i = 0; i < 6; i++)
{
obj.customcrewmoods[i]=atoi(values[i].c_str());
}
}
}
LOAD_ARRAY_RENAME(moods, obj.customcrewmoods)
if (pKey == "crewstats")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
crewstats.push_back(atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY(crewstats)
if (pKey == "collect")
{
@ -5864,19 +5831,7 @@ void Game::loadsummary()
map.finalstretch = atoi(pText);
}
if (pKey == "crewstats")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
tele_crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
tele_crewstats.push_back(atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY_RENAME(crewstats, tele_crewstats)
}
tele_gametime = giventimestring(l_hours,l_minute, l_second);
@ -5953,19 +5908,7 @@ void Game::loadsummary()
map.finalstretch = atoi(pText);
}
if (pKey == "crewstats")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
quick_crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
quick_crewstats.push_back(atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY_RENAME(crewstats, quick_crewstats)
}
@ -6037,7 +5980,7 @@ void Game::savetele()
msgs->LinkEndChild( msg );
std::string crewstatsString;
for(size_t i = 0; i < crewstats.size(); i++ )
for(size_t i = 0; i < SDL_arraysize(crewstats); i++ )
{
crewstatsString += help.String(crewstats[i]) + ",";
}
@ -6233,7 +6176,7 @@ void Game::savequick()
msgs->LinkEndChild( msg );
std::string crewstatsString;
for(size_t i = 0; i < crewstats.size(); i++ )
for(size_t i = 0; i < SDL_arraysize(crewstats); i++ )
{
crewstatsString += help.String(crewstats[i]) + ",";
}
@ -6422,7 +6365,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg );
std::string moods;
for(int i = 0; i < 6; i++ )
for(size_t i = 0; i < SDL_arraysize(obj.customcrewmoods); i++ )
{
moods += help.String(obj.customcrewmoods[i]) + ",";
}
@ -6431,7 +6374,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg );
std::string crewstatsString;
for(size_t i = 0; i < crewstats.size(); i++ )
for(size_t i = 0; i < SDL_arraysize(crewstats); i++ )
{
crewstatsString += help.String(crewstats[i]) + ",";
}
@ -6653,19 +6596,7 @@ void Game::loadtele()
}
}
if (pKey == "crewstats")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
crewstats.push_back(atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY(crewstats)
if (pKey == "collect")
{
@ -7646,7 +7577,7 @@ void Game::swnpenalty()
int Game::crewrescued()
{
int temp = 0;
for (size_t i = 0; i < crewstats.size(); i++)
for (size_t i = 0; i < SDL_arraysize(crewstats); i++)
{
if (crewstats[i])
{

View File

@ -196,7 +196,6 @@ public:
//Menu interaction stuff
bool mapheld;
int menupage;
//public var crewstats:Array = new Array();
int lastsaved;
int deathcounts;
@ -278,15 +277,16 @@ public:
bool inintermission;
std::vector<bool> crewstats;
static const int numcrew = 6;
bool crewstats[numcrew];
bool alarmon;
int alarmdelay;
bool blackout;
std::vector<bool> tele_crewstats;
bool tele_crewstats[numcrew];
std::vector<bool> quick_crewstats;
bool quick_crewstats[numcrew];
static const int numunlock = 25;
bool unlock[numunlock];

View File

@ -1366,8 +1366,8 @@ void scriptclass::run()
}
else if (words[0] == "ifcrewlost")
{
int crewmate = ss_toi(words[1]);
if (crewmate >= 0 && crewmate < (int) game.crewstats.size() && game.crewstats[crewmate]==false)
size_t crewmate = ss_toi(words[1]);
if (crewmate < SDL_arraysize(game.crewstats) && game.crewstats[crewmate]==false)
{
load(words[2]);
position--;
@ -3570,7 +3570,7 @@ void scriptclass::hardreset()
game.nodeathmode = false;
game.nocutscenes = false;
for (i = 0; i < 6; i++)
for (i = 0; i < (int) SDL_arraysize(game.crewstats); i++)
{
game.crewstats[i] = false;
}
@ -3704,8 +3704,8 @@ void scriptclass::hardreset()
obj.flags.clear();
obj.flags.resize(100);
for (i = 0; i < 6; i++){
obj.customcrewmoods[i]=1;
for (i = 0; i < (int) SDL_arraysize(obj.customcrewmoods); i++){
obj.customcrewmoods[i]=true;
}
obj.collect.clear();