Added a variable vector to objects
This commit is contained in:
parent
3ef58e1aea
commit
85ea7fb6ac
@ -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<VariableVector> 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user