Dump of #18754 (Generic Light Source)

@create #59933 named generic light source:generic light source,light,source
@prop #18754."fuel_packets" 8 r
@prop #18754."home" #16020 rc
@prop #18754."burning_desc" "A small translucent orb, furiously shedding light on the scene." rc
@prop #18754."burning" 0 r
"#18754.("max_charges") => E_PERM (Permission denied)
@prop #18754."heart" #48923 rc
@prop #18754."lumens" 12 r
"#18754.("bonus") => E_PERM (Permission denied)
"#18754.("visible_spells") => E_PERM (Permission denied)
"#18754.("no_imp") => E_PERM (Permission denied)
"#18754.("dodgable") => E_PERM (Permission denied)
"#18754.("parryable") => E_PERM (Permission denied)
"#18754.("slowness") => E_PERM (Permission denied)
"#18754.("parry") => E_PERM (Permission denied)
"#18754.("attack") => E_PERM (Permission denied)
"#18754.("pen") => E_PERM (Permission denied)
"#18754.("dam") => E_PERM (Permission denied)
"#18754.("skill") => E_PERM (Permission denied)
;;#18754.("pierce") = 0
"#18754.("max_str_bonus") => E_PERM (Permission denied)
"#18754.("can_degrade") => E_PERM (Permission denied)
"#18754.("track_usage") => E_PERM (Permission denied)
;;#18754.("encumbrance") = 1
;;#18754.("manufactured") = 820783482
;;#18754.("worth") = -1
;;#18754.("condition") = 100
;;#18754.("use_spell_msg_db") = 1
;;#18754.("odrop_failed_msg") = "%<tries> to drop %t but fails!"
;;#18754.("odrop_succeeded_msg") = "%<drops> %t."
;;#18754.("otake_succeeded_msg") = "%<picks> up %t."
"#18754.("key") => E_PERM (Permission denied)
;;#18754.("aliases") = {"generic light source", "light", "source"}
;;#18754.("description") = "A small translucent orb."
;;#18754.("object_size") = {17479, 1141286561}

@verb #18754:"description" this none this
@program #18754:description
if (this.burning)
  return this.burning_desc;
else
  return pass(@args);
endif
.

@verb #18754:"douse ex*tinguish" this none none rx
@program #18754:douse
rpg = $local.rpg;
if (!rpg:trusted())
  return E_PERM;
elseif ((player.location != this.location) && (this.location != player))
  player:tell("You cannot reach ", this.name, " from there.");
elseif (!this.burning)
  player:tell("The ", this.name, " is not lit.");
else
  "OK, actually do the dousing.";
  rpg:say_action("%N %<extinguishes> %t.", player, this);
  this:do_douse();
endif
"DR 22-MAR-94 -- Fixed permissions check bug and added location check, cleaned up the logic for better readability.";
"DR 06-AUG-94 -- Added heart functionality.";
"Profane 28-FEB-95 -- s/$object_utils:has_verb/rpg:trusted_verb/1-$";
"Profane 4-MAR-95 -- changed message announcing to rpg:say_action. Maybe others will actually SEE the message now.";
"Profane 7-JAN-96 1908PST -- moved actual douse bit to :do_douse";
.

@verb #18754:"tell_condition" this none this rx
@program #18754:tell_condition
if (this.fuel_packets == 0)
  player:tell(("The " + this.name) + " is on its last legs!");
elseif (this.fuel_packets == this.max_charges)
  player:tell("The ", this.name, " is spiffy and new!");
  return;
else
  factor = this.max_charges / this.fuel_packets;
  if (factor > 1)
    if (factor > 2)
      player:tell(("The " + this.name) + " is looking quite exhausted.");
    else
      player:tell(("The " + this.name) + " is starting to look a bit tired.");
    endif
  endif
endif
.

