def calculate_light(self): creatures = [Creature.by_id(c) for c in self.__creatures] sources = set((c.where_is(), c.light) for c in creatures if c.light > 0) statlight = set(i for i in self.statics if i.light not in [None, 0]) if sources != self.sources: self.lightmap = [[self.ambient_light] * self.w for i in range(self.h)] for s in statlight: d = int((s.light - 1) ** 0.5) for lx in range(max(0, s.x - d), min(self.w, s.x + d + 1)): for ly in range(max(0, s.y - d), min(self.h, s.y + d + 1)): self.lightmap[ly][lx] += int(s.light / (((s.x - lx) ** 2 + (s.y - ly) ** 2) + 1)) for c in creatures: z = c if z: zx, zy = z.where_is() if z.light > 0: d = int((z.light - 1) ** 0.5) for lx in range(max(0, zx - d), min(self.w, zx + d + 1)): for ly in range(max(0, zy - d), min(self.h, zy + d + 1)): self.lightmap[ly][lx] += int(z.light / (((zx - lx) ** 2 + (zy - ly) ** 2) + 1)) self.sources = sources
def get_hero(self): for c in self.__creatures: if Creature.by_id(c).controlled_by_player: return Creature.by_id(c) raise Exception("No hero found")
def get_creatures(self): return [Creature.by_id(c) for c in self.__creatures]