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,9 +233,8 @@ func _load_worldmap():
func requestTiles(unit = null):
print("a")
rpc_id(1, 'requestTiles', unit)
signal receiveTiles
remote func receiveTiles(bundledTileStuff):
@ -246,8 +245,15 @@ remote func receiveTiles(bundledTileStuff):
func requestUnits():
rpc_id(1, 'requestUnits')
signal receiveUnits
remote func 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.
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.
rpc_id(1, 'moveUnit', route, selectedUnit.id)
WorldManager.requestMove(route,selectedUnit.id)
var convertedRoute = []
for coords in route:
convertedRoute.append($TileMap.map_to_world(coords))
@ -375,7 +375,7 @@ func clickSuperPath():
executeSuperPath(route, routeVertices)
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 = []
for coords in route:
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
if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false:
var localEvent = (self.make_input_local(event))
print(localEvent.position)
print(self.position)
if isSelected== true:
emit_signal("unitSelected",null)
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:
print("superunit")
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:
if isSelected== false:
emit_signal("unitSelected",self)
isSelected = true
return
func moveOnPath(route:Array):#this coordinates the movement/animation
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:
emit_signal("unitSelected",null)
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)
isSelected = true
return
func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true

View File

@ -10,7 +10,26 @@ var player:Array = []
var knownPlayers = {}
var pathToPlayers = 'user://users/'
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}
@ -34,31 +53,6 @@ func checkdiplo(factionA, factionB):
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):

View File

@ -216,3 +216,9 @@ remote func requestUnits(regionId = 123):
var clientId = get_tree().get_rpc_sender_id()
var boardUnits = regions[regionId].requestUnits()
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()