summaryrefslogtreecommitdiff
path: root/src/levelinfo.cpp
blob: 59bca374a47e6e29281e56ffa20164b9c782615e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "levelinfo.h"

dDvdLoader_c s_levelInfoLoader;
bool s_levelInfoLoaded = false;

dLevelInfo_c dLevelInfo_c::s_info;

bool LoadLevelInfo() {
	if (s_levelInfoLoaded)
		return true;

	void *data = s_levelInfoLoader.load("/NewerRes/LevelInfo.bin");
	if (data) {
		dLevelInfo_c::s_info.load(data);
		s_levelInfoLoaded = true;
		return true;
	}

	return false;
}


void dLevelInfo_c::load(void *buffer) {
	data = (header_s*)buffer;

	// decode all the level names
	for (int sect = 0; sect < sectionCount(); sect++) {
		// parse this section
		section_s *thisSect = getSectionByIndex(sect);

		for (int lev = 0; lev < thisSect->levelCount; lev++) {
			entry_s *level = &thisSect->levels[lev];

			if (level->levelSlot < 42)
				SetSomeConditionShit(level->worldSlot, level->levelSlot, level->flags);
		}
	}
}

dLevelInfo_c::entry_s *dLevelInfo_c::searchBySlot(int world, int level) {
	for (int i = 0; i < sectionCount(); i++) {
		section_s *sect = getSectionByIndex(i);

		for (int j = 0; j < sect->levelCount; j++) {
			entry_s *entry = &sect->levels[j];
			if (entry->worldSlot == world && entry->levelSlot == level)
				return entry;
		}
	}

	return 0;
}

dLevelInfo_c::entry_s *dLevelInfo_c::searchByDisplayNum(int world, int level) {
	for (int i = 0; i < sectionCount(); i++) {
		section_s *sect = getSectionByIndex(i);

		for (int j = 0; j < sect->levelCount; j++) {
			entry_s *entry = &sect->levels[j];
			if (entry->displayWorld == world && entry->displayLevel == level)
				return entry;
		}
	}

	return 0;
}


void UpdateFSStars() {
	dLevelInfo_c *li = &dLevelInfo_c::s_info;
	SaveBlock *save = GetSaveFile()->GetBlock(-1);

	bool coinsNormal = true, exitsNormal = true;
	bool coinsW9 = true, exitsW9 = true;

	for (int i = 0; i < li->sectionCount(); i++) {
		dLevelInfo_c::section_s *sect = li->getSectionByIndex(i);

		for (int j = 0; j < sect->levelCount; j++) {
			dLevelInfo_c::entry_s *entry = &sect->levels[j];

			// Levels only
			if (!(entry->flags & 2))
				continue;

			u32 conds = save->GetLevelCondition(entry->worldSlot, entry->levelSlot);

			if (entry->displayWorld == 9) {
				if ((conds & COND_COIN_ALL) != COND_COIN_ALL)
					coinsW9 = false;
				if (entry->flags & 0x10)
					if (!(conds & COND_NORMAL))
						exitsW9 = false;
				if (entry->flags & 0x20)
					if (!(conds & COND_SECRET))
						exitsW9 = false;
			} else {
				if ((conds & COND_COIN_ALL) != COND_COIN_ALL)
					coinsNormal = false;
				if (entry->flags & 0x10)
					if (!(conds & COND_NORMAL))
						exitsNormal = false;
				if (entry->flags & 0x20)
					if (!(conds & COND_SECRET))
						exitsNormal = false;
			}
		}
	}

	bool beatGame = (save->GetLevelCondition(7, 23) & COND_NORMAL) != 0;

//	save->bitfield &= ~0x3E;
	save->bitfield &= ~0x3C;
	save->bitfield |=
//		(beatGame ? 2 : 0) |
		(exitsNormal ? 4 : 0) |
		(coinsNormal ? 8 : 0) |
		(exitsW9 ? 0x10 : 0) |
		(coinsW9 ? 0x20 : 0);

	OSReport("FS Stars updated: Status: Game beaten: %d, Normal exits: %d, Normal coins: %d, W9 exits: %d, W9 coins: %d\n", beatGame, exitsNormal, coinsNormal, exitsW9, coinsW9);
}