]> git.mxchange.org Git - shipsimu.git/blobdiff - ship-simu/application/ship-simu/main/ships/class_BaseShip.php
Initial import of current development status
[shipsimu.git] / ship-simu / application / ship-simu / main / ships / class_BaseShip.php
diff --git a/ship-simu/application/ship-simu/main/ships/class_BaseShip.php b/ship-simu/application/ship-simu/main/ships/class_BaseShip.php
new file mode 100644 (file)
index 0000000..65e4da0
--- /dev/null
@@ -0,0 +1,233 @@
+<?php
+class BaseShip extends BaseSimulator {
+       // Name des Shipes
+       private $shipName   = "Unbekanntes Schiff";
+
+       // Anzahl Anker
+       private $numAnchor  = 0;
+
+       // Tiefgang in Meter
+       private $draught    = 0;
+
+       // Besatzung-Objekte
+       private $crewList   = null;
+
+       // Aufbauten-Objekte
+       private $structures = null;
+
+       // Namenloses Ship generieren
+       private function __construct($class) {
+               // Eltern-Konstruktor aufrufen
+               parent::constructor($class);
+
+               // 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");
+
+               // Array-Objekt generieren
+               $this->createStructuresArray();
+               // Instanz entfernen
+               $this->removePartInstance();
+               $this->removeNumberFormaters();
+       }
+
+       // Konstruktor aufrufen
+       public function constructor ($class) {
+               $this->__construct($class);
+       }
+
+       // Array-Objekt anlegen
+       private function createStructuresArray () {
+               $this->structures = new FrameworkArrayObject();
+       }
+
+       // 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",
+                       __CLASS__,
+                       __LINE__,
+                       $this->getShipName(),
+                       $partClass
+               ));
+
+               // 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);
+               } else {
+                       // Nicht vorhanden, dann Ausnahme werfen!
+                       throw new ClassNotFoundException($partClass, 0);
+               }
+
+               // 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",
+                               __CLASS__,
+                               __LINE__,
+                               $this->getShipName(),
+                               $e->getMessage()
+                       ));
+                       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",
+                               __CLASS__,
+                               __LINE__,
+                               $this->getShipName(),
+                               $e->getMessage()
+                       ));
+                       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",
+                               __CLASS__,
+                               __LINE__,
+                               $this->getShipName(),
+                               $e->getMessage()
+                       ));
+                       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",
+                               __CLASS__,
+                               __LINE__,
+                               $this->getShipName(),
+                               $e->getMessage()
+                       ));
+                       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",
+                               __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",
+                       __CLASS__,
+                       __LINE__,
+                       $this->getShipName(),
+                       $partInstance->getPartDescr()
+               ));
+
+               // Alles klar!
+               return true;
+       }
+
+       // Getter-Methode fuer Strukturen-Array
+       public function getStructuresArray () {
+               return $this->structures;
+       }
+
+       // STUB: Getter-Methode Anzahl Betten
+       public function calcTotalBeds () {
+               $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
+               return 0;
+       }
+
+       // Setter-Methode fuer Schiffsnamen
+       public 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;
+       }
+
+       // Getter-Methode fuer Schiffsnamen
+       public 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 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 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 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;
+       }
+}
+
+// [EOF]
+?>