Initial commit
This commit is contained in:
115
engines/crab/stat/Stat.cpp
Normal file
115
engines/crab/stat/Stat.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/* 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/stat/Stat.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace stat {
|
||||
StatType stringToStatType(const Common::String &val) {
|
||||
if (val == STATNAME_HEALTH)
|
||||
return STAT_HEALTH;
|
||||
else if (val == STATNAME_ATTACK)
|
||||
return STAT_ATTACK;
|
||||
else if (val == STATNAME_DEFENSE)
|
||||
return STAT_DEFENSE;
|
||||
else if (val == STATNAME_SPEED)
|
||||
return STAT_SPEED;
|
||||
/*else if(val == STATNAME_CHARISMA) return STAT_CHARISMA;
|
||||
|
||||
return STAT_INTELLIGENCE;*/
|
||||
return STAT_HEALTH;
|
||||
}
|
||||
|
||||
const char *statTypeToString(const StatType &val) {
|
||||
if (val == STAT_HEALTH)
|
||||
return STATNAME_HEALTH;
|
||||
else if (val == STAT_ATTACK)
|
||||
return STATNAME_ATTACK;
|
||||
else if (val == STAT_DEFENSE)
|
||||
return STATNAME_DEFENSE;
|
||||
else if (val == STAT_SPEED)
|
||||
return STATNAME_SPEED;
|
||||
/*else if(val == STAT_CHARISMA) return STATNAME_CHARISMA;
|
||||
|
||||
return STATNAME_INTELLIGENCE;*/
|
||||
return STATNAME_HEALTH;
|
||||
}
|
||||
} // End of namespace stat
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
using namespace pyrodactyl::stat;
|
||||
|
||||
void Stat::load(rapidxml::xml_node<char> *node) {
|
||||
loadNum(_cur, "cur", node);
|
||||
loadNum(_def, "def", node);
|
||||
loadNum(_min, "min", node);
|
||||
loadNum(_max, "max", node);
|
||||
}
|
||||
|
||||
void StatGroup::load(rapidxml::xml_node<char> *node) {
|
||||
_val[STAT_HEALTH].load(node->first_node(STATNAME_HEALTH));
|
||||
_val[STAT_ATTACK].load(node->first_node(STATNAME_ATTACK));
|
||||
_val[STAT_DEFENSE].load(node->first_node(STATNAME_DEFENSE));
|
||||
_val[STAT_SPEED].load(node->first_node(STATNAME_SPEED));
|
||||
/*val[STAT_CHARISMA].load(node->first_node(STATNAME_CHARISMA));
|
||||
val[STAT_INTELLIGENCE].load(node->first_node(STATNAME_INTELLIGENCE));*/
|
||||
}
|
||||
|
||||
void StatGroup::change(const pyrodactyl::stat::StatType &type, const int &change) {
|
||||
_val[type]._cur += change;
|
||||
_val[type].validate();
|
||||
}
|
||||
|
||||
void StatGroup::set(const pyrodactyl::stat::StatType &type, const int &num) {
|
||||
_val[type]._cur = num;
|
||||
_val[type].validate();
|
||||
}
|
||||
|
||||
void Stat::validate() {
|
||||
if (_cur < _min)
|
||||
_cur = _min;
|
||||
else if (_cur > _max)
|
||||
_cur = _max;
|
||||
}
|
||||
|
||||
void Stat::saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root, const char *name) {
|
||||
rapidxml::xml_node<char> *child = doc.allocate_node(rapidxml::node_element, name);
|
||||
child->append_attribute(doc.allocate_attribute("cur", g_engine->_stringPool->get(_cur)));
|
||||
child->append_attribute(doc.allocate_attribute("def", g_engine->_stringPool->get(_def)));
|
||||
child->append_attribute(doc.allocate_attribute("min", g_engine->_stringPool->get(_min)));
|
||||
child->append_attribute(doc.allocate_attribute("max", g_engine->_stringPool->get(_max)));
|
||||
root->append_node(child);
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
85
engines/crab/stat/Stat.h
Normal file
85
engines/crab/stat/Stat.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/* 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_STAT_H
|
||||
#define CRAB_STAT_H
|
||||
|
||||
#include "common/str.h"
|
||||
#include "crab/gametype.h"
|
||||
#include "crab/rapidxml/rapidxml.hpp"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace stat {
|
||||
struct Stat {
|
||||
// The current, default, minimum and maximum value of the stat
|
||||
int _cur, _def, _min, _max;
|
||||
|
||||
Stat() {
|
||||
_min = 0;
|
||||
_max = 1;
|
||||
_cur = 1;
|
||||
_def = 1;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_cur = _def;
|
||||
}
|
||||
|
||||
void validate();
|
||||
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
void saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root, const char *name);
|
||||
};
|
||||
|
||||
struct StatGroup {
|
||||
// We group all stats a single person can have
|
||||
Stat _val[STAT_TOTAL];
|
||||
|
||||
StatGroup() {}
|
||||
StatGroup(rapidxml::xml_node<char> *node) {
|
||||
load(node);
|
||||
}
|
||||
|
||||
void change(const pyrodactyl::stat::StatType &type, const int &change);
|
||||
void set(const pyrodactyl::stat::StatType &type, const int &val);
|
||||
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
};
|
||||
|
||||
StatType stringToStatType(const Common::String &val);
|
||||
const char *statTypeToString(const StatType &val);
|
||||
} // End of namespace stat
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_STAT_H
|
||||
84
engines/crab/stat/StatDrawHelper.cpp
Normal file
84
engines/crab/stat/StatDrawHelper.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/* 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/stat/StatDrawHelper.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
using namespace pyrodactyl::text;
|
||||
using namespace pyrodactyl::stat;
|
||||
using namespace pyrodactyl::people;
|
||||
|
||||
void StatInfo::load(rapidxml::xml_node<char> *node) {
|
||||
if (nodeValid(node)) {
|
||||
loadBool(_active, "active", node);
|
||||
_desc.load(node->first_node("info"));
|
||||
loadStr(_text, "text", node->first_node("info"));
|
||||
|
||||
if (nodeValid("value", node)) {
|
||||
rapidxml::xml_node<char> *valuenode = node->first_node("value");
|
||||
_dim.load(valuenode);
|
||||
loadImgKey(_full, "full", valuenode);
|
||||
loadImgKey(_empty, "empty", valuenode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StatInfo::draw(const int &val, const int &max) {
|
||||
if (_active) {
|
||||
using namespace pyrodactyl::image;
|
||||
_desc.draw(_text);
|
||||
|
||||
int i = 0;
|
||||
for (; i < val; ++i)
|
||||
g_engine->_imageManager->draw(_dim.x + i * _dim.w, _dim.y + i * _dim.h, _full);
|
||||
for (; i < max; ++i)
|
||||
g_engine->_imageManager->draw(_dim.x + i * _dim.w, _dim.y + i * _dim.h, _empty);
|
||||
}
|
||||
}
|
||||
|
||||
void StatDrawHelper::load(rapidxml::xml_node<char> *node) {
|
||||
if (nodeValid(node)) {
|
||||
_info[STAT_HEALTH].load(node->first_node(STATNAME_HEALTH));
|
||||
_info[STAT_ATTACK].load(node->first_node(STATNAME_ATTACK));
|
||||
_info[STAT_DEFENSE].load(node->first_node(STATNAME_DEFENSE));
|
||||
_info[STAT_SPEED].load(node->first_node(STATNAME_SPEED));
|
||||
/*info[STAT_CHARISMA].load(node->first_node(STATNAME_CHARISMA));
|
||||
info[STAT_INTELLIGENCE].load(node->first_node(STATNAME_INTELLIGENCE));*/
|
||||
}
|
||||
}
|
||||
|
||||
void StatDrawHelper::drawInfo(const pyrodactyl::people::Person &obj) {
|
||||
for (int i = 0; i < STAT_TOTAL; i++)
|
||||
_info[i].draw(obj._stat._val[i]._cur, obj._stat._val[i]._max);
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
79
engines/crab/stat/StatDrawHelper.h
Normal file
79
engines/crab/stat/StatDrawHelper.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_STATDRAWHELPER_H
|
||||
#define CRAB_STATDRAWHELPER_H
|
||||
|
||||
#include "crab/people/person.h"
|
||||
#include "crab/ui/TextData.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace stat {
|
||||
struct StatInfo {
|
||||
// Used to draw stat value and description
|
||||
pyrodactyl::ui::TextData _desc;
|
||||
Common::String _text;
|
||||
|
||||
Rect _dim;
|
||||
ImageKey _full, _empty;
|
||||
bool _active;
|
||||
|
||||
StatInfo() {
|
||||
_active = false;
|
||||
_full = 0;
|
||||
_empty = 0;
|
||||
}
|
||||
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
void draw(const int &val, const int &max);
|
||||
};
|
||||
|
||||
class StatDrawHelper {
|
||||
StatInfo _info[STAT_TOTAL];
|
||||
|
||||
public:
|
||||
StatDrawHelper() {}
|
||||
~StatDrawHelper() {}
|
||||
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
void drawInfo(const pyrodactyl::people::Person &obj);
|
||||
|
||||
const Common::String &name(const StatType &type) {
|
||||
return _info[type]._text;
|
||||
}
|
||||
};
|
||||
} // End of namespace stat
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_STATDRAWHELPER_H
|
||||
48
engines/crab/stat/StatTemplate.cpp
Normal file
48
engines/crab/stat/StatTemplate.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/* 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/stat/StatTemplate.h"
|
||||
#include "crab/XMLDoc.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
using namespace pyrodactyl::stat;
|
||||
|
||||
void StatTemplates::load(const Common::Path &filename) {
|
||||
XMLDoc conf(filename);
|
||||
if (conf.ready()) {
|
||||
rapidxml::xml_node<char> *node = conf.doc()->first_node("templates");
|
||||
for (auto n = node->first_node("stats"); n != nullptr; n = n->next_sibling("stats"))
|
||||
_collection.push_back(n);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
56
engines/crab/stat/StatTemplate.h
Normal file
56
engines/crab/stat/StatTemplate.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/* 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_STATTEMPLATE_H
|
||||
#define CRAB_STATTEMPLATE_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/path.h"
|
||||
#include "crab/stat/Stat.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace stat {
|
||||
struct StatTemplates {
|
||||
Common::Array<StatGroup> _collection;
|
||||
|
||||
public:
|
||||
StatTemplates() {}
|
||||
~StatTemplates() {}
|
||||
|
||||
void load(const Common::Path &filename);
|
||||
};
|
||||
} // End of namespace stat
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_STATTEMPLATE_H
|
||||
55
engines/crab/stat/bonus.h
Normal file
55
engines/crab/stat/bonus.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* 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_BONUS_H
|
||||
#define CRAB_BONUS_H
|
||||
|
||||
#include "crab/loaders.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace stat {
|
||||
// Stat bonuses for an item
|
||||
struct Bonus {
|
||||
StatType _type;
|
||||
int _val;
|
||||
|
||||
void load(rapidxml::xml_node<char> *node) {
|
||||
loadStatType(_type, node);
|
||||
loadNum(_val, "val", node);
|
||||
}
|
||||
};
|
||||
} // End of namespace stat
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_BONUS_H
|
||||
Reference in New Issue
Block a user