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->generateUniqueId();
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.",
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.",
113 // Instanz zurueckliefern
114 return $shipyardInstance;
118 private function createStaffList () {
119 $this->staffList = new FrameworkArrayObject("FakedStaffList");
122 // Create ship type list
123 private function createShipTypeList () {
124 $this->shipTypeList = new FrameworkArrayObject("FakedShipTypeList");
127 // Setter-Methode fuer Werft-Name
128 public final function setShipyardName ($shipyardName) {
129 $this->shipyardName = (string) $shipyardName;
132 // Getter-Methode fuer Werft-Name
133 public final function getShipyardName () {
134 return $this->shipyardName;
137 // Setter-Methode fuer Hafen-Instanz
138 public final function setHarborInstance (Harbor $harborInstance) {
139 $this->harborInstance = $harborInstance;
142 // Getter-Methode fuer Hafen-Instanz
143 public final function getHarborInstance () {
144 return $this->harborInstance;
147 // Setter fuer Reederei-Instanz
148 public final function setCompanyInstance (ShippingCompany $companyInstance) {
149 $this->shippingCompany = $companyInstance;
152 // Getter fuer Reederei-Instanz
153 public final function getCompanyInstance () {
154 return $this->shippingCompany;
158 public function addNewPersonell ($personell) {
160 $this->staffList->append($personell);
163 // Add a new ship type to our list
164 public function addNewConstructableShipType ($shipType) {
165 // This must be a string!
166 $shipType = (string) $shipType;
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.",
172 $this->getShipyardName(),
177 $this->shipTypeList->append($shipType);
180 // Is the specified ship type in our list?
181 public function isShipTypeConstructable ($shipType) {
182 // First we can't build this ship
185 // This must be a string!
186 $shipType = (string) $shipType;
189 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.",
192 $this->getShipyardName(),
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();
202 $result = ($type == $shipType);
205 if ($result) break; // Then abort the search!
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.",
212 $this->getShipyardName(),