Difference between revisions of "Powerplants (Programming)"

From Hellmoo Wiki Archive
Jump to navigation Jump to search
imported>Spunky
imported>Spunky
m
 
Line 102: Line 102:
*.ounplug_msg -- What others see when you unplug the thing
*.ounplug_msg -- What others see when you unplug the thing


[[Category:Needs work]] [[Category:Programming]]
[[Category:Programming]]

Latest revision as of 06:13, 4 January 2009

Overview

Powerplants are objects that generate power for an area. There might be lots of things in an area that use power, from television sets to battery chargers. When the powerplant is online all of this is possible, but when it goes offline all of those things lose power and cease to operate.

Powerplants are descended from the generic power plant (#1655). The powerplant does two things, codewise. First, it provides a mechanism for switching lots of devices on and off all at the same time. This can be a dramatic effect in the game, since things the players need to complete their adventures might depend on powered objects. Second, it sends current to devices plugged into it every so often, which can be used to charge things.

To find out what powerplant your area is using, you can look at it's .powerplant property:

 powerplant = this:area().powerplant;

When things are 'plugged in' to the powerplant it just means that they are registered with it, in the sense that it knows it's providing power to that object (via its .plugged_in property). Programatically you can connect things up to the powerplant via the powerplant's :_plug() verb. It's very simple, just pass it the object you want to plug in to it:

 powerplant:_plug(thing)

If you're using the generic powered thing (#2521), there is a command-line wrapper verb that does this for you:

 #2521:plug   this (in/inside/into) none
  1:  if (!is_a(this.location, #489))
  2:    player:tell("You don't see any place to plug ", this:dname(), " in.");
  3:    return;
  4:  elseif (!is_a(pp = this:area().powerplant, $powerplant))
  5:    player:tell("There don't seem to be any working outlets here.");
  6:    return;
  7:  elseif (is_a(this.powered_by, $powerplant))
  8:    player:tell(this:dnamec(), " is already plugged in.");
  9:    return;
 10:  endif
 11:  pp:_plug(this);
 12:  this.powered_by = pp;
 13:  this.location:announce($su:ps(this.oplugin_msg));
 14:  player:tell($su:ps(this.plugin_msg));

First we check to make sure we're indoors, then we find the powerplant for out area, make a quick check to see if we're already plugged in, and then call the powerplant's :_plug() verb. There is a corresponding verb called :_unplug() which does the opposite.

When you have some things plugged into a powerplant, all sorts of fun things can happen. Most importantly, if the powerplant gets blown up by terrorists or something, all of the powered devices hooked up to it turn themselves off. This is done via those objects' :_lose_power() verbs, if they exist. For instance, going back to the generic powered thing:

 #2521:_lose_power   this none this
  1:  if (this.lose_power_msg)
  2:    this.location:announce_all($su:ps(this.lose_power_msg));
  3:  endif
  4:  this:turn_off();

Similarly, when the powerplant is turned on, it will call the :_gain_power() verb on all of the objects that are plugged into it, presuming they have that verb. It does exactly what you would expect.

Here's a quick rundown of the imporant verbs and properties on $powerplant:

Verbs on $powerplant

  • _plug(OBJ thing) -- Connect 'thing' to the powerplant
  • _unplug(OBJ thing) -- Disconnect 'thing' from the powerplant
  • heartbeat() -- You should never have to call this, but should know that it calls :_charge on all the objects that are connected to it when it runs
  • _turn_on() -- Turns the powerplant on, calling :_gain_power() on all objects connected to it
  • _turn_off -- Turns off the powerplant, calling :_lose_power() on all objects connected to it

Properties on $powerplant

  • .plugged_in -- List of objects that are connected to the powerplant
  • .on -- boolean for determing the state of the powerplant

Verbs on generic powered thing (#2521)

  • turn_on() -- turns on the appliance
  • turn_off() -- turns off the appliance
  • _lose_power() -- causes the appliance to lose power (usually turning it off)
  • _gain_power() -- restores power to the appliance
  • plug this in -- command-line verb for connecting the appliance to a wall socket or other power source
  • unplug this -- command-line verb for unplugging the appliance


Properties on generic powered thing (#2521)

  • .on -- for determining whether the thing is turned on
  • .turn_on_msg -- What you see when you turn the thing on
  • .turn_off_msg -- What you see when you turn this thing off
  • .gain_power_msg -- What you see when the thing starts to get power
  • .lose_power_msg* -- What you see when the thing loses power
  • .plugin_msg -- What you see then you plug the thing in
  • .oplugin_msg -- What others see when you plug the thing in
  • .no_power_msg -- What you see when you try to turn the thing on and it has no power
  • .powered_by -- What the thing's source of power is (#-1 if nothing)
  • .unplug_msg -- What you see when you unplug the thing
  • .ounplug_msg -- What others see when you unplug the thing