From 0b243d25cbe8fec67a004cebee288ae741867cff Mon Sep 17 00:00:00 2001 From: yexo Date: Sat, 23 May 2009 14:54:55 +0000 Subject: (svn r16400) -Add [NoAI]: add AISignList that can be used to get a list of valid signs. This makes AISign::GetMaxSignID obsolete. --- src/ai/ai_instance.cpp | 2 ++ src/ai/api/ai_sign.hpp | 1 + src/ai/api/ai_signlist.cpp | 15 +++++++++++++++ src/ai/api/ai_signlist.hpp | 20 ++++++++++++++++++++ src/ai/api/ai_signlist.hpp.sq | 21 +++++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 src/ai/api/ai_signlist.cpp create mode 100644 src/ai/api/ai_signlist.hpp create mode 100644 src/ai/api/ai_signlist.hpp.sq (limited to 'src') diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index 0b140c172..0ab577a0e 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -60,6 +60,7 @@ #include "api/ai_railtypelist.hpp.sq" #include "api/ai_road.hpp.sq" #include "api/ai_sign.hpp.sq" +#include "api/ai_signlist.hpp.sq" #include "api/ai_station.hpp.sq" #include "api/ai_stationlist.hpp.sq" #include "api/ai_subsidy.hpp.sq" @@ -212,6 +213,7 @@ void AIInstance::RegisterAPI() SQAIRailTypeList_Register(this->engine); SQAIRoad_Register(this->engine); SQAISign_Register(this->engine); + SQAISignList_Register(this->engine); SQAIStation_Register(this->engine); SQAIStationList_Register(this->engine); SQAIStationList_Vehicle_Register(this->engine); diff --git a/src/ai/api/ai_sign.hpp b/src/ai/api/ai_sign.hpp index d18cef817..e7e20dc46 100644 --- a/src/ai/api/ai_sign.hpp +++ b/src/ai/api/ai_sign.hpp @@ -30,6 +30,7 @@ public: /** * Gets the maximum sign index; there are no valid signs with a higher index. + * @deprecated This function is deprecated and might be removed in future versions of the API. Use AISignList() instead. * @return The maximum sign index. * @post Return value is always non-negative. */ diff --git a/src/ai/api/ai_signlist.cpp b/src/ai/api/ai_signlist.cpp new file mode 100644 index 000000000..33cb7fed4 --- /dev/null +++ b/src/ai/api/ai_signlist.cpp @@ -0,0 +1,15 @@ +/* $Id$ */ + +/** @file ai_signlist.cpp Implementation of AISignList and friends. */ + +#include "ai_signlist.hpp" +#include "ai_sign.hpp" +#include "../../signs_base.h" + +AISignList::AISignList() +{ + Sign *s; + FOR_ALL_SIGNS(s) { + if (AISign::IsValidSign(s->index)) this->AddItem(s->index); + } +} diff --git a/src/ai/api/ai_signlist.hpp b/src/ai/api/ai_signlist.hpp new file mode 100644 index 000000000..17faa9a80 --- /dev/null +++ b/src/ai/api/ai_signlist.hpp @@ -0,0 +1,20 @@ +/* $Id$ */ + +/** @file ai_signlist.hpp List all the signs of your company. */ + +#ifndef AI_SIGNLIST_HPP +#define AI_SIGNLIST_HPP + +#include "ai_abstractlist.hpp" + +/** + * Create a list of signs your company has created. + * @ingroup AIList + */ +class AISignList : public AIAbstractList { +public: + static const char *GetClassName() { return "AISignList"; } + AISignList(); +}; + +#endif /* AI_SIGNLIST_HPP */ diff --git a/src/ai/api/ai_signlist.hpp.sq b/src/ai/api/ai_signlist.hpp.sq new file mode 100644 index 000000000..b350e86f6 --- /dev/null +++ b/src/ai/api/ai_signlist.hpp.sq @@ -0,0 +1,21 @@ +/* $Id$ */ +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "ai_signlist.hpp" + +namespace SQConvert { + /* Allow AISignList to be used as Squirrel parameter */ + template <> AISignList *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AISignList *)instance; } + template <> AISignList &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AISignList *)instance; } + template <> const AISignList *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AISignList *)instance; } + template <> const AISignList &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AISignList *)instance; } + template <> int Return(HSQUIRRELVM vm, AISignList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AISignList", res, NULL, DefSQDestructorCallback); return 1; } +}; // namespace SQConvert + +void SQAISignList_Register(Squirrel *engine) { + DefSQClass SQAISignList("AISignList"); + SQAISignList.PreRegister(engine, "AIAbstractList"); + SQAISignList.AddConstructor(engine, "x"); + + SQAISignList.PostRegister(engine); +} -- cgit v1.2.3-70-g09d2