1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

Load ped type relationship data

This commit is contained in:
Daniel Evans 2017-01-16 20:39:35 +00:00
parent b0e7cbdadd
commit 79533fac8a
6 changed files with 141 additions and 38 deletions

View File

@ -346,7 +346,7 @@ public:
PLAYER1 = 0, PLAYER1 = 0,
PLAYER2, PLAYER2,
PLAYER3, PLAYER3,
PLAYER_4, PLAYER4,
CIVMALE, CIVMALE,
CIVFEMALE, CIVFEMALE,
COP, COP,
@ -365,6 +365,7 @@ public:
_UNNAMED, _UNNAMED,
PROSTITUTE, PROSTITUTE,
SPECIAL, SPECIAL,
_NUM_PEDTYPE
}; };
PedType pedtype_ = PLAYER1; PedType pedtype_ = PLAYER1;
@ -380,7 +381,7 @@ public:
{"PLAYER1", PLAYER1}, {"PLAYER1", PLAYER1},
{"PLAYER2", PLAYER2}, {"PLAYER2", PLAYER2},
{"PLAYER3", PLAYER3}, {"PLAYER3", PLAYER3},
{"PLAYER_4", PLAYER_4}, {"PLAYER4", PLAYER4},
{"CIVMALE", CIVMALE}, {"CIVMALE", CIVMALE},
{"CIVFEMALE", CIVFEMALE}, {"CIVFEMALE", CIVFEMALE},
{"COP", COP}, {"COP", COP},

View File

@ -3,32 +3,32 @@
uint32_t PedRelationship::threatFromName(const std::string &name) { uint32_t PedRelationship::threatFromName(const std::string &name) {
static const std::unordered_map<std::string, uint32_t> kThreatMap{ static const std::unordered_map<std::string, uint32_t> kThreatMap{
{"PLAYER1", 1}, // Player {"PLAYER1", THREAT_PLAYER1}, // Player
{"PLAYER2", 2}, // Unused {"PLAYER2", THREAT_PLAYER2}, // Unused
{"PLAYER3", 3}, // Unused {"PLAYER3", THREAT_PLAYER3}, // Unused
{"PLAYER4", 4}, // Unused {"PLAYER4", THREAT_PLAYER4}, // Unused
{"CIVMALE", 16}, // Civilan {"CIVMALE", THREAT_CIVMALE}, // Civilan
{"CIVFEMALE", 32}, // Civilan {"CIVFEMALE", THREAT_CIVFEMALE}, // Civilan
{"COP", 64}, // Police {"COP", THREAT_COP}, // Police
{"GANG1", 128}, // Mafia {"GANG1", THREAT_GANG1}, // Mafia
{"GANG2", 256}, // Triad {"GANG2", THREAT_GANG2}, // Triad
{"GANG3", 512}, // Diablo {"GANG3", THREAT_GANG3}, // Diablo
{"GANG4", 1024}, // Yakuza {"GANG4", THREAT_GANG4}, // Yakuza
{"GANG5", 2048}, // Yardie {"GANG5", THREAT_GANG5}, // Yardie
{"GANG6", 4096}, // Columbian {"GANG6", THREAT_GANG6}, // Columbian
{"GANG7", 8192}, // Hood {"GANG7", THREAT_GANG7}, // Hood
{"GANG8", 16384}, // Unused {"GANG8", THREAT_GANG8}, // Unused
{"GANG9", 32768}, // Unused {"GANG9", THREAT_GANG9}, // Unused
{"EMERGENCY", 65536}, // Emergency services {"EMERGENCY", THREAT_EMERGENCY}, // Emergency services
{"PROSTITUTE", 131072}, // ... {"PROSTITUTE", THREAT_PROSTITUTE}, // ...
{"CRIMINAL", 262144}, // Criminals {"CRIMINAL", THREAT_CRIMINAL}, // Criminals
{"SPECIAL", 524288}, // SPECIAL {"SPECIAL", THREAT_SPECIAL}, // SPECIAL
{"GUN", 1048576}, // Not sure {"GUN", THREAT_GUN}, // Not sure
{"COP_CAR", 2097152}, {"COP_CAR", THREAT_COP_CAR},
{"FAST_CAR", 4194304}, {"FAST_CAR", THREAT_FAST_CAR},
{"EXPLOSION", 8388608}, // Explosions {"EXPLOSION", THREAT_EXPLOSION}, // Explosions
{"FIREMAN", 16777216}, // Firemen? {"FIREMAN", THREAT_FIREMAN}, // Firemen?
{"DEADPEDS", 33554432}, // Dead bodies {"DEADPEDS", THREAT_DEADPEDS}, // Dead bodies
}; };
return kThreatMap.at(name); return kThreatMap.at(name);

View File

@ -18,24 +18,52 @@ public:
float attackstrength_; float attackstrength_;
float defendweakness_; float defendweakness_;
uint32_t flags_; uint32_t flags_;
}; };
using PedStatsList = std::vector<PedStats>; using PedStatsList = std::vector<PedStats>;
class PedRelationship { class PedRelationship {
uint32_t id_; public:
enum {
THREAT_PLAYER1 = 1, // Player
THREAT_PLAYER2 = 2, // Unused
THREAT_PLAYER3 = 3, // Unused
THREAT_PLAYER4 = 4, // Unused
THREAT_CIVMALE = 16, // Civilan
THREAT_CIVFEMALE = 32, // Civilan
THREAT_COP = 64, // Police
THREAT_GANG1 = 128, // Mafia
THREAT_GANG2 = 256, // Triad
THREAT_GANG3 = 512, // Diablo
THREAT_GANG4 = 1024, // Yakuza
THREAT_GANG5 = 2048, // Yardie
THREAT_GANG6 = 4096, // Columbian
THREAT_GANG7 = 8192, // Hood
THREAT_GANG8 = 16384, // Unused
THREAT_GANG9 = 32768, // Unused
THREAT_EMERGENCY = 65536, // Emergency services
THREAT_PROSTITUTE = 131072, // ...
THREAT_CRIMINAL = 262144, // Criminals
THREAT_SPECIAL = 524288, // SPECIAL
THREAT_GUN = 1048576, // Not sure
THREAT_COP_CAR = 2097152,
THREAT_FAST_CAR = 4194304,
THREAT_EXPLOSION = 8388608, // Explosions
THREAT_FIREMAN = 16777216, // Firemen?
THREAT_DEADPEDS = 33554432, // Dead bodies
};
uint32_t id_ = 0;
// Unknown values // Unknown values
float a_; float a_ = 0.f;
float b_; float b_ = 0.f;
float c_; float c_ = 0.f;
float d_; float d_ = 0.f;
float e_; float e_ = 0.f;
uint32_t threatflags_; uint32_t threatflags_ = 0;
uint32_t avoidflags_; uint32_t avoidflags_ = 0;
public:
static uint32_t threatFromName(const std::string& name); static uint32_t threatFromName(const std::string& name);
}; };

