-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load ship stats from files so that system health and node health (issue
#12) can be calculated
- Loading branch information
Andrew Brindamour
committed
Jan 17, 2016
1 parent
07aef94
commit f6faf68
Showing
6 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/com/brindyblitz/artemis/engconsole/BaseEngineeringConsoleManager.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
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
66 changes: 66 additions & 0 deletions
66
src/com/brindyblitz/artemis/protocol/NonShittyShipSystemGrid.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,66 @@ | ||
package com.brindyblitz.artemis.protocol; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Map; | ||
|
||
import net.dhleong.acl.enums.ShipSystem; | ||
import net.dhleong.acl.util.GridCoord; | ||
import net.dhleong.acl.util.ShipSystemGrid; | ||
|
||
public class NonShittyShipSystemGrid extends ShipSystemGrid { | ||
|
||
public static final int GRID_SIZE_X = 5; | ||
public static final int GRID_SIZE_Y = 5; | ||
public static final int GRID_SIZE_Z = 10; | ||
|
||
|
||
public void addNode(ShipSystem system, GridCoord coord) { | ||
GridEntry entry = createGridEntry(system, getSystemCount(system)); | ||
addEntry(coord, entry); | ||
incrementSystemCount(system); | ||
} | ||
|
||
|
||
|
||
private void incrementSystemCount(ShipSystem system){ | ||
try { | ||
Field field = this.getClass().getSuperclass().getDeclaredField("mSystemCounts"); | ||
field.setAccessible(true); | ||
int[] mSystemCounts = (int[]) field.get(this); | ||
mSystemCounts[system.ordinal()]++; | ||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { | ||
throw new RuntimeException("Reflection black magic failed", e); | ||
} | ||
|
||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private void addEntry(GridCoord coord, GridEntry entry){ | ||
try { | ||
Field field = this.getClass().getSuperclass().getDeclaredField("mSystems"); | ||
field.setAccessible(true); | ||
Map<GridCoord, GridEntry> systems = (Map<GridCoord, GridEntry>) field.get(this); | ||
systems.put(coord, entry); | ||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { | ||
throw new RuntimeException("Reflection black magic failed", e); | ||
} | ||
|
||
} | ||
|
||
private GridEntry createGridEntry(ShipSystem system, int systemCount) { | ||
try { | ||
Constructor<?> constructor = GridEntry.class.getDeclaredConstructors()[0]; | ||
constructor.setAccessible(true); | ||
return (GridEntry) constructor.newInstance(system, systemCount); | ||
} catch (SecurityException | IllegalArgumentException | IllegalAccessException | InstantiationException e) { | ||
throw new RuntimeException("Reflection black magic failed", e); | ||
} catch (InvocationTargetException e) { | ||
if (e.getTargetException() instanceof RuntimeException) { | ||
throw (RuntimeException) e.getTargetException(); | ||
} | ||
throw new RuntimeException("Unexpected non-runtime exception", e); | ||
} | ||
} | ||
} |