Your browser must have JavaScript enabled in order to view this page.
 >  >
 
Welcome Guest#215 Login/register    Go to Bottom
Go to Top

Source for file DpHeap.php

Documentation is available at DpHeap.php

  1. <?php
  2. /**
  3.  * A heap of credits, stones, etc., represented by one object
  4.  *
  5.  * When instances of these objects get the same environment, they will merge.
  6.  *
  7.  * DutchPIPE version 0.4; PHP version 5
  8.  *
  9.  * LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
  10.  * If you did not receive a copy of the DutchPIPE license, you can obtain one at
  11.  * http://dutchpipe.org/license/1_0.txt or by sending a note to
  12.  * license@dutchpipe.org, in which case you will be mailed a copy immediately.
  13.  *
  14.  * @package    DutchPIPE
  15.  * @subpackage dpuniverse_std
  16.  * @author     Lennert Stock <ls@dutchpipe.org>
  17.  * @copyright  2006, 2007 Lennert Stock
  18.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  19.  * @version    Subversion: $Id: DpHeap.php 278 2007-08-19 22:52:25Z ls $
  20.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  21.  * @see        DpObject
  22.  */
  23.  
  24. /**
  25.  * Builts upon the standard DpObject class
  26.  */
  27. inherit(DPUNIVERSE_STD_PATH 'DpObject.php');
  28.  
  29. /**
  30.  * A heap of credits, stones, etc., represented by one object
  31.  *
  32.  * When instances of these objects get the same environment, they will merge.
  33.  *
  34.  * Creates the following DutchPIPE properties:<br />
  35.  *
  36.  * - int <b>amount</b> - Number of units in heap
  37.  * - string <b>isHeap</b> - Set to TRUE
  38.  * - string <b>heapTitleSingular</b> - Title for single unit
  39.  * - string <b>heapTitlePlural</b> - Title for more units
  40.  * - int|float <b>heapWeightModifier</b> - Weight increase per unit
  41.  * - int|float <b>heapVolumeModifier</b> - Volume increase per unit
  42.  * - int|float <b>heapValueModifier</b> - Value increase per unit
  43.  *
  44.  * @package    DutchPIPE
  45.  * @subpackage dpuniverse_std
  46.  * @author     Lennert Stock <ls@dutchpipe.org>
  47.  * @copyright  2006, 2007 Lennert Stock
  48.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  49.  * @version    Release: 0.2.1
  50.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  51.  * @see        DpObject
  52.  */
  53. class DpHeap extends DpObject
  54. {
  55.     /**
  56.      * Creates this heap object
  57.      *
  58.      * Called by DpObject when this object is created. Adds standard actions
  59.      * which can be performed on this object.
  60.      *
  61.      * Calls {@link createDpHeap()} in the inheriting class.
  62.      *
  63.      * Adds integer or float "amount" property to this object, set to the amount
  64.      * of items in the heap.
  65.      *
  66.      * @access     private
  67.      * @see        createDpHeap()
  68.      */
  69.     final function createDpObject()
  70.     {
  71.         $this->amount new_dp_property(1);
  72.         $this->isHeap new_dp_property(TRUE);
  73.         $this->heapTitleSingular new_dp_property(dp_text('1 unit'));
  74.         $this->heapTitlePlural new_dp_property(dp_text('%d units'));
  75.         $this->heapWeightModifier new_dp_property(1);
  76.         $this->heapVolumeModifier new_dp_property(1);
  77.         $this->heapValueModifier new_dp_property(0);
  78.  
  79.         $this->coinherit(DPUNIVERSE_STD_PATH 'mass.php');
  80.  
  81.         $this->createDpHeap();
  82.     }
  83.  
  84.     /**
  85.      * Sets this heap object up at the time it is created
  86.      *
  87.      * An empty function which can be redefined by the heap object extending on
  88.      * DpHeap.
  89.      *
  90.      * @see        resetDpHeap()
  91.      */
  92.     function createDpHeap()
  93.     {
  94.     }
  95.  
  96.     /**
  97.      * Resets this heap object
  98.      *
  99.      * Called by DpObject at regular intervals as defined in dpuniverse-ini.php.
  100.      * Calls the method 'resetDpHeap' in this heap object. You can redefine
  101.      * that function to periodically do stuff such as alter the state of this
  102.      * heap object.
  103.      *
  104.      * @access     private
  105.      * @see        resetDpHeap()
  106.      */
  107.     final function resetDpObject()
  108.     {
  109.         $this->resetDpHeap();
  110.     }
  111.  
  112.     /**
  113.      * Resets this heap object
  114.      *
  115.      * Called by this heap object at regular intervals as defined in
  116.      * dpuniverse-ini.php. An empty function which can be redefined by the
  117.      * heap object extending on DpDrink. To be used to periodically do stuff
  118.      * such as alter the state of the heap object.
  119.      *
  120.      * @see        createDpHeap()
  121.      */
  122.     function resetDpHeap()
  123.     {
  124.     }
  125.  
  126.     /**
  127.      * Moves this object into the inventory of another object
  128.      *
  129.      * @param   mixed   &$target_ob path or object to move into to
  130.      * @param   boolean $simple     skip some checks
  131.      * @return  int     TRUE for success, an error code for failure
  132.      */
  133.     function moveDpObject(&$target_ob$simple FALSE$heap_amount FALSE)
  134.     {
  135.         if (FALSE !== $heap_amount{
  136.             if ($heap_amount <= || $heap_amount $this->amount{
  137.                 return E_MOVEOBJECT_BADHEAP;
  138.             }
  139.             if ($heap_amount == $this->amount{
  140.                 $heap_amount FALSE;
  141.             }
  142.         }
  143.  
  144.         $inv $target_ob->getInventory();
  145.         foreach ($inv as &$ob{
  146.             if ($ob !== $this && $ob->location === $this->location{
  147.                 if (FALSE === $heap_amount{
  148.                     $ob->amount += $this->amount;
  149.                     $this->removeDpObject();
  150.                 else {
  151.                     $ob->amount += $heap_amount;
  152.                     $this->amount -= $heap_amount;
  153.                 }
  154.                 return TRUE;
  155.             }
  156.         }
  157.  
  158.         if (FALSE === $heap_amount{
  159.             return DpObject::moveDpObject($target_ob$simple);
  160.         }
  161.  
  162.  
  163.         $newheap get_current_dpuniverse()->newDpObject($this->location);
  164.         $newheap->amount $heap_amount;
  165.         $newheap_move_result $newheap->moveDpObject($target_ob$simple);
  166.  
  167.         if (TRUE !== $newheap_move_result{
  168.             $newheap->removeDpObject();
  169.         else {
  170.             $this->amount -= $heap_amount;
  171.         }
  172.         return $newheap_move_result;
  173.     }
  174.  
  175.     /**
  176.      * Checks if the given id is a valid id for this object
  177.      *
  178.      * @param      string    $id                name string to check
  179.      * @param      string    $checkWithArticle  also check ids with articles
  180.      * @return     boolean   TRUE if the id is valid, FALSE otherwise
  181.      * @see        DpObject::isId()
  182.      */
  183.     function isId($id$checkWithArticle TRUE)
  184.     {
  185.         if (DpObject::isId($id)) {
  186.             return TRUE;
  187.         }
  188.         return dp_strlen($id)
  189.             && ((!DPSERVER_ENABLE_MBSTRING
  190.             && preg_match(dp_text('/^(\d+) (.+)$/')$id$matches))
  191.             || (DPSERVER_ENABLE_MBSTRING
  192.             && mb_ereg(dp_text('^([0-9]+) (.+)$')$id$matches)))
  193.             && DpObject::isId($matches[2]&& $matches[10
  194.             && $matches[1<= $this->amount;
  195.     }
  196.  
  197.     /**
  198.      * Sets the amount of items in the heap
  199.      *
  200.      * @param      string    $amount     new number of items in the heap
  201.      * @return     bool      TRUE for success, FALSE for failure
  202.      */
  203.     protected function setAmount($amount)
  204.     {
  205.         if (== $amount{
  206.             return FALSE;
  207.         }
  208.  
  209.         $this->setDpProperty('amount'$amount);
  210.  
  211.         $this->setTitle((== $amount $this->heapTitleSingular
  212.             : sprintf($this->heapTitlePlural$amount)),
  213.             DPUNIVERSE_TITLE_TYPE_NAME);
  214.  
  215.         $this->weight $amount $this->heapWeightModifier;
  216.         $this->volume $amount $this->heapVolumeModifier;
  217.         $this->value $amount $this->heapValueModifier;
  218.  
  219.         if (FALSE !== ($env $this->getEnvironment())) {
  220.             $env->tell(array('abstract' =>
  221.                 '<changeDpElement id="'
  222.                 . $this->getUniqueId('">'
  223.                 . $this->getAppearance(1FALSE'</changeDpElement>',
  224.                 'graphical' => '<changeDpElement id="'
  225.                 . $this->getUniqueId('">'
  226.                 . $this->getAppearance(1FALSE$this'graphical')
  227.                 . '</changeDpElement>'));
  228.         }
  229.         return TRUE;
  230.     }
  231. }
  232.  
  233. ?>

Documentation generated on Mon, 03 Sep 2007 22:19:22 +0200 by phpDocumentor 1.3.0RC6

Click me!
Guest#215
 
 
 
  Go to Top
 
 
Input Field OptionsClose Input Field Go to Top
 
Legal Notices | Copyright © 2006, 2007 Lennert Stock. All rights reserved. Last update: Mon Sep 03 2007, 21:50 CET.