parcels use struct, give initial parcels for city
This commit is contained in:
parent
99b28ecfa3
commit
7486750ca2
7 changed files with 213 additions and 92 deletions
|
@ -93,19 +93,26 @@ func generate_biomes() -> void:
|
|||
Globals.map_terrain_data[y][x] = Globals.TILE_FOREST
|
||||
# can add other tresholds here for other biomes
|
||||
|
||||
# TODO move to globals later
|
||||
var parcel_width = 16
|
||||
var parcel_height = 64
|
||||
|
||||
# forests are not generated yet so can just compare water and terrain
|
||||
func is_filled_with_water(coords:Vector2i) -> bool:
|
||||
var terrain_tile_count:int = 0
|
||||
|
||||
for y in range(coords.y, coords.y + parcel_height):
|
||||
for x in range(coords.x, coords.x + parcel_width):
|
||||
# 0*64, 0*64 +64-1 = 0-63
|
||||
# 1*64, 1*64 +63 = 64-127
|
||||
# 2*64, 2*64 +63 = 128-191
|
||||
# 3*64, 3*64 +63 = 192-255
|
||||
for y in range(
|
||||
coords.y*Globals.PARCEL_HEIGHT,
|
||||
coords.y*Globals.PARCEL_HEIGHT + Globals.PARCEL_HEIGHT-1
|
||||
):
|
||||
for x in range(
|
||||
coords.x*Globals.PARCEL_WIDTH,
|
||||
coords.x*Globals.PARCEL_WIDTH + Globals.PARCEL_WIDTH-1
|
||||
):
|
||||
if Globals.map_terrain_data[y][x] == Globals.TILE_TERRAIN:
|
||||
terrain_tile_count += 1
|
||||
|
||||
|
||||
# parcel is ok if it has at least one land
|
||||
if terrain_tile_count > 0:
|
||||
return false
|
||||
|
@ -115,24 +122,38 @@ func generate_parcels() -> void:
|
|||
# divide the land area Cadastres / Parcels
|
||||
# TODO better solution, this is something my skills were able to handle at proto stage
|
||||
# should replace with a real/better algo when I am skilled enough to do it
|
||||
Globals.map_parcel_data.resize(Globals.map_size / parcel_height)
|
||||
Globals.map_parcel_data.resize(Globals.map_size / Globals.PARCEL_HEIGHT)
|
||||
|
||||
for y in Globals.map_size / parcel_height:
|
||||
Globals.map_parcel_data[y].resize(Globals.map_size / parcel_width)
|
||||
for x in Globals.map_size / parcel_width:
|
||||
for y in Globals.map_size / Globals.PARCEL_HEIGHT:
|
||||
Globals.map_parcel_data[y].resize(Globals.map_size / Globals.PARCEL_WIDTH)
|
||||
for x in Globals.map_size / Globals.PARCEL_WIDTH:
|
||||
# ignore parcels full fo water
|
||||
if !is_filled_with_water(Vector2i(y,x)):
|
||||
# 0 = top left corner, 1 = bottom right corner, 2 = owner
|
||||
Globals.map_parcel_data[y][x] = [
|
||||
Vector2i(y * parcel_height, x * parcel_width),
|
||||
Vector2i(y * parcel_height + parcel_height, x * parcel_width + parcel_width),
|
||||
Globals.PARCEL_STATE
|
||||
]
|
||||
if !is_filled_with_water(Vector2i(x,y)):
|
||||
Globals.map_parcel_data[y][x] = Globals.Parcel.new()
|
||||
Globals.map_parcel_data[y][x].start = Vector2i(
|
||||
y * Globals.PARCEL_HEIGHT,
|
||||
x * Globals.PARCEL_WIDTH,
|
||||
)
|
||||
Globals.map_parcel_data[y][x].size = Vector2i(
|
||||
Globals.PARCEL_WIDTH,
|
||||
Globals.PARCEL_HEIGHT,
|
||||
)
|
||||
Globals.map_parcel_data[y][x].owner = Globals.PARCEL_STATE
|
||||
|
||||
#for row in Globals.map_parcel_data:
|
||||
# print(row)
|
||||
#for col in row:
|
||||
# print(Globals.map_parcel_data[row][col])
|
||||
|
||||
# not used, but could be used later
|
||||
var total_parcels = Globals.map_size/Globals.PARCEL_WIDTH * Globals.map_size / Globals.PARCEL_HEIGHT
|
||||
give_starting_parcels_for_city(total_parcels)
|
||||
|
||||
func give_starting_parcels_for_city(_amount:int) -> void:
|
||||
# gives a x*y parcel initial starting area for the player
|
||||
var p_x = Globals.map_size/Globals.PARCEL_WIDTH/2
|
||||
var p_y = Globals.map_size/Globals.PARCEL_HEIGHT/2
|
||||
|
||||
for y in range(0, Globals.STARTING_AREA_HEIGHT_IN_PARCELS):
|
||||
for x in range(0, Globals.STARTING_AREA_WIDTH_IN_PARCELS):
|
||||
if Globals.map_parcel_data[p_y-y][p_x-x] != null:
|
||||
Globals.map_parcel_data[p_y-y][p_x-x].owner = Globals.PARCEL_CITY
|
||||
|
||||
|
||||
func generate_world(filename) -> bool:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue