All files / js/levels castle.js

100% Statements 270/270
100% Branches 3/3
100% Functions 2/2
100% Lines 270/270

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 2713x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x  
/**
 * castle - NetHack special level
 * Converted from: castle.lua
 */
 
import * as des from '../sp_lev.js';
import { selection, shuffle } from '../sp_lev.js';
 
export async function generate() {
    // NetHack castle castle.lua	$NHDT-Date: 1652196024 2022/5/10 15:20:24 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.7 $
    // Copyright (c) 1989 by Jean-Christophe Collet
    // NetHack may be freely redistributed.  See license for details.
    // 
    // 
    // This is the stronghold level :
    // there are several ways to enter it :
    // - opening the drawbridge (wand of opening, knock spell, playing
    // the appropriate tune)
    // 
    // - enter via the back entry (this suppose a ring of levitation, boots
    // of water walking, etc.)
    // 
    // Note : If you don't play the right tune, you get indications like in the
    // MasterMind game...
    // 
    // To motivate the player : there are 4 storerooms (armors, weapons, food and
    // gems) and a wand of wishing in one of the 4 towers...
 
    des.level_init({ style: "mazegrid", bg: "-" });
 
    des.level_flags("mazelevel", "noteleport", "noflipy");
 
    await des.map(`\
}}}}}}}}}.............................................}}}}}}}}}
}-------}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}-------}
}|.....|-----------------------------------------------|.....|}
}|.....+...............................................+.....|}
}-------------------------------+-----------------------------}
}}}}}}|........|..........+...........|.......S.S.......|}}}}}}
.....}|........|..........|...........|.......|.|.......|}.....
.....}|........------------...........---------S---------}.....
.....}|...{....+..........+.........\\.S.................+......
.....}|........------------...........---------S---------}.....
.....}|........|..........|...........|.......|.|.......|}.....
}}}}}}|........|..........+...........|.......S.S.......|}}}}}}
}-------------------------------+-----------------------------}
}|.....+...............................................+.....|}
}|.....|-----------------------------------------------|.....|}
}-------}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}-------}
}}}}}}}}}.............................................}}}}}}}}}
`);
 
    // Random registers initialisation
    let object = [ "[", ")", "*", "%" ];
    shuffle(object)
 
    let place = selection.new();
    place.set(4,2);
    place.set(58,2);
    place.set(4,14);
    place.set(58,14);
 
    let monster = [ "L", "N", "E", "H", "M", "O", "R", "T", "X", "Z" ]
    shuffle(monster)
 
    des.teleport_region({ region: [1,0,10,20], region_islev: 1, exclude: [1,1,61,15], dir: "down" });
    des.teleport_region({ region: [69,0,79,20], region_islev: 1, exclude: [1,1,61,15], dir: "up" });
    des.levregion({ region: [1,0,10,20], region_islev: 1, exclude: [0,0,62,16], type: "stair-up" });
    des.feature("fountain", 10,8);
    // Doors
    des.door("closed",7,3);
    des.door("closed",55,3);
    des.door("locked",32,4);
    des.door("locked",26,5);
    des.door("locked",46,5);
    des.door("locked",48,5);
    des.door("locked",47,7);
    des.door("closed",15,8);
    des.door("closed",26,8);
    des.door("locked",38,8);
    des.door("locked",56,8);
    des.door("locked",47,9);
    des.door("locked",26,11);
    des.door("locked",46,11);
    des.door("locked",48,11);
    des.door("locked",32,12);
    des.door("closed",7,13);
    des.door("closed",55,13);
    // The drawbridge
    des.drawbridge({ dir: "east", state: "closed", x: 5,y: 8});
    // Storeroom number 1
    await des.object(object[0],39,5);
    await des.object(object[0],40,5);
    await des.object(object[0],41,5);
    await des.object(object[0],42,5);
    await des.object(object[0],43,5);
    await des.object(object[0],44,5);
    await des.object(object[0],45,5);
    await des.object(object[0],39,6);
    await des.object(object[0],40,6);
    await des.object(object[0],41,6);
    await des.object(object[0],42,6);
    await des.object(object[0],43,6);
    await des.object(object[0],44,6);
    await des.object(object[0],45,6);
    // Storeroom number 2
    await des.object(object[1],49,5);
    await des.object(object[1],50,5);
    await des.object(object[1],51,5);
    await des.object(object[1],52,5);
    await des.object(object[1],53,5);
    await des.object(object[1],54,5);
    await des.object(object[1],55,5);
    await des.object(object[1],49,6);
    await des.object(object[1],50,6);
    await des.object(object[1],51,6);
    await des.object(object[1],52,6);
    await des.object(object[1],53,6);
    await des.object(object[1],54,6);
    await des.object(object[1],55,6);
    // Storeroom number 3
    await des.object(object[2],39,10);
    await des.object(object[2],40,10);
    await des.object(object[2],41,10);
    await des.object(object[2],42,10);
    await des.object(object[2],43,10);
    await des.object(object[2],44,10);
    await des.object(object[2],45,10);
    await des.object(object[2],39,11);
    await des.object(object[2],40,11);
    await des.object(object[2],41,11);
    await des.object(object[2],42,11);
    await des.object(object[2],43,11);
    await des.object(object[2],44,11);
    await des.object(object[2],45,11);
    // Storeroom number 4
    await des.object(object[3],49,10);
    await des.object(object[3],50,10);
    await des.object(object[3],51,10);
    await des.object(object[3],52,10);
    await des.object(object[3],53,10);
    await des.object(object[3],54,10);
    await des.object(object[3],55,10);
    await des.object(object[3],49,11);
    await des.object(object[3],50,11);
    await des.object(object[3],51,11);
    await des.object(object[3],52,11);
    await des.object(object[3],53,11);
    await des.object(object[3],54,11);
    await des.object(object[3],55,11);
    // THE WAND OF WISHING in 1 of the 4 towers
    let loc = place.rndcoord(1);
    await des.object({ id: "chest", trapped: 0, locked: 1, coord: loc ,
                 contents: async function() {
                    await des.object("wishing");
                    await des.object("potion of gain level");
                 }
    });
    // Prevent monsters from eating it.  (@'s never eat objects)
    des.engraving({ coord: loc, type: "burn", text: "Elbereth" });
    await des.object({ id: "scroll of scare monster", coord: loc, buc: "cursed" });
    // The treasure of the lord
    await des.object("chest",37,8);
    // Traps
    await des.trap("trap door",40,8);
    await des.trap("trap door",44,8);
    await des.trap("trap door",48,8);
    await des.trap("trap door",52,8);
    await des.trap("trap door",55,8);
    // Soldiers guarding the entry hall
    await des.monster("soldier",8,6);
    await des.monster("soldier",9,5);
    await des.monster("soldier",11,5);
    await des.monster("soldier",12,6);
    await des.monster("soldier",8,10);
    await des.monster("soldier",9,11);
    await des.monster("soldier",11,11);
    await des.monster("soldier",12,10);
    await des.monster("lieutenant",9,8);
    // Soldiers guarding the towers
    await des.monster("soldier",3,2);
    await des.monster("soldier",5,2);
    await des.monster("soldier",57,2);
    await des.monster("soldier",59,2);
    await des.monster("soldier",3,14);
    await des.monster("soldier",5,14);
    await des.monster("soldier",57,14);
    await des.monster("soldier",59,14);
    // The four dragons that are guarding the storerooms
    await des.monster("D",47,5);
    await des.monster("D",47,6);
    await des.monster("D",47,10);
    await des.monster("D",47,11);
    // Sea monsters in the moat
    await des.monster("giant eel",5,7);
    await des.monster("giant eel",5,9);
    await des.monster("giant eel",57,7);
    await des.monster("giant eel",57,9);
    await des.monster("shark",5,0);
    await des.monster("shark",5,16);
    await des.monster("shark",57,0);
    await des.monster("shark",57,16);
    // The throne room and the court monsters
    await des.monster(monster[9],27,5);
    await des.monster(monster[0],30,5);
    await des.monster(monster[1],33,5);
    await des.monster(monster[2],36,5);
    await des.monster(monster[3],28,6);
    await des.monster(monster[4],31,6);
    await des.monster(monster[5],34,6);
    await des.monster(monster[6],37,6);
    await des.monster(monster[7],27,7);
    await des.monster(monster[8],30,7);
    await des.monster(monster[9],33,7);
    await des.monster(monster[0],36,7);
    await des.monster(monster[1],28,8);
    await des.monster(monster[2],31,8);
    await des.monster(monster[3],34,8);
    await des.monster(monster[4],27,9);
    await des.monster(monster[5],30,9);
    await des.monster(monster[6],33,9);
    await des.monster(monster[7],36,9);
    await des.monster(monster[8],28,10);
    await des.monster(monster[9],31,10);
    await des.monster(monster[0],34,10);
    await des.monster(monster[1],37,10);
    await des.monster(monster[2],27,11);
    await des.monster(monster[3],30,11);
    await des.monster(monster[4],33,11);
    await des.monster(monster[5],36,11);
    // MazeWalks
    await des.mazewalk(0,10,"west");
    await des.mazewalk(62,6,"east");
    // Non diggable walls
    des.non_diggable(selection.area(0,0,62,16));
    // Subrooms:
    // Entire castle area
    await des.region(selection.area(0,0,62,16),"unlit");
    // Courtyards
    await des.region(selection.area(0,5,5,11),"lit");
    await des.region(selection.area(57,5,62,11),"lit");
    // Throne room
    await des.region({ region: [27,5, 37,11],lit: 1,type: "throne", filled: 2 });
    // Antechamber
    await des.region(selection.area(7,5,14,11),"lit");
    // Storerooms
    await des.region(selection.area(39,5,45,6),"lit");
    await des.region(selection.area(39,10,45,11),"lit");
    await des.region(selection.area(49,5,55,6),"lit");
    await des.region(selection.area(49,10,55,11),"lit");
    // Corners
    await des.region(selection.area(2,2,6,3),"lit");
    await des.region(selection.area(56,2,60,3),"lit");
    await des.region(selection.area(2,13,6,14),"lit");
    await des.region(selection.area(56,13,60,14),"lit");
    // Barracks
    await des.region({ region: [16,5, 25,6],lit: 1,type: "barracks", filled: 1 });
    await des.region({ region: [16,10, 25,11],lit: 1,type: "barracks", filled: 1 });
    // Hallways
    await des.region(selection.area(8,3,54,3),"unlit");
    await des.region(selection.area(8,13,54,13),"unlit");
    await des.region(selection.area(16,8,25,8),"unlit");
    await des.region(selection.area(39,8,55,8),"unlit");
    // Storeroom alcoves
    await des.region(selection.area(47,5,47,6),"unlit");
    await des.region(selection.area(47,10,47,11),"unlit");
 
 
    return des.finalize_level();
}