Add map beating

This commit is contained in:
Miloslav Ciz 2025-01-27 23:46:44 +01:00
parent 2172fcedd1
commit ea105ba3f3
6 changed files with 119 additions and 18 deletions

67
game.h
View file

@ -838,13 +838,71 @@ void LCR_gameLoadDataFileChunk(unsigned int startIndex, char magicNumber)
}
}
/**
Assumes maps are loaded in menu items, checks (in the resource file) which
ones have been marked as beaten and marks corresponding menu items as such.
*/
void LCR_checkBeatenMaps(void)
{
LCR_LOG2("checking beaten maps");
char name[LCR_MAP_NAME_MAX_LEN + 1];
LCR_gameRewindDataFile();
while (1)
{
char c = LCR_gameGetNextDataFileChar();
if (c == 'B')
{
uint8_t i = 0;
while (i < LCR_MAP_NAME_MAX_LEN + 1)
{
c = LCR_gameGetNextDataFileChar();
if (c < ' ' || c == LCR_RESOURCE_FILE_SEPARATOR ||
c == LCR_RESOURCE_FILE_SEPARATOR2)
break;
name[i] = c;
i++;
}
name[i] = 0;
for (uint8_t j = 0; j < LCR_game.menu.itemCount; ++j)
if (_LCR_strCmp(name,LCR_game.menu.itemNamePtrs[j]))
{
for (uint8_t k = 0; k < LCR_MENU_STRING_SIZE; ++k)
if (LCR_game.menu.itemNames[j][k] == 0)
{
LCR_game.menu.itemNames[j]
[k - (k == LCR_MENU_STRING_SIZE - 1)] = '#';
LCR_game.menu.itemNames[j]
[k + (k != LCR_MENU_STRING_SIZE - 1)] = 0;
break;
}
}
}
else
while (c != 0 && c != LCR_RESOURCE_FILE_SEPARATOR)
c = LCR_gameGetNextDataFileChar();
if (c == 0)
break;
}
}
void LCR_gameEnd(void)
{
LCR_LOG0("ending");
}
void LCR_gameTimeToStr(uint32_t timeMS, char *str)
{
str[9] = 0;
@ -1168,10 +1226,15 @@ void LCR_gameHandleInput(void)
if (tabSwitchedTo == 0)
LCR_gameLoadMainMenuItems();
else if (tabSwitchedTo > 0 || scrolled != 0)
{
LCR_gameLoadDataFileChunk(
(tabSwitchedTo > 0) ? 0 : (LCR_game.dataFile.firstItemIndex +
scrolled * LCR_RESOURCE_ITEM_CHUNK),
LCR_game.menu.selectedTab == 1 ? 'M' : 'R');
if (LCR_game.menu.selectedTab == 1)
LCR_checkBeatenMaps();
}
}
uint8_t LCR_gameStep(uint32_t time)