1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Don't use separate variable for number of collected trinkets

game.trinkets is supposed to be correlated with obj.collect, however why
not just count obj.collect directly?

This turns game.trinkets into a function, game.trinkets(), which will
directly count the number of collected trinkets and return it. This will
fix a few corner cases where the number of trinkets can desync with the
actual collection statuses of trinkets.

In order to keep save compatibility with previous versions of VVVVVV,
the game will still write the <trinkets> variable. However, it will not
read the <trinkets> variable from a save file.
This commit is contained in:
Misa 2020-04-06 23:46:27 -07:00 committed by Ethan Lee
parent 94b2ebd55c
commit 9510c3c871
6 changed files with 43 additions and 58 deletions

View file

@ -2509,7 +2509,6 @@ void entityclass::updateentities( int i )
//wait for collision
if (entities[i].state == 1)
{
game.trinkets++;
if (game.intimetrial)
{
collect[entities[i].para] = 1;
@ -2521,9 +2520,9 @@ void entityclass::updateentities( int i )
if(music.currentsong!=-1) music.silencedasmusik();
music.playef(3);
collect[entities[i].para] = 1;
if (game.trinkets > game.stat_trinkets && !map.custommode)
if (game.trinkets() > game.stat_trinkets && !map.custommode)
{
game.stat_trinkets = game.trinkets;
game.stat_trinkets = game.trinkets();
}
}

View file

@ -1357,16 +1357,16 @@ void Game::updatestate()
timetrialresulttime = seconds + (minutes * 60);
timetrialrank = 0;
if (timetrialresulttime <= timetrialpar) timetrialrank++;
if (trinkets >= timetrialshinytarget) timetrialrank++;
if (trinkets() >= timetrialshinytarget) timetrialrank++;
if (deathcounts == 0) timetrialrank++;
if (timetrialresulttime < besttimes[timetriallevel] || besttimes[timetriallevel]==-1)
{
besttimes[timetriallevel] = timetrialresulttime;
}
if (trinkets > besttrinkets[timetriallevel] || besttrinkets[timetriallevel]==-1)
if (trinkets() > besttrinkets[timetriallevel] || besttrinkets[timetriallevel]==-1)
{
besttrinkets[timetriallevel] = trinkets;
besttrinkets[timetriallevel] = trinkets();
}
if (deathcounts < bestlives[timetriallevel] || bestlives[timetriallevel]==-1)
{
@ -1949,12 +1949,12 @@ void Game::updatestate()
if(map.custommode)
{
graphics.createtextbox(" " + help.number(trinkets) + " out of " + help.number(map.customtrinkets)+ " ", 50, 65, 174, 174, 174);
graphics.createtextbox(" " + help.number(trinkets()) + " out of " + help.number(map.customtrinkets)+ " ", 50, 65, 174, 174, 174);
graphics.textboxcenterx();
}
else
{
graphics.createtextbox(" " + help.number(trinkets) + " out of Twenty ", 50, 65, 174, 174, 174);
graphics.createtextbox(" " + help.number(trinkets()) + " out of Twenty ", 50, 65, 174, 174, 174);
graphics.textboxcenterx();
}
}
@ -1967,12 +1967,12 @@ void Game::updatestate()
if(map.custommode)
{
graphics.createtextbox(" " + help.number(trinkets) + " out of " + help.number(map.customtrinkets)+ " ", 50, 135, 174, 174, 174);
graphics.createtextbox(" " + help.number(trinkets()) + " out of " + help.number(map.customtrinkets)+ " ", 50, 135, 174, 174, 174);
graphics.textboxcenterx();
}
else
{
graphics.createtextbox(" " + help.number(trinkets) + " out of Twenty ", 50, 135, 174, 174, 174);
graphics.createtextbox(" " + help.number(trinkets()) + " out of Twenty ", 50, 135, 174, 174, 174);
graphics.textboxcenterx();
}
}
@ -2090,7 +2090,7 @@ void Game::updatestate()
if(map.customcrewmates-crewmates==0)
{
//Finished level
if(map.customtrinkets-trinkets==0)
if(map.customtrinkets-trinkets()==0)
{
//and got all the trinkets!
updatecustomlevelstats(customlevelfilename, 3);
@ -3121,7 +3121,7 @@ void Game::updatestate()
state++;
statedelay = 45;
std::string tempstring = help.number(trinkets);
std::string tempstring = help.number(trinkets());
if (graphics.flipmode)
{
graphics.createtextbox("Trinkets Found:", 48, 155-24, 0,0,0);
@ -4731,7 +4731,6 @@ void Game::customstart()
gravitycontrol = savegc;
coins = 0;
trinkets = 0;
//state = 2; deathseq = -1; lifeseq = 10; //Not dead, in game initilisation state
state = 0;
@ -4758,7 +4757,6 @@ void Game::start()
gravitycontrol = savegc;
coins = 0;
trinkets = 0;
//state = 2; deathseq = -1; lifeseq = 10; //Not dead, in game initilisation state
state = 0;
@ -4856,7 +4854,6 @@ void Game::startspecial( int t )
savepoint = 0;
gravitycontrol = savegc;
coins = 0;
trinkets = 0;
state = 0;
deathseq = -1;
lifeseq = 0;
@ -4929,7 +4926,6 @@ void Game::starttrial( int t )
gravitycontrol = savegc;
coins = 0;
trinkets = 0;
crewmates = 0;
//state = 2; deathseq = -1; lifeseq = 10; //Not dead, in game initilisation state
@ -5070,10 +5066,6 @@ void Game::loadquick()
{
savepoint = atoi(pText);
}
else if (pKey == "trinkets")
{
trinkets = atoi(pText);
}
else if (pKey == "companion")
{
companion = atoi(pText);
@ -5343,10 +5335,6 @@ void Game::customloadquick(std::string savfile)
{
savepoint = atoi(pText);
}
else if (pKey == "trinkets")
{
trinkets = atoi(pText);
}
else if (pKey == "crewmates")
{
crewmates = atoi(pText);
@ -5727,7 +5715,7 @@ void Game::savetele()
msgs->LinkEndChild( msg );
msg = new TiXmlElement( "trinkets" );
msg->LinkEndChild( new TiXmlText( help.String(trinkets).c_str() ));
msg->LinkEndChild( new TiXmlText( help.String(trinkets()).c_str() ));
msgs->LinkEndChild( msg );
@ -5924,7 +5912,7 @@ void Game::savequick()
msgs->LinkEndChild( msg );
msg = new TiXmlElement( "trinkets" );
msg->LinkEndChild( new TiXmlText( help.String(trinkets).c_str() ));
msg->LinkEndChild( new TiXmlText( help.String(trinkets()).c_str() ));
msgs->LinkEndChild( msg );
@ -6132,7 +6120,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg );
msg = new TiXmlElement( "trinkets" );
msg->LinkEndChild( new TiXmlText( help.String(trinkets).c_str() ));
msg->LinkEndChild( new TiXmlText( help.String(trinkets()).c_str() ));
msgs->LinkEndChild( msg );
msg = new TiXmlElement( "crewmates" );
@ -6377,10 +6365,6 @@ void Game::loadtele()
{
savepoint = atoi(pText);
}
else if (pKey == "trinkets")
{
trinkets = atoi(pText);
}
else if (pKey == "companion")
{
companion = atoi(pText);
@ -7670,3 +7654,8 @@ void Game::resetgameclock()
hours = 0;
timerStartTime = SDL_GetTicks();
}
int Game::trinkets()
{
return std::count(obj.collect.begin(), obj.collect.end(), 1);
}

View file

@ -247,7 +247,7 @@ public:
int deathseq, lifeseq;
int coins, trinkets, crewmates, trinkencollect;
int coins, trinkets(), crewmates, trinkencollect;
int savepoint, teleport, teleportxpos;
int edteleportent;
bool completestop;

View file

@ -2117,7 +2117,7 @@ void mapinput()
game.savetime = game.timestring();
game.savearea = map.currentarea(map.area(game.roomx, game.roomy));
game.savetrinkets = game.trinkets;
game.savetrinkets = game.trinkets();
if (game.roomx >= 102 && game.roomx <= 104 && game.roomy >= 110 && game.roomy <= 111) game.savearea = "The Ship";

View file

@ -649,7 +649,7 @@ void titlerender()
tempstring = "You rescued " + help.number(game.crewrescued()) + " crewmates";
graphics.Print(0, 100, tempstring, tr, tg, tb, true);
tempstring = "and found " + help.number(game.trinkets) + " trinkets.";
tempstring = "and found " + help.number(game.trinkets()) + " trinkets.";
graphics.Print(0, 110, tempstring, tr, tg, tb, true);
tempstring = "You managed to reach:";
@ -700,7 +700,7 @@ void titlerender()
std::string tempstring = "You rescued all the crewmates!";
graphics.Print(0, 100, tempstring, tr, tg, tb, true);
tempstring = "And you found " + help.number(game.trinkets) + " trinkets.";
tempstring = "And you found " + help.number(game.trinkets()) + " trinkets.";
graphics.Print(0, 110, tempstring, tr, tg, tb, true);
graphics.Print(0, 160, "A new trophy has been awarded and", tr, tg, tb, true);
@ -731,11 +731,11 @@ void titlerender()
graphics.Print(220, 85+20, "+1 Rank!", 255, 255, 255);
}
tempstring = help.String(game.trinkets) + " of " + help.String(game.timetrialshinytarget);
tempstring = help.String(game.trinkets()) + " of " + help.String(game.timetrialshinytarget);
graphics.drawspritesetcol(30, 80+55, 22, 22);
graphics.Print(65, 80+55, "SHINY TRINKETS:", 255, 255, 255);
graphics.Print(65, 90+55, tempstring, tr, tg, tb);
if (game.trinkets >= game.timetrialshinytarget)
if (game.trinkets() >= game.timetrialshinytarget)
{
graphics.Print(220, 85+55, "+1 Rank!", 255, 255, 255);
}
@ -1675,13 +1675,13 @@ void gamerender()
{
graphics.bprint(56, 30,help.String(game.deathcounts), 196, 196, 196);
}
if(game.trinkets<game.timetrialshinytarget)
if(game.trinkets()<game.timetrialshinytarget)
{
graphics.bprint(56, 42,help.String(game.trinkets) + " of " +help.String(game.timetrialshinytarget), 196, 80, 80);
graphics.bprint(56, 42,help.String(game.trinkets()) + " of " +help.String(game.timetrialshinytarget), 196, 80, 80);
}
else
{
graphics.bprint(56, 42,help.String(game.trinkets) + " of " +help.String(game.timetrialshinytarget), 196, 196, 196);
graphics.bprint(56, 42,help.String(game.trinkets()) + " of " +help.String(game.timetrialshinytarget), 196, 196, 196);
}
if(game.timetrialparlost)
@ -2249,7 +2249,7 @@ void maprender()
if (graphics.flipmode)
{
graphics.Print(0, 164, "[Trinkets found]", 196, 196, 255 - help.glow, true);
graphics.Print(0, 152, help.number(game.trinkets) + " out of " + help.number(map.customtrinkets), 96,96,96, true);
graphics.Print(0, 152, help.number(game.trinkets()) + " out of " + help.number(map.customtrinkets), 96,96,96, true);
graphics.Print(0, 114, "[Number of Deaths]", 196, 196, 255 - help.glow, true);
graphics.Print(0, 102,help.String(game.deathcounts), 96,96,96, true);
@ -2260,7 +2260,7 @@ void maprender()
else
{
graphics.Print(0, 52, "[Trinkets found]", 196, 196, 255 - help.glow, true);
graphics.Print(0, 64, help.number(game.trinkets) + " out of "+help.number(map.customtrinkets), 96,96,96, true);
graphics.Print(0, 64, help.number(game.trinkets()) + " out of "+help.number(map.customtrinkets), 96,96,96, true);
graphics.Print(0, 102, "[Number of Deaths]", 196, 196, 255 - help.glow, true);
graphics.Print(0, 114,help.String(game.deathcounts), 96,96,96, true);
@ -2272,7 +2272,7 @@ void maprender()
if (graphics.flipmode)
{
graphics.Print(0, 164, "[Trinkets found]", 196, 196, 255 - help.glow, true);
graphics.Print(0, 152, help.number(game.trinkets) + " out of Twenty", 96,96,96, true);
graphics.Print(0, 152, help.number(game.trinkets()) + " out of Twenty", 96,96,96, true);
graphics.Print(0, 114, "[Number of Deaths]", 196, 196, 255 - help.glow, true);
graphics.Print(0, 102,help.String(game.deathcounts), 96,96,96, true);
@ -2283,7 +2283,7 @@ void maprender()
else
{
graphics.Print(0, 52, "[Trinkets found]", 196, 196, 255 - help.glow, true);
graphics.Print(0, 64, help.number(game.trinkets) + " out of Twenty", 96,96,96, true);
graphics.Print(0, 64, help.number(game.trinkets()) + " out of Twenty", 96,96,96, true);
graphics.Print(0, 102, "[Number of Deaths]", 196, 196, 255 - help.glow, true);
graphics.Print(0, 114,help.String(game.deathcounts), 96,96,96, true);
@ -2708,13 +2708,13 @@ void towerrender()
{
graphics.bprint(56, 30,help.String(game.deathcounts), 196, 196, 196);
}
if(game.trinkets<game.timetrialshinytarget)
if(game.trinkets()<game.timetrialshinytarget)
{
graphics.bprint(56, 42,help.String(game.trinkets) + " of " +help.String(game.timetrialshinytarget), 196, 80, 80);
graphics.bprint(56, 42,help.String(game.trinkets()) + " of " +help.String(game.timetrialshinytarget), 196, 80, 80);
}
else
{
graphics.bprint(56, 42,help.String(game.trinkets) + " of " +help.String(game.timetrialshinytarget), 196, 196, 196);
graphics.bprint(56, 42,help.String(game.trinkets()) + " of " +help.String(game.timetrialshinytarget), 196, 196, 196);
}
if(game.timetrialparlost)

View file

@ -155,7 +155,7 @@ void scriptclass::run()
}
if (words[0] == "customiftrinkets")
{
if (game.trinkets >= ss_toi(words[1]))
if (game.trinkets() >= ss_toi(words[1]))
{
load("custom_"+words[2]);
position--;
@ -163,7 +163,7 @@ void scriptclass::run()
}
if (words[0] == "customiftrinketsless")
{
if (game.trinkets < ss_toi(words[1]))
if (game.trinkets() < ss_toi(words[1]))
{
load("custom_"+words[2]);
position--;
@ -1321,7 +1321,7 @@ void scriptclass::run()
}
else if (words[0] == "iftrinkets")
{
if (game.trinkets >= ss_toi(words[1]))
if (game.trinkets() >= ss_toi(words[1]))
{
load(words[2]);
position--;
@ -1466,7 +1466,6 @@ void scriptclass::run()
i = obj.getplayer();
obj.entities[i].tile = 0;
game.trinkets = 0;
game.crewmates=0;
for (i = 0; i < 100; i++)
{
@ -1879,7 +1878,6 @@ void scriptclass::run()
music.haltdasmusik();
music.playef(3);
game.trinkets++;
obj.collect[ss_toi(words[1])] = 1;
graphics.textboxremovefast();
@ -1898,7 +1896,7 @@ void scriptclass::run()
{
usethisnum = "Twenty";
}
graphics.createtextbox(" " + help.number(game.trinkets) + " out of " + usethisnum + " ", 50, 135, 174, 174, 174);
graphics.createtextbox(" " + help.number(game.trinkets()) + " out of " + usethisnum + " ", 50, 135, 174, 174, 174);
graphics.textboxcenterx();
if (!game.backgroundtext)
@ -2040,12 +2038,12 @@ void scriptclass::run()
}
else if (words[0] == "trinketbluecontrol")
{
if (game.trinkets == 20 && obj.flags[67] == 1)
if (game.trinkets() == 20 && obj.flags[67] == 1)
{
load("talkblue_trinket6");
position--;
}
else if (game.trinkets >= 19 && obj.flags[67] == 0)
else if (game.trinkets() >= 19 && obj.flags[67] == 0)
{
load("talkblue_trinket5");
position--;
@ -2058,7 +2056,7 @@ void scriptclass::run()
}
else if (words[0] == "trinketyellowcontrol")
{
if (game.trinkets >= 19)
if (game.trinkets() >= 19)
{
load("talkyellow_trinket3");
position--;
@ -2257,7 +2255,7 @@ void scriptclass::run()
else
{
//Ok, we've already dealt with the trinket thing; so either you have them all, or you don't. If you do:
if (game.trinkets >= 20)
if (game.trinkets() >= 20)
{
load("startepilogue");
position--;
@ -2862,7 +2860,6 @@ void scriptclass::startgamemode( int t )
map.explored[i + (j * 20)] = 1;
}
}
game.trinkets = 20;
game.insecretlab = true;
map.showteleporters = true;