25
25
#include "GlobalsBase.h"
26
26
#include "Globals.h"
27
27
28
+ static boolean buildAMachineOrChildMachine (enum machineTypes bp ,
29
+ short originX , short originY ,
30
+ unsigned long requiredMachineFlags ,
31
+ item * adoptiveItem ,
32
+ item * parentSpawnedItems [50 ],
33
+ creature * parentSpawnedMonsters [50 ],
34
+ machineInfo * thisMachineInfoChain );
35
+
28
36
short topBlobMinX , topBlobMinY , blobWidth , blobHeight ;
29
37
30
38
boolean cellHasTerrainFlag (pos loc , unsigned long flagMask ) {
@@ -979,14 +987,84 @@ typedef struct machineData {
979
987
short sCols [DCOLS ];
980
988
} machineData ;
981
989
990
+ machineInfo * createMachineInfo (int level , int id , int type ) {
991
+ machineInfo * theInfo = (machineInfo * ) malloc (sizeof (machineInfo ));
992
+ memset (theInfo , '\0' , sizeof (machineInfo ));
993
+
994
+ machineInfo * theChildInfo = (machineInfo * ) malloc (sizeof (machineInfo ));
995
+ memset (theChildInfo , '\0' , sizeof (machineInfo ));
996
+
997
+ theInfo -> level = level ;
998
+ theInfo -> type = type ;
999
+ theInfo -> id = id ;
1000
+ theInfo -> childMachineInfo = theChildInfo ;
1001
+ theInfo -> nextMachineInfo = NULL ;
1002
+
1003
+ return theInfo ;
1004
+ }
1005
+
1006
+ void deleteAllMachineInfo (machineInfo * theChain ) {
1007
+ machineInfo * thisMachineInfo , * thisMachineInfo2 ;
1008
+ for (thisMachineInfo = theChain ; thisMachineInfo != NULL ; thisMachineInfo = thisMachineInfo2 ) {
1009
+ thisMachineInfo2 = thisMachineInfo -> nextMachineInfo ;
1010
+ deleteAllMachineInfo (thisMachineInfo -> childMachineInfo );
1011
+ free (thisMachineInfo );
1012
+ }
1013
+ }
1014
+
1015
+ machineInfo * reverseAllMachineInfo (machineInfo * reverseList ) {
1016
+ machineInfo * prev = NULL ;
1017
+ machineInfo * current = reverseList ;
1018
+ machineInfo * next = NULL ;
1019
+
1020
+ while (current != NULL ) {
1021
+ next = current -> nextMachineInfo ;
1022
+ current -> nextMachineInfo = prev ;
1023
+ prev = current ;
1024
+ current = next ;
1025
+ }
1026
+ return prev ;
1027
+ }
1028
+
1029
+ void addMachineInfoAndChainToChain (machineInfo * theInfo , machineInfo * theChain ) {
1030
+ machineInfo * lastMachineInfo = theInfo ;
1031
+ while (lastMachineInfo -> nextMachineInfo != NULL ) {
1032
+ lastMachineInfo = lastMachineInfo -> nextMachineInfo ;
1033
+ }
1034
+
1035
+ lastMachineInfo -> nextMachineInfo = theChain -> nextMachineInfo ;
1036
+ theChain -> nextMachineInfo = theInfo ;
1037
+ }
1038
+
1039
+ void addMachineInfoToChain (machineInfo * theInfo , machineInfo * theChain ) {
1040
+ theInfo -> nextMachineInfo = theChain -> nextMachineInfo ;
1041
+ theChain -> nextMachineInfo = theInfo ;
1042
+ }
1043
+
1044
+ boolean buildAMachine (enum machineTypes bp ,
1045
+ short originX , short originY ,
1046
+ unsigned long requiredMachineFlags ) {
1047
+ machineInfo * tempMachineInfo = createMachineInfo (0 , 0 , 0 );
1048
+ if (buildAMachineOrChildMachine (bp , originX , originY , requiredMachineFlags , NULL , NULL , NULL , tempMachineInfo )) {
1049
+ // Transfer the valid machineInfo into the main chain and delete the head node
1050
+ addMachineInfoToChain (tempMachineInfo -> nextMachineInfo , levelMachineInfo );
1051
+ tempMachineInfo -> nextMachineInfo = NULL ;
1052
+ free (tempMachineInfo );
1053
+ return true;
1054
+ }
1055
+ deleteAllMachineInfo (tempMachineInfo );
1056
+ return false;
1057
+ }
1058
+
982
1059
// Returns true if the machine got built; false if it was aborted.
983
1060
// If empty array parentSpawnedItems or parentSpawnedMonsters is given, will pass those back for deletion if necessary.
984
- boolean buildAMachine (enum machineTypes bp ,
1061
+ static boolean buildAMachineOrChildMachine (enum machineTypes bp ,
985
1062
short originX , short originY ,
986
1063
unsigned long requiredMachineFlags ,
987
1064
item * adoptiveItem ,
988
1065
item * parentSpawnedItems [MACHINES_BUFFER_LENGTH ],
989
- creature * parentSpawnedMonsters [MACHINES_BUFFER_LENGTH ]) {
1066
+ creature * parentSpawnedMonsters [MACHINES_BUFFER_LENGTH ],
1067
+ machineInfo * thisMachineInfoChain ) {
990
1068
991
1069
short totalFreq , instance , instanceCount = 0 ,
992
1070
itemCount , monsterCount , qualifyingTileCount ,
@@ -1245,6 +1323,10 @@ boolean buildAMachine(enum machineTypes bp,
1245
1323
}
1246
1324
}
1247
1325
1326
+ // Store info about created machine (will be deleted if machine fails)
1327
+ machineInfo * thisMachineInfo = createMachineInfo (rogue .depthLevel , machineNumber , bp );
1328
+ addMachineInfoToChain (thisMachineInfo , thisMachineInfoChain );
1329
+
1248
1330
// DEBUG printf("\n\nWorking on blueprint %i, with origin at (%i, %i). Here's the initial interior map:", bp, originX, originY);
1249
1331
// DEBUG logBuffer(interior);
1250
1332
@@ -1548,9 +1630,9 @@ boolean buildAMachine(enum machineTypes bp,
1548
1630
removeItemFromChain (theItem , floorItems );
1549
1631
removeItemFromChain (theItem , packItems );
1550
1632
theItem -> nextItem = NULL ;
1551
- success = buildAMachine (-1 , -1 , -1 , BP_ADOPT_ITEM , theItem , p -> spawnedItemsSub , p -> spawnedMonstersSub );
1633
+ success = buildAMachineOrChildMachine (-1 , -1 , -1 , BP_ADOPT_ITEM , theItem , p -> spawnedItemsSub , p -> spawnedMonstersSub , thisMachineInfo -> childMachineInfo );
1552
1634
} else if (feature -> flags & MF_BUILD_VESTIBULE ) {
1553
- success = buildAMachine (-1 , featX , featY , BP_VESTIBULE , NULL , p -> spawnedItemsSub , p -> spawnedMonstersSub );
1635
+ success = buildAMachineOrChildMachine (-1 , featX , featY , BP_VESTIBULE , NULL , p -> spawnedItemsSub , p -> spawnedMonstersSub , thisMachineInfo -> childMachineInfo );
1554
1636
}
1555
1637
1556
1638
// Now put the item up for adoption.
@@ -1569,6 +1651,13 @@ boolean buildAMachine(enum machineTypes bp,
1569
1651
}
1570
1652
break ;
1571
1653
}
1654
+ else {
1655
+ // Remove failed machine from info
1656
+ deleteAllMachineInfo (thisMachineInfo -> childMachineInfo );
1657
+ machineInfo * theChildInfo = (machineInfo * ) malloc (sizeof (machineInfo ));
1658
+ memset (theChildInfo , '\0' , sizeof (machineInfo ));
1659
+ thisMachineInfo -> childMachineInfo = theChildInfo ;
1660
+ }
1572
1661
}
1573
1662
1574
1663
if (!i ) {
@@ -1737,7 +1826,7 @@ static void addMachines() {
1737
1826
// Add the amulet holder if it's depth 26:
1738
1827
if (rogue .depthLevel == gameConst -> amuletLevel ) {
1739
1828
for (failsafe = 50 ; failsafe ; failsafe -- ) {
1740
- if (buildAMachine (MT_AMULET_AREA , -1 , -1 , 0 , NULL , NULL , NULL )) {
1829
+ if (buildAMachine (MT_AMULET_AREA , -1 , -1 , 0 )) {
1741
1830
break ;
1742
1831
}
1743
1832
}
@@ -1757,7 +1846,7 @@ static void addMachines() {
1757
1846
}
1758
1847
1759
1848
for (failsafe = 50 ; machineCount && failsafe ; failsafe -- ) {
1760
- if (buildAMachine (-1 , -1 , -1 , BP_REWARD , NULL , NULL , NULL )) {
1849
+ if (buildAMachine (-1 , -1 , -1 , BP_REWARD )) {
1761
1850
machineCount -- ;
1762
1851
rogue .rewardRoomsGenerated ++ ;
1763
1852
}
@@ -1835,7 +1924,7 @@ static void runAutogenerators(boolean buildAreaMachines) {
1835
1924
// Attempt to build the machine if requested.
1836
1925
// Machines will find their own locations, so it will not be at the same place as terrain and DF.
1837
1926
if (gen -> machine > 0 ) {
1838
- buildAMachine (gen -> machine , -1 , -1 , 0 , NULL , NULL , NULL );
1927
+ buildAMachine (gen -> machine , -1 , -1 , 0 );
1839
1928
}
1840
1929
}
1841
1930
}
0 commit comments