Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'eclipse'
id 'maven-publish'
id 'idea'
id 'io.freefair.lombok' version '8.11'
}

ext {
Expand All @@ -29,7 +30,7 @@ application {
}
else {
applicationDefaultJvmArgs = ["-Dvisualvm.display.name=OpenKeeper"]
}
}
}

task sourcesJar(type: Jar, dependsOn: [classes, startScripts, distZip, distTar]) {
Expand Down Expand Up @@ -116,8 +117,7 @@ idea {
}

compileJava {
// We have annotation processors in log4j, only needed for writing plugins, disable the warnings
options.compilerArgs += ["-proc:none"]
// disable the warnings
options.compilerArgs += ["-Xlint:deprecation"]
//options.compilerArgs += ["-Xlint:unchecked"]
}
Expand Down
66 changes: 28 additions & 38 deletions src/toniarts/openkeeper/game/MapSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import java.util.Comparator;
import java.util.List;
import toniarts.openkeeper.Main;
import toniarts.openkeeper.tools.convert.map.GameLevel;
import toniarts.openkeeper.tools.convert.map.GameLevel.LevFlag;
import toniarts.openkeeper.tools.convert.map.IKwdMap;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.utils.PathUtils;

Expand All @@ -42,30 +43,29 @@ public final class MapSelector {

private static final Logger logger = System.getLogger(MapSelector.class.getName());

private final List<GameMapContainer> skirmishMaps = new ArrayList<>();
private final List<GameMapContainer> multiplayerMaps = new ArrayList<>();
private final List<GameMapContainer> mpdMaps = new ArrayList<>();
private GameMapContainer map;
private final List<IKwdMap> skirmishMaps = new ArrayList<>();
private final List<IKwdMap> multiplayerMaps = new ArrayList<>();
private final List<IKwdMap> mpdMaps = new ArrayList<>();
private IKwdMap map;
private boolean skirmish;
private boolean mpd;

public MapSelector() {

// Get the maps
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(Main.getDkIIFolder(), PathUtils.DKII_MAPS_FOLDER), PathUtils.getFilterForFilesEndingWith(".kwd"))) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(Main.getDkIIFolder(),
PathUtils.DKII_MAPS_FOLDER), PathUtils.getFilterForFilesEndingWith(".kwd"))) {
for (Path file : stream) {

// Read the map
KwdFile kwd = new KwdFile(Main.getDkIIFolder(), file, false);
GameMapContainer gameMapContainer = new GameMapContainer(kwd, kwd.getGameLevel().getName());
if (kwd.getGameLevel().getLvlFlags().contains(GameLevel.LevFlag.IS_SKIRMISH_LEVEL)) {
skirmishMaps.add(gameMapContainer);
IKwdMap kwd = new KwdFile.KwdFileLoader().load(file);

if (kwd.getGameLevel().getLvlFlags().contains(LevFlag.IS_SKIRMISH_LEVEL)) {
skirmishMaps.add(kwd);
}
if (kwd.getGameLevel().getLvlFlags().contains(GameLevel.LevFlag.IS_MULTIPLAYER_LEVEL)) {
multiplayerMaps.add(gameMapContainer);
if (kwd.getGameLevel().getLvlFlags().contains(LevFlag.IS_MULTIPLAYER_LEVEL)) {
multiplayerMaps.add(kwd);
}
if (kwd.getGameLevel().getLvlFlags().contains(GameLevel.LevFlag.IS_MY_PET_DUNGEON_LEVEL)) {
mpdMaps.add(gameMapContainer);
if (kwd.getGameLevel().getLvlFlags().contains(LevFlag.IS_MY_PET_DUNGEON_LEVEL)) {
mpdMaps.add(kwd);
}
}
} catch (IOException ex) {
Expand All @@ -80,8 +80,8 @@ public MapSelector() {
}

public void random() {
GameMapContainer current;
List<GameMapContainer> maps = getMaps();
IKwdMap current;
List<IKwdMap> maps = getMaps();

if (maps.isEmpty()) {
current = null;
Expand All @@ -102,7 +102,7 @@ public final void reset() {
mpd = false;
}

public GameMapContainer getMap() {
public IKwdMap getMap() {
if (map == null) {
random();
}
Expand All @@ -113,7 +113,7 @@ public void selectMap(int index) {
map = getMaps().get(index);
}

public List<GameMapContainer> getMaps() {
public List<IKwdMap> getMaps() {
if (skirmish) {
return skirmishMaps;
} else if (mpd) {
Expand Down Expand Up @@ -150,38 +150,28 @@ public void setMPD(boolean mpd) {
/**
* Get a map by name, also sets it as the current map
*
* @param map the map name
* @param name the map name
* @return the map, or {@code null} if not found
*/
public GameMapContainer getMap(String map) {
int index = Collections.binarySearch(getMaps(), new GameMapContainer(null, map), new MapComparator());
public IKwdMap getMap(String name) {
int index = Collections.binarySearch(getMaps(), name);
if (index >= 0) {
this.map = getMaps().get(index);
return this.map;
map = getMaps().get(index);
return map;
}
return null;
}

/**
* Compares the maps by their name
*/
private static final class MapComparator implements Comparator<GameMapContainer> {
private static final class MapComparator implements Comparator<IKwdMap> {

@Override
public int compare(GameMapContainer o1, GameMapContainer o2) {
return o1.mapName().compareToIgnoreCase(o2.mapName());
public int compare(IKwdMap o1, IKwdMap o2) {
return o1.getGameLevel().getName().compareToIgnoreCase(o2.getGameLevel().getName());
}

}

/**
* Small container class that holds the actual map data and the name
*/
public record GameMapContainer(KwdFile map, String mapName) {

@Override
public String toString() {
return mapName;
}
}
}
31 changes: 16 additions & 15 deletions src/toniarts/openkeeper/game/controller/CreaturesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,24 @@
import toniarts.openkeeper.game.controller.room.AbstractRoomController;
import toniarts.openkeeper.game.controller.room.IRoomController;
import toniarts.openkeeper.tools.convert.map.Creature;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.tools.convert.map.IKwdFile;
import toniarts.openkeeper.tools.convert.map.Player;
import toniarts.openkeeper.tools.convert.map.Thing;
import toniarts.openkeeper.tools.convert.map.Variable;
import toniarts.openkeeper.utils.Utils;
import toniarts.openkeeper.utils.WorldUtils;

/**
* This is a controller that controls all the game objects in the world TODO:
* Hmm, should this be more a factory/loader maybe, or if this offers the
* ability to load / save, then it is fine
* This is a controller that controls all the game objects in the world TODO: Hmm, should this be more a
* factory/loader maybe, or if this offers the ability to load / save, then it is fine
*
* @author Toni Helenius <helenius.toni@gmail.com>
*/
public final class CreaturesController implements ICreaturesController {

private static final Logger logger = System.getLogger(CreaturesController.class.getName());

private final KwdFile kwdFile;
private final IKwdFile kwdFile;
private final EntityData entityData;
private final Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings;
private final Map<Short, IPartyController> creaturePartiesByPartyId = new HashMap<>();
Expand All @@ -103,10 +102,9 @@ public final class CreaturesController implements ICreaturesController {
*/
private final Map<Short, Thing.HeroParty> heroParties = new HashMap<>();
/**
* I don't know how to design this perfectly in the entity world, we have
* the state machine running inside an CreatureController. That is probably
* wrong (should be inside a system instead). But while it is in there, we
* should share the instances for it to function properly.<br>
* I don't know how to design this perfectly in the entity world, we have the state machine running inside
* an CreatureController. That is probably wrong (should be inside a system instead). But while it is in
* there, we should share the instances for it to function properly.<br>
* The value needs to be weak reference also since it references the key
*/
private final Map<EntityId, WeakReference<ICreatureController>> creatureControllersByEntityId = new WeakHashMap<>();
Expand All @@ -128,7 +126,7 @@ public final class CreaturesController implements ICreaturesController {
* @param mapController
* @param levelInfo
*/
public CreaturesController(KwdFile kwdFile, EntityData entityData, Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings, IGameTimer gameTimer,
public CreaturesController(IKwdFile kwdFile, EntityData entityData, Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings, IGameTimer gameTimer,
IGameController gameController, IMapController mapController, ILevelInfo levelInfo) {
this.kwdFile = kwdFile;
this.entityData = entityData;
Expand Down Expand Up @@ -503,9 +501,8 @@ private void setAttributesByLevel(CreatureComponent creatureComponent, CreatureE
@Override
public void spawnHeroParty(short partyId, PartyType partyType, Vector2f position) {
/**
* In the game manual it is said that it is entirely possible to have
* multiple parties with the same party ID, the old party just isn't
* controlled anymore
* In the game manual it is said that it is entirely possible to have multiple parties with the same
* party ID, the old party just isn't controlled anymore
*/
IPartyController partyController = creaturePartiesByPartyId.get(partyId);
if (partyController.isCreated()) {
Expand Down Expand Up @@ -564,7 +561,11 @@ public ICreatureController createController(EntityId entityId) {
}

private ICreatureController createCreatureController(EntityId id, CreatureComponent creatureComponent) {
return new CreatureController(id, entityData, kwdFile.getCreature(creatureComponent.creatureId), gameController.getNavigationService(), gameController.getTaskManager(), gameTimer, gameSettings, this, gameController.getEntityLookupService(), mapController, levelInfo, gameController.getGameWorldController().getObjectsController(), gameController.getGameWorldController().getShotsController());
return new CreatureController(id, entityData, kwdFile.getCreature(creatureComponent.creatureId),
gameController.getNavigationService(), gameController.getTaskManager(), gameTimer,
gameSettings, this, gameController.getEntityLookupService(), mapController, levelInfo,
gameController.getGameWorldController().getObjectsController(),
gameController.getGameWorldController().getShotsController());
}

@Override
Expand Down
9 changes: 4 additions & 5 deletions src/toniarts/openkeeper/game/controller/DoorsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@
import toniarts.openkeeper.game.controller.door.IDoorController;
import toniarts.openkeeper.game.map.IMapTileInformation;
import toniarts.openkeeper.tools.convert.map.Door;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.tools.convert.map.IKwdFile;
import toniarts.openkeeper.tools.convert.map.Terrain;
import toniarts.openkeeper.tools.convert.map.Thing;
import toniarts.openkeeper.tools.convert.map.Variable;
import toniarts.openkeeper.utils.WorldUtils;
import toniarts.openkeeper.view.map.MapViewController;

/**
* This is a controller that controls all the doors in the world TODO:
Expand All @@ -51,10 +50,10 @@
* @author Toni Helenius <helenius.toni@gmail.com>
*/
public final class DoorsController implements IDoorsController {

private static final Logger logger = System.getLogger(DoorsController.class.getName());

private KwdFile kwdFile;
private IKwdFile kwdFile;
private EntityData entityData;
private Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings;
private IMapController mapController;
Expand All @@ -75,7 +74,7 @@ public DoorsController() {
* @param gameController
* @param levelInfo
*/
public DoorsController(KwdFile kwdFile, EntityData entityData, Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings,
public DoorsController(IKwdFile kwdFile, EntityData entityData, Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings,
IMapController mapController, IGameController gameController, ILevelInfo levelInfo) {
this.kwdFile = kwdFile;
this.entityData = entityData;
Expand Down
17 changes: 9 additions & 8 deletions src/toniarts/openkeeper/game/controller/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import toniarts.openkeeper.game.trigger.party.PartyTriggerLogicController;
import toniarts.openkeeper.game.trigger.player.PlayerTriggerLogicController;
import toniarts.openkeeper.tools.convert.map.KeeperSpell;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.tools.convert.map.IKwdFile;
import toniarts.openkeeper.tools.convert.map.Player;
import toniarts.openkeeper.tools.convert.map.Thing;
import toniarts.openkeeper.tools.convert.map.Variable;
Expand Down Expand Up @@ -91,12 +91,11 @@ public final class GameController implements IGameLogicUpdatable, IGameControlle
* @param gameSettings
* @param playerService
*/
public GameController(KwdFile level, List<Keeper> players, EntityData entityData,
public GameController(IKwdFile level, List<Keeper> players, EntityData entityData,
Map<Variable.MiscVariable.MiscType, Variable.MiscVariable> gameSettings,
PlayerService playerService) {

levelInfo = new LevelInfo();
levelInfo.kwdFile = level;
levelInfo = new LevelInfo(level);
levelObject = null;
this.entityData = entityData;
this.gameSettings = gameSettings;
Expand All @@ -110,7 +109,6 @@ public GameController(KwdFile level, List<Keeper> players, EntityData entityData
}

public void createNewGame() {

levelInfo.load();
// The players
setupPlayers();
Expand Down Expand Up @@ -424,7 +422,7 @@ private static class LevelInfo implements ILevelInfo {
private static final int LEVEL_TIMER_MAX_COUNT = 16;
private static final int LEVEL_FLAG_MAX_COUNT = 128;

private KwdFile kwdFile;
private final IKwdFile kwdFile;
private int levelScore = 0;
private Float timeLimit = null;

Expand All @@ -434,8 +432,11 @@ private static class LevelInfo implements ILevelInfo {
private final Map<Integer, ActionPoint> actionPointsById = new HashMap<>();
private final List<ActionPoint> actionPoints = new ArrayList<>();

public LevelInfo(IKwdFile kwdFile) {
this.kwdFile = kwdFile;
}

public void load() {
kwdFile.load();
// Action points
loadActionPoints();
// Triggers data
Expand All @@ -457,7 +458,7 @@ private void loadActionPoints() {
}

@Override
public KwdFile getLevelData() {
public IKwdFile getLevelData() {
return kwdFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import toniarts.openkeeper.tools.convert.map.Door;
import toniarts.openkeeper.tools.convert.map.GameObject;
import toniarts.openkeeper.tools.convert.map.KeeperSpell;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.tools.convert.map.IKwdFile;
import toniarts.openkeeper.tools.convert.map.Player;
import toniarts.openkeeper.tools.convert.map.Room;
import toniarts.openkeeper.tools.convert.map.Terrain;
Expand Down Expand Up @@ -101,7 +101,7 @@ public final class GameWorldController implements IGameWorldController, IPlayerA
*/
public static final Object GOLD_LOCK = new Object();

private final KwdFile kwdFile;
private final IKwdFile kwdFile;
private final EntityData entityData;
private IObjectsController objectsController;
private ICreaturesController creaturesController;
Expand Down
4 changes: 2 additions & 2 deletions src/toniarts/openkeeper/game/controller/ILevelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import toniarts.openkeeper.game.data.ActionPoint;
import toniarts.openkeeper.game.data.GameTimer;
import toniarts.openkeeper.game.data.Keeper;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.tools.convert.map.IKwdFile;

/**
* General level related info
Expand All @@ -36,7 +36,7 @@ public interface ILevelInfo {
*
* @return the KWD
*/
KwdFile getLevelData();
IKwdFile getLevelData();

Keeper getPlayer(short playerId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static toniarts.openkeeper.tools.convert.map.KeeperSpell.TargetRule.NONE;
import static toniarts.openkeeper.tools.convert.map.KeeperSpell.TargetRule.OWN_CREATURES;
import static toniarts.openkeeper.tools.convert.map.KeeperSpell.TargetRule.POSESSION;
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.tools.convert.map.IKwdFile;
import toniarts.openkeeper.tools.convert.map.Player;

/**
Expand All @@ -53,7 +53,7 @@ private KeeperSpellCastValidator() {

public static boolean isValidCast(
KeeperSpell keeperSpell,
KwdFile kwdFile,
IKwdFile kwdFile,
IMapInformation mapInformation,
IMapTileInformation mapTile,
Keeper player,
Expand All @@ -68,7 +68,7 @@ private static boolean checkPlayerMana(KeeperSpell keeperSpell, Keeper player) {
return keeperSpell.getManaCost() <= player.getMana() - player.getManaLoose();
}

private static boolean checkTargetRule(EntityId target, EntityData entityData, KwdFile kwdFile, KeeperSpell keeperSpell, Keeper player) {
private static boolean checkTargetRule(EntityId target, EntityData entityData, IKwdFile kwdFile, KeeperSpell keeperSpell, Keeper player) {
short playerId = player.getId();
Creature creature = null;
Short owner = null;
Expand Down
Loading
Loading