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.
This commit is contained in:
Emmanuel BENOîT 2012-02-28 12:34:59 +01:00
parent 1f3c7a9202
commit 8c0b4abd1e
2 changed files with 40 additions and 1 deletions

View file

@ -45,6 +45,14 @@ BEGIN
INSERT INTO emp.resources ( empire_id , resource_name_id ) INSERT INTO emp.resources ( empire_id , resource_name_id )
SELECT _name_id , resource_name_id FROM defs.resources; 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 resource mining quantities
UPDATE verse.planet_resources UPDATE verse.planet_resources
SET pres_income = emp.mining_compute_extraction( _update_row ) SET pres_income = emp.mining_compute_extraction( _update_row )

View file

@ -27,6 +27,28 @@ BEGIN;
100 , 0.2 , 0.5 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() /* We replace the emp.mining_get_input() and emp.mining_compute_extraction()
* functions with something we control fully. * functions with something we control fully.
*/ */
@ -49,7 +71,7 @@ BEGIN;
$$; $$;
/***** TESTS BEGIN HERE *****/ /***** TESTS BEGIN HERE *****/
SELECT plan( 8 ); SELECT plan( 9 );
SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) , SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) ,
_get_map_name( 'testPlanet1' ) , _get_map_name( 'testPlanet1' ) ,
@ -92,6 +114,15 @@ BEGIN;
FROM emp.resources FROM emp.resources
WHERE empire_id = _get_emp_name( 'testEmp1' ); 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 diag_test_name( 'emp.create_empire() - Resource mining has been updated' );
SELECT is( pres_income::DOUBLE PRECISION , 42::DOUBLE PRECISION ) SELECT is( pres_income::DOUBLE PRECISION , 42::DOUBLE PRECISION )
FROM verse.planet_resources FROM verse.planet_resources