From 6891bd7541dea3ebbf1ffa7b1c26b1bebf8b75be Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 22 May 2022 12:25:15 +0100 Subject: [PATCH] Add creature statistics, speed depends on strength and equip weight --- src/Dodge/Combine/Combinations.hs | 2 ++ src/Dodge/Creature/Impulse/Movement.hs | 35 ++++++++------------------ src/Dodge/Creature/Statistics.hs | 25 ++++++++++++++++++ src/Dodge/Data.hs | 7 ++++++ src/Dodge/Default.hs | 1 + 5 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 src/Dodge/Creature/Statistics.hs diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index 7158f8357..f6174e550 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -76,6 +76,8 @@ itemCombinations = , po [MAGNET,TIN] magShield + , p [p 2 PIPE,o PLATE,o MOTOR] powerLegs + , p [p 4 CAN] plateCraft , p [p 3 TIN] plateCraft , p [p 2 DRUM] plateCraft diff --git a/src/Dodge/Creature/Impulse/Movement.hs b/src/Dodge/Creature/Impulse/Movement.hs index 8beb246f6..4973a2e3a 100644 --- a/src/Dodge/Creature/Impulse/Movement.hs +++ b/src/Dodge/Creature/Impulse/Movement.hs @@ -1,5 +1,6 @@ module Dodge.Creature.Impulse.Movement where import Dodge.Data +import Dodge.Creature.Statistics import Geometry import Data.Maybe @@ -8,31 +9,11 @@ import Control.Lens {- | Creature attempts to moves under its own steam. The idea is that this may or may not work, depending on the status of the creature. For now, though, this cannot fail. -} ---crMvBy --- :: Point2 -- ^ Movement translation vector, will be made relative to creature direction --- -> Creature --- -> Creature ---crMvBy p' cr = advanceStepCounter (magV p) cr --- & crPos %~ (+.+ p) --- & crMvDir .~ argV p --- where --- p = (*.*) (equipFactor * aimingFactor) $ rotateV (_crDir cr) p' --- equipFactor --- | _posture (_crStance cr) == Aiming --- = product $ map equipAimSpeed $ IM.elems $ _crInv cr --- | otherwise = product $ map equipSpeed $ IM.elems $ _crInv cr --- aimingFactor --- | _posture (_crStance cr) == Aiming = fromMaybe 1 $ it ^? itUse . useAim . aimSpeed --- | otherwise = 1 --- it = _crInv cr IM.! _crInvSel cr - crMvBy :: Point2 -- ^ Movement translation vector, will be made relative to creature direction -> Creature -> Creature -crMvBy p' cr = crMvAbsolute p cr - where - p = rotateV (_crDir cr) p' +crMvBy p cr = crMvAbsolute (rotateV (_crDir cr) p) cr crMvAbsolute :: Point2 -- ^ Movement translation vector @@ -42,7 +23,8 @@ crMvAbsolute p' cr = advanceStepCounter (magV p) cr & crPos %~ (+.+ p) & crMvDir .~ argV p where - p = (equipFactor * aimingFactor) *.* p' + --p = (equipFactor * aimingFactor) *.* p' + p = (strengthFactor (getCrStrength cr) * aimingFactor) *.* p' isAiming = _posture (_crStance cr) == Aiming || _posture (_crStance cr) == Reloading invItSpeed | isAiming = equipAimSpeed @@ -52,6 +34,12 @@ crMvAbsolute p' cr = advanceStepCounter (magV p) cr | isAiming = fromMaybe 1 $ cr ^? crInv . ix (_crInvSel cr) . itUse . useAim . aimSpeed | otherwise = 1 +strengthFactor :: Int -> Float +strengthFactor i + | i > 9 = 1 + | i < 1 = 0.1 + | otherwise = 0.1 * fromIntegral i + crMvForward :: Float -- ^ Speed -> Creature @@ -62,9 +50,8 @@ advanceStepCounter :: Float -- ^ Speed -> Creature -> Creature -advanceStepCounter speed cr = cr & crStance . carriage %~ f +advanceStepCounter speed = crStance . carriage %~ f where - --stnce = _crStance cr f car = case car of Standing -> f (Walking 0 RightForward) Walking i ff -> Walking (i + ceiling speed) ff diff --git a/src/Dodge/Creature/Statistics.hs b/src/Dodge/Creature/Statistics.hs new file mode 100644 index 000000000..ab72296a8 --- /dev/null +++ b/src/Dodge/Creature/Statistics.hs @@ -0,0 +1,25 @@ +module Dodge.Creature.Statistics + ( getCrStrength + ) where +import Dodge.Data +import qualified IntMapHelp as IM + +import Data.IntMap.Merge.Strict + +getCrStrength :: Creature -> Int +getCrStrength cr = strFromEquipment cr + _crStrength (_crStatistics cr) + +strFromEquipment :: Creature -> Int +strFromEquipment = sum . fmap equipmentStrValue . crCurrentEquipment + +equipmentStrValue :: Item -> Int +equipmentStrValue itm = case _itType itm of + FRONTARMOUR -> negate 2 + POWERLEGS -> 3 + _ -> 0 + +crCurrentEquipment :: Creature -> IM.IntMap Item +crCurrentEquipment cr = merge dropMissing dropMissing (zipWithMatched (\_ _ itm -> itm)) + (_crInvEquipped cr) + (_crInv cr) + diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 63ee84d2e..ea1ece92a 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -296,6 +296,12 @@ data Creature = Creature , _crMvType :: CrMvType , _crHammerPosition :: HammerPosition , _crName :: String + , _crStatistics :: CreatureStatistics + } +data CreatureStatistics = CreatureStatistics + { _crStrength :: Int + , _crDexterity :: Int + , _crIntelligence :: Int } data Vocalization = Mute @@ -1307,3 +1313,4 @@ makeLenses ''Beam makeLenses ''BeamType makeLenses ''WorldBeams makeLenses ''ArcStep +makeLenses ''CreatureStatistics diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index b0992a30b..2dc0d4499 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -63,6 +63,7 @@ defaultCreature = Creature , _crMvType = defaultAimMvType , _crHammerPosition = HammerUp , _crName = "DEFAULTCRNAME" + , _crStatistics = CreatureStatistics 10 10 10 } defaultInanimate :: Creature defaultInanimate = defaultCreature & crActionPlan .~ Inanimate