Initial import of current development status
[shipsimu.git] / ship-simu / application / ship-simu / main / ships / class_BaseShip.php
1 <?php
2 class BaseShip extends BaseSimulator {
3         // Name des Shipes
4         private $shipName   = "Unbekanntes Schiff";
5
6         // Anzahl Anker
7         private $numAnchor  = 0;
8
9         // Tiefgang in Meter
10         private $draught    = 0;
11
12         // Besatzung-Objekte
13         private $crewList   = null;
14
15         // Aufbauten-Objekte
16         private $structures = null;
17
18         // Namenloses Ship generieren
19         private function __construct($class) {
20                 // Eltern-Konstruktor aufrufen
21                 parent::constructor($class);
22
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",
26                                 __CLASS__,
27                                 __LINE__
28                         ));
29
30                 // Bezeichnung setzen
31                 $this->setPartDescr("Schiff");
32
33                 // Array-Objekt generieren
34                 $this->createStructuresArray();
35  
36                 // Instanz entfernen
37                 $this->removePartInstance();
38                 $this->removeNumberFormaters();
39         }
40
41         // Konstruktor aufrufen
42         public function constructor ($class) {
43                 $this->__construct($class);
44         }
45
46         // Array-Objekt anlegen
47         private function createStructuresArray () {
48                 $this->structures = new FrameworkArrayObject();
49         }
50
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&auml;lt ein neues Schiffsteil (%s).<br />\n",
56                         __CLASS__,
57                         __LINE__,
58                         $this->getShipName(),
59                         $partClass
60                 ));
61
62                 // Ist die gewuenschte Klasse vorhanden?
63                 if (class_exists($partClass)) {
64                         // Befehl zusammenbauen
65                         $eval = sprintf("\$partInstance = %s::create%s();",
66                                 $partClass, $partClass
67                         );
68
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",
71                                 __CLASS__,
72                                 __LINE__,
73                                 htmlentities($eval)
74                         ));
75
76                         // ... und ausfuehren
77                         eval($eval);
78                 } else {
79                         // Nicht vorhanden, dann Ausnahme werfen!
80                         throw new ClassNotFoundException($partClass, 0);
81                 }
82
83                 // Das Einbauen versuchen...
84                 try {
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",
88                                 __CLASS__,
89                                 __LINE__,
90                                 $this->getShipName(),
91                                 $e->getMessage()
92                         ));
93                         return false;
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",
96                                 __CLASS__,
97                                 __LINE__,
98                                 $this->getShipName(),
99                                 $e->getMessage()
100                         ));
101                         return false;
102
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",
105                                 __CLASS__,
106                                 __LINE__,
107                                 $this->getShipName(),
108                                 $e->getMessage()
109                         ));
110                         return false;
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",
113                                 __CLASS__,
114                                 __LINE__,
115                                 $this->getShipName(),
116                                 $e->getMessage()
117                         ));
118                         return false;
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",
121                                 __CLASS__,
122                                 __LINE__,
123                                 $this->getShipName(),
124                                 $e->getMessage()
125                         ));
126                         return false;
127                 } catch (ExceptionNotChangedException $e) {
128                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht ge&auml;ndert. Details: <strong>%s</strong><br />\n",
129                                 __CLASS__,
130                                 __LINE__,
131                                 $e->getMessage()
132                         ));
133                         return false;
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",
136                                 __CLASS__,
137                                 __LINE__,
138                                 $e->getMessage()
139                         ));
140                         return false;
141                 }
142
143                 // Instanz im Aufbauten-Array vermerken
144                 $this->structures->append($partInstance);
145
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",
148                         __CLASS__,
149                         __LINE__,
150                         $this->getShipName(),
151                         $partInstance->getPartDescr()
152                 ));
153
154                 // Alles klar!
155                 return true;
156         }
157
158         // Getter-Methode fuer Strukturen-Array
159         public function getStructuresArray () {
160                 return $this->structures;
161         }
162
163         // STUB: Getter-Methode Anzahl Betten
164         public function calcTotalBeds () {
165                 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
166                 return 0;
167         }
168
169         // Setter-Methode fuer Schiffsnamen
170         public function setShipName ($shipName) {
171                 // Cast the string
172                 $shipName = (string) $shipName;
173
174                 // Debug message
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",
176                         __CLASS__,
177                         __LINE__,
178                         $this->__toString(),
179                         $shipName
180                 ));
181
182                 // Set ship name
183                 $this->shipName = $shipName;
184         }
185
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",
189                         __CLASS__,
190                         __LINE__,
191                         $this->__toString(),
192                         $this->shipName
193                 ));
194                 return $this->shipName;
195         }
196
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",
200                         __CLASS__,
201                         __LINE__,
202                         $this->__toString(),
203                         $this->shipName,
204                         $draught
205                 ));
206                 $this->draught = (int) $draught;
207         }
208
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",
212                         __CLASS__,
213                         __LINE__,
214                         $this->shipName
215                 ));
216                 return $this->draught;
217         }
218
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",
222                         __CLASS__,
223                         __LINE__,
224                         $this->__toString(),
225                         $this->shipName,
226                         $numAnchor
227                 ));
228                 $this->numAnchor = (int) $numAnchor;
229         }
230 }
231
232 // [EOF]
233 ?>