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 3a80b4d..11eb8a2 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
@@ -10,21 +10,26 @@
-- "Buildables"
--
CREATE TABLE tech.buildables(
- name_id INT NOT NULL PRIMARY KEY ,
- description_id INT NOT NULL ,
- cost INT NOT NULL CHECK( cost > 0 ) ,
- work INT NOT NULL CHECK( work > 0 ) ,
- upkeep INT NOT NULL CHECK( upkeep >= 0 )
+ name_id INT NOT NULL PRIMARY KEY ,
+ description_id INT NOT NULL ,
+ technology_name_id INT ,
+ cost INT NOT NULL CHECK( cost > 0 ) ,
+ work INT NOT NULL CHECK( work > 0 ) ,
+ upkeep INT NOT NULL CHECK( upkeep >= 0 )
);
CREATE INDEX idx_buildables_description
ON tech.buildables (description_id);
+CREATE INDEX idx_buildables_technology
+ ON tech.buildables ( technology_name_id );
ALTER TABLE tech.buildables
ADD CONSTRAINT fk_buildables_name
FOREIGN KEY (name_id) REFERENCES defs.strings ,
ADD CONSTRAINT fk_buildables_description
- FOREIGN KEY (description_id) REFERENCES defs.strings;
+ FOREIGN KEY (description_id) REFERENCES defs.strings ,
+ ADD CONSTRAINT fk_buildables_technology
+ FOREIGN KEY (technology_name_id) REFERENCES defs.technologies;
--
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 2a1f4be..58ee6ee 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
@@ -374,10 +374,8 @@ GRANT EXECUTE
--
CREATE VIEW tech.basic_buildables
- AS SELECT b.* FROM tech.buildables b
- LEFT OUTER JOIN tech.buildable_requirements r
- ON r.buildable_id = b.name_id
- WHERE r.buildable_id IS NULL;
+ AS SELECT * FROM tech.buildables
+ WHERE technology_name_id IS NULL;
--
@@ -385,7 +383,8 @@ CREATE VIEW tech.basic_buildables
--
CREATE VIEW tech.buildings_view
- AS SELECT b.name_id , b.description_id , b.cost , b.work , b.upkeep ,
+ AS SELECT b.name_id , b.description_id , b.technology_name_id ,
+ b.cost , b.work , b.upkeep ,
bld.workers , bld.output_type , bld.output
FROM tech.buildables b
INNER JOIN tech.buildings bld
@@ -397,7 +396,8 @@ CREATE VIEW tech.buildings_view
--
CREATE VIEW tech.ships_view
- AS SELECT b.name_id , b.description_id , b.cost , b.work , b.upkeep ,
+ AS SELECT b.name_id , b.description_id , b.technology_name_id ,
+ b.cost , b.work , b.upkeep ,
s.flight_time , s.power
FROM tech.buildables b
INNER JOIN tech.ships s
@@ -502,50 +502,47 @@ GRANT EXECUTE ON FUNCTION tech.uoc_level( TEXT , INT , TEXT , TEXT , INT , INT )
-- bdc Cost
-- bdw Work
-- bdu Upkeep
--- bdtn Dependency (name)
--- bdtl Dependency (level)
+-- _tech Technology dependency
--
-- Returns:
-- the buildable's identifier
--
-CREATE OR REPLACE FUNCTION tech.uoc_buildable( bdn TEXT , bdd TEXT , bdc INT , bdw INT , bdu INT , bdtn TEXT , bdtl INT )
+CREATE OR REPLACE FUNCTION tech.uoc_buildable( bdn TEXT , bdd TEXT , bdc INT , bdw INT , bdu INT , _tech TEXT )
RETURNS INT
STRICT
VOLATILE
SECURITY INVOKER
AS $$
DECLARE
- nid INT;
- did INT;
- tdid INT;
+ nid INT;
+ did INT;
+ _tech_id INT;
BEGIN
-- Get the various translations
SELECT INTO nid id FROM defs.strings WHERE name = bdn;
SELECT INTO did id FROM defs.strings WHERE name = bdd;
- IF bdtn <> '' THEN
- SELECT INTO tdid tl.id FROM tech.levels tl
- INNER JOIN defs.strings s
- ON s.id = tl.line_id
- WHERE s.name = bdtn AND tl.level = bdtl;
+ IF _tech <> '' THEN
+ SELECT INTO _tech_id technology_name_id
+ FROM defs.technologies
+ INNER JOIN defs.strings s
+ ON s.id = technology_name_id
+ WHERE s.name = _tech;
+ ELSE
+ _tech_id := NULL;
END IF;
-- Create or update the definition
BEGIN
- INSERT INTO tech.buildables ( name_id , description_id , cost , work , upkeep )
- VALUES ( nid , did , bdc , bdw , bdu );
+ INSERT INTO tech.buildables ( name_id , description_id , technology_name_id , cost , work , upkeep )
+ VALUES ( nid , did , _tech_id , bdc , bdw , bdu );
EXCEPTION
WHEN unique_violation THEN
- UPDATE tech.buildables SET description_id = did , cost = bdc , work = bdw , upkeep = bdu
+ UPDATE tech.buildables
+ SET description_id = did , technology_name_id = _tech_id ,
+ cost = bdc , work = bdw , upkeep = bdu
WHERE name_id = nid;
END;
-
- -- Set dependencies
- DELETE FROM tech.buildable_requirements WHERE buildable_id = nid;
- IF bdtn <> '' THEN
- INSERT INTO tech.buildable_requirements ( buildable_id , level_id )
- VALUES ( nid , tdid );
- END IF;
RETURN nid;
END;
@@ -577,7 +574,7 @@ CREATE OR REPLACE FUNCTION tech.uoc_building( bdn TEXT , bdd TEXT , bdc INT , bd
DECLARE
bdid INT;
BEGIN
- bdid := tech.uoc_buildable( bdn , bdd , bdc , bdw , bdu , '' , 0 );
+ bdid := tech.uoc_buildable( bdn , bdd , bdc , bdw , bdu , '' );
PERFORM buildable_id FROM tech.ships WHERE buildable_id = bdid;
IF FOUND THEN
@@ -611,13 +608,12 @@ GRANT EXECUTE ON FUNCTION tech.uoc_building( TEXT , TEXT , INT , INT , INT , INT
-- bdwk Workers
-- bdot Output type
-- bdo Output
--- bdtn Dependency (name)
--- bdtl Dependency (level)
+-- _tech Technology dependency
--
CREATE OR REPLACE FUNCTION tech.uoc_building( bdn TEXT , bdd TEXT , bdc INT , bdw INT ,
bdu INT , bdwk INT , bdot building_output_type , bdo INT ,
- bdtn TEXT , bdtl INT )
+ _tech TEXT )
RETURNS VOID
STRICT
VOLATILE
@@ -626,7 +622,7 @@ CREATE OR REPLACE FUNCTION tech.uoc_building( bdn TEXT , bdd TEXT , bdc INT , bd
DECLARE
bdid INT;
BEGIN
- bdid := tech.uoc_buildable( bdn , bdd , bdc , bdw , bdu , bdtn , bdtl );
+ bdid := tech.uoc_buildable( bdn , bdd , bdc , bdw , bdu , _tech );
PERFORM buildable_id FROM tech.ships WHERE buildable_id = bdid;
IF FOUND THEN
@@ -644,7 +640,7 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
-GRANT EXECUTE ON FUNCTION tech.uoc_building( TEXT , TEXT , INT , INT , INT , INT , building_output_type , INT , TEXT , INT ) TO :dbuser;
+GRANT EXECUTE ON FUNCTION tech.uoc_building( TEXT , TEXT , INT , INT , INT , INT , building_output_type , INT , TEXT ) TO :dbuser;
@@ -671,7 +667,7 @@ CREATE OR REPLACE FUNCTION tech.uoc_ship( sn TEXT , sd TEXT , sc INT , sw INT ,
DECLARE
bdid INT;
BEGIN
- bdid := tech.uoc_buildable( sn , sd , sc , sw , su , '' , 0 );
+ bdid := tech.uoc_buildable( sn , sd , sc , sw , su , '' );
PERFORM buildable_id FROM tech.buildings WHERE buildable_id = bdid;
IF FOUND THEN
@@ -704,12 +700,11 @@ GRANT EXECUTE ON FUNCTION tech.uoc_ship( TEXT , TEXT , INT , INT , INT , INT , I
-- su Upkeep
-- sp Power
-- sft Orbital flight time
--- stdn Tech line name
--- stdl Tech level
+-- _tech Technology dependency
--
CREATE OR REPLACE FUNCTION tech.uoc_ship( sn TEXT , sd TEXT , sc INT , sw INT ,
- su INT , sp INT , sft INT , stdn TEXT , stdl INT )
+ su INT , sp INT , sft INT , _tech TEXT )
RETURNS VOID
STRICT
VOLATILE
@@ -718,7 +713,7 @@ CREATE OR REPLACE FUNCTION tech.uoc_ship( sn TEXT , sd TEXT , sc INT , sw INT ,
DECLARE
bdid INT;
BEGIN
- bdid := tech.uoc_buildable( sn , sd , sc , sw , su , stdn , stdl );
+ bdid := tech.uoc_buildable( sn , sd , sc , sw , su , _tech );
PERFORM buildable_id FROM tech.buildings WHERE buildable_id = bdid;
IF FOUND THEN
@@ -736,6 +731,6 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
-GRANT EXECUTE ON FUNCTION tech.uoc_ship( TEXT , TEXT , INT , INT , INT , INT , INT , TEXT , INT ) TO :dbuser;
+GRANT EXECUTE ON FUNCTION tech.uoc_ship( TEXT , TEXT , INT , INT , INT , INT , INT , TEXT ) TO :dbuser;
diff --git a/legacyworlds-server-data/db-structure/parts/040-functions/140-planets.sql b/legacyworlds-server-data/db-structure/parts/040-functions/140-planets.sql
index 778b57d..2f7d5d9 100644
--- a/legacyworlds-server-data/db-structure/parts/040-functions/140-planets.sql
+++ b/legacyworlds-server-data/db-structure/parts/040-functions/140-planets.sql
@@ -468,8 +468,8 @@ AS $$
SELECT bv.name_id AS id , t1.translated_string AS name , t2.translated_string AS description ,
bv.cost AS cost ,
( CASE
- WHEN ceil( pdat.p_work ) = 0 THEN NULL
- ELSE ceil( bv.work / pdat.p_work )
+ WHEN ceil( pdat.p_work ) = 0 THEN NULL
+ ELSE ceil( bv.work / pdat.p_work )
END )::BIGINT AS time_to_build ,
bv.upkeep AS upkeep , bv.workers AS workers , bv.output_type AS p_type , bv.output AS p_value
FROM (
@@ -478,11 +478,10 @@ AS $$
INNER JOIN tech.basic_buildables bb USING( name_id )
UNION SELECT bv.*
FROM tech.buildings_view bv
- INNER JOIN tech.buildable_requirements r ON r.buildable_id = bv.name_id
- INNER JOIN tech.levels l ON l.id = r.level_id
INNER JOIN emp.planets ep ON ep.planet_id = $1
- INNER JOIN emp.technologies t
- ON t.empire_id = ep.empire_id AND t.line_id = l.line_id AND t.level > l.level
+ INNER JOIN emp.technologies_v2 _emptech
+ USING ( technology_name_id , empire_id )
+ WHERE emptech_state = 'KNOWN'
) AS bv , (
SELECT verse.adjust_production( ( p.population * sys.get_constant( 'game.work.wuPerPopUnit' ) )::REAL , ( ph.current / p.population )::REAL ) AS p_work ,
c.language_id AS language
@@ -530,11 +529,10 @@ AS $$
INNER JOIN tech.basic_buildables bb USING( name_id )
UNION SELECT bv.*
FROM tech.ships_view bv
- INNER JOIN tech.buildable_requirements r ON r.buildable_id = bv.name_id
- INNER JOIN tech.levels l ON l.id = r.level_id
INNER JOIN emp.planets ep ON ep.planet_id = $1
- INNER JOIN emp.technologies t
- ON t.empire_id = ep.empire_id AND t.line_id = l.line_id AND t.level > l.level
+ INNER JOIN emp.technologies_v2 t
+ USING ( empire_id , technology_name_id )
+ WHERE emptech_state = 'KNOWN'
) AS bv , (
SELECT verse.adjust_production( verse.get_raw_production( $1 , 'WORK' ) , ( ph.current / p.population )::REAL ) AS p_work ,
c.language_id AS language
@@ -689,8 +687,8 @@ CREATE OR REPLACE FUNCTION verse.add_military_item( p_id INT , s_id INT , s_cnt
DECLARE
e_id INT;
qlen INT;
- dep_level INT;
- has_level INT;
+ _needed INT;
+ _known INT;
BEGIN
IF s_cnt < 1 THEN
RETURN;
@@ -709,16 +707,16 @@ BEGIN
END IF;
-- Check technologies
- SELECT INTO dep_level , has_level l.level , t.level
+ SELECT INTO _needed , _known
+ b.technology_name_id , t.technology_name_id
FROM tech.ships s
- LEFT OUTER JOIN tech.buildable_requirements r
- ON r.buildable_id = s.buildable_id
- LEFT OUTER JOIN tech.levels l
- ON l.id = r.level_id
- LEFT OUTER JOIN emp.technologies t
- ON t.empire_id = e_id AND t.line_id = l.line_id AND t.level > l.level
+ INNER JOIN tech.buildables b
+ ON b.name_id = s.buildable_id
+ LEFT OUTER JOIN emp.technologies_v2 t
+ ON t.empire_id = e_id AND t.technology_name_id = b.technology_name_id
+ AND t.emptech_state = 'KNOWN'
WHERE s.buildable_id = s_id;
- IF NOT FOUND OR ( has_level IS NULL AND dep_level IS NOT NULL ) THEN
+ IF NOT FOUND OR ( _known IS NULL AND _needed IS NOT NULL ) THEN
RETURN;
END IF;
@@ -755,8 +753,8 @@ CREATE OR REPLACE FUNCTION verse.construct_buildings( p_id INT , b_id INT , b_cn
DECLARE
e_id INT;
qlen INT;
- dep_level INT;
- has_level INT;
+ _needed INT;
+ _known INT;
BEGIN
IF b_cnt < 1 THEN
RETURN;
@@ -775,16 +773,16 @@ BEGIN
END IF;
-- Check technologies
- SELECT INTO dep_level , has_level l.level , t.level
- FROM tech.buildings b
- LEFT OUTER JOIN tech.buildable_requirements r
- ON r.buildable_id = b.buildable_id
- LEFT OUTER JOIN tech.levels l
- ON l.id = r.level_id
- LEFT OUTER JOIN emp.technologies t
- ON t.empire_id = e_id AND t.line_id = l.line_id AND t.level > l.level
- WHERE b.buildable_id = b_id;
- IF NOT FOUND OR ( has_level IS NULL AND dep_level IS NOT NULL ) THEN
+ SELECT INTO _needed , _known
+ b.technology_name_id , t.technology_name_id
+ FROM tech.buildings s
+ INNER JOIN tech.buildables b
+ ON b.name_id = s.buildable_id
+ LEFT OUTER JOIN emp.technologies_v2 t
+ ON t.empire_id = e_id AND t.technology_name_id = b.technology_name_id
+ AND t.emptech_state = 'KNOWN'
+ WHERE s.buildable_id = b_id;
+ IF NOT FOUND OR ( _known IS NULL AND _needed IS NOT NULL ) THEN
RETURN;
END IF;
diff --git a/legacyworlds-server-main/data/buildables.xml b/legacyworlds-server-main/data/buildables.xml
index 5f9ed15..5f6d22a 100644
--- a/legacyworlds-server-main/data/buildables.xml
+++ b/legacyworlds-server-main/data/buildables.xml
@@ -13,15 +13,15 @@
-
+ indFactTech
-
+ reanimationTech
-
+ superTurretTech
@@ -29,15 +29,15 @@
-
+ cruisersTech
-
+ bCruisersTech
-
+ dreadnoughtsTech
\ No newline at end of file
diff --git a/legacyworlds-server-main/data/buildables.xsd b/legacyworlds-server-main/data/buildables.xsd
index 0447edf..73e6a39 100644
--- a/legacyworlds-server-main/data/buildables.xsd
+++ b/legacyworlds-server-main/data/buildables.xsd
@@ -26,7 +26,7 @@
-
+
diff --git a/legacyworlds-server-main/src/main/java/com/deepclone/lw/cli/ImportBuildables.java b/legacyworlds-server-main/src/main/java/com/deepclone/lw/cli/ImportBuildables.java
index a0f4228..30124a0 100644
--- a/legacyworlds-server-main/src/main/java/com/deepclone/lw/cli/ImportBuildables.java
+++ b/legacyworlds-server-main/src/main/java/com/deepclone/lw/cli/ImportBuildables.java
@@ -52,7 +52,8 @@ public class ImportBuildables
public CostData cost;
- public TechData tech;
+ @XStreamAlias( "require-technology" )
+ public String tech;
}
@SuppressWarnings( "serial" )
@@ -70,18 +71,6 @@ public class ImportBuildables
public int work;
}
- @SuppressWarnings( "serial" )
- @XStreamAlias( "tech" )
- public static class TechData
- implements Serializable
- {
- @XStreamAsAttribute
- public String name;
-
- @XStreamAsAttribute
- public int level;
- }
-
@SuppressWarnings( "serial" )
@XStreamAlias( "building" )
public static class BuildingData
@@ -163,7 +152,7 @@ public class ImportBuildables
// Load Hibernate bean
String[] cfg = {
- "configuration/transactions.xml"
+ "configuration/transactions.xml"
};
return new ClassPathXmlApplicationContext( cfg , true , ctx );
}
@@ -195,8 +184,7 @@ public class ImportBuildables
this.uocBuildingDep.addParameter( "workers" , Types.INTEGER );
this.uocBuildingDep.addParameter( "output_type" , "building_output_type" );
this.uocBuildingDep.addParameter( "output" , Types.INTEGER );
- this.uocBuildingDep.addParameter( "dep_name" , Types.VARCHAR );
- this.uocBuildingDep.addParameter( "dep_level" , Types.INTEGER );
+ this.uocBuildingDep.addParameter( "_technology" , Types.VARCHAR );
this.uocShipNoDep = new StoredProc( dataSource , "tech" , "uoc_ship" );
this.uocShipNoDep.addParameter( "name" , Types.VARCHAR );
@@ -215,8 +203,7 @@ public class ImportBuildables
this.uocShipDep.addParameter( "upkeep" , Types.INTEGER );
this.uocShipDep.addParameter( "power" , Types.INTEGER );
this.uocShipDep.addParameter( "flight_time" , Types.INTEGER );
- this.uocShipDep.addParameter( "dep_name" , Types.VARCHAR );
- this.uocShipDep.addParameter( "dep_level" , Types.INTEGER );
+ this.uocShipDep.addParameter( "_technology" , Types.VARCHAR );
}
@@ -241,7 +228,7 @@ public class ImportBuildables
ship.cost.upkeep , ship.power , ship.time );
} else {
this.uocShipDep.execute( ship.name , ship.description , ship.cost.build , ship.cost.work ,
- ship.cost.upkeep , ship.power , ship.time , ship.tech.name , ship.tech.level );
+ ship.cost.upkeep , ship.power , ship.time , ship.tech );
}
}
@@ -256,7 +243,7 @@ public class ImportBuildables
} else {
this.uocBuildingDep.execute( building.name , building.description , building.cost.build ,
building.cost.work , building.cost.upkeep , building.workers , building.type.toString( ) ,
- building.output , building.tech.name , building.tech.level );
+ building.output , building.tech );
}
}