(POH)= # POH Handler The POH Handler is a handler responsible for making sense of a player's POH (Player Owned House) without knowing any info about it's setup in advance. :::{note} :class: dropdown The POH Handler is optional and has to be explicitly included. You can include it by either including all optional files which is not recommended: ```pascal {$I WaspLib/optional.simba} ``` Or include just the POHHandler file which is the recommended way to include it: ```pascal {$I WaspLib/optional/handlers/poh.simba} ``` ::: Several rooms in a POH are unique on the minimap, with windows and/or doors of several sizes and different places. By having this rooms saved in the following format: ```{figure} ../../../osr/walker/poh.png Most relevant rooms for a POH stripped of their floor colors ``` We can attempt to match what we have on the minimap to those rooms and slowly build a map of the POH. Some rooms share the same room layout or are very similar to others and for those we use some mainscreen information to make up what the room is, e.g., Nexus room, Combat Hall and Quest Hall are all identical. - - - ## PRSWalker TRSWalker pointer. - - - (TRSPOHHandler)= ## type TRSPOHHandler ```pascal type TRSPOHHandler = record Map: TPOHMap; RoomObjects: array [ERSRoomObject] of TRoomObject; EnableRunAtEnergy: Int32; Similarity: Double; end; ``` The core record used to handle navigating a POH. - - - ## POH.Init() ```pascal procedure TRSPOHHandler.Init(); ``` Internal method automatically called for your on script startup along with SRL.Setup(). You do not have to call it yourself. - - - ## POH.GetAdjacentRooms() ```pascal function TRSPOHHandler.GetAdjacentRooms(p: TPoint): TPointArray; static; ``` Helper static method that returns coordinates that belong to the north, west, south and east rooms of the point passed in. This assumes the compass is set to `0` (North) or that you've rotated your coordinates so the math works as if you had the compass set that way. Ideally, you will want to pass in a room top left corner to this to get the top left corner of each adjacent room. - - - ## TRSPOHHandler.GetRoomCoordinate() ```pascal function TRSPOHHandler.GetRoomCoordinate(topLeft, p: TPoint; angle: Double; rotation: Int32): TPoint; static; ``` Helper static method that converts a room point `p` (which is always between [0,0] and [32,32] to a point on the minimap. Optionally the point can be rotated on the room's center in 90º increments which is decided by `rotation`. For example, if `rotation` is 3, the point will be rotated 90*3=270º on the room's center. This is useful to look for mainscreen objects in a room we don't know the rotation, we can brute force all the possible rotations and look for what we want. - - - ## POH.GetCuboid() ```pascal function TRSPOHHandler.GetCuboid(topLeft, p: TPoint; tile: Vector3; angle: Double; rotation: Int32): TCuboidEx; static; ``` Static mehod that returns a `TCuboidEx` on the mainscreen of a point we specify `p` with a given `rotation` on the room's center. {ref}`TRSPOHHandler.GetRoomCoordinate()` is used to get the minimap point which then uses {ref}`Minimap.GetCuboidMS()` to give us a cuboid as a result. To work, this requires the room's `topLeft` TPoint and the compass `angle`. - - - ## POH.ContainsObject() ```pascal function TRSPOHHandler.ContainsObject(objType: ERSRoomObject; topLeft: TPoint; angle: Double; rotation: Int32): Boolean; ``` Checks if a {ref}`TRoomObject` stored in `POH.RoomObjects` exists in a room at a given `rotation`. - - - ## POH.MapRoomObjects() ```pascal procedure TRSPOHHandler.MapRoomObjects(room: ERSHouseRoom; topLeft: TPoint; roomIndex: TPoint; angle: Double); ``` Method responsible for mapping known {ref}`TRoomObject``TRoomObject` coordinates which later can be used to interact with them. - - - ## POH.MapAdjacentRooms() ```pascal procedure TRSPOHHandler.MapAdjacentRooms(minimapBMP: TMufasaBitmap; topLeft, currentRoom: TPoint; angle: Double); ``` The core of the "POH Handler". This method is what's responsible for mapping unknown adjacent rooms (north, west, south and east). If you know what you are doing you can call this directly, but this is called automatically by {ref}`POH.Position()` and {ref}`POH.Setup()`. - - - ## POH.Setup() ```pascal procedure TRSPOHHandler.Setup(); ``` The method that sets up the "POH Handler" so it can be used. It's your responsibility to call it and it must be called from your POH entrance. There is some wiggle room as from where you can use this on your garden and you might get away using it from anywhere but for best results you should use this from the tile right northwest to your exit portal. This is the tile that the `POH.Setup()` assumes you will be calling it from and it's the tile you will always be in as soon as you enter your POH no matter the method you choose to enter it (teleport, using the portal, building or non building mode, ...). Example: ```pascal if MainScreen.WaitLoadingPOH(5000) then POH.Setup(); ``` - - - ## POH.LoadSuroundings() ```pascal procedure TRSPOHHandler.LoadSuroundings(minimapBMP: TMufasaBitmap; p: TPoint; angle: double); ``` Wrapper method that performs some common math required by {ref}`POH.MapAdjacentRooms()`. You can use this directly if you know what you are doing, but this is called automatically for you with {ref}`POH.Position()`. - - - ## POH.Position() ```pascal function TRSPOHHandler.Position(): TPoint; ``` Returns the player position relative to the `POH.Map`. Whenever this method is called, if there's unknown adjacent rooms (north, west, south and east), they will be mapped. - - - ## POH.DebugPosition() ```pascal procedure TRSPOHHandler.DebugPos(); ``` Debugs the current player position on the `POH.Map`. Example: ```pascal {$I WaspLib/optional/handlers/poh.simba} begin POH.Setup(); //call from the northwest tile of your exit portal. while True do POH.DebugPos(); end; ``` - - - ## POH.GetCurrentRoom() ```pascal function TRSPOHHandler.GetCurrentRoom(): ERSHouseRoom; ``` Returns the current {ref}`ERSHouseRoom` we are on. Example: ```pascal POH.Setup(); //call from the northwest tile of your exit portal. WriteLn POH.GetCurrentRoom(); ``` - - - # POH Objects The following methods are related to interacting with {ref}`POH` {ref}`TRoomObject`. - - - ## POH.Find ```pascal function TRSPOHHandler.FindEx(objType: ERSRoomObject; out cuboids: TCuboidExArray; out atpa: T2DPointArray): function TRSPOHHandler.FindAny(objType: ERSRoomObject; out tpa: TPointArray): Boolean; function TRSPOHHandler.FindAll(objType: ERSRoomObject; out atpa: T2DPointArray): Boolean; ``` Method used to find a {ref}`TRoomObject` by specifying a {ref}`ERSRoomObject`. You can find any occurence of the object or all of them depending on the method you use. The extended version of the method is mostly for debugging. - - - ## TRSPOHHandler.Draw() ```pascal procedure TRSPOHHandler.Draw(out bitmap: TMufasaBitmap; objType: ERSRoomObject); ``` Internal method used to draw found {ref}`TRoomObject` in a TMufasaBitmap. An easy way to see this in action is to use `Debug(ERSRoomObject)`. - - - ## POH.Interact ```pascal function TRSPOHHandler.Hover(objType: ERSRoomObject): Boolean; function TRSPOHHandler.Click(objType: ERSRoomObject): Boolean; function TRSPOHHandler.Select(objType: ERSRoomObject; options: TStringArray): Boolean; ``` Method used to interact with a {ref}`TRoomObject` by specifying a {ref}`ERSRoomObject`. The interactions are self explanatory. Example: ```pascal POH.Setup(); //call from the northwest tile of your exit portal. WriteLn POH.Hover(ERSRoomObject.POOL); //pool has to be on the same room, north, west, south or east. ``` - - - ## POH.WalkInteract ```pascal function TRSPOHHandler.WalkHover(objType: ERSRoomObject; attempts: Int32): Boolean; function TRSPOHHandler.WalkClick(objType: ERSRoomObject; attempts: Int32): Boolean; function TRSPOHHandler.WalkSelect(objType: ERSRoomObject; options: TStringArray; attempts: Int32): Boolean; ``` Method used to walk and interact with a {ref}`TRoomObject` by specifying a {ref}`ERSRoomObject`. The interactions are self explanatory. Example: ```pascal POH.Setup(); //call from the northwest tile of your exit portal. WriteLn POH.Hover(ERSRoomObject.POOL); //pool has to be on the same room, north, west, south or east. ``` - - - ## var POH ```pascal var POH ``` Global variable to use the {ref}`TRSPOHHandler`. - - - ## Debug ```pascal procedure Debug(pohObject: ERSRoomObject); overload; ``` Method used to debug {ref}`TRoomObject`.