-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameState.py
More file actions
238 lines (211 loc) · 6.73 KB
/
gameState.py
File metadata and controls
238 lines (211 loc) · 6.73 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import os
import copy
import re
import cDefines
import gameLogic
import threading
import server
import json
import Queue
#class gameState:
mapDatas = []
mapDatas.append([])
mapDatas.append([])
mapDatas.append([])
mapDatas.append([])
dirList=os.listdir("maps")
for fileName in dirList:
if((not fileName.startswith(".")) and not fileName.startswith("defaultMap") and (fileName.endswith("map"))):
file = open("maps/"+fileName)
mapData = gameLogic.mapData(fileName,file.read())
mapDatas[mapData.teamSize-1].append(mapData)
file.close()
def getMapDatas():
global mapDatas
return mapDatas
playerUserNames = [False,False,False,False,False,False,False,False,]#need this because arbitrary players can leave, unlike ai players
def resetPlayerUserNames():
global playerUserNames
playerUserNames = [False,False,False,False,False,False,False,False,]
unitTypesList = []
dirList=os.listdir("units")
for fileName in dirList:
if((not fileName.startswith(".")) and fileName != "template" and (not fileName.endswith("~"))):
unitFile = open("units/"+fileName)
obj = json.load(unitFile)
unitTypesList.append(gameLogic.unitType(fileName.replace("_"," ").strip(),cDefines.defines[obj['textureName']+"_INDEX"],obj['movementSpeed'],obj['attackSpeed'],obj['attackPower'],obj['armor'],obj['range'],obj['health'],bool(obj['canFly']),bool(obj['canSwim']),obj['costRed'],obj['costBlue'],obj['buildTime'],obj['movementSpeedBonus'],obj['researchCostRed'],obj['researchCostBlue'],obj['researchTime']))
unitFile.close()
global theUnitTypes
theUnitTypes = {}
for unitType in unitTypesList:
theUnitTypes[unitType.name] = unitType
configOptions = {}
configFile = open("config.txt")
for line in configFile:
tokens = line.split("=")
configOptions[tokens[0]] = tokens[1].strip()
configFile.close()
def getConfig():
global configOptions
return configOptions
userName = None
def getOwnUserName():
global userName
return userName
def setOwnUserName(uName):
global userName
userName = uName
def changeUserName(playerNumber,newUserName):
thePlayers[playerNumber].userName = newUserName
theMapName = None
def getMapName():
global theMapName
return theMapName
def setMapName(mapName):
global theMapName
theMapName = mapName
theGameMode = None
def setGameMode(gameModeType,args=[]):
global theGameMode
if(theGameMode != None and theGameMode.modal != None):
theGameMode.modal.destroy()
theGameMode = gameModeType(args)
if(hasattr(theGameMode,"loadMap")):
theGameMode.loadMap()
theGameMode.addUIElements()
# if(hasattr(theGameMode,"startGame")):
# theGameMode.startGame()
def getGameMode():
global theGameMode
return theGameMode
theHostIP = None
def setHostIP(hostIP):
global theHostIP
theHostIP = hostIP
def getHostIP():
global theHostIP
return theHostIP
theClient = None
def setClient(client):
global theClient
theClient = client
def getClient():
global theClient
return theClient
theGameFindClient = None
def setGameFindClient(client):
global theGameFindClient
theGameFindClient = client
def getGameFindClient():
global theGameFindClient
return theGameFindClient
thePlayerNumber = -1
theTeamNumber = 0
def setPlayerNumber(playerNumber):
global thePlayerNumber
global theTeamNumber
thePlayerNumber = playerNumber
theTeamNumber = playerNumber/theTeamSize
def getPlayerNumber():
global thePlayerNumber
# if(thePlayerNumber == -2):
# if(getGameMode().selectedNode != None and getGameMode().selectedNode.unit != None):
# return getGameMode().selectedNode.unit.player
# elif(getGameMode().nextUnit != None):
# return getGameMode().nextUnit.player
# else:
# return 1
# else:
return thePlayerNumber
def getTeamNumber():
global theTeamNumber
return theTeamNumber
theTeamSize = 1
def setTeamSize(teamSize):
global theTeamSize
theTeamSize = teamSize
def getTeamSize():
global theTeamSize
return theTeamSize
#thePlayersLock = threading.Lock()
thePlayers = [None]*8
def addPlayer(playerClass=gameLogic.Player,userName="Player ?",playerNumber=0,requestHandler=None,playerObj=None):
player = None
if(playerObj != None):
player = playerClass(playerNumber=playerNumber,userName=userName,requestHandler=requestHandler,player=playerObj)
thePlayers[playerNumber] = player
elif(thePlayers[playerNumber] == None):#will be a NetworkPlayer already on the host
player = playerClass(playerNumber=playerNumber,userName=userName,requestHandler=requestHandler)
thePlayers[playerNumber] = player
else:
player = thePlayers[playerNumber]
return player
def removePlayer(playerNumber):
for index in range(0,8):
player = thePlayers[index]
if(player != None and player.playerNumber == playerNumber):
thePlayers[index] = None
def movePlayer(oldNumber,newNumber):
if(thePlayers[newNumber] == None):
thePlayers[newNumber] = thePlayers[oldNumber]
thePlayers[oldNumber] = None
thePlayers[newNumber].playerNumber = newNumber
# if(thePlayers[newNumber].userName == "Player " + str(oldNumber+1)):
# thePlayers[newNumber].userName = "Player " + str(newNumber+1)
if(oldNumber == getPlayerNumber()):
setPlayerNumber(newNumber)
def resetPlayers():
global thePlayers
thePlayers = [None]*8
def getPlayers():
global thePlayers
return thePlayers
theAIs = [None]*8
def addAIPlayer(aiPlayer):
theAIs[aiPlayer.playerNumber] = aiPlayer
def resetAIs():
global theAIs
theAIs = [None]*8
global nextAINumber
nextAINumber = 1
global researchProgress
researchProgress = [{},{},{},{},{},{},{},{},]
global availableUnitTypes
availableUnitTypes = [[],[],[],[],[],[],[],[],]
for i in range(0,8):
availableUnitTypes[i].append(theUnitTypes["gatherer"])
researchProgress[i][theUnitTypes["gatherer"]] = [1,0]
availableUnitTypes[i].append(theUnitTypes["swordsman"])
researchProgress[i][theUnitTypes["swordsman"]] = [1,0]
def getAvailableUnitTypes():
global availableUnitTypes
return availableUnitTypes[thePlayerNumber]
def getResearchProgress():
global researchProgress
return researchProgress[thePlayerNumber]
def reevalAvailableUnitTypes():
global researchProgress
global availableUnitTypes
global theUnitTypes
availableUnitTypes = [[],[],[],[],[],[],[],[],]
for i in range(0,8):
availableUnitTypes[i].append(theUnitTypes["gatherer"])
for unit in theGameMode.units:
if(unit.isMeditating and unit.unitType.name == "gatherer" and unit.node.city != None):
for unitType in unit.node.city.unitTypes:
if(availableUnitTypes[unit.player].count(unitType) == 0):
availableUnitTypes[unit.player].append(unitType)
if(not researchProgress[unit.player].has_key(unitType)):
researchProgress[unit.player][unitType] = [1,0]
global doingAStarMove
doingAStarMove = False
global cursorIndex
cursorIndex = -2
global movePath
movePath = []
global aStarPath
aStarPath = []
global focusQueue
focusQueue = Queue.Queue()
global rendererUpdateQueue
rendererUpdateQueue = Queue.Queue()