LuaGameplay.wiki
changeset 1749 91756d20ce3e
child 1754 33355f5010ce
equal deleted inserted replaced
1748:e78a3fd5a0e4 1749:91756d20ce3e
       
     1 #summary List of gameplay-related functions in the Lua API
       
     2 
       
     3 = Lua API: Gameplay functions =
       
     4 This page is a list of all gameplay-related functions in the [LuaAPI Lua API].
       
     5 
       
     6 === `GameFlags` functions ===
       
     7 
       
     8 ==== <tt>!ClearGameFlags()</tt> ====
       
     9 Disables *all* !GameFlags.
       
    10 
       
    11 ==== <tt>!DisableGameFlags(gameflag, ...)</tt> ====
       
    12 Disables the listed !GameFlags, without changing the status of other !GameFlags.
       
    13 
       
    14 ==== <tt>!EnableGameFlags(gameflag, ...)</tt> ====
       
    15 Enables the listed !GameFlags, without changing the status of other !GameFlags. In missions, no !GameFlags are set initially.
       
    16 
       
    17 ==== <tt>!GetGameFlag(gameflag)</tt> ====
       
    18 Returns `true` if the specified gameflag is enabled, otherwise `false`.
       
    19 
       
    20 === Turns ===
       
    21 ==== <tt>SkipTurn()</tt> (0.9.24) ====
       
    22 Forces the current hedgehog to skip its turn.
       
    23 
       
    24 ==== <tt>EndTurn([noTaunts])</tt> (0.9.23) ====
       
    25 Ends the current turn immediately.
       
    26 
       
    27 Normally, a “Coward” taunt may be played and an announcer message may be shown (depending on the situation). Set the optional `noTaunts` parameter to `true` to force the engine to never play a taunt or show a message. `noTaunts` is `false` by default.
       
    28 
       
    29 ==== <tt>Retreat(time [, respectGetAwayTimeFactor)</tt> (0.9.25) ====
       
    30 Forces the current turn into the retreating phase, as if the hog made an attack. That is, the current hedgehog is unable to attack or select a weapon, only movement is possible until the retreat time is up.
       
    31 
       
    32 The retreat time must be set with `time` in milliseconds. By default, this time is automatically multiplied with get-away time percentage from the game scheme for seamless integration with schemes. If you want to ignore the game scheme for some reason and set the retreat time no matter what, set `respectGetAwayTimeFactor` to `false`.
       
    33 
       
    34 If the current hedgehog was busy doing an attack, the attack is aborted, no shot is made. If this function is called in the ready phase of a turn, the ready phase continues normally, but the turn will begin in the retreat phase instead.
       
    35 
       
    36 Note: If you want the turn to end instantly, it is recommended to use `EndTurn` instead.
       
    37 
       
    38 ==== <tt>!SetTurnTimeLeft(newTurnTimeLeft)</tt> (0.9.25) ====
       
    39 Set the remaining turn time in milliseconds. The current remaining turn time can be read from the variable `TurnTimeLeft`.
       
    40 
       
    41 ==== <tt>!SetReadyTimeLeft(newReadyTimeLeft)</tt> (0.9.25) ====
       
    42 Set the remaining ready time in milliseconds. This function should only be called in onNewTurn. The current remaining ready time can be read from the variable `ReadyTimeLeft`.
       
    43 
       
    44 ==== <tt>!SetTurnTimePaused(isPaused)</tt> (0.9.25) ====
       
    45 Pauses the turn time indefinitely if `isPaused` is set to `true`, disabled the turn time pause if `isPaused` is set to `false`.
       
    46 
       
    47 ==== <tt>!GetTurnTimePaused()</tt> (0.9.25) ====
       
    48 Returns `true` if the turn time is currently paused by `SetTurnTimePaused`, otherwise returns `false`.
       
    49 
       
    50 ==== <tt>!EndGame()</tt> ====
       
    51 Makes the game end.
       
    52 
       
    53 === Environment ===
       
    54 ==== <tt>!SetGravity(percent)</tt> ====
       
    55 Changes the current gravity of the game in percent (relative to default, integer value).
       
    56 Setting it to 100 will set gravity to default gravity of Hedgewars, 200 will double it, etc.
       
    57 
       
    58 ==== <tt>!GetGravity()</tt> ====
       
    59 Returns the current gravity in percent.
       
    60 
       
    61 ==== <tt>!SetWaterLine(waterline)</tt> ====
       
    62 Sets the water level (`WaterLine`) to the specified y-coordinate.
       
    63 
       
    64 ==== <tt>!SetWind(windSpeed)</tt> ====
       
    65 Sets the current wind in the range of -100 to 100 inclusive. Use together with `gfDisableWind` for full control.
       
    66 
       
    67 ==== <tt>!GetWind()</tt> (0.9.24) ====
       
    68 Returns current wind, expressed as a floating point number between -100 to 100 inclusive. Note there may be rounding errors.
       
    69 
       
    70 ==== <tt>!SetMaxBuildDistance(distInPx)</tt> ====
       
    71 Sets the maximum building distance for of girders and rubber bands in pixels to `distInPx`. If `distInPx` is `0`, the limit is disabled. If called without arguments, the distance will be reset to the default value.
       
    72 
       
    73 ==== <tt>Explode(x, y, radius[, options])</tt> (0.9.24) ====
       
    74 Cause an explosion or erase land, push or damage gears.
       
    75 
       
    76 By default, an explosion destroys a circular piece of land and damages and pushes gears in its radius.
       
    77 
       
    78 The explosion occurs at coordinates `(x, y)` with the given `radius`. Assuming 100% damage, the explosion damage at the center equals the explosion radius.
       
    79 
       
    80 The explosion will also have a visual effect (by spawning an explosion visual gear), unless the radius is very small.
       
    81 
       
    82 `options` is a bitmask which can be used to tweak how the explosion behaves:
       
    83 
       
    84 || *Flag* || *Meaning* ||
       
    85 || `EXPLAutoSound` || Plays an appropriate sound ||
       
    86 || `EXPLNoDamage` || Deal no damage to gears ||
       
    87 || `EXPLDoNotTouchHH` || Do not push hedgehogs ||
       
    88 || `EXPLDoNotTouchAny` || Do not push any gears ||
       
    89 || `EXPLDontDraw` || Do not destroy land ||
       
    90 || `EXPLForceDraw` || Destroy land, even if `gfSolidLand` is active ||
       
    91 || `EXPLNoGfx` || Do not show an explosion animation and do not shake the screen ||
       
    92 || `EXPLPoisoned` || Poison all hedgehogs in explosion radius ||
       
    93 
       
    94 `options` is assumed to be `EXPLAutoSound` by default. Set `options` to 0 to disable all flags.
       
    95 
       
    96 Examples:
       
    97 <code language="lua">
       
    98 -- Simple explosion at (100, 50) with radius 50
       
    99 Explode(100, 50, 50)
       
   100 
       
   101 -- Simple explosion without sound
       
   102 Explode(100, 50, 50, 0)
       
   103 
       
   104 -- Fake explosion which only pushes gears but deals no damage to gears and terrain
       
   105 Explode(500, 1000, 50, EXPLAutoSound + EXPLNoDamage + EXPLDontDraw)
       
   106 
       
   107 -- Erase a circle of land without side effects
       
   108 Explode(500, 100, 100, EXPLNoDamage + EXPLDoNotTouchAny + EXPLNoGfx)
       
   109 </code>
       
   110 
       
   111 === Ammo ===
       
   112 ==== <tt>!SetAmmo(ammoType, count, probability, delay, numberInCrate)</tt> ====
       
   113 This updates the settings (initial ammo, crate probability, etc.) for a specified [AmmoTypes ammo type]. This must only be used in the `onAmmoStoreInit()` event handler. In other places, this function will not work.
       
   114 
       
   115 In Lua missions, for *all* ammo types, the ammo count, probability, delay and number in crates is set to 0 initially. Note: This also includes skip!
       
   116 
       
   117 Parameters:
       
   118 
       
   119  * `ammoType`: Ammo type to be set
       
   120  * `count`: Initial ammo count. 9 = infinite
       
   121  * `probability`: Crate probability. Max. value is 9. 0 = never
       
   122  * `delay`: Number of rounds this ammo is delayed
       
   123  * `numberInCrate`: Amount of ammo in a crate
       
   124 
       
   125 Example:
       
   126 
       
   127 <code language="lua">    SetAmmo(amShotgun, 9, 0, 0, 0) -- unlimited amount of shotgun ammo for players
       
   128     SetAmmo(amGrenade, 0, 0, 0, 3) -- crates should contain always three grenade
       
   129     SetAmmo(amSkip, 9, 0, 0, 0) -- enable skip</code>
       
   130 
       
   131 Hint: It is recommended to always enable skip in missions. Only in exceptional circumstances you should choose to not enable skip.
       
   132 
       
   133 ==== <tt>!GetAmmo(ammoType)</tt> ====
       
   134 Returns ammo settings (initial ammo, crate probability, etc.) for a specified [AmmoTypes ammo type]. This function is analogue to `SetAmmo`.
       
   135 
       
   136 This function returns four numbers, in this order: initial ammo count, probability, delay and number in crate. These values correspond to the parameters 2-5 provided in `SetAmmo` and have the same meaning.
       
   137 
       
   138 Example:
       
   139 
       
   140 <code language="lua">count, prob, delay, numberInCrate = GetAmmo(amGrenade) -- Get ammo settings of amGrenade</code>
       
   141 
       
   142 ==== <tt>!SetAmmoDelay(ammoType, delay)</tt> ====
       
   143 Changes the delay of a specified [AmmoTypes Ammo Type].
       
   144 
       
   145 ==== <tt>!SetAmmoTexts(ammoType, name, caption, description [, showExtra])</tt> (0.9.23) ====
       
   146 Allows you to overwrite the displayed name and tooltip descriptions of a given ammo type. This function must only be called either inside the `onGameStart` callback function, or after the engine has called `onGameStart`.
       
   147 
       
   148  * `ammoType`: The ammo type to set the text for
       
   149  * `name`: Name of the ammo type (e.g. “Grenade” for `amGrenade`), affects both name in ammo menu and in the “ticker” message on the screen top.
       
   150  * `caption`: The second line in the ammo menu (below the title). E.g. “Timed grenade” for `amGrenade`.
       
   151  * `description`: Description text in ammo menu, below the caption.
       
   152  * `showExtra`: If `false` the special “extra” text line like “Weapon is not yet available” or “Weapon does not end turn” will be suppressed
       
   153 
       
   154 `title`, `caption`, `description` can be `nil`, in which case they will be reverted to the engine default value. This function returns `nil`.
       
   155 
       
   156 Example:
       
   157 <code language="lua">
       
   158 -- Overwrites bazooka name and description
       
   159 SetAmmoTexts(amBazooka, "Spoon Missile", "Crazy weapon", "This crazy weapon looks like a spoon and explodes on impact.|Attack: Hold to launch with more power")</code>
       
   160 
       
   161 ==== <tt>!SetAmmoDescriptionAppendix(ammoType, descAppend)</tt> (0.9.23) ====
       
   162 Will set a string `descAppend` to be appended below the “core” description (ammo tooltip) of the specified `ammoType`, without changing the ordinary description.
       
   163 Note that calling this function always sets the complete appended string, you can't use this function to append multiple texts in row.
       
   164 
       
   165 This function is recommended if you have tweaked an existing ammo type only a little and want to keep the original description intact as much as possible.
       
   166 
       
   167 Example:
       
   168 <code language="lua">
       
   169 -- Appends a text to the ammo tooltip of the bazooka but leaves name and main description intact
       
   170 SetAmmoTexts(amBazooka, "This weapon deals double the damage than usually.")</code>
       
   171 
       
   172 ==== <tt>!AddAmmo(gearUid, ammoType, ammoCount)</tt> ====
       
   173 Adds `ammoType` to the specified gear. The amount added is determined by the arguments passed via `SetAmmo()` in the `onAmmoStoreInit()` event handler. `ammoCount` is an optional parameter. If this is set, the ammo will *not* be added, but instead set to `ammoCount`. A value of `0` will remove the weapon, a value of `AMMO_INFINITE` will give infinite ammo.
       
   174 
       
   175 Note: By default, ammo is per-team, so calling `AddAmmo` for a hedgehog will give the ammo for the whole team. The game flags `gfPerHogAmmo` and `gfSharedAmmo` change how ammo is managed in the game, so these game flags also affect `AddAmmo`.
       
   176 
       
   177 ==== <tt>!GetAmmoName(ammoType [, ignoreOverwrite ])</tt> (0.9.23) ====
       
   178 Returns the localized name for the specified `ammoType`, taking an ammo name overwritten by `SetAmmoTexts` into account. If `ignoreOverwrite` is `true`, this function will always return the original ammo name of the weapon and ignores names which may have been overwritten by `SetAmmoTexts`.
       
   179 
       
   180 === Map ===
       
   181 ==== <tt>!MapHasBorder()</tt> ====
       
   182 Returns `true`/`false` if the map has a border or not.
       
   183 
       
   184 ==== <tt>!TestRectForObstacle(x1, y1, x2, y2, landOnly)</tt> ====
       
   185 Checks the rectangle between the given coordinates for possible collisions. Set `landOnly` to `true` if you don’t want to check for collisions with gears (hedgehogs, etc.).
       
   186 
       
   187 ==== <tt>!PlaceGirder(x, y, frameIdx)</tt> ====
       
   188 Attempts to place a girder with centre points `x`, `y` and a certain length and orientation, specified by `frameIdx`. The girder can only be placed in open space and must not collide with anything so this function may fail. It will return `true` on successful placement and `false` on failure.
       
   189 
       
   190 These are the accepted values for `frameIdx`:
       
   191 
       
   192 || *`frameIdx`* || *Length* || *Orientation* ||
       
   193 || 0 || short || horizontal ||
       
   194 || 1 || short || decreasing right ||
       
   195 || 2 || short || vertical ||
       
   196 || 3 || short || increasing right ||
       
   197 || 4 || long || horizontal ||
       
   198 || 5 || long || decreasing right ||
       
   199 || 6 || long || vertical ||
       
   200 || 7 || long || increasing right ||
       
   201 
       
   202 ==== <tt>!PlaceRubber(x, y, frameIdx)</tt> (0.9.23) ====
       
   203 Attempts to place a rubber with centre points `x`, `y` and a certain orientation, specified by `frameIdx`. The rubber can only be placed in open space and must not collide with anything so this function may fail. It will return `true` on successful placement and `false` on failure.
       
   204 
       
   205 These are the accepted values for `frameIdx`:
       
   206 
       
   207 || *`frameIdx`* || *Orientation* ||
       
   208 || 0 || horizontal ||
       
   209 || 1 || decreasing right ||
       
   210 || 2 || vertical ||
       
   211 || 3 || increasing right ||
       
   212 
       
   213 ==== <tt>!PlaceSprite(x, y, sprite, frameIdx, tint, behind, flipHoriz, flipVert, [, landFlag, ...])</tt> ====
       
   214 Places a [Sprites sprite] at the specified position (`x`, `y`) on the map, it behaves like terrain then. Unlike `PlaceGirder`, this function does not check for collisions, so the sprite can be placed anywhere within map boundaries. The function returns `true` if the placement was successful, `false` otherwise. `frameIdx` is the frame index starting by 0. `frameIdx` is used if the sprite consists of several sub-images. Only a subset of the sprites is currently supported by this function:
       
   215 
       
   216  * `sprAmGirder`
       
   217  * `sprAmRubber`
       
   218  * `sprAMSlot`
       
   219  * `sprAMAmmos`
       
   220  * `sprAMAmmosBW`
       
   221  * `sprAMCorners`
       
   222  * `sprHHTelepMask`
       
   223  * `sprTurnsLeft`
       
   224  * `sprSpeechCorner`
       
   225  * `sprSpeechEdge`
       
   226  * `sprSpeechTail`
       
   227  * `sprTargetBee`
       
   228  * `sprThoughtCorner`
       
   229  * `sprThoughtEdge`
       
   230  * `sprThoughtTail`
       
   231  * `sprShoutCorner`
       
   232  * `sprShoutEdge`
       
   233  * `sprShoutTail`
       
   234  * `sprBotlevels`
       
   235  * `sprIceTexture`
       
   236  * `sprCustom1`
       
   237  * `sprCustom2`
       
   238 
       
   239 `tint` is for an RGBA colouring to apply, this works about the same as `Tint` in gears. If `nil`, the original color is used.
       
   240 
       
   241 `behind` indicates the sprite should not replace existing land.
       
   242 
       
   243 `flipHoriz` and `flipVert` are for mirroring the sprite vertically and horizontally before placing, respectively.
       
   244 
       
   245 The 9th and later arguments specify land flags (see the constants section) to be used for the newly created terrain. If omitted, `lfNormal` is assumed.
       
   246 
       
   247 Example:
       
   248 
       
   249 <code language="lua">PlaceSprite(2836, 634, sprAmGirder, 5)
       
   250 -- Places the girder sprite as normal terrain at (2836, 634). The `frameIdx` 5 is for the long decreasing right girder.</code>
       
   251 <code language="lua">PlaceSprite(1411, 625, sprAmRubber, 1, nil, nil, nil, nil, lfBouncy)
       
   252 -- Places the rubber band sprite as bouncy terrain at (2836, 634). The `frameIdx` 1 is for the decreasing right rubber band.</code>
       
   253 
       
   254 ==== <tt>!EraseSprite(x, y, sprite, frameIdx, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert, [, landFlag, ...])</tt> ====
       
   255 Erases a [Sprites sprite] at the specified position (`x`, `y`) on the map. `frameIdx` is the frame index starting by 0. `sprite`, `frameIdx`, `flipHoriz` and `flipVert` behave the same as in `PlaceSprite`. For `sprite`, the same subset of sprites is permitted.
       
   256 
       
   257 Set `eraseOnLFMatch` to `true` to erase all land for a pixel that matches any of the passed in land flags.  This is useful if, for example, an `lfBouncy` sprite was placed “behind” land using `PlaceSprite` and you want to remove it without destroying the non-bouncy terrain.
       
   258 
       
   259 Set `onlyEraseLF` to `true` to only remove specific land flags. If for example a sprite consists of `lfIndestructible` and `lfBouncy`, and you call `EraseSprite` with `onlyEraseLF` and `lfIndestructible` set, the sprite will remain bouncy but can be destroyed.  You can use this to entirely remove all land flags from a sprite—at this point the sprite will be visual only, painted on the map but with no collision.
       
   260 
       
   261 Examples:
       
   262 
       
   263 <code language="lua">EraseSprite(2836, 634, sprAmGirder, 5)
       
   264 -- Removes the girder sprite at (2836, 634). The frameIdx 5 is for the long decreasing right girder.</code>
       
   265 <code language="lua">EraseSprite(1411, 625, sprAmRubber, 1, true, true, nil, nil, lfIndestructible)
       
   266 -- Removes indestructibility from a rubber band sprite at (2836, 634). The frameIdx 1 is for the decreasing right rubber band.</code>
       
   267 
       
   268 ==== <tt>!AddPoint(x, y [, width [, erase] ])</tt> ====
       
   269 This function is used to draw your own maps using Lua. The maps drawn with this are of type “hand-drawn”.
       
   270 
       
   271 The function takes a `x`,`y` location, a `width` (means start of a new line) and `erase` (if `false`, this function will draw normally, if `true`, this function will erase drawn stuff).
       
   272 
       
   273 This function must be called within `onGameInit`, where `MapGen` has been set to `mgDrawn`. You also should call `FlushPoints` when you are finished with drawing.
       
   274 
       
   275 See [LuaDrawning] for some examples.
       
   276 
       
   277 ==== <tt>!FlushPoints()</tt> ====
       
   278 Makes sure that all the points/lines specified using `AddPoint` are actually applied to the map. This function must be called within `onGameInit`.
       
   279 
       
   280 === Current hedgehog ===
       
   281 
       
   282 ==== <tt>!GetCurAmmoType()</tt> ====
       
   283 Returns the currently selected [AmmoTypes Ammo Type].
       
   284 
       
   285 ==== <tt>!SwitchHog(gearUid)</tt> ====
       
   286 This function will switch to the hedgehog with the specifiedd `gearUid`.
       
   287 
       
   288 ==== <tt>!SetWeapon(ammoType)</tt> ====
       
   289 Sets the selected weapon of `CurrentHedgehog` to one of the [AmmoTypes Ammo Type].
       
   290 
       
   291 Examples:
       
   292 
       
   293 <code language="lua">
       
   294   SetWeapon(amBazooka) -- select the bazooka (if hog has one)
       
   295 </code>
       
   296 <code language="lua">
       
   297   SetWeapon(amNothing) -- unselects the weapon.
       
   298 </code>
       
   299 
       
   300 ==== <tt>!SetNextWeapon()</tt> ====
       
   301 This function makes the current hedgehog switch to the next weapon in list of available weapons. It can be used for example in trainings to pre-select a weapon.
       
   302 
       
   303 ==== <tt>!SetInputMask(mask)</tt> ====
       
   304 Masks specified player input. This means that Hedgewars ignores certain player inputs, such as walking or jumping.
       
   305 
       
   306 Example: 
       
   307 <code language="lua">    -- masks the long and high jump commands
       
   308 SetInputMask(band(0xFFFFFFFF, bnot(gmLJump + gmHJump))) 
       
   309     -- clears input mask, allowing player to take actions
       
   310     SetInputMask(0xFFFFFFFF) 
       
   311 		</code>
       
   312 *Note*: Using the input mask is an effective way to script uninterrupted cinematics, or create modes such as No Jumping.
       
   313 
       
   314 *Note*: This function is used internally in the Animate [LuaLibraries library].
       
   315 
       
   316 See also [GearMessages].
       
   317 
       
   318 ==== <tt>!GetInputMask()</tt> ====
       
   319 Returns the current input mask of the player.
       
   320 
       
   321 ==== <tt>!SetVampiric(bool)</tt> (0.9.24) ====
       
   322 Toggles vampirism mode for this turn. Set `bool` to `true` to enable (same effect as if the hedgehog has used Vampirism), `false` to disable.
       
   323 
       
   324 ==== <tt>!GetVampiric()</tt> (0.9.25) ====
       
   325 Returns true if vampirism mode is currently active.
       
   326 
       
   327 ==== <tt>!SetLaserSight(bool)</tt> (0.9.24) ====
       
   328 Toggles laser sight for this turn. Set `bool` to `true` to enable (same effect as if the hedgehog has used Laser Sight), `false` to disable.
       
   329 
       
   330 ==== <tt>!GetLaserSight()</tt> (0.9.25) ====
       
   331 Returns true if laser sight (as utility) is currently active. The sniper rifle's built-in laser sight does not count.
       
   332 
       
   333 ==== <tt>!EnableSwitchHog()</tt> (0.9.25) ====
       
   334 Enable hog switching mode for the current hedgehog. This function should be called while the hedgehog is standing on solid ground (`GetFlightTime` returns 0).
       
   335 
       
   336 Internally, this tries to spawn a `gtSwitcher` gear which, as long it exists, handles the hog switching. You can delete this gear to stop the hog switching prematurely. If there already is a `gtSwitcher` gear, no additional gear is spawned.
       
   337 
       
   338 On success, returns the `gtSwitcher` gear being spawned or, if hog switching mode is already active, returns the exsting gear. On failure, returns `nil`.
       
   339 
       
   340 === Randomness ===
       
   341 ==== <tt>!GetRandom(number)</tt> ====
       
   342 Returns a randomly generated number in the range of 0 to number - 1. This random number uses the game seed, so is synchronised, and thus safe for multiplayer and saved games. Use `GetRandom` for anything that could impact the engine state. For example, a visual gear could simply use Lua’s `math.random`, but adding a regular gear should use `GetRandom`.
       
   343 
       
   344 === Clans and teams ===
       
   345 ==== <tt>!AddTeam(teamname, color, grave, fort, voicepack, flag)</tt> ====
       
   346 
       
   347 Adds a new team.
       
   348 
       
   349 You *must* call it only in `onGameInit`.
       
   350 You *must* add at least one hedgehog with `AddHog` after calling this. The engine does not support empty teams.
       
   351 `AddTeam` is only supported for singleplayer missions. You *must not* call this function in multiplayer.
       
   352 
       
   353 Arguments:
       
   354 
       
   355  * `teamname`: The name of the team.
       
   356  * `color`: Team color, usually a number from -9 to -1 (see below)
       
   357  * `grave`: The name of the team’s grave (equals file name without the suffix)
       
   358  * `fort`: The name of the team’s fort (equals file name without the suffix and without the letter “L” or “R” before that suffix)
       
   359  * `voicepack`: The name of the team’s voice pack (equals the directory name)
       
   360  * `flag`: Optional argument for the name of the team’s flag (equals file name without the suffix). If set to `nil`, the flag “hedgewars” is used.
       
   361 
       
   362 ===== Clan color =====
       
   363 Each team must have a color. The color also determines clan membership: Teams with equal color are in the same clan.
       
   364 
       
   365 The team color is specified as a number from -9 to -1. This will select one of the 9 possible team colors as specified in the player's settings. As the actual colors are set by the player, you can't predict them, but you can usually trust these defaults:
       
   366 
       
   367  * `-1`: red
       
   368  * `-2`: blue
       
   369  * `-3`: cyan
       
   370  * `-4`: purple
       
   371  * `-5`: magenta
       
   372  * `-6`: green
       
   373  * `-7`: orange
       
   374  * `-8`: brown
       
   375  * `-9`: yellow
       
   376 
       
   377 An older (and now discouraged) method of specifying the color is by hardcoding it as an RGB color (i.e. `0xDD0000`). This practice is now strongly discouraged because it will ignore the player-chosen color (which is *bad* for players with color blindness) and in 99% of cases you don't need it anyway. It should be only used for testing and debugging. 
       
   378 
       
   379 ===== Example =====
       
   380 
       
   381 <code language="lua">AddTeam("team 1", -1, "Simple", "Tank", "Default", "hedgewars")
       
   382 --[[ Adds a new team with name “team 1”, the first default color (usually red), the grave “Simple”,
       
   383 the fort “Tank” the voicepack “Default” and the flag “hedgewars”. ]]</code>
       
   384 
       
   385 ==== <tt>!AddMissionTeam(color)</tt> (0.9.25) ====
       
   386 Adds a new team using the player-chosen team identity when playing a singleplayer mission. Does not work in multiplayer.
       
   387 
       
   388 This function is very similar to `AddTeam`. Team settings like team name and flag will be taken from the player-chosen team.
       
   389 You only need to specify the clan color, which has the same meaning as in `AddTeam`.
       
   390 
       
   391 Use `AddMissionHog` or `AddHog` afterwards to add hedgehogs for this team. You can mix `AddMissionHog` and `AddHog` as you wish.
       
   392 
       
   393 Example:
       
   394 <code language="lua">-- Add mission team with default clan color
       
   395 AddMissionTeam(-1)</code>
       
   396 
       
   397 ==== <tt>!GetTeamName(teamIdx)</tt> (0.9.24) ====
       
   398 Returns the name of the team with the index `teamIdx`. `teamIdx` is a number between 0 and `TeamsCount-1`.
       
   399 
       
   400 ==== <tt>!GetTeamIndex(teamname)</tt> (0.9.24) ====
       
   401 Returns the team index (number between 0 and `TeamsCount-1`) of the team with the name `teamName`.
       
   402 
       
   403 ==== <tt>!GetTeamClan(teamname)</tt> (0.9.24) ====
       
   404 Returns the clan ID of the team with the given `teamName`.
       
   405 
       
   406 ==== <tt>!DismissTeam(teamname)</tt> ====
       
   407 Vaporizes all the hogs of the team with the given team name in a puff of smoke.
       
   408 
       
   409 This function must not be called while it's the team's turn.
       
   410 
       
   411 ==== <tt>!SetTeamLabel(teamname[, label])</tt> (0.9.24) ====
       
   412 Set or remove a label for the team with the given team name. The label is a string and will be displayed next to the team's health bar.
       
   413 
       
   414 If `label` is `nil`, the label will be removed.
       
   415 
       
   416 There's a special case: If the AI Survival game modifier is active, the AI kill counter will be replaced by the custom team label if it has been set. If `label` is set to `nil`, the default AI counter is shown again.
       
   417 
       
   418 Use this to display a score, power value or another important team attribute. There's no hard length limit, but please try to keep it as short as possible to avoid visual clutter.
       
   419 
       
   420 === <tt>SetTeamPassive(teamname, isPassive)</tt> (1.0.0) ===
       
   421 Mark a team as passive if `isPassive` is `true`. Passive teams do not participate in the game and are treated like frozen teams. When determining the team order, passive teams are completely ignored.
       
   422 
       
   423 ==== <tt>!GetClanColor(clan)</tt> ====
       
   424 Returns the RGBA color of the chosen clan by its number. The color data type is described in [LuaOverview#Color].
       
   425 
       
   426 ==== <tt>!SetClanColor(clan, color)</tt> ====
       
   427 Sets the RGBA color of the chosen clan by its number. The color data type is described in [LuaOverview#Color]. The new clan color *must* be different from the color of all clans (you can't use this function to change clan memberships of teams).
       
   428 
       
   429 Note: The stats graph does not support changing clan colors. If the clan colors change in mid-game, the graph might get confused and shows weird stuff. You may want to turn off the graph with if this is the case (see `SendHealthStatsOff`).
       
   430 
       
   431 === Campaign management ===
       
   432 ==== <tt>!SaveCampaignVar(varname, value)</tt> ====
       
   433 Stores the value `value` (a string) into the campaign variable `varname` (also a string). Campaign variables allow you to save progress of a team in a certain campaign. Campaign variables are saved on a per-team per-campaign basis. They are written into the team file (see [ConfigurationFiles#TeamName.hwt]).
       
   434 
       
   435 There are some special campaign variables which are used by Hedgewars to determine which missions to display in the campaign menu. This is described [ConfigurationFiles#%5BCampaign%20%3CCAMPAIGN_NAME%3E%5D here].
       
   436 
       
   437 ==== <tt>!GetCampaignVar(varname)</tt> ====
       
   438 Returns the value of the campaign variable `varname` as a string. See also `SaveCampaignVar`.
       
   439 
       
   440 ==== <tt>!SaveMissionVar(varname, value)</tt> (0.9.25) ====
       
   441 Stores the value `value` (a string) into the mission variable `varname` (also a string). A mission variable is like a campaign variable, but it applies for singleplayer missions only (Training/Challenge/Scenario), excluding campaign missions.
       
   442 
       
   443 ==== <tt>!GetMissionVar(varname)</tt> (0.9.25) ====
       
   444 Returns the value of the mission variable `varname` as a string. See also `SaveMissionVar`.
       
   445 
       
   446