(svn r15481) -Fix [NoAI]: Make sure AIs can't call functions they shouldn't call.

This commit is contained in:
yexo 2009-02-14 20:03:06 +00:00
parent 0dcf301d6d
commit 8e75f5244c
9 changed files with 27 additions and 30 deletions

View File

@ -136,6 +136,7 @@ public:
*/ */
static char *GetLastErrorString(); static char *GetLastErrorString();
#ifndef EXPORT_SKIP
/** /**
* Get the error based on the OpenTTD StringID. * Get the error based on the OpenTTD StringID.
* @note DO NOT INVOKE THIS METHOD YOURSELF! * @note DO NOT INVOKE THIS METHOD YOURSELF!
@ -159,6 +160,7 @@ public:
* @param message The string representation of this error message, used for debug purposes. * @param message The string representation of this error message, used for debug purposes.
*/ */
static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message); static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message);
#endif /* EXPORT_SKIP */
private: private:
typedef std::map<StringID, AIErrorType> AIErrorMap; typedef std::map<StringID, AIErrorType> AIErrorMap;

View File

@ -109,12 +109,9 @@ void SQAIError_Register(Squirrel *engine) {
AIError::RegisterErrorMapString(AIError::ERR_TOO_CLOSE_TO_EDGE, "ERR_TOO_CLOSE_TO_EDGE"); AIError::RegisterErrorMapString(AIError::ERR_TOO_CLOSE_TO_EDGE, "ERR_TOO_CLOSE_TO_EDGE");
AIError::RegisterErrorMapString(AIError::ERR_STATION_TOO_SPREAD_OUT, "ERR_STATION_TOO_SPREAD_OUT"); AIError::RegisterErrorMapString(AIError::ERR_STATION_TOO_SPREAD_OUT, "ERR_STATION_TOO_SPREAD_OUT");
SQAIError.DefSQStaticMethod(engine, &AIError::GetErrorCategory, "GetErrorCategory", 1, "?"); SQAIError.DefSQStaticMethod(engine, &AIError::GetErrorCategory, "GetErrorCategory", 1, "?");
SQAIError.DefSQStaticMethod(engine, &AIError::GetLastError, "GetLastError", 1, "?"); SQAIError.DefSQStaticMethod(engine, &AIError::GetLastError, "GetLastError", 1, "?");
SQAIError.DefSQStaticMethod(engine, &AIError::GetLastErrorString, "GetLastErrorString", 1, "?"); SQAIError.DefSQStaticMethod(engine, &AIError::GetLastErrorString, "GetLastErrorString", 1, "?");
SQAIError.DefSQStaticMethod(engine, &AIError::StringToError, "StringToError", 2, "?i");
SQAIError.DefSQStaticMethod(engine, &AIError::RegisterErrorMap, "RegisterErrorMap", 3, "?ii");
SQAIError.DefSQStaticMethod(engine, &AIError::RegisterErrorMapString, "RegisterErrorMapString", 3, "?is");
SQAIError.PostRegister(engine); SQAIError.PostRegister(engine);
} }

View File

