Add quit block
This commit is contained in:
parent
7f00b5aa5f
commit
2a84afa981
4 changed files with 85 additions and 86 deletions
138
game.h
138
game.h
|
@ -798,6 +798,75 @@ void LCR_gameLoadMainMenuItems(void)
|
|||
LCR_game.menu.itemCount = 4;
|
||||
}
|
||||
|
||||
/**
|
||||
Loads up to LCR_RESOURCE_ITEM_CHUNK items of given type, starting at given
|
||||
index (among items of the same type). This will also load the menu item names.
|
||||
*/
|
||||
void LCR_gameLoadDataFileChunk(unsigned int startIndex, char magicNumber)
|
||||
{
|
||||
char c;
|
||||
unsigned char state = 0;
|
||||
|
||||
LCR_gameEraseMenuItemNames();
|
||||
|
||||
LCR_game.dataFile.firstItemIndex = startIndex;
|
||||
LCR_game.dataFile.itemsTotal = 0;
|
||||
|
||||
LCR_gameRewindDataFile();
|
||||
|
||||
/* 3 iterations: in first we seek to the start index, in second we load the
|
||||
names, in third we just read the rest to get the total count. */
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
if (i == 0 && !startIndex)
|
||||
break;
|
||||
|
||||
c = LCR_gameGetNextDataFileChar();
|
||||
|
||||
if (c == 0)
|
||||
return;
|
||||
|
||||
if (state == 0) // second magic char
|
||||
{
|
||||
state = 255;
|
||||
|
||||
if (c == magicNumber)
|
||||
{
|
||||
LCR_game.dataFile.itemsTotal++;
|
||||
|
||||
if (i == 0)
|
||||
startIndex--;
|
||||
else if (i == 1)
|
||||
state = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else if (i == 1 && state != 255)
|
||||
{
|
||||
if (c == LCR_RESOURCE_FILE_SEPARATOR ||
|
||||
c == LCR_RESOURCE_FILE_SEPARATOR2 ||
|
||||
state >= 1 + LCR_MENU_STRING_SIZE - 1)
|
||||
{
|
||||
state = 255;
|
||||
LCR_game.menu.itemCount++;
|
||||
|
||||
if (LCR_game.menu.itemCount >= LCR_RESOURCE_ITEM_CHUNK)
|
||||
break;
|
||||
}
|
||||
else
|
||||
LCR_game.menu.itemNames[LCR_game.menu.itemCount][state - 1] = c;
|
||||
|
||||
state++;
|
||||
}
|
||||
|
||||
if (c == LCR_RESOURCE_FILE_SEPARATOR)
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LCR_gameInit(int argc, const char **argv)
|
||||
{
|
||||
LCR_LOG0("initializing");
|
||||
|
@ -871,75 +940,6 @@ void LCR_gameInit(int argc, const char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Loads up to LCR_RESOURCE_ITEM_CHUNK items of given type, starting at given
|
||||
index (among items of the same type). This will also load the menu item names.
|
||||
*/
|
||||
void LCR_gameLoadDataFileChunk(unsigned int startIndex, char magicNumber)
|
||||
{
|
||||
char c;
|
||||
unsigned char state = 0;
|
||||
|
||||
LCR_gameEraseMenuItemNames();
|
||||
|
||||
LCR_game.dataFile.firstItemIndex = startIndex;
|
||||
LCR_game.dataFile.itemsTotal = 0;
|
||||
|
||||
LCR_gameRewindDataFile();
|
||||
|
||||
/* 3 iterations: in first we seek to the start index, in second we load the
|
||||
names, in third we just read the rest to get the total count. */
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
if (i == 0 && !startIndex)
|
||||
break;
|
||||
|
||||
c = LCR_gameGetNextDataFileChar();
|
||||
|
||||
if (c == 0)
|
||||
return;
|
||||
|
||||
if (state == 0) // second magic char
|
||||
{
|
||||
state = 255;
|
||||
|
||||
if (c == magicNumber)
|
||||
{
|
||||
LCR_game.dataFile.itemsTotal++;
|
||||
|
||||
if (i == 0)
|
||||
startIndex--;
|
||||
else if (i == 1)
|
||||
state = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else if (i == 1 && state != 255)
|
||||
{
|
||||
if (c == LCR_RESOURCE_FILE_SEPARATOR ||
|
||||
c == LCR_RESOURCE_FILE_SEPARATOR2 ||
|
||||
state >= 1 + LCR_MENU_STRING_SIZE - 1)
|
||||
{
|
||||
state = 255;
|
||||
LCR_game.menu.itemCount++;
|
||||
|
||||
if (LCR_game.menu.itemCount >= LCR_RESOURCE_ITEM_CHUNK)
|
||||
break;
|
||||
}
|
||||
else
|
||||
LCR_game.menu.itemNames[LCR_game.menu.itemCount][state - 1] = c;
|
||||
|
||||
state++;
|
||||
}
|
||||
|
||||
if (c == LCR_RESOURCE_FILE_SEPARATOR)
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue