Permalink
Browse files

Adding holographic trail and temporal web behaviors. Temporal web is …

…currently broken.
  • Loading branch information...
1 parent 5eff417 commit 8efa52198524fb31c35c936f83e4e5d04cb6500c @clanehin committed Oct 1, 2013
Showing with 502 additions and 267 deletions.
  1. +19 −0 Makefile
  2. +51 −89 Roguestar/Lib/Behavior.hs
  3. +1 −1 Roguestar/Lib/Behavior/Activate.hs
  4. +1 −0 Roguestar/Lib/Behavior/Construction.hs
  5. +61 −0 Roguestar/Lib/Behavior/Outcome.hs
  6. +107 −11 Roguestar/Lib/Behavior/Travel.hs
  7. +3 −3 Roguestar/Lib/{ → Behavior}/Turns.hs
  8. +1 −1 Roguestar/Lib/Core/Monster.hs
  9. +0 −1 Roguestar/Lib/Core/Plane.hs
  10. +28 −17 Roguestar/Lib/DB.hs
  11. +39 −0 Roguestar/Lib/Data/BehaviorData.hs
  12. +3 −1 Roguestar/Lib/Data/LocationData.hs
  13. +1 −1 Roguestar/Lib/Data/MakeData.hs
  14. +1 −1 Roguestar/Lib/Data/MonsterData.hs
  15. +52 −3 Roguestar/Lib/Data/ReferenceTypes.hs
  16. +0 −2 Roguestar/Lib/Data/SpeciesData.hs
  17. +2 −4 Roguestar/Lib/{Species.hs → Data/SpeciesTraits.hs}
  18. +1 −1 Roguestar/Lib/{ → Data}/Substances.hs
  19. +5 −4 Roguestar/Lib/Data/TerrainData.hs
  20. +1 −1 Roguestar/Lib/Data/ToolData.hs
  21. +7 −4 Roguestar/Lib/Data/VisibilityData.hs
  22. +5 −4 Roguestar/Lib/HTML/Mustache.hs
  23. +1 −1 Roguestar/Lib/Perception.hs
  24. +0 −1 Roguestar/Lib/PlaneVisibility.hs
  25. +2 −3 Roguestar/Lib/Random.hs
  26. +0 −61 Roguestar/Lib/Reference.hs
  27. +2 −1 Roguestar/Lib/Roguestar.hs
  28. +34 −0 Roguestar/Lib/Time.hs
  29. +0 −15 Roguestar/Lib/TimeCoordinate.hs
  30. +1 −2 Roguestar/Lib/Tool.hs
  31. +9 −10 Roguestar/Lib/Utility/DetailedLocation.hs
  32. +0 −1 Roguestar/Lib/Utility/DetailedTravel.hs
  33. +1 −1 Roguestar/Lib/{ → World}/Planet.hs
  34. +9 −2 Roguestar/Server/Main.hs
  35. +0 −1 feedback/37b314aa-7182-439e-915e-65ae52cdd943
  36. +16 −14 roguestar.cabal
  37. +11 −4 static/templates/play.mustache
  38. +9 −1 static/themes/glass/style.js
  39. +18 −0 static/themes/glass/ui.less
