From 8c0b4abd1e946843c3a19435dabb17215c55142a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Tue, 28 Feb 2012 12:34:59 +0100 Subject: [PATCH] Empire research initialisation * When an empire is created, all technologies that have no dependencies will be added as ongoing research with default priority and no points in the empire research table. --- .../parts/040-functions/040-empire.sql | 8 +++++ .../040-empire/010-create-empire.sql | 33 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/legacyworlds-server-data/db-structure/parts/040-functions/040-empire.sql b/legacyworlds-server-data/db-structure/parts/040-functions/040-empire.sql index a49c0d6..1c1defa 100644 --- a/legacyworlds-server-data/db-structure/parts/040-functions/040-empire.sql +++ b/legacyworlds-server-data/db-structure/parts/040-functions/040-empire.sql @@ -45,6 +45,14 @@ BEGIN INSERT INTO emp.resources ( empire_id , resource_name_id ) SELECT _name_id , resource_name_id FROM defs.resources; + -- Insert technologies that have no dependencies as research in progress + INSERT INTO emp.technologies_v2 ( empire_id , technology_name_id ) + SELECT _name_id , technology_name_id + FROM defs.technologies + LEFT OUTER JOIN defs.technology_dependencies + USING ( technology_name_id ) + WHERE techdep_id IS NULL; + -- Update resource mining quantities UPDATE verse.planet_resources SET pres_income = emp.mining_compute_extraction( _update_row ) diff --git a/legacyworlds-server-data/db-structure/tests/admin/040-functions/040-empire/010-create-empire.sql b/legacyworlds-server-data/db-structure/tests/admin/040-functions/040-empire/010-create-empire.sql index 5aa570b..c079d75 100644 --- a/legacyworlds-server-data/db-structure/tests/admin/040-functions/040-empire/010-create-empire.sql +++ b/legacyworlds-server-data/db-structure/tests/admin/040-functions/040-empire/010-create-empire.sql @@ -27,6 +27,28 @@ BEGIN; 100 , 0.2 , 0.5 ); + /* + * We also need 3 technologies (tech1, tech2 and tech3), and a chain of + * dependencies between them (i.e. tech3 -> tech2 -> tech1). Disabling + * unused fields in defs.technologies makes things easier. + */ + ALTER TABLE defs.technologies + ALTER technology_category_id DROP NOT NULL , + ALTER technology_discovery_id DROP NOT NULL , + ALTER technology_description_id DROP NOT NULL , + ALTER technology_price DROP NOT NULL , + ALTER technology_points DROP NOT NULL; + SELECT _create_test_strings( 3 , 'tech' ); + INSERT INTO defs.technologies ( technology_name_id ) + VALUES ( _get_string( 'tech1' ) ) , + ( _get_string( 'tech2' ) ) , + ( _get_string( 'tech3' ) ); + INSERT INTO defs.technology_dependencies( + technology_name_id , technology_name_id_depends + ) VALUES ( _get_string( 'tech2' ) , _get_string( 'tech1' ) ) , + ( _get_string( 'tech3' ) , _get_string( 'tech2' ) ); + + /* We replace the emp.mining_get_input() and emp.mining_compute_extraction() * functions with something we control fully. */ @@ -49,7 +71,7 @@ BEGIN; $$; /***** TESTS BEGIN HERE *****/ - SELECT plan( 8 ); + SELECT plan( 9 ); SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) , _get_map_name( 'testPlanet1' ) , @@ -92,6 +114,15 @@ BEGIN; FROM emp.resources WHERE empire_id = _get_emp_name( 'testEmp1' ); + SELECT diag_test_name( 'emp.create_empire() - Empire technologies have been initialised' ); + SELECT set_eq( $$ + SELECT technology_name_id , emptech_state::TEXT , emptech_points , emptech_priority + FROM emp.technologies_v2 + WHERE empire_id = _get_emp_name( 'testEmp1' ); + $$ , $$ VALUES( + _get_string( 'tech1' ) , 'RESEARCH' , 0.0 , 2 + ) $$ ); + SELECT diag_test_name( 'emp.create_empire() - Resource mining has been updated' ); SELECT is( pres_income::DOUBLE PRECISION , 42::DOUBLE PRECISION ) FROM verse.planet_resources