src/ai/api/ai_tilelist.cpp
branchnoai
changeset 9592 c5c09cfde63a
child 9599 949374e83b78
equal deleted inserted replaced
9591:cd88f4b7cba0 9592:c5c09cfde63a
       
     1 #include "ai_tilelist.hpp"
       
     2 
       
     3 void AITileList::FixRectangleSpan(TileIndex &t1, TileIndex &t2)
       
     4 {
       
     5 	uint x1 = ::TileX(t1);
       
     6 	uint x2 = ::TileX(t2);
       
     7 
       
     8 	uint y1 = ::TileY(t1);
       
     9 	uint y2 = ::TileY(t2);
       
    10 
       
    11 	if (x1 >= x2) ::Swap(x1, x2);
       
    12 	if (y1 >= y2) ::Swap(y1, y2);
       
    13 
       
    14 	t1 = ::TileXY(x1, y1);
       
    15 	t2 = ::TileXY(x2, y2);
       
    16 }
       
    17 
       
    18 void AITileList::AddRectangle(TileIndex t1, TileIndex t2)
       
    19 {
       
    20 	if (!IsValidTile(t1) || !IsValidTile(t2)) return;
       
    21 
       
    22 	this->FixRectangleSpan(t1, t2);
       
    23 
       
    24 	uint w = TileX(t2) - TileX(t1) + 1;
       
    25 	uint h = TileY(t2) - TileY(t1) + 1;
       
    26 
       
    27 	BEGIN_TILE_LOOP(t, w, h, t1) {
       
    28 		this->AddItem(t);
       
    29 	} END_TILE_LOOP(t, w, h, t1)
       
    30 }
       
    31 
       
    32 void AITileList::AddTile(TileIndex tile)
       
    33 {
       
    34 	if (!IsValidTile(tile)) return;
       
    35 
       
    36 	this->AddItem(tile);
       
    37 }
       
    38 
       
    39 void AITileList::RemoveRectangle(TileIndex t1, TileIndex t2)
       
    40 {
       
    41 	if (!IsValidTile(t1) || !IsValidTile(t2)) return;
       
    42 
       
    43 	this->FixRectangleSpan(t1, t2);
       
    44 
       
    45 	uint w = TileX(t2) - TileX(t1) + 1;
       
    46 	uint h = TileY(t2) - TileY(t1) + 1;
       
    47 
       
    48 	BEGIN_TILE_LOOP(t, w, h, t1) {
       
    49 		this->RemoveItem(t);
       
    50 	} END_TILE_LOOP(t, w, h, t1)
       
    51 }
       
    52 
       
    53 void AITileList::RemoveTile(TileIndex tile)
       
    54 {
       
    55 	if (!IsValidTile(tile)) return;
       
    56 
       
    57 	this->RemoveItem(tile);
       
    58 }