View
@@ -20,3 +20,22 @@ run:
check: clean
cabal-dev configure --ghc-options="-O0" --disable-library-profiling --disable-executable-profiling
cabal-dev build
+
+depends:
+ cabal-dev install cipher-aes-0.1.8
+ cabal-dev install MaybeT
+ cabal-dev install MonadCatchIO-transformers
+ cabal-dev install aeson
+ cabal-dev install data-lens-template
+ cabal-dev install data-memocombinators
+ cabal-dev install hastache
+ cabal-dev install hslogger
+ cabal-dev install mwc-random
+ cabal-dev install snap-core
+ cabal-dev install snap-server
+ cabal-dev install snap
+ cabal-dev install streams
+ cabal-dev install system-uuid
+ cabal-dev install data-lens-template
+ cabal-dev install snap
+ cabal-dev install streams
View
@@ -2,9 +2,7 @@
-- Mechanics
module Roguestar.Lib.Behavior
- (Behavior(..),
- FacingBehavior(..),
- facingBehavior,
+ (facingBehavior,
isBehaviorAvailable,
executeBehavior)
where
@@ -14,12 +12,13 @@ import Roguestar.Lib.DB
import Roguestar.Lib.Logging
import Roguestar.Lib.Position
import Roguestar.Lib.Data.FacingData
-import Data.Ratio
+import Roguestar.Lib.Time
import Roguestar.Lib.Tool
import Control.Monad.Error
import Roguestar.Lib.Behavior.Combat
import Roguestar.Lib.Behavior.Activate
import Roguestar.Lib.Behavior.Travel
+import Roguestar.Lib.Behavior.Outcome
import Roguestar.Lib.Data.TravelData
import Roguestar.Lib.Core.Monster
import Roguestar.Lib.Data.MonsterData
@@ -30,36 +29,9 @@ import Roguestar.Lib.Data.TerrainData
import Roguestar.Lib.Behavior.Make
import Roguestar.Lib.Behavior.Construction
import Roguestar.Lib.Core.Building
-import Roguestar.Lib.Reference
import Roguestar.Lib.Utility.DetailedLocation
import Roguestar.Lib.Data.PlaneData
-
-data FacingBehavior =
- Step
- | TurnInPlace
- | Jump
- | Fire
- | Attack
- | ClearTerrain
- | ActivateBuilding
- deriving (Show)
-
---
--- Every possible behavior that a creature might take, AI or Human.
---
-data Behavior =
- FacingBehavior FacingBehavior Facing
- | StepDown
- | StepUp
- | Pickup ToolRef
- | Wield ToolRef
- | Unwield
- | Drop ToolRef
- | Wait
- | Vanish
- | Activate
- | Make PrepareMake
- deriving (Show)
+import Roguestar.Lib.Data.BehaviorData
-- | Decide which FacingBehavior is most appropriate for for a character's situation.
facingBehavior :: (DBReadable db) => MonsterRef -> Facing -> db FacingBehavior
@@ -72,8 +44,7 @@ facingBehavior creature_ref face =
result <- case t of
_ | not (null who) -> return Attack
_ | not (null what) -> return ActivateBuilding
- Forest -> return $ ClearTerrain
- RockFace -> return $ ClearTerrain
+ _ | t `elem` impassable_terrains -> return $ ClearTerrain
_ -> return $ Step
logDB gameplay_log INFO ("facingBehavior is: " ++ show result)
return result
@@ -89,6 +60,10 @@ isBehaviorAvailable (FacingBehavior Jump _) creature_ref =
return $
creature_has_teleport_ability ||
the_terrain == RecreantFactory
+isBehaviorAvailable (FacingBehavior TemporalWebStep _) creature_ref = getMonsterSpecial TemporalWeb creature_ref
+isBehaviorAvailable (FacingBehavior HolographicTrailStep facing) creature_ref =
+ do has_special <- getMonsterSpecial HolographicTrail creature_ref
+ return $ has_special && facing `elem` [North,South,East,West,Here]
isBehaviorAvailable _ _ = return True
executeBehavior :: Behavior -> MonsterRef -> DB ()
@@ -101,75 +76,85 @@ executeBehavior the_behavior the_creature =
dbBehave_ :: Behavior -> MonsterRef -> DB ()
dbBehave_ (FacingBehavior Step face) creature_ref =
- do (move_from,move_to) <- move creature_ref =<< stepMonster face creature_ref
- dbAdvanceTime creature_ref =<< case () of
- () | (move_from == move_to) -> return 0
- () | face == Here -> actionTime creature_ref -- counts as turning in place
- () | face `elem` [North,South,East,West] -> move1ActionTime creature_ref
- () | otherwise -> move2ActionTime creature_ref
+ do motion_outcome <- stepMonster face creature_ref
+ applyEffect motion_outcome
+ increaseTime creature_ref =<< getDuration motion_outcome
+
+dbBehave_ (FacingBehavior TemporalWebStep face) creature_ref =
+ do motion_outcome <- resolveStepWithTemporalWeb face creature_ref
+ applyEffect motion_outcome
+ increaseTime creature_ref =<< getDuration motion_outcome
+
+dbBehave_ (FacingBehavior HolographicTrailStep face) creature_ref =
+ do holo_outcome <- resolveStepWithHolographicTrail face creature_ref
+ applyEffect holo_outcome
+ increaseTime creature_ref =<< getDuration holo_outcome
dbBehave_ StepDown creature_ref =
do _ <- atomic executeClimb $ resolveClimb creature_ref ClimbDown
-- FIXME: should be conditional
- dbAdvanceTime creature_ref =<< move2ActionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
dbBehave_ StepUp creature_ref =
do _ <- atomic executeClimb $ resolveClimb creature_ref ClimbUp
-- FIXME: should be conditional
- dbAdvanceTime creature_ref =<< move2ActionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
dbBehave_ (FacingBehavior Jump face) creature_ref =
do _ <- atomic executeTeleportJump $ resolveTeleportJump creature_ref face
- dbAdvanceTime creature_ref =<< move2ActionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref -- FIXME: this should use moveActionTime
-dbBehave_ (FacingBehavior TurnInPlace face) creature_ref =
- do _ <- move creature_ref =<< turnMonster face creature_ref
- dbAdvanceTime creature_ref =<< actionTime creature_ref
+dbBehave_ (FacingBehavior TurnInPlace face) monster_ref =
+ do turn_outcome <- turnMonster face monster_ref
+ applyEffect turn_outcome
+ increaseTime monster_ref =<< getDuration turn_outcome
dbBehave_ (Pickup tool_ref) creature_ref =
do _ <- move tool_ref =<< pickupTool creature_ref tool_ref
- dbAdvanceTime creature_ref =<< actionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
dbBehave_ (Wield tool_ref) creature_ref =
do available <- availableWields creature_ref
already_wielded <- getWielded creature_ref
when (not $ tool_ref `elem` available) $ throwError $ DBErrorFlag ToolIs_Unreachable
_ <- move tool_ref =<< wieldTool tool_ref
- dbAdvanceTime creature_ref =<< case () of
+ increaseTime creature_ref =<< case () of
() | Just tool_ref == already_wielded -> return 0 -- already wielded, so this was an empty action
() | otherwise -> actionTime creature_ref
dbBehave_ (Unwield) creature_ref =
do dbUnwieldMonster creature_ref
- dbAdvanceTime creature_ref =<< actionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
dbBehave_ (Drop tool_ref) creature_ref =
do tool_parent <- liftM parentReference $ whereIs tool_ref
already_wielded <- getWielded creature_ref
when (tool_parent =/= creature_ref) $ throwError $ DBErrorFlag ToolIs_NotInInventory
_ <- move tool_ref =<< dropTool tool_ref
- dbAdvanceTime creature_ref =<< case () of
+ increaseTime creature_ref =<< case () of
() | Just tool_ref == already_wielded -> return 0 -- instantly drop a tool if it's already held in the hand
() | otherwise -> actionTime creature_ref
dbBehave_ (FacingBehavior Fire face) creature_ref =
- do _ <- move creature_ref =<< turnMonster face creature_ref
+ do turn_outcome <- turnMonster face creature_ref
+ applyEffect turn_outcome
ranged_attack_model <- rangedAttackModel creature_ref
_ <- atomic executeAttackChain $ resolveAttackChain ranged_attack_model (Left face)
- dbAdvanceTime creature_ref =<< actionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
return ()
dbBehave_ (FacingBehavior Attack face) creature_ref =
- do _ <- move creature_ref =<< turnMonster face creature_ref
+ do turn_outcome <- turnMonster face creature_ref
+ applyEffect turn_outcome
melee_attack_model <- meleeAttackModel creature_ref
_ <- atomic executeAttackChain $ resolveAttackChain melee_attack_model (Left face)
- dbAdvanceTime creature_ref =<< actionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
return ()
-dbBehave_ Wait creature_ref = dbAdvanceTime creature_ref =<< actionTime creature_ref
+dbBehave_ Wait creature_ref = increaseTime creature_ref =<< actionTime creature_ref
dbBehave_ Vanish creature_ref =
- do dbAdvanceTime creature_ref =<< actionTime creature_ref
+ do increaseTime creature_ref =<< actionTime creature_ref
(Parent plane_ref :: Parent Plane) <- liftM detail $ getPlanarLocation creature_ref
faction <- getMonsterFaction creature_ref
is_visible_to_anyone_else <- liftM (any (genericReference creature_ref `elem`)) $
@@ -180,50 +165,27 @@ dbBehave_ Vanish creature_ref =
dbBehave_ Activate creature_ref =
do _ <- atomic executeActivation $ resolveActivation creature_ref
- dbAdvanceTime creature_ref =<< actionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
return ()
dbBehave_ (Make make_prep) creature_ref =
do _ <- atomic executeMake $ resolveMake creature_ref make_prep
- dbAdvanceTime creature_ref =<< actionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
return ()
dbBehave_ (FacingBehavior ClearTerrain face) creature_ref =
- do _ <- move creature_ref =<< turnMonster face creature_ref
+ do turn_outcome <- turnMonster face creature_ref
+ applyEffect turn_outcome
ok <- modifyFacingTerrain clearTerrain face creature_ref
when (not ok) $ throwError $ DBErrorFlag Unable
- dbAdvanceTime creature_ref =<< actionTime creature_ref
+ increaseTime creature_ref =<< actionTime creature_ref
return ()
dbBehave_ (FacingBehavior ActivateBuilding face) creature_ref =
- do _ <- move creature_ref =<< turnMonster face creature_ref
+ do turn_outcome <- turnMonster face creature_ref
+ applyEffect turn_outcome
ok <- activateFacingBuilding face creature_ref
when (not ok) $ throwError $ DBErrorFlag Unable
- dbAdvanceTime creature_ref =<< actionTime creature_ref
-
-{---------------------------------------------------------------------------------------------------
--- These are functions related to determing how long it takes for a creature to execute an action.
-----------------------------------------------------------------------------------------------------}
-
-getBaseSpeed :: (DBReadable db) => MonsterRef -> db Integer
-getBaseSpeed creature_ref =
- do c <- dbGetMonster creature_ref
- let raw_speed = rawScore Speed c
- when (raw_speed <= 0) $ error $ "getBaseSpeed: Non-positive raw speed (" ++ show c ++ ")"
- return raw_speed
-
--- | Time required to do a simple physical task.
-actionTime :: (DBReadable db) => MonsterRef -> db Rational
-actionTime creature_ref =
- do raw_speed <- getBaseSpeed creature_ref
- return $ 1000 % (1000 + raw_speed)
-
--- | Time required to move one step.
-move1ActionTime :: (DBReadable db) => MonsterRef -> db Rational
-move1ActionTime creature_ref =
- do raw_speed <- getBaseSpeed creature_ref
- return $ 100 % (100+raw_speed)
-
--- | Time required to move diagonally one step.
-move2ActionTime :: (DBReadable db) => MonsterRef -> db Rational
-move2ActionTime = liftM (*1.4142) . move1ActionTime
+ increaseTime creature_ref =<< actionTime creature_ref
+
+
@@ -9,7 +9,7 @@ import Roguestar.Lib.Data.ToolData
import Roguestar.Lib.Core.Monster
import Roguestar.Lib.DB
import Control.Monad.Error
-import Roguestar.Lib.Substances
+import Roguestar.Lib.Data.Substances
-- | Outcome of activating a tool.
data ActivationOutcome =
@@ -32,4 +32,5 @@ modifyFacingTerrain f face creature_ref = liftM (fromMaybe False) $ runMaybeT $
clearTerrain :: Terrain -> Terrain
clearTerrain RockFace = RockyGround
clearTerrain Forest = Grass
+clearTerrain ForceField = RockyGround
clearTerrain x = x
@@ -0,0 +1,61 @@
+{-# LANGUAGE Rank2Types #-}
+
+module Roguestar.Lib.Behavior.Outcome
+ (Effect(..),
+ Outcome(..),
+ FailureMode(..),
+ OutcomeWithEffect(..),
+ HasDuration(..))
+ where
+
+import Roguestar.Lib.DB
+
+-- | An effect or consequence in the game world.
+class Effect e where
+ applyEffect :: e -> DB ()
+
+instance Effect (DB x) where
+ applyEffect effect = effect >> return ()
+
+-- | A failure mode: Abort means that the attempt was so obviously never possible that we should pretend the user (or AI, if an AI bug) never attempted.
+-- An example of an Abort would be picking up an object that isn't nearby, or trying to go downstairs when there are no stairs.
+data FailureMode = Success | Failure | Abort
+
+-- | A primary outcome of a character's action.
+class Outcome e where
+ failureMode :: e -> FailureMode
+
+instance (Effect e) => Effect [e] where
+ applyEffect es = mapM_ applyEffect es
+
+instance (Effect a, Effect b) => Effect (a,b) where
+ applyEffect (a,b) = applyEffect a >> applyEffect b
+
+instance (Effect a, Effect b, Effect c) => Effect (a,b,c) where
+ applyEffect (a,b,c) = applyEffect a >> applyEffect b >> applyEffect c
+
+instance (Effect a) => Effect (Maybe a) where
+ applyEffect = maybe (return ()) applyEffect
+
+instance (Outcome a) => Outcome (Maybe a) where
+ failureMode = maybe Abort failureMode
+
+-- | An outcome (success or failure) with an effect (consequences of the outcome). If the outcome is also an effect (that is, it implements both classes),
+-- then it must in both the outcome component and the effect component.
+data OutcomeWithEffect o e = OutcomeWithEffect {
+ _owe_outcome :: o,
+ _owe_effect :: e,
+ owe_duration :: (DBReadable db) => db Rational }
+
+instance (Effect e) => Effect (OutcomeWithEffect o e) where
+ applyEffect (OutcomeWithEffect _ e _) = applyEffect e
+
+instance (Outcome o) => Outcome (OutcomeWithEffect o e) where
+ failureMode (OutcomeWithEffect o _ _) = failureMode o
+
+class HasDuration a where
+ getDuration :: (DBReadable db) => a -> db Rational
+
+instance HasDuration (OutcomeWithEffect o e) where
+ getDuration = owe_duration
+
Oops, something went wrong.

0 comments on commit 8efa521

Please sign in to comment.