Skip to content

Commit

Permalink
Merge pull request #78 from Edern76/secondary
Browse files Browse the repository at this point in the history
Merge lot of stuff
  • Loading branch information
Edern76 authored May 15, 2017
2 parents 6ca4d8f + 75f6c58 commit 6905fd1
Show file tree
Hide file tree
Showing 8 changed files with 1,621 additions and 479 deletions.
Binary file added assets/ascii/violetpotion.xp
Binary file not shown.
168 changes: 39 additions & 129 deletions code/experiments/chasmGen.py → code/chasmGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
rooms = []
roomTiles = []
tunnelTiles = []
visuTiles = []
visuEdges = []
confTiles = []
dispEmpty = False
dispDebug = True
state = "base"
unchasmable = []
lastX = 0
lastY = 0
Expand Down Expand Up @@ -78,77 +72,6 @@ def returnOtherOwners(self, base):
newList.remove(base)
return newList


class Room:
def __init__(self, tiles, borders = []):
self.tiles = tiles
self.borders = borders
rooms.append(self)
self.contestedTiles = []
self.collidingRooms = []
self.connectedRooms = []
self.protect = False
self.mainRoom = False
self.reachableFromMainRoom = False

def remove(self):
for (x,y) in self.tiles:
closeTile(x, y, myMap)
rooms.remove(self)
del self

def claimTile(self, x, y):
if (x,y) in self.tiles or (x,y) in self.borders:
conflict = myMap[x][y].addOwner(self)
if conflict:
print("CONFLICT")
self.contestedTiles.append((x,y))
for contester in conflict:
if not contester in self.collidingRooms:
self.collidingRooms.append(contester)
else:
raise IllegalTileInvasion("At {} {}".format(x, y))

def claimBorders(self):
for (x, y) in self.borders:
self.claimTile(x, y)

def mergeWith(self, other, arbitraryTiles = []):
self.protect = True
if not other.protect:
if self in self.collidingRooms:
self.collidingRooms.remove(self)
print("REMOVED SELF FROM COLLROOMS")
for (x,y) in other.tiles:
if not (x,y) in self.tiles:
self.tiles.append((x,y))

for (x,y) in arbitraryTiles:
if not (x,y) in self.tiles:
self.tiles.append((x,y))

for (x,y) in other.borders:
if not (x,y) in self.borders:
self.borders.append((x,y))

if other in rooms:
rooms.remove(other)
else:
print("Other room not in rooms")
if other in self.collidingRooms:
self.collidingRooms.remove(other)
else:
print("Other room not in colliding rooms")
del other
else:
print("OTHER ROOM IS FUCKING PROTECTED, DO NOT MERGE")

def setReachable(self):
if not self.reachableFromMainRoom:
self.reachableFromMainRoom = True
for room in self.connectedRooms:
room.setReachable()


class Rectangle:
def __init__(self, x, y, w, h):
Expand Down Expand Up @@ -186,17 +109,39 @@ def createVerticalTunnel(y1, y2, x):
myMap[x][y].blocked = False
tunnelTiles.append((x, y))

def unblockTunnels():
global myMap, tunnelTiles, roomTiles
def unblockTunnels(mapToUse, roomTiles, tunnelTiles, unchasmable):
for x in range(MAP_WIDTH):
for y in range(MAP_HEIGHT):
if myMap[x][y].chasm and ((x, y) in unchasmable or ((x,y) in tunnelTiles and not (x, y) in roomTiles)):
myMap[x][y].chasm = False
if mapToUse[x][y].chasm and ((x, y) in unchasmable or ((x,y) in tunnelTiles and not (x, y) in roomTiles)):
mapToUse[x][y].chasm = False
mapToUse[x][y].fg = colors.lighter_grey
mapToUse[x][y].bg = colors.darker_sepia
return mapToUse

def checkMap():
for x in range(MAP_WIDTH):
for y in range(MAP_HEIGHT):
if myMap[x][y].chasm:
myMap[x][y].fg = colors.dark_grey
myMap[x][y].bg = colors.black
else:
myMap[x][y].fg = colors.lighter_grey
myMap[x][y].bg = colors.darker_sepia
myMap[x][y].bg = colors.dark_sepia

def createChasms(mapToUse, roomTiles, tunnelTiles, unchasmable):
for x in range(1, MAP_WIDTH - 1):
for y in range(1, MAP_HEIGHT - 1):
if randint(0, 100) < CHANCE_TO_START_ALIVE:
#mapToUse[x][y].fg = colors.lighter_grey
#mapToUse[x][y].bg = colors.dark_sepia
mapToUse[x][y].chasm = False
for loop in range(STEPS_NUMBER):
mapToUse = doStep(mapToUse)
newMap = unblockTunnels(mapToUse, roomTiles, tunnelTiles, unchasmable)
return newMap

