1
/* $Id: ai_log.cpp 15060 2009-01-13 15:44:36Z smatz $ */
3
/** @file ai_log.cpp Implementation of AILog. */
6
#include "../../core/alloc_func.hpp"
7
#include "../../company_func.h"
8
#include "../../debug.h"
9
#include "../../window_func.h"
11
/* static */ void AILog::Info(const char *message)
13
AILog::Log(LOG_INFO, message);
16
/* static */ void AILog::Warning(const char *message)
18
AILog::Log(LOG_WARNING, message);
21
/* static */ void AILog::Error(const char *message)
23
AILog::Log(LOG_ERROR, message);
26
/* static */ void AILog::Log(AILog::AILogType level, const char *message)
28
if (AIObject::GetLogPointer() == NULL) {
29
AIObject::GetLogPointer() = new LogData();
30
LogData *log = (LogData *)AIObject::GetLogPointer();
32
log->lines = CallocT<char *>(80);
33
log->type = CallocT<AILog::AILogType>(80);
35
log->pos = log->count;
38
LogData *log = (LogData *)AIObject::GetLogPointer();
40
/* Go to the next log-line */
41
log->pos = (log->pos + 1) % log->count;
43
if (log->used != log->count) log->used++;
45
/* Free last message, and write new message */
46
free(log->lines[log->pos]);
47
log->lines[log->pos] = strdup(message);
48
log->type[log->pos] = level;
50
/* Cut string after first \n */
52
while ((p = strchr(log->lines[log->pos], '\n')) != NULL) {
60
case LOG_SQ_ERROR: logc = 'S'; break;
61
case LOG_ERROR: logc = 'E'; break;
62
case LOG_SQ_INFO: logc = 'P'; break;
63
case LOG_WARNING: logc = 'W'; break;
64
case LOG_INFO: logc = 'I'; break;
65
default: logc = '?'; break;
68
/* Also still print to debug window */
69
DEBUG(ai, level, "[%d] [%c] %s", (uint)_current_company, logc, log->lines[log->pos]);
70
InvalidateWindowData(WC_AI_DEBUG, 0, _current_company);
73
/* static */ void AILog::FreeLogPointer()
75
LogData *log = (LogData *)AIObject::GetLogPointer();
77
for (int i = 0; i < log->count; i++) {