Add IntMapHelper, locate wall cutting bug

This commit is contained in:
2021-05-22 15:14:21 +02:00
parent 26f0ca4ab5
commit 9c2bcbec10
35 changed files with 221 additions and 139 deletions
+2 -2
View File
@@ -19,6 +19,7 @@ import Dodge.Inventory
--import Dodge.LightSources
import Geometry
import Picture
import qualified IntMapHelp as IM
import Control.Lens
--import Control.Monad
@@ -26,7 +27,6 @@ import Control.Lens
import Data.Maybe
--import Data.List
import System.Random
import qualified Data.IntMap.Strict as IM
--import qualified Data.Map as M
startReloadingWeapon
@@ -107,7 +107,7 @@ copyItemToFloor cr i w = case _crInv cr IM.! i of
updateLocation w' = case it ^? itID of
Just (Just i') -> w' & itemPositions . ix i' .~ OnFloor flid
_ -> w'
flid = newKey $ _floorItems w
flid = IM.newKey $ _floorItems w
theflit = FlIt
{_flIt = it
,_flItPos = offset +.+ _crPos cr
+4 -3
View File
@@ -22,16 +22,17 @@ armourChaseCrit = defaultCreature
{ _crUpdate = stateUpdate $ impulsiveAIR $
doStrategyActionsR >=>
performActionsR >=>
overrideMeleeCloseTargetR >=>
chaseTargetR targetYouLOS >=>
basicPerceptionUpdateR [0] >=>
targetYouWhenCognizantR >=>
return . (crMeleeCooldown . _Just %~ (max 0 . subtract 1))
targetYouWhenCognizantR >=>
overrideMeleeCloseTargetR >=>
return . (crMeleeCooldown . _Just %~ max 0 . subtract 1)
, _crHP = 300
, _crPict = basicCrPict green
, _crInv = IM.fromList
[(0,frontArmour)
,(1,medkit 200)
]
, _crMeleeCooldown = Just 0
, _crGroup = ShieldGroup
}
+1 -1
View File
@@ -41,7 +41,7 @@ chaseCrit = defaultCreature
chaseTargetR targetYouLOS >=>
basicPerceptionUpdateR [0] >=>
targetYouWhenCognizantR >=>
return . (crMeleeCooldown . _Just %~ (max 0 . subtract 1))
return . (crMeleeCooldown . _Just %~ max 0 . subtract 1)
, _crHP = 300
, _crPict = basicCrPict green
, _crInv = IM.fromList [(0,medkit 200)]
-13
View File
@@ -20,19 +20,6 @@ chaseTarget targFunc w cr = case targFunc cr w of
Nothing -> cr
Just crTarg -> cr & crActionPlan . crImpulse .~ chaseTarg cr crTarg
overrideMeleeCloseTarget :: World -> Creature -> Creature
overrideMeleeCloseTarget _ cr = case _crTarget cr of
Nothing -> cr
Just tcr
| _crMeleeCooldown cr == Just 0
&& dist (_crPos tcr) cpos < _crRad cr + _crRad tcr + 5
&& abs (_crDir cr - argV (_crPos tcr -.- cpos)) < pi/4
-> cr & crActionPlan . crAction .~ [DoImpulses [Melee (_crID tcr)]]
| otherwise -> cr
where
cpos = _crPos cr
meleeHeadingMove
:: Float -- ^ max turn speed
-> Float -- ^ min turn speed
+2 -3
View File
@@ -6,7 +6,6 @@ module Dodge.Creature.Inanimate
import Dodge.Data
--import Dodge.Creature.Stance.Data
import Dodge.Creature.State.Data
import Dodge.Base
import Dodge.Picture.Layer
import Dodge.Default
import Dodge.Creature.State
@@ -15,8 +14,8 @@ import Dodge.WorldEvent.Flash
import Dodge.WorldEvent.Sound
import Dodge.Creature.Update hiding (CRUpdate)
import Picture
import qualified IntMapHelp as IM
import qualified Data.IntMap.Strict as IM
import Control.Lens
defaultInanimate :: Creature
@@ -34,7 +33,7 @@ lamp = defaultInanimate
initialiseLamp :: CRUpdate
initialiseLamp w (f,g) cr = ( (addLS . f , g), Just $ cr & crUpdate .~ updateLamp i)
where
i = newKey $ _lightSources $ f w -- to give different lights different keys
i = IM.newKey $ _lightSources $ f w -- to give different lights different keys
addLS = over lightSources (IM.insert i (lightAt (_crPos cr) i))
updateLamp :: Int -> CRUpdate
+1 -1
View File
@@ -69,7 +69,7 @@ followImpulse cr w imp = case imp of
ChangePosture post -> (id, cr & crStance . posture .~ post)
UseItem -> (crUseItem cr, cr)
SwitchToItem i -> (id, cr & crInvSel .~ i)
Melee cid ->
Melee cid ->
(hitCr cid
, crMvBy (10 *.* normalizeV (posFromID cid -.- cpos)) $ cr & crMeleeCooldown ?~ 20) -- randomise cooldown?
RandomTurn a -> (id, creatureTurn (rr a) cr)
+6 -5
View File
@@ -22,14 +22,15 @@ tryMeleeAttack cr tcr
| _crMeleeCooldown cr == Just 0
&& dist (_crPos tcr) cpos < _crRad cr + _crRad tcr + 5
&& abs (_crDir cr - argV (_crPos tcr -.- cpos)) < pi/4
= cr & crActionPlan . crStrategy .~ StrategyActions MeleeStrike meleeActions
-- = cr & crActionPlan . crStrategy .~ StrategyActions MeleeStrike meleeActions
= cr & crActionPlan . crImpulse .~ [Melee $ _crID tcr]
| otherwise = cr
where
cpos = _crPos cr
meleeActions =
[DoImpulses [Melee (_crID tcr)]
`DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
]
--meleeActions =
-- [DoImpulses [Melee (_crID tcr)]
-- `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
-- ]
chaseTargetR
:: (Creature -> World -> Maybe Creature) -- ^ Function for determining target
+4 -5
View File
@@ -11,6 +11,7 @@ import Dodge.WorldEvent
import Dodge.Creature.Action
import Geometry
import Picture
import qualified IntMapHelp as IM
import Data.List
--import Data.Char
@@ -24,7 +25,6 @@ import Control.Monad.State
--import qualified SDL.Mixer as Mix
import System.Random
--import qualified Data.Set as S
import qualified Data.IntMap.Strict as IM
--import qualified Data.Map as M
type CRUpdate = World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature)
@@ -53,7 +53,7 @@ stateUpdate u w (f,g) cr =
. over decorations addCorpse
. dropByState cr
--crBeforeDeath = colCrWall w cr
addCorpse = insertNewKey
addCorpse = IM.insertNewKey
$ uncurry translate (_crOldPos cr)
$ rotate (_crDir cr)
(_crCorpse cr)
@@ -210,9 +210,8 @@ updateExpBarrel _ (f,g) cr
--perforate (Piercing amount sp int ep) cr = over (crState . crSpState . piercedPoints)
-- ((:) $ int -.- _crPos cr) cr
--perforate _ cr = cr
applyFuseDamage cr' = over crHP (subtract $ length (_piercedPoints
$ _crSpState $ _crState cr'))
cr'
applyFuseDamage cr' = cr' & crHP %~
subtract (length . _piercedPoints . _crSpState $ _crState cr')
hiss | null poss = id
| otherwise = soundMultiFrom [BarrelHiss 0,BarrelHiss 1] 41 50 1
stopSounds = stopSoundFrom (BarrelHiss 0) . stopSoundFrom (BarrelHiss 1)
+1 -1
View File
@@ -32,7 +32,7 @@ swarmCrit :: Creature
swarmCrit = defaultCreature
{ _crUpdate = stateUpdate $ impulsiveAIR $
flockToPointUsing (encircleDistP (100)) (meleeHeadingMove 0.1 0.1 (pi/4) 3.9)
>=> return . (crMeleeCooldown . _Just %~ (max 0 . subtract 1))
>=> return . (crMeleeCooldown . _Just %~ max 0 . subtract 1)
>=> basicPerceptionUpdateR [0]
>=> doStrategyActionsR
>=> targetYouWhenCognizantR