This repository has been archived by the owner on Oct 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
349 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 0 additions & 82 deletions
82
jsettlers.common/src/main/java/jsettlers/common/statistics/IPlayerStatistics.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 42 additions & 25 deletions
67
...rs/common/statistics/IConversionRate.java → ...s/common/map/shapes/MapRectangleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 | ||
* | ||
* Copyright (c) 2018 | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* <p> | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* <p> | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*******************************************************************************/ | ||
package jsettlers.common.statistics; | ||
|
||
/** | ||
* This class specifies how many bearers may be converted to a given type. | ||
* | ||
* @author michael | ||
*/ | ||
public interface IConversionRate { | ||
/** | ||
* How many bearers may be converted to this type at maximum | ||
* | ||
* @return A value from 0..1, defining a relative ammount to the sum of all non-military people. | ||
*/ | ||
float getMaximumRate(); | ||
|
||
/** | ||
* Sets the rate of bearers that may be converted at maximum. | ||
* | ||
* @param rate | ||
*/ | ||
void setMaximumRate(float rate); | ||
package jsettlers.common.map.shapes; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class MapRectangleTest { | ||
@Test | ||
public void containsBorders() { | ||
MapRectangle mapRectangle = new MapRectangle(0, 0, 10, 10); | ||
|
||
assertTrue(mapRectangle.contains(0, 0)); | ||
assertTrue(mapRectangle.contains(9, 0)); | ||
assertTrue(mapRectangle.contains(4, 9)); | ||
assertTrue(mapRectangle.contains(13, 9)); | ||
} | ||
|
||
@Test | ||
public void containsNotOutsideBorders() { | ||
MapRectangle mapRectangle = new MapRectangle(0, 0, 10, 10); | ||
|
||
assertFalse(mapRectangle.contains(0 - 1, 0)); | ||
assertFalse(mapRectangle.contains(0, -1)); | ||
assertFalse(mapRectangle.contains(-1, -1)); | ||
|
||
assertFalse(mapRectangle.contains(10, 0)); | ||
assertFalse(mapRectangle.contains(9, -1)); | ||
assertFalse(mapRectangle.contains(10, -1)); | ||
|
||
assertFalse(mapRectangle.contains(4 - 1, 9)); | ||
assertFalse(mapRectangle.contains(4, 9 + 1)); | ||
assertFalse(mapRectangle.contains(4 - 1, 9 + 1)); | ||
|
||
assertFalse(mapRectangle.contains(13 + 1, 9)); | ||
assertFalse(mapRectangle.contains(13, 9 + 1)); | ||
assertFalse(mapRectangle.contains(13 + 1, 9 + 1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
jsettlers.graphics/src/main/java/jsettlers/graphics/map/minimap/MiniMapShapeCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2018 | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package jsettlers.graphics.map.minimap; | ||
|
||
import jsettlers.common.map.shapes.MapRectangle; | ||
import jsettlers.graphics.map.geometry.MapCoordinateConverter; | ||
|
||
/** | ||
* Calculates the shape of the screen displayed on the minimap. | ||
* the origin of coordinates is in the bottom left and values increase to the top right. | ||
*/ | ||
class MiniMapShapeCalculator { | ||
|
||
private float width; | ||
private float height; | ||
private float stride; | ||
private MapRectangle mapViewport; | ||
private final MapCoordinateConverter converter; | ||
|
||
|
||
MiniMapShapeCalculator(float stride, MapCoordinateConverter converter) { | ||
this.stride = stride; | ||
|
||
this.converter = converter; | ||
} | ||
|
||
float[] getMiniMapShapeNodes() { | ||
if (mapViewport == null) { | ||
return new float[0]; | ||
} | ||
int offset = 50; | ||
int minX = mapViewport.getMinX(); | ||
int minY = mapViewport.getMinY(); | ||
int maxX = minX + mapViewport.getWidth(); | ||
int maxY = minY + mapViewport.getHeight() - offset; | ||
float minViewX = converter.getViewX(minX, minY, 0) * width; | ||
float maxViewY = converter.getViewY(minX, minY, 0) * height; | ||
float maxViewX = converter.getViewX(maxX, maxY + offset, 0) * width; | ||
float minViewY = converter.getViewY(maxX, maxY, 0) * height; | ||
|
||
return new float[] { | ||
// bottom left | ||
minViewX, | ||
minViewY, | ||
0, | ||
// bottom right | ||
Math.min(maxViewX, (minViewY / height * stride + 1) * width), | ||
minViewY, | ||
0, | ||
// mid right | ||
maxViewX, | ||
Math.max(minViewY, (maxViewX - width) / width / stride * height), | ||
0, | ||
// top right | ||
maxViewX, | ||
maxViewY, | ||
0, | ||
// top left | ||
Math.max(minViewX, (maxViewY / height * stride ) * width), | ||
maxViewY, | ||
0, | ||
// mid left | ||
minViewX, | ||
Math.min(maxViewY, minViewX / stride / width * height + 10), | ||
0, | ||
}; | ||
} | ||
|
||
void setMapViewport(MapRectangle mapViewport) { | ||
this.mapViewport = mapViewport; | ||
} | ||
|
||
void setWidth(float width) { | ||
this.width = width; | ||
} | ||
|
||
void setHeight(float height) { | ||
this.height = height; | ||
} | ||
} |
Oops, something went wrong.