Translations to english and debug messages removed (missing files added)
[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                 // Set description
53                 $this->setObjectDescription("Werft");
54
55                 // Staff-Liste/Schiffstyp-Liste erzeugen
56                 $this->createStaffList();
57                 $this->createShipTypeList();
58
59                 // Generate unique ID number
60                 $this->createUniqueID();
61         }
62
63         // Create a shipyard and notify it about it's owner
64         public final static function createShipyardNotify (Harbor $harborInstance, $shipyardName, ShippingCompany $companyInstance) {
65                 // Werft-Instanz holen
66                 $shipyardInstance = self::createShipyard($harborInstance, $shipyardName);
67
68                 // Reederei der Werft zuweisen
69                 $shipyardInstance->setCompanyInstance($companyInstance);
70
71                 // Die Reederei ueber ihre Werft informieren
72                 $companyInstance->addNewShipyard($shipyardInstance);
73
74                 // Instanz zurueckgeben
75                 return $shipyardInstance;
76         }
77
78         // Create a shipyard, first we need to create a harbor
79         public final static function createShipyard (Harbor $harborInstance, $shipyardName) {
80                 // Instanz temporaer holen
81                 $shipyardInstance = new Shipyard();
82
83                 // Debug message
84                 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",
85                         __CLASS__,
86                         __LINE__,
87                         $shipyardName,
88                         $harborInstance->getHarborName()
89                 ));
90
91                 // Werft-Name setzen
92                 $shipyardInstance->setShipyardName($shipyardName);
93
94                 // Hafen-Instanz setzen
95                 $shipyardInstance->setHarborInstance($harborInstance);
96
97                 // Abmasse setzen in Meter
98                 $shipyardInstance->setWidth(30);
99                 $shipyardInstance->setHeight(30);
100                 $shipyardInstance->setLength(100);
101
102                 // Clean up a little
103                 $shipyardInstance->removeDraught();
104                 $shipyardInstance->removeSystemArray();
105
106                 // Debug-Meldung
107                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.<br />\n",
108                         __CLASS__,
109                         __LINE__,
110                         $shipyardName
111                 ));
112
113                 // Instanz zurueckliefern
114                 return $shipyardInstance;
115         }
116
117         // Create staff list
118         private function createStaffList () {
119                 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",
120                         __CLASS__,
121                         __LINE__,
122                         $this->getShipyardName()
123                 ));
124                 $this->staffList = new FrameworkArrayObject();
125         }
126
127         // Create ship type list
128         private function createShipTypeList () {
129                 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",
130                         __CLASS__,
131                         __LINE__,
132                         $this->getShipyardName()
133                 ));
134                 $this->shipTypeList = new FrameworkArrayObject();
135         }
136
137         // Setter-Methode fuer Werft-Name
138         public final function setShipyardName ($shipyardName) {
139                 $this->shipyardName = (string) $shipyardName;
140         }
141
142         // Getter-Methode fuer Werft-Name
143         public final function getShipyardName () {
144                 return $this->shipyardName;
145         }
146
147         // Setter-Methode fuer Hafen-Instanz
148         public final function setHarborInstance (Harbor $harborInstance) {
149                 $this->harborInstance = $harborInstance;
150         }
151
152         // Getter-Methode fuer Hafen-Instanz
153         public final function getHarborInstance () {
154                 return $this->harborInstance;
155         }
156
157         // Setter fuer Reederei-Instanz
158         public final function setCompanyInstance (ShippingCompany $companyInstance) {
159                 $this->shippingCompany = $companyInstance;
160         }
161
162         // Getter fuer Reederei-Instanz
163         public final function getCompanyInstance () {
164                 return $this->shippingCompany;
165         }
166
167         // Add new personell
168         public function addNewPersonell ($personell) {
169                 if (is_null($this->staffList)) {
170                         // Opps, not initialized!
171                         ApplicationEntryPoint::app_die("New personell: <pre>".print_r($this, true)."</pre>");
172                 }
173
174                 // Add to list
175                 $this->staffList->append($personell);
176         }
177
178         // Add a new ship type to our list
179         public function addNewConstructableShipType ($shipType) {
180                 // This must be a string!
181                 $shipType = (string) $shipType;
182
183                 // Debug message
184                 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",
185                         __CLASS__,
186                         __LINE__,
187                         $this->getShipyardName(),
188                         $shipType
189                 ));
190
191                 // Add to list
192                 $this->shipTypeList->append($shipType);
193         }
194
195         // Is the specified ship type in our list?
196         public function isShipTypeConstructable ($shipType) {
197                 // First we can't build this ship
198                 $result = false;
199
200                 // This must be a string!
201                 $shipType = (string) $shipType;
202
203                 // Debug message
204                 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",
205                         __CLASS__,
206                         __LINE__,
207                         $this->getShipyardName(),
208                         $shipType
209                 ));
210
211                 // Iterate through all types
212                 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
213                         // Get current ship type
214                         $type = (string) $idx->current();
215
216                         // Is both the same?
217                         $result = ($type == $shipType);
218
219                         // Type is found?
220                         if ($result) break; // Then abort the search!
221                 }
222
223                 // Debug message
224                 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",
225                         __CLASS__,
226                         __LINE__,
227                         $this->getShipyardName(),
228                         $shipType
229                 ));
230
231                 // Return result
232                 return $result;
233         }
234
235         /**
236          * Stub!
237          */
238         public function saveObjectToDatabase () {
239                 $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
240                         $this->__toString(),
241                         __FUNCTION__
242                 ));
243         }
244
245         /**
246          * Limits this object with an ObjectLimits instance
247          */
248         public function limitObject (ObjectLimits $limitInstance) {
249                 ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");
250         }
251 }
252
253 // [EOF]
254 ?>