]> git.mxchange.org Git - shipsimu.git/blobdiff - ship-simu/application/ship-simu/main/constructions/yards/class_Shipyard.php
Initial import of current development status
[shipsimu.git] / ship-simu / application / ship-simu / main / constructions / yards / class_Shipyard.php
diff --git a/ship-simu/application/ship-simu/main/constructions/yards/class_Shipyard.php b/ship-simu/application/ship-simu/main/constructions/yards/class_Shipyard.php
new file mode 100644 (file)
index 0000000..9d555dd
--- /dev/null
@@ -0,0 +1,241 @@
+<?php
+
+// Die Werft-Klasse
+class Shipyard extends BaseConstruction {
+       // Werft-Name
+       private $shipyardName    = "Namenlose Werft";
+
+       // Arbeiter-Liste
+       private $staffList       = null;
+
+       // Queue-Liste fuer zu bauende Schiffe
+       private $queueList       = null;
+
+       // Aktuell im Bau befindliches Schiff
+       private $currShipInConst = null;
+
+       // Liste konstruierbarer Schiffstypen
+       private $shipTypeList = null;
+
+       // Zugewiesener Hafen
+       private $harborInstance = null;
+
+       // Zugewiesene Reederei
+       private $shippingCompany = null;
+
+       // Constructor
+       private function __construct () {
+               // Eltern-Konstruktor aufrufen
+               parent::constructor(__CLASS__);
+
+               // Debug message
+               if (((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
+                       $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
+                               __CLASS__,
+                               __LINE__
+                       ));
+               }
+
+               // Beschreibung setzen
+               $this->setPartDescr("Werft");
+
+               // Staff-Liste/Schiffstyp-Liste erzeugen
+               $this->createStaffList();
+               $this->createShipTypeList();
+
+               // Unique-ID erzeugen
+               $this->createUniqueID();
+       }
+
+       // Create a shipyard and notify it about it's owner
+       public static function createShipyardNotify (Harbor $harborInstance, $shipyardName, ShippingCompany $companyInstance) {
+               // Werft-Instanz holen
+               $shipyardInstance = self::createShipyard($harborInstance, $shipyardName);
+
+               // Reederei der Werft zuweisen
+               $shipyardInstance->setCompanyInstance($companyInstance);
+
+               // Die Reederei ueber ihre Werft informieren
+               $companyInstance->addNewShipyard($shipyardInstance);
+
+               // Instanz zurueckgeben
+               return $shipyardInstance;
+       }
+
+       // Create a shipyard, first we need to create a harbor
+       public final static function createShipyard (Harbor $harborInstance, $shipyardName) {
+               // Instanz temporaer holen
+               $shipyardInstance = new Shipyard();
+
+               // Debug message
+               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",
+                       __CLASS__,
+                       __LINE__,
+                       $shipyardName,
+                       $harborInstance->getHarborName()
+               ));
+
+               // Werft-Name setzen
+               $shipyardInstance->setShipyardName($shipyardName);
+
+               // Hafen-Instanz setzen
+               $shipyardInstance->setHarborInstance($harborInstance);
+
+               // Abmasse setzen in Meter
+               $shipyardInstance->setWidth(30);
+               $shipyardInstance->setHeight(30);
+               $shipyardInstance->setLength(100);
+
+               // Etwas aufraeumen
+               $shipyardInstance->removeDraught();
+               $shipyardInstance->removeSystemArray();
+
+               // Debug-Meldung
+               if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.<br />\n",
+                       __CLASS__,
+                       __LINE__,
+                       $shipyardName
+               ));
+
+               // Instanz zurueckliefern
+               return $shipyardInstance;
+       }
+
+       // Create staff list
+       private function createStaffList () {
+               if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erh&auml;lt eine Arbeiterliste.<br />\n",
+                       __CLASS__,
+                       __LINE__,
+                       $this->getShipyardName()
+               ));
+               $this->staffList = new FrameworkArrayObject();
+       }
+
+       // Create ship type list
+       private function createShipTypeList () {
+               if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erh&auml;lt eine Typenliste.<br />\n",
+                       __CLASS__,
+                       __LINE__,
+                       $this->getShipyardName()
+               ));
+               $this->shipTypeList = new FrameworkArrayObject();
+       }
+
+       // Setter-Methode fuer Werft-Name
+       public function setShipyardName ($shipyardName) {
+               $this->shipyardName = (string) $shipyardName;
+       }
+
+       // Getter-Methode fuer Werft-Name
+       public function getShipyardName () {
+               return $this->shipyardName;
+       }
+
+       // Setter-Methode fuer Hafen-Instanz
+       public function setHarborInstance (Harbor $harborInstance) {
+               $this->harborInstance = $harborInstance;
+       }
+
+       // Getter-Methode fuer Hafen-Instanz
+       public function getHarborInstance () {
+               return $this->harborInstance;
+       }
+
+       // Setter fuer Reederei-Instanz
+       public function setCompanyInstance (ShippingCompany $companyInstance) {
+               $this->shippingCompany = $companyInstance;
+       }
+
+       // Getter fuer Reederei-Instanz
+       public function getCompanyInstance () {
+               return $this->shippingCompany;
+       }
+
+       // Add new personell
+       public function addNewPersonell ($personell) {
+               if (is_null($this->staffList)) {
+                       // Opps, not initialized!
+                       ApplicationEntryPoint::app_die("New personell: <pre>".print_r($this, true)."</pre>");
+               }
+
+               // Add to list
+               $this->staffList->append($personell);
+       }
+
+       // Add a new ship type to our list
+       public function addNewConstructableShipType ($shipType) {
+               // This must be a string!
+               $shipType = (string) $shipType;
+
+               // Debug message
+               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",
+                       __CLASS__,
+                       __LINE__,
+                       $this->getShipyardName(),
+                       $shipType
+               ));
+
+               // Add to list
+               $this->shipTypeList->append($shipType);
+       }
+
+       // Is the specified ship type in our list?
+       public function isShipTypeConstructable ($shipType) {
+               // First we can't build this ship
+               $result = false;
+
+               // This must be a string!
+               $shipType = (string) $shipType;
+
+               // Debug message
+               if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> pr&uuml;ft, ob Schiffe vom Typ <strong>%s</strong> baubar sind.<br />\n",
+                       __CLASS__,
+                       __LINE__,
+                       $this->getShipyardName(),
+                       $shipType
+               ));
+
+               // Iterate through all types
+               for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
+                       // Get current ship type
+                       $type = (string) $idx->current();
+
+                       // Is both the same?
+                       $result = ($type == $shipType);
+
+                       // Type is found?
+                       if ($result) break; // Then abort the search!
+               }
+
+               // Debug message
+               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",
+                       __CLASS__,
+                       __LINE__,
+                       $this->getShipyardName(),
+                       $shipType
+               ));
+
+               // Return result
+               return $result;
+       }
+
+       /**
+        * Stub!
+        */
+       public function saveObjectToDatabase () {
+               $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
+                       $this->__toString(),
+                       __FUNCTION__
+               ));
+       }
+
+       /**
+        * Limits this object with an ObjectLimits instance
+        */
+       public function limitObject (ObjectLimits $limitInstance) {
+               ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");
+       }
+}
+
+// [EOF]
+?>