#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Diagnostic détaillé d'un seed : pourquoi le chemin ennemi->joueur casse.""" import sys sys.path.insert(0, "tools/sim") from navmesh_connectivity import (load_segments, generate_map, NavMeshSim, standable, exterminate_spawn, JavaRandom, ground_row, LEFT_EDGE, RIGHT_EDGE, SOLO, PLATFORM, WALK, FALL, JUMP) def describe(sim, i, j): n = sim.nav[i][j] tname = {0: "NONE", 1: "PLATFORM", 2: "LEFT_EDGE", 3: "RIGHT_EDGE", 4: "SOLO"}[n.type] types = [ {0:"WALK",1:"FALL",2:"JUMP"}[t] + "->(%d,%d)" % (tgt.x//100, tgt.y//100) for (t, tgt) in n.links ] return "%s liens=%d %s" % (tname, len(n.links), " ".join(types[:8])) def main(seed): segs = load_segments() solid, _, _ = generate_map(seed, segs) sim = NavMeshSim(solid) sim.init((20.0, 20.0)) print("liens :", sim.count_links) rnd = JavaRandom(42) stand = [(i, j) for i in range(sim.W) for j in range(sim.H) if standable(sim, i, j)] pc = (1, 258) # spawn joueur réel # un joueur au hasard 2 étages plus bas pc = [c for c in stand if c[1] >= pc[1] + 3][0] sp = exterminate_spawn(sim, pc, rnd) pos, erow = sp ecol = int(pos[0] / 100) ecell = (ecol, erow - 1) print("joueur :", pc, "ennemi :", ecell, "Δrow =", pc[1] - ecell[1]) en = sim.nav[ecell[0]][ecell[1]] # ecell EST déjà la cellule nav print("cellule ennemi :", describe(sim, *ecell)) pn = sim.get_nav_point(float(pc[0]*100), float(pc[1]*100 - 100)) pi2, pj2 = pc[0], pc[1] print("cellule joueur :", describe(sim, pi2, pj2)) reach = sim.reachable(en) print("joignables depuis ennemi :", len(reach)) rows = sorted(set(p.y // 100 for p in reach)) print("lignes joignables :", rows[:40]) bottom = max(p.y // 100 for p in reach if standable(sim, p.x//100, p.y//100) or True) stand_in_reach = [(p.x//100, p.y//100) for p in reach if standable(sim, p.x//100, p.y//100)] print("debout joignables :", len(stand_in_reach), "plus bas :", max(stand_in_reach, key=lambda c: c[1]) if stand_in_reach else None) # Géométrie autour de l'ennemi : les bords du sol de l'ennemi ei, ej = ecell print("\n-- sol de l'ennemi, ligne %d, colonnes %d±6 --" % (ej, ei)) for x in range(max(0, ei-6), min(sim.W, ei+7)): if standable(sim, x, ej): print(" (%d,%d) %s" % (x, ej, describe(sim, x, ej))) # colonnes : où est le sol sous l'ennemi ? print("\n-- profil vertical colonne par colonne (%d±6), lignes %d..%d --" % (ei, ej-1, ej+12)) for x in range(max(0, ei-6), min(sim.W, ei+7)): prof = "".join("#" if sim.coll(x, r) else "." for r in range(ej-1, ej+12)) print(" col %3d : %s" % (x, prof)) if __name__ == "__main__": main(int(sys.argv[1]) if len(sys.argv) > 1 else 1000000)