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($class) {
42 // Call parent constructor
43 parent::__construct($class);
45 // Set object description
46 $this->setObjectDescription("Allgemeines Schiff");
48 // Prepare array object for all structures
49 $this->createStructuresArray();
52 $this->removePartInstance();
53 $this->removeNumberFormaters();
56 // Array-Objekt anlegen
57 private function createStructuresArray () {
58 $this->structures = new FrameworkArrayObject("FakedShipStructures");
61 // Schiffsteil generieren (kann alles sein)
62 // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
63 // partClass = Das zu konstruierende Schiffsteil
64 public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
65 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> erhält ein neues Schiffsteil (%s).<br />\n",
72 // Ist die gewuenschte Klasse vorhanden?
73 if (class_exists($partClass)) {
74 // Get an instance back from our object factory
75 $partInstance = ObjectFactory::createObjectByName($partClass);
77 // Nicht vorhanden, dann Ausnahme werfen!
78 throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND);
81 // Das Einbauen versuchen...
83 $partInstance->addShipPartToShip($this, $buildInstance);
84 } catch (MotorShipMismatchException $e) {
85 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",
92 } catch (RoomShipMismatchException $e) {
93 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",
101 } catch (StructureShipMismatchException $e) {
102 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",
105 $this->getShipName(),
109 } catch (CabinShipMismatchException $e) {
110 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",
113 $this->getShipName(),
117 } catch (DeckShipMismatchException $e) {
118 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",
121 $this->getShipName(),
125 } catch (ExceptionNotChangedException $e) {
126 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht geändert. Details: <strong>%s</strong><br />\n",
132 } catch (ExceptionNotFoundException $e) {
133 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
141 // Instanz im Aufbauten-Array vermerken
142 $this->structures->append($partInstance);
144 // Debug-Meldung ausgeben
145 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",
148 $this->getShipName(),
149 $partInstance->getObjectDescription()
156 // Getter-Methode fuer Strukturen-Array
157 public final function getStructuresArray () {
158 return $this->structures;
161 // STUB: Getter-Methode Anzahl Betten
162 public function calcTotalBeds () {
163 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
167 // Setter-Methode fuer Schiffsnamen
168 public final function setShipName ($shipName) {
170 $shipName = (string) $shipName;
173 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",
181 $this->shipName = $shipName;
184 // Getter-Methode fuer Schiffsnamen
185 public final function getShipName () {
186 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",
192 return $this->shipName;
195 // Setter-Methode fuer Tiefgang
196 public final function setDraught ($draught) {
197 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",
204 $this->draught = (int) $draught;
207 // Getter-Methode fuer Tiefgang
208 public final function getDraught() {
209 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
214 return $this->draught;
217 // Setter-Methode fuer Anzahl Anker
218 public final function setNumAnchor ($numAnchor) {
219 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",
226 $this->numAnchor = (int) $numAnchor;