Empire resources initialisation
* Empire resources will be initialised when an empire is created * When a new resource is created through the appropriate defs.uoc_... function, it will be added to all empires as well.
This commit is contained in:
parent
afc66166e0
commit
37555841ce
7 changed files with 106 additions and 11 deletions
|
@ -102,6 +102,12 @@ BEGIN
|
||||||
) VALUES (
|
) VALUES (
|
||||||
_name_id , _desc_id , _cat_id , _weight
|
_name_id , _desc_id , _cat_id , _weight
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Add the resource to all empires
|
||||||
|
INSERT INTO emp.resources ( empire_id , resource_name_id )
|
||||||
|
SELECT name_id , _name_id
|
||||||
|
FROM emp.empires;
|
||||||
|
|
||||||
RETURN 'CREATED';
|
RETURN 'CREATED';
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
WHEN unique_violation THEN
|
WHEN unique_violation THEN
|
||||||
|
@ -312,6 +318,12 @@ BEGIN
|
||||||
_difficulty_avg , _difficulty_dev ,
|
_difficulty_avg , _difficulty_dev ,
|
||||||
_recovery_avg , _recovery_dev
|
_recovery_avg , _recovery_dev
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Add the resource to all empires
|
||||||
|
INSERT INTO emp.resources ( empire_id , resource_name_id )
|
||||||
|
SELECT name_id , _name_id
|
||||||
|
FROM emp.empires;
|
||||||
|
|
||||||
RETURN 'CREATED';
|
RETURN 'CREATED';
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,10 @@ BEGIN
|
||||||
SELECT _name_id , _resource.resource_name_id
|
SELECT _name_id , _resource.resource_name_id
|
||||||
FROM defs.natural_resources _resource;
|
FROM defs.natural_resources _resource;
|
||||||
|
|
||||||
|
-- Add empire resources
|
||||||
|
INSERT INTO emp.resources ( empire_id , resource_name_id )
|
||||||
|
SELECT _name_id , resource_name_id FROM defs.resources;
|
||||||
|
|
||||||
-- Add empire update records
|
-- Add empire update records
|
||||||
FOR _update_type IN SELECT _type
|
FOR _update_type IN SELECT _type
|
||||||
FROM unnest( enum_range( NULL::update_type ) ) AS _type
|
FROM unnest( enum_range( NULL::update_type ) ) AS _type
|
||||||
|
|
|
@ -10,7 +10,7 @@ BEGIN;
|
||||||
SELECT _create_natural_resources( 1 , 'natRes' );
|
SELECT _create_natural_resources( 1 , 'natRes' );
|
||||||
|
|
||||||
/****** TESTS BEGIN HERE ******/
|
/****** TESTS BEGIN HERE ******/
|
||||||
SELECT plan( 15 );
|
SELECT plan( 16 );
|
||||||
|
|
||||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - creation without category' );
|
SELECT diag_test_name( 'defs.uoc_resource_internal() - creation without category' );
|
||||||
SELECT is( defs.uoc_resource_internal( 'test3' , 'test4' , NULL , 1 ) , 'CREATED' );
|
SELECT is( defs.uoc_resource_internal( 'test3' , 'test4' , NULL , 1 ) , 'CREATED' );
|
||||||
|
@ -70,5 +70,20 @@ BEGIN;
|
||||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - weight <= 0' );
|
SELECT diag_test_name( 'defs.uoc_resource_internal() - weight <= 0' );
|
||||||
SELECT is( defs.uoc_resource_internal( 'test1' , 'test2' , NULL , 0 ) , 'BAD_VALUE' );
|
SELECT is( defs.uoc_resource_internal( 'test1' , 'test2' , NULL , 0 ) , 'BAD_VALUE' );
|
||||||
|
|
||||||
|
/* Reset resources, create empire */
|
||||||
|
DELETE FROM defs.natural_resources;
|
||||||
|
DELETE FROM defs.resources;
|
||||||
|
ALTER TABLE emp.empires
|
||||||
|
DROP CONSTRAINT fk_empires_name;
|
||||||
|
INSERT INTO emp.empires ( name_id , cash )
|
||||||
|
VALUES ( 1 , 0 );
|
||||||
|
|
||||||
|
SELECT diag_test_name( 'defs.uoc_resource_internal() - new resources are added to empires' );
|
||||||
|
SELECT defs.uoc_resource_internal( 'test3' , 'test4' , NULL , 1 );
|
||||||
|
SELECT is( COUNT(*)::INT , 1 )
|
||||||
|
FROM emp.resources
|
||||||
|
WHERE empire_id = 1
|
||||||
|
AND resource_name_id = _get_string( 'test3' );
|
||||||
|
|
||||||
SELECT * FROM finish( );
|
SELECT * FROM finish( );
|
||||||
ROLLBACK;
|
ROLLBACK;
|
|
@ -10,7 +10,7 @@ BEGIN;
|
||||||
SELECT _create_natural_resources( 1 , 'natRes' );
|
SELECT _create_natural_resources( 1 , 'natRes' );
|
||||||
|
|
||||||
/****** TESTS BEGIN HERE ******/
|
/****** TESTS BEGIN HERE ******/
|
||||||
SELECT plan( 22 );
|
SELECT plan( 24 );
|
||||||
|
|
||||||
SELECT diag_test_name( 'defs.uoc_resource() - NULL name (no category)' );
|
SELECT diag_test_name( 'defs.uoc_resource() - NULL name (no category)' );
|
||||||
SELECT is( defs.uoc_resource( NULL , 'test2' , 1 ) , NULL );
|
SELECT is( defs.uoc_resource( NULL , 'test2' , 1 ) , NULL );
|
||||||
|
@ -86,5 +86,26 @@ BEGIN;
|
||||||
SELECT diag_test_name( 'defs.uoc_resource() - weight <= 0' );
|
SELECT diag_test_name( 'defs.uoc_resource() - weight <= 0' );
|
||||||
SELECT is( defs.uoc_resource( 'natRes1' , 'test2' , 0 ) , 'BAD_VALUE' );
|
SELECT is( defs.uoc_resource( 'natRes1' , 'test2' , 0 ) , 'BAD_VALUE' );
|
||||||
|
|
||||||
|
/* Reset resources, create empire */
|
||||||
|
DELETE FROM defs.natural_resources;
|
||||||
|
DELETE FROM defs.resources;
|
||||||
|
ALTER TABLE emp.empires
|
||||||
|
DROP CONSTRAINT fk_empires_name;
|
||||||
|
INSERT INTO emp.empires ( name_id , cash )
|
||||||
|
VALUES ( 1 , 0 );
|
||||||
|
|
||||||
|
SELECT diag_test_name( 'defs.uoc_resource() - new resources are added to empires (no category)' );
|
||||||
|
SELECT defs.uoc_resource( 'test1' , 'test2' , 1 );
|
||||||
|
SELECT is( COUNT(*)::INT , 1 )
|
||||||
|
FROM emp.resources
|
||||||
|
WHERE empire_id = 1
|
||||||
|
AND resource_name_id = _get_string( 'test1' );
|
||||||
|
SELECT diag_test_name( 'defs.uoc_resource() - new resources are added to empires' );
|
||||||
|
SELECT defs.uoc_resource( 'test3' , 'test4' , 'test5' , 1 );
|
||||||
|
SELECT is( COUNT(*)::INT , 1 )
|
||||||
|
FROM emp.resources
|
||||||
|
WHERE empire_id = 1
|
||||||
|
AND resource_name_id = _get_string( 'test3' );
|
||||||
|
|
||||||
SELECT * FROM finish( );
|
SELECT * FROM finish( );
|
||||||
ROLLBACK;
|
ROLLBACK;
|
|
@ -10,7 +10,7 @@ BEGIN;
|
||||||
SELECT _create_resources( 1 , 'basicRes' );
|
SELECT _create_resources( 1 , 'basicRes' );
|
||||||
|
|
||||||
/****** TESTS BEGIN HERE ******/
|
/****** TESTS BEGIN HERE ******/
|
||||||
SELECT plan( 37 );
|
SELECT plan( 38 );
|
||||||
|
|
||||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - creation without category' );
|
SELECT diag_test_name( 'defs.uoc_natres_internal() - creation without category' );
|
||||||
SELECT is( defs.uoc_natres_internal( 'test3' , 'test4' , NULL , 1 ,
|
SELECT is( defs.uoc_natres_internal( 'test3' , 'test4' , NULL , 1 ,
|
||||||
|
@ -171,5 +171,21 @@ BEGIN;
|
||||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.75 , 0.5 ) , 'BAD_VALUE' );
|
0.5 , 100 , 50 , 0.5 , 0.05 , 0.75 , 0.5 ) , 'BAD_VALUE' );
|
||||||
|
|
||||||
|
/* Reset resources, create empire */
|
||||||
|
DELETE FROM defs.natural_resources;
|
||||||
|
DELETE FROM defs.resources;
|
||||||
|
ALTER TABLE emp.empires
|
||||||
|
DROP CONSTRAINT fk_empires_name;
|
||||||
|
INSERT INTO emp.empires ( name_id , cash )
|
||||||
|
VALUES ( 1 , 0 );
|
||||||
|
|
||||||
|
SELECT diag_test_name( 'defs.uoc_natres_internal() - new resources are added to empires' );
|
||||||
|
SELECT defs.uoc_natres_internal( 'test1' , 'test2' , NULL , 1 ,
|
||||||
|
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 );
|
||||||
|
SELECT is( COUNT(*)::INT , 1 )
|
||||||
|
FROM emp.resources
|
||||||
|
WHERE empire_id = 1
|
||||||
|
AND resource_name_id = _get_string( 'test1' );
|
||||||
|
|
||||||
SELECT * FROM finish( );
|
SELECT * FROM finish( );
|
||||||
ROLLBACK;
|
ROLLBACK;
|
|
@ -10,7 +10,7 @@ BEGIN;
|
||||||
SELECT _create_resources( 1 , 'basicRes' );
|
SELECT _create_resources( 1 , 'basicRes' );
|
||||||
|
|
||||||
/****** TESTS BEGIN HERE ******/
|
/****** TESTS BEGIN HERE ******/
|
||||||
SELECT plan( 58 );
|
SELECT plan( 60 );
|
||||||
|
|
||||||
|
|
||||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL name (no category)' );
|
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL name (no category)' );
|
||||||
|
@ -238,5 +238,28 @@ BEGIN;
|
||||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.75 , 0.5 ) , 'BAD_VALUE' );
|
0.5 , 100 , 50 , 0.5 , 0.05 , 0.75 , 0.5 ) , 'BAD_VALUE' );
|
||||||
|
|
||||||
|
/* Reset resources, create empire */
|
||||||
|
DELETE FROM defs.natural_resources;
|
||||||
|
DELETE FROM defs.resources;
|
||||||
|
ALTER TABLE emp.empires
|
||||||
|
DROP CONSTRAINT fk_empires_name;
|
||||||
|
INSERT INTO emp.empires ( name_id , cash )
|
||||||
|
VALUES ( 1 , 0 );
|
||||||
|
|
||||||
|
SELECT diag_test_name( 'defs.uoc_natural_resource() - new resources are added to empires (no category)' );
|
||||||
|
SELECT defs.uoc_natural_resource( 'test1' , 'test2' , 1 ,
|
||||||
|
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 );
|
||||||
|
SELECT is( COUNT(*)::INT , 1 )
|
||||||
|
FROM emp.resources
|
||||||
|
WHERE empire_id = 1
|
||||||
|
AND resource_name_id = _get_string( 'test1' );
|
||||||
|
SELECT diag_test_name( 'defs.uoc_natural_resource() - new resources are added to empires' );
|
||||||
|
SELECT defs.uoc_natural_resource( 'test3' , 'test4' , 'test5' , 1 ,
|
||||||
|
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 );
|
||||||
|
SELECT is( COUNT(*)::INT , 1 )
|
||||||
|
FROM emp.resources
|
||||||
|
WHERE empire_id = 1
|
||||||
|
AND resource_name_id = _get_string( 'test3' );
|
||||||
|
|
||||||
SELECT * FROM finish( );
|
SELECT * FROM finish( );
|
||||||
ROLLBACK;
|
ROLLBACK;
|
|
@ -16,7 +16,7 @@ BEGIN;
|
||||||
SELECT _create_emp_names( 1 , 'testEmp' );
|
SELECT _create_emp_names( 1 , 'testEmp' );
|
||||||
|
|
||||||
/***** TESTS BEGIN HERE *****/
|
/***** TESTS BEGIN HERE *****/
|
||||||
SELECT plan( 7 );
|
SELECT plan( 8 );
|
||||||
|
|
||||||
SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) ,
|
SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) ,
|
||||||
_get_map_name( 'testPlanet1' ) ,
|
_get_map_name( 'testPlanet1' ) ,
|
||||||
|
@ -46,12 +46,16 @@ BEGIN;
|
||||||
USING ( resource_name_id )
|
USING ( resource_name_id )
|
||||||
WHERE empire_id = _get_emp_name( 'testEmp1' );
|
WHERE empire_id = _get_emp_name( 'testEmp1' );
|
||||||
|
|
||||||
SELECT diag_test_name( 'emp.create_empire() - Empire mining settings are all set to the same value' );
|
SELECT diag_test_name( 'emp.create_empire() - Empire mining settings are all set to 2' );
|
||||||
SELECT is( COUNT( _temp.* )::INT , 1 )
|
SELECT is( COUNT( * )::INT , 0 )
|
||||||
FROM ( SELECT DISTINCT empmset_weight
|
FROM emp.mining_settings
|
||||||
FROM emp.mining_settings
|
WHERE empire_id = _get_emp_name( 'testEmp1' )
|
||||||
WHERE empire_id = _get_emp_name( 'testEmp1' )
|
AND empmset_weight <> 2;
|
||||||
) AS _temp;
|
|
||||||
|
SELECT diag_test_name( 'emp.create_empire() - Empire resources have been initialised' );
|
||||||
|
SELECT is( COUNT(*)::INT , 3 )
|
||||||
|
FROM emp.resources
|
||||||
|
WHERE empire_id = _get_emp_name( 'testEmp1' );
|
||||||
|
|
||||||
SELECT diag_test_name( 'emp.create_empire() - Empire update records' );
|
SELECT diag_test_name( 'emp.create_empire() - Empire update records' );
|
||||||
SELECT is( _eur.quantity , _utv.quantity)
|
SELECT is( _eur.quantity , _utv.quantity)
|
||||||
|
|
Reference in a new issue