Compare commits

...

3 Commits

46 changed files with 1427 additions and 258 deletions

View File

@ -0,0 +1,3 @@
source_md5="a47db4bc7df31e2470e9663216138fec"
dest_md5="ff372a0a033369ebd292e33a30b28788"

View File

@ -0,0 +1,3 @@
source_md5="60fad784db3412e499a61e159fb0ab54"
dest_md5="8f21de330736bfda6b5c832cb18acbb8"

View File

@ -0,0 +1,3 @@
source_md5="a72e8867108b6ac04fc080a52599b278"
dest_md5="16e818811c57f4954b8f804f2b6a4bd4"

View File

@ -0,0 +1,3 @@
source_md5="97cea05c45971cc8ae3f0dbb70b26d39"
dest_md5="e9948a9e9f2c54d77ffbc60b4cf29da7"

View File

@ -0,0 +1,3 @@
source_md5="4649619802d7e43bcb178d0ca22d8f87"
dest_md5="7afddab8fa81674668efb848afc5a75e"

View File

@ -0,0 +1,3 @@
source_md5="f2f86a04a5e4e9f760d7a35d7a636bd9"
dest_md5="93f1454ca0c6306e7a64849450c73751"

View File

@ -0,0 +1,3 @@
source_md5="e9ff5f579208eb30fd1830c6d95b8da7"
dest_md5="b04a777d7a1923a84af05ebf47a14ddf"

View File

@ -41,9 +41,9 @@ func _ready():
func _process(delta):
#smooth movement
var inpx = (int(Input.is_action_pressed("ui_right"))
- int(Input.is_action_pressed("ui_left")))
- int(Input.is_action_pressed("ui_left")))
var inpy = (int(Input.is_action_pressed("ui_down"))
- int(Input.is_action_pressed("ui_up")))
- int(Input.is_action_pressed("ui_up")))
self.position.x = lerp(position.x, position.x + inpx *speed,speed * delta)
self.position.y = lerp(position.y, position.y + inpy *speed,speed * delta)
if Input.is_key_pressed(KEY_CONTROL):

View File

@ -18,8 +18,9 @@ signal server_disconnected
func _ready():
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
get_tree().connect('network_peer_connected', self, '_on_player_connected')
connect_to_server("name","","")
yield(get_tree().create_timer(1),"timeout")
rpc_id(1, 'TESTFUNCTION', "TEST TEST TEST")
func connect_to_server(playerName,pw,serverpassword):
self.serverpassword = serverpassword
@ -33,7 +34,6 @@ func connect_to_server(playerName,pw,serverpassword):
# PlayerManager.authcache['password']=pw
# PlayerManager.authcache['playername']=playerName
func _connected_to_server():
var local_player_id = get_tree().get_network_unique_id()
players[local_player_id] = self_data
@ -44,7 +44,6 @@ func _connected_to_server():
rpc_id(1, '_request_auth', local_player_id, self_data)# anstatt playerName und pw -> self_data
rpc('_send_player_info', local_player_id, self_data) # requests all player in the current session
func _on_player_disconnected(id):
players.erase(id)
PlayerManager.player_disconnected(id)

View File

