Planet mining settings interface

* Modified owned planet view to include a field which indicates whether
mining settings are specific to the planet or come from the empire;
modified "simple" game components accordingly

* Modified stored procedures to only allow planet-specific mining
settings updates when the planet actually uses planet-specific settings,
and added a stored procedure which toggles the source of a planet's
settings

* Added corresponding parts to mining settings DAO and resources
controller

* Added session commands and server command handlers that toggle the
source of the settings and that upload the settings

* Split planet page template into multiple files for clarity and added
the mining priorities form to the natural resources tab
This commit is contained in:
Emmanuel BENOîT 2012-02-07 17:03:55 +01:00
parent 51b529a09f
commit e64f847ec3
25 changed files with 1009 additions and 152 deletions
legacyworlds-server-data/db-structure/parts/040-functions

View file

@ -69,8 +69,9 @@ GRANT EXECUTE
* _planet_id The planet's identifier
*
* Returns:
* ? True if the empire exists and owns the planet, false
* otherwise
* ? True if the empire exists and owns the planet and if
* the planet is using planet-specific settings,
* false otherwise
*/
DROP FUNCTION IF EXISTS emp.mset_update_start( INT , INT );
CREATE FUNCTION emp.mset_update_start( _empire_id INT , _planet_id INT )
@ -95,9 +96,14 @@ BEGIN
ON _planet.name_id = _emp_planet.planet_id
INNER JOIN verse.resource_providers _resprov
ON _resprov.planet_id = _planet.name_id
INNER JOIN emp.planet_mining_settings _mset
ON _mset.planet_id = _planet.name_id
AND _mset.empire_id = _empire.name_id
AND _mset.resource_name_id = _resprov.resource_name_id
WHERE _empire.name_id = _empire_id
AND _planet.name_id = _planet_id
FOR SHARE OF _empire, _emp_planet , _planet , _resprov;
FOR SHARE OF _empire, _emp_planet , _planet , _resprov
FOR UPDATE OF _mset;
IF NOT FOUND THEN
RETURN FALSE;
END IF;
@ -239,4 +245,71 @@ REVOKE EXECUTE
FROM PUBLIC;
GRANT EXECUTE
ON FUNCTION emp.mset_update_apply( )
TO :dbuser;
/*
* Toggle the source of a planet's mining settings
* ------------------------------------------------
*
* This function causes a planet to be switched between empire-wide and
* planet-specific mining settings.
*
* Parameters:
* _empire The empire's identifier
* _planet The planet's identifier
*
* Returns:
* ? TRUE if the operation succeeded, FALSE if the planet
* didn't exist or wasn't owned by the specified empire.
*/
DROP FUNCTION IF EXISTS emp.mset_toggle_source( INT , INT );
CREATE FUNCTION emp.mset_toggle_source( _empire INT , _planet INT )
RETURNS BOOLEAN
LANGUAGE PLPGSQL
STRICT VOLATILE
SECURITY DEFINER
AS $mset_toggle_source$
BEGIN
PERFORM 1
FROM emp.planets _ep
INNER JOIN verse.resource_providers _rp
USING ( planet_id )
LEFT OUTER JOIN (
SELECT * FROM emp.planet_mining_settings _pms
WHERE planet_id = _planet
AND empire_id = _empire
FOR UPDATE
) _pms USING ( planet_id , empire_id , resource_name_id )
WHERE _ep.empire_id = _empire
AND _ep.planet_id = _planet
FOR UPDATE OF _ep;
IF NOT FOUND THEN
RETURN FALSE;
END IF;
PERFORM 1 FROM emp.planet_mining_settings _pms
WHERE planet_id = _planet AND empire_id = _empire;
IF FOUND THEN
DELETE FROM emp.planet_mining_settings
WHERE planet_id = _planet AND empire_id = _empire;
ELSE
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id , resource_name_id , emppmset_weight
) SELECT empire_id , planet_id , resource_name_id , empmset_weight
FROM verse.resource_providers _rp
INNER JOIN emp.mining_settings
USING ( resource_name_id )
WHERE planet_id = _planet AND empire_id = _empire;
END IF;
RETURN TRUE;
END;
$mset_toggle_source$;
REVOKE EXECUTE
ON FUNCTION emp.mset_toggle_source( INT , INT )
FROM PUBLIC;
GRANT EXECUTE
ON FUNCTION emp.mset_toggle_source( INT , INT )
TO :dbuser;

View file

@ -36,14 +36,16 @@ CREATE TYPE planet_orbital_data AS (
-- Planet owner view
CREATE TYPE planet_owner_data AS (
happiness INT ,
h_change INT ,
income BIGINT ,
upkeep BIGINT ,
can_rename BOOLEAN ,
can_abandon BOOLEAN ,
abandon_time INT
DROP TYPE IF EXISTS emp.planet_owner_data;
CREATE TYPE emp.planet_owner_data AS (
happiness INT ,
h_change INT ,
income BIGINT ,
upkeep BIGINT ,
specific_mining_settings BOOLEAN ,
can_rename BOOLEAN ,
can_abandon BOOLEAN ,
abandon_time INT
);
@ -243,26 +245,33 @@ GRANT EXECUTE ON FUNCTION verse.get_orbital_view( INT , INT ) TO :dbuser;
-- an owner planet view entry
--
DROP FUNCTION IF EXISTS verse.get_owner_view( INT , INT ) CASCADE;
CREATE OR REPLACE FUNCTION verse.get_owner_view( e_id INT , p_id INT )
RETURNS planet_owner_data
RETURNS emp.planet_owner_data
STRICT STABLE
SECURITY DEFINER
AS $$
DECLARE
rv planet_owner_data;
rv emp.planet_owner_data;
t_happ INT;
h_chg INT;
mdelay BIGINT;
r_time INTERVAL;
BEGIN
-- Get income, upkeep, current and target happiness
SELECT INTO rv.income , rv.upkeep , rv.happiness , t_happ
SELECT INTO rv.income , rv.upkeep , rv.happiness , t_happ , rv.specific_mining_settings
floor( pm.income )::INT , floor( pm.upkeep )::INT ,
floor( 100 * ph.current / p.population )::INT ,
floor( 100 * ph.target )::INT
floor( 100 * ph.target )::INT ,
_count.settings_exist
FROM verse.planets p
INNER JOIN verse.planet_happiness ph ON ph.planet_id = p.name_id
INNER JOIN verse.planet_money pm ON pm.planet_id = p.name_id
CROSS JOIN (
SELECT ( COUNT( * ) > 0 ) AS settings_exist
FROM emp.planet_mining_settings
WHERE planet_id = p_id AND empire_id = e_id
) _count
WHERE p.name_id = p_id;
-- Compute happiness change indicator
@ -306,7 +315,12 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
GRANT EXECUTE ON FUNCTION verse.get_owner_view( INT , INT ) TO :dbuser;
REVOKE EXECUTE
ON FUNCTION verse.get_owner_view( INT , INT )
FROM PUBLIC;
GRANT EXECUTE
ON FUNCTION verse.get_owner_view( INT , INT )
TO :dbuser;