Pathfinding networking works now

This commit is contained in:
Joa2 2023-11-16 16:10:09 +01:00
parent 1a7ff9cd96
commit 0c2a075e5a
6 changed files with 42 additions and 37 deletions

View File

@ -233,7 +233,6 @@ func _load_worldmap():
func requestTiles(unit = null): func requestTiles(unit = null):
print("a")
rpc_id(1, 'requestTiles', unit) rpc_id(1, 'requestTiles', unit)
signal receiveTiles signal receiveTiles
@ -251,3 +250,10 @@ signal receiveUnits
remote func receiveUnits(newBoardUnits): remote func receiveUnits(newBoardUnits):
emit_signal("receiveUnits", newBoardUnits) emit_signal("receiveUnits", newBoardUnits)
func requestMove(route, unitID):
rpc_id(1, 'requestMove', route, unitID)
func endTurn():
rpc_id(1, 'endTurn')

View File

@ -125,11 +125,11 @@ func hoverPath(coord = hoveredCoords):#this gets the hovered tile and tells the
func nextRound():#this sends a nextRound signal to units on the board and refreshes their ap. func nextRound():#this sends a nextRound signal to units on the board and refreshes their ap.
resetPathing() resetPathing()
rpc_id(1, 'nextRound') # rpc_id(1, 'nextRound')
func executePath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route. func executePath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route.
rpc_id(1, 'moveUnit', route, selectedUnit.id) WorldManager.requestMove(route,selectedUnit.id)
var convertedRoute = [] var convertedRoute = []
for coords in route: for coords in route:
convertedRoute.append($TileMap.map_to_world(coords)) convertedRoute.append($TileMap.map_to_world(coords))
@ -375,7 +375,7 @@ func clickSuperPath():
executeSuperPath(route, routeVertices) executeSuperPath(route, routeVertices)
func executeSuperPath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route. func executeSuperPath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route.
rpc_id(1, 'moveUnit', route, selectedUnit.id) WorldManager.requestMove(route,selectedUnit.id)
var convertedRoute = [] var convertedRoute = []
for coords in route: for coords in route:
convertedRoute.append($TileMap.map_to_world(coords)) convertedRoute.append($TileMap.map_to_world(coords))

View File

@ -32,15 +32,15 @@ func snapToPosition():
func _input(event):#this selects unit and signals the selected node to the main node func _input(event):#this selects unit and signals the selected node to the main node
if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false: if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false:
var localEvent = (self.make_input_local(event)) var localEvent = (self.make_input_local(event))
print(localEvent.position)
print(self.position)
if isSelected== true: if isSelected== true:
emit_signal("unitSelected",null) emit_signal("unitSelected",null)
isSelected = false isSelected = false
if localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 128 and localEvent.position.y < self.position.y + 128: if localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 64 and localEvent.position.y < self.position.y + 64:
print("superunit")
if isSelected== false: if isSelected== false:
emit_signal("unitSelected",self) emit_signal("unitSelected",self)
isSelected = true isSelected = true
return
func moveOnPath(route:Array):#this coordinates the movement/animation func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true isMoving=true

View File

@ -28,10 +28,9 @@ func _input(event):#this selects unit and signals the selected node to the main
if isSelected== true: if isSelected== true:
emit_signal("unitSelected",null) emit_signal("unitSelected",null)
isSelected = false isSelected = false
elif event.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 64 and localEvent.position.y < self.position.y + 64: elif event.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 32 and localEvent.position.y < self.position.y + 32:
emit_signal("unitSelected",self) emit_signal("unitSelected",self)
isSelected = true isSelected = true
return
func moveOnPath(route:Array):#this coordinates the movement/animation func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true isMoving=true

View File

@ -10,7 +10,26 @@ var player:Array = []
var knownPlayers = {} var knownPlayers = {}
var pathToPlayers = 'user://users/' var pathToPlayers = 'user://users/'
var clients_factions = {} #used to recognize if networkrequest are allowed to do an action {networkid:factionname} var clients_factions = {} #used to recognize if networkrequest are allowed to do an action {networkid:factionname}
var factions = {} var factions = {
playerFaction = {
diplomacy={
enemies =['enemyFaction'],
allies=['allyFaction']
}
},
allyFaction = {
diplomacy={
enemies =[],
allies=['playerFaction','enemyFaction']
}
},
enemyFaction = {
diplomacy={
enemies =['playerFaction',],
allies=['allyFaction']
}
}
}
var diplomacyStates = {'neutral': 1, 'own' : 2, 'enemies':3, "allies":4} var diplomacyStates = {'neutral': 1, 'own' : 2, 'enemies':3, "allies":4}
@ -34,31 +53,6 @@ func checkdiplo(factionA, factionB):
return response return response
return response return response
#returns neutral for neutral, allies for allies, own for own and enemies for enemies
func checkDiplo(faction):
var data = authcache['response']
var authed = data['found']
var response = 'neutral'
if faction==data['faction']:
response = 'own'
return response
elif authed:
if data.has('factiondata'):
var factiondata = data['factiondata']
if factiondata.has('diplomacy'):
var diplo = factiondata['diplomacy']
for key in diplo:
if diplo[key].has(faction):
response = key
return response
# print("checking diplo")
# print(data, faction)
# print("considered ", response)
# print(" ")
# print("illegal move attempt")
return response
#var diplo = factiondata['diplomacy']
pass
func confirmFaction(id, factionname): func confirmFaction(id, factionname):

View File

@ -216,3 +216,9 @@ remote func requestUnits(regionId = 123):
var clientId = get_tree().get_rpc_sender_id() var clientId = get_tree().get_rpc_sender_id()
var boardUnits = regions[regionId].requestUnits() var boardUnits = regions[regionId].requestUnits()
rpc_id(clientId, 'receiveUnits', boardUnits) rpc_id(clientId, 'receiveUnits', boardUnits)
remote func requestMove(route, unitID, regionId = 123):
regions[regionId].moveUnit(route, unitID)
remote func endTurn(regionId = 123):
regions[regionId].nextRound()