src/ai/api/ai_tilelist_valuator.cpp
author truelight
Sat, 14 Jul 2007 22:06:38 +0000
branchnoai
changeset 9658 e7675771bca4
parent 9657 f2c6e332d8bc
child 9694 e72987579514
permissions -rw-r--r--
(svn r10565) [NoAI] -Add: allow giving width, height and radius to check for cargo acceptance
9592
c5c09cfde63a (svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff changeset
     1
#include "ai_tilelist_valuator.hpp"
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9611
diff changeset
     2
#include "ai_tile.hpp"
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9611
diff changeset
     3
#include "ai_road.hpp"
9655
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
     4
#include "ai_map.hpp"
9592
c5c09cfde63a (svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff changeset
     5
#include "../../tile.h"
9603
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
     6
#include "../../road_map.h"
9592
c5c09cfde63a (svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff changeset
     7
c5c09cfde63a (svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff changeset
     8
int32 AITileListBuildable::Valuate(int32 tile) const
c5c09cfde63a (svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff changeset
     9
{
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9611
diff changeset
    10
	return AITile::IsBuildable(tile);
9592
c5c09cfde63a (svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff changeset
    11
}
9603
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
    12
9657
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    13
int32 AITileListBuildableRectangle::Valuate(int32 tile) const
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    14
{
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    15
	uint tx, ty;
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    16
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    17
	tx = AIMap::GetTileX(tile);
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    18
	ty = AIMap::GetTileY(tile);
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    19
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    20
	for (uint x = tx; x < this->width + tx; x++) {
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    21
		for (uint y = ty; y < this->height + ty; y++) {
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    22
			if (!AITile::IsBuildable(AIMap::GetTileIndex(x, y))) return false;
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    23
		}
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    24
	}
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    25
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    26
	return true;
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    27
}
f2c6e332d8bc (svn r10564) [NoAI] -Add: added a AITileList valuator that checks for a NxM buildable spot with the entry from the AITileList as top-left tile
truelight
parents: 9655
diff changeset
    28
9611
5cf58c6571b7 (svn r9776) [NoAI] -Add: added AITileListSlope as valuator to see if tiles are flat or not
truelight
parents: 9609
diff changeset
    29
int32 AITileListSlope::Valuate(int32 tile) const
5cf58c6571b7 (svn r9776) [NoAI] -Add: added AITileListSlope as valuator to see if tiles are flat or not
truelight
parents: 9609
diff changeset
    30
{
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9611
diff changeset
    31
	return AITile::GetSlope(tile);
9611
5cf58c6571b7 (svn r9776) [NoAI] -Add: added AITileListSlope as valuator to see if tiles are flat or not
truelight
parents: 9609
diff changeset
    32
}
5cf58c6571b7 (svn r9776) [NoAI] -Add: added AITileListSlope as valuator to see if tiles are flat or not
truelight
parents: 9609
diff changeset
    33
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9611
diff changeset
    34
int32 AITileListNeighbourRoadCount::Valuate(int32 tile) const
9603
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
    35
{
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9611
diff changeset
    36
	return AIRoad::GetNeighbourRoadCount(tile);
9603
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
    37
}
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
    38
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
    39
int32 AITileListRoadTile::Valuate(int32 tile) const
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
    40
{
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
    41
	return ::IsTileType(tile, MP_STREET) && ::GetRoadTileType(tile) != ROAD_TILE_DEPOT;
49323bf80ebd (svn r9747) [NoAI] -Add: added AITileListRoadTile and AITileListNeighbourRoad as Valuators for AITileList
truelight
parents: 9592
diff changeset
    42
}
9609
f0dbf5850145 (svn r9767) [NoAI] -Add: add support for params in the constructor (via C++ templates)
truelight
parents: 9604
diff changeset
    43
f0dbf5850145 (svn r9767) [NoAI] -Add: add support for params in the constructor (via C++ templates)
truelight
parents: 9604
diff changeset
    44
int32 AITileListCargoAcceptance::Valuate(int32 tile) const
f0dbf5850145 (svn r9767) [NoAI] -Add: add support for params in the constructor (via C++ templates)
truelight
parents: 9604
diff changeset
    45
{
9658
e7675771bca4 (svn r10565) [NoAI] -Add: allow giving width, height and radius to check for cargo acceptance
truelight
parents: 9657
diff changeset
    46
	return AITile::GetCargoAcceptance(tile, this->cargo_type, this->width, this->height, this->radius);
9609
f0dbf5850145 (svn r9767) [NoAI] -Add: add support for params in the constructor (via C++ templates)
truelight
parents: 9604
diff changeset
    47
}
9655
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    48
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    49
int32 AITileListDistanceManhattanToTile::Valuate(int32 tile) const
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    50
{
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    51
	return AIMap::DistanceManhattan(this->tile, tile);
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    52
}
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    53
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    54
int32 AITileListDistanceSquareToTile::Valuate(int32 tile) const
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    55
{
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    56
	return AIMap::DistanceSquare(this->tile, tile);
e8e43f333832 (svn r10557) [NoAI] -Add: added for all lists 2 valuators: DistanceManhattanToTile and DistanceSquareToTile, to get the distance from object to some tile you specify
truelight
parents: 9617
diff changeset
    57
}