Resources information on planet list

* Added resource information records to the planet list's response.

* Added a database view and the corresponding row mapper and DAO method
which can be used as the data source for the planet list's resource
information. For now this view always returns 0 for both civilian and
military investments.

* Added new tab to display resource information on the planet list page.
The old version of the economy tab will be kept until the corresponding
data no longer exists.

* The following SQL scripts must be re-executed to upgrade a database:
  -> 040-functions/167-planet-list.sql
This commit is contained in:
Emmanuel BENOîT 2012-02-15 14:45:43 +01:00
parent bf6bea5a79
commit 96670d45be
15 changed files with 1079 additions and 31 deletions
legacyworlds-server-data/db-structure
parts/040-functions
tests
admin/040-functions/167-planet-list
user/040-functions/167-planet-list

View file

@ -3,7 +3,7 @@
--
-- Views for empires' planet lists
--
-- Copyright(C) 2004-2010, DeepClone Development
-- Copyright(C) 2004-2012, DeepClone Development
-- --------------------------------------------------------
@ -114,6 +114,58 @@ CREATE VIEW emp.planets_list_fleets
END );
/*
* Planet list resources information
* ----------------------------------
*
* This view is used to display the resources-related information in the
* planet list pages. All rows in the view are ordered using the usual
* resource ordering view.
*
* FIXME: time-related constants are hardcoded.
* FIXME: civilian and military investments are set to 0.
*
* Columns:
* empire_id The empire's identifier
* planet_id The planet's identifier
* pres_income The income for this type of resources on a period
* of 12h RT / one month GT.
* pres_upkeep The upkeep for this type of resources on a period
* of 12h RT / one month GT.
* civ_investment The current amount invested in the civillian build
* queue (FIXME: forced to 0)
* mil_investment The current amount invested in the military build
* queue (FIXME: forced to 0)
*/
DROP VIEW IF EXISTS emp.plist_resources_view;
CREATE VIEW emp.plist_resources_view
AS SELECT _emp_planet.empire_id , _emp_planet.planet_id ,
_name.translated_string AS resource_name ,
FLOOR( _pres.pres_income * 720.0 )::BIGINT AS pres_income ,
CEIL( _pres.pres_upkeep * 720.0 )::BIGINT AS pres_upkeep ,
0::BIGINT AS civ_investment ,
0::BIGINT AS mil_investment
FROM emp.planets _emp_planet
INNER JOIN verse.planet_resources _pres
USING ( planet_id )
INNER JOIN naming.empire_names _emp_name
ON _emp_name.id = _emp_planet.empire_id
INNER JOIN users.credentials _creds
ON _creds.address_id = _emp_name.owner_id
INNER JOIN defs.translations _name
ON _name.string_id = resource_name_id
AND _name.lang_id = _creds.language_id
INNER JOIN defs.ordered_resources_view _res_def
USING ( resource_name_id )
WHERE _pres.pres_income > 0
OR _pres.pres_upkeep > 0
ORDER BY _res_def.resource_ordering;
GRANT SELECT
ON emp.plist_resources_view
TO :dbuser;
--
-- Actual planet list
--

View file

@ -0,0 +1,78 @@
/*
* Tests for emp.plist_resources_view
*/
BEGIN;
\i utils/strings.sql
\i utils/resources.sql
\i utils/accounts.sql
\i utils/naming.sql
\i utils/universe.sql
/* Create a couple of resources, three planets and two empire names */
SELECT _create_resources( 2 , 'resource' );
SELECT _create_raw_planets( 3 , 'planet' );
SELECT _create_emp_names( 2 , 'empire' );
/* One of the empires possesses two planets */
SELECT emp.create_empire( _get_emp_name( 'empire1' ) ,
_get_map_name( 'planet1' ) ,
200.0 );
INSERT INTO emp.planets( empire_id , planet_id )
VALUES ( _get_emp_name( 'empire1' ) , _get_map_name( 'planet2' ) );
/* First planet has income for one resource and upkeep for the other */
INSERT INTO verse.planet_resources ( planet_id , resource_name_id , pres_income )
VALUES ( _get_map_name( 'planet1' ) , _get_string( 'resource1' ) , 0.23 );
INSERT INTO verse.planet_resources ( planet_id , resource_name_id , pres_upkeep )
VALUES ( _get_map_name( 'planet1' ) , _get_string( 'resource2' ) , 0.22 );
/* Second planet has no income or upkeep */
INSERT INTO verse.planet_resources ( planet_id , resource_name_id )
SELECT _get_map_name( 'planet2' ) , resource_name_id
FROM defs.resources;
/* The second empire has no planets */
INSERT INTO emp.empires( name_id , cash )
VALUES ( _get_emp_name( 'empire2' ) , 123 );
/* Third planet has income and upkeep for all resources */
INSERT INTO verse.planet_resources ( planet_id , resource_name_id , pres_income , pres_upkeep )
SELECT _get_map_name( 'planet3' ) , resource_name_id ,
4 + row_number( ) OVER( ) * 2 , row_number( ) OVER( ) * 2 + 5
FROM defs.resources;
-- ***** TESTS BEGIN HERE *****
SELECT plan( 4 );
SELECT diag_test_name( 'emp.plist_resources_view - No rows for neutral planets' );
SELECT is_empty( $$
SELECT * FROM emp.plist_resources_view
WHERE planet_id = _get_map_name( 'planet3' );
$$ );
SELECT diag_test_name( 'emp.plist_resources_view - No rows for empires with no planets' );
SELECT is_empty( $$
SELECT * FROM emp.plist_resources_view
WHERE empire_id = _get_emp_name( 'empire2' );
$$ );
SELECT diag_test_name( 'emp.plist_resources_view - No rows for owned planets with zero income and upkeep' );
SELECT is_empty( $$
SELECT * FROM emp.plist_resources_view
WHERE planet_id = _get_map_name( 'planet2' );
$$ );
SELECT diag_test_name( 'emp.plist_resources_view - Rows for owned planets with income and upkeep' );
SELECT set_eq( $$
SELECT empire_id , resource_name , pres_income , pres_upkeep ,
civ_investment , mil_investment
FROM emp.plist_resources_view
WHERE planet_id = _get_map_name( 'planet1' );
$$ , $$ VALUES(
_get_emp_name( 'empire1' ) , 'Test string #1' , 165 , 0 , 0 , 0
) , (
_get_emp_name( 'empire1' ) , 'Test string #2' , 0 , 159 , 0 , 0
) $$ );
SELECT * FROM finish( );
ROLLBACK;

View file

@ -0,0 +1,11 @@
/*
* Test privileges on emp.plist_resources_view
*/
BEGIN;
SELECT plan( 1 );
SELECT diag_test_name( 'emp.plist_resources_view - SELECT privilege' );
SELECT lives_ok( 'SELECT * FROM emp.plist_resources_view' );
SELECT * FROM finish( );
ROLLBACK;