@ -225,3 +225,29 @@ func setPresent(tile):
func _load_worldmap():
get_tree().change_scene('res://Worldmap.tscn')
func requestTiles(unit = null):
print("a")
rpc_id(1, 'requestTiles', unit)
signal receiveTiles
remote func receiveTiles(bundledTileStuff):
var newTileRect = bundledTileStuff[0]
var newTiles = bundledTileStuff[1]
var newSuperTiles = bundledTileStuff[2]
emit_signal("receiveTiles", newTileRect, newTiles, newSuperTiles)
func requestUnits():
rpc_id(1, 'requestUnits')
signal receiveUnits
remote func receiveUnits(newBoardUnits):
emit_signal("receiveUnits", newBoardUnits)

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Leerzeichen.bmp-0e69595e5ec48ab400945277c9828255.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://font/Leerzeichen.bmp"
dest_files=[ "res://.import/Leerzeichen.bmp-0e69595e5ec48ab400945277c9828255.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -0,0 +1,102 @@
extends Node2D
var red = Color( 1, 0, 0, 1 )
var yellow = Color( 1, 1, 0, 1 )
var blue = Color( 0, 1, 1, 1 )
var route1 = []#blue line
var route2 = []#yellow line
var route3 = []#redline
var vertices1 = []#blue line
var vertices2 = []#yellow line
var vertices3 = []#redline
func _ready():#this sets colors to the different lines
$Line1.default_color = blue
$Line2.default_color = yellow
$Line3.default_color = red
func drawAdvancedLine(route, vertices, unitAp, unitMoveAp):#this creates the seperate lines and draws them
route1 = []
route2 = []
route3 = []
vertices1 = []
vertices2 = []
vertices3 = []
#blue
route1 = route.duplicate()
vertices1 = vertices.duplicate()
while addUpArray(vertices1) > unitMoveAp:
route1.pop_back()
vertices1.pop_back()
#yellow
route2 = route.duplicate()
vertices2 = vertices.duplicate()
while addUpArray(vertices2) > unitMoveAp+unitAp:
route2.pop_back()
vertices2.pop_back()
#red
route3 = route.duplicate()
vertices3 = vertices.duplicate()
subtractPaths(route3, route2)
subtractPaths(route2, route1)
$Line1.points = convertMapRouteToWorldRoute(route1)
$Line2.points = convertMapRouteToWorldRoute(route2)
$Line3.points = convertMapRouteToWorldRoute(route3)
func addUpArray(array):#this adds up each int in an array. useful for calculating total distance.
var total = 0
for number in array:
total += number
return(total)
func convertMapRouteToWorldRoute(route):#this uses the map_to_world function on each coord of a route
var returnRoute = []
for point in route:
returnRoute.append(get_parent().map_to_world(point)+Vector2(32,32))
return(returnRoute)
func subtractPaths(path1, path2):#this produces a path1 that only overlaps path2 in their first coord. Or something.
var lastDuplicateValue
for value in path2:
path1.erase(value)
lastDuplicateValue = value
if lastDuplicateValue != null:
path1.push_front(lastDuplicateValue)
return path1
func drawAdvancedSuperLine(route, vertices, unitAp, unitMoveAp):#this creates the seperate lines and draws them
route1 = []
route2 = []
route3 = []
vertices1 = []
vertices2 = []
vertices3 = []
#blue
route1 = route.duplicate()
vertices1 = vertices.duplicate()
while addUpArray(vertices1) > unitMoveAp:
route1.pop_back()
vertices1.pop_back()
#yellow
route2 = route.duplicate()
vertices2 = vertices.duplicate()
while addUpArray(vertices2) > unitMoveAp+unitAp:
route2.pop_back()
vertices2.pop_back()
#red
route3 = route.duplicate()
vertices3 = vertices.duplicate()
subtractPaths(route3, route2)
subtractPaths(route2, route1)
$Line1.points = convertSuperMapRouteToWorldRoute(route1)
$Line2.points = convertSuperMapRouteToWorldRoute(route2)
$Line3.points = convertSuperMapRouteToWorldRoute(route3)
func convertSuperMapRouteToWorldRoute(route):#this uses the map_to_world function on each coord of a route
var returnRoute = []
for point in route:
returnRoute.append(get_parent().map_to_world(point)+Vector2(64,64))
return(returnRoute)

View File

@ -1,18 +1,384 @@
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var ownedBy = ""
var tiles = []
var superTiles=[]
var tileRect = Vector2(7,7)
var animationInProgress = false
var selectedNode
var selectedUnit
var selectedFaction
var boardUnits ={}
var occupiedTiles=[]
var enemyOccupiedTiles=[]
var route
var routeVertices
var hoveredCoords
func _ready():#this mostly just builds a bunch of stuff
WorldManager.connect("receiveTiles", self, "receiveTiles")
WorldManager.connect("receiveUnits", self, "receiveUnits")
yield(get_tree().create_timer(1), "timeout")
buildWorld()
func buildWorld():
requestTiles()
requestUnits()
func requestTiles(unit = null):
WorldManager.requestTiles(unit)
func receiveTiles(newTileRect, newTiles, newSuperTiles):
tileRect = newTileRect
tiles = newTiles
superTiles = newSuperTiles
$TileMap.buildTileMap(tiles)
func requestUnits():
WorldManager.requestUnits()
func receiveUnits(newBoardUnits):
boardUnits = newBoardUnits
for child in $TileMap/Units.get_children():
child.queue_free()
var boardUnitsIndex = 0
for unit in boardUnits:
var newUnit
if unit.superUnit:
newUnit = (load("res://region/SuperUnit.tscn")).instance()
else:
newUnit = (load("res://region/Unit.tscn")).instance()
newUnit.boardUnitsIndex = boardUnitsIndex
$TileMap/Units.add_child(newUnit)
newUnit.on_ready()
boardUnitsIndex +=1
func unitSelectedMethod(unit):#this is called when a unit is selected
if unit == null:
clearPathingInfo()
$moveapcost.text = ""
$unitapcounter.text = ""
selectedFaction = null
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)
# getOccupiedTiles(selectedUnit)
func _input(event):#this responds to any input. Has various functions depending on input
# print("region ",boardUnits)
# print("server ",server.boardUnits)
if selectedUnit != null:
if event is InputEventMouseButton and Input.is_action_just_released("ui_left_mouse_button"):
if !selectedUnit.superUnit:
clickPath()
else:
clickSuperPath()
if event is InputEventMouseMotion:
if true:
hoveredCoords = (self.make_input_local(event)).position
if !selectedUnit.superUnit:
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:
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()
routeVertices.pop_back()
while route.size() != 0 and occupiedTiles.has(route[-1]):#prevents overlap
route.pop_back()
routeVertices.pop_back()
if route.size() > 1:
executePath(route, 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:
coord = $TileMap.world_to_map(hoveredCoords)
coord.x=clamp(coord.x,0,tileRect.x-1)
coord.y=clamp(coord.y,0,tileRect.y-1)
if animationInProgress == false:# and occupiedTiles.has(coord) == false: #might be buggy
clearPathingInfo()
$unitapcounter.text = str("Unit Faction: ", selectedUnit.faction ,"\n Total AP: ", selectedUnit.moveAp + selectedUnit.ap, "\nUnit Movement AP: ", selectedUnit.moveAp, " Unit Universal AP: ", selectedUnit.ap)
if occupiedTiles.has(coord) == false:
var path=findPath(selectedUnit.coords,coord)
if path != null :#and selectedUnit.unitCurrentPosition != path[0][-1]: #might be buggy
$moveapcost.text = str("AP Cost: ",addUpArray(path[1]))
$TileMap.get_node("LineManager").drawAdvancedLine(path[0], routeVertices, selectedUnit.ap, selectedUnit.moveAp)
func nextRound():#this sends a nextRound signal to units on the board and refreshes their ap.
resetPathing()
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)
var convertedRoute = []
for coords in route:
convertedRoute.append($TileMap.map_to_world(coords))
selectedNode.moveOnPath(convertedRoute)
animationInProgress = true
clearPathingInfo()
# Called when the node enters the scene tree for the first time.
func _ready():
PlayerManager.subMenuOpen = false
print(DataManager.selectedTile)
pass # Replace with function body.
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.shortestKnownPath = INF
tile.vertices = []
for column in superTiles:
for tile in column:
tile.verticeExplored = false
tile.route = []
tile.shortestKnownPath = INF
tile.vertices = []
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# 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
"road":
origin.verticeDistance[index] = 2
"mountain":
origin.verticeDistance[index] = INF
"enemyOccupied":
origin.verticeDistance[index] = INF
else:
match target.type:
"grass":
origin.verticeDistance[index] = 8
"road":
origin.verticeDistance[index] = 3
"mountain":
origin.verticeDistance[index] = INF
"enemyOccupied":
origin.verticeDistance[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).
var startingTile = tiles[start.x][start.y]
var endTile = tiles[end.x][end.y]
startingTile.vertices = [0]
var smallestVerticeDistance
var a = [1]
for number in a:
var currentTile = null #Unerkundedte Tile mit dem kurzesten Weg finden. Ohne jegliche Erkundung sollte es die Starting Tile sein
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")
break
if tile.verticeExplored == false and tile.vertices.size() > 0:
smallestVerticeDistance = addUpArray(smallestVertice)
var tileTotalVertice = 0
tileTotalVertice = addUpArray(tile.vertices)
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
if currentTile == null:
animationInProgress = false
break
if currentTile == endTile:
route=endTile.route
routeVertices=endTile.vertices
return[endTile.route, endTile.vertices]
var translation = null
var direction = 0
for entry in currentTile.verticeDistance:
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 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:
# 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 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
direction += 1
tiles[currentTile.coords.x][currentTile.coords.y]= currentTile
currentTile.verticeExplored = true
a.append(1)
func addUpArray(array):#adds up each int in an array. useful for calculating total distance.
var total = 0
for number in array:
total += number
return(total)
func _on_pathAnimationCompleted():#this gets a signal from the selected unit and tells the program that the movement is over by setting animationInProgress to false. starting an animation for example requires this to be false (so no two can be started at once).
requestTiles()
requestUnits()
resetPathing()
print(boardUnits)
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 = []
routeVertices = []
if selectedUnit != null:
$TileMap/LineManager.drawAdvancedLine(route, routeVertices, selectedUnit.ap, selectedUnit.moveAp)
else:
$TileMap/LineManager.drawAdvancedLine(route, routeVertices, 0, 0)
func findSuperPath(start,end):
var startingTile = superTiles[start.x][start.y]
var endTile = superTiles[end.x][end.y]
startingTile.vertices = [0]
var smallestVerticeDistance
var a = [1]
for number in a:
var currentTile = null #Unerkundedte Tile mit dem kurzesten Weg finden. Ohne jegliche Erkundung sollte es die Starting Tile sein
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")
break
if tile.verticeExplored == false and tile.vertices.size() > 0:
smallestVerticeDistance = addUpArray(smallestVertice)
var tileTotalVertice = 0
tileTotalVertice = addUpArray(tile.vertices)
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
if currentTile == null:
animationInProgress = false
break
if currentTile == endTile:
route=endTile.route
routeVertices=endTile.vertices
return[endTile.route, endTile.vertices]
var translation = null
var direction = 0
for entry in currentTile.verticeDistance:
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 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:
# 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 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
direction += 1
superTiles[currentTile.coords.x][currentTile.coords.y]= currentTile
currentTile.verticeExplored = true
a.append(1)
func hoverSuperPath(coord = hoveredCoords):
coord = $TileMap.world_to_map(hoveredCoords+Vector2(-32,-32))
coord.x=clamp(coord.x,0,tileRect.x-2)
coord.y=clamp(coord.y,0,tileRect.y-2)
if animationInProgress == false:# and occupiedTiles.has(coord) == false: #might be buggy
clearPathingInfo()
$unitapcounter.text = str("Unit Faction: ", selectedUnit.faction ,"\n Total AP: ", selectedUnit.moveAp + selectedUnit.ap, "\nUnit Movement AP: ", selectedUnit.moveAp, " Unit Universal AP: ", selectedUnit.ap)
if occupiedTiles.has(coord) == false and occupiedTiles.has(coord+Vector2(1,0)) == false and occupiedTiles.has(coord+Vector2(0,1)) == false and occupiedTiles.has(coord+Vector2(1,1)) == false:
var path=findSuperPath(selectedUnit.coords,coord)
if path != null :#and selectedUnit.unitCurrentPosition != path[0][-1]: #might be buggy
$moveapcost.text = str("AP Cost: ",addUpArray(path[1]))
$TileMap/LineManager.drawAdvancedSuperLine(path[0], path[1], selectedUnit.ap, selectedUnit.moveAp)
func clickSuperPath():
if animationInProgress == false and route.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()
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()
routeVertices.pop_back()
if route.size() != 0 and route[0] != route[-1]:
totalApCost = addUpArray(routeVertices)
apDebt = totalApCost - selectedUnit.moveAp
if route.size() > 1:
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)
var convertedRoute = []
for coords in route:
convertedRoute.append($TileMap.map_to_world(coords))
selectedNode.moveOnPath(convertedRoute)
animationInProgress = true
clearPathingInfo()

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,49 @@
[gd_resource type="TileSet" load_steps=4 format=2]
[ext_resource path="res://region/Unbenannt - Kopie - Kopie - Kopie - Kopie.png" type="Texture" id=1]
[ext_resource path="res://region/Unbenannt.png" type="Texture" id=2]
[ext_resource path="res://region/Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png" type="Texture" id=3]
[resource]
0/name = "Unbenannt.png 0"
0/texture = ExtResource( 2 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 64, 64 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape_one_way = false
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
4/name = "Unbenannt - Kopie - Kopie - Kopie - Kopie.png 4"
4/texture = ExtResource( 1 )
4/tex_offset = Vector2( 0, 0 )
4/modulate = Color( 1, 1, 1, 1 )
4/region = Rect2( 0, 0, 64, 64 )
4/tile_mode = 0
4/occluder_offset = Vector2( 0, 0 )
4/navigation_offset = Vector2( 0, 0 )
4/shape_offset = Vector2( 0, 0 )
4/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
4/shape_one_way = false
4/shape_one_way_margin = 0.0
4/shapes = [ ]
4/z_index = 0
5/name = "Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png 5"
5/texture = ExtResource( 3 )
5/tex_offset = Vector2( 0, 0 )
5/modulate = Color( 1, 1, 1, 1 )
5/region = Rect2( 0, 0, 64, 64 )
5/tile_mode = 0
5/occluder_offset = Vector2( 0, 0 )
5/navigation_offset = Vector2( 0, 0 )
5/shape_offset = Vector2( 0, 0 )
5/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
5/shape_one_way = false
5/shape_one_way_margin = 0.0
5/shapes = [ ]
5/z_index = 0

View File

@ -0,0 +1,75 @@
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":
modulate = Color(1,0,0,1)
if region.boardUnits[boardUnitsIndex].faction == "allyFaction":
modulate = Color(0,1,0,1)
# emit_signal("pathAnimationCompleted")
func snapToPosition():
self.position = get_parent().get_parent().map_to_world(region.boardUnits[boardUnitsIndex].coords)
var undertiles = []
undertiles.append(Vector2(region.boardUnits[boardUnitsIndex].coords.x,region.boardUnits[boardUnitsIndex].coords.y))
undertiles.append(Vector2(region.boardUnits[boardUnitsIndex].coords.x,region.boardUnits[boardUnitsIndex].coords.y+1))
undertiles.append(Vector2(region.boardUnits[boardUnitsIndex].coords.x+1,region.boardUnits[boardUnitsIndex].coords.y))
undertiles.append(Vector2(region.boardUnits[boardUnitsIndex].coords.x+1,region.boardUnits[boardUnitsIndex].coords.y+1))
# 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_just_released("ui_right_mouse_button")and isMoving==false:
var localEvent = (self.make_input_local(event))
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 isSelected== false:
emit_signal("unitSelected",self)
isSelected = true
return
func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true
var indexPosition = 0
for coords in route:
if route[0] == coords:
var t = Transform2D()
t.origin = coords
else:
moveTo(route[indexPosition],coords)
yield(self,"positionReached")
indexPosition+=1
emit_signal("pathAnimationCompleted")
isMoving = false
var speed =4
onready var motion = Vector2(0,0)
func moveTo(start:Vector2, destination:Vector2):#this does a step of the movement/animation. coordinated by moveOnPath
var travel = destination-start
motion = travel*speed
yield(get_tree().create_timer(travel.length()/motion.length()), "timeout")
motion= Vector2(0,0)
var t = Transform2D()
t.origin = destination
transform = t
emit_signal("positionReached")
# unitCurrentPosition=GlobalTileMap.world_to_map(destination)
snapToPosition()
func _physics_process(delta):
position += motion*delta

View File

@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://region/SuperUnit.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[node name="Sprite" type="Sprite"]
scale = Vector2( 2, 2 )
z_index = 1
z_as_relative = false
texture = ExtResource( 2 )
centered = false
script = ExtResource( 1 )

22
Client/region/TileMap.gd Normal file
View File

@ -0,0 +1,22 @@
extends TileMap
var mountainTiles = []
var roadTiles = []
func buildTileMap(tiles):#this builds the tilemap by looking up on the special tile arrays whether a tile belongs to a special category (road/mountain etc) if not the tile is grass
var x=0
for column in tiles:
var y=0
for tile in column:
if tile.type == "mountain":
set_cell(x,y,4)
elif tile.type == "road":
set_cell(x,y,5)
else:
set_cell(x, y, 0)
y += 1
x += 1
func setTerrain():#this sets the special tile arrays to what is placed on the tilemap
roadTiles= get_used_cells_by_id(5)
mountainTiles = get_used_cells_by_id(4)
pass

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png-25669cdb99469b4149cec015f84e52b1.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png-25669cdb99469b4149cec015f84e52b1.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie - Kopie - Kopie - Kopie.png-9720aced28368a22298ccaf2a68942cc.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie - Kopie - Kopie - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie - Kopie - Kopie - Kopie.png-9720aced28368a22298ccaf2a68942cc.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie - Kopie - Kopie.png-87c11b1469a9d84d4f76a51d1203572a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie - Kopie - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie - Kopie - Kopie.png-87c11b1469a9d84d4f76a51d1203572a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie - Kopie.png-efca2ee418235964b71d2c06816282db.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie - Kopie.png-efca2ee418235964b71d2c06816282db.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie.png-039fc52b1d6966267896d4c3bf84548a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie.png-039fc52b1d6966267896d4c3bf84548a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
Client/region/Unbenannt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt.png-33f6792a5bb8046827aa692c8732e313.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt.png"
dest_files=[ "res://.import/Unbenannt.png-33f6792a5bb8046827aa692c8732e313.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

64
Client/region/Unit.gd Normal file
View File

@ -0,0 +1,64 @@
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":
modulate = Color(1,0,0,1)
if region.boardUnits[boardUnitsIndex].faction == "allyFaction":
modulate = Color(0,1,0,1)
# emit_signal("pathAnimationCompleted")
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)
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:
emit_signal("unitSelected",self)
isSelected = true
return
func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true
var indexPosition = 0
for coords in route:
if route[0] == coords:
var t = Transform2D()
t.origin = coords
else:
moveTo(route[indexPosition],coords)
yield(self,"positionReached")
indexPosition+=1
emit_signal("pathAnimationCompleted")
isMoving = false
snapToPosition()
var speed =4
onready var motion = Vector2(0,0)
func moveTo(start:Vector2, destination:Vector2):#this does a step of the movement/animation. coordinated by moveOnPath
var travel = destination-start
motion = travel*speed
yield(get_tree().create_timer(travel.length()/motion.length()), "timeout")
motion= Vector2(0,0)
position = destination
emit_signal("positionReached")
func _physics_process(delta):
# print(position)
position += motion*delta

11
Client/region/Unit.tscn Normal file
View File

@ -0,0 +1,11 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://region/Unit.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[node name="Unit" type="Sprite"]
z_index = 1
z_as_relative = false
texture = ExtResource( 2 )
centered = false
script = ExtResource( 1 )

View File

@ -16,6 +16,10 @@ signal server_disconnected
func _ready():
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
get_tree().connect('network_peer_connected', self, '_on_player_connected')
create_server()
remote func TESTFUNCTION(string):
print(string)
remote func checkServerPassword(serverPassword):
if (serverPassword=="myPW"):
@ -54,8 +58,9 @@ func firstStart():
# file.close()
func _on_player_disconnected(id):
players.erase(id)
PlayerManager.player_disconnected(id)
pass
# players.erase(id)
# PlayerManager.player_disconnected(id)
func _on_player_connected(connected_player_id):
print(">>>>>>>>>>> on player connected <<<<<<<<<<<<< ", connected_player_id)

View File

@ -129,8 +129,9 @@ func identifyPlayer(playerName, pw = ''): # get the data from the json file
func player_disconnected(id):
if clients_factions[id]:
clients_factions.erase(id)
pass
# if clients_factions[id]:
# clients_factions.erase(id)
remote func receiveAuth(response):

View File

@ -199,3 +199,20 @@ remote func settle(tile, army, ascending): #if ascending, the cheapest ressource
var finish = buildingtime / 1.5 + ['turn']
else:
var finish = buildingtime + ['turn']
var regions = {}
func _ready():
var newRegion = load("res://region/Region.gd").new()
newRegion.buildWorld()
regions[123] = newRegion
remote func requestTiles(unit,regionId = 123):
var clientId = get_tree().get_rpc_sender_id()
var tileStuff = regions[regionId].requestTiles(unit)
rpc_id(clientId, 'receiveTiles', tileStuff)
remote func requestUnits(regionId = 123):
var clientId = get_tree().get_rpc_sender_id()
var boardUnits = regions[regionId].requestUnits()
rpc_id(clientId, 'receiveUnits', boardUnits)

View File

@ -26,9 +26,6 @@ margin_top = -2.96259
margin_right = 1919.0
margin_bottom = 1021.04
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="VBoxContainer"]
margin_top = 203.0

