You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
62 lines
1.7 KiB
5 years ago
|
-- __ _ _______ _ __
|
||
|
-- / / /\ | | |__ __| | | \ \
|
||
|
-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \
|
||
|
-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > >
|
||
|
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
|
||
|
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
|
||
|
|
||
5 years ago
|
Quantum.Zone = {}
|
||
5 years ago
|
|
||
5 years ago
|
Quantum.Zone.Zones = {} -- all zones are rectangles where they go from vec1 to vec2
|
||
5 years ago
|
|
||
5 years ago
|
function Quantum.Zone.Register( zoneid, tbl )
|
||
|
if( Quantum.Zone.Zones[zoneid] == nil ) then
|
||
5 years ago
|
local zone = {
|
||
|
name = tbl.name || "Unknown Zone",
|
||
|
id = zoneid,
|
||
|
vec1 = tbl.vec1,
|
||
5 years ago
|
vec2 = tbl.vec2,
|
||
|
property = tbl.property -- not used for normal zones
|
||
|
-- why cant lua just have classes :(
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
Quantum.Zone.Zones[zoneid] = zone
|
||
5 years ago
|
return zone
|
||
|
else
|
||
|
Quantum.Error( "Zone id '" .. zoneid .. "' already exists! Aborting..." )
|
||
|
end
|
||
|
end
|
||
|
|
||
5 years ago
|
function Quantum.Zone.Get( zoneid )
|
||
|
return Quantum.Zone.Zones[zoneid]
|
||
5 years ago
|
end
|
||
|
|
||
5 years ago
|
function Quantum.Zone.IsInZone( vec, zoneid, zone )
|
||
|
zone = zone || Quantum.Zone.Get( zoneid )
|
||
5 years ago
|
return vec:WithinAABox( zone.vec1, zone.vec2 )
|
||
|
end
|
||
|
|
||
5 years ago
|
function Quantum.Zone.GetCurrentZone( vec )
|
||
|
for i, zone in pairs( Quantum.Zone.Zones ) do
|
||
|
if( Quantum.Zone.IsInZone( vec, nil, zone ) ) then
|
||
5 years ago
|
return zone
|
||
|
end
|
||
|
end
|
||
5 years ago
|
end
|
||
|
|
||
5 years ago
|
function Quantum.Zone.GetDoors( zoneid )
|
||
|
local zone = Quantum.Zone.Get( zoneid )
|
||
5 years ago
|
local entInZone = {}
|
||
|
for i, ent in pairs( ents.FindInBox( zone.vec1, zone.vec2 ) ) do
|
||
5 years ago
|
if( Quantum.DoorClasses[ ent:GetClass() ]) then
|
||
5 years ago
|
entInZone[i] = ent
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return entInZone
|
||
5 years ago
|
end
|
||
|
|
||
5 years ago
|
function Quantum.Zone.DoorIsInZone( doorent, zoneid )
|
||
|
local doors = Quantum.Zone.GetDoors( zoneid )
|
||
5 years ago
|
return table.HasValue( doors, doorent )
|
||
5 years ago
|
end
|