From 8e3ec9aeef96bdbc8b03b51732f31209816a4aec Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 5 Jun 2023 17:50:19 -0700 Subject: [PATCH] Use enums for time trial indexes This adds an anonymous enum for time trial indexes (e.g. the bestrank, bestlives, etc. arrays and timetriallevel), and replaces all integer literals with them. Just like the unlock arrays, these are indexes to an array in XML save files, so the numbers matter, and therefore should not use strict typechecking. --- desktop_version/src/Entity.cpp | 12 ++++---- desktop_version/src/Game.cpp | 41 ++++++++++++++++++--------- desktop_version/src/Game.h | 12 ++++++++ desktop_version/src/Logic.cpp | 12 ++++---- desktop_version/src/Spacestation2.cpp | 2 +- desktop_version/src/main.cpp | 30 ++++++++++++++++---- 6 files changed, 77 insertions(+), 32 deletions(-) diff --git a/desktop_version/src/Entity.cpp b/desktop_version/src/Entity.cpp index 5233c769..1cf4f0bd 100644 --- a/desktop_version/src/Entity.cpp +++ b/desktop_version/src/Entity.cpp @@ -1828,42 +1828,42 @@ void entityclass::createentity(int xp, int yp, int t, int meta1, int meta2, int switch (meta2) { case 1: - if(game.bestrank[0]>=3) + if (game.bestrank[TimeTrial_SPACESTATION1] >= 3) { entity.tile = 184 + meta1; entity.colour = 31; } break; case 2: - if(game.bestrank[1]>=3) + if (game.bestrank[TimeTrial_LABORATORY] >= 3) { entity.tile = 186 + meta1; entity.colour = 35; } break; case 3: - if(game.bestrank[2]>=3) + if (game.bestrank[TimeTrial_TOWER] >= 3) { entity.tile = 184 + meta1; entity.colour = 33; } break; case 4: - if(game.bestrank[3]>=3) + if (game.bestrank[TimeTrial_SPACESTATION2] >= 3) { entity.tile = 184 + meta1; entity.colour = 32; } break; case 5: - if(game.bestrank[4]>=3) + if (game.bestrank[TimeTrial_WARPZONE] >= 3) { entity.tile = 184 + meta1; entity.colour = 34; } break; case 6: - if(game.bestrank[5]>=3) + if (game.bestrank[TimeTrial_FINALLEVEL] >= 3) { entity.tile = 184 + meta1; entity.colour = 30; diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 50105785..6646cc45 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -1633,13 +1633,28 @@ void Game::updatestate(void) if (timetrialrank > bestrank[timetriallevel] || bestrank[timetriallevel]==-1) { bestrank[timetriallevel] = timetrialrank; - if(timetrialrank>=3){ - if(timetriallevel==0) unlockAchievement("vvvvvvtimetrial_station1_fixed"); - if(timetriallevel==1) unlockAchievement("vvvvvvtimetrial_lab_fixed"); - if(timetriallevel==2) unlockAchievement("vvvvvvtimetrial_tower_fixed"); - if(timetriallevel==3) unlockAchievement("vvvvvvtimetrial_station2_fixed"); - if(timetriallevel==4) unlockAchievement("vvvvvvtimetrial_warp_fixed"); - if(timetriallevel==5) unlockAchievement("vvvvvvtimetrial_final_fixed"); + if (timetrialrank >= 3) + { + switch (timetriallevel) + { + case TimeTrial_SPACESTATION1: + unlockAchievement("vvvvvvtimetrial_station1_fixed"); + break; + case TimeTrial_LABORATORY: + unlockAchievement("vvvvvvtimetrial_lab_fixed"); + break; + case TimeTrial_TOWER: + unlockAchievement("vvvvvvtimetrial_tower_fixed"); + break; + case TimeTrial_SPACESTATION2: + unlockAchievement("vvvvvvtimetrial_station2_fixed"); + break; + case TimeTrial_WARPZONE: + unlockAchievement("vvvvvvtimetrial_warp_fixed"); + break; + case TimeTrial_FINALLEVEL: + unlockAchievement("vvvvvvtimetrial_final_fixed"); + } } } @@ -6814,12 +6829,12 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) { //Alright, we haven't unlocked any time trials. How about no death mode? temp = 0; - if (bestrank[0] >= 2) temp++; - if (bestrank[1] >= 2) temp++; - if (bestrank[2] >= 2) temp++; - if (bestrank[3] >= 2) temp++; - if (bestrank[4] >= 2) temp++; - if (bestrank[5] >= 2) temp++; + if (bestrank[TimeTrial_SPACESTATION1] >= 2) temp++; + if (bestrank[TimeTrial_LABORATORY] >= 2) temp++; + if (bestrank[TimeTrial_TOWER] >= 2) temp++; + if (bestrank[TimeTrial_SPACESTATION2] >= 2) temp++; + if (bestrank[TimeTrial_WARPZONE] >= 2) temp++; + if (bestrank[TimeTrial_FINALLEVEL] >= 2) temp++; if (temp >= 4 && !unlocknotify[Unlock_NODEATHMODE]) { //Unlock No Death Mode diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index ca3a115a..e2d2d714 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -158,6 +158,18 @@ enum UnlockTrophy_NODEATHMODE_COMPLETE = 20 }; +/* enums for bestrank, bestlives, besttrinkets, besttimes, bestframes arrays + * and timetriallevel */ +enum +{ + TimeTrial_SPACESTATION1 = 0, + TimeTrial_LABORATORY = 1, + TimeTrial_TOWER = 2, + TimeTrial_SPACESTATION2 = 3, + TimeTrial_WARPZONE = 4, + TimeTrial_FINALLEVEL = 5 +}; + struct MenuStackFrame { int option; diff --git a/desktop_version/src/Logic.cpp b/desktop_version/src/Logic.cpp index 5fa3609e..a81fd4be 100644 --- a/desktop_version/src/Logic.cpp +++ b/desktop_version/src/Logic.cpp @@ -761,22 +761,22 @@ void gamelogic(void) { switch(game.timetriallevel) { - case 0: + case TimeTrial_SPACESTATION1: music.play(Music_PUSHINGONWARDS); break; - case 1: + case TimeTrial_LABORATORY: music.play(Music_POTENTIALFORANYTHING); break; - case 2: + case TimeTrial_TOWER: music.play(Music_POSITIVEFORCE); break; - case 3: + case TimeTrial_SPACESTATION2: music.play(Music_PUSHINGONWARDS); break; - case 4: + case TimeTrial_WARPZONE: music.play(Music_PRESSURECOOKER); break; - case 5: + case TimeTrial_FINALLEVEL: music.play(Music_PREDESTINEDFATEREMIX); break; } diff --git a/desktop_version/src/Spacestation2.cpp b/desktop_version/src/Spacestation2.cpp index f69a34f1..1da7cbc6 100644 --- a/desktop_version/src/Spacestation2.cpp +++ b/desktop_version/src/Spacestation2.cpp @@ -2191,7 +2191,7 @@ const short* spacestation2class::loadlevel(int rx, int ry) obj.createentity(272, 40, 2, 14, 2); // Platform obj.createentity(240, 40, 3, 707); //Disappearing Platform - if(game.intimetrial && game.timetriallevel > 0) + if (game.intimetrial && game.timetriallevel > TimeTrial_SPACESTATION1) { obj.fatal_top(); } diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 392cc2a9..8a416845 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -729,12 +729,30 @@ int main(int argc, char *argv[]) } } - if(game.bestrank[0]>=3) game.unlockAchievement("vvvvvvtimetrial_station1_fixed"); - if(game.bestrank[1]>=3) game.unlockAchievement("vvvvvvtimetrial_lab_fixed"); - if(game.bestrank[2]>=3) game.unlockAchievement("vvvvvvtimetrial_tower_fixed"); - if(game.bestrank[3]>=3) game.unlockAchievement("vvvvvvtimetrial_station2_fixed"); - if(game.bestrank[4]>=3) game.unlockAchievement("vvvvvvtimetrial_warp_fixed"); - if(game.bestrank[5]>=3) game.unlockAchievement("vvvvvvtimetrial_final_fixed"); + if (game.bestrank[TimeTrial_SPACESTATION1] >= 3) + { + game.unlockAchievement("vvvvvvtimetrial_station1_fixed"); + } + if (game.bestrank[TimeTrial_LABORATORY] >= 3) + { + game.unlockAchievement("vvvvvvtimetrial_lab_fixed"); + } + if (game.bestrank[TimeTrial_TOWER] >= 3) + { + game.unlockAchievement("vvvvvvtimetrial_tower_fixed"); + } + if (game.bestrank[TimeTrial_SPACESTATION2] >= 3) + { + game.unlockAchievement("vvvvvvtimetrial_station2_fixed"); + } + if (game.bestrank[TimeTrial_WARPZONE] >= 3) + { + game.unlockAchievement("vvvvvvtimetrial_warp_fixed"); + } + if (game.bestrank[TimeTrial_FINALLEVEL] >= 3) + { + game.unlockAchievement("vvvvvvtimetrial_final_fixed"); + } obj.init();