This commit is contained in:
parent
ea0af29777
commit
f76a59215c
@ -1,13 +1,20 @@
|
|||||||
package org.studiorailgun.sim.character;
|
package org.studiorailgun.sim.character;
|
||||||
|
|
||||||
|
import org.studiorailgun.Globals;
|
||||||
import org.studiorailgun.sim.character.emotion.EmotionData;
|
import org.studiorailgun.sim.character.emotion.EmotionData;
|
||||||
import org.studiorailgun.sim.character.vis.CharacterAppearance;
|
import org.studiorailgun.sim.character.vis.CharacterAppearance;
|
||||||
|
import org.studiorailgun.sim.space.Location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A reasoning entity being simulated in the game world
|
* A reasoning entity being simulated in the game world
|
||||||
*/
|
*/
|
||||||
public class Character {
|
public class Character {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An unassigned location
|
||||||
|
*/
|
||||||
|
public static final int LOCATION_UNASSIGNED = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The id of the character
|
* The id of the character
|
||||||
*/
|
*/
|
||||||
@ -23,12 +30,32 @@ public class Character {
|
|||||||
*/
|
*/
|
||||||
EmotionData emotions;
|
EmotionData emotions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the location of this character is in
|
||||||
|
*/
|
||||||
|
int locationId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simulates this character
|
* Simulates this character
|
||||||
*/
|
*/
|
||||||
public void simulate(){
|
public void simulate(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves this character to the destination
|
||||||
|
* @param destination The destination location
|
||||||
|
*/
|
||||||
|
public void move(Location destination){
|
||||||
|
//remove from old pos
|
||||||
|
Location oldLoc = Globals.world.getLocation(locationId);
|
||||||
|
if(oldLoc != null){
|
||||||
|
oldLoc.removeCharacter(this);
|
||||||
|
}
|
||||||
|
//add to new pos
|
||||||
|
destination.addCharacter(this);
|
||||||
|
locationId = destination.getId();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the appearance of the character
|
* Gets the appearance of the character
|
||||||
* @return The appearance of the character
|
* @return The appearance of the character
|
||||||
@ -61,4 +88,22 @@ public class Character {
|
|||||||
this.emotions = emotions;
|
this.emotions = emotions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the id of the location this character is at
|
||||||
|
* @return The id of the location this character is at
|
||||||
|
*/
|
||||||
|
public int getLocationId() {
|
||||||
|
return locationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the id of the location this character is at
|
||||||
|
* @param locationId The id of the location this character is at
|
||||||
|
*/
|
||||||
|
public void setLocationId(int locationId) {
|
||||||
|
this.locationId = locationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ public class CharacterGenerator {
|
|||||||
*/
|
*/
|
||||||
public static Character generateCharacter(){
|
public static Character generateCharacter(){
|
||||||
Character rVal = new Character();
|
Character rVal = new Character();
|
||||||
|
rVal.setLocationId(Character.LOCATION_UNASSIGNED);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
package org.studiorailgun.sim.character.gen;
|
package org.studiorailgun.sim.character.gen;
|
||||||
|
|
||||||
|
import org.studiorailgun.Globals;
|
||||||
import org.studiorailgun.sim.character.Character;
|
import org.studiorailgun.sim.character.Character;
|
||||||
|
import org.studiorailgun.sim.space.Location;
|
||||||
|
import org.studiorailgun.sim.space.util.LocationResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sources the player character (ie either by prompting the player, loading from file, generating, etc)
|
* Sources the player character (ie either by prompting the player, loading from file, generating, etc)
|
||||||
@ -12,7 +15,9 @@ public class PlayerCharSourcer {
|
|||||||
* @return The player's character
|
* @return The player's character
|
||||||
*/
|
*/
|
||||||
public static Character getPlayerCharacter(){
|
public static Character getPlayerCharacter(){
|
||||||
Character rVal = new Character();
|
Character rVal = CharacterGenerator.generateCharacter();
|
||||||
|
Location first = LocationResolver.first(Globals.world);
|
||||||
|
rVal.move(first);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,11 @@ public class Location {
|
|||||||
* The id of the location
|
* The id of the location
|
||||||
*/
|
*/
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the location
|
||||||
|
*/
|
||||||
|
String type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The characters currently in this region
|
* The characters currently in this region
|
||||||
@ -27,6 +32,30 @@ public class Location {
|
|||||||
*/
|
*/
|
||||||
transient List<Item> items = new LinkedList<Item>();
|
transient List<Item> items = new LinkedList<Item>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param type The type of the location
|
||||||
|
*/
|
||||||
|
public Location(String type){
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a character from this location
|
||||||
|
* @param character The character
|
||||||
|
*/
|
||||||
|
public void removeCharacter(Character character){
|
||||||
|
this.chars.remove(character);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a character to this location
|
||||||
|
* @param character The character
|
||||||
|
*/
|
||||||
|
public void addCharacter(Character character){
|
||||||
|
this.chars.add(character);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the characters in this location
|
* Gets the characters in this location
|
||||||
* @return The characters in this location
|
* @return The characters in this location
|
||||||
@ -58,6 +87,32 @@ public class Location {
|
|||||||
public void setItems(List<Item> items) {
|
public void setItems(List<Item> items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the type of the location
|
||||||
|
* @return The type of the location
|
||||||
|
*/
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the type of the location
|
||||||
|
* @param type The type of the location
|
||||||
|
*/
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the id of this location
|
||||||
|
* @return The id of this location
|
||||||
|
*/
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,11 @@ import java.util.List;
|
|||||||
* A recursive tree of regions that contain locations at their leaves
|
* A recursive tree of regions that contain locations at their leaves
|
||||||
*/
|
*/
|
||||||
public class Region {
|
public class Region {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the region
|
||||||
|
*/
|
||||||
|
int id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The child reglions of this region
|
* The child reglions of this region
|
||||||
@ -14,9 +19,9 @@ public class Region {
|
|||||||
transient List<Region> children = new LinkedList<Region>();
|
transient List<Region> children = new LinkedList<Region>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The location data for this leaf node
|
* The discrete locations that are within this region
|
||||||
*/
|
*/
|
||||||
Location leaf;
|
transient List<Location> locations = new LinkedList<Location>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the child regions of this region
|
* Gets the child regions of this region
|
||||||
@ -34,22 +39,6 @@ public class Region {
|
|||||||
this.children = children;
|
this.children = children;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the leaf location of this region
|
|
||||||
* @return The leaf location of this region
|
|
||||||
*/
|
|
||||||
public Location getLeaf() {
|
|
||||||
return leaf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the leaf location of this region
|
|
||||||
* @param leaf The leaf location of this region
|
|
||||||
*/
|
|
||||||
public void setLeaf(Location leaf) {
|
|
||||||
this.leaf = leaf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a child region
|
* Adds a child region
|
||||||
* @param child The child region
|
* @param child The child region
|
||||||
@ -58,6 +47,28 @@ public class Region {
|
|||||||
children.add(child);
|
children.add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the locations of this region
|
||||||
|
* @return The locations of this region
|
||||||
|
*/
|
||||||
|
public List<Location> getLocations() {
|
||||||
|
return locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the locations of this region
|
||||||
|
* @param locations The locations of this region
|
||||||
|
*/
|
||||||
|
public void setLocations(List<Location> locations) {
|
||||||
|
this.locations = locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a location to the region
|
||||||
|
* @param location The location
|
||||||
|
*/
|
||||||
|
public void addLocation(Location location){
|
||||||
|
this.locations.add(location);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package org.studiorailgun.sim.space;
|
package org.studiorailgun.sim.space;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.studiorailgun.sim.character.Character;
|
import org.studiorailgun.sim.character.Character;
|
||||||
|
|
||||||
@ -20,6 +22,11 @@ public class World {
|
|||||||
*/
|
*/
|
||||||
List<Character> characters = new LinkedList<Character>();
|
List<Character> characters = new LinkedList<Character>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of location id -> location
|
||||||
|
*/
|
||||||
|
transient Map<Integer,Location> idLocationMap = new HashMap<Integer,Location>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the top level region of this world
|
* Gets the top level region of this world
|
||||||
* @return The top level region of this world
|
* @return The top level region of this world
|
||||||
@ -52,6 +59,23 @@ public class World {
|
|||||||
this.characters = characters;
|
this.characters = characters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a location
|
||||||
|
* @param location The location
|
||||||
|
*/
|
||||||
|
public void registerLocation(Location location){
|
||||||
|
this.idLocationMap.put(location.getId(), location);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a location based on its id
|
||||||
|
* @param id The id of the location
|
||||||
|
* @return The location if it exists, null otherwise
|
||||||
|
*/
|
||||||
|
public Location getLocation(int id){
|
||||||
|
return this.idLocationMap.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,8 @@ public class BuildingGenerator {
|
|||||||
public static Region generateBuilding(){
|
public static Region generateBuilding(){
|
||||||
Region rVal = new Region();
|
Region rVal = new Region();
|
||||||
|
|
||||||
|
rVal.addLocation(LocationGenerator.generate("Entrance"));
|
||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,20 @@
|
|||||||
|
package org.studiorailgun.sim.space.gen;
|
||||||
|
|
||||||
|
import org.studiorailgun.sim.space.Location;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a location
|
||||||
|
*/
|
||||||
|
public class LocationGenerator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a location
|
||||||
|
* @param type The type of the location
|
||||||
|
* @return The location
|
||||||
|
*/
|
||||||
|
public static Location generate(String type){
|
||||||
|
Location rVal = new Location(type);
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -14,7 +14,7 @@ public class TownGenerator {
|
|||||||
public static Region generateTown(){
|
public static Region generateTown(){
|
||||||
Region rVal = new Region();
|
Region rVal = new Region();
|
||||||
|
|
||||||
Region building = new Region();
|
Region building = BuildingGenerator.generateBuilding();
|
||||||
rVal.addChild(building);
|
rVal.addChild(building);
|
||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
|
|||||||
@ -1,6 +1,13 @@
|
|||||||
package org.studiorailgun.sim.space.gen;
|
package org.studiorailgun.sim.space.gen;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.studiorailgun.sim.space.Location;
|
||||||
import org.studiorailgun.sim.space.World;
|
import org.studiorailgun.sim.space.World;
|
||||||
|
import org.studiorailgun.sim.space.util.LocationResolver;
|
||||||
|
import org.studiorailgun.Globals;
|
||||||
|
import org.studiorailgun.sim.character.Character;
|
||||||
|
import org.studiorailgun.sim.character.gen.CharacterGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a world
|
* Generates a world
|
||||||
@ -13,8 +20,31 @@ public class WorldGenerator {
|
|||||||
*/
|
*/
|
||||||
public static World generateWorld(){
|
public static World generateWorld(){
|
||||||
World rVal = new World();
|
World rVal = new World();
|
||||||
|
Globals.world = rVal;
|
||||||
|
|
||||||
|
//generate the regions
|
||||||
|
rVal.setRegion(TownGenerator.generateTown());
|
||||||
|
|
||||||
|
//generate the characters
|
||||||
|
WorldGenerator.generateCharacters(rVal);
|
||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the world with characters
|
||||||
|
* @param world The world
|
||||||
|
*/
|
||||||
|
private static void generateCharacters(World world){
|
||||||
|
List<Character> characters = world.getCharacters();
|
||||||
|
|
||||||
|
//create the character
|
||||||
|
Character newChar = CharacterGenerator.generateCharacter();
|
||||||
|
characters.add(newChar);
|
||||||
|
|
||||||
|
//place the character in the world
|
||||||
|
Location placementDest = LocationResolver.first(world);
|
||||||
|
newChar.move(placementDest);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
package org.studiorailgun.sim.space.util;
|
||||||
|
|
||||||
|
import org.studiorailgun.sim.space.Location;
|
||||||
|
import org.studiorailgun.sim.space.Region;
|
||||||
|
import org.studiorailgun.sim.space.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities for resolving locations
|
||||||
|
*/
|
||||||
|
public class LocationResolver {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the first location available
|
||||||
|
* @return The location
|
||||||
|
*/
|
||||||
|
public static Location first(World world){
|
||||||
|
Region root = world.getRegion();
|
||||||
|
while(root.getLocations().size() < 1){
|
||||||
|
root = root.getChildren().get(0);
|
||||||
|
}
|
||||||
|
return root.getLocations().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user