'final' added to factory methods
[shipsimu.git] / application / ship-simu / main / ships / passenger / class_PassengerShip.php
1 <?php
2 /**
3  * A passenger ship with one or more decks, cabins, bridge (replacement for the
4  * captain) and many more
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
8  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.ship-simu.org
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25 class PassengerShip extends BaseShip implements ConstructableShip, LimitableObject {
26         // Konstruktor
27         private function __construct () {
28                 // Eltern-Kontruktor aufrufen
29                 parent::constructor(__CLASS__);
30
31                 // Debug message
32                 if (((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
33                         $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
34                                 __CLASS__,
35                                 __LINE__
36                         ));
37                 }
38
39                 // Set description
40                 $this->setPartDescr("Passagier-Schiff");
41
42                 // Generate unique ID number
43                 $this->createUniqueID();
44
45                 // Clean up a little
46                 $this->removeSystemArray();
47         }
48
49         // Passagier-Schiff erstellen
50         public final static function createPassengerShip ($shipName) {
51                 // Get new instance
52                 $passInstance = new PassengerShip();
53
54                 // Debug message
55                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) {
56                         $passInstance->getDebugInstance()->output(sprintf("[%s:%d] Ein Passagier-Schiff wird erstellt.<br />\n",
57                                 __CLASS__,
58                                 __LINE__
59                         ));
60                 }
61
62                 // Set ship's name
63                 $passInstance->setShipName($shipName);
64
65                 // Instanz zurueckgeben
66                 return $passInstance;
67         }
68
69         // Anzahl Betten ermitteln
70         final function calcTotalBeds () {
71                 // Struktur-Array holen
72                 $struct = $this->getStructuresArray();
73
74                 if (is_null($struct)) {
75                         // Empty structures list!
76                         throw new EmptyStructuresListException($this, self::EXCEPTION_EMPTY_STRUCTURES_ARRAY);
77                 }
78
79                 // Anzahl Betten auf 0 setzen
80                 $numBeds = 0;
81
82                 // Alle Strukturen nach Kabinen durchsuchen
83                 for ($idx = $struct->getIterator(); $idx->valid(); $idx->next()) {
84                         // Element holen
85                         $el = $idx->current();
86
87                         // Ist es eine Kabine?
88                         if ($el->isCabin()) {
89                                 // Anzahl Betten ermitteln
90                                 $total = $el->calcTotalBedsByCabin();
91                                 $numBeds += $total;
92
93                                 // Debug-Meldung ausgeben?
94                                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) {
95                                         // Get new instance
96                                         $cabType = "Kabine ohne Namen";
97                                         $cab = $el->getPartInstance();
98                                         if (!is_null($cab)) {
99                                                 // Kabinenbeschreibung holen
100                                                 $cabType = $cab->getPartDescr();
101                                         }
102
103                                         // Debug-Meldung ausgeben
104                                         $this->getDebugInstance()->output(sprintf("[%s:%d] Es stehen <strong>%d</strong> Betten vom Kabinen-Typ <strong>%s</strong> bereit.<br />\n",
105                                                 __CLASS__,
106                                                 __LINE__,
107                                                 $total,
108                                                 $cabType
109                                         ));
110                                 }
111                         } else {
112                                 // Keine Kabine!
113                                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%s</strong> ist keine Kabine.<br />\n",
114                                         __CLASS__,
115                                         __LINE__,
116                                         $el->getPartDescr()
117                                 ));
118                         }
119                 }
120
121                 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",
122                         __CLASS__,
123                         __LINE__,
124                         $this->getPartDescr(),
125                         $this->getShipName(),
126                         $numBeds
127                 ));
128
129                 // Anzahl zurueckliefern
130                 return $numBeds;
131         }
132
133         /**
134          * Stub!
135          */
136         public function saveObjectToDatabase () {
137                 $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
138                         $this->__toString(),
139                         __FUNCTION__
140                 ));
141         }
142
143         /**
144          * Limits this object with an ObjectLimits instance
145          */
146         public function limitObject (ObjectLimits $limitInstance) {
147                 ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");
148         }
149 }
150
151 // [EOF]
152 ?>