From: Roland Haeder Date: Sat, 1 Aug 2015 14:41:38 +0000 (+0200) Subject: Added classes and interfaces for districts + updated map and some renames X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cc05cc124c273dd7fa727c4872d147287a09951b;p=city.git Added classes and interfaces for districts + updated map and some renames Signed-off-by: Roland Haeder --- diff --git a/application/city/config.php b/application/city/config.php index 15a5266..069434b 100644 --- a/application/city/config.php +++ b/application/city/config.php @@ -52,6 +52,12 @@ $cfg->setConfigEntry('region_map_db_wrapper_class', 'RegionMapDatabaseWrapper'); // CFG: CITY-SECTIONS-DB-WRAPPER-CLASS $cfg->setConfigEntry('city_sections_db_wrapper_class', 'CitySectionsDatabaseWrapper'); +// CFG: CITY-LOTS-DB-WRAPPER-CLASS +$cfg->setConfigEntry('city_lots_db_wrapper_class', 'CityLotsDatabaseWrapper'); + +// CFG: CITY-DISTRICTS-DB-WRAPPER-CLASS +$cfg->setConfigEntry('city_districts_db_wrapper_class', 'CityDistrictsDatabaseWrapper'); + // CFG: CITY-INIT-STATE-CLASS $cfg->setConfigEntry('city_init_state_class', 'CityInitState'); @@ -485,6 +491,12 @@ $cfg->setConfigEntry('city_manager_class', 'CityManager'); // CFG: CITY-SECTIONS-MANAGER-CLASS $cfg->setConfigEntry('city_sections_manager_class', 'CitySectionsManager'); +// CFG: CITY-LOTS-MANAGER-CLASS +$cfg->setConfigEntry('city_lots_manager_class', 'CityLotsManager'); + +// CFG: CITY-DISTRICTS-MANAGER-CLASS +$cfg->setConfigEntry('city_districts_manager_class', 'CityDistrictsManager'); + // CFG: REGION-MANAGER-CLASS $cfg->setConfigEntry('region_manager_class', 'RegionManager'); diff --git a/application/city/interfaces/database/frontend/city_entities/districts/.htaccess b/application/city/interfaces/database/frontend/city_entities/districts/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/database/frontend/city_entities/districts/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/database/frontend/city_entities/districts/class_CityDistrictsWrapper.php b/application/city/interfaces/database/frontend/city_entities/districts/class_CityDistrictsWrapper.php new file mode 100644 index 0000000..19999f1 --- /dev/null +++ b/application/city/interfaces/database/frontend/city_entities/districts/class_CityDistrictsWrapper.php @@ -0,0 +1,35 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City 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 . + */ +interface CityDistrictsWrapper extends DatabaseWrapper { + /** + * Checks if the given city id is found in districts table + * + * @param $cityId City id to check + * @return $isFound Whether the city id is found + */ + function ifCityHasDistricts ($cityId); +} + +// [EOF] +?> diff --git a/application/city/interfaces/manager/city_entities/districts/.htaccess b/application/city/interfaces/manager/city_entities/districts/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/manager/city_entities/districts/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/manager/city_entities/districts/class_ManageableCityDistricts.php b/application/city/interfaces/manager/city_entities/districts/class_ManageableCityDistricts.php new file mode 100644 index 0000000..4fc2843 --- /dev/null +++ b/application/city/interfaces/manager/city_entities/districts/class_ManageableCityDistricts.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City 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 . + */ +interface ManageableCityDistricts extends ManageableCityEntities { +} + +// [EOF] +?> diff --git a/application/city/main/city_daemon/class_BaseCityDaemon.php b/application/city/main/city_daemon/class_BaseCityDaemon.php index 89b3a51..8584beb 100644 --- a/application/city/main/city_daemon/class_BaseCityDaemon.php +++ b/application/city/main/city_daemon/class_BaseCityDaemon.php @@ -257,10 +257,10 @@ class BaseCityDaemon extends BaseCitySystem implements Updateable, AddableCriter */ public function isMapPendingExpansion () { // Get sections manager - $mapInstance = ManagerFactory::createManagerByType('city_sections'); + $sectionsInstance = ManagerFactory::createManagerByType('city_sections'); // Call it's method and return value - return $mapInstance->isMapPendingExpansion(); + return $sectionsInstance->isMapPendingExpansion(); } /** @@ -270,10 +270,10 @@ class BaseCityDaemon extends BaseCitySystem implements Updateable, AddableCriter */ public function expandMaps () { // Get sections manager - $mapInstance = ManagerFactory::createManagerByType('city_sections'); + $sectionsInstance = ManagerFactory::createManagerByType('city_sections'); // Call it's method and return value - $mapInstance->expandMaps(); + $sectionsInstance->expandMaps(); } } diff --git a/application/city/main/database/frontend/city_entities/districts/.htaccess b/application/city/main/database/frontend/city_entities/districts/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/database/frontend/city_entities/districts/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/database/frontend/city_entities/districts/class_CityDistrictsDatabaseWrapper.php b/application/city/main/database/frontend/city_entities/districts/class_CityDistrictsDatabaseWrapper.php new file mode 100644 index 0000000..67ea7c4 --- /dev/null +++ b/application/city/main/database/frontend/city_entities/districts/class_CityDistrictsDatabaseWrapper.php @@ -0,0 +1,89 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City 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 . + */ +class CityDistrictsDatabaseWrapper extends BaseDatabaseWrapper implements CityDistrictsWrapper, Registerable { + // Constants for database table names + const DB_TABLE_CITY_DISTRICTS = 'city_districts'; + + // Section id, an referenced city id and district id + const DB_COLUMN_CITY_ID = 'city_id'; + const DB_COLUMN_DISTRICT_ID = 'district_id'; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this database wrapper by a provided user class + * + * @return $wrapperInstance An instance of the created wrapper class + */ + public static final function createCityDistrictsDatabaseWrapper () { + // Get a new instance + $wrapperInstance = new CityDistrictsDatabaseWrapper(); + + // Set (primary!) table name + $wrapperInstance->setTableName(self::DB_TABLE_CITY_DISTRICTS); + + // Return the instance + return $wrapperInstance; + } + + /** + * Checks if the given city id is found in districts table + * + * @param $cityId City id to check + * @return $isFound Whether the city id is found + */ + public function ifCityHasDistricts ($cityId) { + // Get search instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Search for 'city_id' + $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId); + + /* + * Only one entry is enough to find, else this query could run very\ + * long on large maps. + */ + $searchInstance->setLimit(1); + + // Execute it on database instance + $resultInstance = $this->doSelectByCriteria($searchInstance); + + // Check if there is one entry + $isFound = ($resultInstance->next() == 1); + + // Return result + return $isFound; + } +} + +// [EOF] +?> diff --git a/application/city/main/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php b/application/city/main/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php index cafd007..7e4bfd5 100644 --- a/application/city/main/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php +++ b/application/city/main/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php @@ -28,6 +28,7 @@ class CityLotsDatabaseWrapper extends BaseDatabaseWrapper implements CityLotsWra // Section id, an referenced city id and lot id const DB_COLUMN_CITY_ID = 'city_id'; const DB_COLUMN_LOT_ID = 'lot_id'; + const DB_COLUMN_DISTRICT_ID = 'district_id'; /** * Protected constructor 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 007129d..941dc02 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 @@ -1,6 +1,14 @@ * @version 0.0.0 @@ -28,6 +36,11 @@ class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySec // Section id, an referenced city id and lot id const DB_COLUMN_SECTION_ID = 'city_section_id'; const DB_COLUMN_CITY_ID = 'city_id'; + + /* + * Lot id, the lot id is only set if the player has "aquired" the sections + * and has created a lot based on these sections. + */ const DB_COLUMN_LOT_ID = 'lot_id'; // Section and sub type (e.g. residential, hut) diff --git a/application/city/main/manager/city_entities/districts/.htaccess b/application/city/main/manager/city_entities/districts/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/manager/city_entities/districts/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php b/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php new file mode 100644 index 0000000..e1f1907 --- /dev/null +++ b/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php @@ -0,0 +1,101 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 . + */ +class CityDistrictsManager extends BaseFrameworkSystem implements ManageableCityDistricts, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $managerInstance An instance of a ManageableCityDistricts class + */ + public final static function createCityDistrictsManager () { + // Get new instance + $managerInstance = new CityDistrictsManager(); + + // Get database wrapper + $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_districts_db_wrapper_class'); + + // And set it here + $managerInstance->setWrapperInstance($wrapperInstance); + + // Return the prepared instance + return $managerInstance; + } + + /** + * Checks whether at least one map requires expansion + * + * @return $requiresExpansion Whether a map requires expansion + * @todo 0% done + */ + public function isMapPendingExpansion () { + // Default is no expansion is needed + $requireExpansion = FALSE; + + // First, a simple check if the districts table contains any entries at all + if ($this->getWrapperInstance()->countTotalRows() == 0) { + // This definedly requires expansion + $requireExpansion = TRUE; + } // END - if + + // Return status + return $requireExpansion; + } + + /** + * Expands any map that requires expansion + * + * @return void + * @todo 0% done + */ + public function expandMaps () { + // Get a city info wrapper instance + $cityWrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_info_db_wrapper_class'); + + // Get all city ids from it + $cityIds = $cityWrapperInstance->getAllCityIds(); + + // Now check all ids + foreach ($cityIds as $cityId) { + // Does this id have any districts + if (!$this->getWrapperInstance()->ifCityHasDistricts($cityId)) { + // Nothing found, so it is a brand-new city that needs first initialization + $districts = $this->getWrapperInstance()->doInitialCityExpansion($cityId); + } else { + // @TODO Maybe some expansion is needed + } + } // END - foreach + } +} + +// [EOF] +?> 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 5e25cc4..29539b6 100644 --- a/application/city/main/manager/city_entities/lots/class_CityLotsManager.php +++ b/application/city/main/manager/city_entities/lots/class_CityLotsManager.php @@ -89,7 +89,7 @@ class CityLotsManager extends BaseFrameworkSystem implements ManageableCityLots, // Does this id have any lots if (!$this->getWrapperInstance()->ifCityHasLots($cityId)) { // Nothing found, so it is a brand-new city that needs first initialization - $sections = $this->getWrapperInstance()->doInitialCityExpansion($cityId); + $lots = $this->getWrapperInstance()->doInitialCityExpansion($cityId); } else { // @TODO Maybe some expansion is needed } diff --git a/docs/mindmaps/Simple City Growth Simulation.mm b/docs/mindmaps/Simple City Growth Simulation.mm index 9ab289f..2017422 100644 --- a/docs/mindmaps/Simple City Growth Simulation.mm +++ b/docs/mindmaps/Simple City Growth Simulation.mm @@ -1,6 +1,6 @@ - + @@ -53,2073 +53,2148 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - + - + - + - + + + - - + - + - + + - - - - - + - - + - + - + + + - + - - - + - + - + - + - - - + - + + + + + + - + - + - - + + - + - + - + - - - + - + - - - - + - + - - + - + - + - + - + - + - + - + - + - + - + + + + + - + + + + + + + + + + + + + + - + + - + + + + + + + + - + + + - + + + - - + - + + - + + - + + + + + + + - + - + + + + + + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +