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 final static 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 final static 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();
98 $shipyardInstance->removeSystemArray();
101 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->debugOutput(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.",
107 // Instanz zurueckliefern
108 return $shipyardInstance;
112 private function createStaffList () {
113 $this->staffList = new FrameworkArrayObject("FakedStaffList");
116 // Create ship type list
117 private function createShipTypeList () {
118 $this->shipTypeList = new FrameworkArrayObject("FakedShipTypeList");
121 // Setter-Methode fuer Werft-Name
122 public final function setShipyardName ($shipyardName) {
123 $this->shipyardName = (string) $shipyardName;
126 // Getter-Methode fuer Werft-Name
127 public final function getShipyardName () {
128 return $this->shipyardName;
131 // Setter-Methode fuer Hafen-Instanz
132 public final function setHarborInstance (Harbor $harborInstance) {
133 $this->harborInstance = $harborInstance;
136 // Getter-Methode fuer Hafen-Instanz
137 public final function getHarborInstance () {
138 return $this->harborInstance;
141 // Setter fuer Reederei-Instanz
142 public final function setCompanyInstance (ShippingCompany $companyInstance) {
143 $this->shippingCompany = $companyInstance;
146 // Getter fuer Reederei-Instanz
147 public final function getCompanyInstance () {
148 return $this->shippingCompany;
152 public function addNewPersonell ($personell) {
154 $this->staffList->append($personell);
157 // Add a new ship type to our list
158 public function addNewConstructableShipType ($shipType) {
159 // This must be a string!
160 $shipType = (string) $shipType;
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.",
166 $this->getShipyardName(),
171 $this->shipTypeList->append($shipType);
174 // Is the specified ship type in our list?
175 public function isShipTypeConstructable ($shipType) {
176 // First we can't build this ship
179 // This must be a string!
180 $shipType = (string) $shipType;
183 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.",
186 $this->getShipyardName(),
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();
196 $result = ($type == $shipType);
199 if ($result) break; // Then abort the search!
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.",
206 $this->getShipyardName(),