Playtest fixes: smoke by engine, searchlights, far launch sites that load their chunks, air defence balance, last chance and radar-cued shots, radars in smart raids, echo, Windows release build from a tag
Smoke: one rule by engine, no heat on trails, no trail on P1-SUN. Searchlights: two lamps a target, off with an empty sky. Halos fade before their reach and their sum is limited. Launch sites load chunks through the server thread, go off-map as a last resort, and reach 4000 blocks. Air defence: ranges x1.5, shots grow with urgency, claims released, /airdef lastchance, long shots on a big radar's tracks. Build: rust-toolchain.toml, airdef.py check, generator manifest and --check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+116
-1
@@ -7,17 +7,21 @@
|
||||
python3 tools/airdef.py install # положить мод в папку игры и включить
|
||||
python3 tools/airdef.py play [аргументы игры] # запустить форк на папке игры
|
||||
python3 tools/airdef.py all # всё по порядку: fork, game, mod, install
|
||||
python3 tools/airdef.py check # совпадают ли форк, упаковщик, уровень API мода и ресурсы
|
||||
|
||||
Переменные окружения: HORIZON_HOME (папка игры), HORIZON_RESOURCES (подготовленные ресурсы
|
||||
Minecraft 26.3), AIRDEF_GAME (готовый horizon-client вместо собранного).
|
||||
"""
|
||||
import glob
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -165,11 +169,122 @@ def play(args):
|
||||
run([exe, "--resources", resources(), *args], cwd=home)
|
||||
|
||||
|
||||
def fork_api():
|
||||
"""Новейший уровень API форка и его таблица функций (horizon-mods/src/api_level.rs); None без форка."""
|
||||
try:
|
||||
text = (FORK / "crates" / "horizon-mods" / "src" / "api_level.rs").read_text(encoding="utf-8")
|
||||
except OSError:
|
||||
return None
|
||||
try:
|
||||
level = int(re.search(r"pub const LEVEL: u32 = (\d+);", text).group(1))
|
||||
table = text[text.index("pub const FUNCTIONS"):]
|
||||
table = table[:table.index("];")]
|
||||
except (AttributeError, ValueError):
|
||||
return None
|
||||
return level, [(name, int(lvl)) for name, lvl in re.findall(r'\("([a-z.\-]+)", (\d+)\)', table)]
|
||||
|
||||
|
||||
def needed_level(wasm: bytes, table) -> tuple:
|
||||
"""Уровень, который нужен модулю: самая новая функция, которую он импортирует (как api_level::needed).
|
||||
|
||||
В компоненте имя функции записано как 0x00, длина, UTF-8 имя; по этим байтам и ищем."""
|
||||
need = (0, None)
|
||||
for name, level in table:
|
||||
part = name.split(".", 1)[1].encode()
|
||||
if level > need[0] and b"\x00" + bytes([len(part)]) + part in wasm:
|
||||
need = (level, name)
|
||||
return need
|
||||
|
||||
|
||||
def game_level():
|
||||
"""Уровень, который игра записала в себя (метка horizon-mod-api-level:NNNN;); None, если игры нет.
|
||||
Игра без метки считается уровня 0, как в api_level::read_mark."""
|
||||
try:
|
||||
exe = built_game()
|
||||
except SystemExit:
|
||||
return None
|
||||
if not exe.exists():
|
||||
return None
|
||||
found = re.search(rb"horizon-mod-api-level:(\d{4});", exe.read_bytes())
|
||||
return int(found.group(1)) if found else 0
|
||||
|
||||
|
||||
def check():
|
||||
"""Говорит прямо, совпадают ли форк, упаковщик, уровень API мода с игрой и ресурсы. Код 0 — да, 1 — нет."""
|
||||
commit = (ROOT / "HORIZON_COMMIT").read_text().strip()
|
||||
patches = sorted((ROOT / "horizon-patches").glob("*.patch"))
|
||||
stamp = fork_stamp(commit, patches)
|
||||
problems = []
|
||||
|
||||
def line(name, ok, text):
|
||||
print(f"[{'ok' if ok else 'нет'}] {name}: {text}")
|
||||
if not ok:
|
||||
problems.append(name)
|
||||
|
||||
stamp_file = FORK / ".git" / "airdef-stamp"
|
||||
fork_ok = stamp_file.exists() and stamp_file.read_text().strip() == stamp
|
||||
line("форк", fork_ok, f"коммит {commit[:12]}, патчей {len(patches)}" if fork_ok else
|
||||
"horizon/ не собран из HORIZON_COMMIT и horizon-patches/: python3 tools/airdef.py fork")
|
||||
|
||||
tool = shutil.which("cargo-horizon-mod") or str(Path.home() / ".cargo" / "bin" / ("cargo-horizon-mod" + EXE))
|
||||
packer_stamp = FORK / ".git" / "airdef-packer-stamp"
|
||||
packer_ok = Path(tool).exists() and packer_stamp.exists() and packer_stamp.read_text().strip() == stamp
|
||||
line("упаковщик", packer_ok, "собран из этого форка" if packer_ok else
|
||||
"не установлен или собран из другого форка: python3 tools/airdef.py mod")
|
||||
|
||||
api = fork_api()
|
||||
try:
|
||||
mod_file = hmod()
|
||||
except SystemExit:
|
||||
mod_file = None
|
||||
if api is None:
|
||||
line("уровень API", False, "нет или не читается horizon/crates/horizon-mods/src/api_level.rs: python3 tools/airdef.py fork")
|
||||
elif mod_file is None:
|
||||
line("уровень API", False, "нет airdef.hmod: python3 tools/airdef.py mod")
|
||||
else:
|
||||
level, table = api
|
||||
with zipfile.ZipFile(mod_file) as z:
|
||||
wasm = z.read("mod.wasm") if "mod.wasm" in z.namelist() else b""
|
||||
need, function = needed_level(wasm, table)
|
||||
game = game_level()
|
||||
text = f"мод нужен {need} ({function}), форк {level}, игра " + ("не собрана" if game is None else str(game))
|
||||
if game is None:
|
||||
line("уровень API", False, text + ": python3 tools/airdef.py game")
|
||||
else:
|
||||
# Сравнивается уровень, не код: одинаковый уровень не доказывает одинаковые патчи.
|
||||
supported = need <= game and game == level
|
||||
line("уровень API", supported, text if supported else
|
||||
text + ": игра не поддерживает мод или собрана из другого форка")
|
||||
|
||||
try:
|
||||
res = resources()
|
||||
except SystemExit as e:
|
||||
res = None
|
||||
line("ресурсы", False, str(e.code))
|
||||
if res is not None:
|
||||
try:
|
||||
preparer = (FORK / "crates" / "horizon-prepare" / "src" / "lib.rs").read_text(encoding="utf-8")
|
||||
schema = int(re.search(r"pub const SCHEMA: i64 = (\d+);", preparer).group(1))
|
||||
except (OSError, AttributeError):
|
||||
schema = None
|
||||
try:
|
||||
manifest = json.loads((res / "horizon-resources.json").read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError):
|
||||
manifest = {}
|
||||
ok = schema is not None and manifest.get("schema") == schema and manifest.get("minecraft") == "26.3"
|
||||
line("ресурсы", ok, f"{res}, схема {schema}, Minecraft 26.3" if ok else
|
||||
f"{res}: схема {manifest.get('schema')}, Minecraft {manifest.get('minecraft')}; нужны схема {schema} и Minecraft 26.3")
|
||||
|
||||
if problems:
|
||||
sys.exit("Не совпадает: " + ", ".join(problems) + ".")
|
||||
print("Всё совпадает: форк, упаковщик, уровень API мода и ресурсы.")
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(__doc__)
|
||||
cmd, rest = sys.argv[1], sys.argv[2:]
|
||||
steps = {"fork": fork, "game": game, "mod": mod, "install": install}
|
||||
steps = {"fork": fork, "game": game, "mod": mod, "install": install, "check": check}
|
||||
if cmd == "play":
|
||||
play(rest)
|
||||
elif cmd == "all":
|
||||
|
||||
Reference in New Issue
Block a user