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

src/ai/ai_building.cpp File Reference

#include "stratagus.h"
#include "ai_local.h"
#include "map.h"
#include "pathfinder.h"
#include "player.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)

Function Documentation

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:
worker Worker to build.
type Type of building.
pos map tile position for the building.
backupok Location can be used as a backup
Returns:
True if the surrounding is free, false otherwise.
Note:
Can be faster written.

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

Find free building place.

Parameters:
worker Worker to build building.
type Type of building.
nearPos Start search near nearPos position (or worker->X if nearPos is invalid).
resultPos Pointer 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.

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:
worker Worker to build building.
type Type of building.
startPos Original position to try building
checkSurround Check if the perimeter of the building is free
resultPos OUT: Pointer for position returned.
Returns:
True if place found, false if no found.

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:
worker Worker to build building.
type Type of building.
startPos Start search position (if == -1 then unit X pos used).
resource resource to be near.
resultPos OUT: 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.

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:
worker Worker to build building.
type Type of building.
resource resource terrain to be near.
startPos Start search X position (if == -1 then unit X pos used).
resultPos OUT: 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.

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

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.