Fixed GCC Errors.
This commit is contained in:
parent
68f2f010fd
commit
10e94e0bee
4 changed files with 46 additions and 42 deletions
|
|
@ -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...);
|
||||||
|
|
|
||||||
|
|
@ -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,42 +355,42 @@ 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 (!chat[CHAT_DEAD].empty ()) {
|
||||||
if (rng.chance (50)) {
|
const String &phrase = chat[CHAT_DEAD].random ();
|
||||||
m_lastChatTime = game.timebase ();
|
bool sayBufferExists = false;
|
||||||
bots.setLastChatTimestamp (game.timebase ());
|
|
||||||
|
|
||||||
if (!chat[CHAT_DEAD].empty ()) {
|
// search for last messages, sayed
|
||||||
const String &phrase = chat[CHAT_DEAD].random ();
|
for (auto &sentence : m_sayTextBuffer.lastUsedSentences) {
|
||||||
bool sayBufferExists = false;
|
if (strncmp (sentence.chars (), phrase.chars (), sentence.length ()) == 0) {
|
||||||
|
sayBufferExists = true;
|
||||||
// search for last messages, sayed
|
break;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!sayBufferExists) {
|
||||||
|
prepareChatMessage (phrase);
|
||||||
|
pushMsgQueue (GAME_MSG_SAY_CMD);
|
||||||
|
|
||||||
// clear the used line buffer every now and then
|
m_lastChatTime = game.timebase ();
|
||||||
if (static_cast <int> (m_sayTextBuffer.lastUsedSentences.length ()) > rng.getInt (4, 6)) {
|
bots.setLastChatTimestamp (game.timebase ());
|
||||||
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_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;
|
||||||
|
|
|
||||||
|
|
@ -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/");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue