_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

Classes
ai_building.cpp File Reference
#include "stratagus.h"
#include "ai_local.h"
#include "map.h"
#include "pathfinder.h"
#include "player.h"
#include "tileset.h"
#include "unit.h"
#include "unit_find.h"
#include "unittype.h"

Classes

class  BuildingPlaceFinder
 
class  HallPlaceFinder
 
class  LumberMillPlaceFinder
 

Functions

ai_building.cpp - AI building functions.
static bool IsPosFree (const Vec2i &pos, const CUnit &exceptionUnit)
 
static bool AiCheckSurrounding (const CUnit &worker, const CUnitType &type, const Vec2i &pos, bool &backupok)
 
static bool AiFindBuildingPlace2 (const CUnit &worker, const CUnitType &type, const Vec2i &startPos, const CUnit *startUnit, bool checkSurround, Vec2i *resultPos)
 
static bool AiFindHallPlace (const CUnit &worker, const CUnitType &type, const Vec2i &startPos, int resource, Vec2i *resultPos)
 
static bool AiFindLumberMillPlace (const CUnit &worker, const CUnitType &type, const Vec2i &startPos, int resource, Vec2i *resultPos)
 
static bool AiFindMiningPlace (const CUnit &worker, const CUnitType &type, const Vec2i &startPos, int resource, Vec2i *resultPos)
 
bool AiFindBuildingPlace (const CUnit &worker, const CUnitType &type, const Vec2i &nearPos, Vec2i *resultPos)
 Find nice building place. More...
 

Function Documentation

◆ AiCheckSurrounding()

static bool AiCheckSurrounding ( const CUnit worker,
const CUnitType type,
const Vec2i pos,
bool &  backupok 
)
static

Check if the surrounding are free. Depending on the value of flag, it will check : 0: the building will not block any way 1: all surrounding is free

Parameters
workerWorker to build.
typeType of building.
posmap tile position for the building.
backupokLocation can be used as a backup
Returns
True if the surrounding is free, false otherwise.
Note
Can be faster written.

◆ AiFindBuildingPlace()

bool AiFindBuildingPlace ( const CUnit worker,
const CUnitType type,
const Vec2i nearPos,
Vec2i resultPos 
)

Find nice building place.

Find free building place.

Parameters
workerWorker to build building.
typeType of building.
nearPosStart search near nearPos position (or worker->X if nearPos is invalid).
resultPosPointer for position returned.
Returns
True if place found, false if no found.
Todo:
Better and faster way to find building place of oil platforms Special routines for special buildings.

◆ AiFindBuildingPlace2()

static bool AiFindBuildingPlace2 ( const CUnit worker,
const CUnitType type,
const Vec2i startPos,
const CUnit startUnit,
bool  checkSurround,
Vec2i resultPos 
)
static

Find free building place. (flood fill version)

Parameters
workerWorker to build building.
typeType of building.
startPosOriginal position to try building
checkSurroundCheck if the perimeter of the building is free
resultPosOUT: Pointer for position returned.
Returns
True if place found, false if no found.

◆ AiFindHallPlace()

static bool AiFindHallPlace ( const CUnit worker,
const CUnitType type,
const Vec2i startPos,
int  resource,
Vec2i resultPos 
)
static

Find building place for hall. (flood fill version)

The best place: 1) near to resource. !2) near to wood. !3) near to worker and must be reachable. 4) no enemy near it. 5) no hall already near !6) enough gold in mine

Parameters
workerWorker to build building.
typeType of building.
startPosStart search position (if == -1 then unit X pos used).
resourceresource to be near.
resultPosOUT: Pointer for position returned.
Returns
True if place found, false if not found.
Todo:
FIXME: This is slow really slow, using two flood fills, is not a perfect solution.

◆ AiFindLumberMillPlace()

static bool AiFindLumberMillPlace ( const CUnit worker,
const CUnitType type,
const Vec2i startPos,
int  resource,
Vec2i resultPos 
)
static

Find free building place for lumber mill. (flood fill version)

Parameters
workerWorker to build building.
typeType of building.
resourceresource terrain to be near.
startPosStart search X position (if == -1 then unit X pos used).
resultPosOUT: Pointer for position returned.
Returns
True if place found, false if not found.
Todo:
FIXME: This is slow really slow, using two flood fills, is not a perfect solution.

◆ AiFindMiningPlace()

static bool AiFindMiningPlace ( const CUnit worker,
const CUnitType type,
const Vec2i startPos,
int  resource,
Vec2i resultPos 
)
static

◆ IsPosFree()

static bool IsPosFree ( const Vec2i pos,
const CUnit exceptionUnit 
)
static
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.