2009-01-12 17:11:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/** @file script_tilelist.cpp Implementation of ScriptTileList and friends. */
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-01-22 10:33:16 +00:00
|
|
|
#include "../../stdafx.h"
|
2011-11-29 23:07:38 +00:00
|
|
|
#include "script_tilelist.hpp"
|
|
|
|
#include "script_industry.hpp"
|
2009-08-30 11:47:41 +00:00
|
|
|
#include "../../industry.h"
|
2009-06-24 17:39:54 +00:00
|
|
|
#include "../../station_base.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(t1)) return;
|
|
|
|
if (!::IsValidTile(t2)) return;
|
|
|
|
|
2010-01-04 18:39:46 +00:00
|
|
|
TileArea ta(t1, t2);
|
|
|
|
TILE_AREA_LOOP(t, ta) this->AddItem(t);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
void ScriptTileList::AddTile(TileIndex tile)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return;
|
|
|
|
|
|
|
|
this->AddItem(tile);
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
void ScriptTileList::RemoveRectangle(TileIndex t1, TileIndex t2)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(t1)) return;
|
|
|
|
if (!::IsValidTile(t2)) return;
|
|
|
|
|
2010-01-04 18:39:46 +00:00
|
|
|
TileArea ta(t1, t2);
|
|
|
|
TILE_AREA_LOOP(t, ta) this->RemoveItem(t);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
void ScriptTileList::RemoveTile(TileIndex tile)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return;
|
|
|
|
|
|
|
|
this->RemoveItem(tile);
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
ScriptTileList_IndustryAccepting::ScriptTileList_IndustryAccepting(IndustryID industry_id, int radius)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!ScriptIndustry::IsValidIndustry(industry_id) || radius <= 0) return;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const Industry *i = ::Industry::Get(industry_id);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/* Check if this industry accepts anything */
|
|
|
|
{
|
|
|
|
bool cargo_accepts = false;
|
2009-01-23 22:09:31 +00:00
|
|
|
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
|
|
|
if (i->accepts_cargo[j] != CT_INVALID) cargo_accepts = true;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
if (!cargo_accepts) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
|
|
|
|
|
2010-12-12 18:47:08 +00:00
|
|
|
TileArea ta(i->location.tile - ::TileDiffXY(radius, radius), i->location.w + radius * 2, i->location.h + radius * 2);
|
|
|
|
TILE_AREA_LOOP(cur_tile, ta) {
|
2009-01-12 17:11:45 +00:00
|
|
|
if (!::IsValidTile(cur_tile)) continue;
|
|
|
|
/* Exclude all tiles that belong to this industry */
|
|
|
|
if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue;
|
|
|
|
|
|
|
|
/* Only add the tile if it accepts the cargo (sometimes just 1 tile of an
|
|
|
|
* industry triggers the acceptance). */
|
2009-06-27 21:06:58 +00:00
|
|
|
CargoArray acceptance = ::GetAcceptanceAroundTiles(cur_tile, 1, 1, radius);
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
bool cargo_accepts = false;
|
2009-01-23 22:09:31 +00:00
|
|
|
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
2009-06-27 18:26:50 +00:00
|
|
|
if (i->accepts_cargo[j] != CT_INVALID && acceptance[i->accepts_cargo[j]] != 0) cargo_accepts = true;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
if (!cargo_accepts) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->AddTile(cur_tile);
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
ScriptTileList_IndustryProducing::ScriptTileList_IndustryProducing(IndustryID industry_id, int radius)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!ScriptIndustry::IsValidIndustry(industry_id) || radius <= 0) return;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const Industry *i = ::Industry::Get(industry_id);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/* Check if this industry produces anything */
|
2010-01-04 21:10:20 +00:00
|
|
|
bool cargo_produces = false;
|
|
|
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
|
if (i->produced_cargo[j] != CT_INVALID) cargo_produces = true;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
2010-01-04 21:10:20 +00:00
|
|
|
if (!cargo_produces) return;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
|
|
|
|
|
2010-12-12 18:47:08 +00:00
|
|
|
TileArea ta(i->location.tile - ::TileDiffXY(radius, radius), i->location.w + radius * 2, i->location.h + radius * 2);
|
|
|
|
TILE_AREA_LOOP(cur_tile, ta) {
|
2009-01-12 17:11:45 +00:00
|
|
|
if (!::IsValidTile(cur_tile)) continue;
|
|
|
|
/* Exclude all tiles that belong to this industry */
|
|
|
|
if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue;
|
|
|
|
|
|
|
|
this->AddTile(cur_tile);
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
ScriptTileList_StationType::ScriptTileList_StationType(StationID station_id, ScriptStation::StationType station_type)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!ScriptStation::IsValidStation(station_id)) return;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const StationRect *rect = &::Station::Get(station_id)->rect;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
uint station_type_value = 0;
|
2011-11-29 23:15:35 +00:00
|
|
|
/* Convert ScriptStation::StationType to ::StationType, but do it in a
|
2009-01-12 17:11:45 +00:00
|
|
|
* bitmask, so we can scan for multiple entries at the same time. */
|
2011-11-29 23:15:35 +00:00
|
|
|
if ((station_type & ScriptStation::STATION_TRAIN) != 0) station_type_value |= (1 << ::STATION_RAIL);
|
|
|
|
if ((station_type & ScriptStation::STATION_TRUCK_STOP) != 0) station_type_value |= (1 << ::STATION_TRUCK);
|
|
|
|
if ((station_type & ScriptStation::STATION_BUS_STOP) != 0) station_type_value |= (1 << ::STATION_BUS);
|
|
|
|
if ((station_type & ScriptStation::STATION_AIRPORT) != 0) station_type_value |= (1 << ::STATION_AIRPORT) | (1 << ::STATION_OILRIG);
|
|
|
|
if ((station_type & ScriptStation::STATION_DOCK) != 0) station_type_value |= (1 << ::STATION_DOCK) | (1 << ::STATION_OILRIG);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-12-12 18:47:08 +00:00
|
|
|
TileArea ta(::TileXY(rect->left, rect->top), rect->right - rect->left + 1, rect->bottom - rect->top + 1);
|
|
|
|
TILE_AREA_LOOP(cur_tile, ta) {
|
2009-01-12 17:11:45 +00:00
|
|
|
if (!::IsTileType(cur_tile, MP_STATION)) continue;
|
|
|
|
if (::GetStationIndex(cur_tile) != station_id) continue;
|
|
|
|
if (!HasBit(station_type_value, ::GetStationType(cur_tile))) continue;
|
|
|
|
this->AddTile(cur_tile);
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|