diff --git a/legacyworlds-server-beans-bt/pom.xml b/legacyworlds-server-beans-bt/pom.xml index 378a9a5..152da94 100644 --- a/legacyworlds-server-beans-bt/pom.xml +++ b/legacyworlds-server-beans-bt/pom.xml @@ -15,6 +15,11 @@ xstream + + postgresql + postgresql + + legacyworlds-server-beans-bt diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireSummaryBean.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireSummaryBean.java index a6ec5f8..2cc7d8d 100644 --- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireSummaryBean.java +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireSummaryBean.java @@ -21,7 +21,9 @@ import com.deepclone.lw.beans.bt.es.data.MovementInformation; import com.deepclone.lw.beans.bt.es.data.PlanetInformation; import com.deepclone.lw.beans.bt.es.data.QueueInformation; import com.deepclone.lw.beans.bt.es.data.QueueItemInformation; +import com.deepclone.lw.beans.bt.es.data.ResearchGraphInformation; import com.deepclone.lw.beans.bt.es.data.ResearchInformation; +import com.deepclone.lw.beans.bt.es.data.ResearchLineInformation; import com.deepclone.lw.beans.bt.es.data.ResourceDeltaInformation; import com.deepclone.lw.beans.bt.es.data.ResourceProviderInformation; import com.deepclone.lw.beans.bt.es.data.ShipsInformation; @@ -122,8 +124,8 @@ public class EmpireSummaryBean AccountInformation.class , AllianceInformation.class , BuildingsInformation.class , DebugInformation.class , EmpireInformation.class , FleetInformation.class , MovementInformation.class , PlanetInformation.class , QueueInformation.class , QueueItemInformation.class , - ResearchInformation.class , ResourceDeltaInformation.class , ResourceProviderInformation.class , - ShipsInformation.class , SystemInformation.class + ResearchLineInformation.class , ResearchGraphInformation.class , ResourceDeltaInformation.class , + ResourceProviderInformation.class , ShipsInformation.class , SystemInformation.class } ); this.mMainInfo = new DebugInformationMapper( ); diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResearchInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResearchInformationMapper.java index c2cc5da..09a6ce7 100644 --- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResearchInformationMapper.java +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResearchInformationMapper.java @@ -4,9 +4,12 @@ package com.deepclone.lw.beans.bt.es; import java.sql.ResultSet; import java.sql.SQLException; +import org.postgresql.util.PGobject; import org.springframework.jdbc.core.RowMapper; +import com.deepclone.lw.beans.bt.es.data.ResearchGraphInformation; import com.deepclone.lw.beans.bt.es.data.ResearchInformation; +import com.deepclone.lw.beans.bt.es.data.TechnologyState; @@ -14,8 +17,8 @@ import com.deepclone.lw.beans.bt.es.data.ResearchInformation; * Research information row mapper * *

- * This class maps rows from bugs.dump_research_view into {@link ResearchInformation} - * instances. + * This class maps rows from bugs.dump_research_view into + * {@link ResearchGraphInformation} instances. * * @author E. Benoît * @@ -28,17 +31,19 @@ final class ResearchInformationMapper * Map a bugs.dump_research_view row * *

