Browse Source

angefangen pathfinding zu überabreiten. funktioniert noch nicht

master
Joa2 1 month ago
parent
commit
71ca8d3357
  1. 1
      Client/menues/LoginPlayerMenu.gd
  2. 283
      Client/region/Region.gd
  3. 12
      Client/region/SuperUnit.gd
  4. 12
      Client/region/Unit.gd
  5. BIN
      Server/new_script.vs
  6. 14
      Server/region/Region.gd

1
Client/menues/LoginPlayerMenu.gd

@ -7,6 +7,7 @@ func _on_btnBack_button_down():
func _on_btnRegister_button_down():
PlayerManager.logInUser(username, password)
get_tree().change_scene("res://region/Region.tscn")
func _on_iptPlayerName_text_changed(new_text):
username = new_text

283
Client/region/Region.gd

@ -12,7 +12,7 @@ var selectedFaction
var boardUnits ={}
var occupiedTiles=[]
var enemyOccupiedTiles=[]
var route
var stepsStartToTileInCoords
var routeVertices
var hoveredCoords
var regionID = 123
@ -39,7 +39,7 @@ func receiveTiles(newTileRect, newTiles, newSuperTiles):
func requestUnits():
WorldManager.requestUnits(regionID)
func receiveUnits(newBoardUnits):#overwork this
func receiveUnits(newBoardUnits):
boardUnits = newBoardUnits
for child in $TileMap/Units.get_children():
child.queue_free()
@ -55,31 +55,22 @@ func receiveUnits(newBoardUnits):#overwork this
newUnit.on_ready()
boardUnitsIndex +=1
func unitSelectedMethod(unit, debugOriginUnit):#this is called when a unit is selected
print("from: ",boardUnits[debugOriginUnit.boardUnitsIndex].id)
if unit == null:
clearPathingInfo()
$moveapcost.text = ""
$unitapcounter.text = ""
selectedFaction = null
selectedUnit = null
for unit in boardUnits:
unit.isSelected = false
$TileMap/LineManager.drawAdvancedLine([],[],0,0)
else:
selectedNode = unit
selectedUnit = boardUnits[unit.boardUnitsIndex]
requestTiles(selectedUnit)
selectedFaction = selectedUnit.faction
for unit in boardUnits:
if unit.id != selectedUnit.id:
unit.isSelected = false
$TileMap/LineManager.drawAdvancedLine([],[],0,0)
# print(selectedUnit)
func _input(event):#this responds to any input. Has various functions depending on input
if selectedUnit != null:
if event is InputEventMouseButton and Input.is_action_just_released("ui_left_mouse_button"):
if event is InputEventMouse:
mouseEvent(event)
if event is InputEvent and Input.is_action_just_released("ui_accept"):
if animationInProgress == false:
nextRound()
if event is InputEvent and Input.is_action_just_released("ui_right"):
print("reset pathing")
resetPathing()
func mouseEvent(event):
if !selectedUnit:
if Input.is_action_just_released("ui_left_mouse_button"):
pass
else:
if Input.is_action_just_released("ui_left_mouse_button"):
if !selectedUnit.superUnit:
clickPath()
else:
@ -91,27 +82,21 @@ func _input(event):#this responds to any input. Has various functions depending
hoverPath()
else:
hoverSuperPath()
if event is InputEvent and Input.is_action_just_released("ui_accept"):
if animationInProgress == false:
nextRound()
if event is InputEvent and Input.is_action_just_released("ui_right"):
print("reset pathing")
resetPathing()
func clickPath():#this finalizes the selected path while calculating ap and new ap and shortening the path if ap is insufficient. Then it calls to execute the path
if animationInProgress == false and route.size() >1:
if animationInProgress == false and stepsStartToTileInCoords.size() >1:
var totalApCost = addUpArray(routeVertices)
if totalApCost > selectedUnit.moveAp:
var apDebt = totalApCost - selectedUnit.moveAp
if apDebt > selectedUnit.ap:
while addUpArray(routeVertices) > selectedUnit.ap + selectedUnit.moveAp:
route.pop_back()
stepsStartToTileInCoords.pop_back()
routeVertices.pop_back()
while route.size() != 0 and occupiedTiles.has(route[-1]):#prevents overlap
route.pop_back()
while stepsStartToTileInCoords.size() != 0 and occupiedTiles.has(stepsStartToTileInCoords[-1]):#prevents overlap
stepsStartToTileInCoords.pop_back()
routeVertices.pop_back()
if route.size() > 1:
executePath(route, routeVertices)
if stepsStartToTileInCoords.size() > 1:
executePath(stepsStartToTileInCoords, routeVertices)
func hoverPath(coord = hoveredCoords):#this gets the hovered tile and tells the pathfinding to make the path and tells the line to draw the returned path
if selectedUnit !=null and coord != null:
@ -132,11 +117,10 @@ func nextRound():#this sends a nextRound signal to units on the board and refres
WorldManager.endTurn(regionID)
WorldManager.requestUnits(regionID)
func executePath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route.
WorldManager.requestMove(route,selectedUnit.id, regionID)
func executePath(stepsStartToTileInCoords, stepsStartToTileInDistances):#this takes the current selected stepsStartToTileInCoords and tells the unit to execute it/ follow the selected stepsStartToTileInCoords.
WorldManager.requestMove(stepsStartToTileInCoords,selectedUnit.id, regionID)
var convertedRoute = []
for coords in route:
for coords in stepsStartToTileInCoords:
convertedRoute.append($TileMap.map_to_world(coords))
selectedNode.moveOnPath(convertedRoute)
animationInProgress = true
@ -145,44 +129,44 @@ func executePath(route, vertices):#this takes the current selected route and tel
func clearPathingInfo():#this erases the Dijkstra/pathfinding-specific tile info for when a new tile is selected and new pathfinding info is needed.
for column in tiles:
for tile in column:
tile.verticeExplored = false
tile.route = []
tile.surroundingTilesExplored = false
tile.stepsStartToTileInCoords = []
tile.shortestKnownPath = INF
tile.vertices = []
tile.stepsStartToTileInDistances = []
for column in superTiles:
for tile in column:
tile.verticeExplored = false
tile.route = []
tile.surroundingTilesExplored = false
tile.stepsStartToTileInCoords = []
tile.shortestKnownPath = INF
tile.vertices = []
tile.stepsStartToTileInDistances = []
pass
func setDistance(target, origin, index, diagonal = false):#this sets the distances to the connections between tiles.
if not diagonal:
match target.type:
"grass":
origin.verticeDistance[index] = 5
origin.distancesToSurroundingTiles[index] = 5
"road":
origin.verticeDistance[index] = 2
origin.distancesToSurroundingTiles[index] = 2
"mountain":
origin.verticeDistance[index] = INF
origin.distancesToSurroundingTiles[index] = INF
"enemyOccupied":
origin.verticeDistance[index] = INF
origin.distancesToSurroundingTiles[index] = INF
else:
match target.type:
"grass":
origin.verticeDistance[index] = 8
origin.distancesToSurroundingTiles[index] = 8
"road":
origin.verticeDistance[index] = 3
origin.distancesToSurroundingTiles[index] = 3
"mountain":
origin.verticeDistance[index] = INF
origin.distancesToSurroundingTiles[index] = INF
"enemyOccupied":
origin.verticeDistance[index] = INF
origin.distancesToSurroundingTiles[index] = INF
func findPath(start, end):#this actually finds the path. returns an array that at [0] contains the route and at [1] contains the distances of each step on the route (vertices).
func findPath(start, end):#this actually finds the path. returns an array that at [0] contains the stepsStartToTileInCoords and at [1] contains the distances of each step on the stepsStartToTileInCoords (stepsStartToTileInDistances).
var startingTile = tiles[start.x][start.y]
var endTile = tiles[end.x][end.y]
startingTile.vertices = [0]
startingTile.stepsStartToTileInDistances = [0]
var smallestVerticeDistance
var a = [1]
for number in a:
@ -190,28 +174,28 @@ func findPath(start, end):#this actually finds the path. returns an array that a
var smallestVertice = [INF]
for columns in tiles:
for tile in columns:
if tile.route.size() == 0:
tile.route.append(startingTile.coords)
if tile.vertices == null:
print("\n ERROR Some vertices are null \n")
if tile.stepsStartToTileInCoords.size() == 0:
tile.stepsStartToTileInCoords.append(startingTile.coords)
if tile.stepsStartToTileInDistances == null:
print("\n ERROR Some stepsStartToTileInDistances are null \n")
break
if tile.verticeExplored == false and tile.vertices.size() > 0:
if tile.surroundingTilesExplored == false and tile.stepsStartToTileInDistances.size() > 0:
smallestVerticeDistance = addUpArray(smallestVertice)
var tileTotalVertice = 0
tileTotalVertice = addUpArray(tile.vertices)
tileTotalVertice = addUpArray(tile.stepsStartToTileInDistances)
if tileTotalVertice < smallestVerticeDistance:
smallestVertice = tile.vertices
currentTile = tile# Hier wird die neue currentTile gesetzt. DIe neue CurrenTile ist die mit dem kleinsten zusammengerechneten Vertices/ dem kurzesten Pfad
smallestVertice = tile.stepsStartToTileInDistances
currentTile = tile# Hier wird die neue currentTile gesetzt. DIe neue CurrenTile ist die mit dem kleinsten zusammengerechneten stepsStartToTileInDistances/ dem kurzesten Pfad
if currentTile == null:
animationInProgress = false
break
if currentTile == endTile:
route=endTile.route
routeVertices=endTile.vertices
return[endTile.route, endTile.vertices]
stepsStartToTileInCoords=endTile.stepsStartToTileInCoords
routeVertices=endTile.stepsStartToTileInDistances
return[endTile.stepsStartToTileInCoords, endTile.stepsStartToTileInDistances]
var translation = null
var direction = 0
for entry in currentTile.verticeDistance:
for entry in currentTile.distancesToSurroundingTiles:
match direction:
0:
if entry != INF:
@ -239,17 +223,17 @@ func findPath(start, end):#this actually finds the path. returns an array that a
translation = Vector2(-1,1)
if translation != null:
var tileToModify = tiles[(currentTile.coords + translation).x][(currentTile.coords + translation).y]
if addUpArray(currentTile.vertices) + currentTile.verticeDistance[direction] < addUpArray(tileToModify.vertices) or tileToModify.vertices.size() == 0:
if addUpArray(currentTile.stepsStartToTileInDistances) + currentTile.distancesToSurroundingTiles[direction] < addUpArray(tileToModify.stepsStartToTileInDistances) or tileToModify.stepsStartToTileInDistances.size() == 0:
# print("Shorter Path found.")
var newShortestPath = currentTile.duplicate().vertices.duplicate()
var newnewShortestPath = newShortestPath.append(currentTile.duplicate().verticeDistance.duplicate()[direction])
tileToModify.vertices = newShortestPath.duplicate()
var newShortestRoute = currentTile.duplicate().route.duplicate()
var newShortestPath = currentTile.duplicate().stepsStartToTileInDistances.duplicate()
var newnewShortestPath = newShortestPath.append(currentTile.duplicate().distancesToSurroundingTiles.duplicate()[direction])
tileToModify.stepsStartToTileInDistances = newShortestPath.duplicate()
var newShortestRoute = currentTile.duplicate().stepsStartToTileInCoords.duplicate()
var newnewShortestRoute = newShortestRoute.append(tileToModify.coords) #this is really bodged but i dont know how to fix it and it somehow works fine despite everything
tileToModify.route = newShortestRoute
tileToModify.stepsStartToTileInCoords = newShortestRoute
direction += 1
tiles[currentTile.coords.x][currentTile.coords.y]= currentTile
currentTile.verticeExplored = true
currentTile.surroundingTilesExplored = true
a.append(1)
func addUpArray(array):#adds up each int in an array. useful for calculating total distance.
@ -266,18 +250,18 @@ func _on_pathAnimationCompleted():#this gets a signal from the selected unit and
animationInProgress = false
selectedUnit = null
func resetPathing():#this clears the current route and removes the line. Without it weird bugs can happen where It can do a path that it already did again.
route = []
func resetPathing():#this clears the current stepsStartToTileInCoords and removes the line. Without it weird bugs can happen where It can do a path that it already did again.
stepsStartToTileInCoords = []
routeVertices = []
if selectedUnit != null:
$TileMap/LineManager.drawAdvancedLine(route, routeVertices, selectedUnit.ap, selectedUnit.moveAp)
$TileMap/LineManager.drawAdvancedLine(stepsStartToTileInCoords, routeVertices, selectedUnit.ap, selectedUnit.moveAp)
else:
$TileMap/LineManager.drawAdvancedLine(route, routeVertices, 0, 0)
$TileMap/LineManager.drawAdvancedLine(stepsStartToTileInCoords, routeVertices, 0, 0)
func findSuperPath(start,end):
var startingTile = superTiles[start.x][start.y]
var endTile = superTiles[end.x][end.y]
startingTile.vertices = [0]
startingTile.stepsStartToTileInDistances = [0]
var smallestVerticeDistance
var a = [1]
for number in a:
@ -285,28 +269,28 @@ func findSuperPath(start,end):
var smallestVertice = [INF]
for columns in superTiles:
for tile in columns:
if tile.route.size() == 0:
tile.route.append(startingTile.coords)
if tile.vertices == null:
print("\n ERROR Some vertices are null \n")
if tile.stepsStartToTileInCoords.size() == 0:
tile.stepsStartToTileInCoords.append(startingTile.coords)
if tile.stepsStartToTileInDistances == null:
print("\n ERROR Some stepsStartToTileInDistances are null \n")
break
if tile.verticeExplored == false and tile.vertices.size() > 0:
if tile.surroundingTilesExplored == false and tile.stepsStartToTileInDistances.size() > 0:
smallestVerticeDistance = addUpArray(smallestVertice)
var tileTotalVertice = 0
tileTotalVertice = addUpArray(tile.vertices)
tileTotalVertice = addUpArray(tile.stepsStartToTileInDistances)
if tileTotalVertice < smallestVerticeDistance:
smallestVertice = tile.vertices
currentTile = tile# Hier wird die neue currentTile gesetzt. DIe neue CurrenTile ist die mit dem kleinsten zusammengerechneten Vertices/ dem kurzesten Pfad
smallestVertice = tile.stepsStartToTileInDistances
currentTile = tile# Hier wird die neue currentTile gesetzt. DIe neue CurrenTile ist die mit dem kleinsten zusammengerechneten stepsStartToTileInDistances/ dem kurzesten Pfad
if currentTile == null:
animationInProgress = false
break
if currentTile == endTile:
route=endTile.route
routeVertices=endTile.vertices
return[endTile.route, endTile.vertices]
stepsStartToTileInCoords=endTile.stepsStartToTileInCoords
routeVertices=endTile.stepsStartToTileInDistances
return[endTile.stepsStartToTileInCoords, endTile.stepsStartToTileInDistances]
var translation = null
var direction = 0
for entry in currentTile.verticeDistance:
for entry in currentTile.distancesToSurroundingTiles:
match direction:
0:
if entry != INF:
@ -334,17 +318,17 @@ func findSuperPath(start,end):
translation = Vector2(-1,1)
if translation != null:
var tileToModify = superTiles[(currentTile.coords + translation).x][(currentTile.coords + translation).y]
if addUpArray(currentTile.vertices) + currentTile.verticeDistance[direction] < addUpArray(tileToModify.vertices) or tileToModify.vertices.size() == 0:
if addUpArray(currentTile.stepsStartToTileInDistances) + currentTile.distancesToSurroundingTiles[direction] < addUpArray(tileToModify.stepsStartToTileInDistances) or tileToModify.stepsStartToTileInDistances.size() == 0:
# print("Shorter Path found.")
var newShortestPath = currentTile.duplicate().vertices.duplicate()
var newnewShortestPath = newShortestPath.append(currentTile.duplicate().verticeDistance.duplicate()[direction])
tileToModify.vertices = newShortestPath.duplicate()
var newShortestRoute = currentTile.duplicate().route.duplicate()
var newShortestPath = currentTile.duplicate().stepsStartToTileInDistances.duplicate()
var newnewShortestPath = newShortestPath.append(currentTile.duplicate().distancesToSurroundingTiles.duplicate()[direction])
tileToModify.stepsStartToTileInDistances = newShortestPath.duplicate()
var newShortestRoute = currentTile.duplicate().stepsStartToTileInCoords.duplicate()
var newnewShortestRoute = newShortestRoute.append(tileToModify.coords) #this is really bodged but i dont know how to fix it and it somehow works fine despite everything
tileToModify.route = newShortestRoute
tileToModify.stepsStartToTileInCoords = newShortestRoute
direction += 1
superTiles[currentTile.coords.x][currentTile.coords.y]= currentTile
currentTile.verticeExplored = true
currentTile.surroundingTilesExplored = true
a.append(1)
func hoverSuperPath(coord = hoveredCoords):
@ -361,20 +345,103 @@ func hoverSuperPath(coord = hoveredCoords):
$TileMap/LineManager.drawAdvancedSuperLine(path[0], path[1], selectedUnit.ap, selectedUnit.moveAp)
func clickSuperPath():
if animationInProgress == false and route.size() >1:
if animationInProgress == false and stepsStartToTileInCoords.size() >1:
var totalApCost = addUpArray(routeVertices)
if totalApCost > selectedUnit.moveAp:
var apDebt = totalApCost - selectedUnit.moveAp
if apDebt > selectedUnit.ap:
# print("Not enough AP for this move.")
while addUpArray(routeVertices) > selectedUnit.ap + selectedUnit.moveAp:
route.pop_back()
stepsStartToTileInCoords.pop_back()
routeVertices.pop_back()
while route.size() != 0 and (occupiedTiles.has(route[-1]) == true or occupiedTiles.has(route[-1]+Vector2(1,0)) == true or occupiedTiles.has(route[-1]+Vector2(0,1)) == true or occupiedTiles.has(route[-1]+Vector2(1,1)) == true):#prevents overlap
route.pop_back()
while stepsStartToTileInCoords.size() != 0 and (occupiedTiles.has(stepsStartToTileInCoords[-1]) == true or occupiedTiles.has(stepsStartToTileInCoords[-1]+Vector2(1,0)) == true or occupiedTiles.has(stepsStartToTileInCoords[-1]+Vector2(0,1)) == true or occupiedTiles.has(stepsStartToTileInCoords[-1]+Vector2(1,1)) == true):#prevents overlap
stepsStartToTileInCoords.pop_back()
routeVertices.pop_back()
if route.size() != 0 and route[0] != route[-1]:
if stepsStartToTileInCoords.size() != 0 and stepsStartToTileInCoords[0] != stepsStartToTileInCoords[-1]:
totalApCost = addUpArray(routeVertices)
apDebt = totalApCost - selectedUnit.moveAp
if route.size() > 1:
executePath(route, routeVertices)
if stepsStartToTileInCoords.size() > 1:
executePath(stepsStartToTileInCoords, routeVertices)
func findPathFromCoordToCoord(coord1, coord2, tiles):
var startingTile = tiles[coord1.x][coord1.y]
var endTile = tiles[coord2.x][coord2.y]
startingTile.stepsStartToTileInDistances = [0, ]
for columns in tiles:
for tile in columns:
tile.stepsStartToTileInCoords = [startingTile.coords,]
var shortestPathDistance #smallestVerticeDistance
var shortestPathFound = false
while !shortestPathFound:
var currentTile = null #The unexplored Tile with the shortest Path
#Selects next currentTile / Tile with shortest path to it
for columns in tiles:
for tile in columns:
if tile.surroundingTilesExplored == false and tile.stepsStartToTileInDistances.size() > 0:
if addUpArray(tile.stepsStartToTileInDistances) < shortestPathDistance:
shortestPathDistance = addUpArray(tile.stepsStartToTileInDistances)
currentTile = tile
#Checks whether the search is completed
if currentTile == endTile:
stepsStartToTileInCoords=endTile.stepsStartToTileInCoords
routeVertices=endTile.stepsStartToTileInDistances
shortestPathFound = true
return[endTile.stepsStartToTileInCoords, endTile.stepsStartToTileInDistances]
#Explore surrounding Tiles. Add the path taken to reach them via the current Tile if it is the shortest current path or the first.
var translation = null
var direction = 0
for entry in currentTile.distancesToSurroundingTiles:
match direction:
0:
if entry != INF:
translation = Vector2(0,1)
1:
if entry != INF:
translation = Vector2(1,1)
2:
if entry != INF:
translation = Vector2(1,0)
3:
if entry != INF:
translation = Vector2(1,-1)
4:
if entry != INF:
translation = Vector2(0,-1)
5:
if entry != INF:
translation = Vector2(-1,-1)
6:
if entry != INF:
translation = Vector2(-1,0)
7:
if entry != INF:
translation = Vector2(-1,1)
if translation != null:
var surroundingTile = tiles[(currentTile.coords + translation).x][(currentTile.coords + translation).y]
if (addUpArray(currentTile.stepsStartToTileInDistances) + currentTile.distancesToSurroundingTiles[direction]) < addUpArray(surroundingTile.stepsStartToTileInDistances):
pass
surroundingTile.stepsStartToTileInDistances.append()
surroundingTile.stepsStartToTileInCoords.append()
if addUpArray(currentTile.stepsStartToTileInDistances) + currentTile.distancesToSurroundingTiles[direction] < addUpArray(surroundingTile.stepsStartToTileInDistances) or surroundingTile.stepsStartToTileInDistances.size() == 0:
var newShortestPath = currentTile.duplicate().stepsStartToTileInDistances.duplicate()
var newnewShortestPath = newShortestPath.append(currentTile.duplicate().distancesToSurroundingTiles.duplicate()[direction])
surroundingTile.stepsStartToTileInDistances = newShortestPath.duplicate()
var newShortestRoute = currentTile.duplicate().stepsStartToTileInCoords.duplicate()
var newnewShortestRoute = newShortestRoute.append(surroundingTile.coords) #this is really bodged but i dont know how to fix it and it somehow works fine despite everything
surroundingTile.stepsStartToTileInCoords = newShortestRoute
direction += 1
currentTile.surroundingTilesExplored = true
return