View File

@ -1,35 +1,346 @@
extends Node2D
var inventory = {}
var tiles = []
# Called when the node enters the scene tree for the first time.
func _ready():
PlayerManager.subMenuOpen = false
pass # Replace with function body.
var superTiles=[]
func Buildings(tile, army):
# if region.faction == army.faction or worldtile != buildings(): #RegionOwner or worldtile == leer?
# if setPresent() == true:
return
var tileRect = Vector2(10,11)
func mine(tile, army):
if Buildings(tile, army) == true:
if army.inventory.eschenwood() >= 30 or army.inventory.xp() >= 200: #inventory not properly defined yet, might need change
# var minekoordinate = Player.Tile #Player.Tile = Aktuelles Feld auf dem der Spieler sein soll.
# minekoordinate = earth.Tile #Building Sprite Tile
var buildingtime = 5
var finish = buildingtime + ['turn'] #finish = Gebäude fertig
if finish == ['turn']:
preload("res://region/MineSmall.tscn").instance()
var boardUnits = [
{
"coords":Vector2(0,4),
"faction":"playerFaction",
"superUnit":false,
"type":"default",
"id":14231,
"maxMoveAp": 10,
"maxAp": 10,
"moveAp": 10,
"ap": 10,
},
{
"coords":Vector2(6,4),
"faction":"playerFaction",
"superUnit":true,
"type":"default",
"id":14232,
"maxMoveAp": 10,
"maxAp": 10,
"moveAp": 10,
"ap": 10,
},
{
"coords":Vector2(0,2),
"faction":"enemyFaction",
"superUnit":false,
"type":"default",
"id":14233,
"maxMoveAp": 10,
"maxAp": 10,
"moveAp": 10,
"ap": 10,
},
]
func _ready():#this mostly just builds a bunch of stuff
buildWorld()
func buildWorld():
tiles = buildTiles(tileRect.x,tileRect.y)
superTiles = buildSuperTiles(tiles)
func nextRound():#this sends a nextRound signal to units on the board and refreshes their ap.
for unit in boardUnits:
unit.moveAp = unit.maxMoveAp
unit.ap = unit.maxAp
func buildTiles(x,y):#this creates the tiles array and adds all the tile-dictionaries. Also sets ground-type.
var tilesToReturn = []
var currentX = 0
var currentY = 0
var roadTiles = [] #client.get_node("TileMap").roadTiles
roadTiles.append(Vector2(2,4))
roadTiles.append(Vector2(1,4))
roadTiles.append(Vector2(3,4))
roadTiles.append(Vector2(4,4))
var mountainTiles = []
mountainTiles.append(Vector2(2,3))
mountainTiles.append(Vector2(1,3))
mountainTiles.append(Vector2(3,3))
mountainTiles.append(Vector2(4,3))
var type = "grass"
for i in x:
var column = []
currentY = 0
for z in y:
type = "grass"
if roadTiles.has(Vector2(currentX,currentY)):
type = "road"
if mountainTiles.has(Vector2(currentX,currentY)):
type = "mountain"
var currentTile = {
"coords":null,
"vertices":[],
"verticeExplored":false,
"verticeDistance":[INF,INF,INF,INF,INF,INF,INF,INF],
"type":"grass",
"route":[]
}
currentTile.type = type
currentTile.coords = Vector2(currentX,currentY)
column.append(currentTile.duplicate())
currentY += 1
tilesToReturn.append(column)
currentX += 1
return setVertices(tilesToReturn)
func setVertices(templateTiles):#this finds the connection a tile has to other tiles. name is bad.
var tileToAdapt
var x = 0
for row in templateTiles:
var y = 0
for line in row:
tileToAdapt = templateTiles[x][y]
# print("\n")
# print("x:",x, " y:",y)
if templateTiles.size() > x+1:
if x ==0 and y == 2:
pass
if templateTiles[x].size() > (y+1):
setDistance(templateTiles[x][y+1], tileToAdapt, 0, false)
if templateTiles[x].size() > (x+1) and templateTiles[x+1].size() > (y+1):#returns null sometimes??
setDistance(templateTiles[x+1][y+1], tileToAdapt, 1, true)
if templateTiles.size() > (x+1):
setDistance(templateTiles[x+1][y], tileToAdapt, 2, false)
if templateTiles[x].size() > (x+1) and templateTiles[x+1].size() > (y-1)and y-1 >=0:
setDistance(templateTiles[x+1][y-1], tileToAdapt, 3, true)
if templateTiles.size() > (y-1) and y-1 >=0:
setDistance(templateTiles[x][y-1], tileToAdapt, 4, false)
if templateTiles[x].size() > (x-1) and templateTiles[x-1].size() > (y-1)and x-1 >=0 and y-1 >=0:
setDistance(templateTiles[x-1][y-1], tileToAdapt, 5, true)
if templateTiles.size() > (x-1) and x-1 >=0:
setDistance(templateTiles[x-1][y], tileToAdapt, 6, false)
if templateTiles[x].size() > (x-1) and templateTiles[x-1].size() > (y+1)and x-1 >=0:
setDistance(templateTiles[x-1][y+1], tileToAdapt, 7, true)
# print("Tiles procedurally: ",tileToAdapt)
y+=1
x+=1
return templateTiles
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
"road":
origin.verticeDistance[index] = 2
"mountain":
origin.verticeDistance[index] = INF
"enemyOccupied":
origin.verticeDistance[index] = INF
else:
match target.type:
"grass":
origin.verticeDistance[index] = 8
"road":
origin.verticeDistance[index] = 3
"mountain":
origin.verticeDistance[index] = INF
"enemyOccupied":
origin.verticeDistance[index] = INF
func buildSuperTiles(templateTiles):
var superTilesToReturn = []
var x = 0
var y = 0
for i in range(tileRect.x-1):
var column=[]
for line in range(tileRect.y-1):
var newSuperTile = {
"coords":null,
"vertices":[],
"verticeExplored":false,
"verticeDistance":[INF,INF,INF,INF,INF,INF,INF,INF],
"type":"grass",
"route":[],
"underTiles":[]
}
newSuperTile.underTiles.append(templateTiles[x][y])
newSuperTile.underTiles.append(templateTiles[x][y+1])
newSuperTile.underTiles.append(templateTiles[x+1][y])
newSuperTile.underTiles.append(templateTiles[x+1][y+1])
newSuperTile.coords = Vector2(x,y)
column.append(newSuperTile)
y+=1
superTilesToReturn.append(column)
x+=1
y=0
return setSuperVertices(superTilesToReturn)
func setSuperVertices(templateTiles):
var tileToAdapt
var x = 0
for row in templateTiles:
var y = 0
for line in row:
tileToAdapt = templateTiles[x][y]
# print("\n")
# print("x:",x, " y:",y)
if templateTiles.size() > x+1:
if templateTiles[x].size() > (y+1):
setSuperDistance(templateTiles[x][y+1], tileToAdapt, 0, false)
if templateTiles[x].size() > (x+1) and templateTiles[x+1].size() > (y+1):
setSuperDistance(templateTiles[x+1][y+1], tileToAdapt, 1, true)
if templateTiles.size() > (x+1):
setSuperDistance(templateTiles[x+1][y], tileToAdapt, 2, false)
if templateTiles[x].size() > (x+1) and templateTiles[x+1].size() > (y-1)and y-1 >=0:
setSuperDistance(templateTiles[x+1][y-1], tileToAdapt, 3, true)
if templateTiles.size() > (y-1)and y-1 >=0:
setSuperDistance(templateTiles[x][y-1], tileToAdapt, 4, false)
if templateTiles[x].size() > (x-1) and templateTiles[x-1].size() > (y-1)and x-1 >=0 and y-1 >=0:
setSuperDistance(templateTiles[x-1][y-1], tileToAdapt, 5, true)
if templateTiles.size() > (x-1)and x-1 >=0:
setSuperDistance(templateTiles[x-1][y], tileToAdapt, 6, false)
if templateTiles[x].size() > (x-1) and templateTiles[x-1].size() > (y+1)and x-1 >=0:
setSuperDistance(templateTiles[x-1][y+1], tileToAdapt, 7, true)
# print("Tiles procedurally: ",tileToAdapt)
y+=1
x+=1
return templateTiles
func setSuperDistance(target,origin,index,diagonal = false):
var totalDistance = 0
for tile in target.underTiles:
if not diagonal:
match tile.type:
"grass":
totalDistance += 5
"road":
totalDistance += 2
"mountain":
totalDistance += INF
"enemyOccupied":
totalDistance += INF
else:
match tile.type:
"grass":
totalDistance += 8
"road":
totalDistance += 3
"mountain":
totalDistance += INF
"enemyOccupied":
totalDistance += INF
origin.verticeDistance[index] = totalDistance/target.underTiles.size()
func moveUnit(path,unitID):
var apCost = 0
var unit = getUnitById(unitID)
var occupiedTiles=getOccupiedTiles(unit)[0]
var enemyOccupiedTiles=getOccupiedTiles(unit)[1]
var tiles = addEnemyOccupiedTilesToMap(enemyOccupiedTiles)
# lie check
if occupiedTiles.has(path[-1]):
return false
if unit.superUnit == true:
if occupiedTiles.has(path[-1]+Vector2(0,0)) or occupiedTiles.has(path[-1]+Vector2(1,0)) or occupiedTiles.has(path[-1]+Vector2(0,1)) or occupiedTiles.has(path[-1]+Vector2(1,1)):
return false
# overlap check
if path[0] != unit.coords:
return false
for i in range(path.size()-1):
var coordDirection = Vector2((path[i+1].x - path[i].x) , (path[i+1].y-path[i].y))
# movement check
if abs(path[i].x - path[i+1].x)>1 and abs(path[i].y - path[i+1].y)>1:
return false
# distance check
var currTile = tiles[path[i].x][path[i].y]
var nextTile = tiles[path[i+1].x][path[i+1].y]
var directionIndex
if coordDirection == Vector2(0,1):
directionIndex = 0
if coordDirection == Vector2(1,1):
directionIndex = 1
if coordDirection == Vector2(1,0):
directionIndex = 2
if coordDirection == Vector2(1,-1):
directionIndex = 3
if coordDirection == Vector2(0,-1):
directionIndex = 4
if coordDirection == Vector2(-1,-1):
directionIndex = 5
if coordDirection == Vector2(-1,0):
directionIndex = 6
if coordDirection == Vector2(-1,1):
directionIndex = 7
apCost += currTile.verticeDistance[directionIndex]
# collision check
if unit.superUnit == true:
if enemyOccupiedTiles.has(path[i+1]+Vector2(0,0)) or enemyOccupiedTiles.has(path[i+1]+Vector2(1,0)) or enemyOccupiedTiles.has(path[i+1]+Vector2(0,1)) or enemyOccupiedTiles.has(path[i+1]+Vector2(1,1)):
return false
else:
if enemyOccupiedTiles.has(path[i+1]):
return false
if apCost > unit.moveAp+unit.ap:
return false
if unit.moveAp < apCost:
unit.ap -= (apCost-unit.moveAp)
unit.moveAp = 0
else:
unit.moveAp -= apCost
unit.coords = path[-1]
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:
if unit.id == unitId:
return unit
return null
func getOccupiedTiles(forUnit):#looks into boardUnits to find their position and adds each of them to the occupiedTiles array.
var selectedFaction
if forUnit == null:
selectedFaction = "playerFaction"
else:
selectedFaction = forUnit.faction
var occupiedTiles = []
var enemyOccupiedTiles = []
for unit in boardUnits:
if unit != forUnit:
if !unit.superUnit:
occupiedTiles.append(unit.coords)
else:
occupiedTiles.append(Vector2(unit.coords.x, unit.coords.y))
occupiedTiles.append(Vector2(unit.coords.x, unit.coords.y+1))
occupiedTiles.append(Vector2(unit.coords.x+1, unit.coords.y))
occupiedTiles.append(Vector2(unit.coords.x+1, unit.coords.y+1))
if PlayerManager.checkdiplo(selectedFaction, unit.faction) == "enemies":
if !unit.superUnit:
enemyOccupiedTiles.append(unit.coords)
else:
enemyOccupiedTiles.append(Vector2(unit.coords.x, unit.coords.y))
enemyOccupiedTiles.append(Vector2(unit.coords.x, unit.coords.y+1))
enemyOccupiedTiles.append(Vector2(unit.coords.x+1, unit.coords.y))
enemyOccupiedTiles.append(Vector2(unit.coords.x+1, unit.coords.y+1))
return [occupiedTiles,enemyOccupiedTiles]
func addEnemyOccupiedTilesToMap(enemyOccupiedTiles):#this creates the tiles array and adds all the tile-dictionaries. Also sets ground-type.
var mapTiles = tiles.duplicate(true)
var currentX = 0
for tile in enemyOccupiedTiles:
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])))
return [tileRect, newTiles, newSuperTiles]
func endTurn():
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func requestUnits():
return boardUnits