- * Create a {@link ResearchInformation} instance from the row's contents. + * Create a {@link ResearchGraphInformation} instance from the row's contents. */ @Override public ResearchInformation mapRow( ResultSet rs , int rowNum ) throws SQLException { - ResearchInformation ri = new ResearchInformation( ); - ri.setId( rs.getInt( "line_id" ) ); - ri.setCurrentLevel( rs.getInt( "level" ) ); - ri.setLevelName( rs.getString( "name" ) ); - ri.setAccumulated( rs.getDouble( "accumulated" ) ); + ResearchGraphInformation ri = new ResearchGraphInformation( ); + ri.setName( rs.getString( "name" ) ); + ri.setState( TechnologyState.valueOf( ( (PGobject) rs.getObject( "state" ) ).toString( ) ) ); + if ( ri.getState( ) == TechnologyState.RESEARCH ) { + ri.setPoints( rs.getDouble( "points" ) ); + ri.setPriority( rs.getInt( "priority" ) ); + } return ri; } } \ No newline at end of file diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/DebugInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/DebugInformation.java index 2959182..ab6c15f 100644 --- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/DebugInformation.java +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/DebugInformation.java @@ -2,7 +2,7 @@ package com.deepclone.lw.beans.bt.es.data; import java.io.Serializable; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import com.thoughtworks.xstream.annotations.XStreamAlias; @@ -28,13 +28,13 @@ public class DebugInformation private EmpireInformation empire = new EmpireInformation( ); @XStreamAlias( "research" ) - private List< ResearchInformation > research = new LinkedList< ResearchInformation >( ); + private List< ResearchInformation > research = new ArrayList< ResearchInformation >( ); @XStreamAlias( "planets" ) - private List< PlanetInformation > planets = new LinkedList< PlanetInformation >( ); + private List< PlanetInformation > planets = new ArrayList< PlanetInformation >( ); @XStreamAlias( "fleets" ) - private List< FleetInformation > fleets = new LinkedList< FleetInformation >( ); + private List< FleetInformation > fleets = new ArrayList< FleetInformation >( ); public int getVersion( ) diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/PlanetInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/PlanetInformation.java index bd60545..a03f60c 100644 --- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/PlanetInformation.java +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/PlanetInformation.java @@ -2,7 +2,7 @@ package com.deepclone.lw.beans.bt.es.data; import java.io.Serializable; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import com.thoughtworks.xstream.annotations.XStreamAlias; @@ -59,7 +59,7 @@ public class PlanetInformation /** List of buildings */ @XStreamAlias( "buildings" ) - private final List< BuildingsInformation > buildings = new LinkedList< BuildingsInformation >( ); + private final List< BuildingsInformation > buildings = new ArrayList< BuildingsInformation >( ); /** Civilian construction queue */ @XStreamAlias( "civ-queue" ) @@ -71,11 +71,11 @@ public class PlanetInformation /** Planet resource deltas */ @XStreamImplicit - private final LinkedList< ResourceDeltaInformation > resourceDeltas = new LinkedList< ResourceDeltaInformation >( ); + private final ArrayList< ResourceDeltaInformation > resourceDeltas = new ArrayList< ResourceDeltaInformation >( ); /** List of resource providers */ @XStreamImplicit( itemFieldName = "resource-provider" ) - private final LinkedList< ResourceProviderInformation > resourceProviders = new LinkedList< ResourceProviderInformation >( ); + private final ArrayList< ResourceProviderInformation > resourceProviders = new ArrayList< ResourceProviderInformation >( ); /** @return the planet's identifier */ @@ -195,14 +195,14 @@ public class PlanetInformation /** @return the list of resource delta records */ - public LinkedList< ResourceDeltaInformation > getResourceDeltas( ) + public ArrayList< ResourceDeltaInformation > getResourceDeltas( ) { return this.resourceDeltas; } /** @return the list of resource provider records */ - public LinkedList< ResourceProviderInformation > getResourceProviders( ) + public ArrayList< ResourceProviderInformation > getResourceProviders( ) { return this.resourceProviders; } diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchGraphInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchGraphInformation.java new file mode 100644 index 0000000..8f9e137 --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchGraphInformation.java @@ -0,0 +1,136 @@ +package com.deepclone.lw.beans.bt.es.data; + + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamAsAttribute; + + + +/** + * Technology from the technology graph and associated state information + * + *

+ * This class represents the state of a technology from the B6M2+ technology graph for the empire + * being dumped. + * + * @author E. Benoît + */ +@SuppressWarnings( "serial" ) +@XStreamAlias( "technology" ) +public class ResearchGraphInformation + extends ResearchInformation +{ + + /** The technology's name */ + @XStreamAsAttribute + private String name; + + /** The technology's state */ + @XStreamAsAttribute + private TechnologyState state; + + /** + * The amount of accumulated research points, or null if the technology has been + * researched + */ + @XStreamAsAttribute + private Double points; + + /** The research priority, or null if the technology has been researched */ + @XStreamAsAttribute + private Integer priority; + + + /** + * Gets the technology's name. + * + * @return the technology's name + */ + public String getName( ) + { + return this.name; + } + + + /** + * Sets the technology's name. + * + * @param name + * the technology's new name + */ + public void setName( String name ) + { + this.name = name; + } + + + /** + * Gets the technology's state. + * + * @return the technology's state + */ + public TechnologyState getState( ) + { + return this.state; + } + + + /** + * Sets the technology's state. + * + * @param state + * the technology's new state + */ + public void setState( TechnologyState state ) + { + this.state = state; + } + + + /** + * Gets the amount of accumulated research points + * + * @return the amount of accumulated research points, or null if the technology has + * been researched + */ + public Double getPoints( ) + { + return this.points; + } + + + /** + * Sets the amount of accumulated research points + * + * @param points + * the amount of accumulated research points + */ + public void setPoints( Double points ) + { + this.points = points; + } + + + /** + * Gets the research priority + * + * @return the research priority, or null if the technology has been researched + */ + public Integer getPriority( ) + { + return this.priority; + } + + + /** + * Sets the research priority + * + * @param priority + * the new research priority + */ + public void setPriority( Integer priority ) + { + this.priority = priority; + } + +} diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchInformation.java index fc4746c..4465b2f 100644 --- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchInformation.java +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchInformation.java @@ -3,81 +3,23 @@ package com.deepclone.lw.beans.bt.es.data; import java.io.Serializable; -import com.thoughtworks.xstream.annotations.XStreamAlias; -import com.thoughtworks.xstream.annotations.XStreamAsAttribute; - -@XStreamAlias( "research-line" ) -public class ResearchInformation +/** + * Empty, base research record + * + *

+ * This class used to contain B6M1 research line entries; however, in order to support B6M2 + * technologies while maintaining XML compatibility, it has been replaced with an empty class which + * servces as the base class for both old and new records. + * + * @author E. Benoît + * + */ +@SuppressWarnings( "serial" ) +public abstract class ResearchInformation implements Serializable { - - private static final long serialVersionUID = 1L; - - @XStreamAsAttribute - @XStreamAlias( "line") - private int id; - - @XStreamAsAttribute - @XStreamAlias( "level") - private int currentLevel; - - @XStreamAsAttribute - @XStreamAlias( "name") - private String levelName; - - @XStreamAsAttribute - @XStreamAlias( "accumulated-points") - private double accumulated; - - - public int getId( ) - { - return id; - } - - - public void setId( int id ) - { - this.id = id; - } - - - public int getCurrentLevel( ) - { - return currentLevel; - } - - - public void setCurrentLevel( int currentLevel ) - { - this.currentLevel = currentLevel; - } - - - public String getLevelName( ) - { - return levelName; - } - - - public void setLevelName( String levelName ) - { - this.levelName = levelName; - } - - - public double getAccumulated( ) - { - return accumulated; - } - - - public void setAccumulated( double accumulated ) - { - this.accumulated = accumulated; - } - + // EMPTY } diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchLineInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchLineInformation.java new file mode 100644 index 0000000..392ee79 --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchLineInformation.java @@ -0,0 +1,137 @@ +package com.deepclone.lw.beans.bt.es.data; + + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamAsAttribute; + + + +/** + * Research line information + * + *

+ * This class defines data stored in the dumps for B6M1 research lines. It is no longer actively + * used as of B6M2, but is kept around so the XML files can still be used if necessary. + * + * @author E. Benoît + */ +@XStreamAlias( "research-line" ) +public class ResearchLineInformation + extends ResearchInformation +{ + + private static final long serialVersionUID = 1L; + + /** Identifier of the technology line */ + @XStreamAsAttribute + @XStreamAlias( "line" ) + private int id; + + /** Current level for that line */ + @XStreamAsAttribute + @XStreamAlias( "level" ) + private int currentLevel; + + /** Name of the last level */ + @XStreamAsAttribute + @XStreamAlias( "name" ) + private String levelName; + + /** Accumulated points towards the next level */ + @XStreamAsAttribute + @XStreamAlias( "accumulated-points" ) + private double accumulated; + + + /** + * Gets the identifier of the technology line. + * + * @return the identifier of the technology line + */ + public int getId( ) + { + return this.id; + } + + + /** + * Sets the identifier of the technology line. + * + * @param id + * the new identifier of the technology line + */ + public void setId( int id ) + { + this.id = id; + } + + + /** + * Gets the current level for that line. + * + * @return the current level for that line + */ + public int getCurrentLevel( ) + { + return this.currentLevel; + } + + + /** + * Sets the current level for that line. + * + * @param currentLevel + * the new level for that line + */ + public void setCurrentLevel( int currentLevel ) + { + this.currentLevel = currentLevel; + } + + + /** + * Gets the name of the last level. + * + * @return the name of the last level + */ + public String getLevelName( ) + { + return this.levelName; + } + + + /** + * Sets the name of the last level. + * + * @param levelName + * the new name of the last level + */ + public void setLevelName( String levelName ) + { + this.levelName = levelName; + } + + + /** + * Gets the accumulated points towards the next level. + * + * @return the accumulated points towards the next level + */ + public double getAccumulated( ) + { + return this.accumulated; + } + + + /** + * Sets the accumulated points towards the next level. + * + * @param accumulated + * the new accumulated points towards the next level + */ + public void setAccumulated( double accumulated ) + { + this.accumulated = accumulated; + } + +} diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/TechnologyState.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/TechnologyState.java new file mode 100644 index 0000000..3684b61 --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/TechnologyState.java @@ -0,0 +1,20 @@ +package com.deepclone.lw.beans.bt.es.data; + + +/** + * State of a (B6M2+) technology + * + * @author E. Benoît + */ +public enum TechnologyState { + + /** The technology is being researched */ + RESEARCH , + + /** The technology needs to be implemented */ + PENDING , + + /** The technology has been researched and implemented */ + KNOWN + +} diff --git a/legacyworlds-server-beans-system/src/main/java/com/deepclone/lw/beans/sys/ConstantsRegistrarBean.java b/legacyworlds-server-beans-system/src/main/java/com/deepclone/lw/beans/sys/ConstantsRegistrarBean.java index 13fa90f..5a0cf11 100644 --- a/legacyworlds-server-beans-system/src/main/java/com/deepclone/lw/beans/sys/ConstantsRegistrarBean.java +++ b/legacyworlds-server-beans-system/src/main/java/com/deepclone/lw/beans/sys/ConstantsRegistrarBean.java @@ -103,7 +103,7 @@ public class ConstantsRegistrarBean // Work and income String[] wcNames = { "population" , "factory" , "strikeEffect" , "wuPerPopUnit" , "destructionRecovery" , "destructionWork" , - "rpPerPopUnit" , "cancelRecovery" + "cancelRecovery" }; for ( int i = 0 ; i < wcNames.length ; i++ ) { wcNames[ i ] = "game.work." + wcNames[ i ]; @@ -121,10 +121,8 @@ public class ConstantsRegistrarBean defs.add( new ConstantDefinition( wcNames[ 4 ] , cat , cDesc , 0.1 , 0.01 , 0.99 ) ); cDesc = "Proportion of a building's construction work units required to destroy it"; defs.add( new ConstantDefinition( wcNames[ 5 ] , cat , cDesc , 0.25 , 0.01 , 1.0 ) ); - cDesc = "Research points per population unit."; - defs.add( new ConstantDefinition( wcNames[ 6 ] , cat , cDesc , 0.50 , 0.01 , true ) ); cDesc = "Proportion of queue investments that is recovered when flushing the queue."; - defs.add( new ConstantDefinition( wcNames[ 7 ] , cat , cDesc , 0.1 , 0.01 , 1.0 ) ); + defs.add( new ConstantDefinition( wcNames[ 6 ] , cat , cDesc , 0.1 , 0.01 , 1.0 ) ); // Research String[] rcNames = { @@ -158,8 +156,6 @@ public class ConstantsRegistrarBean defs.add( new ConstantDefinition( "vacation.cost" , "Vacation mode" , cDesc , 3.0 , 2.0 , 20.0 ) ); cDesc = "Income/upkeep divider used when vacation mode is active."; defs.add( new ConstantDefinition( "vacation.cashDivider" , "Vacation mode" , cDesc , 3.0 , 1.1 , 10.0 ) ); - cDesc = "Research points divider used when vacation mode is active."; - defs.add( new ConstantDefinition( "vacation.researchDivider" , "Vacation mode" , cDesc , 10.0 , 1.1 , 50.0 ) ); // Map names cDesc = "Minimal delay between map object renaming."; diff --git a/legacyworlds-server-data/db-structure/parts/030-data/080-techs.sql b/legacyworlds-server-data/db-structure/parts/030-data/080-techs.sql index de20289..2c77522 100644 --- a/legacyworlds-server-data/db-structure/parts/030-data/080-techs.sql +++ b/legacyworlds-server-data/db-structure/parts/030-data/080-techs.sql @@ -161,56 +161,3 @@ ALTER TABLE defs.techdep_cache REFERENCES defs.techdep_cache( technology_name_id , tdcache_reverse , tdcache_id ) ON DELETE CASCADE; - - -/* - * Old B6M1 research system below. - */ - --- --- Technology lines --- - -CREATE TABLE tech.lines( - name_id INT NOT NULL PRIMARY KEY , - description_id INT NOT NULL -); - -CREATE INDEX idx_lines_description - ON tech.lines (description_id); - -ALTER TABLE tech.lines - ADD CONSTRAINT fk_lines_name - FOREIGN KEY (name_id) REFERENCES defs.strings , - ADD CONSTRAINT fk_lines_description - FOREIGN KEY (description_id) REFERENCES defs.strings; - - --- --- Technology levels --- - -CREATE TABLE tech.levels( - id SERIAL NOT NULL PRIMARY KEY , - line_id INT NOT NULL , - level INT NOT NULL CHECK( level > 0 ) , - name_id INT NOT NULL , - description_id INT NOT NULL , - points INT NOT NULL CHECK( points > 0 ) , - cost INT NOT NULL CHECK( cost > 0 ) -); - -CREATE UNIQUE INDEX idx_levels_linelevel - ON tech.levels (line_id, level); -CREATE INDEX idx_levels_name - ON tech.levels (name_id); -CREATE INDEX idx_levels_description - ON tech.levels (description_id); - -ALTER TABLE tech.levels - ADD CONSTRAINT fk_levels_line - FOREIGN KEY (line_id) REFERENCES tech.lines , - ADD CONSTRAINT fk_levels_name - FOREIGN KEY (name_id) REFERENCES defs.strings , - ADD CONSTRAINT fk_levels_description - FOREIGN KEY (description_id) REFERENCES defs.strings; diff --git a/legacyworlds-server-data/db-structure/parts/030-data/090-buildables.sql b/legacyworlds-server-data/db-structure/parts/030-data/090-buildables.sql index 11eb8a2..9fd997d 100644 --- a/legacyworlds-server-data/db-structure/parts/030-data/090-buildables.sql +++ b/legacyworlds-server-data/db-structure/parts/030-data/090-buildables.sql @@ -32,25 +32,6 @@ ALTER TABLE tech.buildables FOREIGN KEY (technology_name_id) REFERENCES defs.technologies; --- --- Requirements --- -CREATE TABLE tech.buildable_requirements( - buildable_id INT NOT NULL , - level_id INT NOT NULL , - PRIMARY KEY( buildable_id , level_id ) -); - -CREATE INDEX idx_buildablereqs_level - ON tech.buildable_requirements( level_id ); - -ALTER TABLE tech.buildable_requirements - ADD CONSTRAINT fk_buildablereqs_buildable - FOREIGN KEY (buildable_id) REFERENCES tech.buildables , - ADD CONSTRAINT fk_buildablereqs_level - FOREIGN KEY (level_id) REFERENCES tech.levels; - - -- -- Buildings -- diff --git a/legacyworlds-server-data/db-structure/parts/030-data/110-empires.sql b/legacyworlds-server-data/db-structure/parts/030-data/110-empires.sql index 4480ff9..91a7c22 100644 --- a/legacyworlds-server-data/db-structure/parts/030-data/110-empires.sql +++ b/legacyworlds-server-data/db-structure/parts/030-data/110-empires.sql @@ -146,32 +146,6 @@ ALTER TABLE emp.technologies_v2 FOREIGN KEY ( technology_name_id ) REFERENCES defs.technologies; - --- --- Empire technologies --- - -CREATE TABLE emp.technologies( - empire_id INT NOT NULL , - line_id INT NOT NULL , - level INT NOT NULL DEFAULT 1 - CHECK( level > 0 ) , - accumulated REAL NOT NULL DEFAULT 0 - CHECK( accumulated >= 0 ), - PRIMARY KEY( empire_id , line_id ) -); - -CREATE INDEX idx_technologies_line - ON emp.technologies (line_id); - -ALTER TABLE emp.technologies - ADD CONSTRAINT fk_technologies_empire - FOREIGN KEY (empire_id) REFERENCES emp.empires - ON DELETE CASCADE , - ADD CONSTRAINT fk_technologies_line - FOREIGN KEY (line_id) REFERENCES tech.lines; - - -- -- Empire planets -- diff --git a/legacyworlds-server-data/db-structure/parts/030-data/170-events.sql b/legacyworlds-server-data/db-structure/parts/030-data/170-events.sql index 186a032..87ce1fc 100644 --- a/legacyworlds-server-data/db-structure/parts/030-data/170-events.sql +++ b/legacyworlds-server-data/db-structure/parts/030-data/170-events.sql @@ -83,28 +83,6 @@ ALTER TABLE events.bqe_locations FOREIGN KEY (location_id) REFERENCES verse.planets; - --- --- Empire events --- - -CREATE TABLE events.empire_events( - event_id BIGINT NOT NULL PRIMARY KEY , - technology_id INT NOT NULL -); - -CREATE INDEX idx_empevents_tech - ON events.empire_events (technology_id); - -ALTER TABLE events.empire_events - ADD CONSTRAINT fk_empevents_event - FOREIGN KEY (event_id) REFERENCES events.events - ON DELETE CASCADE, - ADD CONSTRAINT fk_empevents_tech - FOREIGN KEY (technology_id) REFERENCES tech.levels; - - - -- -- Fleet events -- 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 58ee6ee..271609c 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 @@ -404,95 +404,6 @@ CREATE VIEW tech.ships_view ON b.name_id = s.buildable_id; - --- --- Creates or updates a technology line --- --- Parameters: --- tln Tech line name --- tld Tech line description --- - -CREATE OR REPLACE FUNCTION tech.uoc_line( tln TEXT , tld TEXT ) - RETURNS VOID - STRICT - VOLATILE - SECURITY DEFINER - AS $$ -DECLARE - nid INT; - did INT; -BEGIN - -- Get string identifiers - SELECT INTO nid id FROM defs.strings WHERE name = tln; - SELECT INTO did id FROM defs.strings WHERE name = tld; - - -- Try creating / updating - BEGIN - INSERT INTO tech.lines ( name_id , description_id ) - VALUES ( nid , did ); - EXCEPTION - WHEN unique_violation THEN - UPDATE tech.lines SET description_id = did - WHERE name_id = nid; - END; -END; -$$ LANGUAGE plpgsql; - -GRANT EXECUTE ON FUNCTION tech.uoc_line( TEXT , TEXT ) TO :dbuser; - - - --- --- Creates or updates a technology level --- --- Parameters: --- tln Tech line name --- lv Level --- lvn Level name --- lvd Level description --- lvp Points --- lvc Cost --- - -CREATE OR REPLACE FUNCTION tech.uoc_level( tln TEXT , lv INT , lvn TEXT , lvd TEXT , lvp INT , lvc INT ) - RETURNS VOID - STRICT - VOLATILE - SECURITY DEFINER - AS $$ -DECLARE - lid INT; - nid INT; - did INT; -BEGIN - -- Get tech line - SELECT INTO lid t.name_id - FROM tech.lines t - INNER JOIN defs.strings s - ON s.id = t.name_id - WHERE s.name = tln; - - -- Get name / description IDs - SELECT INTO nid id FROM defs.strings WHERE name = lvn; - SELECT INTO did id FROM defs.strings WHERE name = lvd; - - -- Create or update the level - BEGIN - INSERT INTO tech.levels ( line_id , level , name_id , description_id , points , cost ) - VALUES ( lid , lv , nid , did , lvp , lvc ); - EXCEPTION - WHEN unique_violation THEN - UPDATE tech.levels SET name_id = nid , description_id = did , points = lvp , cost = lvc - WHERE line_id = lid AND level = lv; - END; -END; -$$ LANGUAGE plpgsql; - -GRANT EXECUTE ON FUNCTION tech.uoc_level( TEXT , INT , TEXT , TEXT , INT , INT ) to :dbuser; - - - -- -- Creates or updates a buildable definition -- 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 16443aa..7b1e6ad 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 @@ -105,48 +105,6 @@ GRANT EXECUTE ON FUNCTION emp.get_current( INT ) TO :dbuser; --- --- Implements a technology (OLD VERSION) --- - -CREATE OR REPLACE FUNCTION emp.implement_tech( e_id INT , l_id INT ) - RETURNS VOID - STRICT VOLATILE - SECURITY DEFINER - AS $$ -DECLARE - e_cash REAL; - lev INT; - cost REAL; -BEGIN - SELECT INTO e_cash , lev , cost e.cash , et.level , tl.cost - FROM emp.empires e - INNER JOIN emp.technologies et - ON et.line_id = l_id AND et.empire_id = e.name_id - INNER JOIN tech.levels tl - ON tl.line_id = l_id AND tl.level = et.level - AND tl.points = floor( et.accumulated ) - AND tl.cost <= e.cash - WHERE e.name_id = e_id - FOR UPDATE OF e , et; - - IF NOT FOUND THEN - RETURN; - END IF; - - UPDATE emp.empires - SET cash = e_cash - cost - WHERE name_id = e_id; - UPDATE emp.technologies - SET level = lev + 1 , accumulated = 0 - WHERE empire_id = e_id AND line_id = l_id; -END; -$$ LANGUAGE plpgsql; - -GRANT EXECUTE ON FUNCTION emp.implement_tech( INT , INT ) TO :dbuser; - - - -- -- Add an enemy empire -- @@ -628,50 +586,6 @@ CREATE VIEW emp.overview GRANT SELECT ON emp.overview TO :dbuser; --- --- Empire tech lines --- - -CREATE VIEW emp.tech_lines_view - AS SELECT e.name_id AS empire , tl.name_id AS tech_line , - t1.translated_string AS name , - t2.translated_string AS description - FROM emp.empires e - INNER JOIN emp.technologies et ON et.empire_id = e.name_id - INNER JOIN tech.lines tl ON tl.name_id = et.line_id - INNER JOIN naming.empire_names en ON en.id = e.name_id - INNER JOIN users.credentials c ON c.address_id = en.owner_id - INNER JOIN defs.translations t1 ON t1.string_id = tl.name_id AND t1.lang_id = c.language_id - INNER JOIN defs.translations t2 ON t2.string_id = tl.description_id AND t2.lang_id = c.language_id - ORDER BY t1.translated_string; - -GRANT SELECT ON emp.tech_lines_view TO :dbuser; - - --- --- Empire technologies --- - -CREATE VIEW emp.technologies_view - AS SELECT e.name_id AS empire , tl.name_id AS tech_line , - t1.translated_string AS name , - t2.translated_string AS description , - ( et.level > tlv.level ) AS implemented , - floor( 100 * et.accumulated / tlv.points ) AS progress , - tlv.cost AS cost - FROM emp.empires e - INNER JOIN emp.technologies et ON et.empire_id = e.name_id - INNER JOIN tech.lines tl ON tl.name_id = et.line_id - INNER JOIN tech.levels tlv ON tlv.line_id = tl.name_id AND tlv.level <= et.level - INNER JOIN naming.empire_names en ON en.id = e.name_id - INNER JOIN users.credentials c ON c.address_id = en.owner_id - INNER JOIN defs.translations t1 ON t1.string_id = tlv.name_id AND t1.lang_id = c.language_id - INNER JOIN defs.translations t2 ON t2.string_id = tlv.description_id AND t2.lang_id = c.language_id - ORDER BY tl.name_id , tlv.level; - -GRANT SELECT ON emp.technologies_view TO :dbuser; - - -- -- Enemy lists -- diff --git a/legacyworlds-server-data/db-structure/parts/040-functions/170-events.sql b/legacyworlds-server-data/db-structure/parts/040-functions/170-events.sql index 24f5e41..9e63f90 100644 --- a/legacyworlds-server-data/db-structure/parts/040-functions/170-events.sql +++ b/legacyworlds-server-data/db-structure/parts/040-functions/170-events.sql @@ -228,32 +228,6 @@ $$ LANGUAGE plpgsql; --- --- Creates an event for a technology's availability --- --- Parameters: --- e_id Empire identifier --- t_id Technology identifier --- - -CREATE OR REPLACE FUNCTION events.tech_ready_event( e_id INT , t_id INT ) - RETURNS VOID - STRICT VOLATILE - SECURITY INVOKER - AS $$ -DECLARE - evt_id BIGINT; -BEGIN - INSERT INTO events.events ( empire_id , tick , evt_type , evt_subtype , status ) - VALUES ( e_id , sys.get_tick( ) - 1 , 'EMPIRE' , 0 , 'READY' ) - RETURNING event_id INTO evt_id; - INSERT INTO events.empire_events ( event_id , technology_id ) - VALUES ( evt_id , t_id ); -END; -$$ LANGUAGE plpgsql; - - - -- -- Creates an event for start/end of debt -- @@ -856,17 +830,6 @@ CREATE VIEW events.queue_events_view GRANT SELECT ON events.queue_events_view TO :dbuser; -CREATE VIEW events.empire_events_view - AS SELECT e.event_id AS id , e.evt_type , e.evt_subtype , e.tick , e.real_time , s.name AS technology - FROM events.events e - LEFT OUTER JOIN events.empire_events ed USING (event_id) - LEFT OUTER JOIN tech.levels tl ON tl.id = ed.technology_id - LEFT OUTER JOIN defs.strings s ON s.id = tl.name_id - WHERE e.evt_type = 'EMPIRE'; - -GRANT SELECT ON events.empire_events_view TO :dbuser; - - CREATE VIEW events.fleets_events_view AS SELECT e.event_id AS id , e.evt_type , e.evt_subtype , e.tick , e.real_time , ed.* , s.x , s.y , p.orbit diff --git a/legacyworlds-server-data/db-structure/parts/040-functions/200-bugs.sql b/legacyworlds-server-data/db-structure/parts/040-functions/200-bugs.sql index 773e718..c339285 100644 --- a/legacyworlds-server-data/db-structure/parts/040-functions/200-bugs.sql +++ b/legacyworlds-server-data/db-structure/parts/040-functions/200-bugs.sql @@ -1196,11 +1196,10 @@ GRANT SELECT ON bugs.dump_main_view TO :dbuser; CREATE VIEW bugs.dump_research_view - AS SELECT et.empire_id , et.line_id AS line_id , et.level AS level , - tst.name AS name , et.accumulated AS accumulated - FROM emp.technologies et - LEFT OUTER JOIN tech.levels tlv ON tlv.line_id = et.line_id AND tlv.level = et.level - LEFT OUTER JOIN defs.strings tst ON tst.id = tlv.name_id; + AS SELECT et.empire_id , tst.name AS name , et.emptech_state AS state , + et.emptech_points AS points , et.emptech_priority AS priority + FROM emp.technologies_v2 et + INNER JOIN defs.strings tst ON tst.id = et.technology_name_id; GRANT SELECT ON bugs.dump_research_view TO :dbuser; diff --git a/legacyworlds-server-main/data/techs.xml b/legacyworlds-server-main/data/techs.xml deleted file mode 100644 index aef6fc6..0000000 --- a/legacyworlds-server-main/data/techs.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/legacyworlds-server-main/data/techs.xsd b/legacyworlds-server-main/data/techs.xsd deleted file mode 100644 index 84698c3..0000000 --- a/legacyworlds-server-main/data/techs.xsd +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/legacyworlds-server-main/src/main/java/com/deepclone/lw/cli/ImportTechs.java b/legacyworlds-server-main/src/main/java/com/deepclone/lw/cli/ImportTechs.java deleted file mode 100644 index bc74f83..0000000 --- a/legacyworlds-server-main/src/main/java/com/deepclone/lw/cli/ImportTechs.java +++ /dev/null @@ -1,217 +0,0 @@ -package com.deepclone.lw.cli; - - -import java.io.*; -import java.sql.Types; -import java.util.List; - -import javax.sql.DataSource; - -import org.apache.log4j.Logger; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.context.support.FileSystemXmlApplicationContext; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.TransactionCallback; -import org.springframework.transaction.support.TransactionTemplate; - -import com.deepclone.lw.utils.StoredProc; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.annotations.XStreamAlias; -import com.thoughtworks.xstream.annotations.XStreamAsAttribute; -import com.thoughtworks.xstream.annotations.XStreamImplicit; - - - -public class ImportTechs - extends CLITool -{ - - private final Logger logger = Logger.getLogger( ImportTechs.class ); - - @XStreamAlias( "technologies" ) - @SuppressWarnings( "serial" ) - public static class Techs - implements Serializable - { - @XStreamImplicit( itemFieldName = "tech-line" ) - public List< TechLine > lines; - } - - @SuppressWarnings( "serial" ) - public static class TechLine - implements Serializable - { - @XStreamAsAttribute - public String name; - - @XStreamAsAttribute - public String description; - - @XStreamImplicit( itemFieldName = "level" ) - public List< TechLevel > levels; - } - - @SuppressWarnings( "serial" ) - public static class TechLevel - implements Serializable - { - @XStreamAsAttribute - public String name; - - @XStreamAsAttribute - public String description; - - @XStreamAsAttribute - public int points; - - @XStreamAsAttribute - public int cost; - } - - private File file; - private TransactionTemplate tTemplate; - private StoredProc uocLine; - private StoredProc uocLevel; - - - private XStream initXStream( ) - { - XStream xstream = new XStream( ); - xstream.processAnnotations( Techs.class ); - return xstream; - } - - - private Techs loadData( ) - { - FileInputStream fis; - try { - fis = new FileInputStream( this.file ); - } catch ( FileNotFoundException e ) { - return null; - } - - try { - XStream xstream = this.initXStream( ); - return (Techs) xstream.fromXML( fis ); - } catch ( Exception e ) { - e.printStackTrace( ); - return null; - } finally { - try { - fis.close( ); - } catch ( IOException e ) { - // EMPTY - } - } - } - - - private ClassPathXmlApplicationContext createContext( ) - { - // Load data source and Hibernate properties - String[] dataConfig = { - this.getDataSource( ) - }; - FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( dataConfig ); - ctx.refresh( ); - - // Load beans - String[] cfg = { - "configuration/transactions.xml" - }; - return new ClassPathXmlApplicationContext( cfg , true , ctx ); - } - - - private void getBeans( ApplicationContext ctx ) - { - PlatformTransactionManager tManager = ctx.getBean( PlatformTransactionManager.class ); - this.tTemplate = new TransactionTemplate( tManager ); - - DataSource dataSource = ctx.getBean( DataSource.class ); - this.uocLine = new StoredProc( dataSource , "tech" , "uoc_line" ); - this.uocLine.addParameter( "tln" , Types.VARCHAR ); - this.uocLine.addParameter( "tld" , Types.VARCHAR ); - - this.uocLevel = new StoredProc( dataSource , "tech" , "uoc_level" ); - this.uocLevel.addParameter( "tech_line" , Types.VARCHAR ); - this.uocLevel.addParameter( "level" , Types.INTEGER ); - this.uocLevel.addParameter( "name" , Types.VARCHAR ); - this.uocLevel.addParameter( "desc" , Types.VARCHAR ); - this.uocLevel.addParameter( "points" , Types.INTEGER ); - this.uocLevel.addParameter( "cost" , Types.INTEGER ); - } - - - private void importTechnologies( Techs data ) - { - for ( TechLine line : data.lines ) { - this.uocLine.execute( line.name , line.description ); - - int i = 1; - for ( TechLevel level : line.levels ) { - this.uocLevel.execute( line.name , i , level.name , level.description , level.points , level.cost ); - i++; - } - } - } - - - @Override - public void run( ) - { - final Techs data = this.loadData( ); - if ( data == null ) { - System.err.println( "could not read data" ); - return; - } - - AbstractApplicationContext ctx = this.createContext( ); - this.getBeans( ctx ); - boolean rv = this.tTemplate.execute( new TransactionCallback< Boolean >( ) { - - @Override - public Boolean doInTransaction( TransactionStatus status ) - { - boolean rv; - try { - importTechnologies( data ); - rv = true; - } catch ( RuntimeException e ) { - logger.error( e.getMessage( ) ); - rv = false; - } - if ( !rv ) { - status.setRollbackOnly( ); - } - return rv; - } - - } ); - - if ( rv ) { - this.logger.info( "Import successful" ); - } - - this.tTemplate = null; - ToolBase.destroyContext( ctx ); - } - - - @Override - public boolean setOptions( String... options ) - { - if ( options.length != 1 ) { - return false; - } - this.file = new File( options[ 0 ] ); - if ( ! ( this.file.isFile( ) && this.file.canRead( ) ) ) { - return false; - } - return true; - } -} diff --git a/legacyworlds/doc/local-deployment.txt b/legacyworlds/doc/local-deployment.txt index b31c0ff..a2a278d 100644 --- a/legacyworlds/doc/local-deployment.txt +++ b/legacyworlds/doc/local-deployment.txt @@ -39,8 +39,6 @@ from the root of the server's distribution: java -jar legacyworlds-server-main-1.0.0-0.jar \ --run-tool ImportText data/i18n-text.xml - java -jar legacyworlds-server-main-1.0.0-0.jar \ - --run-tool ImportTechs data/techs.xml java -jar legacyworlds-server-main-1.0.0-0.jar \ --run-tool ImportTechGraph data/tech-graph.xml java -jar legacyworlds-server-main-1.0.0-0.jar \