Copyright updated, menu class added for 'home'
[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, 2009 Ship-Simu Developer Team
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                 // Staff-Liste/Schiffstyp-Liste erzeugen
53                 $this->createStaffList();
54                 $this->createShipTypeList();
55         }
56
57         // Create a shipyard and notify it about it's owner
58         public final static function createShipyardNotify (Harbor $harborInstance, $shipyardName, ShippingCompany $companyInstance) {
59                 // Werft-Instanz holen
60                 $shipyardInstance = self::createShipyard($harborInstance, $shipyardName);
61
62                 // Reederei der Werft zuweisen
63                 $shipyardInstance->setCompanyInstance($companyInstance);
64
65                 // Die Reederei ueber ihre Werft informieren
66                 $companyInstance->addNewShipyard($shipyardInstance);
67
68                 // Instanz zurueckgeben
69                 return $shipyardInstance;
70         }
71
72         // Create a shipyard, first we need to create a harbor
73         public final static function createShipyard (Harbor $harborInstance, $shipyardName) {
74                 // Instanz temporaer holen
75                 $shipyardInstance = new Shipyard();
76
77                 // Debug message
78                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->debugOutput(sprintf("[%s:%d] Eine Werft mit dem Namen <strong>%s</strong> wird im Hafen <strong>%s</strong> konstruiert.",
79                         __CLASS__,
80                         __LINE__,
81                         $shipyardName,
82                         $harborInstance->getHarborName()
83                 ));
84
85                 // Werft-Name setzen
86                 $shipyardInstance->setShipyardName($shipyardName);
87
88                 // Hafen-Instanz setzen
89                 $shipyardInstance->setHarborInstance($harborInstance);
90
91                 // Abmasse setzen in Meter
92                 $shipyardInstance->setWidth(30);
93                 $shipyardInstance->setHeight(30);
94                 $shipyardInstance->setLength(100);
95
96                 // Clean up a little
97                 $shipyardInstance->removeDraught();
98                 $shipyardInstance->removeSystemArray();
99
100                 // Debug-Meldung
101                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->debugOutput(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.",
102                         __CLASS__,
103                         __LINE__,
104                         $shipyardName
105                 ));
106
107                 // Instanz zurueckliefern
108                 return $shipyardInstance;
109         }
110
111         // Create staff list
112         private function createStaffList () {
113                 $this->staffList = new FrameworkArrayObject("FakedStaffList");
114         }
115
116         // Create ship type list
117         private function createShipTypeList () {
118                 $this->shipTypeList = new FrameworkArrayObject("FakedShipTypeList");
119         }
120
121         // Setter-Methode fuer Werft-Name
122         public final function setShipyardName ($shipyardName) {
123                 $this->shipyardName = (string) $shipyardName;
124         }
125
126         // Getter-Methode fuer Werft-Name
127         public final function getShipyardName () {
128                 return $this->shipyardName;
129         }
130
131         // Setter-Methode fuer Hafen-Instanz
132         public final function setHarborInstance (Harbor $harborInstance) {
133                 $this->harborInstance = $harborInstance;
134         }
135
136         // Getter-Methode fuer Hafen-Instanz
137         public final function getHarborInstance () {
138                 return $this->harborInstance;
139         }
140
141         // Setter fuer Reederei-Instanz
142         public final function setCompanyInstance (ShippingCompany $companyInstance) {
143                 $this->shippingCompany = $companyInstance;
144         }
145
146         // Getter fuer Reederei-Instanz
147         public final function getCompanyInstance () {
148                 return $this->shippingCompany;
149         }
150
151         // Add new personell
152         public function addNewPersonell ($personell) {
153                 // Add to list
154                 $this->staffList->append($personell);
155         }
156
157         // Add a new ship type to our list
158         public function addNewConstructableShipType ($shipType) {
159                 // This must be a string!
160                 $shipType = (string) $shipType;
161
162                 // Debug message
163                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Werft <strong>%s</strong> kann bald Schiffe vom Typ <strong>%s</strong> bauen.",
164                         __CLASS__,
165                         __LINE__,
166                         $this->getShipyardName(),
167                         $shipType
168                 ));
169
170                 // Add to list
171                 $this->shipTypeList->append($shipType);
172         }
173
174         // Is the specified ship type in our list?
175         public function isShipTypeConstructable ($shipType) {
176                 // First we can't build this ship
177                 $result = false;
178
179                 // This must be a string!
180                 $shipType = (string) $shipType;
181
182                 // Debug message
183                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Werft <strong>%s</strong> pr&uuml;ft, ob Schiffe vom Typ <strong>%s</strong> baubar sind.",
184                         __CLASS__,
185                         __LINE__,
186                         $this->getShipyardName(),
187                         $shipType
188                 ));
189
190                 // Iterate through all types
191                 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
192                         // Get current ship type
193                         $type = (string) $idx->current();
194
195                         // Is both the same?
196                         $result = ($type == $shipType);
197
198                         // Type is found?
199                         if ($result) break; // Then abort the search!
200                 }
201
202                 // Debug message
203                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Werft <strong>%s</strong> hat die Suche nach dem Schiffstyp <strong>%s</strong> abgeschlossen.",
204                         __CLASS__,
205                         __LINE__,
206                         $this->getShipyardName(),
207                         $shipType
208                 ));
209
210                 // Return result
211                 return $result;
212         }
213 }
214
215 // [EOF]
216 ?>