add: new graph cmd: "stats", now accessible through cmd, not only via menu.

fix: changed language string hashes to reduce collisions.
This commit is contained in:
ds 2020-08-31 14:52:12 +03:00
commit eadd7cd3a2
6 changed files with 72 additions and 51 deletions

View file

@ -57,7 +57,7 @@ private:
StringArray m_logos;
StringArray m_avatars;
HashMap <uint32, String, Hash <int32>> m_language;
HashMap <uint32, String, Hash <int32>> m_language { 256 };
HashMap <int32, DifficultyData> m_difficulty;
// default tables for personality weapon preferences, overridden by weapon.cfg

View file

@ -104,6 +104,7 @@ private:
int cmdNodeReleaseEditor ();
int cmdNodeUpload ();
int cmdNodeIterateCamp ();
int cmdNodeShowStats ();
private:
int menuMain (int item);

View file

@ -371,6 +371,7 @@ public:
void convertToPOD (const Path &path, PODPath &pod);
void convertCampDirection (Path &path);
void setAutoPathDistance (const float distance);
void showStats ();
const char *getDataDirectory (bool isMemoryFile = false);
const char *getOldFormatGraphName (bool isMemoryFile = false);

View file

@ -766,13 +766,21 @@ const char *BotConfig::translate (StringRef input) {
uint32 BotConfig::hashLangString (const char *input) {
auto str = reinterpret_cast <uint8 *> (const_cast <char *> (input));
uint32 hash = 0;
uint32_t hash = 0;
while (*str++) {
for (; *str; ++str) {
if (!isalnum (*str)) {
continue;
}
hash = ((*str << 5) + hash) + *str;
hash += *str;
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}

View file

@ -325,6 +325,7 @@ int BotControl::cmdNode () {
addGraphCmd ("flags", "flags [noarguments]", "Open and displays menu for modifying flags for nearest point.", &BotControl::cmdNodeSetFlags);
addGraphCmd ("teleport", "teleport [index]", "Teleports player to specified node index.", &BotControl::cmdNodeTeleport);
addGraphCmd ("upload", "upload [id]", "Uploads created graph to graph database.", &BotControl::cmdNodeUpload);
addGraphCmd ("stats", "[noarguments]", "Shows the stats about node types on the map.", &BotControl::cmdNodeShowStats);
// add path commands
addGraphCmd ("path_create", "path_create [noarguments]", "Opens and displays path creation menu.", &BotControl::cmdNodePathCreate);
@ -842,6 +843,14 @@ int BotControl::cmdNodeIterateCamp () {
return BotCommandResult::Handled;
}
int BotControl::cmdNodeShowStats () {
enum args { graph_cmd = 1 };
graph.showStats ();
return BotCommandResult::Handled;
}
int BotControl::menuMain (int item) {
showMenu (Menu::None); // reset menu display
@ -1222,54 +1231,11 @@ int BotControl::menuGraphPage2 (int item) {
showMenu (Menu::None); // reset menu display
switch (item) {
case 1: {
int terrPoints = 0;
int ctPoints = 0;
int goalPoints = 0;
int rescuePoints = 0;
int campPoints = 0;
int sniperPoints = 0;
int noHostagePoints = 0;
for (int i = 0; i < graph.length (); ++i) {
const Path &path = graph[i];
if (path.flags & NodeFlag::TerroristOnly) {
++terrPoints;
}
if (path.flags & NodeFlag::CTOnly) {
++ctPoints;
}
if (path.flags & NodeFlag::Goal) {
++goalPoints;
}
if (path.flags & NodeFlag::Rescue) {
++rescuePoints;
}
if (path.flags & NodeFlag::Camp) {
++campPoints;
}
if (path.flags & NodeFlag::Sniper) {
++sniperPoints;
}
if (path.flags & NodeFlag::NoHostage) {
++noHostagePoints;
}
}
msg ("Nodes: %d - T Points: %d\n"
"CT Points: %d - Goal Points: %d\n"
"Rescue Points: %d - Camp Points: %d\n"
"Block Hostage Points: %d - Sniper Points: %d\n",
graph.length (), terrPoints, ctPoints, goalPoints, rescuePoints, campPoints, noHostagePoints, sniperPoints);
case 1:
graph.showStats ();
showMenu (Menu::NodeMainPage2);
} break;
break;
case 2:
graph.setEditFlag (GraphEdit::On);

View file

@ -1076,6 +1076,51 @@ void BotGraph::setAutoPathDistance (const float distance) {
}
}
void BotGraph::showStats () {
int terrPoints = 0;
int ctPoints = 0;
int goalPoints = 0;
int rescuePoints = 0;
int campPoints = 0;
int sniperPoints = 0;
int noHostagePoints = 0;
for (const auto &path : m_paths) {
if (path.flags & NodeFlag::TerroristOnly) {
++terrPoints;
}
if (path.flags & NodeFlag::CTOnly) {
++ctPoints;
}
if (path.flags & NodeFlag::Goal) {
++goalPoints;
}
if (path.flags & NodeFlag::Rescue) {
++rescuePoints;
}
if (path.flags & NodeFlag::Camp) {
++campPoints;
}
if (path.flags & NodeFlag::Sniper) {
++sniperPoints;
}
if (path.flags & NodeFlag::NoHostage) {
++noHostagePoints;
}
}
ctrl.msg ("Nodes: %d - T Points: %d", m_paths.length (), terrPoints);
ctrl.msg ("CT Points: %d - Goal Points: %d", ctPoints, goalPoints);
ctrl.msg ("Rescue Points: %d - Camp Points: %d", rescuePoints, campPoints);
ctrl.msg ("Block Hostage Points: %d - Sniper Points: %d", noHostagePoints, sniperPoints);
}
void BotGraph::calculatePathRadius (int index) {
// calculate "wayzones" for the nearest node (meaning a dynamic distance area to vary node origin)