def cast_light(cx, cy, row, start, end, radius, xx, xy, yx, yy, fov_matrix, level): """ Recursive lightcasting function Returns: fov_matrix """ if start < end: return radius_squared = radius * radius for j in range(row, radius + 1): dx, dy = -j - 1, -j blocked = False while dx <= 0: dx += 1 # Translate the dx, dy coordinates into map coordinates: X, Y = cx + dx * xx + dy * xy, cy + dx * yx + dy * yy # l_slope and r_slope store the slopes of the left and right # extremities of the square we're considering: l_slope, r_slope = (dx - 0.5) / (dy + 0.5), (dx + 0.5) / (dy - 0.5) if start < r_slope: continue elif end > l_slope: break else: # Our light beam is touching this square; light it: if dx * dx + dy * dy < radius_squared: #transform from map to light_matrix fov_matrix[(X, Y)] = True if blocked: # we're scanning a row of blocked squares: if blocks_los(level, (X, Y)): new_start = r_slope continue else: blocked = False start = new_start else: if blocks_los(level, (X, Y)) and j < radius: # This is a blocking square, start a child scan: blocked = True cast_light(cx, cy, j + 1, start, l_slope, radius, xx, xy, yx, yy, fov_matrix, level) new_start = r_slope # Row is scanned; do next row unless last square was blocked: if blocked: break return fov_matrix
def cast_light(cx, cy, row, start, end, radius, xx, xy, yx, yy, fov_matrix, level): """ Recursive lightcasting function Returns: fov_matrix """ if start < end: return radius_squared = radius*radius for j in range(row, radius+1): dx, dy = -j-1, -j blocked = False while dx <= 0: dx += 1 # Translate the dx, dy coordinates into map coordinates: X, Y = cx + dx * xx + dy * xy, cy + dx * yx + dy * yy # l_slope and r_slope store the slopes of the left and right # extremities of the square we're considering: l_slope, r_slope = (dx-0.5)/(dy+0.5), (dx+0.5)/(dy-0.5) if start < r_slope: continue elif end > l_slope: break else: # Our light beam is touching this square; light it: if dx*dx + dy*dy < radius_squared: #transform from map to light_matrix fov_matrix[(X, Y)] = True if blocked: # we're scanning a row of blocked squares: if blocks_los(level, (X, Y)): new_start = r_slope continue else: blocked = False start = new_start else: if blocks_los(level, (X, Y)) and j < radius: # This is a blocking square, start a child scan: blocked = True cast_light(cx, cy, j+1, start, l_slope, radius, xx, xy, yx, yy, fov_matrix, level) new_start = r_slope # Row is scanned; do next row unless last square was blocked: if blocked: break return fov_matrix
def targeting_spherical_area(parameters, radius): """ Function to target a spherical area .. versionadded:: 0.10 """ targets = [] initial = get_target_in_direction(level=parameters.caster.level, location=parameters.caster.location, direction=parameters.direction) if initial and initial.previous_target: splash_center = initial.previous_target.location level = parameters.caster.level matrix = get_fov_matrix(splash_center, level, radius) x_range = range(splash_center[0] - radius, splash_center[0] + radius + 1) y_range = range(splash_center[1] - radius, splash_center[1] + radius + 1) for location, is_visible in matrix.items(): if is_visible: creature = get_character(level, location) if creature: targets.append( TargetData('character', location, creature, None)) elif blocks_los(level, location): targets.append(TargetData('wall', location, None, None)) else: targets.append(TargetData('void', location, None, None)) return targets
def targeting_spherical_area(parameters, radius): """ Function to target a spherical area .. versionadded:: 0.10 """ targets = [] initial = get_target_in_direction(level=parameters.caster.level, location=parameters.caster.location, direction=parameters.direction) if initial and initial.previous_target: splash_center = initial.previous_target.location level = parameters.caster.level matrix = get_fov_matrix(splash_center, level, radius) x_range = range(splash_center[0] - radius, splash_center[0] + radius + 1) y_range = range(splash_center[1] - radius, splash_center[1] + radius + 1) for location, is_visible in matrix.items(): if is_visible: creature = get_character(level, location) if creature: targets.append(TargetData('character', location, creature, None)) elif blocks_los(level, location): targets.append(TargetData('wall', location, None, None)) else: targets.append(TargetData('void', location, None, None)) return targets