2 class BaseShip extends BaseSimulator {
4 private $shipName = "Unbekanntes Schiff";
7 private $numAnchor = 0;
13 private $crewList = null;
16 private $structures = null;
18 // Namenloses Ship generieren
19 private function __construct($class) {
20 // Eltern-Konstruktor aufrufen
21 parent::constructor($class);
23 // Beim Schiff angelangt
24 if (((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT')))
25 $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
31 $this->setPartDescr("Schiff");
33 // Array-Objekt generieren
34 $this->createStructuresArray();
37 $this->removePartInstance();
38 $this->removeNumberFormaters();
41 // Konstruktor aufrufen
42 public function constructor ($class) {
43 $this->__construct($class);
46 // Array-Objekt anlegen
47 private function createStructuresArray () {
48 $this->structures = new FrameworkArrayObject();
51 // Schiffsteil generieren (kann alles sein)
52 // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
53 // partClass = Das zu konstruierende Schiffsteil
54 public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
55 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",
62 // Ist die gewuenschte Klasse vorhanden?
63 if (class_exists($partClass)) {
64 // Befehl zusammenbauen
65 $eval = sprintf("\$partInstance = %s::create%s();",
66 $partClass, $partClass
69 // Debug-Meldung ausgeben
70 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
79 // Nicht vorhanden, dann Ausnahme werfen!
80 throw new ClassNotFoundException($partClass, 0);
83 // Das Einbauen versuchen...
85 $partInstance->addShipPartToShip($this, $buildInstance);
86 } catch (MotorShipMismatchException $e) {
87 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",
94 } catch (RoomShipMismatchException $e) {
95 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",
103 } catch (StructureShipMismatchException $e) {
104 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",
107 $this->getShipName(),
111 } catch (CabinShipMismatchException $e) {
112 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",
115 $this->getShipName(),
119 } catch (DeckShipMismatchException $e) {
120 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",
123 $this->getShipName(),
127 } catch (ExceptionNotChangedException $e) {
128 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",
134 } catch (ExceptionNotFoundException $e) {
135 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
143 // Instanz im Aufbauten-Array vermerken
144 $this->structures->append($partInstance);
146 // Debug-Meldung ausgeben
147 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",
150 $this->getShipName(),
151 $partInstance->getPartDescr()
158 // Getter-Methode fuer Strukturen-Array
159 public function getStructuresArray () {
160 return $this->structures;
163 // STUB: Getter-Methode Anzahl Betten
164 public function calcTotalBeds () {
165 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
169 // Setter-Methode fuer Schiffsnamen
170 public function setShipName ($shipName) {
172 $shipName = (string) $shipName;
175 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",
183 $this->shipName = $shipName;
186 // Getter-Methode fuer Schiffsnamen
187 public function getShipName () {
188 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",
194 return $this->shipName;
197 // Setter-Methode fuer Tiefgang
198 public function setDraught ($draught) {
199 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",
206 $this->draught = (int) $draught;
209 // Getter-Methode fuer Tiefgang
210 public function getDraught() {
211 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
216 return $this->draught;
219 // Setter-Methode fuer Anzahl Anker
220 public function setNumAnchor ($numAnchor) {
221 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",
228 $this->numAnchor = (int) $numAnchor;