]> git.mxchange.org Git - city.git/commitdiff
Continued with project:
authorRoland Haeder <roland@mxchange.org>
Mon, 24 Aug 2015 21:38:32 +0000 (23:38 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 24 Aug 2015 21:38:32 +0000 (23:38 +0200)
- 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 <roland@mxchange.org>
application/city/config.php
application/city/interfaces/database/frontend/city_entities/sections/class_CitySectionsWrapper.php
application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php
application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php
application/city/main/manager/city_entities/lots/class_CityLotsManager.php
application/city/main/manager/city_entities/sections/class_CitySectionsManager.php
core
index.php

index c75253d2ea93ca797935e20bb760532de729e68e..ab7204ec7f33fb4dc197833ccb03b7228b602534 100644 (file)
@@ -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]
 ?>
index e96eacc7055934efe6845a9687b26463a7f683f3..591a64a2b6c63a98358a6972adfdbfc4f5ed3c7b 100644 (file)
@@ -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);
 }
index dddad9c18f05adcd3b6f72c10ddd245eda28e9d4..28826adeba3f9baf1002196fb47464582b415404 100644 (file)
@@ -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 . '.');
        }
 }
 
index e1f1907ef07dcf482cd499809b3a4ac1160869e3..a02921408f3bfe57319943a4ac7555dee93817a7 100644 (file)
@@ -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
index 29539b66da134b8d49a3d31673c4685661fa74d6..f4a7e982b2d16313c98c800afc16cf54dfbfaa20 100644 (file)
@@ -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
index fda32de1acf4b5547ca6f3ee3a87933a328092c3..b0821118226500dadbe93686ed19fa9ad5da4b83 100644 (file)
@@ -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 1f1aab69c7ee3964dbcd99dba679e3a4fbcbcddb..e6ff20a8ad777aa6b381dca7f7baf1bc3abded9e 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 1f1aab69c7ee3964dbcd99dba679e3a4fbcbcddb
+Subproject commit e6ff20a8ad777aa6b381dca7f7baf1bc3abded9e
index 51eb50ef9341ef86cdff5c5f4a9b4023502e5024..74d021df5751426487d020a8ec53efe156816280 100644 (file)
--- 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();