---==================================================================================================================---
---                                                                                                                  ---
---    Original Author(s) : Tweaki_Breeki                                                                            ---
---    Edited : NLTP_ASHES                                                                                           ---
---    Date : 17/04/2023                                                                                             ---
---    License : Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)           ---
---                                                                                                                  ---
---    Script used to manage the fake space restrictors used in the Western Goods addon.                             ---
---                                                                                                                  ---
---    These fake space restrictors are composed of :                                                                ---
---     - A point 'pos_a' : the lowest north-western point of an area;                                               ---
---     - A point 'pos_b' : the highest south-eastern point of the area.                                             ---
---                                                                                                                  ---
---          |\¯¯¯¯¯|\                                                                                               ---
---    pos_a |_\____| \                y                                                                             ---
---          \  \___\__\ pos_b         |__ z                                                                         ---
---           \ |    \ |               \                                                                             ---
---            \|_____\|                x                                                                            ---
---                                                                                                                  ---
---    The in_bounds(...) can be used to know if the player is inside that area.                                     ---
---                                                                                                                  ---
---==================================================================================================================---

-- ---------------------------------------------------------------------------------------------------------------------
-- Constants, global variables and imported functions
-- ---------------------------------------------------------------------------------------------------------------------

local dbg_printf                = western_goods_utils.dbg_printf

-- ---------------------------------------------------------------------------------------------------------------------
-- Functions
-- ---------------------------------------------------------------------------------------------------------------------

--- Function used to check if a given object is withing the bounds of a fake restrictor.
--- @param who game_object
--- @param data table
--- @return boolean
function in_bounds(who,data)
    if not who then
        printf("![WG] ERROR | Fake Restrictor | in_bounds() called with no game object !")
        return false
    elseif not data then
        printf("![WG] ERROR | Fake Restrictor | in_bounds() called with no restrictor data !")
        return false
    end

    local posx = who:position().x
    local posy = who:position().y
    local posz = who:position().z

    if (posx > data.ax) and (posz < data.az) and (posy > data.ay) and (posx < data.bx) and (posz > data.bz) and (posy < data.by) then
        dbg_printf("[WG] Fake Restrictor | '%s' in restrictor bounds", who:name())
        return true
    else
        return false
    end
end

--- Function used to check if a given object is withing the bounds of a fake restrictor.
--- This function is specifically made for logic scheme's 'combat_ignore_cond' condlist.
--- @param enemy game_object
--- @param npc game_object
--- @param p table
--- @return boolean
function xr_conditions.in_bounds(enemy,npc,p)
    return in_bounds(enemy, { ax=p[1],ay=p[2],az=p[3],bx=p[4],by=p[5],bz=p[6] })
end