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

Module - AI

What is it?

Stratagus uses a very simple scripted AI. There are no optimizations yet. The complete AI was written on one weekend. Until no AI specialist joins, I keep this AI.

What is scripted AI?

The AI script tells the engine build 4 workers, than build 3 footman, than attack the player, than sleep 100 frames.

The AI API

Management calls

Manage the inititialse and cleanup of the AI players.

InitAiModule()

Initialise all global varaibles and structures. Called before AiInit, or before game loading.

::AiInit(::Player)

Called for each player, to setup the AI structures Player::Aiin the player structure. It can use Player::AiName to select different AI's.

CleanAi()

Called to release all the memory for all AI structures. Must handle self which players contains AI structures.

::SaveAi(::FILE *)

Save the AI structures of all players to file. Must handle self which players contains AI structures.

Periodic calls

This functions are called regular for all AI players.

::AiEachCycle(::Player)

Called each game cycle, to handle quick checks, which needs less CPU.

::AiEachSecond(::Player)

Called each second, to handle more CPU intensive things.

Event call-backs

This functions are called, when some special events happens.

AiHelpMe()

Called if a unit owned by the AI is attacked.

AiUnitKilled()

Called if a unit owned by the AI is killed.

AiNeedMoreSupply()

Called if an trained unit is ready, but not enough food is available for it.

AiWorkComplete()

Called if a unit has completed its work.

AiCanNotBuild()

Called if the AI unit can't build the requested unit-type.

AiCanNotReach()

Called if the AI unit can't reach the building place.

AiTrainingComplete()

Called if AI unit has completed training a new unit.

AiUpgradeToComplete()

Called if AI unit has completed upgrade to new unit-type.

AiResearchComplete()

Called if AI unit has completed research of an upgrade or spell.

(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.