src/ai/api/ai_tilelist.cpp
author rubidium
Sun, 03 Feb 2008 20:17:54 +0000
branchnoai
changeset 9724 b39bc69bb2f2
parent 9723 eee46cb39750
child 9757 5cdc14959fb6
permissions -rw-r--r--
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
/* $Id$ */

/** @file ai_tilelist.cpp handles all functions of the AITileList class */

#include "ai_tilelist.hpp"

#include "../../landscape.h"
#include "../../map_func.h"

void AITileList::FixRectangleSpan(TileIndex &t1, TileIndex &t2)
{
	uint x1 = ::TileX(t1);
	uint x2 = ::TileX(t2);

	uint y1 = ::TileY(t1);
	uint y2 = ::TileY(t2);

	if (x1 >= x2) ::Swap(x1, x2);
	if (y1 >= y2) ::Swap(y1, y2);

	t1 = ::TileXY(x1, y1);
	t2 = ::TileXY(x2, y2);
}

void AITileList::AddRectangle(TileIndex t1, TileIndex t2)
{
	if (!IsValidTile(t1) || !IsValidTile(t2)) return;

	this->FixRectangleSpan(t1, t2);

	uint w = TileX(t2) - TileX(t1) + 1;
	uint h = TileY(t2) - TileY(t1) + 1;

	BEGIN_TILE_LOOP(t, w, h, t1) {
		this->AddItem(t);
	} END_TILE_LOOP(t, w, h, t1)
}

void AITileList::AddTile(TileIndex tile)
{
	if (!IsValidTile(tile)) return;

	this->AddItem(tile);
}

void AITileList::RemoveRectangle(TileIndex t1, TileIndex t2)
{
	if (!IsValidTile(t1) || !IsValidTile(t2)) return;

	this->FixRectangleSpan(t1, t2);

	uint w = TileX(t2) - TileX(t1) + 1;
	uint h = TileY(t2) - TileY(t1) + 1;

	BEGIN_TILE_LOOP(t, w, h, t1) {
		this->RemoveItem(t);
	} END_TILE_LOOP(t, w, h, t1)
}

void AITileList::RemoveTile(TileIndex tile)
{
	if (!IsValidTile(tile)) return;

	this->RemoveItem(tile);
}