39f50db78d00aadf707f3b685d5ce79d5bfcb1d7
[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 {
26         // Konstruktor
27         protected function __construct () {
28                 // Eltern-Kontruktor aufrufen
29                 parent::__construct(__CLASS__);
30
31                 // Set description
32                 $this->setObjectDescription("Passagier-Schiff");
33
34                 // Generate unique ID number
35                 $this->generateUniqueId();
36
37                 // Clean up a little
38                 $this->removeSystemArray();
39         }
40
41         // Passagier-Schiff erstellen
42         public final static function createPassengerShip ($shipName) {
43                 // Get new instance
44                 $passInstance = new PassengerShip();
45
46                 // Set ship name
47                 $passInstance->setShipName($shipName);
48
49                 // Instanz zurueckgeben
50                 return $passInstance;
51         }
52
53         // Anzahl Betten ermitteln
54         public final function calcTotalBeds () {
55                 // Struktur-Array holen
56                 $struct = $this->getStructuresArray();
57
58                 if (is_null($struct)) {
59                         // Empty structures list!
60                         throw new EmptyStructuresListException($this, self::EXCEPTION_EMPTY_STRUCTURES_ARRAY);
61                 } // END - if
62
63                 // Anzahl Betten auf 0 setzen
64                 $numBeds = 0;
65
66                 // Alle Strukturen nach Kabinen durchsuchen
67                 for ($idx = $struct->getIterator(); $idx->valid(); $idx->next()) {
68                         // Element holen
69                         $el = $idx->current();
70
71                         // Ist es eine Kabine?
72                         if ($el->isCabin()) {
73                                 // Anzahl Betten ermitteln
74                                 $total = $el->calcTotalBedsByCabin();
75                                 $numBeds += $total;
76
77                                 // Debug-Meldung ausgeben?
78                                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) {
79                                         // Get new instance
80                                         $cabType = "Kabine ohne Namen";
81                                         $cab = $el->getPartInstance();
82                                         if (!is_null($cab)) {
83                                                 // Kabinenbeschreibung holen
84                                                 $cabType = $cab->getObjectDescription();
85                                         } // END - if
86                                 } // END - if
87                         } // END - if
88                 } // END - for
89
90                 // Anzahl zurueckliefern
91                 return $numBeds;
92         }
93 }
94
95 // [EOF]
96 ?>