Self-Cleaning Room #27777

Parent Owner Flags Source rpg_march_2006/Dependencies/27777.txt

Aliases: Self-Cleaning Room

16 verbs · 17 properties · 1 children

Verbs

VerbSpecFlagsDefinerLines
enterfuncthis none this#2777749
exitfuncthis none this#277777
eject eject_basicthis none thisrxd#2777715
remove_object_msgthis none this#277771
litterpthis none thisrx#2777710
acceptablethis none this#2777711
deleteitemthis none this#277778
too_fullthis none thisrxd#2777710
most_idle_playerthis none thisrx#277778
shove_outthis none thisrxd#2777723
check_if_too_fullthis none thisrxd#2777710
shove_through_exitthis none thisrxd#2777729
flush_item_nowthis none this#277776
forget_trashthis none this#277775
@self-cleanany any nonerxd#2777727
set_self_cleaningthis none this#277775

Properties

PropertyDefinerFlagsOwnerValue
trigger_delay#27777rc20
delay#27777rc3600
remove_object_msg#27777rc"The housekeeper arrives to remove %[tcurrent_names] from %t."
trashtimes#27777r{}
trashobjects#27777r{}
current_names#27777r"nothing"
ejected#27777r#49853{}
maximum_players#27777rc50
idle_max#27777rc300
being_shoved#27777r#49853{}
self_cleaning#27777r0
entrances#27777not readable (E_PERM)
exits#27777not readable (E_PERM)
key#27777not readable (E_PERM)
aliases#27777{"Self-Cleaning Room"}
description#27777
value (646 chars)"This room optionally keeps itself relatively free of garbage. If this.self_cleaning is set, nonplayer objects which are not present in .residents are only allowed to remain for this.delay seconds (default one hour). This is not perfect; it uses :enterfunc as its trigger instead of forking. Messages: @remove_object gets printed to everyone in the room when an object is ejected. [Note kluge: instead of %n to describe the object being removed, use %[tcurrent_names]; this is so multiple items will be mentioned correctly in one message.]. @self-clean commandline verb toggles self cleaning, :set_self_cleaning permits programmatic shift."
object_size#27777{11115, 1141286549}

Ancestry

Ancestors (nearest first): none

Children: #3879 Matching Room

Call graph

calls n27777_0 #27777:enterfunc n27777_4 #27777:litterp n27777_0->n27777_4 n27777_10 #27777:check_if_too_full n27777_0->n27777_10 n27777_12 #27777:flush_item_now n27777_0->n27777_12 n27777_6 #27777:deleteitem n27777_0->n27777_6 n27777_2 #27777:eject n27777_0->n27777_2 n27777_9 #27777:shove_out n27777_10->n27777_9 n27777_7 #27777:too_full n27777_10->n27777_7 n27777_8 #27777:most_idle_player n27777_10->n27777_8 n27777_1 #27777:exitfunc n27777_1->n27777_6 n27777_5 #27777:acceptable n27777_5->n27777_4 n27777_11 #27777:shove_through_exit n27777_9->n27777_11 n27777_11->n27777_2 n27777_14 #27777:@self-clean n27777_15 #27777:set_self_cleaning n27777_14->n27777_15 n27777_13 #27777:forget_trash n27777_14->n27777_13

Source

enterfunc

Spec this none thisDefiner #27777

Referenced by

Source

