Debug mailer finished and debug messages 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($className) {
42                 // Call parent constructor
43                 parent::__construct($className);
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->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> erh&auml;lt ein neues Schiffsteil (%s).",
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->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Motor erhalten! Grund: <strong>%s</strong>",
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->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Maschinenraum erhalten! Grund: <strong>%s</strong>",
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->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Aufbauten erhalten! Grund: <strong>%s</strong>",
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->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Kabine erhalten! Grund: <strong>%s</strong>",
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->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat kein Deck erhalten! Grund: <strong>%s</strong>",
119                                 __CLASS__,
120                                 __LINE__,
121                                 $this->getShipName(),
122                                 $e->getMessage()
123                         ));
124                         return false;
125                 }
126
127                 // Instanz im Aufbauten-Array vermerken
128                 $this->structures->append($partInstance);
129
130                 // Debug-Meldung ausgeben
131                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat das Schiffsteil <strong>%s</strong> eingebaut bekommen.",
132                         __CLASS__,
133                         __LINE__,
134                         $this->getShipName(),
135                         $partInstance->getObjectDescription()
136                 ));
137
138                 // Alles klar!
139                 return true;
140         }
141
142         // Getter-Methode fuer Strukturen-Array
143         public final function getStructuresArray () {
144                 return $this->structures;
145         }
146
147         // STUB: Getter-Methode Anzahl Betten
148         public function calcTotalBeds () {
149                 $this->partialStub("Please implement this stub in your ship!");
150         }
151
152         // Setter-Methode fuer Schiffsnamen
153         public final function setShipName ($shipName) {
154                 $this->shipName = (string) $shipName;
155         }
156
157         // Getter-Methode fuer Schiffsnamen
158         public final function getShipName () {
159                 return $this->shipName;
160         }
161
162         // Setter-Methode fuer Tiefgang
163         public final function setDraught ($draught) {
164                 $this->draught = (int) $draught;
165         }
166
167         // Getter-Methode fuer Tiefgang
168         public final function getDraught() {
169                 return $this->draught;
170         }
171
172         // Setter-Methode fuer Anzahl Anker
173         public final function setNumAnchor ($numAnchor) {
174                 $this->numAnchor = (int) $numAnchor;
175         }
176 }
177
178 // [EOF]
179 ?>