Add Ship Routes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
01a351a865
commit
63eebfc8bd
15 changed files with 1426 additions and 2 deletions
81
ShipRoutes/tools/icons.py
Normal file
81
ShipRoutes/tools/icons.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
"""Draws the map marker textures as 64x64 white-on-transparent TGAs (tinted in game).
|
||||
usage: python3 icons.py <Icons dir>"""
|
||||
import math, os, struct, sys
|
||||
|
||||
N, SS = 64, 4 # size, supersampling
|
||||
|
||||
|
||||
def seg_dist(px, py, ax, ay, bx, by):
|
||||
dx, dy = bx - ax, by - ay
|
||||
t = max(0.0, min(1.0, ((px - ax) * dx + (py - ay) * dy) / (dx * dx + dy * dy)))
|
||||
return math.hypot(px - ax - t * dx, py - ay - t * dy)
|
||||
|
||||
|
||||
def in_tri(px, py, a, b, c):
|
||||
def s(p, q, r):
|
||||
return (p[0] - r[0]) * (q[1] - r[1]) - (q[0] - r[0]) * (p[1] - r[1])
|
||||
d1, d2, d3 = s((px, py), a, b), s((px, py), b, c), s((px, py), c, a)
|
||||
neg = d1 < 0 or d2 < 0 or d3 < 0
|
||||
pos = d1 > 0 or d2 > 0 or d3 > 0
|
||||
return not (neg and pos)
|
||||
|
||||
|
||||
def disc(x, y):
|
||||
return math.hypot(x - 32, y - 32) <= 30
|
||||
|
||||
|
||||
def ring(x, y):
|
||||
return 25.5 <= math.hypot(x - 32, y - 32) <= 30
|
||||
|
||||
|
||||
def anchor(x, y):
|
||||
if abs(math.hypot(x - 32, y - 13) - 4.5) <= 1.8: # eye
|
||||
return True
|
||||
if seg_dist(x, y, 32, 17, 32, 51) <= 2.2: # shank
|
||||
return True
|
||||
if seg_dist(x, y, 23, 23, 41, 23) <= 2.0: # stock
|
||||
return True
|
||||
r = math.hypot(x - 32, y - 33)
|
||||
if y >= 33 and abs(r - 17) <= 2.2: # arms
|
||||
return True
|
||||
for side in (-1, 1): # flukes
|
||||
if in_tri(x, y, (32 + side * 17, 30), (32 + side * 12, 38), (32 + side * 22, 38)):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def zeppelin(x, y):
|
||||
if ((x - 34) / 21) ** 2 + ((y - 24) / 11) ** 2 <= 1: # envelope
|
||||
return True
|
||||
for a, b, c in (((15, 24), (6, 14), (12, 24)), ((15, 24), (6, 34), (12, 24))): # tail fins
|
||||
if in_tri(x, y, a, b, c):
|
||||
return True
|
||||
if seg_dist(x, y, 9, 15, 9, 33) <= 2:
|
||||
return True
|
||||
if 26 <= x <= 42 and 40 <= y <= 47: # gondola
|
||||
return True
|
||||
if seg_dist(x, y, 29, 33, 29, 40) <= 1.3 or seg_dist(x, y, 39, 33, 39, 40) <= 1.3:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def arrow(x, y): # points right, rotated in game
|
||||
if seg_dist(x, y, 12, 32, 44, 32) <= 4:
|
||||
return True
|
||||
return in_tri(x, y, (54, 32), (36, 18), (36, 46))
|
||||
|
||||
|
||||
def write(path, fn):
|
||||
px = bytearray()
|
||||
for j in range(N):
|
||||
for i in range(N):
|
||||
hits = sum(fn(i + (a + 0.5) / SS, j + (b + 0.5) / SS) for a in range(SS) for b in range(SS))
|
||||
alpha = round(255 * hits / (SS * SS))
|
||||
px += bytes((255, 255, 255, alpha))
|
||||
header = struct.pack("<BBBHHBHHHHBB", 0, 0, 2, 0, 0, 0, 0, 0, N, N, 32, 0x28)
|
||||
open(path, "wb").write(header + px)
|
||||
|
||||
|
||||
out = sys.argv[1]
|
||||
for name, fn in (("disc", disc), ("ring", ring), ("anchor", anchor), ("zeppelin", zeppelin), ("arrow", arrow)):
|
||||
write(os.path.join(out, name + ".tga"), fn)
|
||||
Loading…
Add table
Add a link
Reference in a new issue