View File

@ -1,11 +1,6 @@
[gd_scene load_steps=16 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://region/Region.gd" type="Script" id=1]
[ext_resource path="res://images/region/regiontiles.png" type="Texture" id=2]
[ext_resource path="res://region/regionGround.gd" type="Script" id=3]
[ext_resource path="res://army/Stack2x1.tscn" type="PackedScene" id=4]
[ext_resource path="res://region/ressourcenodes/Mountain.tscn" type="PackedScene" id=5]
[ext_resource path="res://region/building/Building.tscn" type="PackedScene" id=6]
[ext_resource path="res://Camera2D.gd" type="Script" id=7]
[ext_resource path="res://region/RegionUI.tscn" type="PackedScene" id=8]
[ext_resource path="res://menues/smallbtn.tscn" type="PackedScene" id=9]
@ -13,112 +8,10 @@
[ext_resource path="res://menues/toggleResearch.gd" type="Script" id=11]
[ext_resource path="res://menues/research.tscn" type="PackedScene" id=12]
[ext_resource path="res://items/Item.tscn" type="PackedScene" id=13]
[ext_resource path="res://region/MineSmall.tscn" type="PackedScene" id=14]
[sub_resource type="TileSet" id=1]
0/name = "regiontiles.png 0"
0/texture = ExtResource( 2 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 128, 0, 128, 128 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape_one_way = false
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
1/name = "regiontiles.png 1"
1/texture = ExtResource( 2 )
1/tex_offset = Vector2( 0, 0 )
1/modulate = Color( 1, 1, 1, 1 )
1/region = Rect2( 480, 0, 128, 128 )
1/tile_mode = 0
1/occluder_offset = Vector2( 0, 0 )
1/navigation_offset = Vector2( 0, 0 )
1/shape_offset = Vector2( 0, 0 )
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
1/shape_one_way = false
1/shape_one_way_margin = 0.0
1/shapes = [ ]
1/z_index = 0
2/name = "regiontiles.png 2"
2/texture = ExtResource( 2 )
2/tex_offset = Vector2( 0, 0 )
2/modulate = Color( 1, 1, 1, 1 )
2/region = Rect2( 224, 384, 128, 128 )
2/tile_mode = 0
2/occluder_offset = Vector2( 0, 0 )
2/navigation_offset = Vector2( 0, 0 )
2/shape_offset = Vector2( 0, 0 )
2/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
2/shape_one_way = false
2/shape_one_way_margin = 0.0
2/shapes = [ ]
2/z_index = 0
3/name = "regiontiles.png 3"
3/texture = ExtResource( 2 )
3/tex_offset = Vector2( 0, 0 )
3/modulate = Color( 1, 1, 1, 1 )
3/region = Rect2( 0, 128, 128, 128 )
3/tile_mode = 0
3/occluder_offset = Vector2( 0, 0 )
3/navigation_offset = Vector2( 0, 0 )
3/shape_offset = Vector2( 0, 0 )
3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
3/shape_one_way = false
3/shape_one_way_margin = 0.0
3/shapes = [ ]
3/z_index = 0
4/name = "regiontiles.png 4"
4/texture = ExtResource( 2 )
4/tex_offset = Vector2( 0, 0 )
4/modulate = Color( 1, 1, 1, 1 )
4/region = Rect2( 128, 128, 128, 128 )
4/tile_mode = 0
4/occluder_offset = Vector2( 0, 0 )
4/navigation_offset = Vector2( 0, 0 )
4/shape_offset = Vector2( 0, 0 )
4/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
4/shape_one_way = false
4/shape_one_way_margin = 0.0
4/shapes = [ ]
4/z_index = 0
[node name="Region" type="Node2D"]
script = ExtResource( 1 )
[node name="ground" type="TileMap" parent="."]
tile_set = SubResource( 1 )
cell_size = Vector2( 128, 128 )
format = 1
tile_data = PoolIntArray( -65537, 1, 0, -131072, 1, 0, -131071, 1, 0, -131070, 1, 0, -131069, 1, 0, -131068, 1, 0, -131067, 1, 0, -131066, 1, 0, -131065, 1, 0, -131064, 1, 0, -131063, 1, 0, -131062, 1, 0, -131061, 1, 0, -131060, 1, 0, -131059, 1, 0, -131058, 1, 0, -1, 1, 0, -65536, 1, 0, -65535, 1, 0, -65534, 1, 0, -65533, 1, 0, -65532, 1, 0, -65531, 1, 0, -65530, 1, 0, -65529, 1, 0, -65528, 1, 0, -65527, 1, 0, -65526, 1, 0, -65525, 1, 0, -65524, 1, 0, -65523, 1, 0, -65522, 1, 0, -65521, 1, 0, -65520, 1, 0, 65535, 1, 0, 0, 0, 0, 1, 0, 0, 2, 2, 0, 3, 2, 0, 4, 2, 0, 5, 2, 0, 6, 2, 0, 7, 2, 0, 8, 1, 0, 9, 1, 0, 10, 1, 0, 11, 1, 0, 12, 1, 0, 13, 1, 0, 14, 1, 0, 15, 1, 0, 16, 1, 0, 131071, 1, 0, 65536, 0, 0, 65537, 0, 0, 65538, 2, 0, 65539, 2, 0, 65540, 2, 0, 65541, 2, 0, 65542, 2, 0, 65543, 2, 0, 65544, 1, 0, 65545, 1, 0, 65546, 1, 0, 65547, 1, 0, 65548, 1, 0, 65549, 1, 0, 65550, 1, 0, 65551, 1, 0, 65552, 1, 0, 196607, 1, 0, 131072, 0, 0, 131073, 0, 0, 131074, 2, 0, 131075, 4, 0, 131076, 4, 0, 131077, 0, 0, 131078, 2, 0, 131079, 2, 0, 131080, 1, 0, 131081, 1, 0, 131082, 1, 0, 131083, 1, 0, 131084, 1, 0, 131085, 1, 0, 131086, 1, 0, 131087, 1, 0, 131088, 1, 0, 131089, 1, 0, 131090, 1, 0, 131091, 1, 0, 131092, 1, 0, 131093, 1, 0, 131094, 1, 0, 262143, 1, 0, 196608, 4, 0, 196609, 4, 0, 196610, 4, 0, 196611, 4, 0, 196612, 4, 0, 196613, 0, 0, 196614, 2, 0, 196615, 2, 0, 196616, 1, 0, 196617, 1, 0, 196618, 1, 0, 196619, 1, 0, 196620, 1, 0, 196621, 1, 0, 196622, 1, 0, 196623, 1, 0, 196625, 1, 0, 196626, 1, 0, 196627, 1, 0, 196628, 1, 0, 196629, 1, 0, 196630, 1, 0, 327678, 1, 0, 327679, 1, 0, 262144, 0, 0, 262145, 0, 0, 262146, 3, 0, 262147, 3, 0, 262148, 3, 0, 262149, 0, 0, 262150, 1, 0, 262151, 1, 0, 262152, 1, 0, 262153, 1, 0, 262154, 1, 0, 262155, 1, 0, 262156, 1, 0, 262157, 1, 0, 262158, 1, 0, 262159, 1, 0, 393214, 1, 0, 393215, 1, 0, 327680, 1, 0, 327681, 1, 0, 327682, 1, 0, 327683, 1, 0, 327684, 1, 0, 327685, 1, 0, 327686, 1, 0, 327687, 1, 0, 327688, 1, 0, 327689, 1, 0, 327690, 1, 0, 327692, 1, 0, 327693, 1, 0, 327694, 1, 0, 327695, 1, 0, 458750, 1, 0, 458751, 1, 0, 393216, 1, 0, 393217, 1, 0, 393218, 1, 0, 393219, 1, 0, 393220, 1, 0, 393221, 1, 0, 393222, 1, 0, 393223, 1, 0, 393224, 1, 0, 393225, 1, 0, 393226, 1, 0, 393227, 1, 0, 393228, 1, 0, 393229, 1, 0, 393230, 1, 0, 393231, 1, 0, 524287, 1, 0, 458752, 1, 0, 458753, 1, 0, 458754, 1, 0, 458755, 1, 0, 458756, 1, 0, 458757, 1, 0, 458758, 1, 0, 458759, 1, 0, 458760, 1, 0, 458761, 1, 0, 458762, 1, 0, 458763, 1, 0, 458764, 1, 0, 458765, 1, 0, 458766, 1, 0, 458767, 1, 0, 589823, 1, 0, 524288, 1, 0, 524289, 1, 0, 524290, 1, 0, 524291, 1, 0, 524292, 1, 0, 524293, 1, 0, 524294, 1, 0, 524295, 1, 0, 524296, 1, 0, 524297, 1, 0, 524298, 1, 0, 524299, 1, 0, 524300, 1, 0, 524301, 1, 0, 524302, 1, 0, 524303, 1, 0, 655359, 1, 0, 589824, 1, 0, 589825, 1, 0, 589826, 1, 0, 589827, 1, 0, 589828, 1, 0, 589829, 1, 0, 589831, 1, 0, 589832, 1, 0, 589833, 1, 0, 589834, 1, 0, 589835, 1, 0, 655367, 1, 0 )
script = ExtResource( 3 )
[node name="units" type="Node" parent="ground"]
[node name="Stack" parent="ground/units" instance=ExtResource( 4 )]
position = Vector2( 128, 256 )
[node name="ressources" type="Node" parent="ground"]
[node name="Mountain" parent="ground/ressources" instance=ExtResource( 5 )]
position = Vector2( 256, 768 )
[node name="buildings" type="Node" parent="ground"]
[node name="Node2D" parent="ground/buildings" instance=ExtResource( 6 )]
position = Vector2( 730, 700 )
[node name="mine" type="Node2D" parent="ground/buildings"]
position = Vector2( 574, 569 )
[node name="MineSmall" parent="ground/buildings/mine" instance=ExtResource( 14 )]
position = Vector2( 1, 0 )
scale = Vector2( 0.427155, 0.427155 )
[node name="Camera2D" type="Camera2D" parent="."]
current = true
drag_margin_left = 0.0