$treeview $search $mathjax
Stratagus  2.2.6
$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 <stdio.h>
#include <stdlib.h>
#include "stratagus.h"
#include "unit.h"
#include "unittype.h"
#include "map.h"
#include "pathfinder.h"
#include "ai_local.h"
#include "player.h"

Functions

ai_building.cpp - AI building functions.
static int AiCheckSurrounding (const CUnit &worker, const CUnitType &type, int x, int y, bool &backupok)
static int AiFindBuildingPlace2 (const CUnit &worker, const CUnitType &type, int ox, int oy, Vec2i *dpos, int surround)
static int AiFindHallPlace (const CUnit &worker, const CUnitType &type, int nx, int ny, Vec2i *dpos, int resource=GoldCost)
static int AiFindLumberMillPlace (const CUnit &worker, const CUnitType &type, int nx, int ny, Vec2i *dpos)
static int AiFindMiningPlace (const CUnit &worker, const CUnitType &type, int nx, int ny, Vec2i *dpos, int resource)
int AiFindBuildingPlace (const CUnit &worker, const CUnitType &type, int nx, int ny, Vec2i *dpos)

Function Documentation

static int AiCheckSurrounding ( const CUnit worker,
const CUnitType type,
int  x,
int  y,
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.
x X map tile position for the building.
y Y 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.

int AiFindBuildingPlace ( const CUnit worker,
const CUnitType type,
int  nx,
int  ny,
Vec2i dpos 
)

Find free building place.

Parameters:
worker Worker to build building.
type Type of building.
nx Start search near X position (or worker->X if nx == -1).
ny Start search near Y position (or worker->Y if ny == -1).
dpos 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 int AiFindBuildingPlace2 ( const CUnit worker,
const CUnitType type,
int  ox,
int  oy,
Vec2i dpos,
int  surround 
) [static]

Find free building place. (flood fill version)

Parameters:
worker Worker to build building.
type Type of building.
ox Original X position to try building
oy Original Y position to try building
dpos Pointer for position returned.
Returns:
True if place found, false if no found.

static int AiFindHallPlace ( const CUnit worker,
const CUnitType type,
int  nx,
int  ny,
Vec2i dpos,
int  resource = GoldCost 
) [static]

Find building place for hall. (flood fill version)

The best place: 1) near to goldmine. !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.
nx Start search X position (if == -1 then unit X pos used).
ny Start search Y position (if == -1 then unit Y pos used).
dpos 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 int AiFindLumberMillPlace ( const CUnit worker,
const CUnitType type,
int  nx,
int  ny,
Vec2i dpos 
) [static]

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

Parameters:
worker Worker to build building.
type Type of building.
nx Start search X position (if == -1 then unit X pos used).
ny Start search X position (if == -1 then unit X pos used).
dpos 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 int AiFindMiningPlace ( const CUnit worker,
const CUnitType type,
int  nx,
int  ny,
Vec2i dpos,
int  resource 
) [static]

(C) Copyright 1998-2011 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.