FreeCraft Configuration Language Description: Artificial Intelligence (AI)


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

(C) Copyright 2002-2003 by The FreeCraft Project. Distributed under the "GNU General Public License"


FreeCraft Readme FAQ CCL PREV NEXT Index
define-ai define-ai-helper define-ai-player define-ai-wc-names ai:attack-with-force ai:check-force ai:debug ai:dump ai:force ai:force-role ai:get-race ai:get-sleep-cycles ai:need ai:player ai:research ai:restart ai:script ai:set ai:set-collect! ai:set-reserve! ai:sleep ai:upgrade-to ai:wait ai:wait-force

Intro - Introduction to AI functions and variables

Everything around the control of the FreeCraft AI.

Functions

define-ai

Description

This defines how a special AI works. Each level can use his own AI definition.

Syntax

(define-ai name race class script)
name
Unique name of this AI definitions.
race
Name of the race for what this definition can be used, if the definition can be used for any race use "*".
class
Class name of this definition. Used to chooce the AI for computer players. The puds contains numbers which are mapped by the C table AiTypeWcNames into internal names. Some common used names are "passive", "land-attack", "sea-attack", "air-attack".
script
A list of scheme statements executed one after another.

( (code-1) (code-2) ... (code-n) )

code-1 can be any valid scheme statement. Currently each second this statement is executed, if the statement returns not #t, than the next time the next statement is executed. No statement should use more than 3 ms.

Example

(define-ai "wc2-passive" "*" "passive"
  '((ai:sleep	10000)
  (ai:restart) ))

Defines the passive computer AI, which does nothing.

Used

$LIBARYPATH/ccl/ai.ccl

define-ai-helper

Description

The AI is complete configurable, nothing is hardcoded. The AI knows nothing about any units without this table. This table defines F.E. what unit can build and what they can build and many other things that the AI must know.

Syntax

(define-ai-helper (list))
list
A list of features:

Example

