final added, code clean-ups
[shipsimu.git] / application / ship-simu / main / structures / extended / class_BaseCabinStructure.php
1 <?php
2 /**
3  * General cabin structure class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class BaseCabinStructure extends BaseStructure {
25         // --- Besondere Eigenschaften dazufuegen: ---
26         // Anzahl der Kabinen im Schiff
27         private $numCabin = 0;
28
29         // Anzahl Raeume pro Kabine (kann auch nur 1 sein)
30         private $numRooms = 0;
31
32         // Anzahl Betten, verallgemeinert
33         private $numBeds = 0;
34
35         // Konstruktor
36         private function __construct ($class) {
37                 // Call parent constructor
38                 parent::constructor($class);
39
40                 // Debug message
41                 if (((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
42                         $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
43                                 __CLASS__,
44                                 __LINE__
45                         ));
46                 }
47
48                 // Set description
49                 $this->setPartDescr("Kabinenstruktur");
50         }
51
52         /**
53          * Calls the private constructor
54          *
55          * @param       $class  The class' name
56          * @return      void
57          */
58         public function constructor ($class) {
59                 $this->__construct($class);
60         }
61
62         // Kabine hinzufuegen
63         public function addShipPartToShip (ConstructableShip $shipInstance, ConstructableShipPart $cabinInstance) {
64                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Kabine <strong>%s</strong> wird f&uuml;r das Schiff <strong>%s</strong> konstruiert.<br />\n",
65                         __CLASS__,
66                         __LINE__,
67                         $cabinInstance->getPartDescr(),
68                         $shipInstance->getShipName()
69                 ));
70
71                 // Eltern-Methode aufrufen
72                 parent::addShipPartToShip ($shipInstance, $cabinInstance);
73
74                 // Restlichen Daten ebenfalls
75                 $this->setNumCabin($cabinInstance->numCabin);
76                 $this->setNumRooms($cabinInstance->numRooms);
77                 $this->setNumBeds($cabinInstance->numBeds);
78
79                 // Unnoetige Attribute entfernen
80                 $cabinInstance->removeNumCabin();
81                 $cabinInstance->removeNumRooms();
82                 $cabinInstance->removeNumBeds();
83
84                 // Instanz setzen
85                 $this->setDeckInstance($cabinInstance);
86
87                 // Einbaut-Meldung ausgeben
88                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Kabine <strong>%s</strong> wurde in das Schiff eingebaut.<br />\n",
89                         __CLASS__,
90                         __LINE__,
91                         $cabinInstance->getPartDescr(),
92                         $shipInstance->getShipName()
93                 ));
94         }
95
96         // Wrapper fuer setDeckInstance->setPartInstance
97         public final function setDeckInstance ($deck) {
98                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Wrapper setDeckInstance->setPartInstance erreicht.<br />\n",
99                         __CLASS__,
100                         __LINE__
101                 ));
102                 parent::setPartInstance($deck);
103         }
104
105         // Getter-Methode fuer Anzahl Betten
106         public final function getNumBeds () {
107                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Betten angefordert.<br />\n",
108                         __CLASS__,
109                         __LINE__,
110                         $this->numBeds
111                 ));
112                 return $this->numBeds;
113         }
114
115         // Getter-Methode fuer Anzahl Kabinen
116         public final function getNumCabin () {
117                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Kabine(n) angefordert.<br />\n",
118                         __CLASS__,
119                         __LINE__,
120                         $this->numCabin
121                 ));
122                 return $this->numCabin;
123         }
124
125         // Setter-Methode fuer Anzahl Betten
126         public final function setNumBeds ($numBeds) {
127                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Betten gesetzt.<br />\n",
128                         __CLASS__,
129                         __LINE__,
130                         $numBeds
131                 ));
132                 $this->numBeds = $numBeds;
133         }
134
135         // Setter-Methode fuer Anzahl Raeume
136         public final function setNumRooms ($numRooms) {
137                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Raum/R&auml;ume gesetzt.<br />\n",
138                         __CLASS__,
139                         __LINE__,
140                         $numRooms
141                 ));
142                 $this->numRooms = $numRooms;
143         }
144
145         // Setter-Methode fuer Anzahl Kabinen
146         public final function setNumCabin ($numCabin) {
147                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Kabine(n) gesetzt.<br />\n",
148                         __CLASS__,
149                         __LINE__,
150                         $numCabin
151                 ));
152                 $this->numCabin = $numCabin;
153         }
154
155         // Loesch-Methode fuer Anzahl Betten
156         public final function removeNumBeds() {
157                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl Betten gel&ouml;scht.<br />\n",
158                         __CLASS__,
159                         __LINE__
160                 ));
161                 unset($this->numBeds);
162         }
163
164         // Loesch-Methode fuer Anzahl Kabinen
165         public final function removeNumCabin() {
166                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl Kabinen gel&ouml;scht.<br />\n",
167                         __CLASS__,
168                         __LINE__
169                 ));
170                 unset($this->numCabin);
171         }
172
173         // Loesch-Methode fuer Anzahl Raeume
174         public final function removeNumRooms() {
175                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl R&auml;ume gel&ouml;scht.<br />\n",
176                         __CLASS__,
177                         __LINE__
178                 ));
179                 unset($this->numRooms);
180         }
181
182         // Bettenanzahl pro Kabine berechnen
183         public function calcTotalBedsByCabin () {
184                 // Dann Bettenanzahl holen und aufaddieren
185                 $beds = $this->getNumBeds();
186                 $num  = $this->getNumCabin();
187                 $cabinBeds = $beds * $num;
188                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) {
189                         // Get new instance
190                         $cabType = "Kabine ohne Namen";
191                         $cab = $this->getPartInstance();
192                         if (!is_null($cab)) {
193                                 // Kabinenbeschreibung holen
194                                 $cabType = $cab->__toString();
195                         }
196
197                         // Debug-Meldung ausgeben
198                         $this->getDebugInstance()->output(sprintf("[%s:%d] Es exisitieren <strong>%d</strong> Kabinen vom Typ <strong>%s</strong> zu je <strong>%d</strong> Betten. Das sind <strong>%d</strong> Betten.<br />\n",
199                                 __CLASS__,
200                                 __LINE__,
201                                 $num,
202                                 $cabType,
203                                 $beds,
204                                 $cabinBeds
205                         ));
206                 }
207                 return $cabinBeds;
208         }
209 }
210
211 // [EOF]
212 ?>