@create #258 named LRPG Illuminated Room:LRPG Illuminated Room,RPX Light Room,Lighted Room,Light Room
@prop #16070."illumination" {} rc
@prop #16070."lightlevel" 0 rc
@prop #16070."totally_dark_msg" "It's pitch black in here." rc
@prop #16070."adjacent" {} rc
@prop #16070."fully_lit" 100 rc
@prop #16070."illumination_msg" {} rc
;;#16070.("illumination_msg") = {"Shadows are cast about %T from the pitiful light source.", "%T is slightly illuminated by the flickering light source.", "You can almost see %T clearly in the light.", "%T is well lit by the strong light source.", "%T is flooded with the blinding light emanating from the powerful light source."}
@prop #16070."light_enabled" 0 r
@prop #16070."dark_description" "Sure is some dark in here, boy." rc
"#16070.("misc_notes") => E_PERM (Permission denied)
"#16070.("magic_effects") => E_PERM (Permission denied)
"#16070.("combat_effects") => E_PERM (Permission denied)
"#16070.("unannounced") => E_PERM (Permission denied)
"#16070.("allowed_exits") => E_PERM (Permission denied)
;;#16070.("dawn_msg") = ""
;;#16070.("night_msg") = ""
;;#16070.("dusk_msg") = ""
;;#16070.("day_msg") = ""
;;#16070.("free_entry") = 0
"#16070.("entrances") => E_PERM (Permission denied)
"#16070.("exits") => E_PERM (Permission denied)
;;#16070.("ctype") = 5
"#16070.("key") => E_PERM (Permission denied)
;;#16070.("aliases") = {"LRPG Illuminated Room", "RPX Light Room", "Lighted Room", "Light Room"}
;;#16070.("description") = "Woo, pretty dark in here ... but there is that dimmer switch on the wall."
;;#16070.("object_size") = {11110, 1141286561}

@verb #16070:"enterfunc" this none this
@program #16070:enterfunc
"enterfunc ( victim ) =>";
"In addition to normal functions, make a call to see if the";
"lightlevel of the room needs adjusting.";
{what} = args;
if ((this.light_enabled && (what.location == this)) && (what in $local.rpg.pcs))
  this:illuminate(what);
endif
pass(what);
"THX1138 13-MAR-1997 -- Added.";
player:tell("Room illuminances: ", toliteral(this.illumination));
.

