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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 88x 88x 88x 88x 73x 73x 7x 7x 7x 7x 73x 73x 73x 4x 4x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 19x 19x 73x 73x 73x 17248x 17248x 17248x 17248x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 2763223x 2763223x 2763223x 2763223x 2763223x 73x 73x 906391x 906391x 73x 73x 73x 19180x 19180x 19180x 19180x 73x 73x 73x 8x 8x 8x 73x 73x 73x 73x 73x 1834207x 1834207x 1834207x 1834207x 73x 73x 73x 73x 73x 73x 121x 121x 121x 121x 121x 73x 73x 73x 9110x 9110x 9110x 73x 73x 73x 1943813x 1943813x 1943813x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 6086x 6086x 73x 73x 73x 306x 306x 73x 73x 73x 3x 3x 3x 73x 73x 73x 19347x 19347x 73x 73x 73x 15x 15x 73x 73x 73x 73x 73x 73x 73x 95164x 95164x 73x 73x 73x 73x 73x 73x 12237x 12237x 73x 73x 73x 58x 58x 73x 73x 73x 146x 146x 73x 73x 73x 148x 148x 148x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 34x 34x 34x 73x 73x 73x 73x 6236x 6236x 6236x 73x 73x 392x 392x 392x 392x 392x 211x 211x 211x 205x 392x 392x 73x 73x 208x 208x 73x 73x 73x 73x 15x 15x 73x 73x | // macros.js — Player-state macros for C-to-JS translation.
// C ref: youprop.h defines ~60 property macros.
//
// CONVENTIONS.md documents these as:
// import { Blind, Hallucination, Stunned, ... } from './macros.js';
// if (Blind()) { ... } // ALL are functions — call them
//
// Each macro checks u.uprops[PROP].intrinsic and/or .extrinsic,
// matching C's HFoo/EFoo/Foo pattern.
import { game } from './gstate.js';
import { DUNCE_CAP, TOWEL } from './objects.js';
import { S_EEL, S_SPIDER } from './monsters.js';
import { ACID_RES, ANTIMAGIC, BLINDED, CLAIRVOYANT, COLD_RES, CONFLICT, CONFUSION, DEAF, DETECT_MONSTERS, DISINT_RES, DISPLACED, DRAIN_RES, FAST, FIRE_RES, FIXED_ABIL, FLYING, FREE_ACTION, FUMBLING, GLIB, HALF_PHDAM, HALF_SPDAM, HALLUC, HALLUC_RES, INFRAVISION, INTRINSIC, INVIS, LEVITATION, LIFESAVED, MAGICAL_BREATHING, PASSES_WALLS, POISON_RES, POLYMORPH, POLYMORPH_CONTROL, PROT_FROM_SHAPE_CHANGERS, PROTECTION, REFLECTING, REGENERATION, SEARCHING, SEE_INVIS, SHOCK_RES, SICK, SICK_RES, SLEEP_RES, SLIMED, SLOW_DIGESTION, STONE_RES, STONED, STRANGLED, STUNNED, SWIMMING, TELEPAT, TELEPORT, TELEPORT_CONTROL, TIMEOUT, UNCHANGING, VOMITING, WARNING, WOUNDED_LEGS } from './const.js';
// Helper: read intrinsic/extrinsic/blocked for a property index
export function H(prop) { return game.u?.uprops?.[prop]?.intrinsic || 0; }
export function E(prop) { return game.u?.uprops?.[prop]?.extrinsic || 0; }
export function B(prop) { return game.u?.uprops?.[prop]?.blocked || 0; }
// C ref: you.h — Role_switch = urole.mnum
export function Role_switch() { return game.urole?.mnum ?? -1; }
export function setH(prop, val) {
if (!game.u.uprops) game.u.uprops = {};
if (!game.u.uprops[prop]) game.u.uprops[prop] = {};
game.u.uprops[prop].intrinsic = val;
}
export function setE(prop, val) {
if (!game.u.uprops) game.u.uprops = {};
if (!game.u.uprops[prop]) game.u.uprops[prop] = {};
game.u.uprops[prop].extrinsic = val;
}
// C: Sick_val() — sickness intrinsic
export function Sick_val() {
return H(SICK);
}
// Armor accessors
export function uarm() { return game.u?.uarm; }
export function uarmc() { return game.u?.uarmc; }
export function uarmh() { return game.u?.uarmh; }
export function uarms() { return game.u?.uarms; }
export function uarmg() { return game.u?.uarmg; }
export function uarmf() { return game.u?.uarmf; }
export function uarmu() { return game.u?.uarmu; }
// C: uhandedness — 0=right, 1=left
const RIGHT_HANDED = 0;
const LEFT_HANDED = 1;
export function ULEFTY() { return game.u?.uhandedness === LEFT_HANDED; }
export function URIGHTY() { return game.u?.uhandedness === RIGHT_HANDED; }
// C: locomotion(ptr, verb) — descriptive movement verb
// locomotion canonical in mondata.js (full implementation with is_floater/is_flyer
// branches matching mondata.c). The old 3-case stub here was a leftover.
import { locomotion } from './mondata.js';
// C: u_locomotion(verb) — descriptive movement verb for hero
export function u_locomotion(verb) {
return locomotion(game.player.data, verb);
}
// C ref: dungeon.h — level type checks
export function is_rogue_level(lev) {
const l = lev ?? game?.u?.uz;
const rl = game?.rogue_level;
return !!l && !!rl && l.dnum === rl.dnum && l.dlevel === rl.dlevel;
}
export function Is_sanctum(lev) {
const l = lev ?? game?.u?.uz;
const sl = game?.sanctum_level;
return !!l && !!sl && l.dnum === sl.dnum && l.dlevel === sl.dlevel;
}
// C ref: youprop.h — individual H-property readers
export function HFast() { return H(FAST); }
export function HBlinded() { return H(BLINDED); }
export function HHallucination() { return H(HALLUC); }
export function HLevitation() { return H(LEVITATION); }
export function HStun() { return H(STUNNED); }
export function HConfusion() { return H(CONFUSION); }
export function EFast() { return E(FAST); }
export function Fast() { return !!(H(FAST) || E(FAST)); }
// --- Resistances ---
// C pattern: Fire_resistance = (HFire_resistance || EFire_resistance)
export function Fire_resistance() { return !!(H(FIRE_RES) || E(FIRE_RES)); }
export function Cold_resistance() { return !!(H(COLD_RES) || E(COLD_RES)); }
export function Sleep_resistance() { return !!(H(SLEEP_RES) || E(SLEEP_RES)); }
export function Disint_resistance() { return !!(H(DISINT_RES) || E(DISINT_RES)); }
export function Shock_resistance() { return !!(H(SHOCK_RES) || E(SHOCK_RES)); }
export function Poison_resistance() { return !!(H(POISON_RES) || E(POISON_RES)); }
export function Acid_resistance() { return !!(H(ACID_RES) || E(ACID_RES)); }
export function Stone_resistance() { return !!(H(STONE_RES) || E(STONE_RES)); }
export function Drain_resistance() { return !!(H(DRAIN_RES) || E(DRAIN_RES)); }
export function Sick_resistance() { return !!(H(SICK_RES) || E(SICK_RES)); }
export function Antimagic() { return !!(H(ANTIMAGIC) || E(ANTIMAGIC)); }
export function Fixed_abil() { return !!(H(FIXED_ABIL) || E(FIXED_ABIL)); }
export function Detect_monsters() { return !!(H(DETECT_MONSTERS) || E(DETECT_MONSTERS)); }
export function Searching() { return !!(H(SEARCHING) || E(SEARCHING)); }
export function Warning() { return !!(H(WARNING) || E(WARNING)); }
export function Clairvoyant() { return !!(H(CLAIRVOYANT) || E(CLAIRVOYANT)) && !B(CLAIRVOYANT); }
export function Infravision() { return !!(H(INFRAVISION) || E(INFRAVISION)); }
export function Regeneration() { return !!(H(REGENERATION) || E(REGENERATION)); }
// --- Status effects ---
// C: Stunned = HStun (intrinsic only, no extrinsic)
export function Stunned() { return !!H(STUNNED); }
// C: Confusion = HConfusion (intrinsic only)
export function Confusion() { return !!H(CONFUSION); }
// System options — currently all true/enabled
export function SYSOPT_SEDUCE() { return true; }
// C: Blind = ((HBlinded || EBlinded) && !BBlinded)
export function Blind() { return !!((H(BLINDED) || E(BLINDED)) && !B(BLINDED)); }
// C: Blinded = (HBlinded && !BBlinded) — timed blindness only
export function Blinded() { return !!(H(BLINDED) && !B(BLINDED)); }
// C: Blindfolded = EBlinded (wearing blindfold/towel)
export function Blindfolded() { return !!E(BLINDED); }
// C: Deaf = (HDeaf || EDeaf || u.uroleplay.deaf)
export function Deaf() { return !!(H(DEAF) || E(DEAF) || game.u?.uroleplay?.deaf); }
// C: Hallucination = (HHallucination && !Halluc_resistance)
export function Halluc_resistance() { return !!(H(HALLUC_RES) || E(HALLUC_RES)); }
export function Hallucination() { return !!(H(HALLUC) && !Halluc_resistance()); }
// C: Invulnerable = u.uprops[INVULNERABLE].intrinsic
export function Invulnerable() { return !!H(35 /* INVULNERABLE */); }
// C: Invis = ((HInvis || EInvis) && !BInvis)
export function Invis() { return !!((H(INVIS) || E(INVIS)) && !B(INVIS)); }
// C: Invisible = (Invis && !See_invisible)
export function Invisible() { return Invis() && !See_invisible(); }
// --- Vision ---
// C: See_invisible = (HSee_invisible || ESee_invisible)
export function See_invisible() { return !!(H(SEE_INVIS) || E(SEE_INVIS)); }
// C: Blind_telepat = (HTelepat || ETelepat)
export function Blind_telepat() { return !!(H(TELEPAT) || E(TELEPAT)); }
// C: Unblind_telepat = ETelepat
export function Unblind_telepat() { return !!E(TELEPAT); }
// --- Movement ---
// C: Levitation = ((HLevitation || ELevitation) && !BLevitation)
export function Levitation() { return !!((H(LEVITATION) || E(LEVITATION)) && !B(LEVITATION)); }
// C: Flying = ((HFlying || EFlying) && !BFlying)
// Full definition also checks steed and polyself — simplified here
export function Flying() { return !!((H(FLYING) || E(FLYING)) && !B(FLYING)); }
// C: Underwater = u.uinwater
export function Underwater() { return !!game.u?.uinwater; }
// C: Swimming = (HSwimming || ESwimming || is_swimmer(youmonst.data))
export function Swimming() { return !!(H(SWIMMING) || E(SWIMMING)); }
// C: Amphibious = (HAmphibious || EAmphibious || is_amphibious(youmonst.data))
export function Amphibious() { return !!(H(40 /* AMPHIBIOUS */) || E(40 /* AMPHIBIOUS */)); }
// C: Passes_walls = (HPasses_walls || EPasses_walls)
export function Passes_walls() { return !!(H(PASSES_WALLS) || E(PASSES_WALLS)); }
// --- Combat ---
// C: Free_action = (HFree_action || EFree_action)
export function Free_action() { return !!(H(FREE_ACTION) || E(FREE_ACTION)); }
// C: Protection_from_shape_changers = (HProt_from_shape_changers || EProt_from_shape_changers)
export function Protection_from_shape_changers() { return !!(H(PROT_FROM_SHAPE_CHANGERS) || E(PROT_FROM_SHAPE_CHANGERS)); }
// Dunce cap caps INT and WIS at 6
export function Dunce_cap() { return !!game.uarmh && game.uarmh.otyp === DUNCE_CAP; }
// Gauntlets of power set STR to 18/100
export function Gauntlets_of_power() { return !!game.uarmg && game.uarmg.otyp === 161 /* GAUNTLETS_OF_POWER */; }
// --- Level classification predicates ---
// C: Sokoban = In_sokoban(&u.uz)
export function In_sokoban(uz) {
const g = game;
const z = uz ?? g.u?.uz;
if (!z || g.sokoban_dnum == null) return false;
return z.dnum === g.sokoban_dnum;
}
export function Sokoban() {
return !!game.Sokoban || !!game.level?.flags?.sokoban_rules || In_sokoban(game.u?.uz);
}
// C ref: you.h — #define In_endgame(uz) ((uz)->dnum == astral_level.dnum)
export function In_endgame(uz) {
const lev = uz ?? game?.u?.uz;
const al = game?.astral_level;
return !!lev && !!al && lev.dnum === al.dnum;
}
// C ref: you.h — #define Is_astralevel(uz) (In_endgame(uz) && (uz)->dlevel == 1)
export function Is_astralevel(uz) {
const lev = uz ?? game?.u?.uz;
return In_endgame(lev) && !!lev && lev.dlevel === 1;
}
// C ref: you.h — #define Inhell (u.uz.dnum == hell_dnum)
// C ref: you.h — Inhell = In_hell(&u.uz)
// Fixed: game.hell_dnum is never set. Use dungeons[].flags.hellish instead.
export function Inhell(uz) {
const lev = uz ?? game?.u?.uz;
if (!lev) return false;
return !!game.dungeons?.[lev.dnum]?.flags?.hellish;
}
// C ref: you.h — #define In_hell(uz) (Inhell)
export function In_hell(uz) { return Inhell(uz); }
// C ref: dungeon.c:2011 Invocation_lev(d_level *lev)
export function Invocation_lev(lev) {
const l = lev ?? game?.u?.uz;
if (!l || !In_hell(l)) return false;
const d = game.dungeons?.[l.dnum];
return !!d && l.dlevel === d.num_dunlevs - 1;
}
// C ref: you.h — #define In_quest(uz) ((uz)->dnum == quest_dnum)
export function In_quest(uz) {
const lev = uz ?? game?.u?.uz;
return !!lev && !!game?.quest_dnum && lev.dnum === game.quest_dnum;
}
// C ref: you.h — #define In_mines(uz) ((uz)->dnum == mines_dnum)
export function In_mines(uz) {
const lev = uz ?? game?.u?.uz;
return !!lev && !!game?.mines_dnum && lev.dnum === game.mines_dnum;
}
// C ref: you.h — #define In_V_tower(uz) ((uz)->dnum == tower_dnum)
export function In_V_tower(uz) {
const lev = uz ?? game?.u?.uz;
return !!lev && !!game?.tower_dnum && lev.dnum === game.tower_dnum;
}
// C ref: you.h — plane classification
export function Is_waterlevel(uz) { const lev = uz ?? game?.u?.uz; const wl = game?.water_level; return !!lev && !!wl && lev.dnum === wl.dnum && lev.dlevel === wl.dlevel; }
export { Is_firelevel, Is_earthlevel } from './const.js';
export function Is_airlevel(uz) { const lev = uz ?? game?.u?.uz; const al = game?.air_level; return !!lev && !!al && lev.dnum === al.dnum && lev.dlevel === al.dlevel; }
// C ref: hack.h — #define um_dist(x,y,n) (distu(x,y) > (n))
// C ref: youprop.h — Very_fast = (HFast & ~INTRINSIC) || EFast
export function Very_fast() {
return !!((H(FAST) & ~INTRINSIC) || E(FAST));
}
// C ref: you.h — Ugender = poly_gender() which is FEMALE if flags.female
export function Ugender() {
return game.flags?.female ? 1 : 0; // FEMALE=1, MALE=0
}
// C ref: youprop.h — Half_gas_damage = wearing wet towel as blindfold
export function Half_gas_damage() {
const ublindf = game.u?.ublindf;
return !!(ublindf && ublindf.otyp === TOWEL && ublindf.spe > 0);
}
// C ref: monst.h — U_AP_TYPE = youmonst.m_ap_type & M_AP_TYPMASK
export function U_AP_TYPE() {
return (game.youmonst?.m_ap_type ?? 0) & 0x7; // M_AP_TYPMASK
}
// C ref: apply.c:692 um_dist() — Chebyshev distance > n
export function um_dist(x, y, n) {
return Math.abs((game.u?.ux ?? 0) - x) > n || Math.abs((game.u?.uy ?? 0) - y) > n;
}
// C ref: you.h — special level classification
export { Is_stronghold, Is_botlevel, Is_rogue_level, Is_oracle_level, Is_knox_level, Is_juiblex_level } from './const.js';
// --- Polymorph ---
// C: Upolyd = (u.mtimedone != 0)
export function Upolyd() {
return !!game.u?.mtimedone;
}
// C: Unchanging = (HUnchanging || EUnchanging)
export function Unchanging() { return !!(H(UNCHANGING) || E(UNCHANGING)); }
// C ref: role.c — Role_if checks current role index
export function Role_if(pm) {
return game.urole?.mnum === pm;
}
// C ref: you.h — Race_if checks current race index
export function Race_if(pm) {
return game.urace?.mnum === pm;
}
// C ref: macro — maybe_polyd(ifpolyd, ifnot)
export function maybe_polyd(ifpolyd, ifnot) {
return Upolyd() ? ifpolyd : ifnot;
}
// C ref: you.h — Luck = u.uluck + u.moreluck
export function getLuck() {
const u = game.u;
return (u?.uluck ?? 0) + (u?.moreluck ?? 0);
}
export { getLuck as Luck };
// --- Strangled / Fumbling / Breathing ---
// C: Strangled = u.uprops[STRANGLED].intrinsic
export function Strangled() { return !!H(STRANGLED); }
// C: Fumbling = (HFumbling || EFumbling)
export function Fumbling() { return !!(H(FUMBLING) || E(FUMBLING)); }
// C: Breathless = (HMagical_breathing || EMagical_breathing || !breaths(youmonst.data))
export function Breathless() { return !!(H(MAGICAL_BREATHING) || E(MAGICAL_BREATHING)); }
// C: Blindfolded_only = (Blindfolded && !Blind)
export function Blindfolded_only() { return Blindfolded() && !Blind(); }
// --- Timed values ---
// C: BlindedTimeout = u.uprops[BLINDED].intrinsic & TIMEOUT
export function BlindedTimeout() { return (H(BLINDED)) & TIMEOUT; }
// --- Protection ---
// C: HProtection & INTRINSIC
export function HProtection() { return !!H(PROTECTION); }
// --- Status effects (timed) ---
// C: Sick = HSick (intrinsic, timed)
export function Sick() { return !!H(SICK); }
export function Stoned() { return !!H(STONED); }
export function Vomiting() { return !!H(VOMITING); }
export function Glib() { return !!H(GLIB); }
export function Slimed() { return !!H(SLIMED); }
export function Wounded_legs() { return !!(H(WOUNDED_LEGS) || E(WOUNDED_LEGS)); }
// --- Movement/combat properties ---
// C: Displaced = (HDisplaced || EDisplaced)
export function Displaced() { return !!(H(DISPLACED) || E(DISPLACED)); }
// C: Teleport_control = (HTeleport_control || ETeleport_control)
export function Teleport_control() { return !!(H(TELEPORT_CONTROL) || E(TELEPORT_CONTROL)); }
// C: Polymorph_control = (HPolymorph_control || EPolymorph_control)
export function Polymorph_control() { return !!(H(POLYMORPH_CONTROL) || E(POLYMORPH_CONTROL)); }
// C: Polymorph = (HPolymorph || EPolymorph)
export function Polymorph() { return !!(H(POLYMORPH) || E(POLYMORPH)); }
// C: Teleportation = (HTeleportation || ETeleportation)
export function Teleportation() { return !!(H(TELEPORT) || E(TELEPORT)); }
// C: Slow_digestion = (HSlow_digestion || ESlow_digestion)
export function Slow_digestion() { return !!(H(SLOW_DIGESTION) || E(SLOW_DIGESTION)); }
// C: Half_spell_damage = (HHalf_spell_damage || EHalf_spell_damage)
export function Half_spell_damage() { return !!(H(HALF_SPDAM) || E(HALF_SPDAM)); }
// C: Half_physical_damage = (HHalf_physical_damage || EHalf_physical_damage)
export function Half_physical_damage() { return !!(H(HALF_PHDAM) || E(HALF_PHDAM)); }
// C: Reflecting = (HReflecting || EReflecting)
export function Reflecting() { return !!(H(REFLECTING) || E(REFLECTING)); }
// C: Lifesaved = (HLifesaved || ELifesaved)
export function Lifesaved() { return !!(H(LIFESAVED) || E(LIFESAVED)); }
// C ref: include/youprop.h — #define Punished (uball != 0)
export function Punished() { return !!game.u?.uball; }
// C: Conflict = (HConflict || EConflict)
export function Conflict() { return !!(H(CONFLICT) || E(CONFLICT)); }
function await_import_hacklib() {
// This is a placeholder for the actual dynamic import or linkage.
// In this project, circular deps are often handled via lazy lookups on the game object.
// For now, we assume distu is available on game or similar, or just require it.
const m = { distu: (x, y) => {
const g = game;
const dx = g.u.ux - x;
const dy = g.u.uy - y;
return dx*dx + dy*dy;
}};
return m;
}
// C ref: dungeon.c — #define has_ceiling(uz) (!Is_airlevel(uz) && !Is_waterlevel(uz))
export function has_ceiling(uz) {
const lev = uz ?? game?.u?.uz;
return !Is_airlevel(lev) && !Is_waterlevel(lev);
}
// ── Awareness ──
// C: Unaware = (multi < 0 && (unconscious() || is_fainted()))
export function Unaware() {
if ((game.multi ?? 0) >= 0) return false;
return unconscious() || is_fainted();
}
// C: unconscious() — sleeping or paralyzed
export function unconscious() {
// C ref: trap.c:6757-6766
// unconscious() is true when multi<0 and hero is sleeping, or when
// nomovemsg indicates wake-up from unconsciousness/paralysis.
if ((game.multi || 0) >= 0) return false;
if (game.u?.usleep) return true;
const msg = game.nomovemsg;
return typeof msg === 'string'
&& (msg.startsWith('You awake')
|| msg.startsWith('You regain con')
|| msg.startsWith('You are consci'));
}
// C: is_fainted() — fainted from lack of food
export function is_fainted() {
return !!(game.u?.uhs >= 5); // FAINTED = 5
}
// ── Damage reduction macros ──
// C: Maybe_Half_Phys(dmg) = Half_physical_damage ? (dmg+1)/2 : dmg
export function Maybe_Half_Phys(dmg) {
return Half_physical_damage() ? Math.trunc((dmg + 1) / 2) : dmg;
}
// C: Maybe_Half_Spell(dmg) = Half_spell_damage ? (dmg+1)/2 : dmg
export function Maybe_Half_Spell(dmg) {
return Half_spell_damage() ? Math.trunc((dmg + 1) / 2) : dmg;
}
|