mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(svn r15481) -Fix [NoAI]: Make sure AIs can't call functions they shouldn't call.
This commit is contained in:
parent
0dcf301d6d
commit
8e75f5244c
@ -136,6 +136,7 @@ public:
|
||||
*/
|
||||
static char *GetLastErrorString();
|
||||
|
||||
#ifndef EXPORT_SKIP
|
||||
/**
|
||||
* Get the error based on the OpenTTD StringID.
|
||||
* @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.
|
||||
*/
|
||||
static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message);
|
||||
#endif /* EXPORT_SKIP */
|
||||
|
||||
private:
|
||||
typedef std::map<StringID, AIErrorType> AIErrorMap;
|
||||
|
@ -112,9 +112,6 @@ void SQAIError_Register(Squirrel *engine) {
|
||||
SQAIError.DefSQStaticMethod(engine, &AIError::GetErrorCategory, "GetErrorCategory", 1, "?");
|
||||
SQAIError.DefSQStaticMethod(engine, &AIError::GetLastError, "GetLastError", 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);
|
||||
}
|
||||
|
@ -87,6 +87,7 @@ public:
|
||||
*/
|
||||
static AIEvent *GetNextEvent();
|
||||
|
||||
#ifndef EXPORT_SKIP
|
||||
/**
|
||||
* Insert an event to the queue for the company.
|
||||
* @param event The event to insert.
|
||||
@ -98,6 +99,7 @@ public:
|
||||
* @note DO NOT CALL YOURSELF; leave it to the internal AI programming.
|
||||
*/
|
||||
static void FreeEventPointer();
|
||||
#endif /* EXPORT_SKIP */
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -64,8 +64,6 @@ void SQAIEventController_Register(Squirrel *engine) {
|
||||
|
||||
SQAIEventController.DefSQStaticMethod(engine, &AIEventController::IsEventWaiting, "IsEventWaiting", 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);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class AILog : public AIObject {
|
||||
public:
|
||||
static const char *GetClassName() { return "AILog"; }
|
||||
|
||||
#ifndef EXPORT_SKIP
|
||||
/**
|
||||
* Log levels; The value is also feed to DEBUG() lvl.
|
||||
* This has no use for you, as AI writer.
|
||||
@ -41,6 +42,7 @@ public:
|
||||
int pos; //!< Current position in lines.
|
||||
int used; //!< Total amount of used log-lines.
|
||||
};
|
||||
#endif /* EXPORT_SKIP */
|
||||
|
||||
/**
|
||||
* Print an Info message to the logs.
|
||||
@ -60,11 +62,13 @@ public:
|
||||
*/
|
||||
static void Error(const char *message);
|
||||
|
||||
#ifndef EXPORT_SKIP
|
||||
/**
|
||||
* Free the log pointer.
|
||||
* @note DO NOT CALL YOURSELF; leave it to the internal AI programming.
|
||||
*/
|
||||
static void FreeLogPointer();
|
||||
#endif /* EXPORT_SKIP */
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -4,10 +4,6 @@
|
||||
#include "ai_log.hpp"
|
||||
|
||||
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 */
|
||||
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.AddConstructor<void (AILog::*)(), 1>(engine, "x");
|
||||
|
||||
SQAILog.DefSQConst(engine, AILog::LOG_SQ_ERROR, "LOG_SQ_ERROR");
|
||||
SQAILog.DefSQConst(engine, AILog::LOG_ERROR, "LOG_ERROR");
|
||||
SQAILog.DefSQConst(engine, AILog::LOG_SQ_INFO, "LOG_SQ_INFO");
|
||||
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);
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ public:
|
||||
* Internal function to help ChangeOrder.
|
||||
*/
|
||||
static bool _ChangeOrder();
|
||||
#endif
|
||||
#endif /* DOXYGEN_SKIP */
|
||||
|
||||
/**
|
||||
* Changes the order flags of the given order.
|
||||
|
@ -64,7 +64,7 @@ public:
|
||||
* Internal function to help BuildTunnel in case of road.
|
||||
*/
|
||||
static bool _BuildTunnelRoad2();
|
||||
#endif
|
||||
#endif /* DOXYGEN_SKIP */
|
||||
|
||||
/**
|
||||
* Builds a tunnel starting at start. The direction of the tunnel depends
|
||||
|
@ -88,7 +88,7 @@ BEGIN {
|
||||
# Ignore special doxygen blocks
|
||||
/^#ifndef DOXYGEN_SKIP/ { doxygen_skip = "next"; next; }
|
||||
/^#ifdef DOXYGEN_SKIP/ { doxygen_skip = "true"; next; }
|
||||
/^#endif/ { doxygen_skip = "false"; next; }
|
||||
/^#endif \/\* DOXYGEN_SKIP \*\// { doxygen_skip = "false"; next; }
|
||||
/^#else/ {
|
||||
if (doxygen_skip == "next") {
|
||||
doxygen_skip = "true";
|
||||
@ -99,6 +99,11 @@ BEGIN {
|
||||
}
|
||||
{ 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
|
||||
/^#/ { next; }
|
||||
/\/\*.*\*\// { comment = "false"; next; }
|
||||
|
Loading…
Reference in New Issue
Block a user