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 protected function __construct ($className) {
37 // Call parent constructor
38 parent::__construct($className);
41 $this->setObjectDescription("Kabinenstruktur");
45 public function addShipPartToShip (ConstructableShip $shipInstance, ConstructableShipPart $cabinInstance) {
46 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Kabine <strong>%s</strong> wird für das Schiff <strong>%s</strong> konstruiert.",
49 $cabinInstance->getObjectDescription(),
50 $shipInstance->getShipName()
53 // Eltern-Methode aufrufen
54 parent::addShipPartToShip ($shipInstance, $cabinInstance);
56 // Restlichen Daten ebenfalls
57 $this->setNumCabin($cabinInstance->numCabin);
58 $this->setNumRooms($cabinInstance->numRooms);
59 $this->setNumBeds($cabinInstance->numBeds);
61 // Unnoetige Attribute entfernen
62 $cabinInstance->removeNumCabin();
63 $cabinInstance->removeNumRooms();
64 $cabinInstance->removeNumBeds();
67 $this->setDeckInstance($cabinInstance);
69 // Einbaut-Meldung ausgeben
70 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Kabine <strong>%s</strong> wurde in das Schiff eingebaut.",
73 $cabinInstance->getObjectDescription(),
74 $shipInstance->getShipName()
78 // Wrapper fuer setDeckInstance->setPartInstance
79 public final function setDeckInstance ($deck) {
80 parent::setPartInstance($deck);
83 // Getter-Methode fuer Anzahl Betten
84 public final function getNumBeds () {
85 return $this->numBeds;
88 // Getter-Methode fuer Anzahl Kabinen
89 public final function getNumCabin () {
90 return $this->numCabin;
93 // Setter-Methode fuer Anzahl Betten
94 public final function setNumBeds ($numBeds) {
95 $this->numBeds = $numBeds;
98 // Setter-Methode fuer Anzahl Raeume
99 public final function setNumRooms ($numRooms) {
100 $this->numRooms = $numRooms;
103 // Setter-Methode fuer Anzahl Kabinen
104 public final function setNumCabin ($numCabin) {
105 $this->numCabin = $numCabin;
108 // Loesch-Methode fuer Anzahl Betten
109 public final function removeNumBeds() {
110 unset($this->numBeds);
113 // Loesch-Methode fuer Anzahl Kabinen
114 public final function removeNumCabin() {
115 unset($this->numCabin);
118 // Loesch-Methode fuer Anzahl Raeume
119 public final function removeNumRooms() {
120 unset($this->numRooms);
123 // Bettenanzahl pro Kabine berechnen
124 public function calcTotalBedsByCabin () {
125 // Dann Bettenanzahl holen und aufaddieren
126 $beds = $this->getNumBeds();
127 $num = $this->getNumCabin();
128 $cabinBeds = $beds * $num;
129 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) {
131 $cabType = "Kabine ohne Namen";
132 $cab = $this->getPartInstance();
133 if (!is_null($cab)) {
134 // Kabinenbeschreibung holen
135 $cabType = $cab->__toString();
138 // Debug-Meldung ausgeben
139 $this->debugOutput(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.",