summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-22 23:18:40 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-22 23:18:40 +0100
commitd8514d79700c3d79465b46b6f855ff5cfd3fa221 (patch)
treefda4da84e7289fbdd9d45d74f631d5b6fe12e362
parent321927671e5d3ab4a63453f2db370dc6ceee82c7 (diff)
downloadnoctis-d8514d79700c3d79465b46b6f855ff5cfd3fa221.tar.bz2
Initial bits of internal knowledge tree
-rw-r--r--src/main/java/net/flarn/noctis/knowledge/InternalKnowledgeTree.java11
-rw-r--r--src/main/java/net/flarn/noctis/knowledge/KnowledgeItem.java58
-rw-r--r--src/main/java/net/flarn/noctis/knowledge/KnowledgeVisibility.java32
3 files changed, 101 insertions, 0 deletions
diff --git a/src/main/java/net/flarn/noctis/knowledge/InternalKnowledgeTree.java b/src/main/java/net/flarn/noctis/knowledge/InternalKnowledgeTree.java
new file mode 100644
index 0000000..737c544
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/knowledge/InternalKnowledgeTree.java
@@ -0,0 +1,11 @@
+package net.flarn.noctis.knowledge;
+
+
+public class InternalKnowledgeTree {
+ public static final KnowledgeItem ROOT_KNOWLEDGE = KnowledgeItem.addKnowledgeItem("root", true, KnowledgeVisibility.KNOWN);
+ public static final KnowledgeItem LIGHT_CATALYST = KnowledgeItem.addKnowledgeItem("catalyst.light", true, KnowledgeVisibility.KNOWN, ROOT_KNOWLEDGE);
+ public static final KnowledgeItem BOUND_CATALYST = KnowledgeItem.addKnowledgeItem("catalyst.bound", true, KnowledgeVisibility.THEORY, LIGHT_CATALYST);
+ public static final KnowledgeItem POTION_SPEED = KnowledgeItem.addKnowledgeItem("potion.speed", true, KnowledgeVisibility.THEORY, BOUND_CATALYST);
+ public static final KnowledgeItem POTION_HEALTH = KnowledgeItem.addKnowledgeItem("potion.health", true, KnowledgeVisibility.HIDDEN, BOUND_CATALYST);
+
+}
diff --git a/src/main/java/net/flarn/noctis/knowledge/KnowledgeItem.java b/src/main/java/net/flarn/noctis/knowledge/KnowledgeItem.java
new file mode 100644
index 0000000..edf5e3a
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/knowledge/KnowledgeItem.java
@@ -0,0 +1,58 @@
+package net.flarn.noctis.knowledge;
+
+
+import net.flarn.noctis.utils.LogHelper;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+public class KnowledgeItem {
+ private static HashMap<String, KnowledgeItem> allKnowledgeItems = new HashMap<String, KnowledgeItem>();
+ private KnowledgeItem prerequisites[];
+ private Set<KnowledgeItem> dependents;
+ private String name;
+ boolean autoGet;
+ KnowledgeVisibility visOnGet;
+
+ private KnowledgeItem(String _name, boolean _autoGet, KnowledgeVisibility _visOnGet, KnowledgeItem... _prerequisites) {
+ name = _name;
+ autoGet = _autoGet;
+ visOnGet = _visOnGet;
+ prerequisites = _prerequisites;
+ dependents = new HashSet<KnowledgeItem>();
+ for (KnowledgeItem ki : prerequisites) {
+ ki.dependents.add(this);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ private boolean findLoops(Set<KnowledgeItem> visited) {
+ if (visited.contains(this)) { return true; }
+ visited.add(this);
+ for (KnowledgeItem prereq : prerequisites) {
+ if (prereq.findLoops(visited)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static KnowledgeItem addKnowledgeItem(String _name, boolean _autoGet, KnowledgeVisibility _visOnGet, KnowledgeItem... _prerequisites) {
+ KnowledgeItem ki = new KnowledgeItem(_name, _autoGet, _visOnGet, _prerequisites);
+ if (ki.findLoops(new HashSet<KnowledgeItem>())) {
+ LogHelper.fatal("Loop detected adding " + ki);
+ }
+ allKnowledgeItems.put(_name, ki);
+ return ki;
+ }
+
+ public static KnowledgeItem findKnowledgeItem(String _name) {
+ return allKnowledgeItems.get(_name);
+ }
+
+}
diff --git a/src/main/java/net/flarn/noctis/knowledge/KnowledgeVisibility.java b/src/main/java/net/flarn/noctis/knowledge/KnowledgeVisibility.java
new file mode 100644
index 0000000..d3962b4
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/knowledge/KnowledgeVisibility.java
@@ -0,0 +1,32 @@
+package net.flarn.noctis.knowledge;
+
+
+public enum KnowledgeVisibility {
+ UNKNOWN(0),
+ HIDDEN(1),
+ THEORY(2),
+ KNOWN(3);
+
+ private int vislevel;
+
+ private KnowledgeVisibility(int _vislevel) {
+ this.vislevel = _vislevel;
+ }
+
+ public int toInteger() { return vislevel; }
+
+ public static KnowledgeVisibility fromInt(int lvl) {
+ switch (lvl) {
+ case 0:
+ return UNKNOWN;
+ case 1:
+ return HIDDEN;
+ case 2:
+ return THEORY;
+ case 4:
+ return KNOWN;
+ }
+ return UNKNOWN;
+ }
+
+}