- removed SDE database requirement from Pathfinder, #628

- improved "shattered" wormholes (e.g. UI updates on map, fixed broken statics,..), closed #647
- improved "route search" algorithm, WHs are no longer supposed to be "insecure"
This commit is contained in:
Mark Friedrich
2018-06-30 13:19:12 +02:00
parent e65d2b8bc0
commit e7184b7312
32 changed files with 653 additions and 913 deletions

View File

@@ -10,6 +10,7 @@ namespace Model;
use DB\SQL\Schema;
use lib\logging;
use Controller\Ccp\Universe;
class SystemModel extends AbstractMapTrackingModel {
@@ -18,6 +19,8 @@ class SystemModel extends AbstractMapTrackingModel {
protected $table = 'system';
protected $staticSystemDataCache = [];
protected $fieldConf = [
'active' => [
'type' => Schema::DT_BOOL,
@@ -40,6 +43,7 @@ class SystemModel extends AbstractMapTrackingModel {
'systemId' => [
'type' => Schema::DT_INT,
'index' => true,
'validate' => true
],
'name' => [
'type' => Schema::DT_VARCHAR128,
@@ -54,7 +58,7 @@ class SystemModel extends AbstractMapTrackingModel {
],
'regionId' => [
'type' => Schema::DT_INT,
'index' => true,
'index' => true
],
'region' => [
'type' => Schema::DT_VARCHAR128,
@@ -63,7 +67,7 @@ class SystemModel extends AbstractMapTrackingModel {
],
'constellationId' => [
'type' => Schema::DT_INT,
'index' => true,
'index' => true
],
'constellation' => [
'type' => Schema::DT_VARCHAR128,
@@ -202,56 +206,58 @@ class SystemModel extends AbstractMapTrackingModel {
if(is_null($systemData)){
// no cached system data found
$systemData = (object) [];
$systemData->id = $this->_id;
$systemData->mapId = is_object($this->mapId) ? $this->get('mapId', true) : 0;
$systemData->systemId = $this->systemId;
$systemData->name = $this->name;
$systemData->alias = $this->alias;
$systemData->effect = $this->effect;
$systemData->security = $this->security;
$systemData->trueSec = $this->trueSec;
$systemData = (object) [];
$systemData->id = $this->_id;
$systemData->mapId = is_object($this->mapId) ? $this->get('mapId', true) : 0;
$systemData->systemId = $this->systemId;
$systemData->alias = $this->alias;
$systemData->region = (object) [];
$systemData->region->id = $this->regionId;
$systemData->region->name = $this->region;
if(is_object($this->typeId)){
$systemData->type = $this->typeId->getData();
}
$systemData->constellation = (object) [];
$systemData->constellation->id = $this->constellationId;
$systemData->constellation->name = $this->constellation;
$systemData->status = (object) [];
$systemData->status->id = is_object($this->statusId) ? $this->statusId->id : 1;
$systemData->status->name = is_object($this->statusId) ? $this->statusId->name : 'unknown';
$systemData->type = (object) [];
$systemData->type->id = $this->typeId->id;
$systemData->type->name = $this->typeId->name;
$systemData->locked = $this->locked;
$systemData->rallyUpdated = strtotime($this->rallyUpdated);
$systemData->rallyPoke = $this->rallyPoke;
$systemData->description = $this->description;
$systemData->status = (object) [];
$systemData->status->id = is_object($this->statusId) ? $this->statusId->id : 1;
$systemData->status->name = is_object($this->statusId) ? $this->statusId->name : 'unknown';
$systemData->position = (object) [];
$systemData->position->x = $this->posX;
$systemData->position->y = $this->posY;
$systemData->locked = $this->locked;
$systemData->rallyUpdated = strtotime($this->rallyUpdated);
$systemData->rallyPoke = $this->rallyPoke;
$systemData->description = $this->description;
$systemData->statics = $this->getStaticWormholeData();
$systemData->position = (object) [];
$systemData->position->x = $this->posX;
$systemData->position->y = $this->posY;
$systemData->created = (object) [];
$systemData->created->created = strtotime($this->created);
$systemData->created = (object) [];
$systemData->created->created = strtotime($this->created);
if(is_object($this->createdCharacterId)){
$systemData->created->character = $this->createdCharacterId->getData();
}
$systemData->updated = (object) [];
$systemData->updated->updated = strtotime($this->updated);
$systemData->updated = (object) [];
$systemData->updated->updated = strtotime($this->updated);
if(is_object($this->updatedCharacterId)){
$systemData->updated->character = $this->updatedCharacterId->getData();
}
// static system data -------------------------------------------------------------------------------------
$systemData->name = $this->name;
$systemData->security = $this->security;
$systemData->trueSec = $this->trueSec;
$systemData->effect = $this->effect;
$systemData->shattered = $this->shattered;
$systemData->constellation = (object) [];
$systemData->constellation->id = $this->constellationId;
$systemData->constellation->name = $this->constellation;
$systemData->region = (object) [];
$systemData->region->id = $this->regionId;
$systemData->region->name = $this->region;
$systemData->statics = $this->statics ? : [];
// max caching time for a system
// the cached date has to be cleared manually on any change
// this includes system, connection,... changes (all dependencies)
@@ -262,7 +268,58 @@ class SystemModel extends AbstractMapTrackingModel {
}
/**
* setter for system alias
* get all static data
* @return mixed|null|\stdClass
* @throws \Exception
*/
private function getStaticSystemData(){
$staticData = null;
if( !empty($this->staticSystemDataCache[$this->systemId]) ){
$staticData = $this->staticSystemDataCache[$this->systemId];
}else{
$staticData = (new Universe())->getSystemData($this->systemId);
if($staticData){
$this->staticSystemDataCache = [$this->systemId => $staticData];
}
}
return $staticData;
}
/**
* get static system data by key
* @param string $key
* @return null
* @throws \Exception
*/
private function getStaticSystemValue(string $key){
$value = null;
if( $staticData = $this->getStaticSystemData()){
if(isset($staticData->$key)){
$value = $staticData->$key;
}
}
return $value;
}
/**
* @param string $key
* @param int $val
* @return bool
* @throws \Exception
*/
protected function validate_systemId(string $key, int $val): bool {
$valid = true;
// check if static system data exists for systemId = $val
if( !(bool)(new Universe())->getSystemData($val) ){
$valid = false;
$this->throwValidationException($key, 'Validation failed: "' . $key . '" = "' . $val . '"');
}
return $valid;
}
/**
* setter for system alias
* @param string $alias
* @return string
*/
@@ -278,30 +335,35 @@ class SystemModel extends AbstractMapTrackingModel {
}
/**
* setter for system security value
* @param float $trueSec
* @return float
* setter for statusId
* @param $status
*/
public function set_trueSec($trueSec){
if(
$trueSec > 0 &&
$trueSec < 0.1
){
// 0.3 is still a LS -> no rounding
$trueSec = 0.1;
}else{
$trueSec = round($trueSec, 1);
public function set_status($status){
if($statusId = (int)$status['id']){
$this->statusId = $statusId;
}
return $trueSec;
}
/**
* setter validation for x coordinate
* setter for position array
* @param $position
* @return null
*/
public function set_position($position){
$position = (array)$position;
if(count($position) === 2){
$this->posX = $position['x'];
$this->posY = $position['y'];
}
return null;
}
/**
* setter for x coordinate
* @param int $posX
* @return int
*/
public function set_posX($posX){
public function set_posX(int $posX) : int {
$posX = abs($posX);
if($posX > self::MAX_POS_X){
$posX = self::MAX_POS_X;
@@ -311,11 +373,11 @@ class SystemModel extends AbstractMapTrackingModel {
}
/**
* setter validation for y coordinate
* setter for y coordinate
* @param int $posY
* @return int
*/
public function set_posY($posY){
public function set_posY(int $posY) : int{
$posY = abs($posY);
if($posY > self::MAX_POS_Y){
$posY = self::MAX_POS_Y;
@@ -348,6 +410,50 @@ class SystemModel extends AbstractMapTrackingModel {
return $rally;
}
public function get_name(){
return $this->getStaticSystemValue('name');
}
public function get_constellationId(){
$constellationData = $this->getStaticSystemValue('constellation');
return $constellationData ? $constellationData->id : null;
}
public function get_constellation(){
$constellationData = $this->getStaticSystemValue('constellation');
return $constellationData ? $constellationData->name : null;
}
public function get_regionId(){
$constellationData = $this->getStaticSystemValue('constellation');
return ($constellationData && $constellationData->region) ? $constellationData->region->id : null;
}
public function get_region(){
$constellationData = $this->getStaticSystemValue('constellation');
return ($constellationData && $constellationData->region) ? $constellationData->region->name : null;
}
public function get_security(){
return $this->getStaticSystemValue('security');
}
public function get_trueSec(){
return $this->getStaticSystemValue('trueSec');
}
public function get_effect(){
return $this->getStaticSystemValue('effect');
}
public function get_shattered(){
return $this->getStaticSystemValue('shattered');
}
public function get_statics(){
return $this->getStaticSystemValue('statics');
}
/**
* Event "Hook" function
* @param self $self
@@ -555,14 +661,6 @@ class SystemModel extends AbstractMapTrackingModel {
return ($this->typeId->id === 1);
}
/**
* check whether this system is a shattered wormhole
* @return bool
*/
public function isShatteredWormhole() : bool {
return ($this->isWormhole() && $this->security === 'SH');
}
/**
* check whether this system is an Abyss system
* @return bool
@@ -631,44 +729,28 @@ class SystemModel extends AbstractMapTrackingModel {
}
/**
* get static WH data for this system
* -> any WH system has at least one static WH
* @return \stdClass[]
* @throws \Exception
* set system type based on security
*/
protected function getStaticWormholeData(){
$wormholeData = [];
// only wormholes have "static" connections
if($this->isWormhole()){
// get static systems by "constellationId" --------------------------------------------
$constellationWormholeModel = self::getNew('ConstellationWormholeModel');
$systemStatics = $constellationWormholeModel->find([
'constellationId = :constellationId',
':constellationId' => $this->constellationId
]);
if( is_object($systemStatics) ){
foreach($systemStatics as $systemStatic){
$wormholeData[] = $systemStatic->getData();
}
}
// get static systems by "systemId" (shattered wormholes) -----------------------------
$systemWormholeModel = self::getNew('SystemWormholeModel');
$systemStatics = $systemWormholeModel->find([
'systemId = :systemId',
':systemId' => $this->systemId
]);
if( is_object($systemStatics) ){
foreach($systemStatics as $systemStatic){
$wormholeData[] = $systemStatic->getData();
}
}
public function setType(){
switch($this->security){
case 'H':
case 'L':
case '0.0':
$typeId = 2; // k-space
break;
case 'A':
$typeId = 3; // a-space
break;
default:
$typeId = 1; // w-space
}
return $wormholeData;
/**
* @var $type MapTypeModel
*/
$type = $this->rel('typeId');
$type->getById($typeId);
$this->typeId = $type;
}
/**