summaryrefslogtreecommitdiff
path: root/src/cat/CommandInterface.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
commit058a2edd75debbd0297f92572316daa704bd379f (patch)
treead303f091f9a08b209b91eb34a9fcad996a3de69 /src/cat/CommandInterface.cpp
parente3594aba9e05c6865d396418c028049cda92c2f3 (diff)
parent7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff)
downloadpowder-058a2edd75debbd0297f92572316daa704bd379f.zip
powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/cat/CommandInterface.cpp')
-rw-r--r--src/cat/CommandInterface.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/cat/CommandInterface.cpp b/src/cat/CommandInterface.cpp
new file mode 100644
index 0000000..3ebc795
--- /dev/null
+++ b/src/cat/CommandInterface.cpp
@@ -0,0 +1,118 @@
+/*
+ * Kitty.cpp
+ *
+ * Created on: Feb 2, 2012
+ * Author: Simon
+ */
+
+#include <iostream>
+#include <string>
+#include <string.h>
+#if !defined(WIN) || defined(__GNUC__)
+#include <strings.h>
+#endif
+#include "CommandInterface.h"
+#include "game/GameModel.h"
+#include "game/GameController.h"
+
+CommandInterface::CommandInterface(GameController * c, GameModel * m) {
+ this->m = m;
+ this->c = c;
+}
+
+/*void CommandInterface::AttachGameModel(GameModel * m)
+{
+ this->m = m;
+}*/
+
+int CommandInterface::Command(std::string command)
+{
+ lastError = "No interpreter";
+ return -1;
+}
+
+std::string CommandInterface::FormatCommand(std::string command)
+{
+ return command;
+}
+
+void CommandInterface::Log(LogType type, std::string message)
+{
+ m->Log(message);
+}
+
+int CommandInterface::GetPropertyOffset(std::string key_, FormatType & format)
+{
+ char * key = (char *)key_.c_str();
+ int offset;
+ if (strcmp(key, "type")==0){
+ offset = offsetof(Particle, type);
+ format = FormatInt;
+ } else if (strcmp(key, "life")==0){
+ offset = offsetof(Particle, life);
+ format = FormatInt;
+ } else if (strcmp(key, "ctype")==0){
+ offset = offsetof(Particle, ctype);
+ format = FormatInt;
+ } else if (strcmp(key, "temp")==0){
+ offset = offsetof(Particle, temp);
+ format = FormatFloat;
+ } else if (strcmp(key, "tmp2")==0){
+ offset = offsetof(Particle, tmp2);
+ format = FormatInt;
+ } else if (strcmp(key, "tmp")==0){
+ offset = offsetof(Particle, tmp);
+ format = FormatInt;
+ } else if (strcmp(key, "vy")==0){
+ offset = offsetof(Particle, vy);
+ format = FormatFloat;
+ } else if (strcmp(key, "vx")==0){
+ offset = offsetof(Particle, vx);
+ format = FormatFloat;
+ } else if (strcmp(key, "x")==0){
+ offset = offsetof(Particle, x);
+ format = FormatFloat;
+ } else if (strcmp(key, "y")==0){
+ offset = offsetof(Particle, y);
+ format = FormatFloat;
+ } else if (strcmp(key, "dcolour")==0){
+ offset = offsetof(Particle, dcolour);
+ format = FormatInt;
+ } else if (strcmp(key, "dcolor")==0){
+ offset = offsetof(Particle, dcolour);
+ format = FormatInt;
+ } else {
+ offset = -1;
+ }
+ return offset;
+}
+
+int CommandInterface::GetParticleType(std::string type)
+{
+ int i = -1;
+ char * txt = (char*)type.c_str();
+
+ //Scope
+ Element * elements = m->GetSimulation()->elements;
+
+ // alternative names for some elements
+ if (strcasecmp(txt,"C4")==0) return PT_PLEX;
+ else if (strcasecmp(txt,"C5")==0) return PT_C5;
+ else if (strcasecmp(txt,"NONE")==0) return PT_NONE;
+ for (i=1; i<PT_NUM; i++) {
+ if (strcasecmp(txt, elements[i].Name)==0 && elements[i].Enabled)
+ {
+ return i;
+ }
+ }
+ return -1;
+}
+
+std::string CommandInterface::GetLastError()
+{
+ return lastError;
+}
+
+CommandInterface::~CommandInterface() {
+}
+