]> git.mxchange.org Git - shipsimu.git/blobdiff - application/ship-simu/main/class_BaseSimulator.php
Interface for actions added (PerformableAction)
[shipsimu.git] / application / ship-simu / main / class_BaseSimulator.php
index 47576da871c9547005432c62d7646b333be40ea4..c31a8d04db5d6db7a866c6c71daade44f44bc854 100644 (file)
@@ -6,7 +6,7 @@
  * @version            0.0.0
  * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.ship-simu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseSimulator extends BaseFrameworkSystem {
        // Schiffsteilinstanz
@@ -42,16 +42,12 @@ class BaseSimulator extends BaseFrameworkSystem {
        );
 
        // Konstruktor
-       private function __construct ($class) {
+       protected function __construct ($class) {
                // Call highest constructor
-               parent::constructor($class);
-
-               if ((defined('DEBUG_CORE')) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruktor erreicht.<br />\n",
-                       $this->__toString()
-               ));
+               parent::__construct($class);
 
                // Set part description and class name
-               $this->setPartDescr("Simulator-Basis-Einheit");
+               $this->setObjectDescription("Simulator-Basis-Einheit");
 
                // Clean up a little, dies sollte ganz zum Schluss erfolgen!
                $this->removeResizeFactorArray();
@@ -59,28 +55,6 @@ class BaseSimulator extends BaseFrameworkSystem {
                $this->removeCurrShip();
        }
 
-       // Public constructor
-       public function constructor ($class) {
-               // Call real constructor
-               $this->__construct($class);
-       }
-
-       // Magic __isset method
-       private function __isset ($var) {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Checking <strong>%s</strong> in class.<br />\n",
-                       $this->__toString(), $var
-               ));
-               return isset($this->$var);
-       }
-
-       // Magic __unset method
-       private function __unset($var) {
-               if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Removing <strong>%s</strong> from class.<br />\n",
-                       $this->__toString(), $var
-               ));
-               unset($this->$var);
-       }
-
        // Setter-Methode fuer Laenge
        public final function setLength ($length) {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%dm</strong> L&auml;nge gesetzt.<br />\n",
@@ -146,7 +120,7 @@ class BaseSimulator extends BaseFrameworkSystem {
        }
 
        // Remover-Methode fuer die Teil-Instanz
-       public function removePartInstance () {
+       public final function removePartInstance () {
                if ($this->getPartInstance() !== null) {
                        // Warnung ausgeben
                        if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] partInstance ist nicht null! Instanz-Attribut wird nicht entfernt.<br />\n",
@@ -177,7 +151,7 @@ class BaseSimulator extends BaseFrameworkSystem {
 
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Maschinenraum mit Motor <strong>%s</strong> wird fuer das Schiff <strong>%s</strong> konstruiert.<br />\n",
                        $this->__toString(),
-                       $this->currPart->getPartDescr(),
+                       $this->getCurrPart()->getObjectDescription(),
                        $this->currShip->getShipName()
                ));
 
@@ -186,24 +160,24 @@ class BaseSimulator extends BaseFrameworkSystem {
                        // Berechnungen fuer umliegendes Objekt anpassen
                        if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Das Schiffsteil <strong>%s</strong> vom Typ <strong>%s</strong> passt in das Schiff <strong>%s</strong> hinein.<br />\n",
                                $this->__toString(),
-                               $this->currPart->getPartDescr(),
-                               $this->currPart->__toString(),
+                               $this->getCurrPart()->getObjectDescription(),
+                               $this->getCurrPart()->__toString(),
                                $this->currShip->getShipName()
                        ));
 
                        // Muessen die Masse angepasst werden?
                        if ($this->isResizeFactorValid()) {
                                // Neue Angaben berechnen (wir lassen etwas Lust fuer Kabelbaeume, Roehren, Maschinisten, etc.)
-                               $this->newWidth  = (float) $this->currPart->getWidth()  * $this->resizeFactorArray['width'];
-                               $this->newHeight = (float) $this->currPart->getHeight() * $this->resizeFactorArray['height'];
-                               $this->newLength = (float) $this->currPart->getLength() * $this->resizeFactorArray['length'];
+                               $this->newWidth  = (float) $this->getCurrPart()->getWidth()  * $this->resizeFactorArray['width'];
+                               $this->newHeight = (float) $this->getCurrPart()->getHeight() * $this->resizeFactorArray['height'];
+                               $this->newLength = (float) $this->getCurrPart()->getLength() * $this->resizeFactorArray['length'];
 
                                // Passt dies nun immer noch?
                                if ($this->isNewSizeValid()) {
                                        // Das passt auch, dann Werte setzen und Motor-Instanz merken
                                        if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Das Schiffsteil <strong>%s</strong> passt in das Schiff <strong>%s</strong> hinein.<br />\n",
                                                $this->__toString(),
-                                               $this->getPartDescr(),
+                                               $this->getObjectDescription(),
                                                $this->currShip->getShipName()
                                        ));
                                        $this->setWidth($this->newWidth);
@@ -215,41 +189,41 @@ class BaseSimulator extends BaseFrameworkSystem {
                                } else {
                                        // Passt nicht! Also wieder Exception werfen...
                                        throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <strong>%s</strong> vom Typ <strong>%s</strong> ist zu gross f&uuml;r das Schiff!",
-                                               $this->currPart->__toString(),
-                                               $this->currPart->getPartDescr(),
-                                               $this->currPart->__toString()
+                                               $this->getCurrPart()->__toString(),
+                                               $this->getCurrPart()->getObjectDescription(),
+                                               $this->getCurrPart()->__toString()
                                        ), 2);
                                }
                        } elseif ($this->currPart != null) {
                                // Aktuelle Masse setzen
-                               $this->setWidth($this->currPart->getWidth());
-                               $this->setHeight($this->currPart->getHeight());
-                               $this->setLength($this->currPart->getLength());
+                               $this->setWidth($this->getCurrPart()->getWidth());
+                               $this->setHeight($this->getCurrPart()->getHeight());
+                               $this->setLength($this->getCurrPart()->getLength());
                        }
 
                        // Existiert ein Schiffsteil?
                        if (!is_null($this->currPart)) {
                                // Debug-Meldung ausgeben
                                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Schiffsteil <strong>%s</strong> gefunden.<br />\n",
-                                       $this->currPart->realClass,
-                                       $this->currPart->getPartDescr()
+                                       $this->getCurrPart()->realClass,
+                                       $this->getCurrPart()->getObjectDescription()
                                ));
 
                                // Schiffsteil-Instanz setzen
                                $this->setPartInstance($this->currPart);
 
                                // Instanzen entfernen
