Sandbox.wiki
changeset 1815 1b39b4fa2e7d
parent 1791 2494d0337156
child 1836 3cbc50296c30
equal deleted inserted replaced
1814:e6e9ed9d2626 1815:1b39b4fa2e7d
     1 #summary List of gear-related functions in the Lua API
     1 #summary Sandbox for testing wiki stuff
     2 
     2 
     3 = Lua API: Gear functions =
     3 Test your wiki stuff here! Feel free to edit!
     4 This is a list of all functions in the [LuaAPI Lua API] that are related to gears and visual gears.
       
     5 
       
     6 Gears are dynamic objects or events in the world that affect the gameplay, including hedgehogs, projectiles, weapons, land objects, active utilities and a few more esoteric things. Visual gears are decorational objects which are usually used for purely decorational graphical effects. They have no effect on gameplay. Visual gears are not the same as gears, but they share some similarities.
       
     7 
       
     8 Refer to [LuaGuide] for a more detailed introduction into gears.
       
     9 
       
    10 <wiki:toc max_depth="3"/>
       
    11 
       
    12 == Creation ==
       
    13 
       
    14 === `AddGear(x, y, gearType, state, dx, dy, timer)` ===
       
    15 This creates a new gear at position x,y (measured from top left) of kind `gearType` (see [GearTypes Gear Types]).
       
    16 The initial velocities are `dx` and `dy`. All arguments are numbers. The function returns the `uid` of the gear created. Gears can have multple states at once: `state` is a bitmask, the flag variables can be found in [States]. `timer` is the initial timer value of the gear. If a particular gear value does not matter, use `0`.
       
    17 
       
    18 Position, velocity, state and timer can be changed afterwards with the various setter functions.
       
    19 
       
    20 Note: If you want to create a hedgehog (`gtHedgehog`), you must call `AddHog` or `AddMissionHog` instead. If you want to spawn a crate (`gtCase`), you must call one of the several “Spawn*Crate” functions (e.g. `SpawnSupplyCrate`) below instead.
       
    21 
       
    22 Example:
       
    23 
       
    24 <code language="lua">    -- Spawn a target at (0,0) and place it randomly
       
    25     local gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0) -- also use 0 for velocity. Also 0 for state and timer because they don't matter.
       
    26     FindPlace(gear, true, 0, LAND_WIDTH)</code>
       
    27 
       
    28 === `AddVisualGear(x, y, visualGearType, state, critical [, layer])` ===
       
    29 This attempts to create a new visual gear at position x,y (measured from top left) of kind `visualGearType` (see [VisualGearTypes Visual Gear Types]).
       
    30 
       
    31 The function returns the `uid` of the visual gear created or `nil` if creation failed.  There is no guarantee that a visual gear will spawn.  *IMPORTANT: Do not rely on visual gears to spawn*. *Always* be prepared for this function to return `nil`.
       
    32 
       
    33 Set `critical` to `true` if the visual gear is crucial to gameplay and must always be spawned when in-game.  Use `false` if it is just an effect or eye-candy, and its creation can be skipped when in fast-forward mode (such as when joining a room).
       
    34 
       
    35 You can set an optional `layer` to specify which visual gears get drawn on top.
       
    36 
       
    37 Most visual gears delete themselves eventually.
       
    38 
       
    39 *NOTE:* Visual gears *must* only be used for decorational/informational/rendering purposes. *Never* use the visual gear's internal state to manipulate anything gameplay-related. Visual gears are not safe for reliable storage and using them as that would lead to strange bugs.
       
    40 
       
    41 *NOTE:* Since 0.9.25, visual gears will never spawn when Hedgewars is run in a testing mode (i.e. not as the real game), so don't rely for visual gears to spawn even if they're critical.
       
    42 
       
    43 Example:
       
    44 
       
    45 <code language="lua">  -- adds an non-critical explosion at position 1000,1000. Returns 0 if it was not created.
       
    46     local vgear = AddVisualGear(1000, 1000, vgtExplosion, 0, false) 
       
    47 </code>
       
    48 
       
    49 === `AddHog(hogname, botlevel, health, hat)` ===
       
    50 Adds a new hedgehog for current team (last created one with the `AddTeam` function), with a bot level, an initial health and a hat.
       
    51 
       
    52 `botlevel` ranges from `0` to `5`, where `0` denotes a human player and `1` to `5` denote the skill level of a bot, where `1` is strongest and `5` is the weakest. Note that this is the reverse order of how the bot level is displayed in the game. Note that mixing human-controlled and computer-controlled hedgehogs in the same team is not permitted, but it is permitted to use different computer difficulty levels in the same team.
       
    53 
       
    54 Returns the gear ID.
       
    55 
       
    56 *Warning*: This only works in singleplayer mode (e.g. missions). Also, Hedgewars only supports up to 64 hedgehogs in a game.
       
    57 
       
    58 Example:
       
    59 
       
    60 <code language="lua">    local player = AddHog("HH 1", 0, 100, "NoHat") -- botlevel 0 means human player
       
    61     SetGearPosition(player, 1500, 1000)
       
    62     -- hint: If you don't call `SetGearPosition`, the hog spawns randomly</code>
       
    63 
       
    64 === `AddMissionHog(health)` (0.9.25) ===
       
    65 Add a hedgehog for the current team, using the player-chosen team identity when playing in singleplayer missions. The “current team” is the last team that was added with `AddMissionTeam` or `AddTeam`.
       
    66 
       
    67 The name and hat match the player's team definition. The hog is also always player-controlled.
       
    68 
       
    69 Examples:
       
    70 <code language="lua">-- Add player team with 3 hogs
       
    71 AddMissionTeam(-1)
       
    72 AddMissionHog(100)
       
    73 AddMissionHog(100)
       
    74 AddMissionHog(100)</code>
       
    75 
       
    76 <code language="lua">-- You can also mix mission hogs with “hardcoded” hogs.
       
    77 -- This adds a player team with 2 hogs taken from the player team and 1 hog with a hardcoded name, botlevel and hat.
       
    78 AddMissionTeam(-2)
       
    79 AddMissionHog(100)
       
    80 AddMissionHog(100)
       
    81 AddHog("My Hardcoded Hog", 0, 100, "NoHat")
       
    82 </code>
       
    83 
       
    84 === `SpawnHealthCrate(x, y, [, health])` ===
       
    85 Spawns a health crate at the specified position. If `x` and `y` are set to 0, the crate will spawn on a random position (but always on land). Set `health` for the initial health contained in the health crate. If not set, the default health (`HealthCaseAmount`) is used. Do not use a negative value for `health`.
       
    86 
       
    87 === `SpawnSupplyCrate(x, y, ammoType [, amount])` (0.9.24) ===
       
    88 Spawns an ammo or utility crate at the specified position with the given ammo type and an optional amount (default: 1). The crate type is chosen automatically based on the ammo type.
       
    89 Otherwise, this function behaves like `SpawnAmmoCrate`.
       
    90 
       
    91 === `SpawnAmmoCrate(x, y, ammoType [, amount])` ===
       
    92 Spawns an ammo crate at the specified position with content of `ammoType` (see [AmmoTypes Ammo Types]). Any `ammoType` is permitted, an ammo crate is spawned even if the ammo is normally defined as an utility.
       
    93 If `ammoType` is set to `amNothing`, a random weapon (out of the available weapons from the weapon scheme) will be selected. If `x` and `y` are set to 0, the crate will spawn on a random position (but always on land). The `amount` parameter specifies the amount of ammo contained in the crate. If `amount` is `nil` or `0`, the value set by `SetAmmo` is used, or if `SetAmmo` has not been used, it falls back to the weapon scheme's value. If `amount` is equal to or greater than `AMMO_INFINITE`, the amount is infinite.
       
    94 
       
    95 Note that in Lua missions, the default number of ammo in crates is 0, so it has to be set to at least 1 with `SetAmmo` first, see the example:
       
    96 
       
    97 Example:
       
    98 
       
    99 <code language="lua">    SetAmmo(amGrenade, 0, 0, 0, 1) -- grenade ammo crates now contain 1 grenade each
       
   100     SpawnAmmoCrate(0, 0, amGrenade) -- spawn grenade ammo crate at random position</code>
       
   101 
       
   102 === `SpawnUtilityCrate(x, y, ammoType [, amount])` ===
       
   103 Spawns an utility crate with some ammo at the specified position. The function behaves almost like `SpawnAmmoCrate`, the differences are 1) the crate looks different and 2) if `ammoType` is set to `amNothing`, a random utility out of the set of available utilities from the weapon scheme is chosen as content.
       
   104 
       
   105 Example:
       
   106 
       
   107 <code language="lua">    SetAmmo(amLaserSight, 0, 0, 0, 1)
       
   108     SpawnUtilityCrate(0, 0, amLaserSight)</code>
       
   109 
       
   110 === `SpawnFakeAmmoCrate(x, y, explode, poison) ` ===
       
   111 Spawns a crate at the specified coordinates which looks exactly like a real ammo crate but contains not any ammo. It can be use useful for scripted events or to create a trap. If `x` and `y` are set to 0, the crate will spawn on a random position (but always on land).
       
   112 `explode` and `poison` are booleans.
       
   113 If `explode` is `true`, the crate will explode when collected.
       
   114 If `poison` is `true`, the collector will be poisoned.
       
   115 
       
   116 Example:
       
   117 
       
   118 <code language="lua">SpawnFakeAmmoCrate(500, 432, false, false) -- Spawns a fake ammo crate at the coordinates (500, 434) without explosion and poison.
       
   119 </code>
       
   120 
       
   121 === `SpawnFakeHealthCrate(x, y, explode, poison) ` ===
       
   122 Same as `SpawnFakeAmmoCrate`, except the crate will look like a health crate.
       
   123 
       
   124 === `SpawnFakeUtilityCrate(x, y, explode, poison) ` ===
       
   125 Same as `SpawnFakeAmmoCrate`, except the crate will look like an utility crate.
       
   126 
       
   127 == Position and velocity ==
       
   128 === `GetGearPosition(gearUid)` ===
       
   129 Returns x,y coordinates for the specified gear. Not to be confused with `GetGearPos`.
       
   130 
       
   131 === `GetX(gearUid)` ===
       
   132 Returns x coordinate of the gear.
       
   133 
       
   134 === `GetY(gearUid)` ===
       
   135 Returns y coordinate of the gear.
       
   136 
       
   137 === `SetGearPosition(gearUid, x, y)` ===
       
   138 Places the specified gear exactly at the position (`x`,`y`). Not to be confused with `SetGearPos`.
       
   139 
       
   140 === `GetGearVelocity(gearUid)` ===
       
   141 Returns a tuple of dx,dy values for the specified gear.
       
   142 
       
   143 === `SetGearVelocity(gearUid, dx, dy)` ===
       
   144 Gives the specified gear the velocity of `dx`, `dy`.
       
   145 
       
   146 === `CopyPV(gearUid, gearUid)` ===
       
   147 This sets the position and velocity of the second gear to the first one.
       
   148 
       
   149 === `FindPlace(gearUid, fall, left, right[, tryHarder])` ===
       
   150 Finds a place for the specified gear between x=`left` and x=`right` and places it there. `tryHarder` is optional, setting it to `true`/`false` will determine whether the engine attempts to make additional passes, even attempting to place gears on top of each other.
       
   151 
       
   152 Example:
       
   153 
       
   154 <code language="lua">    gear = AddGear(...)
       
   155     FindPlace(gear, true, 0, LAND_WIDTH) -- places the gear randomly between 0 and LAND_WIDTH</code>
       
   156 
       
   157 == General gear properties ==
       
   158 
       
   159 === `GetGearType(gearUid)` ===
       
   160 This function returns the [GearTypes gear type] for the specified gear, if it exists.  If it doesn't exist, `nil` is returned.
       
   161 
       
   162 === `GetVisualGearType(vgUid)` (0.9.23) ===
       
   163 This function returns the [VisualGearTypes visual gear type] for the specified visual gear, if it exists.  If it doesn't exist, `nil` is returned.
       
   164 
       
   165 === `GetState(gearUid)` ===
       
   166 Returns the state of the gear. The gear state is a bitmask which is built out of the variables as shown in [States].
       
   167 
       
   168 This function is usually used in combination with `band` to extract the truth value of a single flag. It is also used together with `SetState` and `bor` in order to activate a single flag.
       
   169 
       
   170 Examples:
       
   171 <code language="lua">
       
   172 local state = GetState(gear)
       
   173 --[[ Stores the full raw bitmask of gear in state. Usually
       
   174 useless on its own. ]]
       
   175 </code>
       
   176 
       
   177 <code language="lua">
       
   178 isDrowning = band(GetState(CurrentHedgehog),gstDrowning) ~= 0
       
   179 --[[ GetState(CurrentHedgehog) returns the state bitmask of
       
   180 CurrentHedgehog, gstDrowning is a bitmask where only the
       
   181 “drowning” bit is set. band does a bitwise AND on both, if
       
   182 it returns a non-zero value, the hedgehog is drowning.]]
       
   183 </code>
       
   184 
       
   185 <code language="lua">
       
   186 SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstInvisible))
       
   187 --[[ first the state bitmask of CurrentHedgehog is bitwise ORed with
       
   188 the gstInvisible flag, thus making the bit responsible for
       
   189 invisiblity to become 1. Then the new bitmask is applied to
       
   190 CurrentHedgehog, thus making it invisible.]]
       
   191 </code>
       
   192 
       
   193 === `SetState(gearUid, state)` ===
       
   194 Sets the state of the specified gear to the specified `state`. This is a bitmask made out of the variables as seen in [States].
       
   195 
       
   196 This function is often used together with `GetState` and the bitmask utility functions `band` and `bnot` in order to manipulate a single flag.
       
   197 
       
   198 Examples:
       
   199 <code language="lua">
       
   200 SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstInvisible))
       
   201 --[[ first the state bitmask of CurrentHedgehog is bitwise ORed with
       
   202 the gstInvisible flag, thus making the bit responsible for
       
   203 invisiblity to become 1. Then the new bitmask is applied to
       
   204 CurrentHedgehog, thus making it invisible. ]]
       
   205 </code>
       
   206 
       
   207 <code language="lua">
       
   208 SetState(CurrentHedgehog, band(GetState(CurrentHedgehog), bnot(gstInvisible)))
       
   209 --[[ The reverse of the above: This function toggles CurrentHedgehog’s
       
   210 gstInvisible flag off, thus making it visible again. ]]
       
   211 </code>
       
   212 
       
   213 
       
   214 === `GetGearMessage(gearUid)` ===
       
   215 Returns the message of the gear. This is a bitmask built out of flags seen in [GearMessages].
       
   216 
       
   217 === `SetGearMessage(gearUid, message)` ===
       
   218 Sets the gear messages of the specified gear. `message` is a bitmask built out of flags seen in [GearMessages].
       
   219 
       
   220 === `GetTag(gearUid)` ===
       
   221 Returns the tag of the specified gear (by `gearUid`). 
       
   222 
       
   223 The `Tag` of a gear is just another arbitrary variable to hold the gear's state. The meaning of a tag depends on the gear type. For example, for `gtBall` gears, it specifies the ball color, for `gtAirAttack` gears (airplane) it specifies the direction of the plane, etc. See [GearTypes] for a full list. The returned value will be an integer.
       
   224 
       
   225 Note that the word “tag” here does _not_ refer to the name and health tags you see above hedgehogs, this is something different. 
       
   226 
       
   227 <code language="lua">
       
   228 -- This adds a ball (the one from the ballgun) at (123, 456):
       
   229 ball = AddGear(123, 456, gtBall, 0, 0, 0, 0)
       
   230 -- The tag of a ball defines its color. It will automatically chosen at random when created.
       
   231 colorTag = GetTag(ball)
       
   232 -- Now colorTag stores the tag of ball (in this case a number denoting its color)
       
   233 </code>
       
   234 
       
   235 The meaning of tags are described in [GearTypes].
       
   236 
       
   237 === `SetTag(gearUid, tag)` ===
       
   238 Sets the `Tag` value of the specified gear (by `gearUid`). The `Tag` value of a gear is simply an extra variable to modify misc. things. The meaning of a tag depends on the gear type. For example, for `gtBall` gears, it specifies the ball color, for `gtAirAttack` gears (airplane) it specifies the direction of the plane, etc. See [GearTypes] for a full list. `tag` has to be an integer.
       
   239 
       
   240 Note that the word “tag” here does _not_ refer to the name and health tags you see above hedgehogs, this is something different. 
       
   241 
       
   242 <code language="lua">
       
   243 -- This adds a ball (the one from the ballgun) at (123, 456):
       
   244 ball = AddGear(123, 456, gtBall, 0, 0, 0, 0)
       
   245 -- This sets the tag of the gear. For gtBall, the tag specified the color. “8” is the color white.
       
   246 SetTag(ball, 8) -- 
       
   247 </code>
       
   248 
       
   249 The meaning of tags are described in [GearTypes].
       
   250 
       
   251 === `GetTimer(gearUid)` ===
       
   252 Returns the timer of the gear. This is for example the time it takes for watermelon, mine, etc. to explode. This is also the time used to specify the blowtorch or RC plane time. See [GearTypes] for a full list.
       
   253 
       
   254 === `SetTimer(gearUid, timer)` ===
       
   255 Sets the timer of the specified gear. Also see `GetTimer`.
       
   256 
       
   257 === `GetHealth(gearUid)` ===
       
   258 Returns the health of the gear. Depending on the gear type, the gear's “health” can also refer to other things, see [GearTypes] for a full list.
       
   259 
       
   260 === `SetHealth(gearUid, health)` ===
       
   261 Sets the health of the specified gear. The “health” of a gear can refer to many things, depending on the gear type.
       
   262 
       
   263 *Hint*: If you like to increase the health of a hedgehog with nice visual effects, consider using `HealHog` instead.
       
   264 
       
   265 Use cases:
       
   266 
       
   267   * Setting the health of a hedgehog (`gtHedgehog`) to 99
       
   268   * Starting the RC Plane (`gtRCPlane`) with 10 bombs
       
   269   * Starting flying saucer (`gtJetpack`) with only 50% fuel
       
   270   * Setting all the mines (`gtMine`) to duds
       
   271   * And more!
       
   272 
       
   273 See [GearTypes] for a full description.
       
   274 
       
   275 <code language="lua">    function onGearAdd(gear)
       
   276        if (GetGearType(gear) == gtHedgehog) then
       
   277             -- Set hedgehog health to 99
       
   278             SetHealth(gear, 99)
       
   279        end
       
   280        if (GetGearType(gear) == gtRCPlaane) then
       
   281             -- Give the plane 10 bombs
       
   282             SetHealth(gear, 10)
       
   283        end
       
   284        if (GetGearType(gear) == gtJetpack) then
       
   285             -- Set fuel to 50% only
       
   286             SetHealth(gear, 1000)
       
   287        end
       
   288        if (GetGearType(gear) == gtMine) then
       
   289             -- Turn mine into dud
       
   290             SetHealth(gear, 0)
       
   291        end
       
   292     end</code>
       
   293 
       
   294 
       
   295 === `GetGearPos(gearUid)` ===
       
   296 Get the `Pos` value of the specified gear. `Pos` is just another arbitrary value to hold the state of the gear, such as `Tag` and `Health`, the meaning depends on the gear type. See [GearTypes] for the conrete meaning of a gear's `Pos` value. 
       
   297 
       
   298 *Important*: Pos is *not* related to the gear's position, use `GetGearPosition` for that.
       
   299 
       
   300 === `SetGearPos(gearUid, value)` ===
       
   301 Sets the `Pos` value (not the position!) of the specified gear to specified value. See `GetGearPos` for more information.
       
   302 
       
   303 === `GetGearCollisionMask(gearUid)` ===
       
   304 Returns the current collision mask of the given gear. See `SetGearCollisionMask` for an explanation of the mask.
       
   305 
       
   306 === `SetGearCollisionMask(gearUid, mask)` ===
       
   307 Set the collision mask of the given gear with `gearUid`.
       
   308 The collision mask defines with which gears and terrain types the gear can collide.
       
   309 
       
   310 `mask` is a number between `0x0000` and `0xFFFF` and used as a bitfield, which means you can combine these flags with `bor`. These are the available flags:
       
   311 
       
   312 || *Identifier* || *Collision with …* ||
       
   313 || `lfLandMask` || Terrain ||
       
   314 || `lfCurHogCrate` || Current hedgehog, and crates ||
       
   315 || `lfHHMask` || Any hedgehogs ||
       
   316 || `lfNotHHObjMask` || Objects, not hogs (e.g. mines, explosives) ||
       
   317 || `lfAllObjMask` || Hedgehogs and objects ||
       
   318 
       
   319 Beware, the collision mask is often set by the engine as well.
       
   320 
       
   321 Examples:
       
   322 <code language="lua">SetGearCollisionMask(gear, bnot(lfCurHogCrate))
       
   323 -- Ignore collision with current hedgehog</code>
       
   324 
       
   325 <code language="lua">SetGearCollisionMask(gear, 0xFFFF)
       
   326 -- Collide with everything</code>
       
   327 
       
   328 <code language="lua">SetGearCollisionMask(gear, lfAllObjMask)
       
   329 -- Collide with hedgehogs and objects</code>
       
   330 
       
   331 <code language="lua">SetGearCollisionMask(gear, 0x0000)
       
   332 -- Collide with nothing</code>
       
   333 
       
   334 There are actual more flags availbable, but they are not as useful for use in Lua and their constants have not been exposed to Lua. You can find the full range of flags in the engine source code (in Pascal):
       
   335 
       
   336 [https://hg.hedgewars.org/hedgewars/file/default/hedgewars/uConsts.pas#l112]
       
   337 
       
   338 === `GetGearRadius(gearUid)` ===
       
   339 Returns the `Radius` value for the specified gear. For most [GearTypes gear types] for “projectile” gears (like `gtShell` or `gtGrenade`), the radius refers to the gear's collision radius. This is an invisible circle around the center of the gear which is used for the collision checks. For a few gear types, its radius means something different, see [GearTypes] for a full list.
       
   340 
       
   341 To set the `Radius` value, use `SetGearValues`.
       
   342 
       
   343 === `GetFlightTime(gearUid)` ===
       
   344 Returns the `FlightTime` of the specified gear. The `FlightTime` is a gear varialbe used to store a general time interval. The precise meaning of the `FlightTime` depends on the gear type.
       
   345 
       
   346 For example: The `FlightTime` of a hedgehog (`gtHedgehog`) is the time since they last have stood on solid ground. For most projectile gear types (i.e. `gtShell`), it stores the time after it has been launched.
       
   347 
       
   348 === `SetFlightTime(gearUid, flighttime)` ===
       
   349 Sets the `FlightTime` of the given gear to `flighttime`. The meaning of `FlightTime` is explained in the section `GetFlightTime`.
       
   350 
       
   351 === `GetGearElasticity(gearUid) ` ===
       
   352 Returns the elasticity of the specified gear. The elasticity normally determines how strong the gear will bounce after collisions, where higher elasticity is for stronger bounces.
       
   353 
       
   354 This is also useful for determining if a hog is on a rope or not. If a hog is attached to a rope, or is busy firing one, the elasticity of the rope will be a non-zero number.
       
   355 
       
   356 === `SetGearElasticity(gearUid, Elasticity) ` ===
       
   357 Sets the elasticity of the specified gear. For most gears, the elasticity determines how strong the gear will bounce after collisions, where higher elasticity is for stronger bounces. Recommended are values between `0` and `9999`.
       
   358 
       
   359 === `GetGearFriction(gearUid) ` ===
       
   360 Returns the friction of the specified gear. The friction normally determines how well the gear will slide on terrain. Higher values are for increased sliding properties.
       
   361 
       
   362 === `SetGearFriction(gearUid, Friction) ` ===
       
   363 Sets the friction of the specified gear. The friction normally determines how well the gear will slide on terrain. Higher values are for increased sliding properties. `0` is for no sliding whatsoever, where `9999` is for very long slides, greater values are not recommended.
       
   364 
       
   365 === `GetGearTarget(gearUid, x, y) ` ===
       
   366 Returns the x and y coordinate of target-based weapons/utilities. 
       
   367 <b>Note:</b>: This can’t be used in `onGearAdd()` but must be called after gear creation. 
       
   368 
       
   369 === `SetGearTarget(gearUid, x, y)` ===
       
   370 Sets the x and y coordinate of target-based weapons/utilities.
       
   371 *Note*: This can’t be used in onGearAdd() but must be called after gear creation.
       
   372 
       
   373 === `GetGearValues(gearUid)` ===
       
   374 This returns a bunch of values associated with the gear, their meaning is often depending on the gear type and many values might be unused for certain gear types.
       
   375 
       
   376 This is returned (all variables are integers):
       
   377 
       
   378 `Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, nImpactSounds, Tint, Damage, Boom`
       
   379 
       
   380 A rough description of some of the parameters:
       
   381 
       
   382  * `Radius`: Effect or collision radius, most of the time
       
   383  * `ImpactSound`: Sound it makes on a collision (see [Sounds])
       
   384  * `Tint`: Used by some gear types to determine its colorization. The color is in RGBA format.
       
   385  * `Boom`: Used by most gears to determine the damage dealt.
       
   386 
       
   387 Example:
       
   388 <code language="lua">
       
   389 -- Get all values in a single line of code:
       
   390 local Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, nImpactSounds, Tint, Damage, Boom, Scale = GetGearValues(myGear)
       
   391 </code>
       
   392 
       
   393 === `SetGearValues(gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, ImpactSounds, Tint, Damage, Boom)` ===
       
   394 Sets various gear value for the specified gear (`gearUid`). The meaining of each value often depends on the gear type. See the documentation on !GetGearValues for a brief description of the gear values. If `gearUid` is invalid or the gear does not exist, nothing happens.
       
   395 
       
   396 Set `nil` for each value you do not want to change.
       
   397 
       
   398 Example:
       
   399 <code language="lua">
       
   400 -- Paints all RC planes into a white color
       
   401 function onGearAdd(gear)
       
   402     if GetGearType(gear) == gtRCPlane then
       
   403          SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xFFFFFFFF)
       
   404     end
       
   405 end
       
   406 </code>
       
   407 
       
   408 === `GetVisualGearValues(vgUid)` ===
       
   409 This returns the typically set visual gear values for the specified visual gear `vgUid`, useful if manipulating things like smoke, bubbles or circles. On success, it returns the following values:
       
   410 
       
   411 `X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint, Scale`
       
   412 
       
   413 The meaning of these values is the same as in `SetVisualGearValues`.
       
   414 
       
   415 If the visual gear does not exist, `nil` is returned. Always check the result for `nil` before you plug in the values anywhere.
       
   416 
       
   417 Most visual gears require little to no modification of parameters.
       
   418 
       
   419 Example:
       
   420 
       
   421 <code language="lua">-- Return visual gear values
       
   422 local X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint, Scale = GetVisualGearValues(vgUid)
       
   423 </code>
       
   424 
       
   425 === `SetVisualGearValues(vgUid, X, Y, dX, dY, Angle, Frame, !FrameTicks, State, Timer, Tint, Scale)` ===
       
   426 This allows manipulation of the internal state of the visual gear `vgUid`. If `vgUid` is invalid or the `vgUid` does not refer to an existing visual gear, the function does nothing. Thus, you can safely call this function even if you are not sure if the visual gear actually exists.
       
   427 
       
   428 All visual gear values are numbers. Each visual gear may be using these parameters differently, but the *usual* meaning of these is the following:
       
   429 
       
   430  * `X`, `Y`: Position
       
   431  * `dX`, `dY`: Speed along the X and Y axis
       
   432  * `Angle`: Current rotation
       
   433  * `Frame`: Image frame, if using a sprite sheet
       
   434  * `FrameTicks` is usually an animation counter
       
   435  * `State`: Helper value to save some internal state
       
   436  * `Timer`: Time in milliseconds until it expires
       
   437  * `Tint`: RGBA color
       
   438  * `Scale` is a scale factor (not used by all visual gears)
       
   439 
       
   440 Some visual gears interpret these values differently, just like normal gears. See [VisualGearTypes] for details.  Also, most visual gears are not using all possible values, while some values are just ignored.
       
   441 
       
   442 Note that most visual gears require little to no modification of their values.
       
   443 
       
   444 *NOTE*: *Never* use the visual gear's internal state to manipulate/store anything gameplay-related.  Visual gears are not safe for reliable storage and using them as that would lead to strange bugs.
       
   445 
       
   446 Example 1:
       
   447 
       
   448 <code language="lua">  -- set a circle to position 1000,1000 pulsing from opacity 20 to 200 (8%-78%), radius of 50, 3px thickness, bright red.
       
   449     SetVisualGearValues(circleUid, 1000,1000, 20, 200, 0, 0, 100, 50, 3, 0xff0000ff)</code>
       
   450 
       
   451 Only the first argument is required. Everything else is optional. Any such argument which is declared as `nil` will not overwrite the corresponding value of the visual gear.
       
   452 
       
   453 Example 2:
       
   454 
       
   455 <code language="lua">  -- set a visual gear to position 1000,1000
       
   456     SetVisualGearValues(circleUid, 1000, 1000)</code>
       
   457 <code language="lua">  -- set the tint of a visual gear to bright red.
       
   458     SetVisualGearValues(circleUid, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xff0000ff)</code>
       
   459     
       
   460 === `SetGearAIHints(gearUid, aiHint)` ===
       
   461 Set some behaviour hints for computer-controlled hedgehogs for any given gear with `gearUid`.
       
   462 
       
   463 Set `aiHint` to either of:
       
   464 
       
   465  * `aihUsualProcessing`: AI hogs treat this gear the usual way. This is the default.
       
   466  * `aihDoesntMatter`: AI hogs don't bother attacking this gear intentionally.
       
   467 
       
   468 Example:
       
   469 
       
   470 <code language="lua">
       
   471 SetGearAIHints(uselessHog, aihDoesntMatter)
       
   472 -- This makes AI hogs stop caring about attacking uselessHog</code>
       
   473 
       
   474 == Hedgehog-specific gear properties ==
       
   475 === `GetHogName(gearUid)` ===
       
   476 Returns the name of the specified hedgehog gear.
       
   477 
       
   478 === `SetHogName(gearUid, name)` ===
       
   479 Sets the name of the specified hedgehog gear.
       
   480 
       
   481 === `GetHogTeamName(gearUid)` ===
       
   482 Returns the name of the specified gear’s team. `gearUid` can be a hedgehog or a grave.
       
   483 
       
   484 === `SetHogTeamName(gearUid, name)` ===
       
   485 Sets the team name of the specified gear. The gear can be a hedgehog or grave.
       
   486 
       
   487 === `GetHogClan(gearUid)` ===
       
   488 Returns the clan ID of the specified hedgehog gear.
       
   489 
       
   490 === `GetHogLevel(gearUid)` ===
       
   491 Returns the bot level ranging from `0` to `5`. `1` is the strongest bot level and `5` is the weakest one (this is the reverse of what players see). `0` is for human player.
       
   492 
       
   493 === `SetHogLevel(gearUid, level)` ===
       
   494 Sets the bot level from 0 to 5. `1` is the strongest bot level and `5` is the weakest one (this is the reverse of what players see). `0` means human player.
       
   495 
       
   496 === `GetEffect(gearUid, effect)` ===
       
   497 Returns the state of given effect for the given hedgehog gear.
       
   498 
       
   499 See `SetEffect` for further details.
       
   500 
       
   501 === `SetEffect(gearUid, effect, effectState)` ===
       
   502 Sets the state for one of the effects `heInvulnerable, heResurrectable, hePoisoned, heResurrected, heFrozen` for the specified hedgehog gear.
       
   503 A value of 0 usually means the effect is disabled, values other than that indicate that it is enabled and in some cases specify e.g. the remaining time of that effect.
       
   504 
       
   505 || *`effect`* || *Description* || *`effectState`* ||
       
   506 || `heInvulnerable` || Wether hog is invulnerable || Any non-zero value turns on invulnerability. `0` turns it off. ||
       
   507 || `hePoisoned` || Poison damage, damages hog each turn. || Amount of damage per turn. Use `0` to disable poisoning. ||
       
   508 || `heResurrectable` || Whether to resurrect the hog on death || With a non-zero value, the hedgehog will be resurrected and teleported to a random location on death. `0` disables this. ||
       
   509 || `heResurrected` || Whether the hedgehog has been resurrected once. This is only a subtle graphical effect. || With a non-zero value, the hedgehog was resurrected, `0` otherwise. ||
       
   510 || `heFrozen` || Freeze level. Frozen hedgehogs skip turn, are heavy and take half damage || The hog is considered frozen if the value is `256` or higher, otherwise not. A number of `256` or higher denotes “how frozen” the hedgehog is, i.e. how long it takes to melt. The freezer sets this to `199999` initially. The value will be reduced by `50000` each round. Being hit by a flame reduces this number by `1000`. The values `0` to `255` are used for the freeze/melt animations. ||
       
   511 || `heArtillery` || If enabled, the hedgehog can't walk (since 0.9.24). || `0` = disabled. `1` = permanently enabled. `2` = temporarily enabled (used by sniper rifle between shots) ||
       
   512 
       
   513 Example (sets all bots poisoned with poison damage of 1):
       
   514 
       
   515 <code language="lua">    function onGearAdd(gear)
       
   516         if (GetGearType(gear) == gtHedgehog) and (GetHogLevel(gear) > 0) then
       
   517             SetEffect(gear, hePoisoned, 1)
       
   518         end
       
   519     end</code>
       
   520 
       
   521 === `GetHogHat(gearUid)` ===
       
   522 Returns the hat of the specified hedgehog gear.
       
   523 
       
   524 === `SetHogHat(gearUid, hat)` ===
       
   525 Sets the hat of the specified hedgehog gear.
       
   526 
       
   527 === `GetHogFlag(gearUid)` ===
       
   528 Returns the name of the flag of the team of the specified hedgehog gear.
       
   529 
       
   530 === `GetHogFort(gearUid)` (0.9.23) ===
       
   531 Returns the name of the fort of the team of the specified hedgehog gear.
       
   532 
       
   533 === `GetHogGrave(gearUid)` ===
       
   534 Returns the name of the grave of the team of the specified hedgehog gear.
       
   535 
       
   536 === `GetHogVoicepack(gearUid)` ===
       
   537 Returns the name of the voicepack of the team of the specified hedgehog gear.
       
   538 
       
   539 === `GetAmmoCount(gearUid, ammoType)` ===
       
   540 Returns the ammo count of the specified ammo type for the specified hedgehog gear. If infinite, returns `AMMO_INFINITE`.
       
   541 
       
   542 === `GetAmmoTimer(gearUid, ammoType)` (0.9.25) ===
       
   543 Returns the currently configured ammo timer (in milliseconds) for the given hedgehog gear and specified ammo type. This is the timer which is set by the player by using the timer keys (1-5). For ammo types for which the timer cannot be changed, `nil` is returned.
       
   544 
       
   545 Example:
       
   546 <code lang="lua">GetAmmoTimer(CurrentHedgehog, amGrenade)
       
   547 -- May return 1000, 2000, 3000, 4000 or 5000</code>
       
   548 
       
   549 === `HealHog(gearUid, healthBoost[, showMessage[, tint]])` (0.9.24) ===
       
   550 Convenience function to increase the health of a hedgehog with default visual effects.
       
   551 
       
   552 Specifically, this increases the health of the hedgehog gear with the given ID `gearUid` by `healthBoost`, displays some healing particles at the hedgehog and shows the health increae as a message. This is similar to the behavour after taking a health crate, or getting a health boost from vampirism.
       
   553 
       
   554 If `showMessage` is false, no message is shown. With `tint` you can set the RGBA color of the particles (default: `0x00FF00FF`).
       
   555 
       
   556 This function does not affect the poison state, however (see `SetEffect`).
       
   557 
       
   558 === `HogTurnLeft(gearUid, boolean)` ===
       
   559 Faces the specified hog left or right.
       
   560 
       
   561 Example:
       
   562 
       
   563 <code language="lua">    HogTurnLeft(CurrentHedgehog, true) -- turns CurrentHedgehog left 
       
   564     HogTurnLeft(CurrentHedgehog, false) -- turns CurrentHedgehog right</code>
       
   565 
       
   566 === `IsHogHidden(gearUid)` (0.9.25) ===
       
   567 Returns true if hedgehog gear is hidden (e.g. via `HideHog` or the !TimeBox), false if it isn't, nil if that hedgehog never existed.
       
   568 
       
   569 === `HideHog(gearUid)` ===
       
   570 Removes a hedgehog from the map. The hidden hedgehog can be restored with `RestoreHog(gearUid)`. Since 0.9.23, returns `true` on success and `false` on failure (if gear does not exist / hog is already hidden).
       
   571 
       
   572 Example: 
       
   573 
       
   574 <code language="lua">    gear = AddGear(...)
       
   575      HideHog(gear) -- Hide the newly created gear.</code>
       
   576 
       
   577 === `RestoreHog(gearUid)` ===
       
   578 Restores a previously hidden hedgehog.  Nothing happens if the hedgehog does not exist or is not hidden.
       
   579 
       
   580 Example: 
       
   581 
       
   582 <code language="lua">    gear = AddGear(...)
       
   583      HideHog(gear) -- Hide the newly created gear.
       
   584      RestoreHog(gear) -- Restore the newly hidden gear.</code>
       
   585 
       
   586 === `IsHogLocal(gearUid)` (0.9.23) ===
       
   587 Returns `true` if the specified hedgehog gear is controlled by a human player on the computer on which Hedgewars runs on (i.e. not over a computer over the network). Also returns `true` if the hog is a member of any of the local clans. Returns `false` otherwise. Returns `nil` if `gearUid` is invalid.
       
   588 
       
   589 This is perfect to hide certain captions like weapon messages from enemy eyes.
       
   590 
       
   591 == Special gear actions ==
       
   592 === `GetFollowGear()` ===
       
   593 Returns the uid of the gear that is currently being followed.
       
   594 
       
   595 === `FollowGear(gearUid)` ===
       
   596 Makes the game client follow the specifiec gear (if it exists). Does not work for visual gears.
       
   597 
       
   598 === `HogSay(gearUid, text, manner [,vgState])` ===
       
   599 Makes the specified gear say, think, or shout some text in a comic-style speech or thought bubble. `gearUid` is _not_ limited to hedgehogs, altough the function name suggests otherwise.
       
   600 
       
   601 The `manner` parameter specifies the type of the bubble and can have one of these values:
       
   602 
       
   603 || *Value of `manner`* || *Looks* ||
       
   604 || `SAY_THINK` || Thought bubble ||
       
   605 || `SAY_SAY` || Speech bubble ||
       
   606 || `SAY_SHOUT` || Exclamatory bubble (denotes shouting) ||
       
   607 
       
   608 There is a optional 4th parameter `vgState`, it defines wheather the speechbubble is drawn fully opaque or semi-transparent. The value `0` is the default value.
       
   609 
       
   610 || *Value of `vgState`* || *Effect* ||
       
   611 || `0` || If the specified gear is a hedgehog, and it’s the turn of the hedgehog’s team, the bubble is drawn fully opaque.<br>If the gear is a hedgehog, and it’s another team’s turn, the bubble is drawn translucent.<br>If the gear is not a hedgehog, the bubble is drawn fully opaque. ||
       
   612 || `1` || The bubble is drawn translucent. ||
       
   613 || `2` || The bubble is drawn fully opaque. ||
       
   614 
       
   615 Examples:
       
   616 
       
   617 <code language="lua">HogSay(CurrentHedgehog, "I wonder what to do …", SAY_THINK) -- thought bubble with text “I wonder what to do …”</code>
       
   618 <code language="lua">HogSay(CurrentHedgehog, "I'm hungry.", SAY_SAY) -- speech bubble with text “I’m hungry.”</code>
       
   619 <code language="lua">HogSay(CurrentHedgehog, "I smell CAKE!", SAY_SHOUT) -- exclamatory bubble with text “I smell CAKE!”</code>
       
   620 
       
   621 == Deletion ==
       
   622 === `DeleteGear(gearUid)` ===
       
   623 Deletes a gear.  If the specified gear did not exist, nothing happens.
       
   624 
       
   625 Example:
       
   626 
       
   627 <code language="lua">    gear = AddGear(...)
       
   628     DeleteGear(gear) -- Delete the newly created gear.</code>
       
   629 
       
   630 === `DeleteVisualGear(vgUid)` ===
       
   631 Deletes a visual gear.  If it does not exist, nothing happens. 
       
   632 
       
   633 Note, most visual gears delete themselves after a while.
       
   634 
       
   635 
       
   636 
       
   637 Example:
       
   638 
       
   639 <code language="lua">    vgear = AddVisualGear(...)
       
   640     DeleteVisualGear(vgear) -- Delete the newly created visual gear.</code>