mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r20562) -Change: [NoAI] Move all functions from AIList to AIAbstractList
This commit is contained in:
parent
b18525ad86
commit
0d57e6c193
@ -873,7 +873,6 @@
|
||||
<ClInclude Include="..\src\ai\api\ai_industrytype.hpp" />
|
||||
<ClInclude Include="..\src\ai\api\ai_industrytypelist.hpp" />
|
||||
<ClInclude Include="..\src\ai\api\ai_info_docs.hpp" />
|
||||
<ClInclude Include="..\src\ai\api\ai_list.hpp" />
|
||||
<ClInclude Include="..\src\ai\api\ai_log.hpp" />
|
||||
<ClInclude Include="..\src\ai\api\ai_map.hpp" />
|
||||
<ClInclude Include="..\src\ai\api\ai_marine.hpp" />
|
||||
@ -925,7 +924,6 @@
|
||||
<ClCompile Include="..\src\ai\api\ai_industrylist.cpp" />
|
||||
<ClCompile Include="..\src\ai\api\ai_industrytype.cpp" />
|
||||
<ClCompile Include="..\src\ai\api\ai_industrytypelist.cpp" />
|
||||
<ClCompile Include="..\src\ai\api\ai_list.cpp" />
|
||||
<ClCompile Include="..\src\ai\api\ai_log.cpp" />
|
||||
<ClCompile Include="..\src\ai\api\ai_map.cpp" />
|
||||
<ClCompile Include="..\src\ai\api\ai_marine.cpp" />
|
||||
|
@ -1822,9 +1822,6 @@
|
||||
<ClInclude Include="..\src\ai\api\ai_info_docs.hpp">
|
||||
<Filter>AI API</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\ai\api\ai_list.hpp">
|
||||
<Filter>AI API</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\ai\api\ai_log.hpp">
|
||||
<Filter>AI API</Filter>
|
||||
</ClInclude>
|
||||
@ -1978,9 +1975,6 @@
|
||||
<ClCompile Include="..\src\ai\api\ai_industrytypelist.cpp">
|
||||
<Filter>AI API Implementation</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\ai\api\ai_list.cpp">
|
||||
<Filter>AI API Implementation</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\ai\api\ai_log.cpp">
|
||||
<Filter>AI API Implementation</Filter>
|
||||
</ClCompile>
|
||||
|
@ -2807,10 +2807,6 @@
|
||||
RelativePath=".\..\src\ai\api\ai_info_docs.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\ai\api\ai_list.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\ai\api\ai_log.hpp"
|
||||
>
|
||||
@ -3019,10 +3015,6 @@
|
||||
RelativePath=".\..\src\ai\api\ai_industrytypelist.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\ai\api\ai_list.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\ai\api\ai_log.cpp"
|
||||
>
|
||||
|
@ -2804,10 +2804,6 @@
|
||||
RelativePath=".\..\src\ai\api\ai_info_docs.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\ai\api\ai_list.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\ai\api\ai_log.hpp"
|
||||
>
|
||||
@ -3016,10 +3012,6 @@
|
||||
RelativePath=".\..\src\ai\api\ai_industrytypelist.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\ai\api\ai_list.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\ai\api\ai_log.cpp"
|
||||
>
|
||||
|
@ -639,7 +639,6 @@ ai/api/ai_industrylist.hpp
|
||||
ai/api/ai_industrytype.hpp
|
||||
ai/api/ai_industrytypelist.hpp
|
||||
ai/api/ai_info_docs.hpp
|
||||
ai/api/ai_list.hpp
|
||||
ai/api/ai_log.hpp
|
||||
ai/api/ai_map.hpp
|
||||
ai/api/ai_marine.hpp
|
||||
@ -693,7 +692,6 @@ ai/api/ai_industry.cpp
|
||||
ai/api/ai_industrylist.cpp
|
||||
ai/api/ai_industrytype.cpp
|
||||
ai/api/ai_industrytypelist.cpp
|
||||
ai/api/ai_list.cpp
|
||||
ai/api/ai_log.cpp
|
||||
ai/api/ai_map.cpp
|
||||
ai/api/ai_marine.cpp
|
||||
|
@ -52,7 +52,6 @@
|
||||
#include "api/ai_industrylist.hpp.sq"
|
||||
#include "api/ai_industrytype.hpp.sq"
|
||||
#include "api/ai_industrytypelist.hpp.sq"
|
||||
#include "api/ai_list.hpp.sq"
|
||||
#include "api/ai_log.hpp.sq"
|
||||
#include "api/ai_map.hpp.sq"
|
||||
#include "api/ai_marine.hpp.sq"
|
||||
@ -222,7 +221,6 @@ void AIInstance::RegisterAPI()
|
||||
SQAIIndustryList_CargoProducing_Register(this->engine);
|
||||
SQAIIndustryType_Register(this->engine);
|
||||
SQAIIndustryTypeList_Register(this->engine);
|
||||
SQAIList_Register(this->engine);
|
||||
SQAILog_Register(this->engine);
|
||||
SQAIMap_Register(this->engine);
|
||||
SQAIMarine_Register(this->engine);
|
||||
|
@ -404,7 +404,7 @@ void AIAbstractList::Clear()
|
||||
this->sorter->End();
|
||||
}
|
||||
|
||||
void AIAbstractList::AddItem(int32 item)
|
||||
void AIAbstractList::AddItem(int32 item, int32 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@ -412,6 +412,8 @@ void AIAbstractList::AddItem(int32 item)
|
||||
|
||||
this->items[item] = 0;
|
||||
this->buckets[0].insert(item);
|
||||
|
||||
this->SetValue(item, value);
|
||||
}
|
||||
|
||||
void AIAbstractList::RemoveItem(int32 item)
|
||||
@ -734,6 +736,30 @@ SQInteger AIAbstractList::_get(HSQUIRRELVM vm)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger AIAbstractList::_set(HSQUIRRELVM vm)
|
||||
{
|
||||
if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR;
|
||||
if (sq_gettype(vm, 3) != OT_INTEGER || sq_gettype(vm, 3) == OT_NULL) {
|
||||
return sq_throwerror(vm, _SC("you can only assign integers to this list"));
|
||||
}
|
||||
|
||||
SQInteger idx, val;
|
||||
sq_getinteger(vm, 2, &idx);
|
||||
if (sq_gettype(vm, 3) == OT_NULL) {
|
||||
this->RemoveItem(idx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sq_getinteger(vm, 3, &val);
|
||||
if (!this->HasItem(idx)) {
|
||||
this->AddItem(idx, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->SetValue(idx, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SQInteger AIAbstractList::_nexti(HSQUIRRELVM vm)
|
||||
{
|
||||
if (sq_gettype(vm, 2) == OT_NULL) {
|
||||
|
@ -53,25 +53,23 @@ public:
|
||||
AIAbstractListMap items; ///< The items in the list
|
||||
AIAbstractListBucket buckets; ///< The items in the list, sorted by value
|
||||
|
||||
protected:
|
||||
AIAbstractList();
|
||||
~AIAbstractList();
|
||||
|
||||
/**
|
||||
* Add a single item to the list.
|
||||
* @param item the item to add. Should be unique, otherwise it is ignored.
|
||||
* @param value the value to assign.
|
||||
* @note the value is set to 0 by default.
|
||||
*/
|
||||
void AddItem(int32 item);
|
||||
void AddItem(int32 item, int32 value = 0);
|
||||
|
||||
/**
|
||||
* Remove a single item from the list.
|
||||
* @param item the item to remove. If not existing, it is ignored.
|
||||
* @note Always use this function for removing items. It keeps the iterator valid!
|
||||
*/
|
||||
void RemoveItem(int32 item);
|
||||
|
||||
public:
|
||||
AIAbstractList();
|
||||
~AIAbstractList();
|
||||
|
||||
/**
|
||||
* Clear the list, making Count() returning 0 and IsEmpty() returning true.
|
||||
*/
|
||||
@ -247,6 +245,11 @@ public:
|
||||
*/
|
||||
SQInteger _get(HSQUIRRELVM vm);
|
||||
|
||||
/**
|
||||
* Used for [] set from Squirrel.
|
||||
*/
|
||||
SQInteger _set(HSQUIRRELVM vm);
|
||||
|
||||
/**
|
||||
* Used for 'foreach()' from Squirrel.
|
||||
*/
|
||||
|
@ -36,6 +36,8 @@ void SQAIAbstractList_Register(Squirrel *engine)
|
||||
SQAIAbstractList.DefSQConst(engine, AIAbstractList::SORT_ASCENDING, "SORT_ASCENDING");
|
||||
SQAIAbstractList.DefSQConst(engine, AIAbstractList::SORT_DESCENDING, "SORT_DESCENDING");
|
||||
|
||||
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::AddItem, "AddItem", 3, "xii");
|
||||
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::RemoveItem, "RemoveItem", 2, "xi");
|
||||
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::Clear, "Clear", 1, "x");
|
||||
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::HasItem, "HasItem", 2, "xi");
|
||||
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::Begin, "Begin", 1, "x");
|
||||
@ -62,6 +64,7 @@ void SQAIAbstractList_Register(Squirrel *engine)
|
||||
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::KeepBottom, "KeepBottom", 2, "xi");
|
||||
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::KeepList, "KeepList", 2, "xx");
|
||||
SQAIAbstractList.DefSQAdvancedMethod(engine, &AIAbstractList::_get, "_get");
|
||||
SQAIAbstractList.DefSQAdvancedMethod(engine, &AIAbstractList::_set, "_set");
|
||||
SQAIAbstractList.DefSQAdvancedMethod(engine, &AIAbstractList::_nexti, "_nexti");
|
||||
SQAIAbstractList.DefSQAdvancedMethod(engine, &AIAbstractList::Valuate, "Valuate");
|
||||
|
||||
|
@ -58,29 +58,29 @@
|
||||
return industrytype_name;
|
||||
}
|
||||
|
||||
/* static */ AIList *AIIndustryType::GetProducedCargo(IndustryType industry_type)
|
||||
/* static */ AIAbstractList *AIIndustryType::GetProducedCargo(IndustryType industry_type)
|
||||
{
|
||||
if (!IsValidIndustryType(industry_type)) return NULL;
|
||||
|
||||
const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
|
||||
|
||||
AIList *list = new AIList();
|
||||
AIAbstractList *list = new AIAbstractList();
|
||||
for (size_t i = 0; i < lengthof(ins->produced_cargo); i++) {
|
||||
if (ins->produced_cargo[i] != CT_INVALID) list->AddItem(ins->produced_cargo[i], 0);
|
||||
if (ins->produced_cargo[i] != CT_INVALID) list->AddItem(ins->produced_cargo[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/* static */ AIList *AIIndustryType::GetAcceptedCargo(IndustryType industry_type)
|
||||
/* static */ AIAbstractList *AIIndustryType::GetAcceptedCargo(IndustryType industry_type)
|
||||
{
|
||||
if (!IsValidIndustryType(industry_type)) return NULL;
|
||||
|
||||
const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
|
||||
|
||||
AIList *list = new AIList();
|
||||
AIAbstractList *list = new AIAbstractList();
|
||||
for (size_t i = 0; i < lengthof(ins->accepts_cargo); i++) {
|
||||
if (ins->accepts_cargo[i] != CT_INVALID) list->AddItem(ins->accepts_cargo[i], 0);
|
||||
if (ins->accepts_cargo[i] != CT_INVALID) list->AddItem(ins->accepts_cargo[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include "ai_object.hpp"
|
||||
#include "ai_error.hpp"
|
||||
#include "ai_list.hpp"
|
||||
#include "ai_abstractlist.hpp"
|
||||
|
||||
/**
|
||||
* Class that handles all industry-type related functions.
|
||||
@ -55,7 +55,7 @@ public:
|
||||
* @pre IsValidIndustryType(industry_type).
|
||||
* @return The CargoIDs of all cargotypes this industry could produce.
|
||||
*/
|
||||
static AIList *GetProducedCargo(IndustryType industry_type);
|
||||
static AIAbstractList *GetProducedCargo(IndustryType industry_type);
|
||||
|
||||
/**
|
||||
* Get a list of CargoID accepted by this industry-type.
|
||||
@ -65,7 +65,7 @@ public:
|
||||
* @pre IsValidIndustryType(industry_type).
|
||||
* @return The CargoIDs of all cargotypes this industry accepts.
|
||||
*/
|
||||
static AIList *GetAcceptedCargo(IndustryType industry_type);
|
||||
static AIAbstractList *GetAcceptedCargo(IndustryType industry_type);
|
||||
|
||||
/**
|
||||
* Is this industry type a raw industry?
|
||||
|
@ -1,52 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file ai_list.cpp Implementation of AIList. */
|
||||
|
||||
#include "ai_list.hpp"
|
||||
|
||||
void AIList::AddItem(int32 item, int32 value)
|
||||
{
|
||||
AIAbstractList::AddItem(item);
|
||||
this->SetValue(item, value);
|
||||
}
|
||||
|
||||
void AIList::ChangeItem(int32 item, int32 value)
|
||||
{
|
||||
this->SetValue(item, value);
|
||||
}
|
||||
|
||||
void AIList::RemoveItem(int32 item)
|
||||
{
|
||||
AIAbstractList::RemoveItem(item);
|
||||
}
|
||||
|
||||
SQInteger AIList::_set(HSQUIRRELVM vm)
|
||||
{
|
||||
if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR;
|
||||
if (sq_gettype(vm, 3) != OT_INTEGER || sq_gettype(vm, 3) == OT_NULL) {
|
||||
return sq_throwerror(vm, _SC("you can only assign integers to this list"));
|
||||
}
|
||||
|
||||
SQInteger idx, val;
|
||||
sq_getinteger(vm, 2, &idx);
|
||||
if (sq_gettype(vm, 3) == OT_NULL) {
|
||||
this->RemoveItem(idx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sq_getinteger(vm, 3, &val);
|
||||
if (!this->HasItem(idx)) {
|
||||
this->AddItem(idx, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->ChangeItem(idx, val);
|
||||
return 0;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file ai_list.hpp List custom entries. */
|
||||
|
||||
#ifndef AI_LIST_HPP
|
||||
#define AI_LIST_HPP
|
||||
|
||||
#include "ai_abstractlist.hpp"
|
||||
|
||||
/**
|
||||
* Creates an empty list, in which you can add integers.
|
||||
* @ingroup AIList
|
||||
*/
|
||||
class AIList : public AIAbstractList {
|
||||
public:
|
||||
/** Get the name of this class to identify it towards squirrel. */
|
||||
static const char *GetClassName() { return "AIList"; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Add an item to the list.
|
||||
* @param item the item to add.
|
||||
* @param value the value to assign.
|
||||
*/
|
||||
void AddItem(int32 item, int32 value);
|
||||
|
||||
/**
|
||||
* Change the value of an item in the list.
|
||||
* @param item the item to change
|
||||
* @param value the value to assign.
|
||||
*/
|
||||
void ChangeItem(int32 item, int32 value);
|
||||
|
||||
/**
|
||||
* Remove the item from the list.
|
||||
* @param item the item to remove.
|
||||
*/
|
||||
void RemoveItem(int32 item);
|
||||
|
||||
#ifndef DOXYGEN_SKIP
|
||||
/**
|
||||
* Used for [] set from Squirrel.
|
||||
*/
|
||||
SQInteger _set(HSQUIRRELVM vm);
|
||||
#endif /* DOXYGEN_SKIP */
|
||||
};
|
||||
|
||||
#endif /* AI_LIST_HPP */
|
@ -1,35 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||
|
||||
#include "ai_list.hpp"
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow AIList to be used as Squirrel parameter */
|
||||
template <> AIList *GetParam(ForceType<AIList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIList *)instance; }
|
||||
template <> AIList &GetParam(ForceType<AIList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIList *)instance; }
|
||||
template <> const AIList *GetParam(ForceType<const AIList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIList *)instance; }
|
||||
template <> const AIList &GetParam(ForceType<const AIList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIList *)instance; }
|
||||
template <> int Return<AIList *>(HSQUIRRELVM vm, AIList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIList", res, NULL, DefSQDestructorCallback<AIList>); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
void SQAIList_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass <AIList> SQAIList("AIList");
|
||||
SQAIList.PreRegister(engine, "AIAbstractList");
|
||||
SQAIList.AddConstructor<void (AIList::*)(), 1>(engine, "x");
|
||||
|
||||
SQAIList.DefSQMethod(engine, &AIList::AddItem, "AddItem", 3, "xii");
|
||||
SQAIList.DefSQMethod(engine, &AIList::ChangeItem, "ChangeItem", 3, "xii");
|
||||
SQAIList.DefSQMethod(engine, &AIList::RemoveItem, "RemoveItem", 2, "xi");
|
||||
SQAIList.DefSQAdvancedMethod(engine, &AIList::_set, "_set");
|
||||
|
||||
SQAIList.PostRegister(engine);
|
||||
}
|
Loading…
Reference in New Issue
Block a user