Now and then, a group of enemies in a tunnel
Tunnels are wide enough to fight in now, so occasionally one is occupied: each tunnel leg rolls a 10% chance of a group of two or three of one kind, standing within two tiles of each other. Most legs are too short or too near the entrance to qualify, so in practice it is about one depth-1 run in three (60 of 200 measured), rising with depth as tunnels get longer. Rare on purpose -- tunnels are where you go between fights, and a tunnel that is usually empty is what makes the one that is not a surprise. Never within aggro range of the entrance, checked per member rather than per group: members stand up to two tiles off the group's centre, so a centre that clears the entrance does not mean everyone does. The first version checked the centre, and the nearest member landed 15 units outside aggro range by luck. Never a lone straggler: a leg that cannot fit two gets nobody. Placed after every room, so each room's population is exactly what its seed always produced, and every leg rolls the same dice whether or not it is used, so one tunnel's luck never depends on another's shape. Scaled by the dungeon like every other spawn, each member from its own fresh definition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
855669a665
commit
069abdb3fa
4 files changed
+184
-6
No files matched your search
@@ -31,10 +31,26 @@ var stage_delay: int = 0
|
||||
var boss_id: StringName = &""
|
||||
## Generated layout, used to place enemies room by room.
|
||||
var rooms: Array[Rect2i] = []
|
||||
## The rectangle each tunnel leg was carved over -- see MapGen. Overlaps the
|
||||
## rooms at its ends, so _tunnel_tiles() decides what is actually tunnel.
|
||||
var tunnels: Array[Rect2i] = []
|
||||
var boss_spawn := Vector2.ZERO
|
||||
var boss_room := Rect2i()
|
||||
|
||||
|
||||
## Chance that any one tunnel leg has a group of enemies in it. Rolled per leg,
|
||||
## and most legs are too short or too near the entrance to qualify anyway, so a
|
||||
## depth-1 dungeon has a tunnel group about one run in three. Rare on purpose:
|
||||
## tunnels are where you go between fights, and a tunnel that is usually empty
|
||||
## is what makes the one that is not a surprise.
|
||||
const TUNNEL_GROUP_CHANCE := 0.1
|
||||
const TUNNEL_GROUP_MIN := 2
|
||||
const TUNNEL_GROUP_MAX := 3
|
||||
## Members stand within this many tiles of the group's centre, so a group reads
|
||||
## as one encounter rather than a tunnel's worth of strays.
|
||||
const TUNNEL_GROUP_SPREAD := 2
|
||||
|
||||
|
||||
static func make_lobby(instance_id: int) -> Instance:
|
||||
var inst := Instance.new()
|
||||
inst.id = instance_id
|
||||
@@ -78,6 +94,7 @@ static func make_dungeon(instance_id: int, dungeon_seed: int, dungeon_depth: int
|
||||
inst.depth, flavour.arena)
|
||||
inst.world.set_map(built["grid"])
|
||||
inst.rooms = built["rooms"]
|
||||
inst.tunnels = built["tunnels"]
|
||||
inst.boss_spawn = built["boss_pos"]
|
||||
inst.boss_room = built["boss_room"]
|
||||
inst.world.spawn_point = built["spawn"]
|
||||
@@ -119,6 +136,87 @@ func _populate() -> void:
|
||||
if world.map.circle_blocked(at, def.radius):
|
||||
continue
|
||||
world.spawn_enemy(def, at, rng.randi_range(0, 120))
|
||||
# After every room, so adding tunnel groups leaves each room's population
|
||||
# exactly what that seed always produced.
|
||||
_populate_tunnels(rng, flavour)
|
||||
|
||||
|
||||
## Now and then, a group of enemies in a tunnel.
|
||||
##
|
||||
## Never within aggro range of the entrance, by the same reasoning room 0 is
|
||||
## left empty: arriving into a fight you cannot see yet is not a decision, it
|
||||
## is an ambush. And never a lone straggler -- if a leg cannot fit at least
|
||||
## TUNNEL_GROUP_MIN, it gets nobody.
|
||||
func _populate_tunnels(rng: RandomNumberGenerator, flavour: DungeonDef) -> void:
|
||||
var clear_of_spawn := _widest_aggro() + MapGrid.TILE * 2.0
|
||||
for leg in tunnels:
|
||||
# Every leg rolls the same three numbers whether or not it is used, so
|
||||
# one tunnel's dice never depend on another tunnel's shape.
|
||||
var roll := rng.randf()
|
||||
var pick := rng.randi()
|
||||
var size := rng.randi_range(TUNNEL_GROUP_MIN, TUNNEL_GROUP_MAX)
|
||||
if roll >= TUNNEL_GROUP_CHANCE:
|
||||
continue
|
||||
var open := _tunnel_tiles(leg)
|
||||
if open.size() < TUNNEL_GROUP_MAX * 2:
|
||||
continue
|
||||
var centre: Vector2i = open[pick % open.size()]
|
||||
var def := flavour.apply_to_enemy(_pick_enemy(rng))
|
||||
var spots: Array[Vector2] = []
|
||||
for t in open:
|
||||
if absi(t.x - centre.x) > TUNNEL_GROUP_SPREAD \
|
||||
or absi(t.y - centre.y) > TUNNEL_GROUP_SPREAD:
|
||||
continue
|
||||
var at := world.map.tile_centre(t.x, t.y)
|
||||
# Per member, not per group: members stand up to two tiles off the
|
||||
# centre, so a centre that clears the entrance does not mean every
|
||||
# member does.
|
||||
if at.distance_to(world.spawn_point) < clear_of_spawn:
|
||||
continue
|
||||
if not world.map.circle_blocked(at, def.radius):
|
||||
spots.append(at)
|
||||
if spots.size() < TUNNEL_GROUP_MIN:
|
||||
continue
|
||||
for i in range(spots.size() - 1, 0, -1):
|
||||
var j := rng.randi_range(0, i)
|
||||
var held := spots[i]
|
||||
spots[i] = spots[j]
|
||||
spots[j] = held
|
||||
for i in mini(size, spots.size()):
|
||||
# A fresh definition per member: apply_to_enemy mutates in place,
|
||||
# and sharing one object would scale it once per member.
|
||||
var member := def if i == 0 else flavour.apply_to_enemy(Content.enemy(def.id))
|
||||
world.spawn_enemy(member, spots[i], rng.randi_range(0, 120))
|
||||
|
||||
|
||||
## Floor tiles of [param leg] that are tunnel rather than room: clear of every
|
||||
## room by a tile, so a group is never standing in a doorway, and outside the
|
||||
## boss arena.
|
||||
func _tunnel_tiles(leg: Rect2i) -> Array[Vector2i]:
|
||||
var out: Array[Vector2i] = []
|
||||
for ty in range(leg.position.y, leg.end.y):
|
||||
for tx in range(leg.position.x, leg.end.x):
|
||||
if world.map.at(tx, ty) != MapGrid.Kind.FLOOR:
|
||||
continue
|
||||
var here := Vector2i(tx, ty)
|
||||
if boss_room.has_point(here):
|
||||
continue
|
||||
var in_room := false
|
||||
for r in rooms:
|
||||
if r.grow(1).has_point(here):
|
||||
in_room = true
|
||||
break
|
||||
if not in_room:
|
||||
out.append(here)
|
||||
return out
|
||||
|
||||
|
||||
## The furthest any enemy in the game notices a player from.
|
||||
static func _widest_aggro() -> float:
|
||||
var widest := 0.0
|
||||
for id in Content.ALL_ENEMIES:
|
||||
widest = maxf(widest, Content.enemy(id).aggro_range)
|
||||
return widest
|
||||
|
||||
|
||||
func _pick_enemy(rng: RandomNumberGenerator) -> EnemyDef:
|
||||
|
||||
Reference in new issue
Block a user