3 * A shipyard construction class which can be used for constructing all kinds of
6 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
25 class Shipyard extends BaseConstruction {
27 private $shipyardName = "Namenlose Werft";
30 private $staffList = null;
32 // Queue-Liste fuer zu bauende Schiffe
33 private $queueList = null;
35 // Aktuell im Bau befindliches Schiff
36 private $currShipInConst = null;
38 // Liste konstruierbarer Schiffstypen
39 private $shipTypeList = null;
42 private $harborInstance = null;
44 // Zugewiesene Reederei
45 private $shippingCompany = null;
48 protected function __construct () {
49 // Call parent constructor
50 parent::__construct(__CLASS__);
53 $this->setObjectDescription("Werft");
55 // Staff-Liste/Schiffstyp-Liste erzeugen
56 $this->createStaffList();
57 $this->createShipTypeList();
59 // Generate unique ID number
60 $this->createUniqueID();
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);
68 // Reederei der Werft zuweisen
69 $shipyardInstance->setCompanyInstance($companyInstance);
71 // Die Reederei ueber ihre Werft informieren
72 $companyInstance->addNewShipyard($shipyardInstance);
74 // Instanz zurueckgeben
75 return $shipyardInstance;
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();
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",
88 $harborInstance->getHarborName()
92 $shipyardInstance->setShipyardName($shipyardName);
94 // Hafen-Instanz setzen
95 $shipyardInstance->setHarborInstance($harborInstance);
97 // Abmasse setzen in Meter
98 $shipyardInstance->setWidth(30);
99 $shipyardInstance->setHeight(30);
100 $shipyardInstance->setLength(100);
103 $shipyardInstance->removeDraught();
104 $shipyardInstance->removeSystemArray();
107 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.<br />\n",
113 // Instanz zurueckliefern
114 return $shipyardInstance;
118 private function createStaffList () {
119 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erhält eine Arbeiterliste.<br />\n",
122 $this->getShipyardName()
124 $this->staffList = new FrameworkArrayObject();
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ält eine Typenliste.<br />\n",
132 $this->getShipyardName()
134 $this->shipTypeList = new FrameworkArrayObject();
137 // Setter-Methode fuer Werft-Name
138 public final function setShipyardName ($shipyardName) {
139 $this->shipyardName = (string) $shipyardName;
142 // Getter-Methode fuer Werft-Name
143 public final function getShipyardName () {
144 return $this->shipyardName;
147 // Setter-Methode fuer Hafen-Instanz
148 public final function setHarborInstance (Harbor $harborInstance) {
149 $this->harborInstance = $harborInstance;
152 // Getter-Methode fuer Hafen-Instanz
153 public final function getHarborInstance () {
154 return $this->harborInstance;
157 // Setter fuer Reederei-Instanz
158 public final function setCompanyInstance (ShippingCompany $companyInstance) {
159 $this->shippingCompany = $companyInstance;
162 // Getter fuer Reederei-Instanz
163 public final function getCompanyInstance () {
164 return $this->shippingCompany;
168 public function addNewPersonell ($personell) {
170 $this->staffList->append($personell);
173 // Add a new ship type to our list
174 public function addNewConstructableShipType ($shipType) {
175 // This must be a string!
176 $shipType = (string) $shipType;
179 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",
182 $this->getShipyardName(),
187 $this->shipTypeList->append($shipType);
190 // Is the specified ship type in our list?
191 public function isShipTypeConstructable ($shipType) {
192 // First we can't build this ship
195 // This must be a string!
196 $shipType = (string) $shipType;
199 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> prüft, ob Schiffe vom Typ <strong>%s</strong> baubar sind.<br />\n",
202 $this->getShipyardName(),
206 // Iterate through all types
207 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
208 // Get current ship type
209 $type = (string) $idx->current();
212 $result = ($type == $shipType);
215 if ($result) break; // Then abort the search!
219 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",
222 $this->getShipyardName(),