]> git.mxchange.org Git - shipsimu.git/blob - application/ship-simu/main/ships/class_BaseShip.php
Deprecated methods and exceptions removed
[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 (ExceptionNotFoundException $e) {
126                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: <strong>%s</strong><br />\n",
127                                 __CLASS__,
128                                 __LINE__,
129                                 $e->getMessage()
130                         ));
131                         return false;
132                 }
133
134                 // Instanz im Aufbauten-Array vermerken
135                 $this->structures->append($partInstance);
136
137                 // Debug-Meldung ausgeben
138                 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",
139                         __CLASS__,
140                         __LINE__,
141                         $this->getShipName(),
142                         $partInstance->getObjectDescription()
143                 ));
144
145                 // Alles klar!
146                 return true;
147         }
148
149         // Getter-Methode fuer Strukturen-Array
150         public final function getStructuresArray () {
151                 return $this->structures;
152         }
153
154         // STUB: Getter-Methode Anzahl Betten
155         public function calcTotalBeds () {
156                 $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.<br />\n");
157                 return 0;
158         }
159
160         // Setter-Methode fuer Schiffsnamen
161         public final function setShipName ($shipName) {
162                 // Cast the string
163                 $shipName = (string) $shipName;
164
165                 // Debug message
166                 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",
167                         __CLASS__,
168                         __LINE__,
169                         $this->__toString(),
170                         $shipName
171                 ));
172
173                 // Set ship name
174                 $this->shipName = $shipName;
175         }
176
177         // Getter-Methode fuer Schiffsnamen
178         public final function getShipName () {
179                 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",
180                         __CLASS__,
181                         __LINE__,
182                         $this->__toString(),
183                         $this->shipName
184                 ));
185                 return $this->shipName;
186         }
187
188         // Setter-Methode fuer Tiefgang
189         public final function setDraught ($draught) {
190                 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",
191                         __CLASS__,
192                         __LINE__,
193                         $this->__toString(),
194                         $this->shipName,
195                         $draught
196                 ));
197                 $this->draught = (int) $draught;
198         }
199
200         // Getter-Methode fuer Tiefgang
201         public final function getDraught() {
202                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes <strong>%s</strong> wurde angefordert.<br />\n",
203                         __CLASS__,
204                         __LINE__,
205                         $this->shipName
206                 ));
207                 return $this->draught;
208         }
209
210         // Setter-Methode fuer Anzahl Anker
211         public final function setNumAnchor ($numAnchor) {
212                 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",
213                         __CLASS__,
214                         __LINE__,
215                         $this->__toString(),
216                         $this->shipName,
217                         $numAnchor
218                 ));
219                 $this->numAnchor = (int) $numAnchor;
220         }
221 }
222
223 // [EOF]
224 ?>