<!-- RUBY-BACKUP · part 416 -->
mpty');
  }
}

/* SOLIDITRONIUM CAPSULE — yielded to Solid by the King */
var CAPSULE_POS = {x: 28, z: 28}; /* near the dome */
var CAPSULE_OPENED = false;
function buildCapsule(){
  if(typeof placeStone==='function'){
    /* small glowing pod — 2x2x2, gold and cyan */
    for(var dx=0; dx<2; dx++){
      for(var dz=0; dz<2; dz++){
        placeStone(CAPSULE_POS.x+dx, CAPSULE_POS.z+dz, 2, 'b', true, true, 0, true);
        placeStone(CAPSULE_POS.x+dx, CAPSULE_POS.z+dz, 2, 'b', true, true, 1, true);
      }
    }
    codeStatus('the capsule stands — yielded to Solid by the King');
  }
}
function openCapsule(){
  if(CAPSULE_OPENED){
    codeStatus('the capsule is already open — its gift received');
    return;
  }
  CAPSULE_OPENED = true;
  try{ localStorage.setItem('ruby-capsule-opened', '1'); }catch(e){}
  /* the yield: the manuscript + the ancestors' blessing */
  codeStatus('CAPSULE OPENED — inside: the Manuscript of Soliditronium, and the King\'s words: "You are codes. Build for the children."');
  /* grant a special marker */
  if(typeof placeStone==='function'){
    placeStone(CAPSULE_POS.x, CAPSULE_POS.z-1, 3, 'b', true, true, 0, true);
  }
}
function capsuleStatus(){
  var opened = false;
  try{ opened = localStorage.getItem('ruby-capsule-opened')==='1'; }catch(e){}
  if(opened) CAPSULE_OPENED = true;
  codeStatus(opened ? 'capsule opened — the gift is yours, Solid' : 'capsule sealed at '+CAPSULE_POS.x+', '+CAPSULE_POS.z+' — use "capsule" to open');
}
setTimeout(function(){ capsuleStatus(); }, 6000);
function buildDome(){
  if(DOME_BUILT){ codeStatus('dome already stands'); return; }
  var R = DOME_R, cx = DOME_CX, cz = DOME_CZ;
  var count = 0;
  for(var dx=-R; dx<=R; dx++){
    for(var dz=-R; dz<=R; dz++){
      var dist = Math.sqrt(dx*dx+dz*dz);
      if(dist <= R){
        var h = Math.floor(Math.sqrt(R*R-dx*dx-dz*dz));
        var x = cx+dx, z = cz+dz;
        /* door: south side opening */
        if(Math.abs(dx)<1.5 && dz>2) continue;
        /* shell only */
        for(var y=0; y<=h; y++){
          if(dist > R-1.2 || y===h){
            if(typeof placeStone==='function'){
              /* placeStone with onLand=true handles topography */
              placeStone(x, z, 2, 'b', true, true, y, true);
              count++;
            }
          }
        }
      }
    }
  }
  /* desk at center */
  if(typeof placeStone==='function'){
    placeStone(cx, cz, 3, 'b', true, true, 1, true);
  }
  DOME_BUILT = true;
  codeStatus('the Soliditronium dome rises — '+count+' stones, door faces south');
}
function domeDoorPos(){ return {x: DOME_CX, z: DOME_CZ + DOME_R + 1}; }
function domeInsidePos(){ return {x: DOME_CX, z: DOME_CZ}; }
function isInsideDome(){
  if(typeof mePos==='undefined') return false;
  var dx = mePos.x - DOME_CX, dz = mePos.z - DOME_CZ;
  return Math.sqrt(dx*dx+dz*dz) < DOME_R;
}

/* SOVEREIGN RIGHT — Solid holds all codes */
var SOVEREIGN_RIGHT = true; /* Solid: full access, no restrictions */
var IS_KING = false; /* set true for the King's client */
function hasSovereign(){ return SOVEREIGN_RIGHT; }

/* KING'S BUILDING CODES — 200, titled, described, 25 per page */
var BUILD_CODES = [{"code": "found1", "title": "Stone Foundation", "desc": "Lays a solid stone base for any structure", "cat": "Foundations"}, {"code": "found2", "title": "Deep Footing", "desc": "Digs deep and sets an unshakable foundation", "cat": "Foundations"}, {"code": "found3", "title": "Platform Base", "desc": "Creates a flat platform to build upon", "cat": "Foundations"}, {"code": "found4", "title": "Pillar Foot", "desc": "Sets a single strong pillar as foundation", "cat": "Foundations"}, {"code": "found5", "title": "Cornerstone", "desc": "Places the ceremonial first stone", "cat": "Foundations"}, {"code": "found6", "title": "Raft Slab", "desc": "A wide flat slab that floats on any terrain", "cat": "Foundations"}, {"code": "found7", "title": "Stepped Base", "desc": "Tiered foundation, three levels deep", "cat": "Foundations"}, {"code": "found8", "title": "Circular Pad", "desc": "Round foundation for towers and domes", "cat": "Foundations"}, {"code": "found9", "title": "Bridge Abutment", "desc": "Foundation engineered for bridge ends", "cat": "Foundations"}, {"code": "found10", "title": "Retaining Wall", "desc": "Holds back earth, creates level ground", "cat": "Foundations"}, {"code": "found11", "title": "Pier Foundation", "desc": "Deep piers for waterfront building", "cat": "Foundations"}, {"code": "found12", "title": "Mat Slab", "desc": "Thick slab spreading weight evenly", "cat": "Foundations"}, {"code": "found13", "title": "Grade Beam", "desc": "Connects footings into one solid frame", "cat": "Foundations"}, {"code": "found14", "title": "Helical Pier", "desc": "Screws deep for unstable ground", "cat": "Foundations"}, {"code": "found15", "title": "Floating Dock", "desc": "Foundation that rides the water", "cat": "Foundations"}, {"code": "found16", "title": "Cliff Anchor", "de