Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/MAFH.activity/Dungeon.py
blob: fb9b24b6cb88026319129c60b6559acf88c23d44 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import os.path

from Room import Room
from constants import MAP_PATH
from JournalIntegration import do_load, load_dungeon_by_id

 ########################################################################
 #Dungeon class:  stores a 2d array of rooms representing the dungeon
 #                reads/parses a text file containing the data for a dungeon
 #######################################################################


class Dungeon:
  def __init__(self,fileName):
    self.fileName=fileName
    self.start=[0,0]
    self.index=0

    ###INITALIZE DICTIONARY, TUPLE:ROOM PAIRINGS
    self.rooms={}

    currentX=0
    currentY=0
    ###ENUM###
    NONE=-1
    PUZZLE=0
    LOCKED=1
    BOTH=2
    UNLOCKED=3
    EXIT=4
    ENTRANCE=5
    SHOP=6
    PUZZLEROOM=7
    HIDDEN=8

    if os.path.exists( MAP_PATH + self.fileName ):
        dgnFile=open( MAP_PATH + self.fileName,'r')
        d_dict = do_load( dgnFile )
        dgnFile.close()
    else:
        d_dict = load_dungeon_by_id( fileName )

    self.sizeX = d_dict['x']
    self.sizeY = d_dict['y']
    self.theme = d_dict['theme']
    self.name = d_dict['name']
    self.id = d_dict['d_id']
    self.next = d_dict['next']

    for line in d_dict['roomstr']:
      ###initialize room variables###
      doorN=False
      doorNFlag=NONE
      doorS=False
      doorSFlag=NONE
      doorE=False
      doorEFlag=NONE
      doorW=False
      doorWFlag=NONE
      roomFlag=NONE
      en1=0
      en2=0
      en3=0
      en4=0
      it1=0
      it2=0
      it3=0
      it4=0
      ###check characters in current line, set variables accordingly###
      ###KEY:1st character=door to north
      ###    2nd=door to south
      ###    3rd=door to east
      ###    4th=door to west
      ###    5th=if the room is a shop
      ###    6-9=enemy number in each slot (0 for no enemy)

      if line[0]=='N':
        doorN=True
        if line[1]=='l':
          doorNFlag=LOCKED
        elif line[1]=='p':
          doorNFlag=PUZZLE
        elif line[1]=='b':
          doorNFlag=BOTH
        elif line[1]=='u':
          doorNFlag=UNLOCKED
        elif line[1]=='e':
          doorNFlag=ENTRANCE
        elif line[1]=='x':
          doorNFlag=EXIT

      if line[2]=='S':
        doorS=True
        if line[3]=='l':
          doorSFlag=LOCKED
        elif line[3]=='p':
          doorSFlag=PUZZLE
        elif line[3]=='b':
          doorSFlag=BOTH
        elif line[3]=='u':
          doorSFlag=UNLOCKED
        elif line[3]=='e':
          doorSFlag=ENTRANCE
        elif line[3]=='x':
          doorSFlag=EXIT

      if line[4]=='W':
        doorW=True
        if line[5]=='l':
          doorWFlag=LOCKED
        elif line[5]=='p':
          doorWFlag=PUZZLE
        elif line[5]=='b':
          doorWFlag=BOTH
        elif line[5]=='u':
          doorWFlag=UNLOCKED
        elif line[5]=='e':
          doorWFlag=ENTRANCE
        elif line[5]=='x':
          doorWFlag=EXIT

      if line[6]=='E':
        doorE=True
        if line[7]=='l':
          doorEFlag=LOCKED
        elif line[7]=='p':
          doorEFlag=PUZZLE
        elif line[7]=='b':
          doorEFlag=BOTH
        elif line[7]=='u':
          doorEFlag=UNLOCKED
        elif line[7]=='e':
          doorEFlag=ENTRANCE
        elif line[7]=='x':
          doorEFlag=EXIT

      if line[8]=='S':
        roomFlag=SHOP
      elif line[8]=='P':
        roomFlag=PUZZLE
      else:
        event=int(line[8])

      rm=Room(doorN,doorNFlag,doorS,doorSFlag,doorE,doorEFlag,doorW,doorWFlag,roomFlag,line[9],line[10],line[11],line[12],line[13],line[15],line[17],line[19])

      #check hidden items
      if line[14]=='h':
        rm.it1.hidden=True
      elif line[14]=='v':
        rm.it1.hidden=False
      if line[16]=='h':
        rm.it2.hidden=True
      elif line[16]=='v':
        rm.it2.hidden=False
      if line[18]=='h':
        rm.it3.hidden=True
      elif line[18]=='v':
        rm.it3.hidden=False
      if line[20]=='h':
        rm.it4.hidden=True
      elif line[20]=='v':
        rm.it4.hidden=False

      #check battle items
      if line[14]=='b':
        rm.it1.battle=True
      if line[16]=='b':
        rm.it2.battle=True
      if line[18]=='b':
        rm.it3.battle=True
      if line[20]=='b':
        rm.it4.battle=True

      if doorSFlag==ENTRANCE or doorNFlag==ENTRANCE or doorWFlag==ENTRANCE or doorEFlag==ENTRANCE:
        self.start=(currentX,currentY)

      #start=[1,4]

      self.rooms[(currentX,currentY)]=rm
      ###update position in array###
      currentX+=1

      if currentX==self.sizeX:
        currentY+=1
        currentX=0

      if currentY>self.sizeY:
        break