X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=application%2Fshipsimu%2Fmain%2Fships%2Fclass_BaseShip.php;fp=application%2Fshipsimu%2Fmain%2Fships%2Fclass_BaseShip.php;h=ae22ca3649c986a4788fc99cf7488ed7455c4e97;hp=0000000000000000000000000000000000000000;hb=02a6b02f96d2193d2161e70477bf8f18a199389f;hpb=4f70843ae8428f051d70ccff5bb43fc4c03dda8d diff --git a/application/shipsimu/main/ships/class_BaseShip.php b/application/shipsimu/main/ships/class_BaseShip.php new file mode 100644 index 0000000..ae22ca3 --- /dev/null +++ b/application/shipsimu/main/ships/class_BaseShip.php @@ -0,0 +1,167 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 . + */ +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 + protected function __construct($className) { + // Call parent constructor + parent::__construct($className); + + // Prepare array object for all structures + $this->createStructuresArray(); + + // Clean-up a little + $this->removePartInstance(); + } + + // Array-Objekt anlegen + private function createStructuresArray () { + $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->debugOutput(sprintf("[%s:%d] Das Schiff %s erhält ein neues Schiffsteil (%s).", + __CLASS__, + __LINE__, + $this->getShipName(), + $partClass + )); + + // Ist die gewuenschte Klasse vorhanden? + if (!class_exists($partClass)) { + // Nicht vorhanden, dann Ausnahme werfen! + throw new NoClassException($partClass, self::EXCEPTION_CLASS_NOT_FOUND); + } // END - if + + // Get an instance back from our object factory + $partInstance = ObjectFactory::createObjectByName($partClass); + + // Das Einbauen versuchen... + try { + $partInstance->addShipPartToShip($this, $buildInstance); + } catch (MotorShipMismatchException $e) { + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keinen Motor erhalten! Grund: %s", + __CLASS__, + __LINE__, + $this->getShipName(), + $e->getMessage() + )); + return false; + } catch (RoomShipMismatchException $e) { + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keinen Maschinenraum erhalten! Grund: %s", + __CLASS__, + __LINE__, + $this->getShipName(), + $e->getMessage() + )); + return false; + + } catch (StructureShipMismatchException $e) { + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keine Aufbauten erhalten! Grund: %s", + __CLASS__, + __LINE__, + $this->getShipName(), + $e->getMessage() + )); + return false; + } catch (CabinShipMismatchException $e) { + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keine Kabine erhalten! Grund: %s", + __CLASS__, + __LINE__, + $this->getShipName(), + $e->getMessage() + )); + return false; + } catch (DeckShipMismatchException $e) { + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat kein Deck erhalten! Grund: %s", + __CLASS__, + __LINE__, + $this->getShipName(), + $e->getMessage() + )); + return false; + } + + // Instanz im Aufbauten-Array vermerken + $this->structures->append($partInstance); + + // Alles klar! + return true; + } + + // Getter-Methode fuer Strukturen-Array + public final function getStructuresArray () { + return $this->structures; + } + + // STUB: Getter-Methode Anzahl Betten + public function calcTotalBeds () { + $this->partialStub("Please implement this stub in your ship!"); + } + + // Setter-Methode fuer Schiffsnamen + public final function setShipName ($shipName) { + $this->shipName = (string) $shipName; + } + + // Getter-Methode fuer Schiffsnamen + public final function getShipName () { + return $this->shipName; + } + + // Setter-Methode fuer Tiefgang + public final function setDraught ($draught) { + $this->draught = (int) $draught; + } + + // Getter-Methode fuer Tiefgang + public final function getDraught() { + return $this->draught; + } + + // Setter-Methode fuer Anzahl Anker + public final function setNumAnchor ($numAnchor) { + $this->numAnchor = (int) $numAnchor; + } +} + +// [EOF] +?>