1pass(@args);
2if (!this.self_cleaning)
3  return;
4endif
5item = args[1];
6now = time();
7if (this:litterp(item))
8  if (loc = item in this.trashobjects)
9    this.trashtimes[loc] = now;
10  else
11    this.trashobjects = {@this.trashobjects, item};
12    this.trashtimes = {@this.trashtimes, now};
13  endif
14else
15  this:check_if_too_full(item);
16endif
17ejectables = {};
18deleteables = {};
19for i in [1..length(this.trashobjects)]
20  item = this.trashobjects[i];
21  if ((!valid(item)) || (!this:litterp(item)))
22    "Maybe a player who connected, no longer litter.";
23    "Also, if a !valid object gets in here, we're in trouble and better flush it.";
24    deleteables = {@deleteables, item};
25  elseif (this:flush_item_now(i, now))
26    ejectables = {@ejectables, item};
27  endif
28endfor
29for x in (deleteables)
30  this:deleteitem(x);
31endfor
32if (ejectables)
33  fork (this.trigger_delay)
34    for x in (ejectables)
35      if (x.location == this)
36        this:eject_basic(x);
37      else
38        ejectables = setremove(ejectables, x);
39        if (x in this.trashobjects)
40          this:deleteitem(x);
41        endif
42      endif
43      this.current_names = $string_utils:english_list($list_utils:map_verb(ejectables, "title"));
44    endfor
45    if (ejectables)
46      this:announce_all($string_utils:pronoun_sub(this.remove_object_msg));
47    endif
48  endfork
49endif

exitfunc

Spec this none thisDefiner #27777

Referenced by

Source

