CreatureLowLevelAPI

Florian Wesch edited this page Apr 5, 2012 · 1 revision

API for programming your creatures

This is the API the game provides you.

<wiki:toc max_depth="2" />

Basic Functions

print

prints a message on all player connections.

usage

print(msg)

parameters

  • msg - message

return values

none

suicide

Kills a creature. 1/3 of creatures food will be placed on the current tile. You lose 40 points.

usage

suicide(creature_id)

parameters

  • creature_id - id of your own creature

return values

none

set_path

Sets a destination for the CREATURE_MOVE state. Use set_state to actually move to the target.

usage

ok = set_path(creature_id, x, y)

parameters

  • creature_id - id of your own creature
  • x - X coordinate
  • y - Y coordinate

return values

  • ok - boolean, indicating whether target could be set

get_pos

Gets coodinate of a creature.

usage

x, y = get_pos(creature_id)

parameters

  • creature_id - id of a creature

return values

  • x - X coordinate
  • y - Y coordinate

get_state

Returns the current state of a creature.

usage

state = get_state(creature_id)

parameters

  • creature_id - id of your own creature

return values

  • state - state of the creature. See ''set_state'' for details

set_state

Sets the state of a creature.

There are 8 different states:

CREATURE_IDLE Creature is idle. Your can only be King of the Hill, if your creature is idle.
CREATURE_WALK Creature moves to the destination previously set by ''set_path''. State changes to IDLE once the target is reached. Requires a destination set by ''set_path''
CREATURE_HEAL Food is used to heal the creature
CREATURE_EAT Creature eats food from the current tile
CREATURE_ATTACK Attack the creature previously set by ''set_target''. See CreatureTypes for details.
CREATURE_CONVERT Creature uses food to change its type to the type previously set by ''set_convert''. Only conversion from type 0 to type 1 is possible. The conversion requires 8000 food. The food used for conversion is lost if the conversion is interrupted by changing into another state.
CREATURE_SPAWN Creature of type 1 can spawn new creatures of type 0. This requires health and food. 20% health is lost by entering the state. Afterwards 8000 food is used. Both is lost if spawning is interrupted by changing to another state.
CREATURE_FEED Creature transfers food to the creature previously set by ''set_target''. Maximum distance is 256 units.

usage

ok = set_state(creature_id, state)

parameters

  • creature_id - id of your own creature
  • state - state

return values

  • ok - true, if state change is possible. false otherwise.

set_target

Sets a target creature for the feeding or attacking state.

usage

ok = set_target(creature_id, target_creature_id)

parameters

  • creature_id - id of your own creature
  • target_creature_id - id of a creature

return values

  • ok - true is possible, false otherwise

set_convert

Sets the type of the conversion state.

usage

ok = set_convert(creature_id, type)

parameters

  • creature_id - id of your own creature
  • type - the target type for conversion

return values

  • ok - true is possible, false otherwise

get_nearest_enemy

Returns information about the nearest enemy

usage

creature_id, x, y, playernum, dist = nearest_enemy(creature_id)

parameters

  • creature_id - id of a creature

return values

  • creature_id - id of the nearest creature or nil if there is no enemy (how boring :-) )
  • x - X coordinate
  • y - Y coordinate
  • playernum - player number
  • dist - linear distance

get_type

Returns the type of a creature.

usage

type = get_type(creature_id)

parameters

  • creature_id - id of a creature

return values

  • type - type

get_food

Returns the amount of food stored by a creature

usage

food = get_food(creature_id)

parameters

  • creature_id - id of your own creature

return values

  • food - food amount

get_health

Returns the health value of a creature.

usage

health = get_health(creature_id)

parameters

  • creature_id - id of a creature

return values

  • health - Health (0-100)

get_speed

Returns the maximum speed of a creature.

usage

speed = get_speed(creature_id)

parameters

  • creature_id - id of your own creature

return values

  • speed - speed in Units/sec.

get_tile_food

Returns the amount of food available on a creatures tile.

usage

food = get_tile_food(creature_id)

parameters

  • creature_id - id of your own creature

return values

  • food - food available

get_max_food

Returns the maximum amount of food a creature can store.

usage

food = get_max_food(creature_id)

parameters

  • creature_id - id of your own creature

return values

  • food - maximum amount of food the creature can store

get_distance

Returns the distance between creatures.

usage

dist = get_distance(creature_id, target_creature_id)

parameters

  • creature_id - id of your own creature
  • target_creature_id - id of a creature

return values

  • dist - linear distance (may change to actual walk distance)

set_message

Sets the short message displayed below your creature.

usage

set_message(creature_id, message)

parameters

  • creature_id - id of your own creature
  • message - message. maximum size if 8 characters.

return values

none

Misc Functions

world_size

Returns the worlds boundary coordinates.

usage

x1, y1, x2, y2 = world_size()

parameters

none

return values

  • x1 - top left X
  • y1 - top left Y
  • x2 - bottom right X
  • y2 - bottom right Y

game_time

Returns the current game time.

usage

time = game_time()

parameters

none

return values

  • time - time since start of game in msec.

get_koth_pos

Returns the center coordinate of the King-of-the-Hill tile.

usage

x, y = get_koth_pos()

parameters

none

return values

  • x - X coordinate
  • y - Y coordinate

creature_exists

Checks whether a creature exists.

usage

flag = creature_exists(creature_id)

parameters

  • creature_id - id of a creature

return values

  • flag - bool indicating existence

creature_player

Returns the creature player number.

usage

player_no = creature_player(creature_id)

parameters

  • creature_id - id of a creature

return values

  • playernumber or nil, if creature doesn't exist

player_exists

Checks whether a player exists.

usage

flag = player_exists(player_id)

parameters

  • player_id - id of a player

return values

  • flag - bool indicating existence

king_player

Returns the current king player.

usage

player_id = king_player()

parameters

none

return values

  • player_id - id of the king :)

player_score

Returns a players score

usage

score = player_score(player_id)

parameters

  • player_id - id of a player

return values

  • score - Score

get_cpu_usage

Returns a players cpu usage.

usage

usage = get_cpu_usage()

parameters

none

return values

  • usage - 0 - 100

Predefined Variables

MAXPLAYER

Maximum amount of players

player_number

id of own player