X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=server_%2Fmap_.py;h=2e87fc59b0c0ed04db0268d132b96bd89434f646;hb=4542a12bf12101e60aedea9bb9df098573bf0d25;hp=836e540b75b89a4b99f3aa0b668d5f00e2a4951e;hpb=990fe3a33887e1f44c25884d7d45c71337efd2f4;p=plomrogue2-experiments diff --git a/server_/map_.py b/server_/map_.py index 836e540..2e87fc5 100644 --- a/server_/map_.py +++ b/server_/map_.py @@ -12,7 +12,10 @@ class Map(game_common.Map): def __setitem__(self, yx, c): pos_i = self.get_position_index(yx) - self.terrain = self.terrain[:pos_i] + c + self.terrain[pos_i + 1:] + if type(c) == str: + self.terrain = self.terrain[:pos_i] + c + self.terrain[pos_i + 1:] + else: + self.terrain[pos_i] = c def __iter__(self): """Iterate over YX position coordinates.""" @@ -97,9 +100,9 @@ class MapHex(Map): def move_DOWNLEFT(self, start_pos): if start_pos[0] % 2 == 1: - return [start_pos[0] + 1, start_pos[1] - 1] + return [start_pos[0] + 1, start_pos[1] - 1] else: - return [start_pos[0] + 1, start_pos[1]] + return [start_pos[0] + 1, start_pos[1]] def move_DOWNRIGHT(self, start_pos): if start_pos[0] % 2 == 1: @@ -107,6 +110,34 @@ class MapHex(Map): else: return [start_pos[0] + 1, start_pos[1] + 1] + def get_neighbors(self, pos): + # DOWNLEFT, DOWNRIGHT, LEFT, RIGHT, UPLEFT, UPRIGHT (alphabetically) + neighbors = [None, None, None, None, None, None] # e, d, c, x, s, w + if pos[1] > 0: + neighbors[2] = [pos[0], pos[1] - 1] + if pos[1] < self.size[1] - 1: + neighbors[3] = [pos[0], pos[1] + 1] + # x, c, s, d, w, e # 3->0, 2->1, 5->4, 0->5 + if pos[0] % 2 == 1: + if pos[0] > 0 and pos[1] > 0: + neighbors[4] = [pos[0] - 1, pos[1] - 1] + if pos[0] < self.size[0] - 1 and pos[1] > 0: + neighbors[0] = [pos[0] + 1, pos[1] - 1] + if pos[0] > 0: + neighbors[5] = [pos[0] - 1, pos[1]] + if pos[0] < self.size[0] - 1: + neighbors[1] = [pos[0] + 1, pos[1]] + else: + if pos[0] > 0 and pos[1] < self.size[1] - 1: + neighbors[5] = [pos[0] - 1, pos[1] + 1] + if pos[0] < self.size[0] - 1 and pos[1] < self.size[1] - 1: + neighbors[1] = [pos[0] + 1, pos[1] + 1] + if pos[0] > 0: + neighbors[4] = [pos[0] - 1, pos[1]] + if pos[0] < self.size[0] - 1: + neighbors[0] = [pos[0] + 1, pos[1]] + return neighbors + class MapFovHex(MapHex): @@ -231,6 +262,19 @@ class MapSquare(Map): def move_DOWN(self, start_pos): return [start_pos[0] + 1, start_pos[1]] + def get_neighbors(self, pos): + # DOWN, LEFT, RIGHT, UP (alphabetically) + neighbors = [None, None, None, None] + if pos[0] > 0: + neighbors[3] = [pos[0] - 1, pos[1]] + if pos[1] > 0: + neighbors[1] = [pos[0], pos[1] - 1] + if pos[0] < self.size[0] - 1: + neighbors[0] = [pos[0] + 1, pos[1]] + if pos[1] < self.size[1] - 1: + neighbors[2] = [pos[0], pos[1] + 1] + return neighbors + class MapFovSquare(MapSquare): """Just a marginally and unsatisfyingly adapted variant of MapFovHex.""" @@ -262,13 +306,15 @@ class MapFovSquare(MapSquare): def merge_cone(new_cone): for old_cone in self.shadow_cones: if new_cone[0] > old_cone[0] and \ - new_cone[1] <= old_cone[0]: + (new_cone[1] < old_cone[0] or + math.isclose(new_cone[1], old_cone[0])): #print('DEBUG merging to', old_cone) old_cone[0] = new_cone[0] #print('DEBUG merged cone:', old_cone) return True if new_cone[1] < old_cone[1] and \ - new_cone[0] >= old_cone[1]: + (new_cone[0] > old_cone[1] or + math.isclose(new_cone[0], old_cone[1])): #print('DEBUG merging to', old_cone) old_cone[1] = new_cone[1] #print('DEBUG merged cone:', old_cone) @@ -290,7 +336,7 @@ class MapFovSquare(MapSquare): self.shadow_cones += [cone] #print('DEBUG', yx) - step_size = fractions.Fraction(CIRCLE, 4) / distance_to_center + step_size = (CIRCLE/4) / distance_to_center number_steps = dir_i * distance_to_center + dir_progress left_arm = correct_arm(-(step_size/2) - step_size*number_steps) right_arm = correct_arm(left_arm - step_size)