"""The war room (Step 3e part 1; Dillon's design, 2026-11-12, DESIGN-3e-war-room.md). Panda3D. You come in through the bunker door and the view glides up to the command table. On the table is an old pre-war paper map of Missouri, coloured by the campaign (mapstate.py, the same rules as the 2D map). Staff work in the background: a radio operator, a clerk at the cabinets, an officer at the board. Every shape is built in code (shapes.py). The pieces (part 2): the fort is a concrete bunker block with a flag; the unit is two toy soldiers on a base beside it; each mission is a pin with a numbered flag in the colour of the group you'd help (numbered as the 2D map numbers them); each region has a wooden block, painted the colour of the group that holds it or leans to it (tall if held, short if leaning, bare wood if undecided), capped white for an ally and black for a hostile. Click a piece for its briefing (briefs.py). Time on the table (part 3): click a mission's flag, then "Plan the unit" (the same plan as the 2D window: squads and travel). The unit's piece sets out from the fort and crosses the map a day at a time (DAY_SECONDS each) while the day counter ticks and the map changes with the news; at the end of the road the view leans in over the table, then the battle opens. When it's over the piece slides home. Close the room on the road and the trip carries on next time (here or in the 2D window). The base (Step 3f, 2026-11-16): the war room is the command room of the fort, cut away (cutaway.py); the tabs along the bottom go room to room. The map is seen from above: the mouse wheel zooms on the point under the mouse, right-drag or the arrow keys move across it, Home shows it all. python -m p02.warroom the main menu (menu.py), then the base and the war room python -m p02.warroom --shot FILE [--at S] render one frame offscreen, S seconds in, and save it """ from __future__ import annotations import math import sys import tkinter as tk from panda3d.core import (AmbientLight, AntialiasAttrib, BitMask32, CollisionHandlerQueue, CollisionNode, CollisionRay, CollisionTraverser, DirectionalLight, LineSegs, NodePath, PointLight, TextNode, Vec4, loadPrcFileData) from . import briefs as B from . import campaign as K from . import data as D from . import mapstate as MS from . import shapes as S TABLE = (8.0, 5.6) # the table top, metres TABLE_Z = 0.95 # its height HALL = 7.0 # floor to ceiling: room for the view over the table MAP_Z = TABLE_Z + 0.03 # the paper on it DOOR_POSE = ((0.0, -13.0, 1.7), (0.0, -4.0, 0.0)) # camera (x, y, z), (heading, pitch, roll) MAX_ZOOM = 6.0 # the map view (Dillon, 2026-11-16): top down, zoom in and out, move across ZOOM_STEP = 1.2 # one click of the mouse wheel OUT_PITCH, IN_PITCH = -89.0, -62.0 # straight down when zoomed out; tilting as you zoom in, so pieces read PAN_SPEED = 0.9 # arrow keys: the share of the view's width crossed in a second OVERHEAD_Z = 3.1 # above this the ceiling, beams and lamp would block the view: hidden INTRO_SECONDS = 2.5 PAPER, INK, WOOD, CONCRETE = "#d8c79c", "#5b4a32", "#5a3d22", "#4a4843" DRAB, SKIN, STEEL = "#4b5320", "#c49a74", "#6b6f6a" TOY_WOOD, BUNKER = "#b08a5a", "#8a877a" PICK = BitMask32.bit(1) # what a click can hit: the pieces, nothing else HINT = ("Click a piece on the table: the fort, your unit, a mission's flag, a region's block.\n" "Mouse wheel: zoom. Right-drag or the arrow keys: move across the map. Home: the whole map.") DAY_SECONDS = 0.8 # a day on the road, on the table LEAN_SECONDS = 1.6 # the view leaning in over the table at the end of the road (and back) HOME_SECONDS = 2.0 # the piece sliding home after the battle def table_xy(x, y): """Map coordinates (missouri.json) -> a point on the table top, the map centred with a margin.""" x0, y0, x1, y1 = MS.extent() s = min((TABLE[0] - 0.6) / (x1 - x0), (TABLE[1] - 0.6) / (y1 - y0)) return (x - (x0 + x1) / 2) * s, (y - (y0 + y1) / 2) * s FOOTPRINT = (-0.3, 0.25, -0.17, 0.06) # a county's pieces around its spot: x from, to; y from, to _SPOTS = None def county_xy(rid): """Where a county's pieces (and name) go on the table: near its middle, nudged until no two counties' pieces, nor the fort's, would touch (spots()).""" return spots()[rid] def spots(): """Every county's spot: start at its middle, then push overlapping footprints apart (each pair along the way they overlap least), the fort and the unit's place by it fixed. Worked out once.""" global _SPOTS if _SPOTS is None: pos = {rid: list(table_xy(*MS.region_centre(rid))) for rid in D.REGIONS} fx, fy = table_xy(*MS.the_map()["fort"]) fixed = [(fx - 0.15, fx + 0.15, fy - 0.12, fy + 0.42)] # the fort, and the unit beside it x0, x1, y0, y1 = FOOTPRINT gap = 0.03 for _ in range(400): moved = False keys = list(pos) boxes = [(k, (pos[k][0] + x0, pos[k][0] + x1, pos[k][1] + y0, pos[k][1] + y1)) for k in keys] for i, (a, A) in enumerate(boxes): for b, B in boxes[i + 1:] + [(None, F) for F in fixed]: ox = min(A[1], B[1]) - max(A[0], B[0]) + gap oy = min(A[3], B[3]) - max(A[2], B[2]) + gap if ox <= 0 or oy <= 0: continue moved = True share = 1.0 if b is None else 0.5 if ox < oy: d = ox * share * (1 if (A[0] + A[1]) >= (B[0] + B[1]) else -1) pos[a][0] += d if b: pos[b][0] -= d else: d = oy * share * (1 if (A[2] + A[3]) >= (B[2] + B[3]) else -1) pos[a][1] += d if b: pos[b][1] -= d if not moved: break _SPOTS = {k: tuple(v) for k, v in pos.items()} return _SPOTS def lerp(a, b, t): return tuple(p + (q - p) * t for p, q in zip(a, b)) def ease(t): t = max(0.0, min(1.0, t)) return t * t * (3 - 2 * t) def map_pose(view, fov): """The map view -> camera ((x, y, z), (h, p, r)). view: (x, y, zoom), the point on the table the view centres on, and how far in (1 = the whole table). fov: the lens's (horizontal, vertical) degrees. Zoomed out it looks straight down; zoomed in it tilts a little, so the pieces stand up.""" x, y, zoom = view d = whole_map_distance(fov) / zoom k = (zoom - 1) / (MAX_ZOOM - 1) p = OUT_PITCH + (IN_PITCH - OUT_PITCH) * k r = math.radians(p) return (x, y - d * math.cos(r), MAP_Z - d * math.sin(r)), (0.0, p, 0.0) def whole_map_distance(fov): """How far from the table the camera has to be to see all of it (with a margin).""" hw, hd = TABLE[0] / 2 + 0.3, TABLE[1] / 2 + 0.3 return max(hw / math.tan(math.radians(fov[0] / 2)), hd / math.tan(math.radians(fov[1] / 2))) def seen_half(view, fov): """Half the width and depth of the table the map view takes in (near enough, for clamping).""" d = whole_map_distance(fov) / view[2] return d * math.tan(math.radians(fov[0] / 2)), d * math.tan(math.radians(fov[1] / 2)) def clamp_view(view, fov): """Keep the zoom in range and the view over the map: zoomed right out it can't move at all.""" x, y, zoom = view zoom = max(1.0, min(MAX_ZOOM, zoom)) sw, sd = seen_half((x, y, zoom), fov) mx, my = max(0.0, TABLE[0] / 2 - sw), max(0.0, TABLE[1] / 2 - sd) return max(-mx, min(mx, x)), max(-my, min(my, y)), zoom def zoom_at(view, factor, point, fov): """Zoom by factor, keeping the table point under the mouse (or None: the centre) where it is.""" x, y, zoom = view new = max(1.0, min(MAX_ZOOM, zoom * factor)) if point is not None: keep = 1 - zoom / new x, y = x + (point[0] - x) * keep, y + (point[1] - y) * keep return clamp_view((x, y, new), fov) def figure(name, colour=DRAB): """A staff member: legs, body, arms, head, cap. Origin at the feet, facing -y.""" f = NodePath(name) for side in (-1, 1): S.box(f"{name}-leg", 0.14, 0.16, 0.8, "#3b3f22", (side * 0.1, 0, 0)).reparentTo(f) S.box(f"{name}-body", 0.44, 0.26, 0.62, colour, (0, 0, 0.8)).reparentTo(f) arms = [] for side in (-1, 1): pivot = f.attachNewNode(f"{name}-shoulder") pivot.setPos(side * 0.29, 0, 1.38) S.box(f"{name}-arm", 0.12, 0.14, 0.6, colour, (0, 0, -0.6)).reparentTo(pivot) arms.append(pivot) head = f.attachNewNode(f"{name}-neck") head.setPos(0, 0, 1.42) S.sphere(f"{name}-head", 0.15, SKIN).reparentTo(head) S.cylinder(f"{name}-cap", 0.16, 0.08, colour).reparentTo(head) head.find(f"{name}-cap").setZ(0.09) return f, arms, head class WarRoom: """The room, built under base.render. t: seconds since you came in (drives every motion), so a frame can be made at any moment, live or offscreen.""" def __init__(self, base, camp, save=None): self.base, self.c, self.save_fn = base, camp, save self.journey = None # the unit's trip as it plays on the table (see go_on) self.tk = None # Tk, for the plan and the battle windows (made when needed) self.on_arrive = self.open_battle # (mission, battle): the battle at the end of the road self.root = base.render.attachNewNode("war room") base.camLens.setFov(60) base.setBackgroundColor(0.08, 0.08, 0.07) self.counties = {} # fips -> NodePath of its paper piece self.colours = {} # fips -> the colour it was drawn self.build_room() self.build_table() self.build_map() self.build_staff() self.build_pieces() self.view = (0.0, 0.0, 1.0) # the map view: centred on (x, y) of the table, zoom (see map_pose) self.drag = None # right mouse held: (mouse x, y, view) when it went down self.build_brief() self.build_controls() self.build_hud() self.light() self.t = 0.0 self.came_in = 0.0 # when you last came in by the door (the glide up to the table) self.shown = True # False while you're out in the base (cutaway.py) if self.c.trip and self.c.trip.get("stage") == "road": self.set_out(0.0) # closed on the road last time: carry on from where it was self.at(0.0) # ── the room ── def build_room(self): r = self.root S.box("floor", 16, 22, 0.1, CONCRETE, (0, -4, -0.1)).reparentTo(r) S.box("back wall", 16, 0.3, HALL, "#5d5a52", (0, 7, 0)).reparentTo(r) up = self.overhead = r.attachNewNode("overhead") # hidden when the view is above it S.box("ceiling", 16, 22, 0.2, "#3a3935", (0, -4, HALL)).reparentTo(up) for y in (-10, -4, 2): S.box("beam", 16, 0.4, 0.35, "#45433e", (0, y, HALL - 0.35)).reparentTo(up) for side in (-1, 1): S.box("side wall", 0.3, 22, HALL, "#57544d", (side * 8, -4, 0)).reparentTo(r) for y in (-10, -4, 2): S.box("pillar", 0.5, 0.5, HALL, "#64615a", (side * 7.6, y, 0)).reparentTo(r) # the doorway you come in by, behind the start for x in (-1.1, 1.1): S.box("door post", 0.3, 0.3, 2.6, STEEL, (x, -14.6, 0)).reparentTo(r) S.box("door head", 2.5, 0.3, 0.3, STEEL, (0, -14.6, 2.6)).reparentTo(r) # the board on the back wall, papers pinned to it S.box("board", 7, 0.1, 2.2, "#7a5c3a", (0, 6.8, 1.3)).reparentTo(r) for i, (x, z, w, h) in enumerate(((-2.8, 2.4, 0.7, 0.9), (-1.6, 2.6, 0.9, 0.6), (-0.3, 2.3, 1.1, 0.8), (1.2, 2.6, 0.6, 0.7), (2.4, 2.3, 0.9, 0.9), (-2.2, 1.5, 1.0, 0.5), (0.6, 1.5, 0.8, 0.6), (2.0, 1.45, 0.7, 0.5))): S.box(f"paper {i}", w, 0.02, h, "#e9e0c8" if i % 3 else "#d9cfae", (x, 6.74, z), bottom=False).reparentTo(r) S.cylinder("clock", 0.3, 0.06, "#e8e4d8").reparentTo(r) r.find("clock").setPosHpr(5.0, 6.84, 3.3, 0, 90, 0) # filing cabinets on the left, the radio desk on the right for i in range(4): S.box("cabinet", 0.9, 0.7, 1.5, "#596356", (-7.2, 3.5 - i * 1.0, 0)).reparentTo(r) S.box("radio desk", 1.0, 2.4, 0.8, WOOD, (6.9, 1.5, 0)).reparentTo(r) S.box("radio set", 0.6, 1.4, 0.6, "#3d4a3a", (7.1, 1.5, 0.8)).reparentTo(r) for i in range(4): S.cylinder("dial", 0.06, 0.03, "#d9d2b8").reparentTo(r) r.findAllMatches("dial")[i].setPosHpr(6.79, 1.0 + i * 0.33, 1.15, 0, 0, 90) S.box("chair", 0.5, 0.5, 0.48, WOOD, (6.0, 1.5, 0)).reparentTo(r) # the lamp over the table S.cylinder("lamp cord", 0.015, HALL - 3.6, "#222222").reparentTo(up) up.find("lamp cord").setPos(0, 0, 3.6) S.cylinder("lamp shade", 0.55, 0.35, "#2f3a2a", r_top=0.12, cap=False).reparentTo(up) up.find("lamp shade").setPos(0, 0, 3.25) def build_table(self): r = self.root w, d = TABLE S.box("table top", w + 0.3, d + 0.3, 0.1, WOOD, (0, 0, TABLE_Z - 0.1)).reparentTo(r) for x in (-w / 2, w / 2): for y in (-d / 2, d / 2): S.box("table leg", 0.16, 0.16, TABLE_Z - 0.1, "#4a3220", (x, y, 0)).reparentTo(r) S.box("paper", w - 0.2, d - 0.2, 0.02, PAPER, (0, 0, TABLE_Z)).reparentTo(r) def build_map(self): m = MS.the_map() self.map = self.root.attachNewNode("map") regions = MS.region_of() for fips, county in m["counties"].items(): colour, hostile = MS.county_colour(self.c, fips, regions) if hostile: colour = MS.blend(colour, "#6b6b6b", 0.35) # hostile: greyed (the 2D map hatches) rings = [[table_xy(x, y) for x, y in ring] for ring in county["outline"]] n = S.flat_polygon(fips, rings, MAP_Z, MS.blend(colour, PAPER, 0.15)) # printed on old paper n.reparentTo(self.map) self.counties[fips], self.colours[fips] = n, colour ink = LineSegs("county lines") ink.setThickness(1.2) ink.setColor(*S.rgba(MS.blend(MS.EDGE, INK, 0.5))) for county in m["counties"].values(): for ring in county["outline"]: pts = [table_xy(x, y) for x, y in ring] ink.moveTo(*pts[0], MAP_Z + 0.002) for p in pts[1:]: ink.drawTo(*p, MAP_Z + 0.002) self.map.attachNewNode(ink.create()) water = LineSegs("rivers") water.setColor(*S.rgba(MS.blend(MS.RIVER, PAPER, 0.2))) for river in m["rivers"]: water.setThickness(3 if river["name"] in ("Missouri", "Mississippi") else 2) pts = [table_xy(x, y) for x, y in river["line"]] water.moveTo(*pts[0], MAP_Z + 0.004) for p in pts[1:]: water.drawTo(*p, MAP_Z + 0.004) self.map.attachNewNode(water.create()) grid = LineSegs("survey grid") grid.setThickness(1) grid.setColor(*S.rgba(MS.blend(PAPER, INK, 0.25))) w, d = TABLE[0] - 0.3, TABLE[1] - 0.3 for i in range(9): x = -w / 2 + w * i / 8 grid.moveTo(x, -d / 2, MAP_Z - 0.005) grid.drawTo(x, d / 2, MAP_Z - 0.005) for i in range(7): y = -d / 2 + d * i / 6 grid.moveTo(-w / 2, y, MAP_Z - 0.005) grid.drawTo(w / 2, y, MAP_Z - 0.005) self.map.attachNewNode(grid.create()) self.label("STATE OF MISSOURI\nCOUNTY SURVEY - PRE-WAR ISSUE", (-TABLE[0] / 2 + 2.1, -TABLE[1] / 2 + 0.5), 0.14, align=TextNode.ACenter) for rid, info in D.REGIONS.items(): x, y = county_xy(rid) self.label(info["counties"][0].upper(), (x, y + 0.1), 0.06, align=TextNode.ACenter) # a county each tx, ty = table_xy(*info["town_xy"]) # the settlement both sides want (scenery) town = self.map.attachNewNode(f"town {rid}") for dx, dy, h in ((-0.018, 0.0, 0.03), (0.012, 0.012, 0.022), (0.01, -0.016, 0.026)): S.box("house", 0.022, 0.022, h, "#6e665a", (dx, dy, 0)).reparentTo(town) town.setPos(tx, ty, MAP_Z) self.label(info["town"], (tx, ty - 0.055), 0.032, align=TextNode.ACenter) def label(self, text, xy, size, align=TextNode.ALeft): tn = TextNode("label") tn.setText(text) tn.setAlign(align) tn.setTextColor(*S.rgba(INK)) n = self.map.attachNewNode(tn) n.setScale(size) n.setPosHpr(xy[0], xy[1], MAP_Z + 0.006, 0, -90, 0) return n # ── the staff ── def build_staff(self): r = self.root self.radio_op, _, self.radio_head = figure("radio operator") self.radio_op.reparentTo(r) self.radio_op.setPosHpr(6.1, 1.5, -0.35, -90, 0, 0) # seated at the set, facing it self.clerk, self.clerk_arms, _ = figure("clerk", "#5a5f3c") self.clerk.reparentTo(r) self.officer, self.officer_arms, _ = figure("officer", "#3f4a2c") self.officer.reparentTo(r) self.officer.setPosHpr(1.5, 5.9, 0, 180, 0, 0) # at the board, back to you self.staff = [self.radio_op, self.clerk, self.officer] # ── the pieces ── def piece(self, key): """A new piece on the table, tagged with key: what a click on it reports.""" n = self.pieces_root.attachNewNode(f"piece {key}") n.setTag("piece", key) self.pieces[key] = n return n def build_pieces(self): c = self.c self.pieces_root = self.root.attachNewNode("pieces") self.pieces = {} # key -> NodePath: "fort", "unit", "mission:", "region:" fx, fy = table_xy(*MS.the_map()["fort"]) fort = self.piece("fort") S.box("bunker", 0.34, 0.26, 0.11, BUNKER).reparentTo(fort) S.box("bunker roof", 0.38, 0.30, 0.03, "#77746a", (0, 0, 0.11)).reparentTo(fort) S.box("gun slit", 0.2, 0.01, 0.025, "#222222", (0, -0.131, 0.06)).reparentTo(fort) S.cylinder("fort pole", 0.008, 0.2, STEEL, sides=6).reparentTo(fort) fort.find("fort pole").setPos(-0.12, 0.08, 0.14) S.box("fort flag", 0.11, 0.008, 0.07, MS.HOME, (-0.065, 0.08, 0.27)).reparentTo(fort) # flies over the roof fort.setPos(fx, fy, MAP_Z) fort.setScale(0.7) # Pulaski is one county among 24 small ones # the unit: two toy soldiers on a base, beside the fort (or at the mission, when out) unit = self.piece("unit") S.cylinder("unit base", 0.1, 0.025, TOY_WOOD, sides=12).reparentTo(unit) for i, x in enumerate((-0.04, 0.04)): toy, _, _ = figure(f"toy soldier {i}", DRAB) toy.reparentTo(unit) toy.setPos(x, 0, 0.025) toy.setScale(0.12) self.unit_home = (fx + 0.05, fy + 0.3) # just north of the fort # a block for every region for rid in D.REGIONS: reg = c.regions[rid] x, y = county_xy(rid) n = self.piece(f"region:{rid}") if reg.owner is not None: colour, h = MS.GROUP_COLOURS[reg.owner], 0.16 elif reg.lean: colour, h = MS.GROUP_COLOURS[0 if reg.lean > 0 else 1], 0.08 else: colour, h = TOY_WOOD, 0.06 S.box("block", 0.09, 0.09, h, colour).reparentTo(n) if reg.owner is not None: S.box("cap", 0.1, 0.1, 0.025, "#f2efe6" if reg.ally else "#1b1b1b", (0, 0, h)).reparentTo(n) n.setPos(x, y - 0.05, MAP_Z) # under the region's name # a pin and a numbered flag for every mission, as the 2D map numbers them per_region = {} for i, m in enumerate(B.mission_order(c)): x, y = county_xy(m.region) k = per_region.get(m.region, 0) per_region[m.region] = k + 1 n = self.piece(f"mission:{m.id}") S.cylinder("pin", 0.01, 0.28, STEEL, sides=6).reparentTo(n) S.sphere("pin head", 0.025, "#d9d2b8").reparentTo(n) n.find("pin head").setZ(0.29) colour = MS.GROUP_COLOURS[m.group] if m.group is not None else MS.UNPICKED # cream: no side yet S.box("flag", 0.13, 0.012, 0.09, colour, (0.07, 0, 0.185)).reparentTo(n) for face, h in ((-1, 0), (1, 180)): # the number on both faces tn = TextNode("flag number") tn.setText(str(i + 1)) tn.setAlign(TextNode.ACenter) tn.setTextColor(1, 1, 1, 1) t = n.attachNewNode(tn) t.setScale(0.07) t.setPosHpr(0.07, face * 0.0065, 0.205, h, 0, 0) n.setPos(x + 0.1, y - 0.02 - k * 0.11, MAP_Z) # east of the block, a second one below it where = self.unit_home if c.trip: # out (on the road, go_on() moves it) where = self.trip_target() unit.setPos(*where, MAP_Z) self.pieces_root.setCollideMask(PICK) # every solid of every piece, once they're all built def trip_target(self): """Where the unit's piece stands at the end of its road: just south of the mission's pin (or, if the pin is gone, of the region's block).""" t = self.c.trip rid = t.get("region") or next((m.region for m in self.c.missions if m.id == t["mission"]), None) if not rid: return self.unit_home x, y = county_xy(rid) return x - 0.18, y - 0.03 # west of the county's block def rebuild(self): """The day changed: recolour the map and reset the pieces from the campaign.""" self.map.removeNode() self.pieces_root.removeNode() self.counties, self.colours = {}, {} self.build_map() self.build_pieces() if self.chosen and self.chosen not in self.pieces and self.chosen != "unit": self.chosen = None self.show(self.chosen) self.update_hud() # ── clicking a piece ── def build_brief(self): for old in (self.base.aspect2d.findAllMatches("war room brief") + self.base.aspect2d.findAllMatches("war room plan") + self.base.camera.findAllMatches("click ray")): old.removeNode() # a room built before this one (tests) tn = TextNode("war room brief") tn.setWordwrap(34) tn.setTextColor(*S.rgba("#f2ead2")) tn.setCardColor(0.1, 0.09, 0.07, 0.82) tn.setCardAsMargin(0.6, 0.6, 0.4, 0.4) self.brief_text = tn n = self.brief_np = self.base.aspect2d.attachNewNode(tn) n.setScale(0.045) n.setPos(-self.base.getAspectRatio() + 0.06, 0, -0.58) # over the base's tabs from direct.gui.DirectGui import DirectButton self.plan_btn = DirectButton(text="Plan the unit", scale=0.05, pad=(0.4, 0.25), pos=(self.base.getAspectRatio() - 0.3, 0, -0.76), command=self.plan, text_fg=(0.95, 0.92, 0.82, 1), frameColor=(0.24, 0.27, 0.16, 1)) self.plan_btn.setName("war room plan") self.plan_btn.hide() self.chosen = None self.show(None) self.picker = CollisionTraverser("war room picker") self.hits = CollisionHandlerQueue() ray = CollisionNode("click ray") ray.setFromCollideMask(PICK) ray.setIntoCollideMask(BitMask32.allOff()) self.ray = CollisionRay() ray.addSolid(self.ray) self.ray_node = self.base.camera.attachNewNode(ray) self.picker.addCollider(self.ray_node, self.hits) self.base.accept("mouse1", self.click) def pick(self, mx, my): """The piece under the screen point (mx, my), each -1..1 across the window -> key, or None.""" self.ray.setFromLens(self.base.camNode, mx, my) self.picker.traverse(self.pieces_root) if not self.hits.getNumEntries(): return None self.hits.sortEntries() return self.hits.getEntry(0).getIntoNodePath().findNetTag("piece").getTag("piece") def brief(self, key): c = self.c if key == "fort": return B.fort_brief(c) if key == "unit": return B.unit_brief(c) kind, _, what = key.partition(":") if kind == "region": return B.region_brief(c, what) order = B.mission_order(c) m = next(m for m in order if m.id == int(what)) return f"Mission {order.index(m) + 1}. " + B.mission_brief(c, m) def show(self, key): self.chosen = key self.brief_text.setText(self.brief(key) if key else HINT) if self.can_plan() and self.shown: self.plan_btn.show() else: self.plan_btn.hide() def can_plan(self): """A mission is chosen, the unit is home, someone is ready, and the campaign is on.""" return bool(self.chosen and self.chosen.startswith("mission:") and self.journey is None and not (self.c.trip and self.c.trip.get("stage") == "road") and self.c.ready() and not self.c.outcome) def set_shown(self, shown, t=None): """In the room (True), or out in the base (False): the room, its briefing and the plan button hidden, while the trip plays on. Coming in at time t: the glide from the door again.""" self.shown = shown for n in (self.root, self.brief_np): n.show() if shown else n.hide() if t is not None: self.came_in = t self.show(self.chosen) def click(self): mw = self.base.mouseWatcherNode if mw.hasMouse() and not mw.getOverRegion(): # not a click on a button self.show(self.pick(mw.getMouseX(), mw.getMouseY())) # ── the map view: zoom and move (Dillon, 2026-11-16) ── def build_controls(self): b = self.base b.accept("wheel_up", self.wheel, [ZOOM_STEP]) b.accept("wheel_down", self.wheel, [1 / ZOOM_STEP]) b.accept("mouse3", self.drag_start) b.accept("mouse3-up", self.drag_end) b.accept("home", self.whole_map) self.keys_at = None def fov(self): f = self.base.camLens.getFov() return f[0], f[1] def in_map(self): """The map view takes input: in the room, past the glide in, not leaning over the road's end.""" return self.shown and self.t - self.came_in >= INTRO_SECONDS and not self.lean() def table_point(self, mx, my): """The table point under screen point (mx, my), or None (off the table).""" from panda3d.core import Plane, Point2, Point3, Vec3 near, far = Point3(), Point3() if not self.base.camLens.extrude(Point2(mx, my), near, far): return None rel = self.base.render near, far = rel.getRelativePoint(self.base.camera, near), rel.getRelativePoint(self.base.camera, far) hit = Point3() if not Plane(Vec3(0, 0, 1), Point3(0, 0, MAP_Z)).intersectsLine(hit, near, far): return None if abs(hit.x) > TABLE[0] / 2 or abs(hit.y) > TABLE[1] / 2: return None return hit.x, hit.y def mouse(self): """The mouse on screen, (x, y) each -1..1, or None (outside the window, or no window).""" mw = self.base.mouseWatcherNode return (mw.getMouseX(), mw.getMouseY()) if mw is not None and mw.hasMouse() else None def wheel(self, factor): if self.in_map(): self.zoom_on(factor, self.mouse()) def zoom_on(self, factor, at=None): """Zoom by factor, keeping the table point under screen point at (or the middle) under it. zoom_at gets close; the tilt that comes with zooming moves it a little, so put that right.""" point = self.table_point(*at) if at else None self.view = zoom_at(self.view, factor, point, self.fov()) if point is None: return cam = self.base.camera for _ in range(4): cam.setPosHpr(*sum(map_pose(self.view, self.fov()), ())) now = self.table_point(*at) if now is None: break x, y, z = self.view self.view = clamp_view((x + point[0] - now[0], y + point[1] - now[1], z), self.fov()) cam.setPosHpr(*sum(map_pose(self.view, self.fov()), ())) def whole_map(self): if self.in_map(): self.view = (0.0, 0.0, 1.0) def drag_start(self): m = self.mouse() if self.in_map() and m: self.drag = (*m, self.view) def drag_end(self): self.drag = None def drag_to(self, mx, my): """The right mouse held and moved to (mx, my): the map follows the mouse.""" x0, y0, (vx, vy, zoom) = self.drag sw, sd = seen_half((vx, vy, zoom), self.fov()) self.view = clamp_view((vx - (mx - x0) * sw, vy - (my - y0) * sd, zoom), self.fov()) def pan(self, dx, dy, seconds): """Arrow keys held: move the view dx, dy (each -1, 0 or 1) for that long.""" sw, sd = seen_half(self.view, self.fov()) x, y, zoom = self.view step = PAN_SPEED * seconds * 2 self.view = clamp_view((x + dx * sw * step, y + dy * sd * step, zoom), self.fov()) def keys(self, t): """Each frame: the drag, and the arrow (or W A S D) keys held down.""" last, self.keys_at = self.keys_at, t mw, m = self.base.mouseWatcherNode, self.mouse() if self.drag and m: self.drag_to(*m) if last is None or mw is None or not self.in_map(): return from panda3d.core import KeyboardButton as KB down = lambda *ks: any(mw.isButtonDown(k) for k in ks) dx = down(KB.right(), KB.asciiKey("d")) - down(KB.left(), KB.asciiKey("a")) dy = down(KB.up(), KB.asciiKey("w")) - down(KB.down(), KB.asciiKey("s")) if dx or dy: self.pan(dx, dy, min(t - last, 0.1)) # ── the day counter and the news ── def build_hud(self): for old in self.base.aspect2d.findAllMatches("war room day"): old.removeNode() tn = TextNode("war room day") tn.setWordwrap(40) tn.setTextColor(*S.rgba("#f2ead2")) tn.setCardColor(0.1, 0.09, 0.07, 0.82) tn.setCardAsMargin(0.6, 0.6, 0.4, 0.4) self.hud_text = tn n = self.base.aspect2d.attachNewNode(tn) n.setScale(0.045) n.setPos(-self.base.getAspectRatio() + 0.06, 0, 0.92) self.update_hud() def update_hud(self): c, t = self.c, self.c.trip if c.outcome: where = "The campaign is won." if c.outcome == "won" else "The campaign is lost." elif t and t.get("stage") == "road": name = D.REGIONS[t["region"]]["name"] who = (f"A caravan is on the road to {D.REGIONS[t['region']]['town']}" if t.get("caravan") else f"The unit is on the road to {name}") where = f"{who}: day {t['gone'] + 1} of {t['days']}." elif self.journey and self.journey["phase"] == "home": where = "The unit is coming home." elif t: where = "The unit is in battle." else: where = "The unit is at the fort." news = [l for l in c.log[-3:]] self.hud_text.setText(f"Day {c.day}. {where}\n" + "\n".join(news)) # ── time on the table: the unit's trip ── def plan(self): """The plan (campaignview.PlanDialog, in Tk) for the chosen mission.""" if not self.can_plan(): return from .campaignview import PlanDialog m = next(m for m in self.c.missions if f"mission:{m.id}" == self.chosen) self.planner = PlanDialog(self.tk_root(), self.c, m, self.send) def tk_root(self): if self.tk is None: self.tk = tk.Tk() self.tk.withdraw() return self.tk def send(self, squads, travel, side=None): """The plan's Go: the unit sets out (campaign.depart). -> True to close the plan.""" m = next(m for m in self.c.missions if f"mission:{m.id}" == self.chosen) try: K.depart(self.c, m.id, squads, travel, side) except K.CampaignError as err: self.brief_text.setText(f"Can't: {err}.") return False self.saved() self.set_out(self.t) self.show(None) self.update_hud() return True def caravan_out(self): """A caravan set out from the garage (campaignview.BunkerDesks): its piece goes as a unit does.""" self.saved() self.set_out(self.t) self.update_hud() def set_out(self, t): """Start the trip on the table at time t, from the day of the road it has reached.""" self.journey = {"phase": "out", "since": t, "from": self.unit_home, "to": self.trip_target()} def saved(self): if self.save_fn: self.save_fn(self.c) def go_on(self, t): """Play the trip up to time t: a day of road every DAY_SECONDS (campaign.road_day), then the lean over the table, then the battle (campaign.arrive, self.on_arrive), then home.""" j = self.journey if j is None: return unit = self.pieces["unit"] if j["phase"] == "out": trip = self.c.trip while t - j["since"] >= DAY_SECONDS and K.on_road(self.c): j["since"] += DAY_SECONDS # a day passes K.road_day(self.c) self.saved() self.rebuild() unit = self.pieces["unit"] k = min(1.0, (t - j["since"]) / DAY_SECONDS) unit.setPos(*lerp(j["from"], j["to"], (trip["gone"] + k) / trip["days"]), MAP_Z) if k >= 1.0 and not K.on_road(self.c): j.update(phase="lean", since=j["since"] + DAY_SECONDS) if j["phase"] == "lean": unit.setPos(*j["to"], MAP_Z) if t - j["since"] >= LEAN_SECONDS: mid = self.c.trip["mission"] m = next((m for m in self.c.missions if m.id == mid), None) battle = K.arrive(self.c) if battle is not None and self.c.trip.get("caravan"): m = K.raid_mission(self.c) # the caravan's raid, shown as a mission self.saved() if battle is None: # too late: they turn for home self.rebuild() j.update(phase="home", since=j["since"] + LEAN_SECONDS) else: j.update(phase="battle", mission=m, since=j["since"] + LEAN_SECONDS) self.update_hud() self.on_arrive(m, battle) if j["phase"] == "battle": self.pieces["unit"].setPos(*j["to"], MAP_Z) if j["phase"] == "home": k = (t - j["since"]) / HOME_SECONDS self.pieces["unit"].setPos(*lerp(j["to"], self.unit_home, ease(k)), MAP_Z) if k >= 1.0: self.journey = None self.update_hud() self.show(self.chosen) def battle_done(self, battle): """The battle is over: settle it (campaign.finish) and send the piece home.""" j = self.journey K.finish(self.c, j["mission"].id, battle) self.saved() j.update(phase="home", since=self.t) self.rebuild() self.pieces["unit"].setPos(*j["to"], MAP_Z) def open_battle(self, m, battle): from .view import BattleView helped, fought = m.names() win = tk.Toplevel(self.tk_root()) self.battle_view = BattleView(win, battle=battle, title=f"{D.REGIONS[m.region]['name']}: against {fought}", on_done=lambda b: self.battle_done(b)) def lean(self): """How far the view leans in over the table, 0..1, for the trip as it is now.""" j = self.journey if j is None: return 0.0 if j["phase"] == "lean": return ease((self.t - j["since"]) / LEAN_SECONDS) if j["phase"] == "battle": return 1.0 if j["phase"] == "home": return 1.0 - ease((self.t - j["since"]) / LEAN_SECONDS) return 0.0 def light(self): r = self.root a = AmbientLight("ambient") a.setColor(Vec4(0.42, 0.40, 0.36, 1)) r.setLight(r.attachNewNode(a)) p = PointLight("lamp") p.setColor(Vec4(0.8, 0.72, 0.56, 1)) p.setAttenuation((1, 0, 0.03)) lamp = r.attachNewNode(p) lamp.setPos(0, 0, 3.0) r.setLight(lamp) dl = DirectionalLight("fill") dl.setColor(Vec4(0.25, 0.25, 0.28, 1)) d = r.attachNewNode(dl) d.setHpr(-30, -50, 0) r.setLight(d) r.setShaderAuto() r.setAntialias(AntialiasAttrib.MMultisample) # ── time ── def camera_pose(self, t): k = ease((t - self.came_in) / INTRO_SECONDS) top = map_pose(self.view, self.fov()) pos, hpr = lerp(DOOR_POSE[0], top[0], k), lerp(DOOR_POSE[1], top[1], k) lean = self.lean() if lean and self.journey: # over the end of the road x, y = self.journey["to"] pos, hpr = lerp(pos, (x, y - 2.0, MAP_Z + 1.7), lean), lerp(hpr, (0.0, -42.0, 0.0), lean) return pos, hpr def at(self, t, camera=True): """Put everything where it is at time t (seconds since the game opened). camera: False while you're out in the base (the trip plays on; the view is the base's).""" self.t = t self.go_on(t) if camera: pos, hpr = self.camera_pose(t) self.base.camera.setPosHpr(*pos, *hpr) self.overhead.show() if pos[2] < OVERHEAD_Z else self.overhead.hide() # the clerk walks the cabinets and back, 12 s a round; turns at each end k = (t % 12) / 12 leg = k * 2 if k < 0.5 else 2 - k * 2 y = 3.6 - ease(leg) * 3.0 self.clerk.setPosHpr(-6.3, y, 0, 0 if k < 0.5 else 180, 0, 0) swing = 20 * math.sin(t * 5) for side, arm in zip((1, -1), self.clerk_arms): arm.setP(side * swing) # the radio operator leans in to listen; the officer points at the board now and then self.radio_head.setHpr(0, 6 * math.sin(t * 1.3), 0) self.officer_arms[1].setP(-110 if (t % 7) < 2.5 else -10) def tick(self, task): self.keys(task.time) self.at(task.time) if self.tk is not None: try: self.tk.update() # the plan and battle windows except tk.TclError: self.tk = None return task.cont def main(argv=None): argv = sys.argv[1:] if argv is None else argv shot = argv[argv.index("--shot") + 1] if "--shot" in argv else None at = float(argv[argv.index("--at") + 1]) if "--at" in argv else INTRO_SECONDS + 1 loadPrcFileData("", "window-title Project 02: the war room\nwin-size 1280 800\n" "framebuffer-multisample 1\nmultisamples 4\naudio-library-name null\n" + ("window-type offscreen\n" if shot else "")) from direct.showbase.ShowBase import ShowBase from .campaignview import SAVE_FILE from .cutaway import Cutaway base = ShowBase() base.disableMouse() if shot: # a frame of the saved campaign, no menu camp = K.load(SAVE_FILE) if SAVE_FILE.exists() else K.new_campaign() room = Cutaway(base, camp, save=lambda c: K.save(c, SAVE_FILE)) room.at(at) for _ in range(2): base.graphicsEngine.renderFrame() base.win.saveScreenshot(shot) return room from .menu import MainMenu MainMenu(base, lambda camp, path: start_game(base, camp, path), legacy=SAVE_FILE) base.run() def start_game(base, camp, path): """The main menu's choice: the base and the war room for camp, saving to path. -> the Cutaway.""" from .cutaway import Cutaway room = Cutaway(base, camp, save=lambda c: K.save(c, path)) base.taskMgr.add(room.tick, "war room") return room if __name__ == "__main__": main()