143 lines
3.1 KiB
Java
143 lines
3.1 KiB
Java
package electrosphere.server.macro.town;
|
|
|
|
import electrosphere.server.macro.character.Character;
|
|
import electrosphere.server.macro.character.CharacterData;
|
|
import electrosphere.server.macro.character.CharacterDataStrings;
|
|
import electrosphere.server.macro.spatial.MacroAreaObject;
|
|
import electrosphere.server.macro.structure.Structure;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import org.joml.AABBd;
|
|
import org.joml.Vector3d;
|
|
|
|
/**
|
|
* Server representation of a town
|
|
*/
|
|
public class Town extends CharacterData implements MacroAreaObject {
|
|
|
|
/**
|
|
* The id of the town
|
|
*/
|
|
private int id;
|
|
|
|
/**
|
|
* Incrementer for IDs
|
|
*/
|
|
static int idIncrementer = 0;
|
|
|
|
/**
|
|
* The position of the town
|
|
*/
|
|
private Vector3d position;
|
|
|
|
/**
|
|
* The radius of the town
|
|
*/
|
|
private double radius;
|
|
|
|
/**
|
|
* The structures inside the town
|
|
*/
|
|
private List<Structure> structures = new LinkedList<Structure>();
|
|
|
|
/**
|
|
* The residents of the town
|
|
*/
|
|
private List<Character> residents = new LinkedList<Character>();
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
private Town(){
|
|
super(CharacterDataStrings.TOWN);
|
|
this.id = idIncrementer;
|
|
idIncrementer++;
|
|
}
|
|
|
|
/**
|
|
* Creates a town
|
|
* @param position The position of the town
|
|
* @param radius The radius of the town
|
|
* @return The town
|
|
*/
|
|
public static Town createTown(Vector3d position, double radius){
|
|
Town rVal = new Town();
|
|
rVal.position = position;
|
|
rVal.radius = radius;
|
|
return rVal;
|
|
}
|
|
|
|
/**
|
|
* Adds a structure to the town
|
|
* @param structure The structure
|
|
*/
|
|
public void addStructure(Structure structure){
|
|
structures.add(structure);
|
|
}
|
|
|
|
/**
|
|
* Gets the structures that are a part of the town
|
|
* @return The list of structures
|
|
*/
|
|
public List<Structure> getStructures(){
|
|
return structures;
|
|
}
|
|
|
|
/**
|
|
* Adds a resident to the town
|
|
* @param resident The new resident
|
|
*/
|
|
public void addResident(Character resident){
|
|
residents.add(resident);
|
|
}
|
|
|
|
/**
|
|
* Gets the list of residents of the town
|
|
* @return The list of residents
|
|
*/
|
|
public List<Character> getResidents(){
|
|
return residents;
|
|
}
|
|
|
|
@Override
|
|
public String getDataType() {
|
|
return CharacterDataStrings.HOMETOWN;
|
|
}
|
|
|
|
@Override
|
|
public Vector3d getPos() {
|
|
return this.position;
|
|
}
|
|
|
|
@Override
|
|
public void setPos(Vector3d pos) {
|
|
this.position = pos;
|
|
}
|
|
|
|
@Override
|
|
public Vector3d getStartPos() {
|
|
return new Vector3d(this.position).sub(this.radius,this.radius,this.radius);
|
|
}
|
|
|
|
@Override
|
|
public Vector3d getEndPos() {
|
|
return new Vector3d(this.position).add(this.radius,this.radius,this.radius);
|
|
}
|
|
|
|
@Override
|
|
public AABBd getAABB() {
|
|
return new AABBd(this.getStartPos(), this.getEndPos());
|
|
}
|
|
|
|
/**
|
|
* Gets the ID of the town
|
|
* @return The ID
|
|
*/
|
|
public int getId(){
|
|
return this.id;
|
|
}
|
|
|
|
}
|