Use constructed laser as targeting scope

This commit is contained in:
2024-10-08 15:53:03 +01:00
parent da5a895f24
commit 9679f32618
21 changed files with 196 additions and 157 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ itemCombinations =
, po [HELD FLAMESPITTER, cr STEELDRUM] flameThrower
, po [HELD FLAMETHROWER, cr STEELDRUM] flameWall
, po [HELD FLAMETHROWER, cr PUMP] flameTorrent
, p [o $ cr PRISM, o $ cr TRANSFORMER, o $ cr PIPE] lasGun
, p [o $ cr PRISM, o $ cr TRANSFORMER, o $ cr PIPE] laser
-- , po [HELD LASGUN, HELD LASGUN, cr HARDWARE] dualBeam
-- , po [HELD LASGUN, cr TRANSFORMER] (lasWide 2)
-- , po [HELD LASGUN, HELD LASGUN, HELD LASGUN, cr HARDWARE] lasCircle
+4 -4
View File
@@ -201,8 +201,8 @@ inventoryX c = case c of
, makeTypeCraftNum 2 MICROCHIP
]
'J' ->
[ lasGun
, lasGun
[ laser
, battery
--, dualBeam
] <> makeTypeCraftNum 10 TRANSFORMER
'K' ->
@@ -282,13 +282,13 @@ testInventory =
stackedInventory :: [Item]
stackedInventory =
[ torch
, battery
, smallBattery
, remoteScreen
, megaShellMag
, targetingScope TARGETLASER
, burstRifle
, megaTinMag 100
, lasGun
, laser
, makeTypeCraft TRANSFORMER
, teslaGun
, megaBattery
+9 -6
View File
@@ -196,14 +196,15 @@ updateItemWithOrientation ::
LocationLDT ItemLink ComposedItem ->
World ->
World
updateItemWithOrientation cr m loc@(LocLDT _ itmtree) = case _itType itm of
HELD TORCH -> shineTorch cr itmtree m
TARGETING TARGETLASER -> shineTargetLaser cr itmtree m
TARGETING tt -> updateItemTargeting tt cr itm
ATTACH AUGMENTEDHUD -> drawAugmentedHUD loc
updateItemWithOrientation cr m loc@(LocLDT _ itmtree) = case (ci ^. cItem . itType, ci ^. cItemFunction) of
(HELD TORCH, _) -> shineTorch cr itmtree m
(HELD LASER, WeaponTargetingSF) -> shineTargetLaser cr itmtree m
(TARGETING tt, _) -> updateItemTargeting tt cr itm
(ATTACH AUGMENTEDHUD, _) -> drawAugmentedHUD loc
_ -> id
where
itm = itmtree ^. ldtValue . cItem
ci = itmtree ^. ldtValue
itm = ci ^. cItem
drawAugmentedHUD :: LocationLDT ItemLink ComposedItem -> World -> World
drawAugmentedHUD (LocLDT con _) w = fromMaybe w $ do
@@ -219,6 +220,7 @@ shineTargetLaser cr itmtree (p,q) w = fromMaybe (w & pointittarg . itTgPos .~ No
guard $ i >= x
maginvid <- mag ^? ldtValue . cItem . itLocation . ilInvID
return $ w
& worldEventFlags . at InventoryChange ?~ ()
& cWorld . lWorld . creatures . ix (_crID cr)
. crInv . ix maginvid . itUse . amagLoadStatus . iaLoaded -~ x
& cWorld . lWorld . lasers .:~ LaserStart
@@ -245,6 +247,7 @@ shineTorch :: Creature -> LabelDoubleTree ItemLink ComposedItem -> (Point3, Q.Qu
shineTorch cr itmtree (p, q) = fromMaybe id $ do
(_, mag) <- find (isammolink . _iatType . fst) (itmtree ^. ldtLeft)
i <- mag ^? ldtValue . cItem . itUse . amagLoadStatus . iaLoaded
guard $ crIsAiming cr
guard $ i >= x
invid <- mag ^? ldtValue . cItem . itLocation . ilInvID
return $
+1 -1
View File
@@ -152,7 +152,7 @@ data HeldItemType
| BLOWTORCH
| SPARKGUN
| TESLAGUN
| LASGUN
| LASER
| TRACTORGUN
| LAUNCHER
| LAUNCHERX {_xNum :: Int}
+1 -1
View File
@@ -400,7 +400,7 @@ makeBullet thebullet itm cr mz w =
mcUseHeld :: HeldItemType -> Item -> Machine -> World -> World
mcUseHeld hit = case hit of
LASGUN -> mcShootLaser
LASER -> mcShootLaser
_ -> \_ _ -> id
--useHeld :: Huse -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
+39 -40
View File
@@ -1,22 +1,20 @@
module Dodge.Inventory.Location
(updateRootItemID
, crUpdateItemLocations
, setInvPosFromSS
-- , tryGetRootItemInvID
)
where
module Dodge.Inventory.Location (
updateRootItemID,
crUpdateItemLocations,
setInvPosFromSS,
) where
import NewInt
import qualified Data.IntSet as IS
import Dodge.Base.You
import Dodge.Data.SelectionList
import Dodge.Data.Item.Use.Consumption.LoadAction
import Control.Lens
import Dodge.Data.World
import qualified IntMapHelp as IM
import Dodge.Item.Grammar
import Data.Maybe
import Control.Applicative
import Control.Lens
import qualified Data.IntSet as IS
import Data.Maybe
import Dodge.Base.You
import Dodge.Data.Item.Use.Consumption.LoadAction
import Dodge.Data.SelectionList
import Dodge.Data.World
import Dodge.Item.Grammar
import qualified IntMapHelp as IM
import NewInt
-- assumes all item locations inside the items are correct
tryGetRootAttachedFromInvID :: Int -> IM.IntMap Item -> Maybe (Int, IS.IntSet)
@@ -24,16 +22,14 @@ tryGetRootAttachedFromInvID invid im = do
let imroots = invRootMap im
theroot = fromMaybe invid $ imroots ^? ix invid . _1 . _Just
t <- imroots ^? ix theroot . _2
--return (theroot, foldMap (IS.singleton . (^?! _1 . itLocation . ilInvID)) t)
return (theroot, foldMap (IS.singleton . (^?! itLocation . ilInvID)) t)
-- this assumes the creature inventory is well formed, specifically the
-- location ids
-- this assumes the creature inventory is well formed, specifically the
-- location ids
tryGetRootItemInvID :: Int -> Creature -> Maybe Int
tryGetRootItemInvID i cr = do
let adj = case invAdj (_crInv cr) of
Left str -> error $ "tryToGetRootItemInvID: "++ str
Left str -> error $ "tryToGetRootItemInvID: " ++ str
Right x -> x
theroot <- adj ^? ix i
theroot ^? _1 . _Just . _1 <|> Just i
@@ -46,24 +42,26 @@ updateRootItemID cr = fromMaybe cr $ do
-- the following assumes that the crManipulation is correct
crUpdateItemLocations :: Int -> LWorld -> LWorld
crUpdateItemLocations crid lw = fromMaybe lw $ do
crUpdateItemLocations crid lw = fromMaybe lw $ do
mo <- lw ^? creatures . ix crid . crManipulation . manObject
crinv <- lw ^? creatures . ix crid . crInv
return $ IM.foldlWithKey' (crUpdateInvidLocations mo crid) lw crinv
crUpdateInvidLocations :: ManipulatedObject -> Int -> LWorld -> Int -> Item -> LWorld
crUpdateInvidLocations mo crid lw invid itm = lw
& creatures . ix crid . crInv . ix invid . itLocation .~ newloc
& itemLocations %~ IM.insert itid newloc
crUpdateInvidLocations mo crid lw invid itm =
lw
& creatures . ix crid . crInv . ix invid . itLocation .~ newloc
& itemLocations %~ IM.insert itid newloc
where
itid = itm ^. itID . unNInt
newloc = InInv
{ _ilCrID = crid
, _ilInvID = invid
, _ilIsRoot = Just invid == mo ^? imRootItem
, _ilIsSelected = Just invid == mo ^? imSelectedItem
, _ilIsAttached = invid `IS.member` (mo ^. imAttachedItems)
}
newloc =
InInv
{ _ilCrID = crid
, _ilInvID = invid
, _ilIsRoot = Just invid == mo ^? imRootItem
, _ilIsSelected = Just invid == mo ^? imSelectedItem
, _ilIsAttached = invid `IS.member` (mo ^. imAttachedItems)
}
-- this should be looked at, as it is sometimes used in functions that need not
-- concern the player creature
@@ -78,13 +76,14 @@ setInvPosFromSS w =
(i, j) <- sss ^? sssExtra . sssSelPos . _Just
case i of
(-1) -> Just SortInventory
0 -> do
(rootid,aset) <- tryGetRootAttachedFromInvID j (you w ^. crInv)
return SelectedItem
{ _imSelectedItem = j
, _imRootItem = rootid
, _imAttachedItems = aset
}
0 -> do
(rootid, aset) <- tryGetRootAttachedFromInvID j (you w ^. crInv)
return
SelectedItem
{ _imSelectedItem = j
, _imRootItem = rootid
, _imAttachedItems = aset
}
1 -> Just SelNothing
2 -> Just SortNearby
3 -> Just $ SelCloseObject j
+35 -13
View File
@@ -1,14 +1,26 @@
module Dodge.Item.Ammo
where
module Dodge.Item.Ammo (
drumMag,
tinMag,
beltMag,
shellMag,
battery,
smallBattery,
chemFuelPouch,
bulletSynthesizer,
megaShellMag,
megaTinMag,
megaBattery,
) where
import Dodge.Item.Attach
import Control.Lens
import Dodge.Data.World
import Dodge.Default.Item
import Dodge.Item.Attach
import Dodge.Item.Weapon.Bullet
megaTinMag :: Int -> Item
megaTinMag x = tinMag
megaTinMag x =
tinMag
& itUse . amagLoadStatus . iaMax .~ x
& itUse . amagLoadStatus . iaLoaded .~ x
@@ -47,7 +59,8 @@ beltMag =
& itUse . amagType .~ BeltBulletAmmo
megaShellMag :: Item
megaShellMag = shellMag
megaShellMag =
shellMag
& itUse . amagLoadStatus . iaMax .~ 1000000
& itUse . amagLoadStatus . iaLoaded .~ 1000000
@@ -56,9 +69,10 @@ shellMag =
defaultHeldItem & itType .~ AMMOMAG SHELLMAG
& itUse
.~ UseAmmoMag
{ _amagParams = ProjectileParams
{ _ampPayload = ExplosionPayload
}
{ _amagParams =
ProjectileParams
{ _ampPayload = ExplosionPayload
}
, _amagLoadStatus =
ReloadStatus
{ _iaMax = 1
@@ -66,10 +80,18 @@ shellMag =
}
, _amagType = ProjectileAmmo
}
megaBattery :: Item
megaBattery = battery
& itUse . amagLoadStatus . iaMax .~ 1000000
& itUse . amagLoadStatus . iaLoaded .~ 1000000
megaBattery =
battery
& itUse . amagLoadStatus . iaMax .~ 1000000
& itUse . amagLoadStatus . iaLoaded .~ 1000000
smallBattery :: Item
smallBattery =
battery
& itUse . amagLoadStatus . iaMax .~ 999
& itUse . amagLoadStatus . iaLoaded .~ 999
battery :: Item
battery =
@@ -80,8 +102,8 @@ battery =
, _amagType = ElectricalAmmo
, _amagLoadStatus =
ReloadStatus
{ _iaMax = 10^ (9::Int)
, _iaLoaded = 10^ (9::Int)
{ _iaMax = 10 ^ (9 :: Int)
, _iaLoaded = 10 ^ (9 :: Int)
}
}
+9 -9
View File
@@ -200,7 +200,7 @@ heldItemSPic ht it = case ht of
BLOWTORCH -> flamerPic it
SPARKGUN -> teslaGunPic
TESLAGUN -> teslaGunPic
LASGUN -> lasGunPic it
LASER -> lasGunPic it
TRACTORGUN -> tractorGunPic it
LAUNCHER -> launcherPic it
LAUNCHERX _ -> launcherPic it
@@ -349,14 +349,14 @@ teslaGunPic :: SPic
teslaGunPic = shatterGunSPic
lasGunPic :: Item -> SPic
lasGunPic _ =
colorSH
blue
( upperBoxST 4 (rectNSWE 3 1 0 30)
<> upperBoxSU 4 (rectNSWE (-1) (-3) 0 30)
<> upperBoxSU 1 (rectNSWE 3 (-3) 0 30)
)
:!: mempty
lasGunPic _ = noPic $ colorSH blue $ upperPrismPolyST 3 $ square 4
-- colorSH
-- blue
-- ( upperBoxST 4 (rectNSWE 3 1 0 30)
-- <> upperBoxSU 4 (rectNSWE (-1) (-3) 0 30)
-- <> upperBoxSU 1 (rectNSWE 3 (-3) 0 30)
-- )
-- :!: mempty
--dualBeamPic :: Item -> SPic
--dualBeamPic it =
+9 -23
View File
@@ -1,7 +1,6 @@
module Dodge.Item.Grammar (
invLDT,
invTrees,
invIndentIM,
invAdj,
invRootMap,
invRootTrees,
@@ -89,7 +88,7 @@ pciToCI (x,y,_) = CItem x y
basePCI :: Item -> PartiallyComposedItem
basePCI itm = case _itType itm of
HELD LASGUN -> (itm, WeaponScopeSF, laserLinkTest itm)
HELD LASER -> (itm, WeaponTargetingSF, laserLinkTest itm)
_ -> (itm, itemToFunction itm, uncurry useBreakL $ itemToBreakLists itm)
laserLinkTest :: Item -> LinkTest
@@ -181,13 +180,6 @@ invAdj im = do
Right
$ itm ^? itLocation . ilInvID
invIndentIM :: IM.IntMap Item -> IM.IntMap (Item, Int, LabelDoubleTreeNodeType ComposeLinkType)
invIndentIM =
IM.fromDistinctAscList . zip [0 ..] . reverse . map (over _1 (^. _1))
. concatMap ldtToIndentList
. map (bimap _iatType (\(x, y, _) -> (x, y)))
. invLDT
-- returns an intmap with trees for all items
invTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ComposeLinkType Item)
invTrees = fmap (first _iatType) . invTrees'
@@ -200,23 +192,17 @@ invTrees' = IM.unions . map (ldtToIM getindex . fmap (^. _1)) . map (fmap (\(x,
fromMaybe (error "in invTrees try to get non-inventory item tree") $
i ^? itLocation . ilInvID
-- returns an intmap with trees for all items
--invTrees'' :: IM.IntMap Item -> [LocationLDT ItemLink ComposedItem]
allInvLocs :: IM.IntMap Item -> IM.IntMap (Int,LocationLDT ItemLink ComposedItem)
allInvLocs inv = foldMap (f . LocLDT TopLDT) (IM.elems (invRootTrees inv)) mempty
where
f t = cldtPropagateFold h h g 0 t id
h x _ _ _ = x + 1
g x ldt = (.) (IM.insert (ldt ^?! locLDT . ldtValue . cItem . itLocation . ilInvID) (x,ldt))
--invTrees'' = IM.unions . map (f . LocLDT TopLDT) . IM.elems . invRootTrees
-- where
-- f t = cldtPropagateFold h h g 0 t mempty
-- h x _ _ _ = x + 1
-- g x ldt = IM.insert (ldt ^?! locLDT . ldtValue . cItem . itLocation . ilInvID) (x,ldt)
-- returns an intmap with trees for root items, indexed by inventory position
invRootTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ItemLink ComposedItem)
invRootTrees = IM.fromDistinctAscList . reverse . map (getid . fmap (\(x, y, _) -> CItem x y)) . invLDT
where
getid :: LabelDoubleTree ItemLink ComposedItem -> (Int,LabelDoubleTree ItemLink ComposedItem)
getid t = (t ^?! ldtValue . cItem . itLocation . ilInvID, t)
-- returns an intmap with indents and locations for all items
allInvLocs :: IM.IntMap Item -> IM.IntMap (Int,LocationLDT ItemLink ComposedItem)
allInvLocs inv = foldMap (f . LocLDT TopLDT) (IM.elems (invRootTrees inv)) mempty
where
f t = cldtPropagateFold h h g 0 t id
h x _ _ _ = x + 1
g x ldt = (.) (IM.insert (ldt ^?! locLDT . ldtValue . cItem . itLocation . ilInvID) (x,ldt))
+1 -1
View File
@@ -54,7 +54,7 @@ itemFromHeldType ht = case ht of
BLOWTORCH -> blowTorch
SPARKGUN -> sparkGun
TESLAGUN -> teslaGun
LASGUN -> lasGun
LASER -> laser
-- LASCIRCLE -> lasCircle
-- DUALBEAM -> dualBeam
-- LASWIDE i -> lasWide i
+19 -7
View File
@@ -1,7 +1,7 @@
module Dodge.Item.Held.BatteryGuns
( sparkGun
, teslaGun
, lasGun
, laser
, tractorGun
) where
@@ -37,14 +37,14 @@ teslaGun =
& itUse . heldTriggerType .~ AutoTrigger
-- previous phaseV parameters: 0.2, 1, 5
lasGun :: Item
lasGun =
laser :: Item
laser =
defaultHeldItem
& itUse . heldParams .~ BeamShooterParams (Just (tone440sawtoothquietS,2))
& itAmmoSlots .~ singleAmmo ElectricalAmmo
& itUse . heldDelay .~ NoDelay
& itUse . heldTriggerType .~ AutoTrigger
& itUse . heldAim . aimMuzzles . ix 0 . mzPos .~ V2 30 0
& itUse . heldAim . aimMuzzles . ix 0 . mzPos .~ V2 4 0
& itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0
& itUse . heldAim . aimMuzzles . ix 0 . mzFlareType .~ LasGunFlare
& itUse . heldAim . aimMuzzles . ix 0 . mzEffect .~ MuzzleLaser
@@ -58,15 +58,27 @@ lasGun =
& itUse . heldAim . aimWeight .~ 6
& itUse . heldAim . aimRange .~ 1
& itUse . heldAim . aimStance .~ TwoHandUnder
& itType .~ HELD LASGUN
& itType .~ HELD LASER
-- previous attractionPower values: 1, -1, -10, 0
tractorGun :: Item
tractorGun =
lasGun
& itUse . heldDelay .~ NoDelay
defaultHeldItem
& itUse . heldParams .~ BeamShooterParams (Just (tone440sawtoothquietS,2))
& itAmmoSlots .~ singleAmmo ElectricalAmmo
& itUse . heldTriggerType .~ AutoTrigger
& itUse . heldAim . aimMuzzles . ix 0 . mzPos .~ V2 30 0
& itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0
& itTargeting .~ ItTargeting
{ _itTgPos = Nothing
, _itTgID = Nothing
, _itTgActive = False
}
& itDimension . dimRad .~ 10
& itDimension . dimCenter .~ V3 15 0 0
& itUse . heldAim . aimWeight .~ 6
& itUse . heldAim . aimRange .~ 1
& itUse . heldAim . aimStance .~ TwoHandUnder
& itUse . heldAim . aimMuzzles . ix 0 . mzFlareType .~ DefaultFlareType
& itUse . heldAim . aimMuzzles . ix 0 . mzEffect .~ MuzzleTractor
& itType .~ HELD TRACTORGUN
+1 -4
View File
@@ -76,10 +76,7 @@ heldInfo hit = case hit of
BLOWTORCH -> "A weapon that produces a concentrated flame."
SPARKGUN -> "A weapon that produces an arc of electricity. The arc will attempt to discharge at a nearby object."
TESLAGUN -> "A weapon that discharges a sustained arc of electricity. The arc will attempt to discharge at a nearby object."
LASGUN -> "A weapon that continuously emits photons in a narrow beam."
-- LASCIRCLE -> "A extensive configuration of prisms and mirrors that produces multiple laser beams around its user."
-- DUALBEAM -> "A weapon that emits two beams that converge at a selectable point in front of the user."
-- LASWIDE _ -> "A weapon that continuously emits photons in a narrow beam. The beam expands as the weapon heats up."
LASER -> "A device that, when electrically powered, continuously emits photons in a narrow beam."
TRACTORGUN -> "An item that produces a beam of gravitons."
LAUNCHER -> "A large tube that can launch self propelled projectiles. Moving the tube after launch will cause the projectile to spin."
LAUNCHERX i -> over _head toUpper (showInt i) ++ " tubes that can launch self propelled projectiles. Tubes that do not face forward launch their projecitles at an angle."
+22 -1
View File
@@ -1,7 +1,9 @@
{-# LANGUAGE LambdaCase#-}
module Dodge.Item.InventoryColor
( itemInvColor
) where
--import Dodge.Data.Item.Use.Consumption.Ammo
import Dodge.Data.ComposedItem
import Color
import Control.Lens
@@ -9,7 +11,26 @@ import Control.Lens
itemInvColor :: ComposedItem -> Color
itemInvColor ci = case ci ^. cItemFunction of
WeaponPlatformSF -> white
_ -> greyN 0.8
WeaponScopeSF -> chartreuse
WeaponTargetingSF -> green
AugmentedHUDSF -> rose
AmmoMagSF {} -> red
RemoteScreenSF -> azure
UncomposableIsolateSF -> greyN 0.5
AmmoModifierSF {} -> orange
AmmoTargetingSF {} -> green
AmmoPayloadSF {} -> violet
AmmoEffectSF {} -> aquamarine
FunctionChangeSF -> yellow
--ammoTypeColor :: AmmoType -> Color
--ammoTypeColor = \case
-- BulletAmmo -> white
-- ProjectileAmmo -> red
-- BeltBulletAmmo -> orange
-- ElectricalAmmo -> blue
-- GasAmmo -> green
-- HELD {} -> white
-- LEFT {} -> cyan
-- EQUIP {} -> yellow
+1
View File
@@ -11,6 +11,7 @@ orientChild :: Item -> (Point3, Q.Quaternion Float)
orientChild itm = case _itType itm of
HELD TORCH -> (V3 0 5 0, Q.qID)
TARGETING TARGETLASER -> (V3 15 (-5) 0, Q.qID)
HELD LASER -> (V3 15 (-5) 0, Q.qID)
_ -> (0, Q.qID)
orientByLink :: Item -> ComposeLinkType -> (Point3, Q.Quaternion Float)
+4 -4
View File
@@ -24,11 +24,11 @@ lockRoomMultiItems =
lockRoomKeyItems :: RandomGen g => [(Int -> State g (MetaTree Room String), State g ItemType)]
lockRoomKeyItems =
[ (lasCenSensEdge, takeOne [HELD LAUNCHER, HELD LASGUN, HELD SPARKGUN, HELD FLATSHIELD])
, (sensorRoomRunPast LASERING, return $ HELD LASGUN)
[ (lasCenSensEdge, takeOne [HELD LAUNCHER, HELD LASER, HELD SPARKGUN, HELD FLATSHIELD])
, (sensorRoomRunPast LASERING, return $ HELD LASER)
, (const slowDoorRoomRunPast, return $ HELD (MINIGUNX 3))
, (const longRoomRunPast, takeOne [HELD SNIPERRIFLE, HELD FLATSHIELD])
, (const glassLessonRunPast, takeOne [HELD LASGUN])
, (const glassLessonRunPast, takeOne [HELD LASER])
, (const $ lasTunnelRunPast 400, takeOne [HELD FLATSHIELD])
, (keyCardRoomRunPast 0, return (HELD $ KEYCARD 0))
]
@@ -55,7 +55,7 @@ itemRooms =
]
)
,
( HELD LASGUN
( HELD LASER
, join $
takeOne
[ rc $ map makeTypeCraft [PRISM, TRANSFORMER, PIPE]
+1 -1
View File
@@ -23,7 +23,7 @@ putLasTurret rotSpeed =
lasTurret :: MachineType
lasTurret = McTurret $
Turret
{ _tuWeapon = lasGun
{ _tuWeapon = laser
, -- { _tuWeapon = autoRifle
_tuTurnSpeed = 0.1
, _tuFireTime = 0
+1 -1
View File
@@ -12,4 +12,4 @@ randFirstWeapon =
++ replicate 5 (bangStick 4)
++ replicate 5 (volleyGun 3)
++ replicate 5 bangCone
++ [lasGun]
++ [laser]