* @version 0.0.0
* @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
class BaseShip extends BaseSimulator {
// Name des Shipes
private $shipName = "Unbekanntes Schiff";
// Anzahl Anker
private $numAnchor = 0;
// Tiefgang in Meter
private $draught = 0;
// Besatzung-Objekte
private $crewList = null;
// Aufbauten-Objekte
private $structures = null;
// Namenloses Ship generieren
protected function __construct($className) {
// Call parent constructor
parent::__construct($className);
// Prepare array object for all structures
$this->createStructuresArray();
// Clean-up a little
$this->removePartInstance();
}
// Array-Objekt anlegen
private function createStructuresArray () {
$this->structures = new FrameworkArrayObject("FakedShipStructures");
}
// Schiffsteil generieren (kann alles sein)
// buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
// partClass = Das zu konstruierende Schiffsteil
public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s erhält ein neues Schiffsteil (%s).",
__CLASS__,
__LINE__,
$this->getShipName(),
$partClass
));
// Ist die gewuenschte Klasse vorhanden?
if (!class_exists($partClass)) {
// Nicht vorhanden, dann Ausnahme werfen!
throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND);
} // END - if
// Get an instance back from our object factory
$partInstance = ObjectFactory::createObjectByName($partClass);
// Das Einbauen versuchen...
try {
$partInstance->addShipPartToShip($this, $buildInstance);
} catch (MotorShipMismatchException $e) {
if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keinen Motor erhalten! Grund: %s",
__CLASS__,
__LINE__,
$this->getShipName(),
$e->getMessage()
));
return false;
} catch (RoomShipMismatchException $e) {
if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keinen Maschinenraum erhalten! Grund: %s",
__CLASS__,
__LINE__,
$this->getShipName(),
$e->getMessage()
));
return false;
} catch (StructureShipMismatchException $e) {
if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keine Aufbauten erhalten! Grund: %s",
__CLASS__,
__LINE__,
$this->getShipName(),
$e->getMessage()
));
return false;
} catch (CabinShipMismatchException $e) {
if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keine Kabine erhalten! Grund: %s",
__CLASS__,
__LINE__,
$this->getShipName(),
$e->getMessage()
));
return false;
} catch (DeckShipMismatchException $e) {
if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat kein Deck erhalten! Grund: %s",
__CLASS__,
__LINE__,
$this->getShipName(),
$e->getMessage()
));
return false;
}
// Instanz im Aufbauten-Array vermerken
$this->structures->append($partInstance);
// Alles klar!
return true;
}
// Getter-Methode fuer Strukturen-Array
public final function getStructuresArray () {
return $this->structures;
}
// STUB: Getter-Methode Anzahl Betten
public function calcTotalBeds () {
$this->partialStub("Please implement this stub in your ship!");
}
// Setter-Methode fuer Schiffsnamen
public final function setShipName ($shipName) {
$this->shipName = (string) $shipName;
}
// Getter-Methode fuer Schiffsnamen
public final function getShipName () {
return $this->shipName;
}
// Setter-Methode fuer Tiefgang
public final function setDraught ($draught) {
$this->draught = (int) $draught;
}
// Getter-Methode fuer Tiefgang
public final function getDraught() {
return $this->draught;
}
// Setter-Methode fuer Anzahl Anker
public final function setNumAnchor ($numAnchor) {
$this->numAnchor = (int) $numAnchor;
}
}
// [EOF]
?>