____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

ai_force.cpp File Reference

AI force functions. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include "unittype.h"
#include "unit.h"
#include "ai_local.h"
#include "actions.h"
#include "map.h"
#include "pathfinder.h"
#include "player.h"

Go to the source code of this file.

Functions

void AiResetUnitTypeEquiv (void)
 Finds all equivalents units to a given one.
void AiNewUnitTypeEquiv (CUnitType *a, CUnitType *b)
 Remove any equivalence between unittypes.
int AiFindUnitTypeEquiv (const CUnitType *unittype, int *result)
 Finds all available equivalents units to a given one, in the prefered order.
int AiFindAvailableUnitTypeEquiv (const CUnitType *unittype, int *usableTypes)
static void AiCleanForce (int force)
void AiCleanForces (void)
 < Cleanup units in force
static int AiCheckBelongsToForce (int force, const CUnitType *type)
void AiAssignToForce (CUnit *unit)
 Assign a free units to a force.
void AiAssignFreeUnitsToForce (void)
 Attack with force at position.
void AiAttackWithForceAt (int force, int x, int y)
 Attack with force.
void AiAttackWithForce (int force)
 Periodic called force manager handler.
static void AiForceAttacks (AiForce *force)
void AiForceManager (void)

Variables

int UnitTypeEquivs [UnitTypeMax+1]
 equivalence between unittypes


Detailed Description

AI force functions.

Definition in file ai_force.cpp.


Function Documentation

void AiAssignFreeUnitsToForce ( void   ) 

Attack with force at position.

Assign free units to force.

Definition at line 334 of file ai_force.cpp.

References AI_MAX_ATTACKING_FORCES, AiAssignToForce(), AiCleanForces(), AiPlayer, PlayerAi::Force, int(), PlayerAi::Player, CPlayer::TotalNumUnits, UnitMax, AiForce::Units, and CPlayer::Units.

Referenced by AiForceManager(), and CclAiForce().

void AiAssignToForce ( CUnit unit  ) 

Assign a free units to a force.

Ai assign unit to force.

Parameters:
unit Unit to assign to force.

Definition at line 310 of file ai_force.cpp.

References AI_MAX_FORCES, AiCheckBelongsToForce(), AiPlayer, AiForce::Attacking, AiForce::Defending, PlayerAi::Force, CUnit::RefsIncrease(), CUnit::Type, and AiForce::Units.

Referenced by AiAssignFreeUnitsToForce(), and AiTrainingComplete().

void AiAttackWithForce ( int  force  ) 

void AiAttackWithForceAt ( int  force,
int  x,
int  y 
)

Attack with force.

Attack at position with force.

Parameters:
force Force number to attack with.
x X tile map position to be attacked.
y Y tile map position to be attacked.

Definition at line 376 of file ai_force.cpp.

References AiCleanForce(), AiPlayer, AiForce::Attacking, CUnitType::CanAttack, CommandAttack(), CommandMove(), FlushCommands, PlayerAi::Force, int(), CUnit::Type, AiForce::Units, and CUnit::Wait.

Referenced by AiHelpMe().

static int AiCheckBelongsToForce ( int  force,
const CUnitType type 
) [static]

Check if the units belongs to the force.

Parameters:
force Force to be checked.
type Type to check.
Returns:
True if it fits, false otherwise.

Definition at line 267 of file ai_force.cpp.

References AiPlayer, AiForce::Completed, PlayerAi::Force, int(), CUnitType::Slot, AiUnitType::Type, CUnit::Type, AiForce::Units, UnitTypeEquivs, UnitTypeMax, AiForce::UnitTypes, and AiUnitType::Want.

Referenced by AiAssignToForce().

static void AiCleanForce ( int  force  )  [static]

void AiCleanForces ( void   ) 

< Cleanup units in force

Cleanup units in forces.

Definition at line 249 of file ai_force.cpp.

References AI_MAX_ATTACKING_FORCES, and AiCleanForce().

Referenced by AiAssignFreeUnitsToForce(), AiTrainingComplete(), and CclAiWaitForce().

int AiFindAvailableUnitTypeEquiv ( const CUnitType unittype,
int *  usableTypes 
)

Find All unittypes equivalent to a given one, and which are available UnitType are returned in the prefered order ( ie palladin >> knight... )

Parameters:
unittype The unittype to find equivalence for
usableTypes int array which will hold the result. (Size UnitTypeMax+1)
Returns:
the number of unittype found

Definition at line 137 of file ai_force.cpp.

References AiFindUnitTypeEquiv(), AiPlayer, CPlayer::Index, PlayerAi::Player, and UnitTypes.

Referenced by AiMakeUnit().

int AiFindUnitTypeEquiv ( const CUnitType unittype,
int *  result 
)

Finds all available equivalents units to a given one, in the prefered order.

Find All unittypes equivalent to a given one

Parameters:
unittype the unittype to find equivalence for
result int array which will hold the result. (Size UnitTypeMax+1)
Returns:
the number of unittype found

Definition at line 108 of file ai_force.cpp.

References CUnitType::Slot, UnitTypeEquivs, and UnitTypeMax.

Referenced by AiFindAvailableUnitTypeEquiv(), AiReduceMadeInBuilt(), and AiRemoveFromBuilt().

static void AiForceAttacks ( AiForce force  )  [static]

Force on attack ride. We attack until there is no unit or enemy left.

Parameters:
force Force pointer.

Definition at line 479 of file ai_force.cpp.

References AiForce::Attacking, AttackUnitsInDistance(), CUnitType::CanAttack, CommandAttack(), CommandMove(), DebugPrint, FlushCommands, int(), CUnit::IsIdle(), MaxMapWidth, NoUnitP, CUnit::Orders, CUnit::Type, AiForce::Units, CUnit::X, CUnit::Y, and y.

Referenced by AiForceManager().

void AiForceManager ( void   ) 

Entry point of force manager, perodic called.

Todo:
FIXME: is this really needed anymore

Definition at line 565 of file ai_force.cpp.

References AI_MAX_ATTACKING_FORCES, AiAssignFreeUnitsToForce(), AiCleanForce(), AiForceAttacks(), AiPlayer, AiForce::Attacking, AttackUnitsInReactRange(), CUnitType::CanAttack, DebugPrint, AiForce::Defending, PlayerAi::Force, int(), CUnit::Type, and AiForce::Units.

Referenced by AiEachSecond().

void AiNewUnitTypeEquiv ( CUnitType a,
CUnitType b 
)

Remove any equivalence between unittypes.

Make two unittypes equivalents from the AI's point of vue

Parameters:
a the first unittype
b the second unittype

Definition at line 75 of file ai_force.cpp.

References CUnitType::Slot, UnitTypeEquivs, and UnitTypeMax.

Referenced by CclDefineAiHelper().

void AiResetUnitTypeEquiv ( void   ) 

Finds all equivalents units to a given one.

Remove any equivalence between unittypes

Definition at line 62 of file ai_force.cpp.

References UnitTypeEquivs, and UnitTypeMax.

Referenced by FreeAi(), and InitAiModule().


Variable Documentation

int UnitTypeEquivs[UnitTypeMax+1]

equivalence between unittypes

Definition at line 52 of file ai_force.cpp.

Referenced by AiCheckBelongsToForce(), AiCleanForce(), AiFindUnitTypeEquiv(), AiNewUnitTypeEquiv(), AiResetUnitTypeEquiv(), and CclAiForce().


Generated on Sat Feb 21 00:28:15 2009 for Bos Wars by  doxygen 1.5.6