eval() commands replace by improved object factory, user login class stub added
[shipsimu.git] / application / ship-simu / main / ships / class_BaseShip.php
1 <?php
2 /**
3  * A general ship class for all other kinds of ships even small sail ships
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 BaseShip extends BaseSimulator {
25         // Name des Shipes
26         private $shipName   = "Unbekanntes Schiff";
27
28         // Anzahl Anker
29         private $numAnchor  = 0;
30
31         // Tiefgang in Meter
32         private $draught    = 0;
33
34         // Besatzung-Objekte
35         private $crewList   = null;
36
37         // Aufbauten-Objekte
38         private $structures = null;
39
40         // Namenloses Ship generieren
41         protected function __construct($class) {
42                 // Call parent constructor
43                 parent::__construct($class);
44
45                 // Set object description
46                 $this->setObjectDescription("Allgemeines Schiff");
47
48                 // Prepare array object for all structures
49                 $this->createStructuresArray();
50
51                 // Clean-up a little
52                 $this->removePartInstance();
53                 $this->removeNumberFormaters();
54         }
55
56         // Array-Objekt anlegen
57         private function createStructuresArray () {
58                 $this->structures = new FrameworkArrayObject("FakedShipStructures");
59         }
60
61         // Schiffsteil generieren (kann alles sein)
62         // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
63         // partClass = Das zu konstruierende Schiffsteil
64         public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
65                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> erh&auml;lt ein neues Schiffsteil (%s).<br />\n",
66                         __CLASS__,
67                         __LINE__,
68                         $this->getShipName(),
69                         $partClass
70                 ));
71
72                 // Ist die gewuenschte Klasse vorhanden?
73                 if (class_exists($partClass)) {
74                         // Get an instance back from our object factory
75                         $partInstance = ObjectFactory::createObjectByName($partClass);
76                 } else {
77                         // Nicht vorhanden, dann Ausnahme werfen!
78                         throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND);
79                 }
80
81                 // Das Einbauen versuchen...
82                 try {
83                         $partInstance->addShipPartToShip($this, $buildInstance);
84                 } catch (MotorShipMismatchException $e) {
85                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Motor erhalten! Grund: <strong>%s</strong><br />\n",
86                                 __CLASS__,
87                                 __LINE__,
88                                 $this->getShipName(),
89                                 $e->getMessage()
90                         ));
91                         return false;
92                 } catch (RoomShipMismatchException $e) {
93                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Maschinenraum erhalten! Grund: <strong>%s</strong><br />\n",
94                                 __CLASS__,
95                                 __LINE__,
96                                 $this->getShipName(),
97                                 $e->getMessage()
98                         ));
99                         return false;
100
101                 } catch (StructureShipMismatchException $e) {
102                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Aufbauten erhalten! Grund: <strong>%s</strong><br />\n",
103                                 __CLASS__,
104                                 __LINE__,
105                                 $this->getShipName(),
106                                 $e->getMessage()
107                         ));
108                         return false;
109                 } catch (CabinShipMismatchException $e) {
110                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Kabine erhalten! Grund: <strong>%s</strong><br />\n",
111                                 __CLASS__,
112                                 __LINE__,
113                                 $this->getShipName(),
114                                 $e->getMessage()
115                         ));
116                         return false;
117                 } catch (DeckShipMismatchException $e) {
118                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat kein Deck erhalten! Grund: <strong>%s</strong><br />\n",
119                                 __CLASS__,
120                                 __LINE__,
121                                 $this->getShipName(),
122                                 $e->getMessage()
123                         ));
124                         return false;
125                 } catch (ExceptionNotChangedException $e) {
126                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht ge&auml;ndert. Details: <strong>%s</strong><br />\n",
127                                 __CLASS__,
128                                 __LINE__,
129                                 $e->getMessage()
130                         ));
131                         return false;
132                 } catch (ExceptionNotFoundException $e) {
133                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
134                                 __CLASS__,
135                                 __LINE__,
136                                 $e->getMessage()
137                         ));
138                         return false;
139                 }
140
141                 // Instanz im Aufbauten-Array vermerken
142                 $this->structures->append($partInstance);
143
144                 // Debug-Meldung ausgeben
145                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat das Schiffsteil <strong>%s</strong> eingebaut bekommen.<br />\n",
146                         __CLASS__,
147                         __LINE__,
148                         $this->getShipName(),
149                         $partInstance->getObjectDescription()
150                 ));
151
152                 // Alles klar!
153                 return true;
154         }
155
156         // Getter-Methode fuer Strukturen-Array
157         public final function getStructuresArray () {
158                 return $this->structures;
159         }
160
161         // STUB: Getter-Methode Anzahl Betten
162         public function calcTotalBeds () {
163                 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
164                 return 0;
165         }
166
167         // Setter-Methode fuer Schiffsnamen
168         public final function setShipName ($shipName) {
169                 // Cast the string
170                 $shipName = (string) $shipName;
171
172                 // Debug message
173                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das neue Schiff vom Typ <strong>%s</strong> wird auf den Namen <strong>%s</strong> getauft.<br />\n",
174                         __CLASS__,
175                         __LINE__,
176                         $this->__toString(),
177                         $shipName
178                 ));
179
180                 // Set ship name
181                 $this->shipName = $shipName;
182         }
183
184         // Getter-Methode fuer Schiffsnamen
185         public final function getShipName () {
186                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das <strong>%s</strong> ist auf den Namen <strong>%s</strong> getauft worden.<br />\n",
187                         __CLASS__,
188                         __LINE__,
189                         $this->__toString(),
190                         $this->shipName
191                 ));
192                 return $this->shipName;
193         }
194
195         // Setter-Methode fuer Tiefgang
196         public final function setDraught ($draught) {
197                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das <strong>%s</strong> mit dem Namen <strong>%s</strong> hat einen Tiefgang von <strong>%sm</strong>.<br />\n",
198                         __CLASS__,
199                         __LINE__,
200                         $this->__toString(),
201                         $this->shipName,
202                         $draught
203                 ));
204                 $this->draught = (int) $draught;
205         }
206
207         // Getter-Methode fuer Tiefgang
208         public final function getDraught() {
209                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
210                         __CLASS__,
211                         __LINE__,
212                         $this->shipName
213                 ));
214                 return $this->draught;
215         }
216
217         // Setter-Methode fuer Anzahl Anker
218         public final function setNumAnchor ($numAnchor) {
219                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das <strong>%s</strong> mit dem Namen <strong>%s</strong> hat <strong>%s</strong> Anker.<br />\n",
220                         __CLASS__,
221                         __LINE__,
222                         $this->__toString(),
223                         $this->shipName,
224                         $numAnchor
225                 ));
226                 $this->numAnchor = (int) $numAnchor;
227         }
228 }
229
230 // [EOF]
231 ?>