12
Client/region/SuperUnit.gd

@ -3,14 +3,12 @@ extends Sprite
signal positionReached
var Route
signal pathAnimationCompleted
signal unitSelected(unit)
var isSelected = false
var isMoving = false
var boardUnitsIndex
onready var region = get_parent().get_parent().get_parent()
func on_ready():#this connects the unit to the main node using signals
connect("unitSelected",region, "unitSelectedMethod")
connect("pathAnimationCompleted",region, "_on_pathAnimationCompleted")
snapToPosition()
if region.boardUnits[boardUnitsIndex].faction == "enemyFaction":
@ -29,16 +27,6 @@ func snapToPosition():
# unitCurrentUndertiles = undertiles
pass
func _input(event):#this selects unit and signals the selected node to the main node
if event is InputEventMouseButton and Input.is_action_pressed("ui_right_mouse_button")and isMoving==false:
var localEvent = (self.make_input_local(event))
if isSelected== true:
# emit_signal("unitSelected",null,self)
isSelected = false
elif localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < 64 and localEvent.position.y < 64:
emit_signal("unitSelected",self,self)
isSelected = true
func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true
var indexPosition = 0

12
Client/region/Unit.gd

@ -3,14 +3,12 @@ extends Sprite
signal positionReached
var Route
signal pathAnimationCompleted
signal unitSelected(unit)
var isSelected = false
var isMoving = false
var boardUnitsIndex
onready var region = get_parent().get_parent().get_parent()
func on_ready():#this connects the unit to the main node using signals
connect("unitSelected",region, "unitSelectedMethod")
connect("pathAnimationCompleted",region, "_on_pathAnimationCompleted")
snapToPosition()
if region.boardUnits[boardUnitsIndex].faction == "enemyFaction":
@ -22,16 +20,6 @@ func on_ready():#this connects the unit to the main node using signals
func snapToPosition():
self.position = get_parent().get_parent().map_to_world(region.boardUnits[boardUnitsIndex].coords)
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))
if isSelected == true:
# emit_signal("unitSelected",null,self) Problem here ist das weil signale asynchron sind es mehrere units gibt die meinen is Selected wäre true und dan je nach layer der units, eine das selectunit(null) signal schickt, nachdem die anderen ihr selectunit(self) signal schickt und so null selektiert wird. Lösungen: Call statt Signal. Deselect funktion funktion in der diesem Script selbst ausführen.
isSelected = false
elif localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < 64 and localEvent.position.y < 64:
emit_signal("unitSelected",self,self)
isSelected = true
func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true
var indexPosition = 0

