-
Notifications
You must be signed in to change notification settings - Fork 3
/
crewcomm.py
160 lines (108 loc) · 5.63 KB
/
crewcomm.py
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
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 15 18:01:01 2019
CrewComm - Communicate with crew members... poorly.
Note: I am very tempted to make this more sophisticated.
Note: * is now used in keywords files to indicate multi-word terms.
@author: Nuke Bloodaxe
"""
import io, os, pygame, random, crew
import global_constants as g
import helper_functions as h
CrewKeywords = {} #crewmember{}->Keyword->{event:reponse code,runtime event,list treatment-single/multiline etc}
CrewReplies = {} #crewmember{}->Key Respose Code->[responses]
#dictionary of key words->check event codes->check response requirement
#->pick response from list
#Dictionary of replies, index by reponse code. Contains lists.
class crewComm(object):
def __init__(self, shipCrew):
self.crewMembers = shipCrew
self.selectedCrew = 0 #nobody
self.state = 8
self.commStage = 0 # What Setup/Interaction stage are we at.
# Prepare background image
self.charCom = pygame.image.load(os.path.join('Graphics_Assets', 'charcom.png'))
self.charComScaled = pygame.transform.scale(self.charCom,(g.width,g.height))
# Prepare Character communication screen for blitting.
self.charComScaled = pygame.transform.scale(self.charCom, (g.width, g.height))
self.charComScaled.set_colorkey(g.BLACK)
self.musicState = False # Music playback?
def update(self, displaySurface):
return self.communicate(displaySurface)
# Handle mouse events for user interaction.
def interact(self, mouseButton):
# click to exit.
self.systemState = 10 # Untrap us.
return self.systemState
# Compare the keyword against all event entries and check to see which
# flags have been tripped, return the reply entry matching the highest
# tripped flag number.
def checkKeywordEventFlags(self, keyword = ""):
pass
# Parse the string of text looking for keywords present in the crewKeywords
# Dictionary. Returns a reply based on the best event flag for the text.
def textInterpret(self, text=""):
tokenisedText = text.split()
pass
# Draw the interface for the crew communicator.
def drawInterface(self, displaySurface):
displaySurface.fill(g.BLACK)
displaySurface.blit(self.charComScaled,(0,0)) # Set background.
# Main communication routine loop.
def communicate(self,displaySurface):
if self.commStage == 0:
# We need to ensure our system state is set.
self.systemState = 8
# Start comm music
if self.musicState == False:
pygame.mixer.music.load(os.path.join('sound', 'CREWCOMM.OGG'))
pygame.mixer.music.play()
self.musicState = True
self.commStage += 1
elif self.commStage == 1:
self.drawInterface(displaySurface)
# rewind and start music playing again if track end reached.
if not pygame.mixer.music.get_busy():
pygame.mixer.music.play()
if self.systemState != 8:
self.commStage = 0
self.musicState = False
return self.systemState # loop for the moment.
# load all crew comversation related data.
# file location and prefix, Number of files(file number), extension.
# Note: We have some advantages with the reposnse lines, as they are written
# to the crew terminal character by character, we can take advantage of the
# data formatting codes dynamically.
def loadCrewCommunications(file=os.path.join('Data_Generators', 'Other', 'crewcon'), count=6, extension='.tab'):
for index in range(1,count+1):
commFile = io.open(file+str(index)+extension, "r")
commDataString = []
keyWords = []
# commResponseString = [""]
CrewKeywords[index] = {}
CrewReplies[index] = {}
temp = [""]
while temp[0] != "ENDF":
commDataString = (commFile.readline().split('\n')[0]).split('\t') #Data Line
# print(commDataString) # for debug.
keyWords = commDataString[4].split('*')
for word in keyWords:
try:
CrewKeywords[index][word][commDataString[0]] = [commDataString[1],
commDataString[2],
commDataString[3]]
except:
CrewKeywords[index][word] = {}
CrewKeywords[index][word][commDataString[0]] = [commDataString[1],
commDataString[2],
commDataString[3]]
temp = (commFile.readline().split('\n')[0]).split('\t')
while temp[0] != "EOD" and temp[0] != "ENDF":
try:
CrewReplies[index][temp[0]]
except:
CrewReplies[index][temp[0]] = []
CrewReplies[index][temp[0]].append(temp[1])
temp = (commFile.readline().split('\n')[0]).split('\t')
# A crewmember's responses have now been loaded.
commFile.close()