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 // 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->setObjectDescription("Schiff");
55 // Array-Objekt generieren
56 $this->createStructuresArray();
59 $this->removePartInstance();
60 $this->removeNumberFormaters();
63 // Array-Objekt anlegen
64 private function createStructuresArray () {
65 $this->structures = new FrameworkArrayObject();
68 // Schiffsteil generieren (kann alles sein)
69 // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
70 // partClass = Das zu konstruierende Schiffsteil
71 public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
72 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",
79 // Ist die gewuenschte Klasse vorhanden?
80 if (class_exists($partClass)) {
81 // Befehl zusammenbauen
82 $eval = sprintf("\$partInstance = %s::create%s();",
83 $partClass, $partClass
86 // Debug-Meldung ausgeben
87 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
96 // Nicht vorhanden, dann Ausnahme werfen!
97 throw new ClassNotFoundException($partClass, 0);
100 // Das Einbauen versuchen...
102 $partInstance->addShipPartToShip($this, $buildInstance);
103 } catch (MotorShipMismatchException $e) {
104 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",
107 $this->getShipName(),
111 } catch (RoomShipMismatchException $e) {
112 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",
115 $this->getShipName(),
120 } catch (StructureShipMismatchException $e) {
121 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",
124 $this->getShipName(),
128 } catch (CabinShipMismatchException $e) {
129 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",
132 $this->getShipName(),
136 } catch (DeckShipMismatchException $e) {
137 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",
140 $this->getShipName(),
144 } catch (ExceptionNotChangedException $e) {
145 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",
151 } catch (ExceptionNotFoundException $e) {
152 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
160 // Instanz im Aufbauten-Array vermerken
161 $this->structures->append($partInstance);
163 // Debug-Meldung ausgeben
164 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",
167 $this->getShipName(),
168 $partInstance->getObjectDescription()
175 // Getter-Methode fuer Strukturen-Array
176 public final function getStructuresArray () {
177 return $this->structures;
180 // STUB: Getter-Methode Anzahl Betten
181 public function calcTotalBeds () {
182 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
186 // Setter-Methode fuer Schiffsnamen
187 public final function setShipName ($shipName) {
189 $shipName = (string) $shipName;
192 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",
200 $this->shipName = $shipName;
203 // Getter-Methode fuer Schiffsnamen
204 public final function getShipName () {
205 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",
211 return $this->shipName;
214 // Setter-Methode fuer Tiefgang
215 public final function setDraught ($draught) {
216 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",
223 $this->draught = (int) $draught;
226 // Getter-Methode fuer Tiefgang
227 public final function getDraught() {
228 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
233 return $this->draught;
236 // Setter-Methode fuer Anzahl Anker
237 public final function setNumAnchor ($numAnchor) {
238 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",
245 $this->numAnchor = (int) $numAnchor;