BIN
Server/new_script.vs

14
Server/region/Region.gd

@ -4,7 +4,7 @@ var tiles = []
var superTiles=[]
var tileRect = Vector2(10,11)
var tileRect = Vector2(10,51)
var boardUnits = [
{
@ -80,11 +80,11 @@ func buildTiles(x,y):#this creates the tiles array and adds all the tile-diction
type = "mountain"
var currentTile = {
"coords":null,
"vertices":[],
"verticeExplored":false,
"verticeDistance":[INF,INF,INF,INF,INF,INF,INF,INF],
"stepsStartToTileInDistances":[], #vertices
"surroundingTilesExplored":false, #verticeExplored
"distancesToSurroundingTiles":[INF,INF,INF,INF,INF,INF,INF,INF], #verticeDistance
"type":"grass",
"route":[]
"stepsStartToTileInCoords":[] #route
}
currentTile.type = type
currentTile.coords = Vector2(currentX,currentY)
@ -292,9 +292,6 @@ func moveUnit(path,unitID):
for boardUnit in boardUnits:
if boardUnit.id == unit.id:
boardUnit.coords = unit.coords
# print(path," NEXT ",unit.coords)
# return [path, apCost]
# return validated path and ap and then execute it
func getUnitById(unitId):
for unit in boardUnits:
@ -336,7 +333,6 @@ func addEnemyOccupiedTilesToMap(enemyOccupiedTiles):#this creates the tiles arra
mapTiles[tile.x][tile.y].type = "enemyOccupied"
return mapTiles
func requestTiles(unit):
var newTiles = setVertices(addEnemyOccupiedTilesToMap(getOccupiedTiles(unit)[1]))
var newSuperTiles = buildSuperTiles(setVertices(addEnemyOccupiedTilesToMap(getOccupiedTiles(unit)[1])))

Loading…
Cancel
Save