70fa5ed56b79e7e333d934a8e81f19d2e8bb2c51
[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@shipsimu.org>
7  * @version             0.0.0
8  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.shipsimu.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
32         // Passagier-Schiff erstellen
33         public static final function createPassengerShip ($shipName) {
34                 // Get new instance
35                 $passInstance = new PassengerShip();
36
37                 // Set ship name
38                 $passInstance->setShipName($shipName);
39
40                 // Instanz zurueckgeben
41                 return $passInstance;
42         }
43
44         // Anzahl Betten ermitteln
45         public final function calcTotalBeds () {
46                 // Struktur-Array holen
47                 $struct = $this->getStructuresArray();
48
49                 if (is_null($struct)) {
50                         // Empty structures list!
51                         throw new EmptyStructuresListException($this, self::EXCEPTION_EMPTY_STRUCTURES_ARRAY);
52                 } // END - if
53
54                 // Anzahl Betten auf 0 setzen
55                 $numBeds = 0;
56
57                 // Alle Strukturen nach Kabinen durchsuchen
58                 for ($idx = $struct->getIterator(); $idx->valid(); $idx->next()) {
59                         // Element holen
60                         $el = $idx->current();
61
62                         // Ist es eine Kabine?
63                         if ($el->isCabin()) {
64                                 // Anzahl Betten ermitteln
65                                 $total = $el->calcTotalBedsByCabin();
66                                 $numBeds += $total;
67
68                                 // Debug-Meldung ausgeben?
69                                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) {
70                                         // Get new instance
71                                         $cabType = "Kabine ohne Namen";
72                                         $cab = $el->getPartInstance();
73                                         if (!is_null($cab)) {
74                                                 // Kabinenbeschreibung holen
75                                                 $cabType = $cab->getObjectDescription();
76                                         } // END - if
77                                 } // END - if
78                         } // END - if
79                 } // END - for
80
81                 // Anzahl zurueckliefern
82                 return $numBeds;
83         }
84 }
85
86 // [EOF]
87 ?>