3 * A general ship class for all other kinds of ships even small sail ships
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class BaseShip extends BaseSimulator {
26 private $shipName = "Unbekanntes Schiff";
29 private $numAnchor = 0;
35 private $crewList = null;
38 private $structures = null;
40 // Namenloses Ship generieren
41 protected function __construct($className) {
42 // Call parent constructor
43 parent::__construct($className);
45 // Prepare array object for all structures
46 $this->createStructuresArray();
49 $this->removePartInstance();
52 // Array-Objekt anlegen
53 private function createStructuresArray () {
54 $this->structures = new FrameworkArrayObject("FakedShipStructures");
57 // Schiffsteil generieren (kann alles sein)
58 // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
59 // partClass = Das zu konstruierende Schiffsteil
60 public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
61 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> erhält ein neues Schiffsteil (%s).",
68 // Ist die gewuenschte Klasse vorhanden?
69 if (!class_exists($partClass)) {
70 // Nicht vorhanden, dann Ausnahme werfen!
71 throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND);
74 // Get an instance back from our object factory
75 $partInstance = ObjectFactory::createObjectByName($partClass);
77 // Das Einbauen versuchen...
79 $partInstance->addShipPartToShip($this, $buildInstance);
80 } catch (MotorShipMismatchException $e) {
81 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>",
88 } catch (RoomShipMismatchException $e) {
89 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>",
97 } catch (StructureShipMismatchException $e) {
98 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>",
101 $this->getShipName(),
105 } catch (CabinShipMismatchException $e) {
106 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>",
109 $this->getShipName(),
113 } catch (DeckShipMismatchException $e) {
114 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>",
117 $this->getShipName(),
123 // Instanz im Aufbauten-Array vermerken
124 $this->structures->append($partInstance);
130 // Getter-Methode fuer Strukturen-Array
131 public final function getStructuresArray () {
132 return $this->structures;
135 // STUB: Getter-Methode Anzahl Betten
136 public function calcTotalBeds () {
137 $this->partialStub("Please implement this stub in your ship!");
140 // Setter-Methode fuer Schiffsnamen
141 public final function setShipName ($shipName) {
142 $this->shipName = (string) $shipName;
145 // Getter-Methode fuer Schiffsnamen
146 public final function getShipName () {
147 return $this->shipName;
150 // Setter-Methode fuer Tiefgang
151 public final function setDraught ($draught) {
152 $this->draught = (int) $draught;
155 // Getter-Methode fuer Tiefgang
156 public final function getDraught() {
157 return $this->draught;
160 // Setter-Methode fuer Anzahl Anker
161 public final function setNumAnchor ($numAnchor) {
162 $this->numAnchor = (int) $numAnchor;