diff options
author | yexo <yexo@openttd.org> | 2009-05-23 14:54:55 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2009-05-23 14:54:55 +0000 |
commit | 0b243d25cbe8fec67a004cebee288ae741867cff (patch) | |
tree | 73b8b77851f4ed6ecaaf4de3c11b3a41cb0174e0 | |
parent | 8e30f0e75abe83358a0d3c72716d7a77d0f89cf1 (diff) | |
download | openttd-0b243d25cbe8fec67a004cebee288ae741867cff.tar.xz |
(svn r16400) -Add [NoAI]: add AISignList that can be used to get a list of valid signs. This makes AISign::GetMaxSignID obsolete.
-rw-r--r-- | bin/ai/regression/regression.nut | 7 | ||||
-rw-r--r-- | bin/ai/regression/regression.txt | 13 | ||||
-rw-r--r-- | projects/openttd_vs80.vcproj | 8 | ||||
-rw-r--r-- | projects/openttd_vs90.vcproj | 8 | ||||
-rw-r--r-- | src/ai/ai_instance.cpp | 2 | ||||
-rw-r--r-- | src/ai/api/ai_sign.hpp | 1 | ||||
-rw-r--r-- | src/ai/api/ai_signlist.cpp | 15 | ||||
-rw-r--r-- | src/ai/api/ai_signlist.hpp | 20 | ||||
-rw-r--r-- | src/ai/api/ai_signlist.hpp.sq | 21 |
9 files changed, 79 insertions, 16 deletions
diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut index 82154c9db..7ec415639 100644 --- a/bin/ai/regression/regression.nut +++ b/bin/ai/regression/regression.nut @@ -1077,9 +1077,10 @@ function Regression::Sign() print(" BuildSign(33409, 'Some other Sign'): " + sign_id); print(" RemoveSign(" + sign_id + "): " + AISign.RemoveSign(sign_id)); print(""); - print(" GetMaxSignID(): " + AISign.GetMaxSignID()); - for (local i = -1; i < AISign.GetMaxSignID() + 1; i++) { - if (AISign.IsValidSign(i)) j++; + local list = AISignList(); + list.Sort(AIAbstractList.SORT_BY_ITEM, true); + for (local i = list.Begin(); list.HasNext(); i = list.Next()) { + j++; print(" Sign " + i); print(" IsValidSign(): " + AISign.IsValidSign(i)); print(" GetName(): " + AISign.GetName(i)); diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index d19c93605..c6745d056 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -7242,11 +7242,6 @@ BuildSign(33409, 'Some other Sign'): 2 RemoveSign(2): true - GetMaxSignID(): 3 - Sign -1 - IsValidSign(): false - GetName(): (null : 0x00000000) - GetLocation(): -1 Sign 0 IsValidSign(): true GetName(): Some Sign @@ -7255,14 +7250,6 @@ IsValidSign(): true GetName(): Test2 GetLocation(): 33411 - Sign 2 - IsValidSign(): false - GetName(): (null : 0x00000000) - GetLocation(): -1 - Sign 3 - IsValidSign(): false - GetName(): (null : 0x00000000) - GetLocation(): -1 Valid Signs: 2 --Station-- diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index c6b09aa27..f87499382 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -2692,6 +2692,10 @@ > </File> <File + RelativePath=".\..\src\ai\api\ai_signlist.hpp" + > + </File> + <File RelativePath=".\..\src\ai\api\ai_station.hpp" > </File> @@ -2896,6 +2900,10 @@ > </File> <File + RelativePath=".\..\src\ai\api\ai_signlist.cpp" + > + </File> + <File RelativePath=".\..\src\ai\api\ai_station.cpp" > </File> diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 8aa31b1e7..ec1db4894 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -2689,6 +2689,10 @@ > </File> <File + RelativePath=".\..\src\ai\api\ai_signlist.hpp" + > + </File> + <File RelativePath=".\..\src\ai\api\ai_station.hpp" > </File> @@ -2893,6 +2897,10 @@ > </File> <File + RelativePath=".\..\src\ai\api\ai_signlist.cpp" + > + </File> + <File RelativePath=".\..\src\ai\api\ai_station.cpp" > </File> 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<AISignList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AISignList *)instance; } + template <> AISignList &GetParam(ForceType<AISignList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AISignList *)instance; } + template <> const AISignList *GetParam(ForceType<const AISignList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AISignList *)instance; } + template <> const AISignList &GetParam(ForceType<const AISignList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AISignList *)instance; } + template <> int Return<AISignList *>(HSQUIRRELVM vm, AISignList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AISignList", res, NULL, DefSQDestructorCallback<AISignList>); return 1; } +}; // namespace SQConvert + +void SQAISignList_Register(Squirrel *engine) { + DefSQClass <AISignList> SQAISignList("AISignList"); + SQAISignList.PreRegister(engine, "AIAbstractList"); + SQAISignList.AddConstructor<void (AISignList::*)(), 1>(engine, "x"); + + SQAISignList.PostRegister(engine); +} |