diff --git a/legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies/ResearchControllerBean.java b/legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies/ResearchControllerBean.java index c1c9388..7be0c2d 100644 --- a/legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies/ResearchControllerBean.java +++ b/legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies/ResearchControllerBean.java @@ -1,6 +1,7 @@ package com.deepclone.lw.beans.game.technologies; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -107,6 +108,8 @@ class ResearchControllerBean tech.setName( translations.get( tech.getName( ) ) ); tech.setDescription( translations.get( tech.getDescription( ) ) ); } + + tech.setBuildings( this.translateList( tech.getBuildings( ) , translations ) ); } // Add reverse dependency identifiers @@ -144,6 +147,7 @@ class ResearchControllerBean identifiers.add( tech.getName( ) ); identifiers.add( tech.getDescription( ) ); } + identifiers.addAll( tech.getBuildings( ) ); } try { @@ -154,6 +158,29 @@ class ResearchControllerBean } + /** + * Translate a list of strings + * + *
+ * This method fetches translations for a list of string identifiers. + * + * @param input + * the list of strings to translate + * @param translations + * the map of translations returned by {@link #getTranslationsFor(List, String)} + * + * @return the translated list of strings + */ + private List< String > translateList( List< String > input , Map< String , String > translations ) + { + ArrayList< String > result = new ArrayList< String >( input.size( ) ); + for ( String str : input ) { + result.add( translations.get( str ) ); + } + return result; + } + + /** * Update research priorities * diff --git a/legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies/ResearchRowMapper.java b/legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies/ResearchRowMapper.java index e69c979..8f0b19f 100644 --- a/legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies/ResearchRowMapper.java +++ b/legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies/ResearchRowMapper.java @@ -57,13 +57,39 @@ class ResearchRowMapper output.setCompletion( ratio ); output.setPriority( rs.getInt( "emptech_priority" ) ); } - - String dependencies = rs.getString( "technology_dependencies" ); - if ( ! "".equals( dependencies ) ) { - output.setDependencies( dependencies.split( "," ) ); - } + + output.setDependencies( this.splitField( rs , "technology_dependencies" ) ); + output.setBuildings( this.splitField( rs , "technology_buildings" ) ); return output; } + + /** + * Extract a comma-separated field + * + *
+ * This method accesses then extracts the contents of a comma-separated field (for example + * dependencies or unlocked buildings). + * + * @param rs + * the SQL result set + * @param field + * the field's name + * + * @return an array of strings containing the field's values + * + * @throws SQLException + * if something goes wrong while accessing the field + */ + private String[] splitField( ResultSet rs , String field ) + throws SQLException + { + String fValue = rs.getString( field ); + if ( fValue == null || "".equals( fValue ) ) { + return new String[ 0 ]; + } + return fValue.split( "," ); + } + } diff --git a/legacyworlds-server-data/db-structure/parts/040-functions/030-tech.sql b/legacyworlds-server-data/db-structure/parts/040-functions/030-tech.sql index 271609c..212bce0 100644 --- a/legacyworlds-server-data/db-structure/parts/040-functions/030-tech.sql +++ b/legacyworlds-server-data/db-structure/parts/040-functions/030-tech.sql @@ -391,6 +391,29 @@ CREATE VIEW tech.buildings_view ON b.name_id = bld.buildable_id; +/* + * Buildings / technology view + * ---------------------------- + * + * This view generates a parseable list of buildings unlocked by a technology + * for each technology. + * + * Columns: + * technology_name_id The technology's name + * technology_buildings A list of comma-separated building identifiers + */ +DROP VIEW IF EXISTS defs.technology_buildings_view CASCADE; +CREATE VIEW defs.technology_buildings_view + AS SELECT technology_name_id , + array_to_string( array_agg( _name.name ) , ',' ) AS technology_buildings + FROM defs.technologies _tech + LEFT OUTER JOIN tech.buildings_view _building + USING ( technology_name_id ) + LEFT OUTER JOIN defs.strings _name + ON _name.id = _building.name_id + GROUP BY technology_name_id; + + -- -- Ships view -- diff --git a/legacyworlds-server-data/db-structure/parts/040-functions/045-empire-research.sql b/legacyworlds-server-data/db-structure/parts/040-functions/045-empire-research.sql index 7860984..4b1e967 100644 --- a/legacyworlds-server-data/db-structure/parts/040-functions/045-empire-research.sql +++ b/legacyworlds-server-data/db-structure/parts/040-functions/045-empire-research.sql @@ -447,6 +447,8 @@ CREATE VIEW emp.research_total_weights_view * the technology is not supposed to be visible * technology_dependencies The technology's dependencies from the * dependencies view + * technology_buildings The buildings which are unlocked when the + * technology is implemented */ DROP VIEW IF EXISTS emp.technologies_v2_view CASCADE; CREATE VIEW emp.technologies_v2_view @@ -488,7 +490,13 @@ CREATE VIEW emp.technologies_v2_view ELSE NULL::INT END ) AS technology_price , - technology_dependencies + technology_dependencies , + ( CASE + WHEN emptech_visible THEN + technology_buildings + ELSE + '' + END ) AS technology_buildings FROM emp.technologies_v2 INNER JOIN emp.technology_visibility_view USING ( technology_name_id , empire_id ) @@ -496,6 +504,8 @@ CREATE VIEW emp.technologies_v2_view USING ( technology_name_id ) INNER JOIN defs.technology_dependencies_view USING ( technology_name_id ) + INNER JOIN defs.technology_buildings_view + USING ( technology_name_id ) INNER JOIN defs.strings _name_str ON _name_str.id = _tech.technology_name_id INNER JOIN defs.strings _cat_str diff --git a/legacyworlds-session/src/main/java/com/deepclone/lw/cmd/player/gdata/empire/ResearchData.java b/legacyworlds-session/src/main/java/com/deepclone/lw/cmd/player/gdata/empire/ResearchData.java index 67add05..a6f63d0 100644 --- a/legacyworlds-session/src/main/java/com/deepclone/lw/cmd/player/gdata/empire/ResearchData.java +++ b/legacyworlds-session/src/main/java/com/deepclone/lw/cmd/player/gdata/empire/ResearchData.java @@ -78,7 +78,10 @@ public class ResearchData private List< String > dependencies = new ArrayList< String >( ); /** List of identifiers of technologies that depend on the current technology. */ - private List< String > revDependencies = new LinkedList< String >( ); + private final List< String > revDependencies = new LinkedList< String >( ); + + /** List of buildings the current technology unlocks. */ + private List< String > buildings = new ArrayList< String >( ); /** @@ -320,6 +323,41 @@ public class ResearchData } + /** + * Update the list of unlocked buildings + * + * @param buildings + * the new list of buildings + */ + public void setBuildings( String[] buildings ) + { + this.buildings = Arrays.asList( buildings ); + } + + + /** + * Update the list of unlocked buildings + * + * @param buildings + * the new list of buildings + */ + public void setBuildings( List< String > buildings ) + { + this.buildings = buildings; + } + + + /** + * Gets the list of buildings the current technology unlocks. + * + * @return the list of buildings the current technology unlocks + */ + public List< String > getBuildings( ) + { + return this.buildings; + } + + /** * Research page entry comparison * diff --git a/legacyworlds-web-main/Content/Raw/WEB-INF/fm/en/types/research.ftl b/legacyworlds-web-main/Content/Raw/WEB-INF/fm/en/types/research.ftl index 7e84965..ce4a1ba 100644 --- a/legacyworlds-web-main/Content/Raw/WEB-INF/fm/en/types/research.ftl +++ b/legacyworlds-web-main/Content/Raw/WEB-INF/fm/en/types/research.ftl @@ -236,6 +236,15 @@ #if> + <#if tech.buildings?has_content> +