Initial commit
This commit is contained in:
82
engines/crab/people/opinion.cpp
Normal file
82
engines/crab/people/opinion.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "crab/crab.h"
|
||||
#include "crab/GameParam.h"
|
||||
#include "crab/people/opinion.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace people {
|
||||
int OPINION_MIN = 0, OPINION_MAX = 100;
|
||||
}
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
using namespace pyrodactyl::people;
|
||||
|
||||
Opinion::Opinion() {
|
||||
_val[OPI_LIKE] = 0;
|
||||
_val[OPI_FEAR] = 0;
|
||||
_val[OPI_RESPECT] = 0;
|
||||
}
|
||||
|
||||
void Opinion::load(rapidxml::xml_node<char> *node) {
|
||||
loadNum(_val[OPI_LIKE], "like", node);
|
||||
loadNum(_val[OPI_FEAR], "fear", node);
|
||||
loadNum(_val[OPI_RESPECT], "respect", node);
|
||||
}
|
||||
|
||||
void Opinion::change(const OpinionType &type, const int &change) {
|
||||
_val[type] += change;
|
||||
validate(type);
|
||||
}
|
||||
|
||||
void Opinion::set(const OpinionType &type, const int &num) {
|
||||
_val[type] = num;
|
||||
validate(type);
|
||||
}
|
||||
|
||||
void Opinion::validate(const OpinionType &type) {
|
||||
if (_val[type] < OPINION_MIN)
|
||||
_val[type] = OPINION_MIN;
|
||||
else if (_val[type] > OPINION_MAX)
|
||||
_val[type] = OPINION_MAX;
|
||||
}
|
||||
|
||||
void Opinion::saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root) {
|
||||
rapidxml::xml_node<char> *child = doc.allocate_node(rapidxml::node_element, "opinion");
|
||||
child->append_attribute(doc.allocate_attribute("like", g_engine->_stringPool->get(_val[OPI_LIKE])));
|
||||
child->append_attribute(doc.allocate_attribute("fear", g_engine->_stringPool->get(_val[OPI_FEAR])));
|
||||
child->append_attribute(doc.allocate_attribute("respect", g_engine->_stringPool->get(_val[OPI_RESPECT])));
|
||||
root->append_node(child);
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
73
engines/crab/people/opinion.h
Normal file
73
engines/crab/people/opinion.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRAB_OPINION_H
|
||||
#define CRAB_OPINION_H
|
||||
|
||||
#include "crab/rapidxml/rapidxml.hpp"
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace people {
|
||||
// What each opinion type is
|
||||
// like - how much a person likes you
|
||||
// intimidate - how much a person fears you
|
||||
// respect - how much a person respects you
|
||||
enum OpinionType {
|
||||
OPI_LIKE,
|
||||
OPI_RESPECT,
|
||||
OPI_FEAR,
|
||||
OPI_TOTAL
|
||||
};
|
||||
|
||||
// The limits on opinion values
|
||||
extern int OPINION_MIN, OPINION_MAX;
|
||||
|
||||
struct Opinion {
|
||||
// The opinion of the character about the player
|
||||
// Range 0 to 100 , 100 = absolutely adore you, and 0 = really hate you
|
||||
int _val[OPI_TOTAL];
|
||||
|
||||
Opinion();
|
||||
~Opinion() {}
|
||||
|
||||
void change(const OpinionType &type, const int &change);
|
||||
void set(const OpinionType &type, const int &val);
|
||||
void validate(const OpinionType &type);
|
||||
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
void saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root);
|
||||
};
|
||||
} // End of namespace people
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_OPINION_H
|
||||
154
engines/crab/people/person.cpp
Normal file
154
engines/crab/people/person.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "crab/crab.h"
|
||||
#include "crab/GameParam.h"
|
||||
#include "crab/people/person.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
using namespace pyrodactyl::stat;
|
||||
using namespace pyrodactyl::people;
|
||||
|
||||
Person::Person() {
|
||||
_type = PE_NEUTRAL;
|
||||
_state = PST_NORMAL;
|
||||
_altJournalName = false;
|
||||
_trig.clear();
|
||||
}
|
||||
|
||||
void Person::load(rapidxml::xml_node<char> *node, const pyrodactyl::stat::StatTemplates &stem) {
|
||||
if (nodeValid(node)) {
|
||||
loadStr(_id, "id", node);
|
||||
loadStr(_name, "name", node);
|
||||
// loadImgKey(pic, "img", node);
|
||||
|
||||
if (nodeValid("opinion", node))
|
||||
_opinion.load(node->first_node("opinion"));
|
||||
|
||||
if (node->first_attribute("type") != nullptr) {
|
||||
Common::String t;
|
||||
loadStr(t, "type", node);
|
||||
_type = stringToPersonType(t);
|
||||
} else
|
||||
_type = PE_NEUTRAL;
|
||||
|
||||
if (node->first_attribute("state") != nullptr) {
|
||||
Common::String s;
|
||||
loadStr(s, "state", node);
|
||||
_state = stringToPersonState(s);
|
||||
} else
|
||||
_state = PST_NORMAL;
|
||||
|
||||
if (node->first_attribute("journal_name") != nullptr) {
|
||||
loadStr(_journalName, "journal_name", node);
|
||||
_altJournalName = true;
|
||||
} else
|
||||
_altJournalName = false;
|
||||
|
||||
if (nodeValid("stats", node)) {
|
||||
rapidxml::xml_node<char> *statnode = node->first_node("stats");
|
||||
if (statnode->first_attribute("template") == nullptr) {
|
||||
_stat.load(statnode);
|
||||
} else {
|
||||
int index = 0;
|
||||
loadNum(index, "template", statnode);
|
||||
if (index >= 0 && (uint)index < stem._collection.size())
|
||||
for (int i = 0; i < STAT_TOTAL; i++)
|
||||
_stat._val[i] = stem._collection[index]._val[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (nodeValid("traits", node, false)) {
|
||||
rapidxml::xml_node<char> *traitnode = node->first_node("traits");
|
||||
for (auto n = traitnode->first_node("trait"); n != nullptr; n = n->next_sibling("trait"))
|
||||
_trait.push_back(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Person::reset() {
|
||||
for (auto i = 0; i < STAT_TOTAL; ++i)
|
||||
_stat._val[i].reset();
|
||||
}
|
||||
|
||||
void Person::validate() {
|
||||
for (int i = 0; i < STAT_TOTAL; ++i)
|
||||
_stat._val[i].validate();
|
||||
}
|
||||
|
||||
void Person::saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root) {
|
||||
rapidxml::xml_node<char> *child = doc.allocate_node(rapidxml::node_element, "object");
|
||||
child->append_attribute(doc.allocate_attribute("id", _id.c_str()));
|
||||
child->append_attribute(doc.allocate_attribute("name", _name.c_str()));
|
||||
|
||||
uint val = static_cast<uint>(_state);
|
||||
child->append_attribute(doc.allocate_attribute("state", g_engine->_stringPool->get(val)));
|
||||
|
||||
_opinion.saveState(doc, child);
|
||||
|
||||
rapidxml::xml_node<char> *child_s = doc.allocate_node(rapidxml::node_element, "stats");
|
||||
_stat._val[STAT_HEALTH].saveState(doc, child_s, STATNAME_HEALTH);
|
||||
_stat._val[STAT_ATTACK].saveState(doc, child_s, STATNAME_ATTACK);
|
||||
_stat._val[STAT_DEFENSE].saveState(doc, child_s, STATNAME_DEFENSE);
|
||||
_stat._val[STAT_SPEED].saveState(doc, child_s, STATNAME_SPEED);
|
||||
/*stat.val[STAT_CHARISMA].saveState(doc, child_s, STATNAME_CHARISMA);
|
||||
stat.val[STAT_INTELLIGENCE].saveState(doc, child_s, STATNAME_INTELLIGENCE);*/
|
||||
child->append_node(child_s);
|
||||
|
||||
rapidxml::xml_node<char> *child_t = doc.allocate_node(rapidxml::node_element, "traits");
|
||||
for (auto &i : _trait)
|
||||
i.saveState(doc, child_t, "trait");
|
||||
child->append_node(child_t);
|
||||
|
||||
root->append_node(child);
|
||||
}
|
||||
|
||||
void Person::loadState(rapidxml::xml_node<char> *node) {
|
||||
loadStr(_id, "id", node);
|
||||
loadStr(_name, "name", node);
|
||||
loadEnum(_state, "state", node);
|
||||
|
||||
if (nodeValid("opinion", node))
|
||||
_opinion.load(node->first_node("opinion"));
|
||||
|
||||
if (nodeValid("stats", node))
|
||||
_stat.load(node->first_node("stats"));
|
||||
|
||||
if (nodeValid("traits", node, false)) {
|
||||
rapidxml::xml_node<char> *traitnode = node->first_node("traits");
|
||||
|
||||
_trait.clear();
|
||||
for (auto n = traitnode->first_node("trait"); n != nullptr; n = n->next_sibling("trait"))
|
||||
_trait.push_back(n);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
93
engines/crab/people/person.h
Normal file
93
engines/crab/people/person.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRAB_PERSON_H
|
||||
#define CRAB_PERSON_H
|
||||
|
||||
#include "crab/stat/StatTemplate.h"
|
||||
#include "crab/people/opinion.h"
|
||||
#include "crab/people/personbase.h"
|
||||
#include "crab/people/trait.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace people {
|
||||
struct Person {
|
||||
// The id of the object
|
||||
Common::String _id;
|
||||
|
||||
// Opinion of the person towards the player
|
||||
Opinion _opinion;
|
||||
|
||||
// The state of the object, defines what behavior it is doing right now
|
||||
PersonState _state;
|
||||
|
||||
// The stats of the character
|
||||
pyrodactyl::stat::StatGroup _stat;
|
||||
|
||||
// Name of object
|
||||
Common::String _name;
|
||||
|
||||
// Type of object
|
||||
PersonType _type;
|
||||
|
||||
// Sometimes a person's journal entry isn't the same as their name
|
||||
Common::String _journalName;
|
||||
|
||||
// If this is true, use the alternate journal name instead
|
||||
bool _altJournalName;
|
||||
|
||||
// The picture of the object - DISABLED DUE TO LOW BUDGET
|
||||
// ImageKey pic;
|
||||
|
||||
// The trigger areas the person is in right now
|
||||
Common::Array<int> _trig;
|
||||
|
||||
// The traits of a person
|
||||
Common::Array<Trait> _trait;
|
||||
|
||||
Person();
|
||||
void load(rapidxml::xml_node<char> *node, const pyrodactyl::stat::StatTemplates &stem);
|
||||
|
||||
void reset();
|
||||
void validate();
|
||||
|
||||
void saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root);
|
||||
void loadState(rapidxml::xml_node<char> *node);
|
||||
};
|
||||
|
||||
typedef Common::HashMap<Common::String, Person> PersonMap;
|
||||
} // End of namespace people
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_PERSON_H
|
||||
64
engines/crab/people/personbase.cpp
Normal file
64
engines/crab/people/personbase.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "crab/people/personbase.h"
|
||||
namespace Crab {
|
||||
namespace pyrodactyl {
|
||||
namespace people {
|
||||
|
||||
PersonType stringToPersonType(const Common::String &val) {
|
||||
if (val == "neutral")
|
||||
return PE_NEUTRAL;
|
||||
else if (val == "hostile")
|
||||
return PE_HOSTILE;
|
||||
else if (val == "coward")
|
||||
return PE_COWARD;
|
||||
else if (val == "immobile")
|
||||
return PE_IMMOBILE;
|
||||
|
||||
return PE_NEUTRAL;
|
||||
}
|
||||
|
||||
PersonState stringToPersonState(const Common::String &val) {
|
||||
if (val == "ko")
|
||||
return PST_KO;
|
||||
else if (val == "fight")
|
||||
return PST_FIGHT;
|
||||
else if (val == "flee")
|
||||
return PST_FLEE;
|
||||
else if (val == "dying")
|
||||
return PST_DYING;
|
||||
|
||||
return PST_NORMAL;
|
||||
}
|
||||
} // End of namespace people
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
73
engines/crab/people/personbase.h
Normal file
73
engines/crab/people/personbase.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRAB_PERSONBASE_H
|
||||
#define CRAB_PERSONBASE_H
|
||||
|
||||
#include "common/str.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace people {
|
||||
// What each type is, and what it does
|
||||
// neutral - peaceful person who will fight back on being attacked
|
||||
// hostile - person who will attack you on sight
|
||||
// coward - person who will flee on being attacked
|
||||
// immobile - person who cannot move but can be killed
|
||||
enum PersonType {
|
||||
PE_NEUTRAL,
|
||||
PE_HOSTILE,
|
||||
PE_COWARD,
|
||||
PE_IMMOBILE
|
||||
};
|
||||
|
||||
// What each state is, and what it does
|
||||
// normal - person doing his default movement
|
||||
// fight - person fighting you
|
||||
// flee - person running away from you
|
||||
// ko - person is dead/knocked out
|
||||
// dying - play the dying animation
|
||||
enum PersonState {
|
||||
PST_NORMAL,
|
||||
PST_FIGHT,
|
||||
PST_FLEE,
|
||||
PST_KO,
|
||||
PST_DYING
|
||||
};
|
||||
|
||||
PersonType stringToPersonType(const Common::String &val);
|
||||
PersonState stringToPersonState(const Common::String &val);
|
||||
} // End of namespace people
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_PERSONBASE_H
|
||||
76
engines/crab/people/trait.cpp
Normal file
76
engines/crab/people/trait.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "crab/crab.h"
|
||||
#include "crab/GameParam.h"
|
||||
#include "crab/people/trait.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
using namespace pyrodactyl::people;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Purpose: Load
|
||||
//------------------------------------------------------------------------
|
||||
void Trait::load(rapidxml::xml_node<char> *node) {
|
||||
loadStr(_idStr, "id", node);
|
||||
_id = stringToNumber<int>(_idStr);
|
||||
|
||||
loadStr(_name, "name", node);
|
||||
loadStr(_desc, "desc", node);
|
||||
loadImgKey(_img, "img", node);
|
||||
loadBool(_unread, "unread", node);
|
||||
}
|
||||
|
||||
void Trait::clear() {
|
||||
_id = -1;
|
||||
_idStr = "";
|
||||
_name = "";
|
||||
_desc = "";
|
||||
_img = 0;
|
||||
_unread = false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Purpose: Save and load state
|
||||
//------------------------------------------------------------------------
|
||||
void Trait::saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root, const char *rootname) {
|
||||
rapidxml::xml_node<char> *child = doc.allocate_node(rapidxml::node_element, rootname);
|
||||
child->append_attribute(doc.allocate_attribute("id", g_engine->_stringPool->get(_id)));
|
||||
child->append_attribute(doc.allocate_attribute("name", _name.c_str()));
|
||||
child->append_attribute(doc.allocate_attribute("desc", _desc.c_str()));
|
||||
child->append_attribute(doc.allocate_attribute("img", g_engine->_stringPool->get(_img)));
|
||||
|
||||
saveBool(_unread, "unread", doc, child);
|
||||
|
||||
root->append_node(child);
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
79
engines/crab/people/trait.h
Normal file
79
engines/crab/people/trait.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRAB_TRAIT_H
|
||||
#define CRAB_TRAIT_H
|
||||
|
||||
#include "crab/image/ImageManager.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace people {
|
||||
struct Trait {
|
||||
// The id of the trait
|
||||
int _id;
|
||||
|
||||
// Used for achievements
|
||||
Common::String _idStr;
|
||||
|
||||
// The name of the trait
|
||||
Common::String _name;
|
||||
|
||||
// The description of the trait
|
||||
Common::String _desc;
|
||||
|
||||
// The image used to draw the trait
|
||||
ImageKey _img;
|
||||
|
||||
// Indicator for traits the player hasn't read before
|
||||
bool _unread;
|
||||
|
||||
Trait() {
|
||||
_id = -1;
|
||||
_img = 0;
|
||||
_unread = true;
|
||||
}
|
||||
Trait(rapidxml::xml_node<char> *node) : Trait() {
|
||||
load(node);
|
||||
}
|
||||
|
||||
~Trait() {}
|
||||
|
||||
void clear();
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
void saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root, const char *rootname);
|
||||
};
|
||||
} // End of namespace people
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_TRAIT_H
|
||||
Reference in New Issue
Block a user