A minimal AI helper definition:
(define-ai-helper
  (list 'build 'unit-peasant 'unit-farm)
  (list 'train 'unit-town-hall 'unit-peasant)
  (list 'upgrade 'unit-town-hall 'unit-keep)
  (list 'research 'unit-human-blacksmith 'upgrade-sword1)
  (list 'repair 'unit-peasant 'unit-town-hall)
  (list 'collect 'unit-peasant 'gold)
  (list 'with-goods 'unit-peasant-with-gold 'gold)
  (list 'unit-limit 'unit-farm 'food)
  (list 'unit-equiv 'unit-town-hall 'unit-keep))

A peasant can build a farm.

The town hall can train a peasant.

A town hall can be upgraded to a keep.

The blacksmith can reasearch the upgrade sword1.

A peasant can repair the town hall.

A peasant can collect gold.

A the peasant with gold carries gold.

To fix the food shortage the AI must build farms.

For the AI is a keep equivalent to a town hall.

Used

$LIBARYPATH/ccl/ai.ccl

define-ai-player

Description

Define an AI player. (NOT SUPPORTED)

Syntax

(define-ai-player (list ...))

Example

FIXME:
    (define-ai-player (list ...))

FIXME:

Not Used

define-ai-wc-names

Description

Define AI mapping from original number to internal symbol.

Syntax

(define-ai-wc-names (list ...))

Example

FIXME:
    (define-ai-wc-names (list ...))

FIXME:

Not Used

ai:attack-with-force

Description

Attack the opponent with a force. The place is choosen by the AI. If there are flyers, ships and land units in the force they could attack different goals.

Syntax

(ai:attack-with-force force)
force
Number of the force to which the units should belong. 0 - 9 is currently supported.
The force isn't moved as unit, faster units attacks first, than later the slower units will attack.

Example

    (ai:force 0 'unit-footman 1)
    (ai:wait-force 0)
    (ai:attack-with-force 0)

Force 0 is built with one footman. The script continues processing, if the footman is ready trained. Now attack the opponent with force 0.

Used

$LIBARYPATH/ccl/ai.ccl

ai:check-force

Description

Check if a force is ready.

Syntax

(ai:check-force force)
force
Number of the force to which the units should belong. 0 - 9 is currently supported.

Example

    (ai:force 0 'unit-footman 1)
    (if (ai:check-force 0) (ai:sleep 500))

Force 0 is build with one footman. When the force is ready, sleep for 500 frames.

Not Used

ai:debug

Description

Enable or disable the debug output of the AI script execution.

Syntax

(ai:debug flag)
flag
If #t enables printing of the AI commands, if #f disables it.

Example

    (ai:debug #t)

Prints now the commands of this computer player.

Used

$LIBARYPATH/ccl/ai.ccl

ai:dump

Description

Dump some AI debug information.

Syntax

(ai:dump)

Example

    (ai:dump)

Prints out some debug information.

Not Used

ai:force

Description

Define a force, what and how many units should belong to a force. Up to 10 forces are currently supported.
Force 0 is currently fixed to be the defence force. Send to a building or unit under attack.
If there are any unassigned units of the requested unit-type, than they are assigned to the force.
Note: The low-level didn't support the reduce of a force.

Syntax

(ai:force force unit-type-1 count-1 ... unit-type-N count-N)
force
Number of the force to which the units should belong. 0 - 9 is currently supported.
unit-type-1
unit-type-N
Unit-type that should be in the force. Currently only mobile (trained) units are allowed.
count-1
count-N
How many of this units should be in the force.
The unit-types should be build in a fixed order. From left to right? or from each unit-type one after the other?

Example

    (ai:force 0 'unit-footman 4 'unit-bowman 5)
    (ai:force 1 'unit-footman 3 'unit-bowman 2)

First the force 0 is filled up with 4 footmans and 5 bowmans, after this force 1 is filled with 3 footmans and 2 bowmans.

Used

$LIBARYPATH/ccl/ai.ccl

ai:force-role

Description

Define the role of a force.

Syntax

(ai:force-role force role)
force
Number of the force to which the units should belong. 0 - 9 is currently supported.
role
The role of the force. Can be either 'attack or 'defend.

Example

    (ai:force-role 0 'attack)

Sets the role of force 0 to attack.

Used

$LIBARYPATH/ccl/ai.ccl

ai:get-race

Description

Get the race of the current AI player.

Syntax

(ai:get-race)

Example

    (ai:get-race)

Returns the race name of the current AI player.

Used

$LIBARYPATH/ccl/ai.ccl

ai:get-sleep-cycles

Description

Get the number of cycles to sleep.

Syntax

(ai:get-sleep-cycles)

Example

    (ai:get-sleep-cycles)

Returns the number of cycles to sleep.

Not Used

ai:need

Description

Tells the AI that it should have an unit of this unit-type. The AI builds or trains units in this order of the ai:set/ai:need commands. If the unit or an equivalent unit already exists, the AI does nothing. If the unit is lost, it is automatic rebuild. If the units are requested in wrong order, the AI could hang up. Resources are collected automatic and farms are automatic build, but additional could be requested.

Syntax

(ai:need unit-type)
unit-type
Name of the unit-type required.

Example

  (ai:need (unit-type 'unit-great-hall))
  (ai:need (unit-type 'unit-barrack))

The great hall must be build before a barrack.

Used

$LIBARYPATH/ccl/ai.ccl

ai:player

Description

Return the player of the running AI.

Syntax

(ai:player)

Example

    (ai:player)

Returns the player of the running AI.

Not Used

ai:research

Description

Let the AI research an upgrade, upgrades are reseached in command order. And automatic researched if lost. Building orders have a higher priority. The script writer is responsible for the correct order. If wrong the AI could hang up.

Syntax

(ai:research upgrade)
upgrade
Upgrade name to be researched.

Example

    (ai:research 'upgrade-shield1)

Research a better armor for land units.

Used

$LIBARYPATH/ccl/ai.ccl

ai:restart

Description

Restart with the main AI script. Could be used as longjmp for the AI scripts.

Syntax

(ai:restart)

Example

(define-ai "passive" "*" "passive"
  '( (ai:sleep   10000)
     (ai:restart) ))

A endless script doing nothing.

Used

$LIBARYPATH/ccl/ai.ccl

ai:script

Description

Execute a new script, can be used for loops, subroutines. But this must be handled by the user.

Syntax

(ai:script script)
script
A list of AI commands. Executed one after the other.

Example

(define attack-endloop
  '((ai:with-force 1)
    (ai:attack-with-force 1)
    (ai:script attack-endloop) ))

An example with a for ever loop. Wait for force 1 ready (all units trained), than attack with the force 1. This is done endless.

Used

$LIBARYPATH/ccl/ai.ccl

ai:set

Description

This ai:need with a number. Tells the AI that it should have a specified number of an unit of this unit-type. The AI builds or trains units in this order of the ai:set/ai:need commands. If the unit or an equivalent unit already exists, the AI does nothing. If the units are lost, they are automatic rebuild. If the units are requested in wrong order, the AI could hang up. Resources are collected automatic and farms are automatic build, but additional could be requested. In the opposite to ai:need, which always inserts a request, ai:set modifies the last request to the new number.

Syntax

(ai:set unit-type count)
unit-type
Name of the unit-type(s) required.
count
Number of unit-types(s) required.

Example

    (ai:set 'unit-peon 2)

Request two peons.

Used

$LIBARYPATH/ccl/ai.ccl

ai:set-collect!

Description

Set AI player resource collect percent.

Syntax

(ai:set-collect! #(time gold wood oil ore stone coal))
time
Time in game cycles.
gold
Gold resource.
wood
Wood resource.
oil
Oil resource.
ore
Ore resource.
stone
Stone resource.
coal
Coal resource.

Example

    (ai:set-collect! #(0  50 50 0  0 0 0))

Set the collect percent to 50% gold and 50% wood.

Not Used

ai:set-reserve!

Description

Set AI player resource reserve.

Syntax

(ai:set-reserve! #( time gold wood oil ore stone coal))
time
Time in game cycles.
gold
Gold resource.
wood
Wood resource.
oil
Oil resource.
ore
Ore resource.
stone
Stone resource.
coal
Coal resource.

Example

    (ai:set-reserve! #( 0  0 0 0  0 0 0))

Set all of the reserves to 0.

Not Used

ai:sleep

Description

Wait some frames, to let the opponent (you) recover.

Syntax

(ai:sleep frames)
frames
How many frames (~1/30s) the AI shouldn't proceed with the script.

Example

    (ai:sleep 500)

Wait 500 frames ~16s.

Used

$LIBARYPATH/ccl/ai.ccl

ai:upgrade-to

Description

Upgrade units to an improved type. You must give for each unit you want to upgrade an upgrade command. The computer automatic searches which unit it upgrades.

Syntax

(ai:upgrade-to unit-type)
unit-type
Unit type to that an unit should be upgraded.

Example

    (ai:upgrade-to 'unit-keep)

Upgrade a town-hall to keep.

Used

$LIBARYPATH/ccl/ai.ccl

ai:wait

Description

Waits until the *first* request of this unit-type is completed. Don't forget to request an unit-type, before you wait on it.

Syntax

(ai:wait type)
type
Wait for this unit type.

Example

    (ai:need 'unit-peasant)
    (ai:wait 'unit-peasant)

Proceed only if a peasant is ready.

Used

$LIBARYPATH/ccl/ai.ccl

ai:wait-force

Description

Wait until a force is complete, the forces are build in force number order. First 0, than 1, last 9.

Syntax

(ai:wait-force force)
force
Number of the force to which the units should belong. 0 - 9 is currently supported.

Example

    (ai:force 0 'unit-footman 1)
    (ai:wait-force 0)

Force 0 is build with one footman. The script continues processing, if the footman is ready trained.

Used

$LIBARYPATH/ccl/ai.ccl

Notes

The current AI script support is very limited, many new functions are needed. If you want to write this you know who to contact.

Examples

(define-ai "wc2-example" 'orc 'land-attack

This is the AI "wc2-example" usable for human race and land-attack.

  '( (ai:need (unit-type 'unit-great-hall))

The first need unit is the great-hall.

     (ai:need 'unit-peon)

The next unit should be the peon.

     (ai:wait 'unit-great-hall)

Now wait until the great hall is available. Could hang if no great hall can be build.

     (ai:wait 'unit-peon) ))

Now wait unit we have a worker to build the next things.

FIXME: need some complex examples.
Last changed: $Id: ai.html,v 1.8 2003/02/05 00:35:02 jsalmon3 Exp $
All trademarks and copyrights on this page are owned by their respective owners.
(c) 2002-2003 by The FreeCraft Project