Skip to content

Commit 7fcc6ef

Browse files
committed
Adding level by level in a more principled way
1 parent ae25f1c commit 7fcc6ef

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

src/brogue/Architect.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ boolean buildAMachine(enum machineTypes bp,
10271027
machineInfo *tempMachineInfo = createMachineInfo(0, 0, 0);
10281028
if (buildAMachineOrChildMachine(bp, originX, originY, requiredMachineFlags, NULL, NULL, NULL, tempMachineInfo)) {
10291029
// Transfer the valid machineInfo into the main chain and delete the head node
1030-
addMachineInfoToChain(tempMachineInfo->nextMachineInfo, allMachineInfo);
1030+
addMachineInfoToChain(tempMachineInfo->nextMachineInfo, levelMachineInfo);
10311031
tempMachineInfo->nextMachineInfo = NULL;
10321032
deleteMachineInfo(tempMachineInfo);
10331033
return true;

src/brogue/GlobalsBase.c

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ item *floorItems;
5050
item *packItems;
5151
item *monsterItemsHopper;
5252
machineInfo *allMachineInfo;
53+
machineInfo *levelMachineInfo;
5354

5455
char displayedMessage[MESSAGE_LINES][COLS*2];
5556
short messagesUnconfirmed;

src/brogue/GlobalsBase.h

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern item *floorItems;
6666
extern item *packItems;
6767
extern item *monsterItemsHopper;
6868
extern machineInfo *allMachineInfo;
69+
extern machineInfo *levelMachineInfo;
6970
extern short numberOfWaypoints;
7071

7172
extern char displayedMessage[MESSAGE_LINES][COLS*2];

src/brogue/RogueMain.c

+55
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,51 @@ static void updateColors() {
539539
}
540540
}
541541

542+
static machineInfo *reverseAllMachineInfo2() {
543+
machineInfo *prev = NULL;
544+
machineInfo *current = allMachineInfo;
545+
machineInfo *next = NULL;
546+
547+
while (current != NULL) {
548+
next = current->nextMachineInfo;
549+
current->nextMachineInfo = prev;
550+
prev = current;
551+
current = next;
552+
}
553+
return prev;
554+
}
555+
556+
static void deleteMachineInfo2(machineInfo *machineInfo) {
557+
free(machineInfo);
558+
}
559+
560+
static void deleteAllMachineInfo2(machineInfo *theChain) {
561+
machineInfo *thisMachineInfo, *thisMachineInfo2;
562+
for (thisMachineInfo = theChain; thisMachineInfo != NULL; thisMachineInfo = thisMachineInfo2) {
563+
thisMachineInfo2 = thisMachineInfo->nextMachineInfo;
564+
deleteAllMachineInfo2(thisMachineInfo->childMachineInfo);
565+
deleteMachineInfo2(thisMachineInfo);
566+
}
567+
}
568+
569+
static void addMachineInfoToChain2(machineInfo *theInfo, machineInfo *theChain) {
570+
theInfo->nextMachineInfo = theChain->nextMachineInfo;
571+
theChain->nextMachineInfo = theInfo;
572+
}
573+
574+
static void addMachineInfoAndChainToChain(machineInfo *theInfo, machineInfo *theChain) {
575+
//find last machineInfo nextMachineInfo from theInfo
576+
577+
machineInfo *lastMachineInfo = theInfo;
578+
while (lastMachineInfo->nextMachineInfo != NULL) {
579+
lastMachineInfo = lastMachineInfo->nextMachineInfo;
580+
}
581+
582+
lastMachineInfo->nextMachineInfo = theChain->nextMachineInfo;
583+
theChain->nextMachineInfo = theInfo;
584+
}
585+
586+
542587
void startLevel(short oldLevelNumber, short stairDirection) {
543588
uint64_t oldSeed;
544589
item *theItem;
@@ -686,6 +731,9 @@ void startLevel(short oldLevelNumber, short stairDirection) {
686731

687732
levels[rogue.depthLevel-1].items = NULL;
688733

734+
// Initialize a chain for the level only
735+
levelMachineInfo = createMachineInfo(0, 0, 0);
736+
689737
pos upStairLocation;
690738
int failsafe;
691739
for (failsafe = 50; failsafe; failsafe--) {
@@ -729,6 +777,13 @@ void startLevel(short oldLevelNumber, short stairDirection) {
729777
}
730778
}
731779

780+
machineInfo *firstRealNode = levelMachineInfo->nextMachineInfo;
781+
levelMachineInfo->nextMachineInfo = NULL;
782+
deleteAllMachineInfo2(levelMachineInfo);
783+
784+
//machineInfo *reversed = reverseAllMachineInfo2(firstRealNode);
785+
addMachineInfoAndChainToChain(firstRealNode, allMachineInfo);
786+
732787
// re-seed the RNG
733788
seedRandomGenerator(oldSeed);
734789

src/brogue/SeedCatalog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ int printSeedCatalog(uint64_t startingSeed, uint64_t numberOfSeedsToScan, unsign
362362
printSeedCatalogMonsterItems(isCsvFormat);
363363
printSeedCatalogMonsters(isCsvFormat, false); // captives and allies only
364364
if (includeVaults) {
365-
reverseAllMachineInfo();
365+
//reverseAllMachineInfo();
366366
printSeedCatalogMachines(isCsvFormat, allMachineInfo, 0);
367367
} else {
368368
printSeedCatalogAltars(isCsvFormat);

0 commit comments

Comments
 (0)