class_BaseSimulator.php
Go to the documentation of this file.00001 <?php
00024 class BaseSimulator extends BaseFrameworkSystem {
00025
00026 private $partInstance = null;
00027
00028
00029 private $width = 0;
00030 private $height = 0;
00031 private $length = 0;
00032
00033
00034 private $currShip = null;
00035 private $currPart = null;
00036
00037
00038 private $resizeFactorArray = array(
00039 'width' => 1,
00040 'height' => 1,
00041 'length' => 1
00042 );
00043
00044
00045 protected function __construct ($className) {
00046
00047 parent::__construct($className);
00048
00049
00050 $this->removeSystemArray();
00051 $this->removeNumberFormaters();
00052 $this->removeResizeFactorArray();
00053 $this->removeCurrPart();
00054 $this->removeCurrShip();
00055 }
00056
00057
00058 public final function setLength ($length) {
00059 $this->length = (float) $length;
00060 }
00061
00062
00063 public final function setWidth ($width) {
00064 $this->width = (float) $width;
00065 }
00066
00067
00068 public final function setHeight ($height) {
00069 $this->height = (float) $height;
00070 }
00071
00072
00073 public final function getLength () {
00074 return $this->length;
00075 }
00076
00077
00078 public final function getWidth () {
00079 return $this->width;
00080 }
00081
00082
00083 public final function getHeight () {
00084 return $this->height;
00085 }
00086
00087
00088 public final function setPartInstance (ConstructableShipPart $partInstance) {
00089 $this->partInstance = $partInstance;
00090 }
00091
00092
00093 public final function getPartInstance () {
00094 if (!isset($this->partInstance)) {
00095 return null;
00096 }
00097 return $this->partInstance;
00098 }
00099
00100
00101 public final function removePartInstance () {
00102 unset($this->partInstance);
00103 }
00104
00105
00106 private function isResizeFactorValid () {
00107 return (($this->getResizeFactorElement('width') > 1)
00108 || ($this->getResizeFactorElement('height') > 1)
00109 || ($this->getResizeFactorElement('length') > 1)
00110 );
00111 }
00112
00113
00114 public function addShipPartToShip (ConstructableShip $shipInstance, ConstructableShipPart $partInstance) {
00115
00116 $this->currShip = $shipInstance;
00117 $this->currPart = $partInstance;
00118
00119
00120 if ($this->isShipPartSizeValid()) {
00121
00122 if ($this->isResizeFactorValid()) {
00123
00124 $this->newWidth = (float) $this->getCurrPart()->getWidth() * $this->resizeFactorArray['width'];
00125 $this->newHeight = (float) $this->getCurrPart()->getHeight() * $this->resizeFactorArray['height'];
00126 $this->newLength = (float) $this->getCurrPart()->getLength() * $this->resizeFactorArray['length'];
00127
00128
00129 if ($this->isNewSizeValid()) {
00130
00131 $this->setWidth($this->newWidth);
00132 $this->setHeight($this->newHeight);
00133 $this->setLength($this->newLength);
00134
00135
00136 $this->removeAllNewAttr();
00137 } else {
00138
00139 throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <strong>%s</strong> vom Typ <strong>%s</strong> ist zu gross für das Schiff!",
00140 $this->getCurrPart()->__toString(),
00141 $this->getCurrPart()->getObjectDescription(),
00142 $this->getCurrPart()->__toString()
00143 ), 2);
00144 }
00145 } elseif ($this->currPart != null) {
00146
00147 $this->setWidth($this->getCurrPart()->getWidth());
00148 $this->setHeight($this->getCurrPart()->getHeight());
00149 $this->setLength($this->getCurrPart()->getLength());
00150 }
00151
00152
00153 if (!is_null($this->currPart)) {
00154
00155 $this->setPartInstance($this->currPart);
00156
00157
00158 $this->getCurrPart()->removeCurrShip();
00159 $this->getCurrPart()->removeCurrPart();
00160 $this->getCurrPart()->removePartInstance();
00161 $this->getCurrPart()->removeResizeFactorArray();
00162 }
00163 } else {
00164
00165 throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <u>%s</u> vom Typ <u>%s</u> passt nicht in das Schiff!",
00166 $this->getCurrPart()->realClass,
00167 $this->getCurrPart()->getObjectDescription(),
00168 $this->getCurrPart()->__toString()
00169 ), 1);
00170 }
00171
00172
00173 $this->removeResizeFactorArray();
00174 $this->removeCurrShip();
00175 $this->removeCurrPart();
00176 }
00177
00178
00179 public final function removeResizeFactorArray () {
00180 unset($this->resizeFactorArray);
00181 }
00182
00188 public final function removeAllNewAttr () {
00189 unset($this->newWidth);
00190 unset($this->newHeight);
00191 unset($this->newLength);
00192 }
00193
00199 public final function removeCurrShip () {
00200 unset($this->currShip);
00201 }
00202
00203
00204 public final function removeCurrPart () {
00205 unset($this->currPart);
00206 }
00207
00208
00209 public final function removeWidth () {
00210 unset($this->width);
00211 }
00212
00213
00214 public final function removeHeight () {
00215 unset($this->height);
00216 }
00217
00218
00219 public final function removeLength () {
00220 unset($this->length);
00221 }
00222
00223
00224 public final function removeDraught () {
00225 unset($this->draught);
00226 }
00227
00228
00229 public final function getResizeFactorElement ($el) {
00230 if (isset($this->resizeFactorArray[$el])) {
00231
00232 return $this->resizeFactorArray[$el];
00233 } else {
00234
00235 return null;
00236 }
00237 }
00238
00239
00240 public final function setResizeFactorElement ($el, $value) {
00241 $this->resizeFactorArray[$el] = (float) $value;
00242 }
00243
00244
00245 public function isShipPartSizeValid () {
00246 return (
00247 (
00248 (
00249 ($this->getCurrPart()->getWidth() < $this->currShip->getWidth())
00250 && ($this->getCurrPart()->getHeight() < $this->currShip->getDraught())
00251 && ($this->getCurrPart()->getLength() < $this->currShip->getLength())
00252 ) || (
00253 ($this->currShip->getWidth() == 0)
00254 && ($this->currShip->getHeight() == 0)
00255 && ($this->currShip->getLength() == 0)
00256 )
00257
00258 ) && ($this->getCurrPart()->getWidth() > 0)
00259 && ($this->getCurrPart()->getHeight() > 0)
00260 && ($this->getCurrPart()->getLength() > 0)
00261 );
00262 }
00263
00264
00265 public function isNewSizeValid () {
00266 return (
00267 (
00268 ($this->newWidth < $this->currShip->getWidth())
00269 && ($this->newHeight < $this->currShip->getDraught())
00270 && ($this->newLength < $this->currShip->getLength())
00271 ) || (
00272 ($this->currShip->getWidth() == 0)
00273 && ($this->currShip->getHeight() == 0)
00274 && ($this->currShip->getLength() == 0)
00275 )
00276 );
00277 }
00278
00279
00280 public function extractDimensions ($dim) {
00281
00282 if ((isset($dim)) && (is_array($dim)) && (count($dim) == 3)) {
00283
00284 $this->setWidth($dim[0]);
00285 $this->setHeight($dim[1]);
00286 $this->setLength($dim[2]);
00287 } else {
00288
00289 throw new DimNotFoundInArrayException($this, self::EXCEPTION_DIMENSION_ARRAY_INVALID);
00290 }
00291 }
00292
00298 public final function getCurrPart () {
00299 return $this->currPart;
00300 }
00301 }
00302
00303
00304 ?>