share/hedgewars/Data/Scripts/Utils.lua
author nemo
Fri, 18 May 2018 09:57:24 -0400
changeset 13401 a52b8b8cbac4
parent 13220 bc95df84395f
child 13670 5664650befcd
permissions -rw-r--r--
merge this in too
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4873
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     1
-- Library for miscellaneous utilitiy functions
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     2
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     3
-- 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
     4
function gearIsInBox(gear, x, y, w, h)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     5
    gx, gy = GetGearPosition(gear)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     6
    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
     7
        return true
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     8
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     9
    return false
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    10
end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    11
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    12
-- 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
    13
function gearIsInCircle(gear, x, y, r, useRadius)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    14
    gx, gy = GetGearPosition(gear)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    15
    if useRadius then
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    16
        r = r + GetGearRadius(gear)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    17
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    18
    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
    19
        return true
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    20
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    21
    return false
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    22
end
13220
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    23
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    24
local function drawFullMap(erase, flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    25
	for x = 200,4000,600 do
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    26
		for y = 100,2000,150 do
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    27
			AddPoint(x, y, 63, erase)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    28
		end
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
	if flush ~= false then
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    31
		FlushPoints()
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    32
	end
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
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    35
-- Completely fill the map with land. Requires MapGen=mgDrawn.
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    36
-- If flush is false, FlushPoints() is not called.
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    37
function fillMap(flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    38
	drawFullMap(false, flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    39
end
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    40
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    41
-- Completely erase all land from drawn maps. Requires MapGen=mgDrawn.
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    42
-- If flush is false, FlushPoints() is not called.
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    43
function eraseMap(flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    44
	drawFullMap(true, flush)
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    45
end
bc95df84395f Clear drawn maps in TechRacer
Wuzzy <Wuzzy2@mail.ru>
parents: 4873
diff changeset
    46