@ -87,6 +87,7 @@ public:
*/ */
static AIEvent *GetNextEvent(); static AIEvent *GetNextEvent();
#ifndef EXPORT_SKIP
/** /**
* Insert an event to the queue for the company. * Insert an event to the queue for the company.
* @param event The event to insert. * @param event The event to insert.
@ -98,6 +99,7 @@ public:
* @note DO NOT CALL YOURSELF; leave it to the internal AI programming. * @note DO NOT CALL YOURSELF; leave it to the internal AI programming.
*/ */
static void FreeEventPointer(); static void FreeEventPointer();
#endif /* EXPORT_SKIP */
private: private:
/** /**

View File

@ -62,10 +62,8 @@ void SQAIEventController_Register(Squirrel *engine) {
SQAIEventController.PreRegister(engine); SQAIEventController.PreRegister(engine);
SQAIEventController.AddConstructor<void (AIEventController::*)(), 1>(engine, "x"); SQAIEventController.AddConstructor<void (AIEventController::*)(), 1>(engine, "x");
SQAIEventController.DefSQStaticMethod(engine, &AIEventController::IsEventWaiting, "IsEventWaiting", 1, "?"); SQAIEventController.DefSQStaticMethod(engine, &AIEventController::IsEventWaiting, "IsEventWaiting", 1, "?");
SQAIEventController.DefSQStaticMethod(engine, &AIEventController::GetNextEvent, "GetNextEvent", 1, "?"); SQAIEventController.DefSQStaticMethod(engine, &AIEventController::GetNextEvent, "GetNextEvent", 1, "?");
SQAIEventController.DefSQStaticMethod(engine, &AIEventController::InsertEvent, "InsertEvent", 2, "?x");
SQAIEventController.DefSQStaticMethod(engine, &AIEventController::FreeEventPointer, "FreeEventPointer", 1, "?");
SQAIEventController.PostRegister(engine); SQAIEventController.PostRegister(engine);
} }

View File

@ -18,6 +18,7 @@ class AILog : public AIObject {
public: public:
static const char *GetClassName() { return "AILog"; } static const char *GetClassName() { return "AILog"; }
#ifndef EXPORT_SKIP
/** /**
* Log levels; The value is also feed to DEBUG() lvl. * Log levels; The value is also feed to DEBUG() lvl.
* This has no use for you, as AI writer. * This has no use for you, as AI writer.
@ -41,6 +42,7 @@ public:
int pos; //!< Current position in lines. int pos; //!< Current position in lines.
int used; //!< Total amount of used log-lines. int used; //!< Total amount of used log-lines.
}; };
#endif /* EXPORT_SKIP */
/** /**
* Print an Info message to the logs. * Print an Info message to the logs.
@ -60,11 +62,13 @@ public:
*/ */
static void Error(const char *message); static void Error(const char *message);
#ifndef EXPORT_SKIP
/** /**
* Free the log pointer. * Free the log pointer.
* @note DO NOT CALL YOURSELF; leave it to the internal AI programming. * @note DO NOT CALL YOURSELF; leave it to the internal AI programming.
*/ */
static void FreeLogPointer(); static void FreeLogPointer();
#endif /* EXPORT_SKIP */
private: private:
/** /**

View File

@ -4,10 +4,6 @@
#include "ai_log.hpp" #include "ai_log.hpp"
namespace SQConvert { namespace SQConvert {
/* Allow enums to be used as Squirrel parameters */
template <> AILog::AILogType GetParam(ForceType<AILog::AILogType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AILog::AILogType)tmp; }
template <> int Return<AILog::AILogType>(HSQUIRRELVM vm, AILog::AILogType res) { sq_pushinteger(vm, (int32)res); return 1; }
/* Allow AILog to be used as Squirrel parameter */ /* Allow AILog to be used as Squirrel parameter */
template <> AILog *GetParam(ForceType<AILog *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AILog *)instance; } template <> AILog *GetParam(ForceType<AILog *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AILog *)instance; }
template <> AILog &GetParam(ForceType<AILog &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AILog *)instance; } template <> AILog &GetParam(ForceType<AILog &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AILog *)instance; }
@ -21,16 +17,9 @@ void SQAILog_Register(Squirrel *engine) {
SQAILog.PreRegister(engine); SQAILog.PreRegister(engine);
SQAILog.AddConstructor<void (AILog::*)(), 1>(engine, "x"); SQAILog.AddConstructor<void (AILog::*)(), 1>(engine, "x");
SQAILog.DefSQConst(engine, AILog::LOG_SQ_ERROR, "LOG_SQ_ERROR"); SQAILog.DefSQStaticMethod(engine, &AILog::Info, "Info", 2, "?s");
SQAILog.DefSQConst(engine, AILog::LOG_ERROR, "LOG_ERROR"); SQAILog.DefSQStaticMethod(engine, &AILog::Warning, "Warning", 2, "?s");
SQAILog.DefSQConst(engine, AILog::LOG_SQ_INFO, "LOG_SQ_INFO"); SQAILog.DefSQStaticMethod(engine, &AILog::Error, "Error", 2, "?s");
SQAILog.DefSQConst(engine, AILog::LOG_WARNING, "LOG_WARNING");
SQAILog.DefSQConst(engine, AILog::LOG_INFO, "LOG_INFO");
SQAILog.DefSQStaticMethod(engine, &AILog::Info, "Info", 2, "?s");
SQAILog.DefSQStaticMethod(engine, &AILog::Warning, "Warning", 2, "?s");
SQAILog.DefSQStaticMethod(engine, &AILog::Error, "Error", 2, "?s");
SQAILog.DefSQStaticMethod(engine, &AILog::FreeLogPointer, "FreeLogPointer", 1, "?");
SQAILog.PostRegister(engine); SQAILog.PostRegister(engine);
} }

View File

@ -185,7 +185,7 @@ public:
* Internal function to help ChangeOrder. * Internal function to help ChangeOrder.
*/ */
static bool _ChangeOrder(); static bool _ChangeOrder();
#endif #endif /* DOXYGEN_SKIP */
/** /**
* Changes the order flags of the given order. * Changes the order flags of the given order.

View File

@ -64,7 +64,7 @@ public:
* Internal function to help BuildTunnel in case of road. * Internal function to help BuildTunnel in case of road.
*/ */
static bool _BuildTunnelRoad2(); static bool _BuildTunnelRoad2();
#endif #endif /* DOXYGEN_SKIP */
/** /**
* Builds a tunnel starting at start. The direction of the tunnel depends * Builds a tunnel starting at start. The direction of the tunnel depends

View File

@ -86,10 +86,10 @@ BEGIN {
/^( *)private/ { if (cls_level == 1) public = "false"; next; } /^( *)private/ { if (cls_level == 1) public = "false"; next; }
# Ignore special doxygen blocks # Ignore special doxygen blocks
/^#ifndef DOXYGEN_SKIP/ { doxygen_skip = "next"; next; } /^#ifndef DOXYGEN_SKIP/ { doxygen_skip = "next"; next; }
/^#ifdef DOXYGEN_SKIP/ { doxygen_skip = "true"; next; } /^#ifdef DOXYGEN_SKIP/ { doxygen_skip = "true"; next; }
/^#endif/ { doxygen_skip = "false"; next; } /^#endif \/\* DOXYGEN_SKIP \*\// { doxygen_skip = "false"; next; }
/^#else/ { /^#else/ {
if (doxygen_skip == "next") { if (doxygen_skip == "next") {
doxygen_skip = "true"; doxygen_skip = "true";
} else { } else {
@ -99,6 +99,11 @@ BEGIN {
} }
{ if (doxygen_skip == "true") next } { if (doxygen_skip == "true") next }
# Ignore functions that shouldn't be exported to squirrel
/^#ifndef EXPORT_SKIP/ { export_skip = "true"; next; }
/^#endif \/\* EXPORT_SKIP \*\// { export_skip = "false"; next; }
{ if (export_skip == "true") next }
# Ignore the comments # Ignore the comments
/^#/ { next; } /^#/ { next; }
/\/\*.*\*\// { comment = "false"; next; } /\/\*.*\*\// { comment = "false"; next; }