Fixed GCC Errors.
This commit is contained in:
parent
68f2f010fd
commit
10e94e0bee
4 changed files with 46 additions and 42 deletions
|
|
@ -81,13 +81,13 @@ bool BotUtils::checkKeywords (const String &line, String &reply) {
|
|||
}
|
||||
|
||||
for (auto &factory : conf.getReplies ()) {
|
||||
for (auto &keyword : factory.keywords) {
|
||||
for (const auto &keyword : factory.keywords) {
|
||||
|
||||
// check is keyword has occurred in message
|
||||
if (line.find (keyword, 0) != String::INVALID_INDEX) {
|
||||
StringArray &usedReplies = factory.usedReplies;
|
||||
|
||||
if (usedReplies.length () >= factory.replies.length () / 2) {
|
||||
if (usedReplies.length () >= factory.replies.length () / 4) {
|
||||
usedReplies.clear ();
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +107,6 @@ bool BotUtils::checkKeywords (const String &line, String &reply) {
|
|||
if (!replyUsed) {
|
||||
reply.assign (choosenReply); // update final buffer
|
||||
usedReplies.push (choosenReply); // add to ignore list
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -182,10 +181,10 @@ void Bot::prepareChatMessage (const String &message) {
|
|||
|
||||
// get roundtime
|
||||
auto getRoundTime = [] (void) -> String {
|
||||
int roundTimeSecs = static_cast <int> (bots.getRoundEndTime () - game.timebase ());
|
||||
auto roundTimeSecs = static_cast <int> (bots.getRoundEndTime () - game.timebase ());
|
||||
|
||||
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);
|
||||
};
|
||||
|
|
@ -332,12 +331,13 @@ bool Bot::isReplyingToChat (void) {
|
|||
// this function sends reply to a player
|
||||
|
||||
if (m_sayTextBuffer.entityIndex != -1 && !m_sayTextBuffer.sayText.empty ()) {
|
||||
String message;
|
||||
|
||||
// check is time to chat is good
|
||||
if (m_sayTextBuffer.timeNextChat < game.timebase ()) {
|
||||
if (rng.chance (m_sayTextBuffer.chatProbability + rng.getInt (25, 45)) && checkChatKeywords (message)) {
|
||||
prepareChatMessage (message);
|
||||
String replyText;
|
||||
|
||||
if (rng.chance (m_sayTextBuffer.chatProbability + rng.getInt (25, 45)) && checkChatKeywords (replyText)) {
|
||||
prepareChatMessage (replyText);
|
||||
pushMsgQueue (GAME_MSG_SAY_CMD);
|
||||
|
||||
m_sayTextBuffer.entityIndex = -1;
|
||||
|
|
@ -355,42 +355,42 @@ bool Bot::isReplyingToChat (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?
|
||||
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 ();
|
||||
|
||||
// say a text every now and then
|
||||
if (rng.chance (50)) {
|
||||
m_lastChatTime = game.timebase ();
|
||||
bots.setLastChatTimestamp (game.timebase ());
|
||||
if (!chat[CHAT_DEAD].empty ()) {
|
||||
const String &phrase = chat[CHAT_DEAD].random ();
|
||||
bool sayBufferExists = false;
|
||||
|
||||
if (!chat[CHAT_DEAD].empty ()) {
|
||||
const String &phrase = chat[CHAT_DEAD].random ();
|
||||
bool sayBufferExists = false;
|
||||
|
||||
// search for last messages, sayed
|
||||
for (auto &sentence : m_sayTextBuffer.lastUsedSentences) {
|
||||
if (strncmp (sentence.chars (), phrase.chars (), sentence.length ()) == 0) {
|
||||
sayBufferExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sayBufferExists) {
|
||||
prepareChatMessage (phrase);
|
||||
pushMsgQueue (GAME_MSG_SAY_CMD);
|
||||
|
||||
// add to ignore list
|
||||
m_sayTextBuffer.lastUsedSentences.push (phrase);
|
||||
// search for last messages, sayed
|
||||
for (auto &sentence : m_sayTextBuffer.lastUsedSentences) {
|
||||
if (strncmp (sentence.chars (), phrase.chars (), sentence.length ()) == 0) {
|
||||
sayBufferExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!sayBufferExists) {
|
||||
prepareChatMessage (phrase);
|
||||
pushMsgQueue (GAME_MSG_SAY_CMD);
|
||||
|
||||
m_lastChatTime = game.timebase ();
|
||||
bots.setLastChatTimestamp (game.timebase ());
|
||||
|
||||
// clear the used line buffer every now and then
|
||||
if (static_cast <int> (m_sayTextBuffer.lastUsedSentences.length ()) > rng.getInt (4, 6)) {
|
||||
m_sayTextBuffer.lastUsedSentences.clear ();
|
||||
// add to ignore list
|
||||
m_sayTextBuffer.lastUsedSentences.push (phrase);
|
||||
}
|
||||
}
|
||||
|
||||
// clear the used line buffer every now and then
|
||||
if (static_cast <int> (m_sayTextBuffer.lastUsedSentences.length ()) > rng.getInt (4, 6)) {
|
||||
m_sayTextBuffer.lastUsedSentences.clear ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -460,6 +460,9 @@ void BotManager::reset (void) {
|
|||
m_quotaMaintainTime = 0.0f;
|
||||
m_grenadeUpdateTime = 0.0f;
|
||||
m_entityUpdateTime = 0.0f;
|
||||
m_plantSearchUpdateTime = 0.0f;
|
||||
m_lastChatTime = 0.0f;
|
||||
m_timeBombPlanted = 0.0f;
|
||||
|
||||
m_intrestingEntities.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
|
||||
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_weaponBurstMode = BURST_OFF;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//
|
||||
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
|
||||
// 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.uncompressed = size;
|
||||
|
||||
strncpy (header.header, magic, strlen (magic));
|
||||
strncpy (header.header, magic, cr::bufsize (header.header));
|
||||
|
||||
auto compressed = new uint8[header.uncompressed];
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -1324,7 +1324,7 @@ bool Waypoint::loadExtFile (const char *ext, const char *type, const char *magic
|
|||
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);
|
||||
fp.close ();
|
||||
|
||||
|
|
@ -1459,7 +1459,7 @@ bool Waypoint::load (void) {
|
|||
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) {
|
||||
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) {
|
||||
static String buffer;
|
||||
buffer.clear ();
|
||||
|
||||
if (isMemoryFile) {
|
||||
buffer.assign ("addons/yapb/data/");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue