Skip to content

Field manual / Level editor

battle — Battle

The battle as a whole: tiles, turns, the bomb, battle variables, spawning fighters, victory and defeat. Functions without an original Classic name are OpenGorky only; outside battle they do nothing and return 0 or nil.

Summary

battle::PlacePropPlaces a battle object at a fractional grid tile (not snapped to the tile center), rotated by angle degrees.
battle::IsFreeTileTrue if the battle grid tile is inside the grid, walkable and free (false outside battle).
battle::GetTurnNoReturns the current battle turn number, 0 outside battle.
battle::NearestOpenGorky only (the original exe has no such function), for fighter evaluation: returns the living fighter of the side nearest to the tile (dx² + dy²), nil if there is none.
battle::EndTurnEnds the current side's turn in battle.
battle::PutLargeTimeBombPlaces a large time bomb on a battle tile; after 6 enemy turns it explodes and everyone dies.
battle::GetVarThe value of a battle variable (nil if not set); battle variables live until the end of the battle.
battle::SetVarSets a battle variable; every fighter's OnVar(name, value) hears it.
battle::AddVarAdds to a battle variable and returns the new value; every fighter's OnVar(name, value) hears it.
battle::SpawnEnemyPuts a new fighter into the battle on free tile (x, y) (for a large fighter, its top-left tile).
battle::SpawnHeroLike battle::SpawnEnemy, but the fighter is on the heroes' side and is controlled by the player: it can be selected and given a turn like a hero (its death, like a hero's death, is a defeat).
battle::SpawnCivilianLike battle::SpawnEnemy, but the fighter is on nobody's side (side is "civilian"): both heroes and enemies attack it, and it does not count toward victory or defeat (a script can declare the outcome: battle::Lose, §15.2).
battle::LoseThe battle ends in defeat, as when the heroes die (game over): at the next end-of-battle check (after the current action).
battle::WinThe battle ends in victory, as when the last enemy dies: at the next end-of-battle check (after the current action) — reward, OnBattleEnd.

Functions

battle::PlaceProp(string, float, float, float) → int

Classic: PlaceCombatActor

Places a battle object at a fractional grid tile (not snapped to the tile center), rotated by angle degrees. Returns 1 on success, otherwise 0.

battle::IsFreeTile(int, int) → bool

Classic: AIFreeTile

True if the battle grid tile is inside the grid, walkable and free (false outside battle).

battle::GetTurnNo() → int

Classic: AIGetTurnNo

Returns the current battle turn number, 0 outside battle.

battle::Nearest(list, string) → any

Classic: BattleNearest

OpenGorky only (the original exe has no such function), for fighter evaluation: returns the living fighter of the side nearest to the tile (dx² + dy²), nil if there is none.

battle::EndTurn() → int

Classic: EndTurnGlobal

Ends the current side's turn in battle.

battle::PutLargeTimeBomb(int, int) → int

Classic: PutLargeTimeBomb

Places a large time bomb on a battle tile; after 6 enemy turns it explodes and everyone dies. Returns 1 if placed, 0 if the tile is off the map.

battle::GetVar(string name) → any

Classic: BattleGetVar

The value of a battle variable (nil if not set); battle variables live until the end of the battle.

battle::SetVar(string name, any value) → any

Classic: BattleSetVar

Sets a battle variable; every fighter's OnVar(name, value) hears it.

battle::AddVar(string name, any delta) → any

Classic: BattleAddVar

Adds to a battle variable and returns the new value; every fighter's OnVar(name, value) hears it.

battle::SpawnEnemy(character fighter, int x, int y) → any

Classic: BattleSpawnEnemy

Puts a new fighter into the battle on free tile (x, y) (for a large fighter, its top-left tile). fighter is a class key as the rules name it ("ft_hornet": the fighter that includes this script, like a level fighter), or a .ftr file; in an OpenGorky project, a fighter archetype (~c"characters::grandma_child", §10.9): the object of its block with its nested weapons, named after the last part of the path. The object is named after it (ft_hornet, ft_hornet_2…). The fighter gets the native and scripted abilities of its Abilities row and OnSpawn, like a fighter entering battle. Weapons come from the weapons field ("a.wpn, b.wpn"); if it is absent, copies of the weapons of the first fighter of the same class in the world; if there is none, only MonsterAttack rows with give. Returns the object name or nil: outside battle, no such class, the tile is outside the grid or occupied. The fighter is on the enemy side and acts under AI, like any enemy.

battle::SpawnHero(character fighter, int x, int y) → any

Classic: BattleSpawnHero

Like battle::SpawnEnemy, but the fighter is on the heroes' side and is controlled by the player: it can be selected and given a turn like a hero (its death, like a hero's death, is a defeat). It does not join the party: after the battle it stays at the location.

battle::SpawnCivilian(character fighter, int x, int y, ?string ai) → any

Classic: BattleSpawnCivilian

Like battle::SpawnEnemy, but the fighter is on nobody's side (side is "civilian"): both heroes and enemies attack it, and it does not count toward victory or defeat (a script can declare the outcome: battle::Lose, §15.2). ai: "dummy" (default) — stands still and does nothing; "normal" — acts on the enemies' turn under its class's AI and attacks both heroes and enemies. Any other value gives nil.

battle::Lose() → int

Classic: BattleLose

The battle ends in defeat, as when the heroes die (game over): at the next end-of-battle check (after the current action). 1; 0 outside battle.

battle::Win() → int

Classic: BattleWin

The battle ends in victory, as when the last enemy dies: at the next end-of-battle check (after the current action) — reward, OnBattleEnd. 1; 0 outside battle.