summaryrefslogtreecommitdiff
path: root/src/tilearea_type.h
blob: 6c2639cff4bd6b8a33ad82e4519d4e335d69e436 (plain)
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
/* $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 tilearea_type.h Type for storing the 'area' of something uses on the map. */

#ifndef TILEAREA_TYPE_H
#define TILEAREA_TYPE_H

#include "tile_type.h"

/** Represents the covered area of e.g. a rail station */
struct TileArea {
	/** Just construct this tile area */
	TileArea() {}

	/**
	 * Construct this tile area with some set values
	 * @param tile the base tile
	 * @param w the width
	 * @param h the height
	 */
	TileArea(TileIndex tile, uint8 w, uint8 h) : tile(tile), w(w), h(h) {}

	/**
	 * Construct this tile area based on two points.
	 * @param start the start of the area
	 * @param end   the end of the area
	 */
	TileArea(TileIndex start, TileIndex end);

	TileIndex tile; ///< The base tile of the area
	uint8 w;        ///< The width of the area
	uint8 h;        ///< The height of the area

	/**
	 * Add a single tile to a tile area; enlarge if needed.
	 * @param to_add The tile to add
	 */
	void Add(TileIndex to_add);

	/**
	 * Clears the 'tile area', i.e. make the tile invalid.
	 */
	void Clear()
	{
		this->tile = INVALID_TILE;
		this->w    = 0;
		this->h    = 0;
	}

	/**
	 * Does this tile area intersect with another?
	 * @param ta the other tile area to check against.
	 * @return true if they intersect.
	 */
	bool Intersects(const TileArea &ta) const;
};

#endif /* TILEAREA_TYPE_H */