Debug mailer finished and debug messages removed:
[shipsimu.git] / application / ship-simu / main / ships / class_BaseShip.php
index 689374045f8117111e9f6ecffa494f00aee6ee45..51f1559d947e4b9ed1f7c300d8b9dee68230187c 100644 (file)
@@ -1,4 +1,26 @@
 <?php
+/**
+ * A general ship class for all other kinds of ships even small sail ships
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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/>.
+ */
 class BaseShip extends BaseSimulator {
        // Name des Shipes
        private $shipName   = "Unbekanntes Schiff";
@@ -16,48 +38,31 @@ class BaseShip extends BaseSimulator {
        private $structures = null;
 
        // Namenloses Ship generieren
-       private function __construct($class) {
+       protected function __construct($className) {
                // Call parent constructor
-               parent::constructor($class);
+               parent::__construct($className);
 
-               // Beim Schiff angelangt
-               if (((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT')))
-                       $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
-                               __CLASS__,
-                               __LINE__
-                       ));
-
-               // Bezeichnung setzen
-               $this->setPartDescr("Schiff");
+               // Set object description
+               $this->setObjectDescription("Allgemeines Schiff");
 
-               // Array-Objekt generieren
+               // Prepare array object for all structures
                $this->createStructuresArray();
 
-               // Instanz entfernen
+               // Clean-up a little
                $this->removePartInstance();
                $this->removeNumberFormaters();
        }
 
-       /**
-        * Calls the private constructor
-        *
-        * @param       $class  The class' name
-        * @return      void
-        */
-       public function constructor ($class) {
-               $this->__construct($class);
-       }
-
        // Array-Objekt anlegen
        private function createStructuresArray () {
-               $this->structures = new FrameworkArrayObject();
+               $this->structures = new FrameworkArrayObject("FakedShipStructures");
        }
 
        // Schiffsteil generieren (kann alles sein)
        // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
        // partClass = Das zu konstruierende Schiffsteil
        public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
-               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> erh&auml;lt ein neues Schiffsteil (%s).<br />\n",
+               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> erh&auml;lt ein neues Schiffsteil (%s).",
                        __CLASS__,
                        __LINE__,
                        $this->getShipName(),
@@ -66,30 +71,18 @@ class BaseShip extends BaseSimulator {
 
                // Ist die gewuenschte Klasse vorhanden?
                if (class_exists($partClass)) {
-                       // Befehl zusammenbauen
-                       $eval = sprintf("\$partInstance = %s::create%s();",
-                               $partClass, $partClass
-                       );
-
-                       // Debug-Meldung ausgeben
-                       if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
-                               __CLASS__,
-                               __LINE__,
-                               htmlentities($eval)
-                       ));
-
-                       // ... und ausfuehren
-                       eval($eval);
+                       // Get an instance back from our object factory
+                       $partInstance = ObjectFactory::createObjectByName($partClass);
                } else {
                        // Nicht vorhanden, dann Ausnahme werfen!
-                       throw new ClassNotFoundException($partClass, 0);
+                       throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND);
                }
 
                // Das Einbauen versuchen...
                try {
                        $partInstance->addShipPartToShip($this, $buildInstance);
                } catch (MotorShipMismatchException $e) {
-                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Motor erhalten! Grund: <strong>%s</strong><br />\n",
+                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Motor erhalten! Grund: <strong>%s</strong>",
                                __CLASS__,
                                __LINE__,
                                $this->getShipName(),
@@ -97,7 +90,7 @@ class BaseShip extends BaseSimulator {
                        ));
                        return false;
                } catch (RoomShipMismatchException $e) {
-                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Maschinenraum erhalten! Grund: <strong>%s</strong><br />\n",
+                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Maschinenraum erhalten! Grund: <strong>%s</strong>",
                                __CLASS__,
                                __LINE__,
                                $this->getShipName(),
@@ -106,7 +99,7 @@ class BaseShip extends BaseSimulator {
                        return false;
 
                } catch (StructureShipMismatchException $e) {
-                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Aufbauten erhalten! Grund: <strong>%s</strong><br />\n",
+                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Aufbauten erhalten! Grund: <strong>%s</strong>",
                                __CLASS__,
                                __LINE__,
                                $this->getShipName(),
@@ -114,7 +107,7 @@ class BaseShip extends BaseSimulator {
                        ));
                        return false;
                } catch (CabinShipMismatchException $e) {
-                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Kabine erhalten! Grund: <strong>%s</strong><br />\n",
+                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Kabine erhalten! Grund: <strong>%s</strong>",
                                __CLASS__,
                                __LINE__,
                                $this->getShipName(),
@@ -122,38 +115,24 @@ class BaseShip extends BaseSimulator {
                        ));
                        return false;
                } catch (DeckShipMismatchException $e) {
-                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat kein Deck erhalten! Grund: <strong>%s</strong><br />\n",
+                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat kein Deck erhalten! Grund: <strong>%s</strong>",
                                __CLASS__,
                                __LINE__,
                                $this->getShipName(),
                                $e->getMessage()
                        ));
                        return false;
