Updated 'core'.
[shipsimu.git] / application / shipsimu / 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@shipsimu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.shipsimu.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($className) {
42                 // Call parent constructor
43                 parent::__construct($className);
44
45                 // Prepare array object for all structures
46                 $this->createStructuresArray();
47
48                 // Clean-up a little
49                 $this->removePartInstance();
50         }
51
52         // Array-Objekt anlegen
53         private function createStructuresArray () {
54                 $this->structures = new FrameworkArrayObject("FakedShipStructures");
55         }
56
57         // Schiffsteil generieren (kann alles sein)
58         // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
59         // partClass = Das zu konstruierende Schiffsteil
60         public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
61                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> erh&auml;lt ein neues Schiffsteil (%s).",
62                         __CLASS__,
63                         __LINE__,
64                         $this->getShipName(),
65                         $partClass
66                 ));
67
68                 // Ist die gewuenschte Klasse vorhanden?
69                 if (!class_exists($partClass)) {
70                         // Nicht vorhanden, dann Ausnahme werfen!
71                         throw new NoClassException($partClass, self::EXCEPTION_CLASS_NOT_FOUND);
72                 } // END - if
73
74                 // Get an instance back from our object factory
75                 $partInstance = ObjectFactory::createObjectByName($partClass);
76
77                 // Das Einbauen versuchen...
78                 try {
79                         $partInstance->addShipPartToShip($this, $buildInstance);
80                 } catch (MotorShipMismatchException $e) {
81                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Motor erhalten! Grund: <strong>%s</strong>",
82                                 __CLASS__,
83                                 __LINE__,
84                                 $this->getShipName(),
85                                 $e->getMessage()
86                         ));
87                         return false;
88                 } catch (RoomShipMismatchException $e) {
89                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Maschinenraum erhalten! Grund: <strong>%s</strong>",
90                                 __CLASS__,
91                                 __LINE__,
92                                 $this->getShipName(),
93                                 $e->getMessage()
94                         ));
95                         return false;
96
97                 } catch (StructureShipMismatchException $e) {
98                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Aufbauten erhalten! Grund: <strong>%s</strong>",
99                                 __CLASS__,
100                                 __LINE__,
101                                 $this->getShipName(),
102                                 $e->getMessage()
103                         ));
104                         return false;
105                 } catch (CabinShipMismatchException $e) {
106                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Kabine erhalten! Grund: <strong>%s</strong>",
107                                 __CLASS__,
108                                 __LINE__,
109                                 $this->getShipName(),
110                                 $e->getMessage()
111                         ));
112                         return false;
113                 } catch (DeckShipMismatchException $e) {
114                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat kein Deck erhalten! Grund: <strong>%s</strong>",
115                                 __CLASS__,
116                                 __LINE__,
117                                 $this->getShipName(),
118                                 $e->getMessage()
119                         ));
120                         return false;
121                 }
122
123                 // Instanz im Aufbauten-Array vermerken
124                 $this->structures->append($partInstance);
125
126                 // Alles klar!
127                 return true;
128         }
129
130         // Getter-Methode fuer Strukturen-Array
131         public final function getStructuresArray () {
132                 return $this->structures;
133         }
134
135         // STUB: Getter-Methode Anzahl Betten
136         public function calcTotalBeds () {
137                 $this->partialStub("Please implement this stub in your ship!");
138         }
139
140         // Setter-Methode fuer Schiffsnamen
141         public final function setShipName ($shipName) {
142                 $this->shipName = (string) $shipName;
143         }
144
145         // Getter-Methode fuer Schiffsnamen
146         public final function getShipName () {
147                 return $this->shipName;
148         }
149
150         // Setter-Methode fuer Tiefgang
151         public final function setDraught ($draught) {
152                 $this->draught = (int) $draught;
153         }
154
155         // Getter-Methode fuer Tiefgang
156         public final function getDraught() {
157                 return $this->draught;
158         }
159
160         // Setter-Methode fuer Anzahl Anker
161         public final function setNumAnchor ($numAnchor) {
162                 $this->numAnchor = (int) $numAnchor;
163         }
164 }
165
166 // [EOF]
167 ?>