-                               $this->currPart->removeCurrShip();
-                               $this->currPart->removeCurrPart();
-                               $this->currPart->removePartInstance();
-                               $this->currPart->removeResizeFactorArray();
+                               $this->getCurrPart()->removeCurrShip();
+                               $this->getCurrPart()->removeCurrPart();
+                               $this->getCurrPart()->removePartInstance();
+                               $this->getCurrPart()->removeResizeFactorArray();
                        }
                } else {
                        // Exception werfen!
                        throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <u>%s</u> vom Typ <u>%s</u> passt nicht in das Schiff!",
-                               $this->currPart->realClass,
-                               $this->currPart->getPartDescr(),
-                               $this->currPart->__toString()
+                               $this->getCurrPart()->realClass,
+                               $this->getCurrPart()->getObjectDescription(),
+                               $this->getCurrPart()->__toString()
                        ), 1);
                }
 
@@ -260,7 +234,7 @@ class BaseSimulator extends BaseFrameworkSystem {
        }
 
        // Array fuer Umrechnungstabelle entfernen
-       public function removeResizeFactorArray () {
+       public final function removeResizeFactorArray () {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] removeResizeFactor erreicht.<br />\n",
                        $this->__toString()
                ));
@@ -272,7 +246,7 @@ class BaseSimulator extends BaseFrameworkSystem {
         *
         * @return      void
         */
-       public function removeAllNewAttr () {
+       public final function removeAllNewAttr () {
                unset($this->newWidth);
                unset($this->newHeight);
                unset($this->newLength);
@@ -283,7 +257,7 @@ class BaseSimulator extends BaseFrameworkSystem {
         *
         * @return      void
         */
-       public function removeCurrShip () {
+       public final function removeCurrShip () {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] removeCurrShip erreicht.<br />\n",
                        $this->__toString()
                ));
@@ -291,7 +265,7 @@ class BaseSimulator extends BaseFrameworkSystem {
        }
 
        // Aktuelle Schiffsteil-Instanz entfernen
-       public function removeCurrPart () {
+       public final function removeCurrPart () {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] removeCurrPart erreicht.<br />\n",
                        $this->__toString()
                ));
@@ -299,7 +273,7 @@ class BaseSimulator extends BaseFrameworkSystem {
        }
 
        // Breite entfernen
-       public function removeWidth () {
+       public final function removeWidth () {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Breite entfernt.<br />\n",
                        $this->__toString()
                ));
@@ -307,7 +281,7 @@ class BaseSimulator extends BaseFrameworkSystem {
        }
 
        // Hoehe entfernen
-       public function removeHeight () {
+       public final function removeHeight () {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] H&ouml;he entfernt.<br />\n",
                        $this->__toString()
                ));
@@ -315,7 +289,7 @@ class BaseSimulator extends BaseFrameworkSystem {
        }
 
        // Laenge entfernen
-       public function removeLength () {
+       public final function removeLength () {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] L&auml;nge entfernt.<br />\n",
                        $this->__toString()
                ));
