(no commit message)
[shipsimu.git] / application / ship-simu / main / structures / extended / class_BaseCabinStructure.php
1 <?php
2 // Kabinen allgemein
3 class BaseCabinStructure extends BaseStructure {
4         // --- Besondere Eigenschaften dazufuegen: ---
5         // Anzahl der Kabinen im Schiff
6         private $numCabin = 0;
7
8         // Anzahl Raeume pro Kabine (kann auch nur 1 sein)
9         private $numRooms = 0;
10
11         // Anzahl Betten, verallgemeinert
12         private $numBeds = 0;
13
14         // Konstruktor
15         private function __construct ($class) {
16                 // Eltern-Konstruktor aufrufen
17                 parent::constructor($class);
18
19                 // Debug message
20                 if (((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
21                         $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
22                                 __CLASS__,
23                                 __LINE__
24                         ));
25                 }
26
27                 // Beschreibung setzen
28                 $this->setPartDescr("Kabinenstruktur");
29         }
30
31         // Konstruktor aufrufen
32         public function constructor ($class) {
33                 $this->__construct($class);
34         }
35
36         // Kabine hinzufuegen
37         public function addShipPartToShip (ConstructableShip $shipInstance, ConstructableShipPart $cabinInstance) {
38                 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",
39                         __CLASS__,
40                         __LINE__,
41                         $cabinInstance->getPartDescr(),
42                         $shipInstance->getShipName()
43                 ));
44
45                 // Eltern-Methode aufrufen
46                 parent::addShipPartToShip ($shipInstance, $cabinInstance);
47
48                 // Restlichen Daten ebenfalls
49                 $this->setNumCabin($cabinInstance->numCabin);
50                 $this->setNumRooms($cabinInstance->numRooms);
51                 $this->setNumBeds($cabinInstance->numBeds);
52
53                 // Unnoetige Attribute entfernen
54                 $cabinInstance->removeNumCabin();
55                 $cabinInstance->removeNumRooms();
56                 $cabinInstance->removeNumBeds();
57
58                 // Instanz setzen
59                 $this->setDeckInstance($cabinInstance);
60
61                 // Einbaut-Meldung ausgeben
62                 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",
63                         __CLASS__,
64                         __LINE__,
65                         $cabinInstance->getPartDescr(),
66                         $shipInstance->getShipName()
67                 ));
68         }
69
70         // Wrapper fuer setDeckInstance->setPartInstance
71         public function setDeckInstance ($deck) {
72                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Wrapper setDeckInstance->setPartInstance erreicht.<br />\n",
73                         __CLASS__,
74                         __LINE__
75                 ));
76                 parent::setPartInstance($deck);
77         }
78
79         // Getter-Methode fuer Anzahl Betten
80         public function getNumBeds () {
81                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Betten angefordert.<br />\n",
82                         __CLASS__,
83                         __LINE__,
84                         $this->numBeds
85                 ));
86                 return $this->numBeds;
87         }
88
89         // Getter-Methode fuer Anzahl Kabinen
90         public function getNumCabin () {
91                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Kabine(n) angefordert.<br />\n",
92                         __CLASS__,
93                         __LINE__,
94                         $this->numCabin
95                 ));
96                 return $this->numCabin;
97         }
98
99         // Setter-Methode fuer Anzahl Betten
100         public function setNumBeds ($numBeds) {
101                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Betten gesetzt.<br />\n",
102                         __CLASS__,
103                         __LINE__,
104                         $numBeds
105                 ));
106                 $this->numBeds = $numBeds;
107         }
108
109         // Setter-Methode fuer Anzahl Raeume
110         public function setNumRooms ($numRooms) {
111                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Raum/R&auml;ume gesetzt.<br />\n",
112                         __CLASS__,
113                         __LINE__,
114                         $numRooms
115                 ));
116                 $this->numRooms = $numRooms;
117         }
118
119         // Setter-Methode fuer Anzahl Kabinen
120         public function setNumCabin ($numCabin) {
121                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%d</strong> Kabine(n) gesetzt.<br />\n",
122                         __CLASS__,
123                         __LINE__,
124                         $numCabin
125                 ));
126                 $this->numCabin = $numCabin;
127         }
128
129         // Loesch-Methode fuer Anzahl Betten
130         public function removeNumBeds() {
131                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl Betten gel&ouml;scht.<br />\n",
132                         __CLASS__,
133                         __LINE__
134                 ));
135                 unset($this->numBeds);
136         }
137
138         // Loesch-Methode fuer Anzahl Kabinen
139         public function removeNumCabin() {
140                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl Kabinen gel&ouml;scht.<br />\n",
141                         __CLASS__,
142                         __LINE__
143                 ));
144                 unset($this->numCabin);
145         }
146
147         // Loesch-Methode fuer Anzahl Raeume
148         public function removeNumRooms() {
149                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Anzahl R&auml;ume gel&ouml;scht.<br />\n",
150                         __CLASS__,
151                         __LINE__
152                 ));
153                 unset($this->numRooms);
154         }
155
156         // Bettenanzahl pro Kabine berechnen
157         public function calcTotalBedsByCabin () {
158                 // Dann Bettenanzahl holen und aufaddieren
159                 $beds = $this->getNumBeds();
160                 $num  = $this->getNumCabin();
161                 $cabinBeds = $beds * $num;
162                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) {
163                         // Instanz holen
164                         $cabType = "Kabine ohne Namen";
165                         $cab = $this->getPartInstance();
166                         if (!is_null($cab)) {
167                                 // Kabinenbeschreibung holen
168                                 $cabType = $cab->__toString();
169                         }
170
171                         // Debug-Meldung ausgeben
172                         $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",
173                                 __CLASS__,
174                                 __LINE__,
175                                 $num,
176                                 $cabType,
177                                 $beds,
178                                 $cabinBeds
179                         ));
180                 }
181                 return $cabinBeds;
182         }
183 }
184
185 // [EOF]
186 ?>