def makeMap():
global myMap, baseMap, rooms, roomTiles, tunnelTiles, unchasmable, firstX, firstY, lastX, lastY
global myMap, rooms, roomTiles, tunnelTiles, unchasmable, firstX, firstY, lastX, lastY

myMap = [[Tile(blocked = True, x = x, y = y) for y in range(MAP_HEIGHT)]for x in range(MAP_WIDTH)] #Creates a rectangle of blocking tiles from the Tile class, aka walls. Each tile is accessed by myMap[x][y], where x and y are the coordinates of the tile.
rooms = []
Expand All @@ -206,19 +151,13 @@ def makeMap():

for x in range(MAP_WIDTH):
myMap[x][0].setIndestructible()
removeFromEmptyTiles(x,0)
myMap[x][MAP_HEIGHT - 1].setIndestructible()
removeFromEmptyTiles(x, MAP_HEIGHT - 1)
for y in range(MAP_HEIGHT):
if not myMap[x][y].blocked and not (x,y) in emptyTiles:
emptyTiles.append((x,y))
for y in range(MAP_HEIGHT):
myMap[0][y].setIndestructible()
removeFromEmptyTiles(0, y)
myMap[MAP_WIDTH - 1][y].setIndestructible()
removeFromEmptyTiles(MAP_WIDTH - 1, y)

baseMap = list(copy.deepcopy(myMap))

for r in range(30):
w = randint(6, 10)
Expand Down Expand Up @@ -255,6 +194,8 @@ def makeMap():
for y in range(lastCreatedRoom.y1 + 1, lastCreatedRoom.y2):
unchasmable.append((x, y))

myMap = createChasms(myMap, roomTiles, tunnelTiles, unchasmable)
'''
for x in range(1, MAP_WIDTH - 1):
for y in range(1, MAP_HEIGHT - 1):
if randint(0, 100) < CHANCE_TO_START_ALIVE:
Expand All @@ -264,13 +205,9 @@ def makeMap():
for loop in range(STEPS_NUMBER):
myMap = doStep(myMap)
unblockTunnels()
'''

myMap = [[]]
baseMap = [[]]


maps = [myMap, baseMap]
mapIndex = 0

def countNeighbours(mapToUse, startX, startY, stopAtFirst = False):
count = 0
Expand All @@ -290,26 +227,6 @@ def countNeighbours(mapToUse, startX, startY, stopAtFirst = False):
if stopAtFirst and found:
break
return count
def removeFromEmptyTiles(x, y):
if (x,y) in emptyTiles:
emptyTiles.remove((x,y))

def openTile(x, y, mapToUse):
if mapToUse[x][y].open() and not (x,y) in emptyTiles:
#emptyTiles.append((x,y))
pass

def closeTile(x, y, mapToUse):
mapToUse[x][y].close()
#removeFromEmptyTiles(x,y)

def refreshEmptyTiles():
global emptyTiles
emptyTiles = []
for x in range(MAP_WIDTH):
for y in range(MAP_HEIGHT):
if not myMap[x][y].blocked:
emptyTiles.append((x,y))

def doStep(oldMap):
newMap = list(copy.deepcopy(oldMap))
Expand All @@ -318,31 +235,24 @@ def doStep(oldMap):
neighbours = countNeighbours(oldMap, x, y)
if not oldMap[x][y].chasm:
if neighbours < DEATH_LIMIT:
newMap[x][y].fg = colors.dark_grey
newMap[x][y].bg = colors.black
#newMap[x][y].fg = colors.dark_grey
#newMap[x][y].bg = colors.black
newMap[x][y].chasm = True
else:
newMap[x][y].fg = colors.lighter_grey
newMap[x][y].bg = colors.dark_sepia
#newMap[x][y].fg = colors.lighter_grey
#newMap[x][y].bg = colors.dark_sepia
newMap[x][y].chasm = False
else:
if neighbours > BIRTH_LIMIT:
newMap[x][y].fg = colors.lighter_grey
newMap[x][y].bg = colors.dark_sepia
#newMap[x][y].fg = colors.lighter_grey
#newMap[x][y].bg = colors.dark_sepia
newMap[x][y].chasm = False
else:
newMap[x][y].fg = colors.dark_grey
newMap[x][y].bg = colors.black
#newMap[x][y].fg = colors.dark_grey
#newMap[x][y].bg = colors.black
newMap[x][y].chasm = True
return newMap

def drawCentered(cons = root , y = 1, text = "Lorem Ipsum", fg = None, bg = None):
xCentered = (WIDTH - len(text))//2
cons.draw_str(xCentered, y, text, fg, bg)




