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::PlaceProp | Places a battle object at a fractional grid tile (not snapped to the tile center), rotated by angle degrees. |
battle::IsFreeTile | True if the battle grid tile is inside the grid, walkable and free (false outside battle). |
battle::GetTurnNo | Returns the current battle turn number, 0 outside battle. |
battle::Nearest | 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 | Ends the current side's turn in battle. |
battle::PutLargeTimeBomb | Places a large time bomb on a battle tile; after 6 enemy turns it explodes and everyone dies. |
battle::GetVar | The value of a battle variable (nil if not set); battle variables live until the end of the battle. |
battle::SetVar | Sets a battle variable; every fighter's OnVar(name, value) hears it. |
battle::AddVar | Adds to a battle variable and returns the new value; every fighter's OnVar(name, value) hears it. |
battle::SpawnEnemy | Puts a new fighter into the battle on free tile (x, y) (for a large fighter, its top-left tile). |
battle::SpawnHero | 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). |
battle::SpawnCivilian | 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). |
battle::Lose | The battle ends in defeat, as when the heroes die (game over): at the next end-of-battle check (after the current action). |
battle::Win | The 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
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
True if the battle grid tile is inside the grid, walkable and free (false outside battle).
battle::GetTurnNo() → int
Returns the current battle turn number, 0 outside battle.
battle::Nearest(list, string) → any
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
Ends the current side's turn in battle.
battle::PutLargeTimeBomb(int, int) → int
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
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
Sets a battle variable; every fighter's OnVar(name, value) hears it.
battle::AddVar(string name, any delta) → any
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
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
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
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
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
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.