Source for file DpHeap.php
Documentation is available at DpHeap.php
* A heap of credits, stones, etc., represented by one object
* When instances of these objects get the same environment, they will merge.
* DutchPIPE version 0.4; PHP version 5
* LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
* If you did not receive a copy of the DutchPIPE license, you can obtain one at
* http://dutchpipe.org/license/1_0.txt or by sending a note to
* license@dutchpipe.org, in which case you will be mailed a copy immediately.
* @subpackage dpuniverse_std
* @author Lennert Stock <ls@dutchpipe.org>
* @copyright 2006, 2007 Lennert Stock
* @license http://dutchpipe.org/license/1_0.txt DutchPIPE License
* @version Subversion: $Id: DpHeap.php 278 2007-08-19 22:52:25Z ls $
* @link http://dutchpipe.org/manual/package/DutchPIPE
* Builts upon the standard DpObject class
* A heap of credits, stones, etc., represented by one object
* When instances of these objects get the same environment, they will merge.
* Creates the following DutchPIPE properties:<br />
* - int <b>amount</b> - Number of units in heap
* - string <b>isHeap</b> - Set to TRUE
* - string <b>heapTitleSingular</b> - Title for single unit
* - string <b>heapTitlePlural</b> - Title for more units
* - int|float <b>heapWeightModifier</b> - Weight increase per unit
* - int|float <b>heapVolumeModifier</b> - Volume increase per unit
* - int|float <b>heapValueModifier</b> - Value increase per unit
* @subpackage dpuniverse_std
* @author Lennert Stock <ls@dutchpipe.org>
* @copyright 2006, 2007 Lennert Stock
* @license http://dutchpipe.org/license/1_0.txt DutchPIPE License
* @version Release: 0.2.1
* @link http://dutchpipe.org/manual/package/DutchPIPE
* Creates this heap object
* Called by DpObject when this object is created. Adds standard actions
* which can be performed on this object.
* Calls {@link createDpHeap()} in the inheriting class.
* Adds integer or float "amount" property to this object, set to the amount
* Sets this heap object up at the time it is created
* An empty function which can be redefined by the heap object extending on
* Resets this heap object
* Called by DpObject at regular intervals as defined in dpuniverse-ini.php.
* Calls the method 'resetDpHeap' in this heap object. You can redefine
* that function to periodically do stuff such as alter the state of this
* Resets this heap object
* Called by this heap object at regular intervals as defined in
* dpuniverse-ini.php. An empty function which can be redefined by the
* heap object extending on DpDrink. To be used to periodically do stuff
* such as alter the state of the heap object.
* Moves this object into the inventory of another object
* @param mixed &$target_ob path or object to move into to
* @param boolean $simple skip some checks
* @return int TRUE for success, an error code for failure
function moveDpObject(&$target_ob, $simple = FALSE, $heap_amount = FALSE)
if (FALSE !== $heap_amount) {
if ($heap_amount <= 0 || $heap_amount > $this->amount) {
return E_MOVEOBJECT_BADHEAP;
if ($heap_amount == $this->amount) {
$inv = $target_ob->getInventory();
if ($ob !== $this && $ob->location === $this->location) {
if (FALSE === $heap_amount) {
$ob->amount += $this->amount;
$ob->amount += $heap_amount;
$this->amount -= $heap_amount;
if (FALSE === $heap_amount) {
$newheap->amount = $heap_amount;
$newheap_move_result = $newheap->moveDpObject($target_ob, $simple);
if (TRUE !== $newheap_move_result) {
$newheap->removeDpObject();
$this->amount -= $heap_amount;
return $newheap_move_result;
* Checks if the given id is a valid id for this object
* @param string $id name string to check
* @param string $checkWithArticle also check ids with articles
* @return boolean TRUE if the id is valid, FALSE otherwise
function isId($id, $checkWithArticle = TRUE)
&& $matches[1] <= $this->amount;
* Sets the amount of items in the heap
* @param string $amount new number of items in the heap
* @return bool TRUE for success, FALSE for failure
$this->setTitle((1 == $amount ? $this->heapTitleSingular
: sprintf($this->heapTitlePlural, $amount)),
$this->weight = $amount * $this->heapWeightModifier;
$this->volume = $amount * $this->heapVolumeModifier;
$this->value = $amount * $this->heapValueModifier;
$env->tell(array('abstract' =>
. $this->getUniqueId() . '">'
'graphical' => '<changeDpElement id="'
. $this->getUniqueId() . '">'
. '</changeDpElement>'));
|