View File

@ -54,6 +54,7 @@ void GameData::load() {
loadWaterpro("data/waterpro.dat"); loadWaterpro("data/waterpro.dat");
loadWeaponDAT("data/weapon.dat"); loadWeaponDAT("data/weapon.dat");
loadPedStats("data/pedstats.dat"); loadPedStats("data/pedstats.dat");
loadPedRelations("data/ped.dat");
loadIFP("ped.ifp"); loadIFP("ped.ifp");
@ -524,6 +525,50 @@ void GameData::loadPedStats(const std::string& path) {
} }
} }
void GameData::loadPedRelations(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;
for (int index = 0; std::getline(fs, line);) {
if (line.empty() || line[0] == '#') {
continue;
}
std::stringstream ss(line);
if (isspace(line[0])) {
// Add this flags to the last index
ss >> line;
if (line == "Avoid") {
while (!ss.eof()) {
ss >> line;
auto flag = PedRelationship::threatFromName(line);
pedrels[index].avoidflags_ |= flag;
}
}
if (line == "Threat") {
while (!ss.eof()) {
ss >> line;
auto flag = PedRelationship::threatFromName(line);
pedrels[index].threatflags_ |= flag;
}
}
} else {
ss >> line;
index = PedModelInfo::findPedType(line);
PedRelationship& shp = pedrels[index];
shp.id_ = PedRelationship::threatFromName(line);
ss >> shp.a_;
ss >> shp.b_;
ss >> shp.c_;
ss >> shp.d_;
ss >> shp.e_;
}
}
}
bool GameData::loadAudioStream(const std::string& name) { bool GameData::loadAudioStream(const std::string& name) {
auto systempath = index.findFilePath("audio/" + name).string(); auto systempath = index.findFilePath("audio/" + name).string();

View File

@ -165,6 +165,11 @@ public:
*/ */
void loadPedStats(const std::string& path); void loadPedStats(const std::string& path);
/**
* Loads pedestrian relations e.g. peds.dat
*/
void loadPedRelations(const std::string& path);
bool loadAudioStream(const std::string& name); bool loadAudioStream(const std::string& name);
bool loadAudioClip(const std::string& name, const std::string& fileName); bool loadAudioClip(const std::string& name, const std::string& fileName);
@ -283,6 +288,11 @@ public:
*/ */
std::vector<PedStats> pedstats; std::vector<PedStats> pedstats;
/**
* Pedestrian relationships
*/
std::array<PedRelationship, PedModelInfo::_NUM_PEDTYPE> pedrels;
/** /**
* @struct WaterArea * @struct WaterArea
* Stores Water Rectangle Information * Stores Water Rectangle Information

View File

@ -60,6 +60,25 @@ BOOST_AUTO_TEST_CASE(test_ped_stat_info) {
BOOST_CHECK_EQUAL(cop->statindex_, stat_cop.id_); BOOST_CHECK_EQUAL(cop->statindex_, stat_cop.id_);
} }
BOOST_AUTO_TEST_CASE(test_ped_relations) {
GameData gd(&Global::get().log, Global::getGamePath());
gd.load();
auto& rel_cop = gd.pedrels[PedModelInfo::COP];
auto& rel_crim = gd.pedrels[PedModelInfo::CRIMINAL];
BOOST_CHECK_EQUAL(rel_cop.id_, PedRelationship::THREAT_COP);
BOOST_CHECK_EQUAL(rel_cop.threatflags_,
PedRelationship::THREAT_GUN |
PedRelationship::THREAT_EXPLOSION |
PedRelationship::THREAT_DEADPEDS);
BOOST_CHECK_EQUAL(rel_crim.id_, PedRelationship::THREAT_CRIMINAL);
BOOST_CHECK_EQUAL(rel_crim.threatflags_,
PedRelationship::THREAT_GUN |
PedRelationship::THREAT_COP |
PedRelationship::THREAT_COP_CAR |
PedRelationship::THREAT_EXPLOSION);
}
#endif #endif
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()