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();
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 // Befehl zusammenbauen
75 $eval = sprintf("\$partInstance = %s::create%s();",
76 $partClass, $partClass
79 // Debug-Meldung ausgeben
80 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
89 // Nicht vorhanden, dann Ausnahme werfen!
90 throw new ClassNotFoundException($partClass, 0);
93 // Das Einbauen versuchen...
95 $partInstance->addShipPartToShip($this, $buildInstance);
96 } catch (MotorShipMismatchException $e) {
97 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",
100 $this->getShipName(),
104 } catch (RoomShipMismatchException $e) {
105 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",
108 $this->getShipName(),
113 } catch (StructureShipMismatchException $e) {
114 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",
117 $this->getShipName(),
121 } catch (CabinShipMismatchException $e) {
122 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",
125 $this->getShipName(),
129 } catch (DeckShipMismatchException $e) {
130 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",
133 $this->getShipName(),
137 } catch (ExceptionNotChangedException $e) {
138 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",
144 } catch (ExceptionNotFoundException $e) {
145 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
153 // Instanz im Aufbauten-Array vermerken
154 $this->structures->append($partInstance);
156 // Debug-Meldung ausgeben
157 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",
160 $this->getShipName(),
161 $partInstance->getObjectDescription()
168 // Getter-Methode fuer Strukturen-Array
169 public final function getStructuresArray () {
170 return $this->structures;
173 // STUB: Getter-Methode Anzahl Betten
174 public function calcTotalBeds () {
175 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
179 // Setter-Methode fuer Schiffsnamen
180 public final function setShipName ($shipName) {
182 $shipName = (string) $shipName;
185 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",
193 $this->shipName = $shipName;
196 // Getter-Methode fuer Schiffsnamen
197 public final function getShipName () {
198 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",
204 return $this->shipName;
207 // Setter-Methode fuer Tiefgang
208 public final function setDraught ($draught) {
209 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",
216 $this->draught = (int) $draught;
219 // Getter-Methode fuer Tiefgang
220 public final function getDraught() {
221 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
226 return $this->draught;
229 // Setter-Methode fuer Anzahl Anker
230 public final function setNumAnchor ($numAnchor) {
231 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",
238 $this->numAnchor = (int) $numAnchor;