1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 02:12:45 +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,
PLAYER2,
PLAYER3,
PLAYER_4,
PLAYER4,
CIVMALE,
CIVFEMALE,
COP,
@ -365,6 +365,7 @@ public:
_UNNAMED,
PROSTITUTE,
SPECIAL,
_NUM_PEDTYPE
};
PedType pedtype_ = PLAYER1;
@ -380,7 +381,7 @@ public:
{"PLAYER1", PLAYER1},
{"PLAYER2", PLAYER2},
{"PLAYER3", PLAYER3},
{"PLAYER_4", PLAYER_4},
{"PLAYER4", PLAYER4},
{"CIVMALE", CIVMALE},
{"CIVFEMALE", CIVFEMALE},
{"COP", COP},

View File

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

View File

@ -18,24 +18,52 @@ public:
float attackstrength_;
float defendweakness_;
uint32_t flags_;
};
using PedStatsList = std::vector<PedStats>;
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
float a_;
float b_;
float c_;
float d_;
float e_;
float a_ = 0.f;
float b_ = 0.f;
float c_ = 0.f;
float d_ = 0.f;
float e_ = 0.f;
uint32_t threatflags_;
uint32_t avoidflags_;
uint32_t threatflags_ = 0;
uint32_t avoidflags_ = 0;
public:
static uint32_t threatFromName(const std::string& name);
};

View File

@ -54,6 +54,7 @@ void GameData::load() {
loadWaterpro("data/waterpro.dat");
loadWeaponDAT("data/weapon.dat");
loadPedStats("data/pedstats.dat");
loadPedRelations("data/ped.dat");
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) {
auto systempath = index.findFilePath("audio/" + name).string();

View File

@ -165,6 +165,11 @@ public:
*/
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 loadAudioClip(const std::string& name, const std::string& fileName);
@ -283,6 +288,11 @@ public:
*/
std::vector<PedStats> pedstats;
/**
* Pedestrian relationships
*/
std::array<PedRelationship, PedModelInfo::_NUM_PEDTYPE> pedrels;
/**
* @struct WaterArea
* 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_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
BOOST_AUTO_TEST_SUITE_END()