implementedProfiledragon-shapechange-flight-v1Qualifiedcpu

33. Let's build a dragon

Implemented profile (dragon-shapechange-flight-v1). The procedural model script is `scripts/blender/dragon.py`, baked into zone packs by `metaverse/tools/assets/dragon_bake.py` and into standalone GameBuilder GBD1 worlds (/fated-dragon, #13973) by the pure-Coax baker `gamebuilder/tools/dragon-bake.coax`. Its clips live in `everglade/dragon-clips.coax`, shared flight in `metaverse-engine/action/flight.coax`, SRD rules in `rules/srd/shapechange.coax` and `rules/srd/dragon-actions.coax`, shapeshift presentation in `everglade/shapeshift.coax`, and the /druid / /dragon-lab zone in `everglade/zone-shapechange.coax`. Mounted riding and room authority (#13268) are implemented in `everglade/mounts.coax`, `everglade/server/riding.coax`, `everglade/shared/mount-rules.coax`, and `everglade/zone-ride.coax`.

This chapter answers the player's question: "Can I turn into a dragon and fly?"

Yes. At /druid you arrive in an open meadow as a level 17 Druid. Press Shapechange (Dragon), and a rune circle glows under you, leaves swirl up, a flash goes off and an Adult Red Dragon stands where you stood. Press Jump to take off. Hold Fire Breath to aim and let go to breathe.

Each piece of that lives in one place, and every Everglade zone reuses it:

PieceLayerWhere
The dragon's mesh, bones and clipsAsset scriptscripts/blender/dragon.py
Its baked frames in the packAsset pipelinemetaverse/tools/assets/dragon_bake.py, gamebuilder/tools/dragon-bake.coax (GBD1, #13973)
Riding & room-authoritative mountsEvergladeeverglade/mounts.coax, everglade/server/riding.coax, everglade/shared/mount-rules.coax (#13268)
Walking, takeoff, flight, banking and landingEnginemetaverse-engine/action/flight.coax
Shapechange and the dragon's actionsEngine (SRD rules)shapechange.coax, dragon-actions.coax
The change on screen, the breath's aim, the clip to playEvergladeeverglade/shapeshift.coax
The change, breath, burning, sweep, buffet and roar effectsEnginemetaverse-engine/fx/dragon.coax
The druid, the field and the barZoneeverglade/zone-shapechange.coax

The zone holds no rules. It places the druid and passes your keys to the shared layers.

What this chapter teaches

  • How to build a model from a script, with no editor.
  • How SRD speeds in feet become a flier's metres a second.
  • How Fire Breath's cone, Recharge and Burning work as SRD rules.
  • How Shapechange swaps a body and its numbers, and gives them back.
  • How the same dragon becomes a mount.

A model built from a script

The dragon is one Python script that Blender runs headless. Nobody opens an editor. The script lofts the body, neck and tail as one tube along the spine and builds the head, legs, horns, back plates and wings from tapered rods and fans. The faces are flat-shaded, there are 3,260 triangles (the script asserts under 4,000), and each part has one flat colour: a crimson hide, a gold belly, a wine-dark wing membrane with a warmer underside, and ivory horns and claws.

The skeleton has 27 joints. Twelve are the spine: body, chest, three neck bones, head, jaw and five tail bones. Each wing adds arm, forearm, hand and four finger bones, and each leg its own chain. The saddle bone carries no mesh; it marks where a rider sits, astride the base of the neck. Then the script keys each clip on those bones.

The spine and saddle bones, from scripts/blender/dragon.py:

python
# Bones: (name, parent, head). Spine bones sit on the spine; their weights# along the loft blend between neighbors. `saddle` carries no mesh: it marks# where a rider sits, astride the base of the neck.SADDLE = (0, -1.2, 3.62)BONES = [    ("body", None, (0, 0.7, 2.55)),    ("chest", "body", (0, -0.85, 2.8)),    ("saddle", "chest", SADDLE),    ("neck1", "chest", (0, -1.55, 3.1)),    ("neck2", "neck1", (0, -2.05, 3.6)),    ("neck3", "neck2", (0, -2.5, 4.2)),    ("head", "neck3", (0, -2.95, 5.0)),    ("jaw", "head", (0, -3.1, 4.88)),    ("tail1", "body", (0, 2.3, 2.36)),    ("tail2", "tail1", (0, 3.9, 1.9)),    ("tail3", "tail2", (0, 5.5, 1.4)),    ("tail4", "tail3", (0, 6.7, 1.12)),    ("tail5", "tail4", (0, 7.6, 0.98)),]

Each bone is a name, its parent and where its head sits, in metres, with the dragon facing -Y.

Why a script? You can read it, diff it and review it, and the same script gives the same dragon on every machine. A change such as "make the wings wider" is one number, and the preview renders again in seconds.

The three-angle renders (dragon-model-front.png, dragon-model-side.png, and dragon-model-below.png, originally archived under druid-demo-2026-11-09) verify silhouette, wing span, and saddle placement. For standalone GameBuilder worlds (/fated-dragon, #13973), `gamebuilder/tools/dragon-bake.coax` also bakes assets/metaverse/beasts/dragon.gltf directly into a compact pure-Coax GBD1 binary with zero Python or Blender dependency.

The clips are idle, walk, fly, glide, bite, breath, roar and sweep for the druid, and idle_saddled, takeoff, hover, land, bank_left and bank_right for a mount. The baker evaluates each clip's frames and writes them in that order. dragon-clips.coax holds the same order, so frame n of the pack is frame n of the clips:

  • everglade/dragon-clips.coax, `#test "the dragon's clips cover every baked frame once, in order"`.
  • everglade/dragon-clips.coax, `#test "a loop goes round; a clip played once holds its last pose"`.

The rider's place is the saddle bone at rest, DR_SADDLE_X, DR_SADDLE_Y and DR_SADDLE_Z in dragon-clips.coax.

Flight from SRD speeds

The Adult Red Dragon's block gives Speed 40 feet and Fly 80 feet. A realm has its own pace: how many metres a second a 30-foot Speed walks. The flight profile converts both speeds against that pace, so the dragon flies twice as fast as it walks in every realm:

jai
// A profile from SRD speeds in feet: walk_ft on the ground, fly_ft in the air, against the realm's// pace (pace_mps metres a second for a 30-ft Speed).wing_profile_srd :: (walk_ft: int, fly_ft: int, pace_mps: f32) -> WingProfile #effects(all) {  p: WingProfile;  p.walk = pace_mps * f32(walk_ft) / 30.0;  p.fly = pace_mps * f32(fly_ft) / 30.0;  p.accel = p.fly * 0.75;  p.vertical.on = true; p.vertical.ceiling = 60.0;  p.vertical.flap_up = 6.0; p.vertical.climb = 4.0; p.vertical.glide = -1.2; p.vertical.dive = -12.0;  return p;}

A body is in one of four phases. On the ground it walks. A jump starts the takeoff: lift for 0.8 seconds, then free flight. In the air, a held jump beats the wings and climbs, letting go glides down slowly, and a dive drops fast and speeds up. When the body reaches the ground it lands, settles for 0.6 seconds and walks again. Turning in the air leans the body into the turn. Each phase picks a clip: walk, takeoff, fly, glide, hover, bank_left, bank_right or land.

The druid's dragon and a ridden dragon both call wing_step. There is one flight module, not one per zone.

The dragon's actions as SRD rules

Fire Breath is a 60-foot cone. Each creature in it makes a DC 21 Dexterity saving throw and takes 17d6 Fire damage on a failure, half on a success. A cone's width at any distance equals that distance, so a point is inside when it is no further to the side than half the distance along the aim:

jai
// Whether point (dx, dy) from a cone's origin is inside a cone of `length` aimed along (fx, fy),// any units so long as they're the same: no further than length along the aim, and no further to// the side than half the distance along it.rs_in_cone :: (dx: f32, dy: f32, fx: f32, fy: f32, length: f32) -> bool #effects(all) {  n := sqrt(fx * fx + fy * fy);  if !(n > 0) || !(length > 0) { return false; }  ux := fx / n; uy := fy / n;  along := dx * ux + dy * uy;  side := abs(dx * uy - dy * ux);  return along >= 0 && along <= length && side * 2 <= along;}

The same test in three dimensions, rs_in_cone3, lets a flier breathe down onto the ground. A world measures which creatures are in the cone and passes them to rs_fire_breath_on. The engine rolls the saves and the damage.

After a breath, Fire Breath is spent. It has Recharge 5–6: at the start of each of the dragon's turns, a d6 roll of 5 or 6 brings it back. Burning is a house rule: a creature that fails the save burns for 1d4 Fire at the start of each of its turns for three rounds. Both run from the engine's turn start, so any world that steps turns gets them:

jai
// The start of i's turn: Burning, then the Recharge roll.rs_dragon_turn_start :: (b: [] RsBattle, i: int) #effects(all) {  _ := rs_burning_tick(b, i);   // nothing when no fire burns  if rs_breather(b[0].c[i]) && b[0].c[i].breath_spent && rs_recharges(rs_roll(b[0].dice[..], 6)) { b[0].c[i].breath_spent = false; }}

The dragon's other actions are Rend (Multiattack: three Rends), and three house actions: Tail Sweep, Wing Buffet and Frightful Roar. They use the SRD's save DC formula, 8 plus the ability modifier plus the Proficiency Bonus. The compliance ledger lists each house rule.

The druid's Shapechange

Shapechange is a 9th-level spell, so the druid is level 17. Casting it takes an Action, the 9th-level slot, Concentration and a jade circlet. The form must not be Undead, and its Challenge Rating must be no higher than your level:

jai
// The acting i casts Shapechange with a 9th-level slot and takes block m's form (its Action, the slot,// Concentration). A Wild Shape form ends first.rs_shapechange :: (b: [] RsBattle, i: int, m: int) -> bool #effects(all) {  if i < 0 || i >= b[0].n || !rs_shape_eligible(b[0].c[i], m) || rs_shape_keep_at(b, i) < 0 { return false; }  if b[0].c[i].wild_form != 0 { rs_wild_shape_end(b, i, " leaves its Beast form"); }  if !rs_cast(b, i, SP_SHAPECHANGE, 9, b[0].c[i].x, b[0].c[i].y, i) { return false; }  rs_shape_take(b, i, m);  b[0].c[i].temp = rs_max(b[0].c[i].temp, rs_monster_block(m).hp);  rs_say(b, RS_EV_CONDITION, i, i, m, " takes a new shape with Shapechange");  return true;}

You keep your Intelligence, Wisdom and Charisma, your Hit Points and your saving throw proficiencies. You take the dragon's Armor Class, speeds, Strength, Dexterity, Constitution, size and Fire immunity, and its 256 Hit Points as Temporary Hit Points. When Concentration ends, or you press Return to Form, everything comes back.

Your own numbers wait in the battle's side table, shape_keeps, not on every creature. Only the few creatures that cast Shapechange need them, and a battle holds RS_SHAPE_KEEPS (4) at once. A fifth caster's Shapechange is refused before it spends a slot:

  • rules/srd/shapechange.coax, `#test "Shapechange keeps the caster's own numbers in the battle's side table, and refuses when the table is full"`.

The zone doesn't decide which body to draw. It reads the engine's creature and draws that:

jai
// The engine's body, as the shapeshift layer's kinds.xd_form :: (c: RsCreature) -> int { return ifx c.shape_form == MON_ADULT_RED_DRAGON then SH_DRAGON else ifx c.wild_form != 0 then SH_WOLF else SH_DRUID; }

So the picture can't disagree with the rules. If a monster breaks your Concentration, the dragon becomes a druid again on the next frame.

Dragon Lab: arrive as the dragon

Dragon Lab is at /dragon-lab. Open it to walk, fly and fight as the dragon without casting anything first. It is the druid's field with one zone setting, kept, which the page's address turns on. Nothing else is copied: the meadow, the monsters, the flight, the breath and the rules are the same code.

Three things differ:

  • You arrive as the dragon. On the first frame, the zone casts Shapechange for you through the same rule the bar's button calls, rs_shapechange. The cast spends your 9th-level slot and takes Concentration, as it does at /druid. The zone casts it in a setup turn, so your own Action is still free.
  • The change doesn't play. sh_arrive in everglade/shapeshift.coax puts the picture in the dragon's body with the change already finished: no rune circle, no flash and no roar. The dragon is standing there when the page opens.
  • You stay a dragon. The bar holds only Rend, Fire Breath, Tail Sweep, Wing Buffet and Frightful Roar. It has no Wild Shape and no Return to Form. If Concentration ends, because a monster breaks it or the spell's hour runs out, the zone gives the slot back and casts again before the next picture. You never see the druid.

The zone still holds no rules. It decides when to ask for the spell; the engine decides whether the cast succeeds. If the engine refuses, for example while you are at 0 Hit Points, the zone asks again on the next frame.

The setting's whole procedure:

jai
xd_keep :: (s: [] EgZone) {  x := s[0].xc[..]; b := x[0].b[..]; cr := s[0].creator[..];  if !x[0].dr.kept || b[0].c[0].shape_form != 0 || !rs_can_act(b[0].c[0]) { return; }  setup: [1] FbSeat; setup[0].me = 0;  fb_seat_in(b, setup[..]);  ok := rs_shapechange(b, 0, MON_ADULT_RED_DRAGON);  fb_seat_out(b, setup[..]);  if !ok || x[0].dr.arrived { return; }  x[0].dr.arrived = true;  sh := x[0].dr.sh[..];  sh_arrive(sh, xd_form(b[0].c[0]), cr[0].clock);  sh[0].wing.x = cr[0].player_x; sh[0].wing.z = cr[0].player_z; sh[0].wing.y = cr[0].player_y; sh[0].wing.yaw = cr[0].player_face;  sh[0].wing.phase = WING_GROUND;}

Riding it as a mount

Mounted riding (#13268) is implemented across both the client/zone layer and the authoritative room server:

Worked hand calculation

Before running the example, work out the Adult Red Dragon's speeds, Fire Breath cone boundary, and Recharge probability by hand:

text
Realm 30-ft pace   = 4.5 m/s
Walk (40 ft)       = 4.5 × (40 / 30) = 6.0 m/s  (60 tenths-of-m/s)
Fly  (80 ft)       = 4.5 × (80 / 30) = 12.0 m/s (120 tenths-of-m/s)

60-ft Fire Breath cone (along x-axis, half-width = along / 2):
  (30,  0): along = 30 <= 60, side =  0 <= 15   -> inside  (true)
  (40, 20): along = 40 <= 60, side = 20 <= 20   -> on edge (true)
  (40, 21): along = 40 <= 60, side = 21 >  20   -> outside (false)
  (61,  0): along = 61 >  60                    -> past tip (false)

Recharge 5–6 on 1d6:
  roll 4 -> false; roll 5 or 6 -> true (P = 2/6 ≈ 33.3%)

Shapechange CR eligibility (Adult Red Dragon = CR 17):
  level 16 Druid: CR 17 > level 16 -> refused (false, slot unspent)
  level 17 Druid: CR 17 <= level 17 -> admitted (AC 19, STR 27, Fly 80, Temp HP 256)

The checks

  • metaverse-engine/action/flight.coax, `#test "SRD speeds: an Adult Red Dragon walks 40 ft and flies 80 ft against a 30-ft pace", #test "flight is faster than walking: the dragon covers much more ground in the air", #test "climb, glide and dive: a held jump climbs, letting go glides down, a dive drops faster and speeds up" and #test "it lands: gliding or pressing land reaches the ground, settles, then walks"`.
  • rules/srd/battle.coax runs dragon-actions.coax's `#test "the cone: 60 feet long, a half-angle of atan(1/2); in front and inside, never behind or wide", #test "Fire Breath: DC 21 Dexterity, 17d6 Fire to each foe in the cone, half on a success; then it's spent", #test "Recharge 5–6: a 5 or a 6 at the start of its turn brings Fire Breath back" and #test "Burning: 1d4 Fire at the start of each turn for three rounds; an action Prone puts it out"`.
  • rules/srd/battle.coax runs shapechange.coax's `#test "Shapechange: a level 17 Druid becomes an Adult Red Dragon with its 9th-level slot, Action and Concentration" and #test "Shapechange ends with Concentration and gives everything back; its Temporary Hit Points go"`.
  • everglade/shapeshift.coax, `#test "the fire cone: inside 18 m and its angle it hits, outside it misses; a flier aims down"`.
  • everglade/zone.coax runs everglade/zone-shapechange.coax's `#test "druid: Fire Breath held and let go burns the monsters in its cone and none behind"` and `#test "druid: the dragon takes off with Jump, flies faster than it walks, and glides down to land"`.
  • everglade/zone.coax runs everglade/zone-shapechange.coax's `#test "dragon lab: on the first frame you are the dragon, by the rules, with its change already done and its five actions on the bar", #test "dragon lab: Jump takes off from the first frame" and #test "dragon lab: when Concentration ends, the lab casts again before the next picture, so the dragon never leaves"`.
  • everglade/shapeshift.coax, `#test "arriving in a body plays no change: it is whole at once, with none of the change's moments"`.
  • metaverse-engine/fx/puff.coax runs dragon.coax's `#test "dragon: the breath's fire stays inside its cone, half as wide as it is far"`.
sh
coax/bin/coax test --library metaverse-engine/action/flight.coaxcoax/bin/coax test --library rules/srd/battle.coax --only "Shapechange"coax/bin/coax test --library everglade/shapeshift.coaxcoax/bin/coax test --library everglade/zone.coax --only "druid"coax/bin/coax test --library everglade/zone.coax --only "dragon lab"coax/bin/coax run everglade/examples/dragon-flight-breath.coax

Runnable example

`everglade/examples/dragon-flight-breath.coax` drives the Adult Red Dragon end to end across `metaverse-engine/action/flight.coax`, `rules/srd/dragon-actions.coax`, and `rules/srd/shapechange.coax`: SRD speed conversion and 1.0 s takeoff climb (y_cm=590), 60-foot cone geometry and Recharge 5–6, level-16 CR refusal, and level-17 Druid Shapechange → Fire Breath → clean restoration (committed transcript `everglade/examples/dragon-flight-breath.out`):

jai
dfb_try_l16 :: () -> bool {  b: [1] RsBattle; r: [1] RsRoom;  rs_have(b[..], r[..]);  shape_battle(b[..], 16);  return !rs_shapechange(b[..], 0, MON_ADULT_RED_DRAGON);}dfb_run :: () -> bool {  // 1. Flight from SRD speeds (40 ft walk, 80 ft fly at realm 30-ft pace 4.5 m/s -> 6.0 / 12.0 m/s).  wp := wing_profile_srd(40, 80, 4.5);  ws := wing_at(0.0, 0.0, 0.0, 0.0);  // Press jump on ground -> enters WING_TAKEOFF, rises cleanly over 1.0s of fixed 0.1s steps.  ws = wing_step(wp, ws, WingInput.{mz = 1.0, jump = true, climb = true}, 0.0, 0.1);  for step: 0..<9 {    ws = wing_step(wp, ws, WingInput.{mz = 1.0, climb = true}, 0.0, 0.1);  }  print("walk_mps=% fly_mps=% airborne=% phase=% y_cm=%\n",    cast(int) (wp.walk * 10.0), cast(int) (wp.fly * 10.0), wing_flying(ws), ws.phase, cast(int) (ws.y * 100.0));  // 2. 60-foot Fire Breath cone (width == distance -> half-angle atan(1/2)) and Recharge 5-6.  in_center := rs_in_cone(30.0, 0.0, 1.0, 0.0, 60.0);  on_edge := rs_in_cone(40.0, 20.0, 1.0, 0.0, 60.0);  out_wide := rs_in_cone(40.0, 21.0, 1.0, 0.0, 60.0);  past_tip := rs_in_cone(61.0, 0.0, 1.0, 0.0, 60.0);  print("cone_center=% on_edge=% out_wide=% past_tip=% recharge4=% recharge5=%\n",    in_center, on_edge, out_wide, past_tip, rs_recharges(4), rs_recharges(5));  // 3. SRD Shapechange: level 16 refused (CR 17 > 16); level 17 Druid becomes Adult Red Dragon,  //    gains AC 19 / STR 27 / Fly 80 / 256 Temp HP, breathes fire, and restores cleanly on leave.  refuse_l16 := dfb_try_l16();  b: [1] RsBattle; br: [1] RsRoom;  rs_have(b[..], br[..]);  shape_battle(b[..], 17);  own_ac := b[0].c[0].ac;  own_str := b[0].c[0].score[RS_STR];  shifted := rs_shapechange(b[..], 0, MON_ADULT_RED_DRAGON);  d_ac := b[0].c[0].ac;  d_str := b[0].c[0].score[RS_STR];  d_fly := b[0].c[0].fly;  d_temp := b[0].c[0].temp;  // Next turn: unleash Fire Breath on Foe at (6, 4) -> +10 ft east inside 60-ft cone.  rs_fresh(b[..], 0);  hit_n := rs_fire_breath(b[..], 0, 1.0, 0.0);  spent := b[0].c[0].breath_spent;  left := rs_shapechange_leave(b[..], 0);  restored := b[0].c[0].shape_form == 0 && b[0].c[0].ac == own_ac && b[0].c[0].score[RS_STR] == own_str && b[0].c[0].temp == 0;  print("refuse_l16=% shifted=% dragon_ac=% str=% fly=% temp=% breath_hits=% spent=% restored=%\n",    refuse_l16, shifted, d_ac, d_str, d_fly, d_temp, hit_n, spent, restored);  return wing_flying(ws) && in_center && on_edge && !out_wide && !past_tip &&         !rs_recharges(4) && rs_recharges(5) && refuse_l16 && shifted &&         d_ac == 19 && d_str == 27 && d_fly == 80 && d_temp == 256 &&         hit_n == 1 && spent && left && restored;}

Output (coax/bin/coax run everglade/examples/dragon-flight-breath.coax, identical in --release):

text
walk_mps=60 fly_mps=120 airborne=true phase=2 y_cm=590
cone_center=true on_edge=true out_wide=false past_tip=false recharge4=false recharge5=true
refuse_l16=true shifted=true dragon_ac=19 str=27 fly=80 temp=256 breath_hits=1 spent=true restored=true
ok=true

The earlier headless capture sets (druid-demo-2026-11-09 and dragon-lab-2026-11-17) were archived externally; the Coax checks and runnable program above remain the authoritative verification gate.

Mistakes

  • A full spell list. The engine's level 17 Druid already had as many prepared spells as it may, so Shapechange couldn't be prepared and the first cast failed. rs_shapechange_ready now lets the highest prepared spell step out for it.
  • A push that went through a body. The first Wing Buffet check expected a creature to slide 15 feet back. Another creature stood behind it. The engine was right: a push stops at an occupied square, and the check now says so.
  • Fire on an Imp. Imps are immune to Fire, so the first breath check burned nothing. The check now picks creatures that fire harms.

What comes next

  • A Wild Shape body: today the druid keeps its own body as a wolf.
  • Riding the dragon in Experimental, with Fire Breath from the saddle.