Skip to content

Commit

Permalink
Entity based rooms and stubbed room hints
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Jan 9, 2025
1 parent e9c1609 commit acc9bb0
Show file tree
Hide file tree
Showing 22 changed files with 2,725 additions and 2,243 deletions.
18 changes: 18 additions & 0 deletions src/toniarts/openkeeper/common/RoomInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class RoomInstance extends EntityInstance<Room> {
private final Thing.Room.Direction direction;
private short ownerId;
private boolean destroyed = false;
private int health;
private int maxHealth;

public RoomInstance(Room room) {
this(room, null);
Expand Down Expand Up @@ -83,4 +85,20 @@ public boolean isDestroyed() {
return destroyed;
}

public int getHealth() {
return health;
}

public void setHealth(int health) {
this.health = health;
}

public int getMaxHealth() {
return maxHealth;
}

public void setMaxHealth(int maxHealth) {
this.maxHealth = maxHealth;
}

}
96 changes: 52 additions & 44 deletions src/toniarts/openkeeper/game/component/RoomComponent.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
/*
* Copyright (C) 2014-2021 OpenKeeper
*
* OpenKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
package toniarts.openkeeper.game.component;

import com.simsilica.es.EntityComponent;

/**
* A base room component. This entity is a room
*
* @author Toni Helenius <helenius.toni@gmail.com>
*/
public class RoomComponent implements EntityComponent {

public short roomId;
public boolean destroyed = false;

public RoomComponent() {
// For serialization
}

public RoomComponent(short roomId) {
this.roomId = roomId;
}

public RoomComponent(short roomId, boolean destroyed) {
this.roomId = roomId;
this.destroyed = destroyed;
}

}
/*
* Copyright (C) 2014-2021 OpenKeeper
*
* OpenKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
package toniarts.openkeeper.game.component;

import com.simsilica.es.EntityComponent;
import java.awt.Point;

/**
* A base room component. This entity is a room
*
* @author Toni Helenius <helenius.toni@gmail.com>
*/
public class RoomComponent implements EntityComponent {

public short roomId;
public boolean destroyed = false;

/**
* Room center, for convenience
*/
public Point location;

public RoomComponent() {
// For serialization
}

public RoomComponent(RoomComponent roomComponent) {
roomId = roomComponent.roomId;
destroyed = roomComponent.destroyed;
location = roomComponent.location;
}

public RoomComponent(short roomId, boolean destroyed, Point location) {
this.roomId = roomId;
this.destroyed = destroyed;
}

}
14 changes: 13 additions & 1 deletion src/toniarts/openkeeper/game/controller/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import toniarts.openkeeper.game.controller.room.AbstractRoomController;
import toniarts.openkeeper.game.controller.room.AbstractRoomController.ObjectType;
import toniarts.openkeeper.game.controller.room.IRoomController;
import toniarts.openkeeper.game.data.Keeper;
import toniarts.openkeeper.game.listener.MapListener;
import toniarts.openkeeper.game.listener.RoomListener;
import toniarts.openkeeper.game.map.IMapData;
Expand Down Expand Up @@ -116,8 +117,19 @@ private void loadRoom(Point p) {

// Find it
RoomInstance roomInstance = new RoomInstance(kwdFile.getRoomByTerrain(mapTile.getTerrainId()));
Keeper owner = levelInfo.getPlayer(mapTile.getOwnerId());
roomInstance.setDestroyed(roomInstance.getRoom() == kwdFile.getDungeonHeart() && (owner == null || owner.isDestroyed()));
roomInstance.setOwnerId(mapTile.getOwnerId());
findRoom(p, roomInstance);
int health = 0;
int maxHealth = 0;
for (Point coordinate : roomInstance.getCoordinates()) {
IMapTileController roomTile = mapData.getTile(coordinate);
health += roomTile.getHealth();
maxHealth += roomTile.getMaxHealth();
}
roomInstance.setHealth(health);
roomInstance.setMaxHealth(maxHealth);

// Create a controller for it
IRoomController roomController = RoomControllerFactory.constructRoom(entityData, kwdFile, roomInstance, objectsController, gameSettings, gameTimer);
Expand Down Expand Up @@ -360,7 +372,7 @@ public void removeRoomInstances(RoomInstance... instances) {

// Signal the room
IRoomController roomController = getRoomController(instance);
roomController.destroy();
roomController.remove();

roomControllers.remove(instance);
for (Point p : instance.getCoordinates()) {
Expand Down
Loading

0 comments on commit acc9bb0

Please sign in to comment.