+++ /dev/null
-<?php
-/**
- * The general simulator class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 <http://www.gnu.org/licenses/>.
- */
-class BaseSimulator extends BaseFrameworkSystem {
- // Schiffsteilinstanz
- private $partInstance = null;
-
- // Abmasse (Breite/Hoehe/Laenge)
- private $width = 0;
- private $height = 0;
- private $length = 0;
-
- // Aktuelles Schiff und Schiffsteil
- private $currShip = null;
- private $currPart = null;
-
- // Faktoren zur Erweiterung der Masse. Beispielsweise soll der Maschinenraum groesser wie der Motor sein
- private $resizeFactorArray = array(
- 'width' => 1,
- 'height' => 1,
- 'length' => 1
- );
-
- // Konstruktor
- protected function __construct ($className) {
- // Call highest constructor
- parent::__construct($className);
-
- // Clean up a little, dies sollte ganz zum Schluss erfolgen!
- $this->removeResizeFactorArray();
- $this->removeCurrPart();
- $this->removeCurrShip();
- }
-
- // Setter-Methode fuer Laenge
- public final function setLength ($length) {
- $this->length = (float) $length;
- }
-
- // Setter-Methode fuer Breite
- public final function setWidth ($width) {
- $this->width = (float) $width;
- }
-
- // Setter-Methode fuer Hoehe
- public final function setHeight ($height) {
- $this->height = (float) $height;
- }
-
- // Getter-Methode fuer Laenge
- public final function getLength () {
- return $this->length;
- }
-
- // Getter-Methode fuer Breite
- public final function getWidth () {
- return $this->width;
- }
-
- // Getter-Methode fuer Hoehe
- public final function getHeight () {
- return $this->height;
- }
-
- // Setter-Methode fuer Teil-Instanz
- public final function setPartInstance (ConstructableShipPart $partInstance) {
- $this->partInstance = $partInstance;
- }
-
- // Getter-Methode fuer Teil-Instanz
- public final function getPartInstance () {
- if (!isset($this->partInstance)) {
- return null;
- }
- return $this->partInstance;
- }
-
- // Remover-Methode fuer die Teil-Instanz
- public final function removePartInstance () {
- unset($this->partInstance);
- }
-
- // Prueft ob all Umberechnungsfaktoren gesetzt sind
- private function isResizeFactorValid () {
- return (($this->getResizeFactorElement('width') > 1)
- || ($this->getResizeFactorElement('height') > 1)
- || ($this->getResizeFactorElement('length') > 1)
- );
- }
-
- // Baut einen Motor in das Schiff ein
- public function addShipPartToShip (ConstructableShip $shipInstance, ConstructableShipPart $partInstance) {
- // Schiff/-steil merken
- $this->currShip = $shipInstance;
- $this->currPart = $partInstance;
-
- // Passt ueberhaupt das Schiffsteil in's Schiff?
- if ($this->isShipPartSizeValid()) {
- // Muessen die Masse angepasst werden?
- if ($this->isResizeFactorValid()) {
- // Neue Angaben berechnen (wir lassen etwas Lust fuer Kabelbaeume, Roehren, Maschinisten, etc.)
- $this->newWidth = (float) $this->getCurrPart()->getWidth() * $this->resizeFactorArray['width'];
- $this->newHeight = (float) $this->getCurrPart()->getHeight() * $this->resizeFactorArray['height'];
- $this->newLength = (float) $this->getCurrPart()->getLength() * $this->resizeFactorArray['length'];
-
- // Passt dies nun immer noch?
- if ($this->isNewSizeValid()) {
- // Das passt auch, dann Werte setzen und Motor-Instanz merken
- $this->setWidth($this->newWidth);
- $this->setHeight($this->newHeight);
- $this->setLength($this->newLength);
-
- // Einige Dinge entfernen...
- $this->removeAllNewAttr();
- } else {
- // Passt nicht! Also wieder Exception werfen...
- throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <strong>%s</strong> vom Typ <strong>%s</strong> ist zu gross für das Schiff!",
- $this->getCurrPart()->__toString(),
- $this->getCurrPart()->getObjectDescription(),
- $this->getCurrPart()->__toString()
- ), 2);
- }
- } elseif ($this->currPart != null) {
- // Aktuelle Masse setzen
- $this->setWidth($this->getCurrPart()->getWidth());
- $this->setHeight($this->getCurrPart()->getHeight());
- $this->setLength($this->getCurrPart()->getLength());
- }
-
- // Existiert ein Schiffsteil?
- if (!is_null($this->currPart)) {
- // Schiffsteil-Instanz setzen
- $this->setPartInstance($this->currPart);
-
- // Instanzen entfernen
- $this->getCurrPart()->removeCurrShip();
- $this->getCurrPart()->removeCurrPart();
- $this->getCurrPart()->removePartInstance();
- $this->getCurrPart()->removeResizeFactorArray();
- }
- } else {
- // Exception werfen!
- throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <u>%s</u> vom Typ <u>%s</u> passt nicht in das Schiff!",
- $this->getCurrPart()->realClass,
- $this->getCurrPart()->getObjectDescription(),
- $this->getCurrPart()->__toString()
- ), 1);
- }
-
- // Nochmals Clean up a little
- $this->removeResizeFactorArray();
- $this->removeCurrShip();
- $this->removeCurrPart();
- }
-
- // Array fuer Umrechnungstabelle entfernen
- public final function removeResizeFactorArray () {
- unset($this->resizeFactorArray);
- }
-
- /**
- * Remove all new*** attributes
- *
- * @return void
- */
- public final function removeAllNewAttr () {
- unset($this->newWidth);
- unset($this->newHeight);
- unset($this->newLength);
- }
-
- /**
- * Remove current ship instance
- *
- * @return void
- */
- public final function removeCurrShip () {
- unset($this->currShip);
- }
-
- // Aktuelle Schiffsteil-Instanz entfernen
- public final function removeCurrPart () {
- unset($this->currPart);
- }
-
- // Breite entfernen
- public final function removeWidth () {
- unset($this->width);
- }
-
- // Hoehe entfernen
- public final function removeHeight () {
- unset($this->height);
- }
-
- // Laenge entfernen
- public final function removeLength () {
- unset($this->length);
- }
-
- // Tiefgang entfernen
- public final function removeDraught () {
- unset($this->draught);
- }
-
- // Getter-Methode fuer Element aus resizeFactor
- public final function getResizeFactorElement ($el) {
- if (isset($this->resizeFactorArray[$el])) {
- // Element gefunden
- return $this->resizeFactorArray[$el];
- } else {
- // Element nicht gefunden!
- return null;
- }
- }
-
- // Setter-Methode fuer Element in resizeFactor
- public final function setResizeFactorElement ($el, $value) {
- $this->resizeFactorArray[$el] = (float) $value;
- }
-
- // Kontrolliert, ob die Abmasse Schiffsteil->Schiff stimmen
- public function isShipPartSizeValid () {
- return (
- (
- ( // Already defined ship messurings
- ($this->getCurrPart()->getWidth() < $this->currShip->getWidth())
- && ($this->getCurrPart()->getHeight() < $this->currShip->getDraught())
- && ($this->getCurrPart()->getLength() < $this->currShip->getLength())
- ) || ( // Ship messurings shall be calculated
- ($this->currShip->getWidth() == 0)
- && ($this->currShip->getHeight() == 0)
- && ($this->currShip->getLength() == 0)
- )
- // The inserted part must be messured!
- ) && ($this->getCurrPart()->getWidth() > 0)
- && ($this->getCurrPart()->getHeight() > 0)
- && ($this->getCurrPart()->getLength() > 0)
- );
- }
-
- // Kontrolliert, ob die Abmasse Maschinenraum->Schiff stimmen
- public function isNewSizeValid () {
- return (
- ( // Already defined ship messurings
- ($this->newWidth < $this->currShip->getWidth())
- && ($this->newHeight < $this->currShip->getDraught())
- && ($this->newLength < $this->currShip->getLength())
- ) || ( // Ship messurings shall be calculated
- ($this->currShip->getWidth() == 0)
- && ($this->currShip->getHeight() == 0)
- && ($this->currShip->getLength() == 0)
- )
- );
- }
-
- // Masse extrahieren
- public function extractDimensions ($dim) {
- // Abmasse setzen
- if ((isset($dim)) && (is_array($dim)) && (count($dim) == 3)) {
- // Abmasse aus Array holen
- $this->setWidth($dim[0]);
- $this->setHeight($dim[1]);
- $this->setLength($dim[2]);
- } else {
- // Nicht gefundene Abmasse!
- throw new DimNotFoundInArrayException($this, self::EXCEPTION_DIMENSION_ARRAY_INVALID);
- }
- }
-
- /**
- * Getter for current part instance
- *
- * @return $currPart Instance of the current ship part object
- */
- public final function getCurrPart () {
- return $this->currPart;
- }
-}
-
-// [EOF]
-?>