@verb #18754:"possible_glimmer" this none this rx
@program #18754:possible_glimmer
if (#46:trust())
  if ((random(100) > 95) && $object_utils:has_callable_verb(args[1], "echo"))
    args[1]:echo("You notice a glimmer of light from somewhere nearby.  Watch for more.");
  endif
endif
.

@verb #18754:"condition" this none this rx
@program #18754:condition
factor = 0;
if (this.max_charges)
  factor = 100 / this.max_charges;
endif
if (!factor)
  factor = 1;
endif
return this.fuel_packets * factor;
"DR 22-MAR-94 - Originated.  Sort of a stopgap, since max_charges>100 is not well handled.";
.

@verb #18754:"destroy" this none this
@program #18754:destroy
(rpg = $local.rpg):secure();
doll = rpg:get_doll(loc = this.location);
if (valid(doll))
  doll:relight(this, 0);
else
  `loc:relight(this, 0) ! ANY';
endif
rpg.recycler:_recycle(this);
return;
if (rpg:trusted_verb(loc, "illumination_check"))
  loc:illumination_check();
else
  if (rpg:trusted_verb(ploc = loc.location, "illumination_check") && (loc in rpg.pcs))
    ploc:illumination_check();
  endif
endif
"DR 18-MAY-94 Moved from throwable to light source, where it belongs, added security check.";
"Profane 2-MAR-95 13:33EST - s/rpg:trusted()/rpg:trust()/1 &&  s/$object_utils:has_verb/rpg:trusted_verb/1-$ -- make security actually work";
"THX1138 23-FEB-1997 -- Tossed the messaging.  Will use Profane's trusted checks here for all kids instead.  Messaging on the kids.";
"THX (#105941) - Sun Apr  1, 2001 - Started changing over to the new lighting system.";
.

@verb #18754:"cpr" this none this rx
@program #18754:cpr
"then modified to do traditional RPG security check.";
"Recompute order, then jump-start the heart.";
if (!$local.rpg:trust())
  return E_PERM;
endif
this.heart:add(this);
.

@verb #18754:"pulse" this none this
@program #18754:pulse
if (!(rpg = $local.rpg):trust())
  return E_PERM;
endif
if (this.burning)
  `this:possible_glimmer(this.location.location) ! E_PROPNF, E_INVIND => this:moveto(rpg.cemetery)';
endif
"Mooshie (#106469) - Fri Oct 10 21:16:55 1997 PDT - Added error catching if this is stuck in #-1.";
.

@verb #18754:"moveto(obsolete)" this none this
@program #18754:moveto(obsolete)
db = $local.rpg;
dest = args[1];
doll = db:get_doll(place = this.location);
if ((valid(dest) && (valid(doll) && (dest.location == place))) && (!(dest.owner in db.gms)))
  return E_PERM;
elseif ((!valid(place = this.location)) || (!valid(dest)))
  ok = db:trust();
elseif (place.location in {dest, dest.location})
  ok = db:trust(place.owner, place);
elseif (place == dest.location)
  ok = db:trust(dest);
else
  ok = db:trust();
endif
if (!ok)
  return E_PERM;
else
  pass(dest);
  if ((((!valid(where = this.location)) || (where == place)) || $code_utils:verb_or_property(where, "opaque")) || 0)
  elseif ($local.rpg:trusted_verb(where, "illumination_check"))
    where:illumination_check();
  elseif (valid(where = this.location.location) && $local.rpg:trusted_verb(where, "illumination_check"))
    where:illumination_check();
  endif
endif
"Profane 4-MAR-95 13:00EST -- Added.";
.

@verb #18754:"locate(obsolete)" this none this
@program #18754:locate(obsolete)
"Copied from rpx throwable adventure gear (#9296):locate by UndergroundsKeeper (#77500) Thu Aug 15 12:30:35 1996 PDT";
target = args[1];
if ($object_utils:has_verb(target, "location"))
  return target:location();
endif
if ($object_utils:has_verb(target.location, "get_location"))
  return target.location:get_location(target);
endif
return target.location;
.

@verb #18754:"location(obsolete)" this none this
@program #18754:location(obsolete)
"Copied from rpx throwable adventure gear (#9296):location by UndergroundsKeeper (#77500) Thu Aug 15 12:30:39 1996 PDT";
if ($object_utils:has_verb(this.location, "get_location"))
  return this.location:get_location(this);
endif
return this.location;
.

@verb #18754:"title" this none this
@program #18754:title
name = (this.burning ? "lit " | "") + this.name;
prefix = $list_utils:iassoc("tell_contents", callers(), 2) ? $string_utils:a_or_an(name) + " " | "";
return prefix + name;
.

@verb #18754:"do_unwield" this none this
@program #18754:do_unwield
rpg = $local.rpg;
if (rpg:trusted(caller_perms()))
  this.burning ? this:douse() | 0;
  return pass(@args);
else
  return E_PERM;
endif
.

@verb #18754:"do_douse" this none this rx
@program #18754:do_douse
if (!this.burning)
  return E_NONE;
endif
(rpg = $local.rpg):secure();
this.burning = 0;
doll = rpg:get_doll(loc = this.location);
if (valid(doll))
  doll:relight(this, 0);
else
  `loc:relight(this, 0) ! ANY';
endif
this.heart:remove(this);
.

@verb #18754:"light" this none none rxd
@program #18754:light
rpg = $local.rpg;
if (callers() && (!rpg:trusted(caller_perms())))
  return E_PERM;
elseif ((player.location != (loc = this.location)) && (loc != player))
  player:tell("You can't reach ", this.name, " from there.");
elseif (this.burning)
  player:tell("The ", this.name, " is already lit.");
elseif (this.fuel_packets < 1)
  player:tell("The damn thing needs to be recharged.  It doesn't work!");
elseif (!valid(doll = rpg:get_doll(player)))
  player:tell("You can't figure out how.  Haven't been drinking your milk lately, eh?");
elseif (!this:may_wield(player))
else
  if ((loc == player) && (!(this in doll.wielding)))
    this:wield();
  endif
  rpg:say_action("%N %<lights> %t.", player, this);
  this:do_light(doll);
endif
"DR 22-MAR-94  - Added location check, rewrote for clarity.";
"Miles 21-MAY-94 -- made both .burning and .fuel_packets !c";
"DR 06-AUG-94 -- Added functionality for the heart.";
"DR 14-SEP-94 -- Fixed permissions bug.";
"Profane 28-FEB-95 -- s/$object_utils:has_verb/rpg:trusted_verb/1-$";
"Profane 4-MAR-95 -- changed message announcing to a rpg:say_action. Maybe others will actually SEE the message now.";
"THX (#105941) - Sun Apr  1, 2001 - Started changing for the new lighting system.  Including spawning guts off to :do_light().";
.

@verb #18754:"lumens" this none this
@program #18754:lumens
":lumens(OBJ lighted location) => luminous flux from this object in <lighted location>.";
"Generate a luminous flux from the lightsource in lumens.  Do this relative to. let's say, a candle:";
"e.g., a candle has a luminous intensity of about 1 candela.  Through all the region surrounding this intensity source we'd have 4 x pi solid angles.   This is approximately 12 lumens, then, in the case of the candle.   This will be fed into an approximation of room size to generate an illuminance.  Someone else can do the ray tracing (BWAH!!!)";
if (this.burning)
  return this.(verb);
else
  return 0;
endif
.

@verb #18754:"do_move" this none this
@program #18754:do_move
{oldloc, newloc} = args;
if (oldloc == newloc)
  return 0;
endif
(rpg = $local.rpg):secure();
pass(oldloc, newloc);
olddoll = rpg:get_doll(oldloc);
newdoll = rpg:get_doll(newloc);
if (valid(olddoll))
  olddoll:relight(this, 0);
  olddoll.lights || `oldloc.location:relight(olddoll, 0) ! ANY';
else
  `oldloc:relight(this, 0) ! ANY';
endif
if (valid(newdoll) && this:lumens(loc = newloc.location))
  newdoll.lights = setadd(newdoll.lights, this);
  loc:relight(newdoll, 1);
  fork (0)
    if (this in newdoll.wielding)
    elseif (this:lumens(newloc.location))
      this:wield(this);
    endif
  endfork
elseif (this:lumens(newloc))
  `newloc:relight(this, 1) ! ANY';
endif
"THX (#105941) - Sun Apr  1, 2001 - Started converting over to the new lighting system.";
.

@verb #18754:"recharge" this none this
@program #18754:recharge
{amount} = args;
$local.rpg:secure();
this.fuel_packets = this.fuel_packets + amount;
.

@verb #18754:"do_move(obsolete)" this none this
@program #18754:do_move(obsolete)
{oldloc, newloc} = args;
(rpg = $local.rpg):secure();
pass(oldloc, newloc);
if (this:lumens() && valid(doll = rpg:get_doll(newloc)))
  fork (0)
    if (this in doll.wielding)
    elseif (this:lumens())
      this:wield(this);
    endif
  endfork
endif
if ((((!valid(newloc)) || (newloc == oldloc)) || $code_utils:verb_or_property(newloc, "opaque")) || 0)
elseif (rpg:trusted_verb(newloc, "illumination_check"))
  newloc:illumination_check();
elseif (valid(newloc = newloc.location) && rpg:trusted_verb(newloc, "illumination_check"))
  newloc:illumination_check();
endif
.

@verb #18754:"do_douse(obsolete)" this none this rx
@program #18754:do_douse(obsolete)
if (!$local.rpg:trusted(caller_perms()))
  return E_PERM;
elseif (!this.burning)
  return E_NONE;
else
  this.burning = 0;
  if ($local.rpg:trusted_verb(this.location, "illumination_check"))
    this.location:illumination_check();
  endif
  if ($local.rpg:trusted_verb(this.location.location, "illumination_check"))
    this.location.location:illumination_check();
  endif
  this.heart:remove(this);
endif
.

@verb #18754:"light(obsolete)" this none none rxd
@program #18754:light(obsolete)
"Copied from Project Planner (#797):light by THX1138 (#105941) Sat Feb 15 07:44:01 1997 PST";
rpg = $local.rpg;
if (callers() && (!rpg:trusted(caller_perms())))
  return E_PERM;
elseif ((player.location != (loc = this.location)) && (loc != player))
  player:tell("You can't reach ", this.name, " from there.");
elseif (this.burning)
  player:tell("The ", this.name, " is already lit.");
elseif (this.fuel_packets < 1)
  player:tell("The damn thing needs to be recharged.  It doesn't work!");
elseif (!valid(doll = rpg:get_doll(player)))
  player:tell("You can't figure out how.  Haven't been drinking your milk lately, eh?");
else
  if ((loc == player) && (!(this in doll.wielding)))
    this:wield();
  endif
  rpg:say_action("%N %<lights> %t.", player, this);
  this.fuel_packets = this.fuel_packets - 1;
  this.burning = 1;
  if ((!$object_utils:isa(loc, $room)) && valid(loc.location))
    if (rpg:trusted_verb(loc.location, "illumination_check"))
      loc.location:illumination_check();
    endif
  elseif (rpg:trusted_verb(loc, "illumination_check"))
    loc:illumination_check();
  endif
  this.heart:add(this);
endif
"DR 22-MAR-94  - Added location check, rewrote for clarity.";
"Miles 21-MAY-94 -- made both .burning and .fuel_packets !c";
"DR 06-AUG-94 -- Added functionality for the heart.";
"DR 14-SEP-94 -- Fixed permissions bug.";
"Profane 28-FEB-95 -- s/$object_utils:has_verb/rpg:trusted_verb/1-$";
"Profane 4-MAR-95 -- changed message announcing to a rpg:say_action. Maybe others will actually SEE the message now.";
.

@verb #18754:"do_light" this none none rxd
@program #18754:do_light
{doll} = args;
if (this.burning)
  return E_NONE;
endif
(rpg = $local.rpg):secure();
this.fuel_packets = this.fuel_packets - 1;
this.burning = 1;
if (valid(doll) && (this.location == doll.character))
  doll:relight(this, 1);
else
  `this.location:relight(this, 1) ! ANY';
endif
this.heart:add(this);
"THX (#105941) - Mon Apr  2, 2001 - Added.";
.

"***finished***