From c80e259b68b811a732f9da2819cb5367956b72b2 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 24 Aug 2015 23:38:32 +0200 Subject: [PATCH] Continued with project: - Init city sections expansion is now in alpha quality - Added a lot TODOs regarding handling of z coordinate (up/down) as this is not handled yet - 'core' updated Signed-off-by: Roland Haeder --- application/city/config.php | 9 ++ .../sections/class_CitySectionsWrapper.php | 1 + .../class_CitySectionsDatabaseWrapper.php | 123 +++++++++++++++++- .../districts/class_CityDistrictsManager.php | 3 +- .../lots/class_CityLotsManager.php | 3 +- .../sections/class_CitySectionsManager.php | 3 +- core | 2 +- index.php | 2 +- 8 files changed, 139 insertions(+), 7 deletions(-) diff --git a/application/city/config.php b/application/city/config.php index c75253d..ab7204e 100644 --- a/application/city/config.php +++ b/application/city/config.php @@ -576,5 +576,14 @@ $cfg->setConfigEntry('task_building_growth_interval_delay', 200); // CFG: TASK-BUILDING-GROWTH-MAX-RUNS $cfg->setConfigEntry('task_building_growth_max_runs', 0); +// CFG: CITY-MAX-INITIAL-XY-EXPANSION-RADIUS +$cfg->setConfigEntry('city_max_initial_xy_expansion_radius', 40); + +// CFG: CITY-MAX-INITIAL-UP-EXPANSION +$cfg->setConfigEntry('city_max_initial_up_expansion', 5); + +// CFG: CITY-MAX-INITIAL-DOWN-EXPANSION +$cfg->setConfigEntry('city_max_initial_down_expansion', 3); + // [EOF] ?> diff --git a/application/city/interfaces/database/frontend/city_entities/sections/class_CitySectionsWrapper.php b/application/city/interfaces/database/frontend/city_entities/sections/class_CitySectionsWrapper.php index e96eacc..591a64a 100644 --- a/application/city/interfaces/database/frontend/city_entities/sections/class_CitySectionsWrapper.php +++ b/application/city/interfaces/database/frontend/city_entities/sections/class_CitySectionsWrapper.php @@ -35,6 +35,7 @@ interface CitySectionsWrapper extends DatabaseWrapper { * * @param $cityId City id to check * @return $ids Sections ids from initial expansion + * @todo z-coordinate not used */ function doInitialCityExpansion ($cityId); } diff --git a/application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php b/application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php index dddad9c..28826ad 100644 --- a/application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php +++ b/application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php @@ -64,6 +64,19 @@ class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySec // Reserved section (see documentation) const DB_COLUMN_SECTION_RESERVED = 'section_reserved'; + // Section types + // @TODO "water" is not yet supported and may end up in a very random land. + const SECTION_TYPE_WATER = 'water'; + const SECTION_TYPE_EMPTY_LAND = 'land'; + + // Sub sections + // @TODO All types of water are not supported yet. + const SUB_SECTION_TYPE_EMPTY = 'empty'; + + // Reserved flag + const IS_NOT_RESERVED = 0; + const IS_RESERVED = 1; + /** * Protected constructor * @@ -124,13 +137,119 @@ class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySec * * @param $cityId City id to check * @return $ids Sections ids from initial expansion + * @todo Add handling of water types to make a more cooler map */ public function doInitialCityExpansion ($cityId) { // Make sure this city has no sections assert(!$this->ifCityHasSections($cityId)); - // @TODO Unfinished - $this->partialStub('cityId=' . $cityId . ' - UNFINISHED!'); + /* + * "Cache" max "radius" for initial city expansion. It is not a real + * radius but more a max expansion area (expand +- half of "radius" + * from 0/0). The "zero point" is always calculated in. + * + * This gives a maxium initial area calculated as follows: + * + * totalInitialSections = (radius + 1) * (radius + 1) + */ + $radius = $this->getConfigInstance()->getConfigEntry('city_max_initial_xy_expansion_radius'); + + // Max up and down ... + $maxUp = $this->getConfigInstance()->getConfigEntry('city_max_initial_up_expansion'); + $maxDown = $this->getConfigInstance()->getConfigEntry('city_max_initial_down_expansion'); + + // Extremely huge debug message: + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: radius=' . $radius . ',maxUp=' . $maxUp . ',maxDown=' . $maxDown); + + // Get data set instance + $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_CITY_SECTIONS)); + + // Add values for "zero point" + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_ID , 1); + $dataSetInstance->addCriteria(self::DB_COLUMN_CITY_ID , $cityId); + $dataSetInstance->addCriteria(self::DB_COLUMN_LOT_ID , 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_TYPE , self::SECTION_TYPE_EMPTY_LAND); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_SUB_TYPE , self::SUB_SECTION_TYPE_EMPTY); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_POSITION_X , 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_POSITION_Y , 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_POSITION_Z , 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_NORTH_ID, 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_SOUTH_ID, 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_WEST_ID , 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_EAST_ID , 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_UP_ID , 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_DOWN_ID , 0); + $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_RESERVED , self::IS_NOT_RESERVED); + + // Set primary key to 'city_id'/'section_id' + $dataSetInstance->setPrimaryKeyCombined(array(self::DB_COLUMN_CITY_ID, self::DB_COLUMN_SECTION_ID)); + + // Add "zero point" + $this->queryInsertDataSet($dataSetInstance); + + // Set section id to 2 as 1 is already initialized + init array + $sections = array(); + + // Output message to ask for user's patience ... + self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Writing ' . (($radius + 1) * ($radius + 1) * $maxUp * ($maxDown + 1)) . ' sections for city ' . $cityId . ' ... (this may takes some time)'); + + // Expand half of it to north/south (north=positive, south=negative) + for ($north = 1; $north < round($radius / 2); $north++) { + // Expand half of it to west/east (west=positive, east=negative) + for ($west = 1; $west < round($radius / 2); $west++) { + // Expand up/down (including "zero point") + for ($z = $maxDown; $z < ($maxUp + 1); $z++) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: north=' . $north . ',west=' . $west . ',z=' . $z); + + // Fill array up with south/east/down ids + $sections[($north * -1)][($west * -1)][$z]['type'] = self::SECTION_TYPE_EMPTY_LAND; + $sections[($north * -1)][($west * -1)][$z]['sub'] = self::SUB_SECTION_TYPE_EMPTY; + + // Fill up array with north/west/up ids + $sections[$north][$west][$z]['type'] = self::SECTION_TYPE_EMPTY_LAND; + $sections[$north][$west][$z]['sub'] = self::SUB_SECTION_TYPE_EMPTY; + } // END - for + } // END - for + } // END - for + + // Init section id with 2 as 1 is the "zero point" + $sectionId = 2; + + // Loop through whole array again for writing it to database: north/south + foreach ($sections as $x => $sectionX) { + // Loop through west/east values + foreach ($sectionX as $y => $sectionY) { + // Loop through up/down values + foreach ($sectionY as $z => $sectionData) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: x=' . $x . ',y=' . $y . ',z=' . $z . ',sectionId=' . $sectionId); + + // Set all coordinates for positive directions + $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_ID , $sectionId); + $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_POSITION_X, $x); + $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_POSITION_Y, $y); + $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_POSITION_Z, $z); + $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_TYPE , $sectionData['type']); + $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_SUB_TYPE , $sectionData['sub']); + + // Add value to database + $this->queryInsertDataSet($dataSetInstance); + + // Count id up + $sectionId++; + } // END - foreach + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: x=' . $x . ',y=' . $y . ' has been written.'); + } // END - foreach + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: x=' . $x . ' has been written.'); + } // END - foreach + + // Thank you for waiting! :-) + self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: ' . (($radius + 1) * ($radius + 1) * $maxUp * ($maxDown + 1)) . ' sections has been written for city ' . $cityId . '.'); } } diff --git a/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php b/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php index e1f1907..a029214 100644 --- a/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php +++ b/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php @@ -75,7 +75,8 @@ class CityDistrictsManager extends BaseFrameworkSystem implements ManageableCity * Expands any map that requires expansion * * @return void - * @todo 0% done + * @todo ~10% done + * @todo z-coordinate not used */ public function expandMaps () { // Get a city info wrapper instance diff --git a/application/city/main/manager/city_entities/lots/class_CityLotsManager.php b/application/city/main/manager/city_entities/lots/class_CityLotsManager.php index 29539b6..f4a7e98 100644 --- a/application/city/main/manager/city_entities/lots/class_CityLotsManager.php +++ b/application/city/main/manager/city_entities/lots/class_CityLotsManager.php @@ -75,7 +75,8 @@ class CityLotsManager extends BaseFrameworkSystem implements ManageableCityLots, * Expands any map that requires expansion * * @return void - * @todo 0% done + * @todo ~10% done + * @todo z-coordinate not used */ public function expandMaps () { // Get a city info wrapper instance diff --git a/application/city/main/manager/city_entities/sections/class_CitySectionsManager.php b/application/city/main/manager/city_entities/sections/class_CitySectionsManager.php index fda32de..b082111 100644 --- a/application/city/main/manager/city_entities/sections/class_CitySectionsManager.php +++ b/application/city/main/manager/city_entities/sections/class_CitySectionsManager.php @@ -75,7 +75,8 @@ class CitySectionsManager extends BaseFrameworkSystem implements ManageableCityS * Expands any map that requires expansion * * @return void - * @todo 0% done + * @todo ~10% done + * @todo z-coordinate not used */ public function expandMaps () { // Get a city info wrapper instance diff --git a/core b/core index 1f1aab6..e6ff20a 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 1f1aab69c7ee3964dbcd99dba679e3a4fbcbcddb +Subproject commit e6ff20a8ad777aa6b381dca7f7baf1bc3abded9e diff --git a/index.php b/index.php index 51eb50e..74d021d 100644 --- a/index.php +++ b/index.php @@ -208,7 +208,7 @@ define('DEVELOPER', TRUE); // Log all exceptions (only debug! This option can create large error logs) //define('LOG_EXCEPTIONS', TRUE); -//xdebug_start_trace(); +//* DEBUG: */ xdebug_start_trace(); // Do not remove the following line: ApplicationEntryPoint::main(); -- 2.39.5