Even more conflicting calls fixed
[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->generateUniqueId();
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.",
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.",
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                 $this->staffList = new FrameworkArrayObject("FakedStaffList");
120         }
121
122         // Create ship type list
123         private function createShipTypeList () {
124                 $this->shipTypeList = new FrameworkArrayObject("FakedShipTypeList");
125         }
126
127         // Setter-Methode fuer Werft-Name
128         public final function setShipyardName ($shipyardName) {
129                 $this->shipyardName = (string) $shipyardName;
130         }
131
132         // Getter-Methode fuer Werft-Name
133         public final function getShipyardName () {
134                 return $this->shipyardName;
135         }
136
137         // Setter-Methode fuer Hafen-Instanz
138         public final function setHarborInstance (Harbor $harborInstance) {
139                 $this->harborInstance = $harborInstance;
140         }
141
142         // Getter-Methode fuer Hafen-Instanz
143         public final function getHarborInstance () {
144                 return $this->harborInstance;
145         }
146
147         // Setter fuer Reederei-Instanz
148         public final function setCompanyInstance (ShippingCompany $companyInstance) {
149                 $this->shippingCompany = $companyInstance;
150         }
151
152         // Getter fuer Reederei-Instanz
153         public final function getCompanyInstance () {
154                 return $this->shippingCompany;
155         }
156
157         // Add new personell
158         public function addNewPersonell ($personell) {
159                 // Add to list
160                 $this->staffList->append($personell);
161         }
162
163         // Add a new ship type to our list
164         public function addNewConstructableShipType ($shipType) {
165                 // This must be a string!
166                 $shipType = (string) $shipType;
167
168                 // Debug message
169                 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.",
170                         __CLASS__,
171                         __LINE__,
172                         $this->getShipyardName(),
173                         $shipType
174                 ));
175
176                 // Add to list
177                 $this->shipTypeList->append($shipType);
178         }
179
180         // Is the specified ship type in our list?
181         public function isShipTypeConstructable ($shipType) {
182                 // First we can't build this ship
183                 $result = false;
184
185                 // This must be a string!
186                 $shipType = (string) $shipType;
187
188                 // Debug message
189                 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.",
190                         __CLASS__,
191                         __LINE__,
192                         $this->getShipyardName(),
193                         $shipType
194                 ));
195
196                 // Iterate through all types
197                 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
198                         // Get current ship type
199                         $type = (string) $idx->current();
200
201                         // Is both the same?
202                         $result = ($type == $shipType);
203
204                         // Type is found?
205                         if ($result) break; // Then abort the search!
206                 }
207
208                 // Debug message
209                 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.",
210                         __CLASS__,
211                         __LINE__,
212                         $this->getShipyardName(),
213                         $shipType
214                 ));
215
216                 // Return result
217                 return $result;
218         }
219 }
220
221 // [EOF]
222 ?>