-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHouseList.nut
More file actions
99 lines (95 loc) · 2.53 KB
/
HouseList.nut
File metadata and controls
99 lines (95 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* This file is part of CityBuilder, which is a GameScript for OpenTTD
*
* CityBuilder 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 of the License
*
* CityBuilder 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 CityBuilder; If not, see <http://www.gnu.org/licenses/> or
* write to the Free Software Foundation, Inc., 51 Franklin Street,
* Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
// Contributors:
// house list for a town.
require("DiagonalWalker.nut");
class XHouseList{
centerTile = 0;
tid = 0;
walker = null;
hlist = null;
constructor(townID)
{
tid = townID;
centerTile = GSTown.GetLocation(townID);
walker = DiagonalWalker(centerTile);
}
function Populate(n = 16777215, max = 100000);
function GetList();
function RemoveHouses(x);
}
function XHouseList::Populate(n = 16777215, max = 100000)
{
// limit populating to the house count.
local houseCount = GSTown.GetHouseCount(tid);
n = min(max, houseCount);
walker.Reset(-1);
hlist = GSTileList();
local i = 0;
local count = 0;
local curTile = centerTile;
local CARGO_PAXID = GSController.GetSetting("metro_cargo");
while(i++ < max && count < n)
{
// is there a house on the current tile?
// house tiles have to be in the town authority
// house tiles are buildable
// house tiles have no owner
if(GSTile.GetTownAuthority(curTile) == this.tid
&& GSTile.IsBuildable(curTile) == true
&& GSTile.GetOwner(curTile) == -1)
{
if(GSTile.GetCargoAcceptance(curTile, CARGO_PAXID,1,1,0) > 0)
{
if(GSIndustry.GetIndustryID(curTile) == 65535)
{
// we found a house.
count++;
hlist.AddTile(curTile);
}
}
}
curTile = walker.Walk();
}
}
function XHouseList::GetList()
{
return this.hlist;
}
function XHouseList::RemoveHouses(x)
{
local u = 0;
this.Populate(x);
foreach(tl, _ in this.hlist)
{
if(GSController.GetSetting("debug_level") > 5)
{
GSLog.Info("Try to Remove house at X->"+GSMap.GetTileX(tl)+" , Y->"+GSMap.GetTileY(tl));
}
if(GSTile.DemolishTile(tl))
{
if(GSController.GetSetting("debug_level") > 5)
{
GSLog.Info("Successfully removed this house!");
}
u++;
}
}
return u;
}