This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/admin/050-updates/120-planet-mining/040-gu-pmc-update-resource.sql
Emmanuel BENOîT 44b6ec1920 Fixed resource extraction
* Formula was mis-copied from the wiki, the result was multiplied by the
provider's current quantity

* Changed extraction per work unit from 1 to 10
2012-01-30 09:18:20 +01:00

91 lines
No EOL
3.1 KiB
PL/PgSQL

/*
* Test the sys.gu_pmc_update_resource() function
*/
BEGIN;
/*
* We need to create a set of both resource providers and planet resource
* records that will be updated by the function when it is called. We
* disable foreign keys on both tables, as it makes things simpler. We
* also replace verse.get_raw_production(), verse.get_extraction_factor( )
* and verse.adjust_production() so that they return fixed values, and we
* need to set the game.resources.extraction constant.
*/
ALTER TABLE verse.resource_providers
DROP CONSTRAINT fk_resprov_planet ,
DROP CONSTRAINT fk_resprov_resource;
ALTER TABLE verse.planet_resources
DROP CONSTRAINT fk_pres_planet ,
DROP CONSTRAINT fk_pres_resource;
INSERT INTO verse.resource_providers(
planet_id , resource_name_id , resprov_quantity_max, resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
1 , 1 , 1000 , 1000 , 0 , 0.5
);
INSERT INTO verse.planet_resources(
planet_id , resource_name_id , pres_income , pres_upkeep
) VALUES (
1 , 1 , 0 , 0
);
CREATE OR REPLACE FUNCTION verse.get_raw_production( pid INT , pt building_output_type )
RETURNS REAL
AS $$
SELECT 1.0::REAL;
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION verse.adjust_production( prod REAL , happiness REAL )
RETURNS REAL
AS $$
SELECT 1.0::REAL;
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION verse.get_extraction_factor( _fill_ratio DOUBLE PRECISION , _difficulty DOUBLE PRECISION )
RETURNS DOUBLE PRECISION
AS $$
SELECT ( CASE WHEN $1 = 1.0 AND $2 = 0 THEN 0.002 ELSE 0.0 END )::DOUBLE PRECISION;
$$ LANGUAGE SQL;
SELECT sys.uoc_constant( 'game.resources.extraction' , '(test)' , 'Resources' , 1440.0 );
ALTER FUNCTION sys.get_constant( TEXT ) VOLATILE;
/***** TESTS BEGIN HERE *****/
SELECT plan( 4 );
SELECT sys.gu_pmc_update_resource( ROW(
1 , 1 , 1000.0 , 1000.0 , 0.0 , NULL , 1.0 , 0.5 , 1.0
) );
SELECT diag_test_name( 'sys.gu_pmc_update_resource( ) - Provider udpated' );
SELECT is( resprov_quantity , 999.999::DOUBLE PRECISION )
FROM verse.resource_providers
WHERE planet_id = 1 AND resource_name_id = 1;
SELECT diag_test_name( 'sys.gu_pmc_update_resource( ) - Planet resources income udpated' );
SELECT is( pres_income , 0.001::DOUBLE PRECISION )
FROM verse.planet_resources
WHERE planet_id = 1 AND resource_name_id = 1;
UPDATE verse.resource_providers SET resprov_quantity = resprov_quantity_max;
UPDATE sys.constant_definitions
SET c_value = 14400000.0
WHERE name = 'game.resources.extraction';
SELECT sys.gu_pmc_update_resource( ROW(
1 , 1 , 1000.0 , 1000.0 , 0.0 , NULL , 1.0 , 0.5 , 1.0
) );
SELECT diag_test_name( 'sys.gu_pmc_update_resource( ) - Bounded extraction quantity (1/2)' );
SELECT is( resprov_quantity , 990.0::DOUBLE PRECISION )
FROM verse.resource_providers
WHERE planet_id = 1 AND resource_name_id = 1;
SELECT diag_test_name( 'sys.gu_pmc_update_resource( ) - Bounded extraction quantity (2/2)' );
SELECT is( pres_income , 10.0::DOUBLE PRECISION )
FROM verse.planet_resources
WHERE planet_id = 1 AND resource_name_id = 1;
SELECT * FROM finish( );
ROLLBACK;