share/hedgewars/Data/Scripts/Utils.lua
author Wuzzy <Wuzzy2@mail.ru>
Mon, 19 Nov 2018 00:54:36 +0100
changeset 14231 74bf2d906097
parent 13665 5664650befcd
child 14475 2113296b7a29
permissions -rw-r--r--
Turn accidental globals to locals in Lua libraries
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13665
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
     1
-- Library for miscellaneous utilitiy functions and global helper variables
4873
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     2
13665
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
     3
--[[ FUNCTIONS ]]
4873
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     4
-- Check if a gear is inside a box
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     5
function gearIsInBox(gear, x, y, w, h)
14231
74bf2d906097 Turn accidental globals to locals in Lua libraries
Wuzzy <Wuzzy2@mail.ru>
parents: 13665
diff changeset
     6
    local gx, gy = GetGearPosition(gear)
4873
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     7
    if gx >= x and gy >= y and gx <= x + w and gy <= y + h then
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     8
        return true
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     9
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    10
    return false
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    11
end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    12
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    13
-- Check if a gear is inside a circle
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    14
function gearIsInCircle(gear, x, y, r, useRadius)
14231
74bf2d906097 Turn accidental globals to locals in Lua libraries
Wuzzy <Wuzzy2@mail.ru>
parents: 13665
diff changeset
    15
    local gx, gy = GetGearPosition(gear)
4873
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    16
    if useRadius then
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    17
        r = r + GetGearRadius(gear)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    18
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    19
    if r ^ 2 >= (x - gx) ^ 2 + (y - gy) ^ 2 then
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    20
        return true
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    21
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    22
    return false
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    23
end
13215
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    24
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    25
local function drawFullMap(erase, flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    26
	for x = 200,4000,600 do
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    27
		for y = 100,2000,150 do
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    28
			AddPoint(x, y, 63, erase)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    29
		end
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    30
	end
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    31
	if flush ~= false then
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    32
		FlushPoints()
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    33
	end
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    34
end
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    35
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    36
-- Completely fill the map with land. Requires MapGen=mgDrawn.
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    37
-- If flush is false, FlushPoints() is not called.
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    38
function fillMap(flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    39
	drawFullMap(false, flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    40
end
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    41
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    42
-- Completely erase all land from drawn maps. Requires MapGen=mgDrawn.
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    43
-- If flush is false, FlushPoints() is not called.
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    44
function eraseMap(flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    45
	drawFullMap(true, flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    46
end
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    47
13665
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    48
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    49
--[[ GLOBAL VARIABLES ]]
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    50
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    51
-- Shared common land color values for land sprites.
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    52
-- These are useful if you want to make the land type visible.
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    53
-- To be used as tint argument of PlaceSprite.
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    54
U_LAND_TINT_NORMAL = 0xFFFFFFFF			-- tint for normal land
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    55
U_LAND_TINT_INDESTRUCTIBLE = 0x960000FF		-- tint for indestructible land
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    56
U_LAND_TINT_ICE = 0x00FAFAFA			-- tint for icy land
5664650befcd Move common sprite tint values into Utils Lua library
Wuzzy <Wuzzy2@mail.ru>
parents: 13215
diff changeset
    57
U_LAND_TINT_BOUNCY = 0x00FA00FF			-- tint for bouncy land