@verb #16070:"illuminate" this none this
@program #16070:illuminate
(rpg = $local.rpg):secure();
if (this.light_enabled)
  {what} = args;
  lightlevel = this.lightlevel;
  if (valid(doll = rpg:get_doll(what)))
    for t in (doll.lights)
      this.illumination = setadd(this.illumination, t);
      this.lightlevel = this.lightlevel + t:candlefeet();
    endfor
    player:tell("Doll illuminations: ", toliteral(doll.lights), " on ", #20:nn(doll));
  elseif (rpg:trusted_verb(what, "candlefeet"))
    this.illumination = setadd(this.illumination, what);
    this.lightlevel = this.lightlevel + what:candlefeet();
  endif
endif
"THX1138 13-MAR-1997 -- Added.";
.

@verb #16070:"darken" this none this
@program #16070:darken
(rpg = $local.rpg):secure();
if (this.light_enabled)
  {what} = args;
  lightlevel = this.lightlevel;
  if (valid(doll = rpg:get_doll(what)))
    for t in (doll.lights)
      this.illumination = setremove(this.illumination, t);
      this.lightlevel = this.lightlevel - t:candlefeet();
    endfor
  elseif (rpg:trusted_verb(what, "candlefeet"))
    this.illumination = setremove(this.illumination, what);
    this.lightlevel = this.lightlevel - what:candlefeet();
  endif
endif
"THX1138 13-MAR-1997 -- Added.";
.

@verb #16070:"exitfunc" this none this
@program #16070:exitfunc
"exitfunc ( victim ) =>";
"In addition to normal functions, make a call to see if the lightlevel of the room needs adjusting.";
{what} = args;
if (!(rpg = $local.rpg):trusted_efunc())
  return E_PERM;
endif
pass(what);
if ((this.light_enabled && (what.location != this)) && (what in rpg.pcs))
  this:darken(what);
endif
"THX1138 13-MAR-1997 -- Added.";
.

@verb #16070:"illumination_check" this none this
@program #16070:illumination_check
{?lightlevel} = args;
if (this.illumination)
  if (lightlevel < 1)
    this:announce_all_but({player}, this.name, " is flooded with light.");
    " ... show the person who walked in the room.";
    if ("light" in $list_utils:slice(callers(), 2))
      this:look_self();
    endif
  endif
else
  if (lightlevel > 0)
    this.lightlevel = 0;
    this:announce_all(this.name, " is cast into darkness.");
  endif
endif
.

@verb #16070:"description" this none this
@program #16070:description
"description() ... returns the regular integrating room description unless the lightlevel in the room is less than one, in which case it returns :dark_description().";
if ((!this.illumination) || (this.lightlevel < 1))
  return this:dark_description();
else
  if (typeof(desc = pass(@args)) != LIST)
    desc = {desc};
  endif
  if (desc = this:pare_list(desc))
    return desc;
  else
    return {"The light in here is very dim and you have difficulty making out details."};
  endif
endif
.

@verb #16070:"visible" this none this
@program #16070:visible
who = (args == {}) ? player | args[1];
firstlist = setremove({@who.contents, @this.contents, @this:exits()}, who);
for each_room in (this.adjacent)
  if (each_room in this.visible_from_here)
    if (each_room.lightlevel > 4)
      for each_thing in (each_room.contents)
        firstlist = setadd(firstlist, each_thing);
      endfor
    endif
  endif
endfor
return firstlist;
.

@verb #16070:"dark_description" this none this
@program #16070:dark_description
return this.dark_description || "It is too dark to see.";
.

@verb #16070:"say" any any any rxd
@program #16070:say
attrib = ((this.lightlevel * 15) / this.fully_lit) ? player.name | "Somebody";
try
  player:tell("You say, \"", argstr, "\"");
  "If light greater than 7 percent of fully, players can figure out who is saying what.";
  this:announce(attrib, " ", $gender_utils:get_conj("says", player), ", \"", argstr, "\"");
except (ANY)
  "Don't really need to do anything but ignore the idiot who has a bad :tell";
endtry
.

@verb #16070:"look_self" this none this
@program #16070:look_self
if (this.light_enabled && (player.location == this))
  if (this.illumination)
    return pass(@args);
  endif
elseif (this.lightlevel)
  return pass(@args);
endif
return pass(@args);
"elseif (\"enterfunc\" in $list_utils:slice(callers(), 2))";
"  this:illumination_check(player);";
.

@verb #16070:"l*ook" any any any rxd
@program #16070:look
if (!this.lightlevel)
  if (this.totally_dark_msg)
    player:tell(this.totally_dark_msg);
  else
    player:tell("You can't see anything.");
  endif
else
  pass(@args);
endif
.

@verb #16070:"pare*_list" this none this
@program #16070:pare_list
"pare_list(incoming LIST) => outgoing list pared down by room lighting.";
{incoming} = args;
if (((lightlevel = this.lightlevel) < 1) || (!incoming))
  return {};
elseif ((fully = this.fully_lit) <= lightlevel)
  return incoming;
else
  outgoing = {};
  for t in (incoming)
    if (random(fully) <= lightlevel)
      outgoing = setadd(outgoing, t);
    endif
  endfor
  return outgoing;
endif
"THX1138 15-MAR-1997 -- Added.";
.

@verb #16070:"emote think" any any any rxd
@program #16070:emote
attrib = ((this.lightlevel * 15) / this.fully_lit) ? player.name | "Somebody";
if (verb == "think")
  this:announce_all(attrib, " . o O ( ", argstr[1..length(argstr)], " )");
elseif ((argstr != "") && (argstr[1] == ":"))
  this:announce_all(attrib, argstr[2..length(argstr)]);
else
  this:announce_all(attrib, " ", argstr);
endif
.

@verb #16070:"tell_contents" this none this
@program #16070:tell_contents
{contents, ctype} = args;
pass(this:pare_list(contents), ctype);
.

@verb #16070:"announce_all" this none this
@program #16070:announce_all
if (args[1] == player.name)
  args[1] = ((this.lightlevel * 15) / this.fully_lit) ? player.name | "Somebody";
endif
for dude in (this:contents())
  try
    dude:tell(@args);
  except (ANY)
    "Just ignore the dude with the stupid :tell";
    continue dude;
  endtry
endfor
.

@verb #16070:"obvious_exits obvious_entrances" this none this
@program #16070:obvious_exits
if ((!this.light_enabled) || (player in $local.rpg.gms))
  return pass(@args);
endif
return this:pare_list(pass(@args));
.

"***finished***