Initial import of current development status
[shipsimu.git] / ship-simu / application / ship-simu / main / ships / passenger / class_PassengerShip.php
1 <?php
2
3 class PassengerShip extends BaseShip implements ConstructableShip {
4         // Konstruktor
5         private function __construct () {
6                 // Eltern-Kontruktor aufrufen
7                 parent::constructor(__CLASS__);
8
9                 // Debug message
10                 if (((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
11                         $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
12                                 __CLASS__,
13                                 __LINE__
14                         ));
15                 }
16
17                 // Beschreibung setzen
18                 $this->setPartDescr("Passagier-Schiff");
19
20                 // Unique-ID erzeugen
21                 $this->createUniqueID();
22
23                 // Clean up a little
24                 $this->removeSystemArray();
25         }
26
27         // Passagier-Schiff erstellen
28         public static function createPassengerShip ($shipName) {
29                 // Instanz holen
30                 $passInstance = new PassengerShip();
31
32                 // Debug message
33                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) {
34                         $passInstance->getDebugInstance()->output(sprintf("[%s:%d] Ein Passagier-Schiff wird erstellt.<br />\n",
35                                 __CLASS__,
36                                 __LINE__
37                         ));
38                 }
39
40                 // Set ship's name
41                 $passInstance->setShipName($shipName);
42
43                 // Instanz zurueckgeben
44                 return $passInstance;
45         }
46
47         // Anzahl Betten ermitteln
48         final function calcTotalBeds () {
49                 // Struktur-Array holen
50                 $struct = $this->getStructuresArray();
51
52                 if (is_null($struct)) {
53                         // Empty structures list!
54                         throw new EmptyStructuresListException($this, self::EXCEPTION_EMPTY_STRUCTURES_ARRAY);
55                 }
56
57                 // Anzahl Betten auf 0 setzen
58                 $numBeds = 0;
59
60                 // Alle Strukturen nach Kabinen durchsuchen
61                 for ($idx = $struct->getIterator(); $idx->valid(); $idx->next()) {
62                         // Element holen
63                         $el = $idx->current();
64
65                         // Ist es eine Kabine?
66                         if ($el->isCabin()) {
67                                 // Anzahl Betten ermitteln
68                                 $total = $el->calcTotalBedsByCabin();
69                                 $numBeds += $total;
70
71                                 // Debug-Meldung ausgeben?
72                                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) {
73                                         // Instanz holen
74                                         $cabType = "Kabine ohne Namen";
75                                         $cab = $el->getPartInstance();
76                                         if (!is_null($cab)) {
77                                                 // Kabinenbeschreibung holen
78                                                 $cabType = $cab->getPartDescr();
79                                         }
80
81                                         // Debug-Meldung ausgeben
82                                         $this->getDebugInstance()->output(sprintf("[%s:%d] Es stehen <strong>%d</strong> Betten vom Kabinen-Typ <strong>%s</strong> bereit.<br />\n",
83                                                 __CLASS__,
84                                                 __LINE__,
85                                                 $total,
86                                                 $cabType
87                                         ));
88                                 }
89                         } else {
90                                 // Keine Kabine!
91                                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%s</strong> ist keine Kabine.<br />\n",
92                                         __CLASS__,
93                                         __LINE__,
94                                         $el->getPartDescr()
95                                 ));
96                         }
97                 }
98
99                 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>%d</strong> Betten.<br />\n",
100                         __CLASS__,
101                         __LINE__,
102                         $this->getPartDescr(),
103                         $this->getShipName(),
104                         $numBeds
105                 ));
106         
107                 // Anzahl zurueckliefern
108                 return $numBeds;
109         }
110
111         /**
112          * Stub!
113          */
114         public function saveObjectToDatabase () {
115                 $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
116                         $this->__toString(),
117                         __FUNCTION__
118                 ));
119         }
120
121         /**
122          * Limits this object with an ObjectLimits instance
123          */
124         public function limitObject (ObjectLimits $limitInstance) {
125                 ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");
126         }
127 }
128
129 // [EOF]
130 ?>