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 private function __construct($class) {
42 // Call parent constructor
43 parent::constructor($class);
45 // Beim Schiff angelangt
46 if (((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT')))
47 $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
53 $this->setPartDescr("Schiff");
55 // Array-Objekt generieren
56 $this->createStructuresArray();
59 $this->removePartInstance();
60 $this->removeNumberFormaters();
64 * Calls the private constructor
66 * @param $class The class' name
69 public function constructor ($class) {
70 $this->__construct($class);
73 // Array-Objekt anlegen
74 private function createStructuresArray () {
75 $this->structures = new FrameworkArrayObject();
78 // Schiffsteil generieren (kann alles sein)
79 // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
80 // partClass = Das zu konstruierende Schiffsteil
81 public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
82 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",
89 // Ist die gewuenschte Klasse vorhanden?
90 if (class_exists($partClass)) {
91 // Befehl zusammenbauen
92 $eval = sprintf("\$partInstance = %s::create%s();",
93 $partClass, $partClass
96 // Debug-Meldung ausgeben
97 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
103 // ... und ausfuehren
106 // Nicht vorhanden, dann Ausnahme werfen!
107 throw new ClassNotFoundException($partClass, 0);
110 // Das Einbauen versuchen...
112 $partInstance->addShipPartToShip($this, $buildInstance);
113 } catch (MotorShipMismatchException $e) {
114 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",
117 $this->getShipName(),
121 } catch (RoomShipMismatchException $e) {
122 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",
125 $this->getShipName(),
130 } catch (StructureShipMismatchException $e) {
131 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",
134 $this->getShipName(),
138 } catch (CabinShipMismatchException $e) {
139 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",
142 $this->getShipName(),
146 } catch (DeckShipMismatchException $e) {
147 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",
150 $this->getShipName(),
154 } catch (ExceptionNotChangedException $e) {
155 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",
161 } catch (ExceptionNotFoundException $e) {
162 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
170 // Instanz im Aufbauten-Array vermerken
171 $this->structures->append($partInstance);
173 // Debug-Meldung ausgeben
174 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",
177 $this->getShipName(),
178 $partInstance->getPartDescr()
185 // Getter-Methode fuer Strukturen-Array
186 public final function getStructuresArray () {
187 return $this->structures;
190 // STUB: Getter-Methode Anzahl Betten
191 public function calcTotalBeds () {
192 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
196 // Setter-Methode fuer Schiffsnamen
197 public final function setShipName ($shipName) {
199 $shipName = (string) $shipName;
202 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",
210 $this->shipName = $shipName;
213 // Getter-Methode fuer Schiffsnamen
214 public final function getShipName () {
215 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",
221 return $this->shipName;
224 // Setter-Methode fuer Tiefgang
225 public final function setDraught ($draught) {
226 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",
233 $this->draught = (int) $draught;
236 // Getter-Methode fuer Tiefgang
237 public final function getDraught() {
238 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
243 return $this->draught;
246 // Setter-Methode fuer Anzahl Anker
247 public final function setNumAnchor ($numAnchor) {
248 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",
255 $this->numAnchor = (int) $numAnchor;