diff --git a/src/main/java/com/fundynamic/d2tm/game/entities/EntityData.java b/src/main/java/com/fundynamic/d2tm/game/entities/EntityData.java index 0c0b988c..7e7c62bd 100644 --- a/src/main/java/com/fundynamic/d2tm/game/entities/EntityData.java +++ b/src/main/java/com/fundynamic/d2tm/game/entities/EntityData.java @@ -41,7 +41,7 @@ public class EntityData { private float chop = -1f; private float halfChop = -1f; public float buildTimeInSeconds = 5.0F; - public float buildRange = Game.HALF_TILE + (3 * Game.TILE_SIZE); + public float buildRange = 0F; public EntityType type; diff --git a/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesData.java b/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesData.java index 901e634d..67eb4a9c 100644 --- a/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesData.java +++ b/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesData.java @@ -1,6 +1,7 @@ package com.fundynamic.d2tm.game.entities.entitiesdata; +import com.fundynamic.d2tm.Game; import com.fundynamic.d2tm.game.entities.EntityData; import com.fundynamic.d2tm.game.entities.EntityNotFoundException; import com.fundynamic.d2tm.game.entities.EntityType; @@ -100,6 +101,35 @@ public EntityData addStructure(String id, IniDataStructure iniDataStructure) thr iniDataStructure.hitpoints ); + // The buildRange is (for now) determined by the size of the structure. + // Because the range is calculated from the center of the structure. + // In order to make it 'fair' for larger structures (if any would appear), + // we add 'half' of the structure to the range. + // + // For a constyard it is a square, so 64x64 pixels = 1 'half', meaning: + // + // (64/64)/2 = 0,5 * 32 (tile width) = 16 pixels + // + // A larger structure would be (width/height), ie a heavy factory thing would be: + // (96/64)/2 = ,75 * 32 = 24 pixels. + // + // Although on every squared structure this would even out fine, but then the + // 'buildRange' should have one tile extra because (again) it is calculated + // from the center + // + // this is all weird , then again, fixing this would require to check for every cell + // on the structure which basically makes calculating the 'can I place it in this distance' logic + // Width*height times more consuming. + // + // Unless.... + // + // We do the 'computed map' thing (where we have all entity data on a map attached), so we don't + // need to do an expensive lookup in the EntityRepository + //TODO: Do something about the above, for now accept its quirks + float someRatio = (float)entityData.getWidth() / (float)entityData.getHeight(); + int extraFromCenter = (int)((someRatio / 2) * Game.TILE_SIZE); // this is seriously flawed :/ (too tired to fix now) + // add additional '1' to get 'past the center and occupy one cell'. + entityData.buildRange = extraFromCenter + ((1 + iniDataStructure.buildRangeInTiles) * Game.TILE_SIZE); entityData.entityBuilderType = iniDataStructure.getEntityBuilderType(); entityData.buildTimeInSeconds = iniDataStructure.buildTimeInSeconds; entityData.buildList = iniDataStructure.buildList; diff --git a/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesDataReader.java b/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesDataReader.java index 50828a7c..472908c4 100644 --- a/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesDataReader.java +++ b/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesDataReader.java @@ -32,6 +32,7 @@ public class EntitiesDataReader { public static final String INI_KEYWORD_BUILD_ICON = "BuildIcon"; public static final String INI_KEYWORD_BUILDS = "Builds"; public static final String INI_KEYWORD_BUILD_TIME = "BuildTime"; + public static final String INI_KEYWORD_BUILD_RANGE = "BuildRange"; public static final String INI_KEYWORD_BUILD_LIST = "BuildList"; public static final String INI_KEYWORD_FPS = "Fps"; public static final String INI_KEYWORD_RECOLOR = "Recolor"; diff --git a/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/ini/IniDataStructure.java b/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/ini/IniDataStructure.java index 5e6f374a..e4b09789 100644 --- a/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/ini/IniDataStructure.java +++ b/src/main/java/com/fundynamic/d2tm/game/entities/entitiesdata/ini/IniDataStructure.java @@ -17,10 +17,12 @@ public class IniDataStructure { public int height; public int sight; public int hitpoints; + public int buildRangeInTiles; public String explosion; public String buildIcon; public String entityBuilderType; public float buildTimeInSeconds; + public String buildList; public IniDataStructure() { @@ -37,6 +39,7 @@ public IniDataStructure(Profile.Section struct) { this.entityBuilderType = struct.get(INI_KEYWORD_BUILDS, String.class, ""); this.buildTimeInSeconds = struct.get(INI_KEYWORD_BUILD_TIME, Float.class, 0F); this.buildList = struct.get(INI_KEYWORD_BUILD_LIST, String.class, ""); + this.buildRangeInTiles = struct.get(INI_KEYWORD_BUILD_RANGE, Integer.class, 0); } public EntityBuilderType getEntityBuilderType() { diff --git a/src/main/resources/rules.ini b/src/main/resources/rules.ini index 55153174..5b32accd 100644 --- a/src/main/resources/rules.ini +++ b/src/main/resources/rules.ini @@ -197,6 +197,7 @@ Builds=STRUCTURES BuildIcon=ui/icons/icon_constyard.bmp BuildList=WINDTRAP,REFINERY,BARRACKS,LIGHTFACTORY,HEAVYFACTORY BuildTime=30 +BuildRange=2 [STRUCTURES/REFINERY] Image=structures/3x2_refinery.png diff --git a/src/test/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesDataReaderTest.java b/src/test/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesDataReaderTest.java index 1c4a2330..e7f39bce 100644 --- a/src/test/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesDataReaderTest.java +++ b/src/test/java/com/fundynamic/d2tm/game/entities/entitiesdata/EntitiesDataReaderTest.java @@ -1,5 +1,6 @@ package com.fundynamic.d2tm.game.entities.entitiesdata; +import com.fundynamic.d2tm.Game; import com.fundynamic.d2tm.game.entities.EntityData; import com.fundynamic.d2tm.game.entities.EntityType; import com.fundynamic.d2tm.game.entities.entitybuilders.EntityBuilderType; @@ -43,6 +44,11 @@ public void readsBuildingStructureFromIniFile() { assertThat(constyard.explosionId, is("BOOM")); assertThat(constyard.buildIcon, is(not(nullValue()))); assertThat(constyard.entityBuilderType, is(EntityBuilderType.STRUCTURES)); + + // 1 extra tile range is added by the EntitiesData class (while it is '2' in the test-rules.ini!) + // therefor we do times 3! + float value = ((Game.TILE_SIZE) * 3) + Game.HALF_TILE; // we can do half-tile because it is a 64x64 structure + assertThat(constyard.buildRange, is(value)); // calculated by entitiesData class } @Test diff --git a/src/test/resources/test-rules.ini b/src/test/resources/test-rules.ini index 15cecad6..0ea65633 100644 --- a/src/test/resources/test-rules.ini +++ b/src/test/resources/test-rules.ini @@ -59,6 +59,9 @@ Height=64 Sight=4 Explosion=BOOM Builds=STRUCTURES +# BuildRange of 1 means attached to building +# BuildRange of 2 means you can have 1 tile in between +BuildRange=2 [STRUCTURES/WINDTRAP] Image=structures/2x2_windtrap.bmp