mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
Load ped group data
This commit is contained in:
parent
79533fac8a
commit
162ff258c8
@ -67,4 +67,7 @@ public:
|
||||
static uint32_t threatFromName(const std::string& name);
|
||||
};
|
||||
|
||||
using PedGroup = std::vector<uint16_t>;
|
||||
using PedGroupList = std::vector<PedGroup>;
|
||||
|
||||
#endif
|
||||
|
@ -64,6 +64,9 @@ void GameData::load() {
|
||||
|
||||
loadLevelFile("data/default.dat");
|
||||
loadLevelFile("data/gta3.dat");
|
||||
|
||||
// Load ped groups after IDEs so they can resolve
|
||||
loadPedGroups("data/pedgrp.dat");
|
||||
}
|
||||
|
||||
void GameData::loadLevelFile(const std::string& path) {
|
||||
@ -569,6 +572,40 @@ void GameData::loadPedRelations(const std::string& path) {
|
||||
}
|
||||
}
|
||||
|
||||
void GameData::loadPedGroups(const std::string& path) {
|
||||
auto syspath = index.findFilePath(path).string();
|
||||
std::ifstream fs(syspath.c_str());
|
||||
if (!fs.is_open()) {
|
||||
throw std::runtime_error("Failed to open " + path);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(fs, line)) {
|
||||
if (line.empty() || line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
std::stringstream ss(line);
|
||||
PedGroup group;
|
||||
while (ss >> line) {
|
||||
if (line.empty() || line[0] == '#') {
|
||||
break;
|
||||
}
|
||||
if (line.back() == ',') {
|
||||
line.resize(line.size()-1);
|
||||
}
|
||||
auto model = findModelObject(line);
|
||||
if (int16_t(model) == -1) {
|
||||
logger->error("Data", "Invalid model in ped group " + line);
|
||||
continue;
|
||||
}
|
||||
group.push_back(model);
|
||||
}
|
||||
if (!group.empty()) {
|
||||
pedgroups.emplace_back(std::move(group));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GameData::loadAudioStream(const std::string& name) {
|
||||
auto systempath = index.findFilePath("audio/" + name).string();
|
||||
|
||||
|
@ -170,6 +170,11 @@ public:
|
||||
*/
|
||||
void loadPedRelations(const std::string& path);
|
||||
|
||||
/**
|
||||
* Loads pedestrian groups e.g. pedgrp.dat for zone info
|
||||
*/
|
||||
void loadPedGroups(const std::string& path);
|
||||
|
||||
bool loadAudioStream(const std::string& name);
|
||||
bool loadAudioClip(const std::string& name, const std::string& fileName);
|
||||
|
||||
@ -293,6 +298,11 @@ public:
|
||||
*/
|
||||
std::array<PedRelationship, PedModelInfo::_NUM_PEDTYPE> pedrels;
|
||||
|
||||
/**
|
||||
* Pedestrian groups
|
||||
*/
|
||||
PedGroupList pedgroups;
|
||||
|
||||
/**
|
||||
* @struct WaterArea
|
||||
* Stores Water Rectangle Information
|
||||
|
@ -79,6 +79,23 @@ BOOST_AUTO_TEST_CASE(test_ped_relations) {
|
||||
PedRelationship::THREAT_COP_CAR |
|
||||
PedRelationship::THREAT_EXPLOSION);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ped_groups) {
|
||||
GameData gd(&Global::get().log, Global::getGamePath());
|
||||
gd.load();
|
||||
|
||||
BOOST_REQUIRE(gd.pedgroups.size() > 2);
|
||||
|
||||
const auto& def = gd.pedgroups[0];
|
||||
const auto& red = gd.pedgroups[1];
|
||||
|
||||
BOOST_REQUIRE_GE(def.size(), 8);
|
||||
BOOST_CHECK_EQUAL(def[0], 30);
|
||||
|
||||
BOOST_REQUIRE_GE(red.size(), 8);
|
||||
BOOST_CHECK_EQUAL(red[0], 34);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user