Renamed 'ship-simu' to 'shipsimu' + added 'core' and symlink to core/inc
[shipsimu.git] / application / shipsimu / 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@shipsimu.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.shipsimu.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 static final 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 static final 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
99                 // Debug-Meldung
100                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->debugOutput(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.",
101                         __CLASS__,
102                         __LINE__,
103                         $shipyardName
104                 ));
105
106                 // Instanz zurueckliefern
107                 return $shipyardInstance;
108         }
109
110         // Create staff list
111         private function createStaffList () {
112                 $this->staffList = new FrameworkArrayObject("FakedStaffList");
113         }
114
115         // Create ship type list
116         private function createShipTypeList () {
117                 $this->shipTypeList = new FrameworkArrayObject("FakedShipTypeList");
118         }
119
120         // Setter-Methode fuer Werft-Name
121         public final function setShipyardName ($shipyardName) {
122                 $this->shipyardName = (string) $shipyardName;
123         }
124
125         // Getter-Methode fuer Werft-Name
126         public final function getShipyardName () {
127                 return $this->shipyardName;
128         }
129
130         // Setter-Methode fuer Hafen-Instanz
131         public final function setHarborInstance (Harbor $harborInstance) {
132                 $this->harborInstance = $harborInstance;
133         }
134
135         // Getter-Methode fuer Hafen-Instanz
136         public final function getHarborInstance () {
137                 return $this->harborInstance;
138         }
139
140         // Setter fuer Reederei-Instanz
141         public final function setCompanyInstance (ShippingCompany $companyInstance) {
142                 $this->shippingCompany = $companyInstance;
143         }
144
145         // Getter fuer Reederei-Instanz
146         public final function getCompanyInstance () {
147                 return $this->shippingCompany;
148         }
149
150         // Add new personell
151         public function addNewPersonell ($personell) {
152                 // Add to list
153                 $this->staffList->append($personell);
154         }
155
156         // Add a new ship type to our list
157         public function addNewConstructableShipType ($shipType) {
158                 // This must be a string!
159                 $shipType = (string) $shipType;
160
161                 // Debug message
162                 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.",
163                         __CLASS__,
164                         __LINE__,
165                         $this->getShipyardName(),
166                         $shipType
167                 ));
168
169                 // Add to list
170                 $this->shipTypeList->append($shipType);
171         }
172
173         // Is the specified ship type in our list?
174         public function isShipTypeConstructable ($shipType) {
175                 // First we can't build this ship
176                 $result = false;
177
178                 // This must be a string!
179                 $shipType = (string) $shipType;
180
181                 // Debug message
182                 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.",
183                         __CLASS__,
184                         __LINE__,
185                         $this->getShipyardName(),
186                         $shipType
187                 ));
188
189                 // Iterate through all types
190                 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
191                         // Get current ship type
192                         $type = (string) $idx->current();
193
194                         // Is both the same?
195                         $result = ($type == $shipType);
196
197                         // Type is found?
198                         if ($result) break; // Then abort the search!
199                 }
200
201                 // Debug message
202                 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.",
203                         __CLASS__,
204                         __LINE__,
205                         $this->getShipyardName(),
206                         $shipType
207                 ));
208
209                 // Return result
210                 return $result;
211         }
212 }
213
214 // [EOF]
215 ?>