From 85ea7fb6ac57156db76cbd01303f07cae90c7afb Mon Sep 17 00:00:00 2001 From: MatCat Date: Wed, 23 Jun 2021 01:29:31 -0700 Subject: [PATCH] Added a variable vector to objects --- src/mush2021.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/mush2021.cpp b/src/mush2021.cpp index 974307e..5726f7b 100644 --- a/src/mush2021.cpp +++ b/src/mush2021.cpp @@ -37,16 +37,41 @@ using namespace std; / ↓ ↓ ↓ ↓ ↓ ↓ \ */ +class VariableVector { + public: + string Name; + string Value; // TODO: Template this for different types +}; class BaseObject { public: uint64_t ID; string Name; BaseObject *Container; + vector Variables; void printName() { printf("Name: %s (#%X)\n",Name.c_str(),ID); } + + void SetVariable(string var, string val) { + for (auto i = Variables.begin() ; i != Variables.end(); i++) { + if (i->Name == var) { + i->Value = val; + return; + } + } + VariableVector v_v; + v_v.Name = var; + v_v.Value = val; + Variables.push_back(v_v); + } + string getVariable(string var) { + for (auto i = Variables.begin() ; i != Variables.end(); i++) { + if (i->Name == var) return i->Value; + } + return (string) NULL; + } }; class UserObject: public BaseObject { @@ -120,6 +145,7 @@ int main() { Magazine.Name = "Canik TP9SF Elite 9mm 15rd Magazine"; Magazine.Container = &Canik; + Magazine.SetVariable("Loaded","15"); God.printUserInfo(); @@ -127,7 +153,8 @@ int main() { BaseObject *TestObj2 = findObjectByID(3); if (TestObj != NULL) printf("Object #2 is: %s which is contained in %s\n",TestObj->Name.c_str(),TestObj->Container->Name.c_str()); - if (TestObj2 != NULL) printf("Object #3 is: %s which is contained in %s\n",TestObj2->Name.c_str(),TestObj2->Container->Name.c_str()); + if (TestObj2 != NULL) printf("Object #3 is: %s which is contained in %s, it is loaded with %s rounds\n",TestObj2->Name.c_str(),TestObj2->Container->Name.c_str(),TestObj2->getVariable("Loaded").c_str()); + printf("There are %u objects in existance\n",ObjectMap.size()); return 0; } \ No newline at end of file