def update(mapToUse):
root.clear()
try:
Expand Down
15 changes: 14 additions & 1 deletion code/dunbranches.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import colors

branches = []

class Branch:
def __init__(self, shortName, name = None, maxDepth = 99999, branchesFrom = None, branchesTo = None, lightStairsColor = colors.white, darkStairsColor = colors.dark_gray,
monsterChances = {'darksoul': 600, 'ogre': 200, 'snake': 50, 'cultist': 150, 'highCultist' : 0},
Expand All @@ -10,7 +12,7 @@ def __init__(self, shortName, name = None, maxDepth = 99999, branchesFrom = None
weaponChances = {'sword': 25, 'axe': 25, 'hammer': 25, 'mace': 25},
foodChances = {'bread' : 500, 'herbs' : 501, 'rMeat' : 300, 'pie' : 200, 'pasta' : 200, 'meat' : 100, 'hBaguette' : 10}, # TO-DO : Add dumb stuff here with very low chances of spawning (maybe more on Gluttony's branch ?) and dumb effects, aka easter eggs.
color_dark_wall = colors.darkest_grey, color_light_wall = colors.darker_grey, color_dark_ground = colors.darkest_sepia, color_dark_gravel = (27, 20, 0),
color_light_ground = colors.darker_sepia, color_light_gravel = (50, 37, 0), bossLevels = [3, 6], bossNames = {'High Inquisitor': 3, 'Gluttony': 6}, fixedMap = None, genType = 'dungeon'):
color_light_ground = colors.darker_sepia, color_light_gravel = (50, 37, 0), bossLevels = [3, 6], bossNames = {'High Inquisitor': 3, 'Gluttony': 6}, fixedMap = None, genType = 'dungeon', genFeatures = ['chasms']):
"""
A branch of the dungeon. Please note that the main dungeon is also considered as a branch.
@type shortName: str
Expand Down Expand Up @@ -50,13 +52,24 @@ def __init__(self, shortName, name = None, maxDepth = 99999, branchesFrom = None
self.bossNames = bossNames
self.fixedMap = fixedMap
self.genType = genType
self.genFeatures = genFeatures
self.appeared = False

branches.append(self)

mainDungeon = Branch(shortName = "main", name = "Main", branchesTo = None)
gluttonyDungeon = Branch(shortName = "glutt", name = "Gluttony Dungeon", maxDepth = 5, branchesFrom = (mainDungeon, 1), lightStairsColor = colors.desaturated_chartreuse, darkStairsColor = colors.darkest_chartreuse, monsterChances = {'darksoul': 400, 'ogre': 200, 'starveling': 250, 'cultist': 150}, itemChances = {'potion': 360, 'scroll': 20, 'weapon': 20, 'shield': 100, 'food': 500}, bossLevels = [5], bossNames = {'Gluttony': 5})
hiddenTown = Branch(shortName = 'town',name = "Hidden Refuge", maxDepth = 1, branchesFrom = (mainDungeon, 1),lightStairsColor = colors.azure, darkStairsColor = colors.darker_azure, fixedMap = 'town')
greedDungeon = Branch(shortName = 'greed', name = 'Greed Cavern', maxDepth = 5, branchesFrom= (mainDungeon, 2), lightStairsColor = colors.yellow, darkStairsColor = colors.darker_yellow, genType = 'cave', monsterChances = {'darksoul': 400, 'ogre': 100, 'snake': 10, 'cultist': 150, 'greedyFiend' : 200}, color_light_wall = colors.darker_yellow, color_dark_wall = colors.darkest_yellow, color_light_ground = colors.darker_sepia, color_dark_ground = colors.darkest_sepia, itemChances = {'potion': 100, 'scroll': 150, 'weapon': 50, 'shield': 50, 'food': 90, 'money' : 300})
wrathDungeon = Branch(shortName = "wrath", name = "Wrath Lair", maxDepth = 5, branchesFrom = (mainDungeon, 2), lightStairsColor = colors.dark_red, darkStairsColor = colors.darkest_red, monsterChances = {'darksoul': 400, 'ogre': 400, 'cultist': 200}, itemChances = {'potion': 360, 'scroll': 20, 'weapon': 400, 'shield': 20, 'food': 200}, bossLevels = [5], bossNames = {'Wrath': 5}, genFeatures = ['holes'])

mainDungeon.branchesTo.append((gluttonyDungeon, 1))
mainDungeon.branchesTo.append((hiddenTown, 1))
mainDungeon.branchesTo.append((greedDungeon, 2))
mainDungeon.branchesTo.append((wrathDungeon, 2))

def reinitializeBranches():
for branch in branches:
print("Reinitializing {}".format(branch.name))
branch.appeared = False

Loading

0 comments on commit 6905fd1

Please sign in to comment.