Permalink
Browse files

made everything have it's own Id type.

====================
Preprocessing library WoWSim-0.1...
Preprocessing executables for WoWSim-0.1...
Building WoWSim-0.1...
Registering WoWSim-0.1...
dist/build/WoWSim/WoWSim 6000 +RTS -sstderr
     269,730,480 bytes allocated in the heap
       6,510,156 bytes copied during GC
       1,594,308 bytes maximum residency (3 sample(s))
          47,916 bytes maximum slop
               5 MB total memory in use (0 MB lost due to fragmentation)

  Generation 0:   513 collections,     0 parallel,  0.02s,  0.03s elapsed
  Generation 1:     3 collections,     0 parallel,  0.01s,  0.02s elapsed

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    0.43s  (  0.43s elapsed)
  GC    time    0.04s  (  0.04s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    0.46s  (  0.47s elapsed)

  %GC time       7.8%  (8.7% elapsed)

  Alloc rate    632,969,551 bytes per MUT second

  Productivity  92.0% of total user, 90.3% of total elapsed
  • Loading branch information...
1 parent be29451 commit 42d868f9e49b2f572eafa447b671b2ae4d8110b1 @periodic committed Jun 24, 2011
Showing with 70 additions and 70 deletions.
  1. +1 −1 AI/AutoAttack.hs
  2. +1 −1 AI/Info.hs
  3. +2 −2 AI/Warrior.hs
  4. +1 −1 Actions/Attacks.hs
  5. +10 −10 Actions/Common.hs
  6. +0 −2 Types/Aura.hs
  7. +27 −20 Types/Common.hs
  8. +13 −15 Types/Entity.hs
  9. +9 −9 Types/Event.hs
  10. +0 −2 Types/World.hs
  11. +6 −6 WoWSim.hs
  12. +0 −1 wowsim.cabal
View
@@ -18,4 +18,4 @@ autoAttack _ = return ()
swing = do
resetGCD
- attack "AutoAttack" 100
+ attack (AbilityId "AutoAttack") 100
View
@@ -9,7 +9,7 @@ onGCD = do
t <- getTime
return $ entityOnGCD t s
-abilOnCooldown :: String -> Action Bool
+abilOnCooldown :: AbilityId -> Action Bool
abilOnCooldown name = do
s <- getSource
t <- getTime
View
@@ -22,7 +22,7 @@ rotation = do
then useAbility slam
else useAbility mortalStrike
where
- msName = "MortalStrike"
+ msName = AbilityId "MortalStrike"
mortalStrike =
Ability { _abilName = msName
, _abilCooldown = Just 6
@@ -31,7 +31,7 @@ rotation = do
, _abilSchool = Physical
, _abilAction = weapon msName 2 100
}
- slamName = "Slam"
+ slamName = AbilityId "Slam"
slam =
Ability { _abilName = slamName
, _abilCooldown = Nothing
View
@@ -39,7 +39,7 @@ startAutoAttack = do
addHandler name (autoAttackHandler owner)
after 0 (EvAutoAttackReady owner)
where
- name = "AutoAttack"
+ name = AbilityId "AutoAttack"
autoAttackHandler owner (EvAutoAttackReady eid)
| eid == owner = do
delay <- getL (weaponSpeed <.> eStats) <$> getSource
View
@@ -13,9 +13,9 @@ import System.Random (StdGen)
-- * Functions on Sim
-- | This function lets us transform handlers defined on Action and lift them to Sim.
-makeHandler :: Entity -> (Event -> Action ()) -> Event -> Sim World Event ()
-makeHandler e a ev = do
- mpEntity <- getEntity . (getL eID) $ e
+makeHandler :: EntityId -> (Event -> Action ()) -> Event -> Sim World Event ()
+makeHandler eid a ev = do
+ mpEntity <- getEntity eid
case mpEntity of
Nothing -> return ()
Just pEntity -> do
@@ -51,15 +51,15 @@ after :: DTime -> Event -> Action ()
after t ev = lift $ Sim.after t ev
-- ** Handlers Utilities
-addHandler :: String -> (Event -> Action ()) -> Action()
+addHandler :: (Show a) => a -> (Event -> Action ()) -> Action()
addHandler name handler = do
actionState <- ask
h <- transformHandler handler
- lift $ Sim.addHandler name h
+ lift $ Sim.addHandler (show name) h
-removeHandler :: String -> Action ()
+removeHandler :: (Show a) => a -> Action ()
removeHandler name = do
- lift $ Sim.removeHandler name
+ lift $ Sim.removeHandler (show name)
transformHandler :: (Event -> Action ()) -> Action (Event -> Sim World Event ())
transformHandler h = do
@@ -105,7 +105,7 @@ resetGCD =
src <- getSource
after 1.5 . EvGcdEnd . getL eID $ src
-setCooldown :: String -> Sim.DTime -> Action ()
+setCooldown :: AbilityId -> Sim.DTime -> Action ()
setCooldown name dt =
do t <- getTime
src <- getSource
@@ -129,7 +129,7 @@ registerCast :: DTime -> Ability -> Action ()
registerCast dt abil= do
sid <- getL eID <$> getSource
let aid = getL abilName abil
- handlerName = show sid ++ aid
+ handlerName = show sid ++ show aid
addHandler handlerName (handler sid)
after 0 $ EvCastStarted sid aid
after dt $ EvCastComplete sid aid
@@ -138,7 +138,7 @@ registerCast dt abil= do
if (eid == sid) && (getL abilName abil) == aid
then do getL abilAction abil
sid <- getL eID <$> getSource
- removeHandler (show sid ++ aid)
+ removeHandler (show sid ++ show aid)
else return ()
handler _ _ = return ()
View
@@ -18,5 +18,3 @@ isAuraInMap = member
emptyAuraMap = empty
-instance Show Aura where
- show (Aura id school typ cat f) = printf "Aura { id = %s, school = %s, type = %s, category = %s}" (show id) (show school) (show typ) (show cat)
View
@@ -31,39 +31,43 @@ data SimConfig = SimConfig {
-- * General types
-type HandlerId = String
-type HandlerAction = Event -> Action ()
-type HandlerList = Map String HandlerAction
+type Health = Integer
+type Damage = Integer
+
+-- ** IDs
+newtype EntityId = EntityId String deriving (Eq, Ord)
+instance Show EntityId where
+ show (EntityId name) = "Entity." ++ name
+
+newtype AbilityId = AbilityId String deriving (Eq, Ord)
+instance Show AbilityId where
+ show (AbilityId name) = "Ability." ++ name
+
+newtype AuraId = AuraId String deriving (Eq, Ord)
+instance Show AuraId where
+ show (AuraId name) = "Aura." ++ name
+-- ** Monads
data ActionState = ActionState { _actionSource :: Entity
, _actionTarget :: Entity
} deriving (Show)
type Action = ReaderT ActionState (Sim World Event)
-type Health = Integer
-type Damage = Integer
-
-newtype EntityId = EntityId String
- deriving (Eq, Ord)
-instance Show EntityId where
- show (EntityId name) = name
-
+-- ** Entity
type EntityMap = Map EntityId Entity
data Entity = Entity { _eID :: !EntityId
, _eTarget :: !EntityId
, _eHealth :: !Health
, _eGlobalCD :: !Time
, _eCast :: Maybe (Ability, Time)
- , _eCooldowns :: Map String Time
+ , _eCooldowns :: Map AbilityId Time
, _eStats :: Stats
- , _eHandlers :: HandlerList
- , _eAI :: HandlerAction
, _eAuras :: AuraMap
}
instance Show Entity where
- show (Entity id targ health gcd cast _ _ _ _ _) =
+ show (Entity id targ health gcd cast _ _ _) =
printf "Entity { eId = \"%s\", eTarget = \"%s\", eHealth = %d, eGlobalCD = %d, eCast = %d }"
(show id)
(show targ)
@@ -94,14 +98,15 @@ data Event = EvSimStart
--deriving (Show)
type AbilityMap = Map AbilityId Ability
-type AbilityId = String
data Ability = Ability { _abilName :: AbilityId
, _abilCooldown :: Maybe DTime
, _abilTriggerGCD :: Bool
, _abilCastTime :: DTime
, _abilSchool :: SpellSchool
, _abilAction :: Action ()
}
+instance Show Ability where
+ show (Ability name _ _ _ _ _) = "Ability." ++ (show name)
-- * Auras
-- | Auras come in two flavors, those that buff, and those that don't. The
@@ -124,16 +129,18 @@ data AuraType = BeneficialAura
| DebuffOther
deriving (Show, Eq, Typeable, Data)
-type AuraId = String
type AuraMap = Map AuraId Aura
type BuffMap = Map AuraId Buff
-data Aura = Aura { _auraId :: AuraId
- , _auraSchool :: SpellSchool
- , _auraType :: AuraType
+data Aura = Aura { _auraId :: AuraId
+ , _auraOwner :: EntityId
+ , _auraSchool :: SpellSchool
+ , _auraType :: AuraType
, _buffCategory :: BuffCategory
, _buffFunc :: Buff
}
+instance Show Aura where
+ show (Aura name owner _ _ _ _) = printf "Aura.%s.%s" (show owner) (show name)
-- * Function types
View
@@ -25,17 +25,15 @@ import Types.Aura
-- |Create a default entity.
-makeEntity name targ ai = Entity { _eID = getIdFromString name
- , _eTarget = getIdFromString targ
- , _eHealth = 0
- , _eGlobalCD = 0
- , _eCast = Nothing
- , _eCooldowns = empty
- , _eStats = defaultStats
- , _eHandlers = emptyHandlerList
- , _eAI = ai
- , _eAuras = emptyAuraMap
- }
+makeEntity name targ = Entity { _eID = EntityId name
+ , _eTarget = EntityId targ
+ , _eHealth = 0
+ , _eGlobalCD = 0
+ , _eCast = Nothing
+ , _eCooldowns = empty
+ , _eStats = defaultStats
+ , _eAuras = emptyAuraMap
+ }
-- |Add an entity to the entity map.
addEntityList :: Entity -> EntityMap -> EntityMap
@@ -58,14 +56,14 @@ entityOnGCD :: Time -> Entity -> Bool
entityOnGCD t e = getL eGlobalCD e > t
-- |Test whether the entity has the named ability on cooldown
-entityOnCooldown :: String -> Time -> Entity -> Bool
-entityOnCooldown name t e =
+entityOnCooldown :: AbilityId -> Time -> Entity -> Bool
+entityOnCooldown name t e =
case Data.Map.lookup name (getL eCooldowns e) of
Nothing -> False
Just t' -> t' > t
-- |Add a cooldown to the entity's cooldown map.
-entityAddCooldown :: String -> Time -> Entity -> Entity
+entityAddCooldown :: AbilityId -> Time -> Entity -> Entity
entityAddCooldown name t e = modL eCooldowns (insert name t) e
-- ** Casting related functions
@@ -77,4 +75,4 @@ entityIsCasting t e = case getL eCast e of
-- | Start the cast timer
entityStartCasting :: Time -> Ability -> Entity -> Entity
-entityStartCasting t abil = setL eCast (Just (abil, t))
+entityStartCasting t abil = setL eCast (Just (abil, t))
View
@@ -7,15 +7,15 @@ import Text.Printf
instance Show Event where
show EvSimStart = "Sim Start"
show (EvGcdEnd eid) = printf "GCD end for %s" (show eid)
- show (EvCooldownExpire eid name) = printf "Cooldown Expired for %s's %s" (show eid) name
+ show (EvCooldownExpire eid name) = printf "Cooldown Expired for %s's %s" (show eid) (show name)
show (EvAutoAttackStart eid) = printf "Autoattack started for %s" (show eid)
show (EvAutoAttackStop eid) = printf "Autoattack stopped for %s" (show eid)
show (EvAutoAttackReady eid) = printf "Autoattack ready for %s" (show eid)
- show (EvHit pid tid abil dmg) = printf "%s's %s hit %s for %d" (show pid) abil (show tid) dmg
- show (EvCrit pid tid abil dmg) = printf "%s's %s crit %s for %d" (show pid) abil (show tid) dmg
- show (EvDodge pid tid abil) = printf "%s dodged %s's %s" (show tid) (show pid) abil
- show (EvParry pid tid abil) = printf "%s parried %s's %s" (show tid) (show pid) abil
- show (EvMiss pid tid abil) = printf "%s %s missed %s" (show pid) abil (show tid)
- show (EvCastStarted eid aid) = printf "%s began casting %s" (show eid) aid
- show (EvCastComplete eid aid) = printf "%s completed cast of %s" (show eid) aid
- show (EvCastInterrupted eid aid) = printf "%s's cast of %s was interrupted" (show eid) aid
+ show (EvHit pid tid abil dmg) = printf "%s's %s hit %s for %d" (show pid) (show abil) (show tid) dmg
+ show (EvCrit pid tid abil dmg) = printf "%s's %s crit %s for %d" (show pid) (show abil) (show tid) dmg
+ show (EvDodge pid tid abil) = printf "%s dodged %s's %s" (show tid) (show pid) (show abil)
+ show (EvParry pid tid abil) = printf "%s parried %s's %s" (show tid) (show pid) (show abil)
+ show (EvMiss pid tid abil) = printf "%s %s missed %s" (show pid) (show abil) (show tid)
+ show (EvCastStarted eid aid) = printf "%s began casting %s" (show eid) (show aid)
+ show (EvCastComplete eid aid) = printf "%s completed cast of %s" (show eid) (show aid)
+ show (EvCastInterrupted eid aid) = printf "%s's cast of %s was interrupted" (show eid) (show aid)
View
@@ -9,8 +9,6 @@ module Types.World ( module Types.Common
, entityOnCooldown
, entityAddCooldown
, makeEntity
- -- From Types.EntityId
- , getIdFromString
-- From Types.Ability
, realAbilCastTime
-- From Types.Aura
View
@@ -19,18 +19,18 @@ import AI.Warrior
main = do
[dur] <- getArgs
gen <- newStdGen
- let pEntity = makeEntity "Player" "Target" nullHandler
- tEntity = makeEntity "Target" "Player" nullHandler
+ let pEntity = makeEntity "Player" "Target"
+ tEntity = makeEntity "Target" "Player"
+ pID = getL eID pEntity
entities = addEntityList pEntity . addEntityList tEntity $ empty
-- TODO: move this to Types.World
- world = World { _wEntities = entities
+ world = World { _wEntities = entities
, _wGen = gen
}
- ai = makeHandler pEntity warrior
config = defaultConfig { enableLog = True }
- (t, log, world') = {-# SCC "sim" #-} simulate config world [("Warrior", ai)] EvSimStart (read dur)
+ (t, log, world') = {-# SCC "sim" #-} simulate config world [(show pID, makeHandler pID warrior)] EvSimStart (read dur)
putStrLn . showLog $ log
- let tFinal = Map.lookup (getIdFromString "Target") . getL wEntities $ world'
+ let tFinal = Map.lookup (EntityId "Target") . getL wEntities $ world'
case tFinal of
Just targ -> print $ (t, getL eHealth targ)
Nothing -> print $ (t)
View
@@ -29,4 +29,3 @@ Other-modules: Actions.Attacks,
Executable: WoWSim
Main-is: WoWSim.hs
ghc-options: -rtsopts
-

0 comments on commit 42d868f

Please sign in to comment.