Fixed GCC Errors.

This commit is contained in:
Dmitry 2019-07-02 09:33:39 +03:00 committed by jeefo
commit 10e94e0bee
4 changed files with 46 additions and 42 deletions

View file

@ -1246,7 +1246,7 @@ public:
template <typename ...Args> void assign (const char *fmt, Args ...args) { template <typename ...Args> void assign (const char *fmt, Args ...args) {
const size_t size = snprintf (nullptr, 0, fmt, args...); const size_t size = snprintf (nullptr, 0, fmt, args...);
reserve (size + 1); reserve (size + 2); // for null-terminator
resize (size); resize (size);
snprintf (&m_data[0], size + 1, fmt, args...); snprintf (&m_data[0], size + 1, fmt, args...);
@ -1256,7 +1256,7 @@ public:
const size_t size = snprintf (nullptr, 0, fmt, args...) + m_length; const size_t size = snprintf (nullptr, 0, fmt, args...) + m_length;
const size_t len = m_length; const size_t len = m_length;
reserve (size + 1); reserve (size + 2); // for null-terminator
resize (size); resize (size);
snprintf (&m_data[len], size + 1, fmt, args...); snprintf (&m_data[len], size + 1, fmt, args...);

View file

@ -81,13 +81,13 @@ bool BotUtils::checkKeywords (const String &line, String &reply) {
} }
for (auto &factory : conf.getReplies ()) { for (auto &factory : conf.getReplies ()) {
for (auto &keyword : factory.keywords) { for (const auto &keyword : factory.keywords) {
// check is keyword has occurred in message // check is keyword has occurred in message
if (line.find (keyword, 0) != String::INVALID_INDEX) { if (line.find (keyword, 0) != String::INVALID_INDEX) {
StringArray &usedReplies = factory.usedReplies; StringArray &usedReplies = factory.usedReplies;
if (usedReplies.length () >= factory.replies.length () / 2) { if (usedReplies.length () >= factory.replies.length () / 4) {
usedReplies.clear (); usedReplies.clear ();
} }
@ -107,7 +107,6 @@ bool BotUtils::checkKeywords (const String &line, String &reply) {
if (!replyUsed) { if (!replyUsed) {
reply.assign (choosenReply); // update final buffer reply.assign (choosenReply); // update final buffer
usedReplies.push (choosenReply); // add to ignore list usedReplies.push (choosenReply); // add to ignore list
return true; return true;
} }
} }
@ -182,10 +181,10 @@ void Bot::prepareChatMessage (const String &message) {
// get roundtime // get roundtime
auto getRoundTime = [] (void) -> String { auto getRoundTime = [] (void) -> String {
int roundTimeSecs = static_cast <int> (bots.getRoundEndTime () - game.timebase ()); auto roundTimeSecs = static_cast <int> (bots.getRoundEndTime () - game.timebase ());
String roundTime; String roundTime;
roundTime.assign ("%02d:%02d", roundTimeSecs / 60, cr::abs (roundTimeSecs) % 60); roundTime.assign ("%02d:%02d", cr::clamp (roundTimeSecs / 60, 0, 59), cr::clamp (cr::abs (roundTimeSecs % 60), 0, 59));
return cr::move (roundTime); return cr::move (roundTime);
}; };
@ -332,12 +331,13 @@ bool Bot::isReplyingToChat (void) {
// this function sends reply to a player // this function sends reply to a player
if (m_sayTextBuffer.entityIndex != -1 && !m_sayTextBuffer.sayText.empty ()) { if (m_sayTextBuffer.entityIndex != -1 && !m_sayTextBuffer.sayText.empty ()) {
String message;
// check is time to chat is good // check is time to chat is good
if (m_sayTextBuffer.timeNextChat < game.timebase ()) { if (m_sayTextBuffer.timeNextChat < game.timebase ()) {
if (rng.chance (m_sayTextBuffer.chatProbability + rng.getInt (25, 45)) && checkChatKeywords (message)) { String replyText;
prepareChatMessage (message);
if (rng.chance (m_sayTextBuffer.chatProbability + rng.getInt (25, 45)) && checkChatKeywords (replyText)) {
prepareChatMessage (replyText);
pushMsgQueue (GAME_MSG_SAY_CMD); pushMsgQueue (GAME_MSG_SAY_CMD);
m_sayTextBuffer.entityIndex = -1; m_sayTextBuffer.entityIndex = -1;
@ -355,16 +355,15 @@ bool Bot::isReplyingToChat (void) {
void Bot::checkForChat (void) { void Bot::checkForChat (void) {
// say a text every now and then
if (rng.chance (35) || m_notKilled || !yb_chat.boolean ()) {
return;
}
// bot chatting turned on? // bot chatting turned on?
if (!m_notKilled && yb_chat.boolean () && m_lastChatTime + 10.0 < game.timebase () && bots.getLastChatTimestamp () + 5.0f < game.timebase () && !isReplyingToChat ()) { if (m_lastChatTime + 10.0 < game.timebase () && bots.getLastChatTimestamp () + 5.0f < game.timebase () && !isReplyingToChat ()) {
auto &chat = conf.getChat (); auto &chat = conf.getChat ();
// say a text every now and then
if (rng.chance (50)) {
m_lastChatTime = game.timebase ();
bots.setLastChatTimestamp (game.timebase ());
if (!chat[CHAT_DEAD].empty ()) { if (!chat[CHAT_DEAD].empty ()) {
const String &phrase = chat[CHAT_DEAD].random (); const String &phrase = chat[CHAT_DEAD].random ();
bool sayBufferExists = false; bool sayBufferExists = false;
@ -376,11 +375,13 @@ void Bot::checkForChat (void) {
break; break;
} }
} }
if (!sayBufferExists) { if (!sayBufferExists) {
prepareChatMessage (phrase); prepareChatMessage (phrase);
pushMsgQueue (GAME_MSG_SAY_CMD); pushMsgQueue (GAME_MSG_SAY_CMD);
m_lastChatTime = game.timebase ();
bots.setLastChatTimestamp (game.timebase ());
// add to ignore list // add to ignore list
m_sayTextBuffer.lastUsedSentences.push (phrase); m_sayTextBuffer.lastUsedSentences.push (phrase);
} }
@ -391,7 +392,6 @@ void Bot::checkForChat (void) {
m_sayTextBuffer.lastUsedSentences.clear (); m_sayTextBuffer.lastUsedSentences.clear ();
} }
} }
}
} }
void Bot::say (const char *text) { void Bot::say (const char *text) {

View file

@ -460,6 +460,9 @@ void BotManager::reset (void) {
m_quotaMaintainTime = 0.0f; m_quotaMaintainTime = 0.0f;
m_grenadeUpdateTime = 0.0f; m_grenadeUpdateTime = 0.0f;
m_entityUpdateTime = 0.0f; m_entityUpdateTime = 0.0f;
m_plantSearchUpdateTime = 0.0f;
m_lastChatTime = 0.0f;
m_timeBombPlanted = 0.0f;
m_intrestingEntities.clear (); m_intrestingEntities.clear ();
m_activeGrenades.clear (); m_activeGrenades.clear ();
@ -905,7 +908,7 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c
// assign how talkative this bot will be // assign how talkative this bot will be
m_sayTextBuffer.chatDelay = rng.getFloat (3.8f, 10.0f); m_sayTextBuffer.chatDelay = rng.getFloat (3.8f, 10.0f);
m_sayTextBuffer.chatProbability = rng.getInt (1, 100); m_sayTextBuffer.chatProbability = rng.getInt (10, 100);
m_notKilled = false; m_notKilled = false;
m_weaponBurstMode = BURST_OFF; m_weaponBurstMode = BURST_OFF;

View file

@ -1,3 +1,4 @@
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd"). // Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team. // Copyright (c) YaPB Development Team.
// //
@ -1275,7 +1276,7 @@ bool Waypoint::saveExtFile (const char *ext, const char *type, const char *magic
header.fileVersion = version; header.fileVersion = version;
header.uncompressed = size; header.uncompressed = size;
strncpy (header.header, magic, strlen (magic)); strncpy (header.header, magic, cr::bufsize (header.header));
auto compressed = new uint8[header.uncompressed]; auto compressed = new uint8[header.uncompressed];
int compressedLength = lz.compress (reinterpret_cast <uint8 *> (data), header.uncompressed, compressed); int compressedLength = lz.compress (reinterpret_cast <uint8 *> (data), header.uncompressed, compressed);
@ -1294,9 +1295,8 @@ bool Waypoint::saveExtFile (const char *ext, const char *type, const char *magic
dataSaved = true; dataSaved = true;
} }
else { else {
util.logEntry (true, LL_ERROR, "Couldn't save %s data (unable to write the file)", type); util.logEntry (true, LL_ERROR, "Couldn't save %s data (unable to write the file \"%s\")", type, util.format ("%slearned/%s.%s", getDataDirectory (), game.getMapName (), ext));
dataSaved = false; dataSaved = false;
} }
} }
else { else {
@ -1324,7 +1324,7 @@ bool Waypoint::loadExtFile (const char *ext, const char *type, const char *magic
return false; return false;
} }
if (!!strncmp (header.header, magic, strlen (magic))) { if (!!strncmp (header.header, magic, cr::bufsize (header.header))) {
util.logEntry (true, LL_ERROR, "%s data damaged (bad header '%s')", type, header.header); util.logEntry (true, LL_ERROR, "%s data damaged (bad header '%s')", type, header.header);
fp.close (); fp.close ();
@ -1459,7 +1459,7 @@ bool Waypoint::load (void) {
return throwError ("%s.pwf - damaged waypoint file (unable to read header)", map); return throwError ("%s.pwf - damaged waypoint file (unable to read header)", map);
} }
if (strncmp (header.header, FH_WAYPOINT, strlen (FH_WAYPOINT)) == 0) { if (strncmp (header.header, FH_WAYPOINT, cr::bufsize (FH_WAYPOINT)) == 0) {
if (header.fileVersion != FV_WAYPOINT) { if (header.fileVersion != FV_WAYPOINT) {
return throwError ("%s.pwf - incorrect waypoint file version (expected '%d' found '%ld')", map, FV_WAYPOINT, header.fileVersion); return throwError ("%s.pwf - incorrect waypoint file version (expected '%d' found '%ld')", map, FV_WAYPOINT, header.fileVersion);
} }
@ -2555,6 +2555,7 @@ void Waypoint::eraseFromDisk (void) {
const char *Waypoint::getDataDirectory (bool isMemoryFile) { const char *Waypoint::getDataDirectory (bool isMemoryFile) {
static String buffer; static String buffer;
buffer.clear ();
if (isMemoryFile) { if (isMemoryFile) {
buffer.assign ("addons/yapb/data/"); buffer.assign ("addons/yapb/data/");