-               } catch (ExceptionNotChangedException $e) {
-                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht ge&auml;ndert. Details: <strong>%s</strong><br />\n",
-                               __CLASS__,
-                               __LINE__,
-                               $e->getMessage()
-                       ));
-                       return false;
-               } catch (ExceptionNotFoundException $e) {
-                       if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
-                               __CLASS__,
-                               __LINE__,
-                               $e->getMessage()
-                       ));
-                       return false;
                }
 
                // Instanz im Aufbauten-Array vermerken
                $this->structures->append($partInstance);
 
                // Debug-Meldung ausgeben
-               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat das Schiffsteil <strong>%s</strong> eingebaut bekommen.<br />\n",
+               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat das Schiffsteil <strong>%s</strong> eingebaut bekommen.",
                        __CLASS__,
                        __LINE__,
                        $this->getShipName(),
-                       $partInstance->getPartDescr()
+                       $partInstance->getObjectDescription()
                ));
 
                // Alles klar!
@@ -167,69 +146,31 @@ class BaseShip extends BaseSimulator {
 
        // STUB: Getter-Methode Anzahl Betten
        public function calcTotalBeds () {
-               $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
-               return 0;
+               $this->partialStub("Please implement this stub in your ship!");
        }
 
        // Setter-Methode fuer Schiffsnamen
        public final function setShipName ($shipName) {
-               // Cast the string
-               $shipName = (string) $shipName;
-
-               // Debug message
-               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das neue Schiff vom Typ <strong>%s</strong> wird auf den Namen <strong>%s</strong> getauft.<br />\n",
-                       __CLASS__,
-                       __LINE__,
-                       $this->__toString(),
-                       $shipName
-               ));
-
-               // Set ship name
-               $this->shipName = $shipName;
+               $this->shipName = (string) $shipName;
        }
 
        // Getter-Methode fuer Schiffsnamen
        public final function getShipName () {
-               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das <strong>%s</strong> ist auf den Namen <strong>%s</strong> getauft worden.<br />\n",
-                       __CLASS__,
-                       __LINE__,
-                       $this->__toString(),
-                       $this->shipName
-               ));
                return $this->shipName;
        }
 
        // Setter-Methode fuer Tiefgang
        public final function setDraught ($draught) {
-               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das <strong>%s</strong> mit dem Namen <strong>%s</strong> hat einen Tiefgang von <strong>%sm</strong>.<br />\n",
-                       __CLASS__,
-                       __LINE__,
-                       $this->__toString(),
-                       $this->shipName,
-                       $draught
-               ));
                $this->draught = (int) $draught;
        }
 
        // Getter-Methode fuer Tiefgang
        public final function getDraught() {
-               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
-                       __CLASS__,
-                       __LINE__,
-                       $this->shipName
-               ));
                return $this->draught;
        }
 
        // Setter-Methode fuer Anzahl Anker
        public final function setNumAnchor ($numAnchor) {
-               if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das <strong>%s</strong> mit dem Namen <strong>%s</strong> hat <strong>%s</strong> Anker.<br />\n",
-                       __CLASS__,
-                       __LINE__,
-                       $this->__toString(),
-                       $this->shipName,
-                       $numAnchor
-               ));
                $this->numAnchor = (int) $numAnchor;
        }
 }