Mining settings

* Changed the way mining settings work: use a priority value (between 0
and 4) as the weight. Leaving them as they were before would have caused
numerous problems (and a lot of unnecessary code to work around them)

* Empire mining settings will be created along with the empire's own
record. By default all natural resources will have weight = 2.

* Added a set of four stored procedures which can be used to update an
empire's mining settings, including planet-specific settings. The
emp.mset_update_start() function can be used to start an update (on an
empire's settings if there is only one parameter, or on a planet's
settings if there are two parameters); the emp.mset_update_set() and
emp.mset_update_apply() functions are then used to modify the settings
and apply the changes, respectively.
This commit is contained in:
Emmanuel BENOîT 2012-01-10 10:17:47 +01:00
parent 3e109b13bc
commit afc66166e0
15 changed files with 745 additions and 55 deletions
legacyworlds-server-data/db-structure/tests/admin/030-data/110-empires

View file

@ -14,10 +14,10 @@ BEGIN;
SELECT id , 0 FROM naming.empire_names;
/****** TESTS BEGIN HERE ******/
SELECT plan( 10 );
SELECT plan( 13 );
SELECT diag_test_name( 'Valid empire mining settings record' );
SELECT diag_test_name( 'emp.mining_settings - Valid record' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -25,12 +25,12 @@ BEGIN;
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , 0
);
SELECT lives_ok( '_test_this' );
SELECT diag_test_name( 'Duplicate empire mining settings record' );
SELECT diag_test_name( 'emp.mining_settings - Duplicate record' );
SELECT throws_ok( '_test_this' , 23505 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings records with same empire but different types' );
SELECT diag_test_name( 'emp.mining_settings - Same empire, different types' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -40,7 +40,7 @@ BEGIN;
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings records with same type but different empires' );
SELECT diag_test_name( 'emp.mining_settings - Same type, different empires' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -51,8 +51,21 @@ BEGIN;
DEALLOCATE ALL;
DELETE FROM emp.mining_settings;
SELECT diag_test_name( 'emp.mining_settings - Valid record with default weight' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' )
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with NULL empire identifier' );
SELECT diag_test_name( 'emp.mining_settings - Default weight = 2' );
SELECT is( empmset_weight , 2 ) FROM emp.mining_settings;
DELETE FROM emp.mining_settings;
SELECT diag_test_name( 'emp.mining_settings - NULL empire identifier' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -62,7 +75,7 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with invalid empire identifier' );
SELECT diag_test_name( 'emp.mining_settings - Invalid empire identifier' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -73,7 +86,7 @@ BEGIN;
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with NULL resource identifier' );
SELECT diag_test_name( 'emp.mining_settings - NULL resource identifier' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -83,7 +96,7 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with invalid resource identifier' );
SELECT diag_test_name( 'emp.mining_settings - Invalid resource identifier' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -94,7 +107,7 @@ BEGIN;
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with NULL weight' );
SELECT diag_test_name( 'emp.mining_settings - NULL weight' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -104,7 +117,7 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with weight < 0' );
SELECT diag_test_name( 'emp.mining_settings - Weight < 0' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
@ -114,6 +127,16 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'emp.mining_settings - Weight > 4' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , 5
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT * FROM finish( );
ROLLBACK;

View file

@ -1,5 +1,5 @@
/*
* Test constraints and foreign keys on emp.mining_settings
* Test constraints and foreign keys on emp.planet_mining_settings
*/
BEGIN;
@ -20,10 +20,10 @@ BEGIN;
-- No provider for testResource2 on testPlanet2
/****** TESTS BEGIN HERE ******/
SELECT plan( 14 );
SELECT plan( 17 );
SELECT diag_test_name( 'Valid empire planet mining settings record' );
SELECT diag_test_name( 'emp.planet_mining_settings - Valid record' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -34,11 +34,11 @@ BEGIN;
);
SELECT lives_ok( '_test_this' );
SELECT diag_test_name( 'Duplicate empire planet mining settings record' );
SELECT diag_test_name( 'emp.planet_mining_settings - Duplicate record' );
SELECT throws_ok( '_test_this' , 23505 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining settings records with different types' );
SELECT diag_test_name( 'emp.planet_mining_settings - Different types' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -50,7 +50,7 @@ BEGIN;
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining settings records with different empires' );
SELECT diag_test_name( 'emp.planet_mining_settings - Different empires' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -62,7 +62,7 @@ BEGIN;
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining settings records with different planets' );
SELECT diag_test_name( 'emp.planet_mining_settings - Different planets' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -73,10 +73,25 @@ BEGIN;
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
DELETE FROM emp.mining_settings;
DELETE FROM emp.planet_mining_settings;
SELECT diag_test_name( 'emp.planet_mining_settings - Valid record with default weight' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id , resource_name_id
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
_get_string( 'testResource1' )
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'emp.planet_mining_settings - Default weight = 2' );
SELECT is( emppmset_weight , 2 ) FROM emp.planet_mining_settings;
DELETE FROM emp.planet_mining_settings;
SELECT diag_test_name( 'Empire planet mining setting record with NULL empire identifier' );
SELECT diag_test_name( 'emp.planet_mining_settings - NULL empire identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -88,7 +103,7 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with invalid empire identifier' );
SELECT diag_test_name( 'emp.planet_mining_settings - Invalid empire identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -101,7 +116,7 @@ BEGIN;
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with NULL planet identifier' );
SELECT diag_test_name( 'emp.planet_mining_settings - NULL planet identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -113,7 +128,7 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with invalid planet identifier' );
SELECT diag_test_name( 'emp.planet_mining_settings - Invalid planet identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -126,7 +141,7 @@ BEGIN;
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with NULL resource identifier' );
SELECT diag_test_name( 'emp.planet_mining_settings - NULL resource identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -138,7 +153,7 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with invalid resource identifier' );
SELECT diag_test_name( 'emp.planet_mining_settings - Invalid resource identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -151,7 +166,7 @@ BEGIN;
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with invalid resource provider identifier' );
SELECT diag_test_name( 'emp.planet_mining_settings - Invalid resource provider identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -164,7 +179,7 @@ BEGIN;
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with NULL weight' );
SELECT diag_test_name( 'emp.planet_mining_settings - NULL weight' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -176,7 +191,7 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with weight < 0' );
SELECT diag_test_name( 'emp.planet_mining_settings - Weight < 0' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
@ -188,6 +203,18 @@ BEGIN;
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'emp.planet_mining_settings - Weight > 4' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
_get_string( 'testResource1' ) , 5
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT * FROM finish( );
ROLLBACK;