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 if (((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
54 $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
61 $this->setObjectDescription("Werft");
63 // Staff-Liste/Schiffstyp-Liste erzeugen
64 $this->createStaffList();
65 $this->createShipTypeList();
67 // Generate unique ID number
68 $this->createUniqueID();
71 // Create a shipyard and notify it about it's owner
72 public final static function createShipyardNotify (Harbor $harborInstance, $shipyardName, ShippingCompany $companyInstance) {
73 // Werft-Instanz holen
74 $shipyardInstance = self::createShipyard($harborInstance, $shipyardName);
76 // Reederei der Werft zuweisen
77 $shipyardInstance->setCompanyInstance($companyInstance);
79 // Die Reederei ueber ihre Werft informieren
80 $companyInstance->addNewShipyard($shipyardInstance);
82 // Instanz zurueckgeben
83 return $shipyardInstance;
86 // Create a shipyard, first we need to create a harbor
87 public final static function createShipyard (Harbor $harborInstance, $shipyardName) {
88 // Instanz temporaer holen
89 $shipyardInstance = new Shipyard();
92 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",
96 $harborInstance->getHarborName()
100 $shipyardInstance->setShipyardName($shipyardName);
102 // Hafen-Instanz setzen
103 $shipyardInstance->setHarborInstance($harborInstance);
105 // Abmasse setzen in Meter
106 $shipyardInstance->setWidth(30);
107 $shipyardInstance->setHeight(30);
108 $shipyardInstance->setLength(100);
111 $shipyardInstance->removeDraught();
112 $shipyardInstance->removeSystemArray();
115 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.<br />\n",
121 // Instanz zurueckliefern
122 return $shipyardInstance;
126 private function createStaffList () {
127 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erhält eine Arbeiterliste.<br />\n",
130 $this->getShipyardName()
132 $this->staffList = new FrameworkArrayObject();
135 // Create ship type list
136 private function createShipTypeList () {
137 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erhält eine Typenliste.<br />\n",
140 $this->getShipyardName()
142 $this->shipTypeList = new FrameworkArrayObject();
145 // Setter-Methode fuer Werft-Name
146 public final function setShipyardName ($shipyardName) {
147 $this->shipyardName = (string) $shipyardName;
150 // Getter-Methode fuer Werft-Name
151 public final function getShipyardName () {
152 return $this->shipyardName;
155 // Setter-Methode fuer Hafen-Instanz
156 public final function setHarborInstance (Harbor $harborInstance) {
157 $this->harborInstance = $harborInstance;
160 // Getter-Methode fuer Hafen-Instanz
161 public final function getHarborInstance () {
162 return $this->harborInstance;
165 // Setter fuer Reederei-Instanz
166 public final function setCompanyInstance (ShippingCompany $companyInstance) {
167 $this->shippingCompany = $companyInstance;
170 // Getter fuer Reederei-Instanz
171 public final function getCompanyInstance () {
172 return $this->shippingCompany;
176 public function addNewPersonell ($personell) {
177 if (is_null($this->staffList)) {
178 // Opps, not initialized!
179 ApplicationEntryPoint::app_die("New personell: <pre>".print_r($this, true)."</pre>");
183 $this->staffList->append($personell);
186 // Add a new ship type to our list
187 public function addNewConstructableShipType ($shipType) {
188 // This must be a string!
189 $shipType = (string) $shipType;
192 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",
195 $this->getShipyardName(),
200 $this->shipTypeList->append($shipType);
203 // Is the specified ship type in our list?
204 public function isShipTypeConstructable ($shipType) {
205 // First we can't build this ship
208 // This must be a string!
209 $shipType = (string) $shipType;
212 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",
215 $this->getShipyardName(),
219 // Iterate through all types
220 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
221 // Get current ship type
222 $type = (string) $idx->current();
225 $result = ($type == $shipType);
228 if ($result) break; // Then abort the search!
232 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",
235 $this->getShipyardName(),
246 public function saveObjectToDatabase () {
247 $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
254 * Limits this object with an ObjectLimits instance
256 public function limitObject (ObjectLimits $limitInstance) {
257 ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");