4 class Shipyard extends BaseConstruction {
6 private $shipyardName = "Namenlose Werft";
9 private $staffList = null;
11 // Queue-Liste fuer zu bauende Schiffe
12 private $queueList = null;
14 // Aktuell im Bau befindliches Schiff
15 private $currShipInConst = null;
17 // Liste konstruierbarer Schiffstypen
18 private $shipTypeList = null;
21 private $harborInstance = null;
23 // Zugewiesene Reederei
24 private $shippingCompany = null;
27 private function __construct () {
28 // Call parent constructor
29 parent::constructor(__CLASS__);
32 if (((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
33 $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
40 $this->setPartDescr("Werft");
42 // Staff-Liste/Schiffstyp-Liste erzeugen
43 $this->createStaffList();
44 $this->createShipTypeList();
46 // Generate unique ID number
47 $this->createUniqueID();
50 // Create a shipyard and notify it about it's owner
51 public static function createShipyardNotify (Harbor $harborInstance, $shipyardName, ShippingCompany $companyInstance) {
52 // Werft-Instanz holen
53 $shipyardInstance = self::createShipyard($harborInstance, $shipyardName);
55 // Reederei der Werft zuweisen
56 $shipyardInstance->setCompanyInstance($companyInstance);
58 // Die Reederei ueber ihre Werft informieren
59 $companyInstance->addNewShipyard($shipyardInstance);
61 // Instanz zurueckgeben
62 return $shipyardInstance;
65 // Create a shipyard, first we need to create a harbor
66 public final static function createShipyard (Harbor $harborInstance, $shipyardName) {
67 // Instanz temporaer holen
68 $shipyardInstance = new Shipyard();
71 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",
75 $harborInstance->getHarborName()
79 $shipyardInstance->setShipyardName($shipyardName);
81 // Hafen-Instanz setzen
82 $shipyardInstance->setHarborInstance($harborInstance);
84 // Abmasse setzen in Meter
85 $shipyardInstance->setWidth(30);
86 $shipyardInstance->setHeight(30);
87 $shipyardInstance->setLength(100);
90 $shipyardInstance->removeDraught();
91 $shipyardInstance->removeSystemArray();
94 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.<br />\n",
100 // Instanz zurueckliefern
101 return $shipyardInstance;
105 private function createStaffList () {
106 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erhält eine Arbeiterliste.<br />\n",
109 $this->getShipyardName()
111 $this->staffList = new FrameworkArrayObject();
114 // Create ship type list
115 private function createShipTypeList () {
116 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erhält eine Typenliste.<br />\n",
119 $this->getShipyardName()
121 $this->shipTypeList = new FrameworkArrayObject();
124 // Setter-Methode fuer Werft-Name
125 public function setShipyardName ($shipyardName) {
126 $this->shipyardName = (string) $shipyardName;
129 // Getter-Methode fuer Werft-Name
130 public function getShipyardName () {
131 return $this->shipyardName;
134 // Setter-Methode fuer Hafen-Instanz
135 public function setHarborInstance (Harbor $harborInstance) {
136 $this->harborInstance = $harborInstance;
139 // Getter-Methode fuer Hafen-Instanz
140 public function getHarborInstance () {
141 return $this->harborInstance;
144 // Setter fuer Reederei-Instanz
145 public function setCompanyInstance (ShippingCompany $companyInstance) {
146 $this->shippingCompany = $companyInstance;
149 // Getter fuer Reederei-Instanz
150 public function getCompanyInstance () {
151 return $this->shippingCompany;
155 public function addNewPersonell ($personell) {
156 if (is_null($this->staffList)) {
157 // Opps, not initialized!
158 ApplicationEntryPoint::app_die("New personell: <pre>".print_r($this, true)."</pre>");
162 $this->staffList->append($personell);
165 // Add a new ship type to our list
166 public function addNewConstructableShipType ($shipType) {
167 // This must be a string!
168 $shipType = (string) $shipType;
171 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",
174 $this->getShipyardName(),
179 $this->shipTypeList->append($shipType);
182 // Is the specified ship type in our list?
183 public function isShipTypeConstructable ($shipType) {
184 // First we can't build this ship
187 // This must be a string!
188 $shipType = (string) $shipType;
191 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",
194 $this->getShipyardName(),
198 // Iterate through all types
199 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
200 // Get current ship type
201 $type = (string) $idx->current();
204 $result = ($type == $shipType);
207 if ($result) break; // Then abort the search!
211 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",
214 $this->getShipyardName(),
225 public function saveObjectToDatabase () {
226 $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
233 * Limits this object with an ObjectLimits instance
235 public function limitObject (ObjectLimits $limitInstance) {
236 ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");