@@ -323,7 +297,7 @@ class BaseSimulator extends BaseFrameworkSystem {
        }
 
        // Tiefgang entfernen
-       public function removeDraught () {
+       public final function removeDraught () {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] Tiefgang entfernt.<br />\n",
                        $this->__toString()
                ));
@@ -363,18 +337,18 @@ class BaseSimulator extends BaseFrameworkSystem {
                return (
                        (
                                ( // Already defined ship messurings
-                                                ($this->currPart->getWidth()  < $this->currShip->getWidth())
-                                       && ($this->currPart->getHeight() < $this->currShip->getDraught())
-                                       && ($this->currPart->getLength() < $this->currShip->getLength())
+                                                ($this->getCurrPart()->getWidth()  < $this->currShip->getWidth())
+                                       && ($this->getCurrPart()->getHeight() < $this->currShip->getDraught())
+                                       && ($this->getCurrPart()->getLength() < $this->currShip->getLength())
                                ) || ( // Ship messurings shall be calculated
                                                 ($this->currShip->getWidth()  == 0)
                                        && ($this->currShip->getHeight() == 0)
                                        && ($this->currShip->getLength() == 0)
                                )
                        // The inserted part must be messured!
-                       ) && ($this->currPart->getWidth()  > 0)
-                               && ($this->currPart->getHeight() > 0)
-                               && ($this->currPart->getLength() > 0)
+                       ) && ($this->getCurrPart()->getWidth()  > 0)
+                               && ($this->getCurrPart()->getHeight() > 0)
+                               && ($this->getCurrPart()->getLength() > 0)
                );
        }
 
@@ -400,7 +374,7 @@ class BaseSimulator extends BaseFrameworkSystem {
        public function extractDimensions ($dim) {
                if (defined('DEBUG_CORE')) $this->getDebugInstance()->output(sprintf("[%s:] extractDimensions erreicht f&uuml;r <strong>%s</strong>.<br />\n",
                        $this->__toString(),
-                       $this->getPartDescr()
+                       $this->getObjectDescription()
                ));
 
                // Abmasse setzen
@@ -414,6 +388,15 @@ class BaseSimulator extends BaseFrameworkSystem {
                        throw new DimNotFoundInArrayException($this, self::EXCEPTION_DIMENSION_ARRAY_INVALID);
                }
        }
+
+       /**
+        * Getter for current part instance
+        *
+        * @return              $currPart       Instance of the current ship part object
+        */
+       public final function getCurrPart () {
+               return $this->currPart;
+       }
 }
 
 // [EOF]