3 * General cabin structure class
5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
24 class BaseCabinStructure extends BaseStructure {
25 // --- Besondere Eigenschaften dazufuegen: ---
26 // Anzahl der Kabinen im Schiff
27 private $numCabin = 0;
29 // Anzahl Raeume pro Kabine (kann auch nur 1 sein)
30 private $numRooms = 0;
32 // Anzahl Betten, verallgemeinert
36 private function __construct ($class) {
37 // Call parent constructor
38 parent::constructor($class);
41 if (((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
42 $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
49 $this->setPartDescr("Kabinenstruktur");
53 * Calls the private constructor
55 * @param $class The class' name
58 public function constructor ($class) {
59 $this->__construct($class);
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ür das Schiff <strong>%s</strong> konstruiert.<br />\n",
67 $cabinInstance->getPartDescr(),
68 $shipInstance->getShipName()
71 // Eltern-Methode aufrufen
72 parent::addShipPartToShip ($shipInstance, $cabinInstance);
74 // Restlichen Daten ebenfalls
75 $this->setNumCabin($cabinInstance->numCabin);
76 $this->setNumRooms($cabinInstance->numRooms);
77 $this->setNumBeds($cabinInstance->numBeds);
79 // Unnoetige Attribute entfernen
80 $cabinInstance->removeNumCabin();
81 $cabinInstance->removeNumRooms();
82 $cabinInstance->removeNumBeds();
85 $this->setDeckInstance($cabinInstance);
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",
91 $cabinInstance->getPartDescr(),
92 $shipInstance->getShipName()
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",
102 parent::setPartInstance($deck);
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",
112 return $this->numBeds;
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",
122 return $this->numCabin;
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",
132 $this->numBeds = $numBeds;
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äume gesetzt.<br />\n",
142 $this->numRooms = $numRooms;
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",
152 $this->numCabin = $numCabin;
155 // Loesch-Methode fuer Anzahl Betten
156 public function removeNumBeds() {
157 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl Betten gelöscht.<br />\n",
161 unset($this->numBeds);
164 // Loesch-Methode fuer Anzahl Kabinen
165 public function removeNumCabin() {
166 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl Kabinen gelöscht.<br />\n",
170 unset($this->numCabin);
173 // Loesch-Methode fuer Anzahl Raeume
174 public function removeNumRooms() {
175 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl Räume gelöscht.<br />\n",
179 unset($this->numRooms);
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'))) {
190 $cabType = "Kabine ohne Namen";
191 $cab = $this->getPartInstance();
192 if (!is_null($cab)) {
193 // Kabinenbeschreibung holen
194 $cabType = $cab->__toString();
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",