29084843a2294ceb728f2a2e011ff9787e42839b
[shipsimu.git] / application / ship-simu / main / constructions / yards / class_Shipyard.php
1 <?php
2 /**
3  * A shipyard construction class which can be used for constructing all kinds of
4  * ships.
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
8  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.ship-simu.org
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 class Shipyard extends BaseConstruction {
26         // Werft-Name
27         private $shipyardName    = "Namenlose Werft";
28
29         // Arbeiter-Liste
30         private $staffList       = null;
31
32         // Queue-Liste fuer zu bauende Schiffe
33         private $queueList       = null;
34
35         // Aktuell im Bau befindliches Schiff
36         private $currShipInConst = null;
37
38         // Liste konstruierbarer Schiffstypen
39         private $shipTypeList = null;
40
41         // Zugewiesener Hafen
42         private $harborInstance = null;
43
44         // Zugewiesene Reederei
45         private $shippingCompany = null;
46
47         // Constructor
48         protected function __construct () {
49                 // Call parent constructor
50                 parent::__construct(__CLASS__);
51
52                 // Debug message
53                 if (((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
54                         $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
55                                 __CLASS__,
56                                 __LINE__
57                         ));
58                 }
59
60                 // Set description
61                 $this->setObjectDescription("Werft");
62
63                 // Staff-Liste/Schiffstyp-Liste erzeugen
64                 $this->createStaffList();
65                 $this->createShipTypeList();
66
67                 // Generate unique ID number
68                 $this->createUniqueID();
69         }
70
71         // Create a shipyard and notify it about it's owner
72         public final static function createShipyardNotify (Harbor $harborInstance, $shipyardName, ShippingCompany $companyInstance) {
73                 // Werft-Instanz holen
74                 $shipyardInstance = self::createShipyard($harborInstance, $shipyardName);
75
76                 // Reederei der Werft zuweisen
77                 $shipyardInstance->setCompanyInstance($companyInstance);
78
79                 // Die Reederei ueber ihre Werft informieren
80                 $companyInstance->addNewShipyard($shipyardInstance);
81
82                 // Instanz zurueckgeben
83                 return $shipyardInstance;
84         }
85
86         // Create a shipyard, first we need to create a harbor
87         public final static function createShipyard (Harbor $harborInstance, $shipyardName) {
88                 // Instanz temporaer holen
89                 $shipyardInstance = new Shipyard();
90
91                 // Debug message
92                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Eine Werft mit dem Namen <strong>%s</strong> wird im Hafen <strong>%s</strong> konstruiert.<br />\n",
93                         __CLASS__,
94                         __LINE__,
95                         $shipyardName,
96                         $harborInstance->getHarborName()
97                 ));
98
99                 // Werft-Name setzen
100                 $shipyardInstance->setShipyardName($shipyardName);
101
102                 // Hafen-Instanz setzen
103                 $shipyardInstance->setHarborInstance($harborInstance);
104
105                 // Abmasse setzen in Meter
106                 $shipyardInstance->setWidth(30);
107                 $shipyardInstance->setHeight(30);
108                 $shipyardInstance->setLength(100);
109
110                 // Clean up a little
111                 $shipyardInstance->removeDraught();
112                 $shipyardInstance->removeSystemArray();
113
114                 // Debug-Meldung
115                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.<br />\n",
116                         __CLASS__,
117                         __LINE__,
118                         $shipyardName
119                 ));
120
121                 // Instanz zurueckliefern
122                 return $shipyardInstance;
123         }
124
125         // Create staff list
126         private function createStaffList () {
127                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erh&auml;lt eine Arbeiterliste.<br />\n",
128                         __CLASS__,
129                         __LINE__,
130                         $this->getShipyardName()
131                 ));
132                 $this->staffList = new FrameworkArrayObject();
133         }
134
135         // Create ship type list
136         private function createShipTypeList () {
137                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erh&auml;lt eine Typenliste.<br />\n",
138                         __CLASS__,
139                         __LINE__,
140                         $this->getShipyardName()
141                 ));
142                 $this->shipTypeList = new FrameworkArrayObject();
143         }
144
145         // Setter-Methode fuer Werft-Name
146         public final function setShipyardName ($shipyardName) {
147                 $this->shipyardName = (string) $shipyardName;
148         }
149
150         // Getter-Methode fuer Werft-Name
151         public final function getShipyardName () {
152                 return $this->shipyardName;
153         }
154
155         // Setter-Methode fuer Hafen-Instanz
156         public final function setHarborInstance (Harbor $harborInstance) {
157                 $this->harborInstance = $harborInstance;
158         }
159
160         // Getter-Methode fuer Hafen-Instanz
161         public final function getHarborInstance () {
162                 return $this->harborInstance;
163         }
164
165         // Setter fuer Reederei-Instanz
166         public final function setCompanyInstance (ShippingCompany $companyInstance) {
167                 $this->shippingCompany = $companyInstance;
168         }
169
170         // Getter fuer Reederei-Instanz
171         public final function getCompanyInstance () {
172                 return $this->shippingCompany;
173         }
174
175         // Add new personell
176         public function addNewPersonell ($personell) {
177                 if (is_null($this->staffList)) {
178                         // Opps, not initialized!
179                         ApplicationEntryPoint::app_die("New personell: <pre>".print_r($this, true)."</pre>");
180                 }
181
182                 // Add to list
183                 $this->staffList->append($personell);
184         }
185
186         // Add a new ship type to our list
187         public function addNewConstructableShipType ($shipType) {
188                 // This must be a string!
189                 $shipType = (string) $shipType;
190
191                 // Debug message
192                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> kann bald Schiffe vom Typ <strong>%s</strong> bauen.<br />\n",
193                         __CLASS__,
194                         __LINE__,
195                         $this->getShipyardName(),
196                         $shipType
197                 ));
198
199                 // Add to list
200                 $this->shipTypeList->append($shipType);
201         }
202
203         // Is the specified ship type in our list?
204         public function isShipTypeConstructable ($shipType) {
205                 // First we can't build this ship
206                 $result = false;
207
208                 // This must be a string!
209                 $shipType = (string) $shipType;
210
211                 // Debug message
212                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> pr&uuml;ft, ob Schiffe vom Typ <strong>%s</strong> baubar sind.<br />\n",
213                         __CLASS__,
214                         __LINE__,
215                         $this->getShipyardName(),
216                         $shipType
217                 ));
218
219                 // Iterate through all types
220                 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
221                         // Get current ship type
222                         $type = (string) $idx->current();
223
224                         // Is both the same?
225                         $result = ($type == $shipType);
226
227                         // Type is found?
228                         if ($result) break; // Then abort the search!
229                 }
230
231                 // Debug message
232                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> hat die Suche nach dem Schiffstyp <strong>%s</strong> abgeschlossen.<br />\n",
233                         __CLASS__,
234                         __LINE__,
235                         $this->getShipyardName(),
236                         $shipType
237                 ));
238
239                 // Return result
240                 return $result;
241         }
242
243         /**
244          * Stub!
245          */
246         public function saveObjectToDatabase () {
247                 $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
248                         $this->__toString(),
249                         __FUNCTION__
250                 ));
251         }
252
253         /**
254          * Limits this object with an ObjectLimits instance
255          */
256         public function limitObject (ObjectLimits $limitInstance) {
257                 ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");
258         }
259 }
260
261 // [EOF]
262 ?>