Skip to content

Commit

Permalink
Correct various looking/finding functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodunit committed Aug 9, 2016
1 parent 9381a07 commit 2903470
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 91 deletions.
38 changes: 10 additions & 28 deletions docs/Screeps/Map.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ Corresponds to the Screeps API [Map](http://support.screeps.com/hc/en-us/article
type ExitsInfo = { 1 :: String, 3 :: String, 5 :: String, 7 :: String }
```

#### `describeExits`
#### `RoomRoute`

``` purescript
describeExits :: String -> Maybe ExitsInfo
type RoomRoute = Array ExitToRoom
```

#### `findExit`
#### `ExitToRoom`

``` purescript
findExit :: Room -> Room -> ReturnCode
type ExitToRoom = { exit :: FindType Unit, room :: String }
```

#### `findExit'`
#### `describeExits`

``` purescript
findExit' :: String -> String -> ReturnCode
describeExits :: String -> Maybe ExitsInfo
```

#### `RoomRoute`
#### `findExit`

``` purescript
type RoomRoute = Array ExitToRoom
findExit :: Room -> Room -> ReturnCode
```

#### `ExitToRoom`
#### `findExit'`

``` purescript
type ExitToRoom = { exit :: FindType Unit, room :: String }
findExit' :: String -> String -> ReturnCode
```

#### `findRoute`
Expand All @@ -56,24 +56,6 @@ findRoute' :: String -> String -> RoomRoute
getRoomLinearDistance :: String -> String -> Int
```

#### `terrain_plain`

``` purescript
terrain_plain :: Terrain
```

#### `terrain_swamp`

``` purescript
terrain_swamp :: Terrain
```

#### `terrain_wall`

``` purescript
terrain_wall :: Terrain
```

#### `getTerrainAt`

``` purescript
Expand Down
28 changes: 2 additions & 26 deletions docs/Screeps/Room.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,40 +140,16 @@ findPath' :: forall o. Room -> RoomPosition -> RoomPosition -> FindPathOpts o ->
getPositionAt :: Room -> Int -> Int -> RoomPosition
```

#### `lookAt`

``` purescript
lookAt :: Room -> Int -> Int -> Array (RoomObject Unit)
```

#### `lookAt'`

``` purescript
lookAt' :: Room -> RoomPosition -> Array (RoomObject Unit)
```

#### `lookAtArea`

``` purescript
lookAtArea :: Room -> Int -> Int -> Int -> Int -> Boolean -> Array (RoomObject Unit)
```

#### `lookForAt`

``` purescript
lookForAt :: forall a. Room -> LookType a -> Int -> Int -> Array a
lookForAt :: forall a. Room -> LookType a -> Int -> Int -> a
```

#### `lookForAt'`

``` purescript
lookForAt' :: forall a. Room -> LookType a -> RoomPosition -> Array a
```

#### `lookForAtArea`

``` purescript
lookForAtArea :: forall a. Room -> LookType a -> Int -> Int -> Int -> Int -> Boolean -> Array a
lookForAt' :: forall a. Room -> LookType a -> RoomPosition -> a
```


14 changes: 4 additions & 10 deletions docs/Screeps/RoomPosition.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ findClosestByPath :: forall a. RoomPosition -> FindType a -> Maybe a
#### `findClosestByPath'`

``` purescript
findClosestByPath' :: RoomPosition -> Array RoomPosition -> Maybe (RoomObject Unit)
findClosestByPath' :: RoomPosition -> Array RoomPosition -> Maybe RoomPosition
```

#### `findClosestByRange`
Expand All @@ -71,7 +71,7 @@ findClosestByRange :: forall a. RoomPosition -> FindType a -> Maybe a
#### `findClosestByRange'`

``` purescript
findClosestByRange' :: RoomPosition -> Array RoomPosition -> Maybe (RoomObject Unit)
findClosestByRange' :: RoomPosition -> Array RoomPosition -> Maybe RoomPosition
```

#### `findInRange`
Expand All @@ -83,7 +83,7 @@ findInRange :: forall a. RoomPosition -> FindType a -> Int -> Array a
#### `findInRange'`

``` purescript
findInRange' :: RoomPosition -> Array RoomPosition -> Int -> Array (RoomObject Unit)
findInRange' :: RoomPosition -> Array RoomPosition -> Int -> Array RoomPosition
```

#### `findPathTo`
Expand Down Expand Up @@ -164,16 +164,10 @@ isNearTo :: RoomPosition -> Int -> Int -> Boolean
isNearTo' :: RoomPosition -> RoomPosition -> Boolean
```

#### `look`

``` purescript
look :: RoomPosition -> Array (RoomObject Unit)
```

#### `lookFor`

``` purescript
lookFor :: forall a. RoomPosition -> LookType a -> Array a
lookFor :: forall a. RoomPosition -> LookType a -> a
```


27 changes: 8 additions & 19 deletions src/Screeps/Room.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Control.Monad.Eff (Eff)
import Data.Maybe (Maybe)

import Screeps.Effects (CMD)
import Screeps.Types (Controller, FindType, LookType, Mode, Path, ReturnCode, Room, RoomObject, RoomPosition, Storage, StructureType, Terminal)
import Screeps.Types (Controller, FindType, LookType, Mode, Path, ReturnCode, Room, RoomPosition, Storage, StructureType, Terminal)
import Screeps.FFI (runThisEffFn2, runThisEffFn3, runThisFn1, runThisFn2, runThisFn3, runThisFn5, runThisFn6, toMaybe, unsafeField)

foreign import data RoomGlobal :: *
Expand Down Expand Up @@ -97,26 +97,15 @@ findPath' = runThisFn3 "findPath"
getPositionAt :: Room -> Int -> Int -> RoomPosition
getPositionAt = runThisFn2 "getPositionAt"

-- TODO: returned types?
lookAt :: Room -> Int -> Int -> Array (RoomObject Unit)
lookAt = runThisFn2 "lookAt"
-- lookAt omitted - use lookForAt
-- lookAtArea omitted - use lookForAtArea

-- TODO: returned types?
lookAt' :: Room -> RoomPosition -> Array (RoomObject Unit)
lookAt' = runThisFn1 "lookAt"

-- TODO: returned types?
lookAtArea :: Room -> Int -> Int -> Int -> Int -> Boolean -> Array (RoomObject Unit)
lookAtArea r top left bot right asArray = runThisFn5 "lookAt" r top left bot right asArray

-- TODO: returned types?
lookForAt :: forall a. Room -> LookType a -> Int -> Int -> Array a
lookForAt :: forall a. Room -> LookType a -> Int -> Int -> a
lookForAt = runThisFn2 "lookForAt"

-- TODO: returned types?
lookForAt' :: forall a. Room -> LookType a -> RoomPosition -> Array a
lookForAt' :: forall a. Room -> LookType a -> RoomPosition -> a
lookForAt' = runThisFn2 "lookForAt"

-- TODO: returned types?
lookForAtArea :: forall a. Room -> LookType a -> Int -> Int -> Int -> Int -> Boolean -> Array a
lookForAtArea r t top left bot right asArray = runThisFn6 "lookForAt" r t top left bot right asArray
-- TODO: implement this
-- lookForAtArea :: forall a. Room -> LookType a -> Int -> Int -> Int -> Int -> Boolean -> Array a
-- lookForAtArea r t top left bot right asArray = runThisFn6 "lookForAt" r t top left bot right asArray
15 changes: 7 additions & 8 deletions src/Screeps/RoomPosition.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Control.Monad.Eff (Eff)
import Data.Maybe (Maybe)

import Screeps.Effects (CMD)
import Screeps.Types (Color, Direction, FindType, LookType, Path, ReturnCode, RoomObject, RoomPosition, StructureType)
import Screeps.Types (Color, Direction, FindType, LookType, Path, ReturnCode, RoomPosition, StructureType)
import Screeps.FFI (toMaybe, runThisEffFn0, runThisEffFn1, runThisEffFn3, runThisFn0, runThisFn1, runThisFn2, runThisFn3, unsafeField)
import Screeps.Room (FindPathOpts)

Expand Down Expand Up @@ -37,20 +37,20 @@ createFlag'' pos name color secondaryColor = runThisEffFn3 "createFlag" pos name
findClosestByPath :: forall a. RoomPosition -> FindType a -> Maybe a
findClosestByPath pos findType = toMaybe $ runThisFn1 "findClosestByPath" pos findType

findClosestByPath' :: RoomPosition -> Array RoomPosition -> Maybe (RoomObject Unit)
findClosestByPath' :: RoomPosition -> Array RoomPosition -> Maybe RoomPosition
findClosestByPath' pos objects = toMaybe $ runThisFn1 "findClosestByPath" pos objects

findClosestByRange :: forall a. RoomPosition -> FindType a -> Maybe a
findClosestByRange pos findType = toMaybe $ runThisFn1 "findClosestByRange" pos findType

findClosestByRange' :: RoomPosition -> Array RoomPosition -> Maybe (RoomObject Unit)
findClosestByRange' :: RoomPosition -> Array RoomPosition -> Maybe RoomPosition
findClosestByRange' pos objects = toMaybe $ runThisFn1 "findClosestByRange" pos objects

findInRange :: forall a. RoomPosition -> FindType a -> Int -> Array a
findInRange pos findType range = runThisFn2 "findInRange" pos findType range

-- TODO: parse return types?
findInRange' :: RoomPosition -> Array RoomPosition -> Int -> Array (RoomObject Unit)
-- TODO: make this more flexible as in original API
findInRange' :: RoomPosition -> Array RoomPosition -> Int -> Array RoomPosition
findInRange' pos findType range = runThisFn2 "findInRange" pos findType range

findPathTo :: RoomPosition -> Int -> Int -> Path
Expand Down Expand Up @@ -92,8 +92,7 @@ isNearTo pos x' y' = runThisFn2 "isNearTo" pos x' y'
isNearTo' :: RoomPosition -> RoomPosition -> Boolean
isNearTo' pos otherPos = runThisFn1 "isNearTo" pos otherPos

look :: RoomPosition -> Array (RoomObject Unit)
look = runThisFn0 "look"
-- look function omitted - use lookFor

lookFor :: forall a. RoomPosition -> LookType a -> Array a
lookFor :: forall a. RoomPosition -> LookType a -> a
lookFor = runThisFn1 "lookFor"

0 comments on commit 2903470

Please sign in to comment.