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, 2009 Ship-Simu Developer Team
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__);
52 // Staff-Liste/Schiffstyp-Liste erzeugen
53 $this->createStaffList();
54 $this->createShipTypeList();
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);
62 // Reederei der Werft zuweisen
63 $shipyardInstance->setCompanyInstance($companyInstance);
65 // Die Reederei ueber ihre Werft informieren
66 $companyInstance->addNewShipyard($shipyardInstance);
68 // Instanz zurueckgeben
69 return $shipyardInstance;
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();
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.",
82 $harborInstance->getHarborName()
86 $shipyardInstance->setShipyardName($shipyardName);
88 // Hafen-Instanz setzen
89 $shipyardInstance->setHarborInstance($harborInstance);
91 // Abmasse setzen in Meter
92 $shipyardInstance->setWidth(30);
93 $shipyardInstance->setHeight(30);
94 $shipyardInstance->setLength(100);
97 $shipyardInstance->removeDraught();
100 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->debugOutput(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.",
106 // Instanz zurueckliefern
107 return $shipyardInstance;
111 private function createStaffList () {
112 $this->staffList = new FrameworkArrayObject("FakedStaffList");
115 // Create ship type list
116 private function createShipTypeList () {
117 $this->shipTypeList = new FrameworkArrayObject("FakedShipTypeList");
120 // Setter-Methode fuer Werft-Name
121 public final function setShipyardName ($shipyardName) {
122 $this->shipyardName = (string) $shipyardName;
125 // Getter-Methode fuer Werft-Name
126 public final function getShipyardName () {
127 return $this->shipyardName;
130 // Setter-Methode fuer Hafen-Instanz
131 public final function setHarborInstance (Harbor $harborInstance) {
132 $this->harborInstance = $harborInstance;
135 // Getter-Methode fuer Hafen-Instanz
136 public final function getHarborInstance () {
137 return $this->harborInstance;
140 // Setter fuer Reederei-Instanz
141 public final function setCompanyInstance (ShippingCompany $companyInstance) {
142 $this->shippingCompany = $companyInstance;
145 // Getter fuer Reederei-Instanz
146 public final function getCompanyInstance () {
147 return $this->shippingCompany;
151 public function addNewPersonell ($personell) {
153 $this->staffList->append($personell);
156 // Add a new ship type to our list
157 public function addNewConstructableShipType ($shipType) {
158 // This must be a string!
159 $shipType = (string) $shipType;
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.",
165 $this->getShipyardName(),
170 $this->shipTypeList->append($shipType);
173 // Is the specified ship type in our list?
174 public function isShipTypeConstructable ($shipType) {
175 // First we can't build this ship
178 // This must be a string!
179 $shipType = (string) $shipType;
182 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Werft <strong>%s</strong> prüft, ob Schiffe vom Typ <strong>%s</strong> baubar sind.",
185 $this->getShipyardName(),
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();
195 $result = ($type == $shipType);
198 if ($result) break; // Then abort the search!
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.",
205 $this->getShipyardName(),