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 // Call parent constructor
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();
42 * Calls the private constructor
44 * @param $class The class' name
47 public function constructor ($class) {
48 $this->__construct($class);
51 // Array-Objekt anlegen
52 private function createStructuresArray () {
53 $this->structures = new FrameworkArrayObject();
56 // Schiffsteil generieren (kann alles sein)
57 // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
58 // partClass = Das zu konstruierende Schiffsteil
59 public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
60 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",
67 // Ist die gewuenschte Klasse vorhanden?
68 if (class_exists($partClass)) {
69 // Befehl zusammenbauen
70 $eval = sprintf("\$partInstance = %s::create%s();",
71 $partClass, $partClass
74 // Debug-Meldung ausgeben
75 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
84 // Nicht vorhanden, dann Ausnahme werfen!
85 throw new ClassNotFoundException($partClass, 0);
88 // Das Einbauen versuchen...
90 $partInstance->addShipPartToShip($this, $buildInstance);
91 } catch (MotorShipMismatchException $e) {
92 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",
99 } catch (RoomShipMismatchException $e) {
100 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 $this->getShipName(),
108 } catch (StructureShipMismatchException $e) {
109 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",
112 $this->getShipName(),
116 } catch (CabinShipMismatchException $e) {
117 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",
120 $this->getShipName(),
124 } catch (DeckShipMismatchException $e) {
125 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",
128 $this->getShipName(),
132 } catch (ExceptionNotChangedException $e) {
133 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",
139 } catch (ExceptionNotFoundException $e) {
140 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
148 // Instanz im Aufbauten-Array vermerken
149 $this->structures->append($partInstance);
151 // Debug-Meldung ausgeben
152 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",
155 $this->getShipName(),
156 $partInstance->getPartDescr()
163 // Getter-Methode fuer Strukturen-Array
164 public final function getStructuresArray () {
165 return $this->structures;
168 // STUB: Getter-Methode Anzahl Betten
169 public function calcTotalBeds () {
170 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
174 // Setter-Methode fuer Schiffsnamen
175 public final function setShipName ($shipName) {
177 $shipName = (string) $shipName;
180 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",
188 $this->shipName = $shipName;
191 // Getter-Methode fuer Schiffsnamen
192 public final function getShipName () {
193 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",
199 return $this->shipName;
202 // Setter-Methode fuer Tiefgang
203 public final function setDraught ($draught) {
204 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",
211 $this->draught = (int) $draught;
214 // Getter-Methode fuer Tiefgang
215 public final function getDraught() {
216 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
221 return $this->draught;
224 // Setter-Methode fuer Anzahl Anker
225 public final function setNumAnchor ($numAnchor) {
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 <strong>%s</strong> Anker.<br />\n",
233 $this->numAnchor = (int) $numAnchor;