1if (callers()[1][1..4] != {#-1, "move", #-1, #-1})
2  return E_PERM;
3endif
4pass(@args);
5if (this.self_cleaning)
6  this:deleteitem(args[1]);
7endif

eject eject_basic

Spec this none thisFlags rxdOwner #89987Definer #27777

Referenced by

Source

1set_task_perms($wiz_utils:random_wizard());
2if (caller in {this, this.owner})
3  if (this.self_cleaning)
4    x = args[1];
5    if (x.location == this)
6      this.ejected = setadd(this.ejected, x);
7      fork (this.delay * 5)
8        this.ejected = setremove(this.ejected, x);
9      endfork
10    endif
11  endif
12  return pass(@args);
13else
14  return E_PERM;
15endif

remove_object_msg

Spec this none thisDefiner #27777

Referenced by

none

Source

1return this.(verb);

litterp

Spec this none thisFlags rxDefiner #27777

Referenced by

Source

1item = args[1];
2if (item == this.owner)
3  return 0;
4elseif (is_player(item) && (!(item in this.residents)))
5  "nonresident idling players are litter, even if sessile";
6  return (typeof(idle_seconds(item)) == ERR) && ((time() - item.last_disconnect_time) > 300);
7else
8  "non-resident objects are litter";
9  return !(item in this.residents);
10endif

acceptable

Spec this none thisDefiner #27777

Referenced by

Source

1"Modified 10/19/98 by TheCat to exclude sleeping players who don't belong.";
2what = args[1];
3if ((this.self_cleaning && (ticks_left() < 15000)) && ((what in this.ejected) || this:litterp(what)))
4  "If less than 15000 ticks, we are either a spammy command line task, or, more likely, a suspended or forked task trying to auto-return.  Deny those.";
5  result = 0;
6elseif ((is_player(what) && (!$object_utils:connected(what))) && (!this:basic_accept_for_abode(what)))
7  result = 0;
8else
9  result = pass(@args);
10endif
11return result;

deleteitem

Spec this none thisDefiner #27777

Referenced by

Source

1if (caller != this)
2  return E_PERM;
3endif
4item = args[1];
5if (loc = item in this.trashobjects)
6  this.trashobjects = listdelete(this.trashobjects, loc);
7  this.trashtimes = listdelete(this.trashtimes, loc);
8endif

too_full

Spec this none thisFlags rxdOwner #49853Definer #27777

Referenced by

Source

1max = this.maximum_players;
2cp = connected_players();
3for x in (this.contents)
4  if (x in cp)
5    if ((max = max - 1) < 0)
6      return 1;
7    endif
8  endif
9endfor
10return 0;

most_idle_player

Spec this none thisFlags rxDefiner #27777

Referenced by

Source

1idler = #-1;
2time = 0;
3for x in (this.contents)
4  if (idle_seconds(x) > time)
5    time = idle_seconds(idler = x);
6  endif
7endfor
8return time && {idler, time};

shove_out

Spec this none thisFlags rxdOwner #49853Definer #27777

Referenced by

Source

1"shove_out(who, ..disallowed destinations...)";
2"since this can move people, requires permissions";
3if ((caller != this) && (!caller_perms().wizard))
4  return E_PERM;
5endif
6who = args[1];
7msg = args[2];
8poss_exits = this.exits;
9while (poss_exits)
10  exit = poss_exits[random(length(poss_exits))];
11  poss_exits = setremove(poss_exits, exit);
12  if ((!(exit.dest in args)) && exit.dest:acceptable(who))
13    break;
14  else
15    exit = 0;
16  endif
17endwhile
18if (typeof(exit) != OBJ)
19  return 0;
20endif
21player = who;
22this:shove_through_exit(exit, msg);
23return 1;

check_if_too_full

Spec this none thisFlags rxdOwner #49853Definer #27777

Referenced by

Source

1item = args[1];
2if (is_player(item) && this:too_full())
3  if ((who = this:most_idle_player()) && (who[2] > this.idle_max))
4    this:shove_out(who[1], {"", "It's awfully crowded in here to idle... you decide to go somewhere else less noisy.", ""});
5  elseif (ents = $set_utils:intersection(this.entrances, $list_utils:slice(callers())))
6    if (item.location == this)
7      this:shove_out(item, {"", "It's too crowded in here, and you decide to explore a little.", ""}, @$list_utils:map_property(ents, "source"));
8    endif
9  endif
10endif

shove_through_exit

Spec this none thisFlags rxdOwner #67Definer #27777

Referenced by

Source

1if (caller != this)
2  return E_PERM;
3endif
4fork (0)
5  who = player;
6  if (who.location != this)
7    "don't do it, not here";
8    return;
9  endif
10  exit = args[1];
11  dest = exit.dest;
12  set_task_perms(player);
13  who:tell_lines(args[2]);
14  if (who.location == this)
15    exit:move(who);
16  endif
17  if (who.location == this)
18    "the 'eject' makes sure that they don't auto-return, and they also move";
19    this:eject_basic(who);
20  endif
21endfork
22fork (1)
23  "REALLY get them out of here, dang it!  In case they killed the above task";
24  if (player.location == this)
25    this:eject_basic(player);
26    dobj = player;
27    this:announce_all_but({player}, this:oejection_msg());
28  endif
29endfork

flush_item_now

Spec this none thisDefiner #27777

Referenced by

Source

1"args[1] is an index into this.trashobjects";
2"args[2] is now, so we don't have to recalculate it for every single item.";
3"Returns 1 if item should be flushed now, else 0.";
4index = args[1];
5now = args[2];
6return (now - this.trashtimes[index]) > this.delay;

forget_trash

Spec this none thisDefiner #27777

Referenced by

Source

1"This verb clears the record of litter in this room, and should be called after changing this.self_cleaning from 1 to 0.";
2if ((caller == this) || $perm_utils:controls(caller_perms(), this))
3  this.trashtimes = {};
4  this.trashobjects = {};
5endif

@self-clean

Spec any any noneFlags rxdDefiner #27777

Referenced by

none

Source

1"If no args, toggle state.  Else turn self-cleaning on or off";
2"+x so you can call it on generics to toggle.";
3if ($perm_utils:controls(valid(caller_perms()) ? caller_perms() | player, this))
4  switch = argstr ? argstr | "toggle";
5  if (this.self_cleaning)
6    if ((switch == "toggle") || (switch == "off"))
7      this:set_self_cleaning(0);
8      this:forget_trash();
9      player:tell(this:title() + " is no longer self cleaning.");
10    elseif (switch == "on")
11      player:tell("Self-cleaning is already on.");
12    else
13      player:tell("Try this instead:  @self-clean off");
14    endif
15  else
16    if ((switch == "toggle") || (switch == "on"))
17      this:set_self_cleaning(1);
18      player:tell("Self-cleaning turned on.");
19    elseif (switch == "off")
20      player:tell("Self-cleaning is already on.");
21    else
22      player:tell("Try this instead:  @self-clean on");
23    endif
24  endif
25else
26  player:tell("Permission denied.");
27endif

set_self_cleaning

Spec this none thisDefiner #27777

Referenced by

Source

1if ((caller == this) || $perm_utils:controls(caller_perms(), this))
2  return this.self_cleaning = args[1];
3else
4  return E_PERM;
5endif