spMonsterBerserk :: Ref EdictT -> Quake ()
spMonsterBerserk selfRef = do
    deathmatchValue <- liftM (^.cvValue) deathmatchCVar

    if deathmatchValue /= 0
      then
        GameUtil.freeEdict selfRef

      else do
        gameImport <- use $ gameBaseGlobals.gbGameImport

        let soundIndex = gameImport^.giSoundIndex
            modelIndex = gameImport^.giModelIndex
            linkEntity = gameImport^.giLinkEntity

        soundIndex (Just "berserk/berpain2.wav") >>= (mBerserkGlobals.mBerserkSoundPain .=)
        soundIndex (Just "berserk/berdeth2.wav") >>= (mBerserkGlobals.mBerserkSoundDie .=)
        soundIndex (Just "berserk/beridle1.wav") >>= (mBerserkGlobals.mBerserkSoundIdle .=)
        soundIndex (Just "berserk/attack.wav") >>= (mBerserkGlobals.mBerserkSoundPunch .=)
        soundIndex (Just "berserk/bersrch1.wav") >>= (mBerserkGlobals.mBerserkSoundSearch .=)
        soundIndex (Just "berserk/sight.wav") >>= (mBerserkGlobals.mBerserkSoundSight .=)

        modelIdx <- modelIndex (Just "models/monsters/berserk/tris.md2")

        modifyRef selfRef (\v -> v & eEntityState.esModelIndex .~ modelIdx
                                      & eMins .~ V3 (-16) (-16) (-24)
                                      & eMaxs .~ V3 16 16 32
                                      & eMoveType .~ Constants.moveTypeStep
                                      & eSolid .~ Constants.solidBbox
                                      & eHealth .~ 240
                                      & eGibHealth .~ (-60)
                                      & eMass .~ 250
                                      & ePain .~ Just berserkPain
                                      & eDie .~ Just berserkDie
                                      & eMonsterInfo.miStand .~ Just berserkStand
                                      & eMonsterInfo.miWalk .~ Just berserkWalk
                                      & eMonsterInfo.miRun .~ Just berserkRun
                                      & eMonsterInfo.miDodge .~ Nothing
                                      & eMonsterInfo.miAttack .~ Nothing
                                      & eMonsterInfo.miMelee .~ Just berserkMelee
                                      & eMonsterInfo.miSight .~ Just berserkSight
                                      & eMonsterInfo.miSearch .~ Just berserkSearch
                                      & eMonsterInfo.miCurrentMove .~ Just berserkMoveStand
                                      & eMonsterInfo.miScale .~ modelScale)

        linkEntity selfRef

        void $ think GameAI.walkMonsterStart selfRef
spMonsterBerserk :: Ref EdictT -> Quake ()
spMonsterBerserk selfRef = do
    deathmatchValue <- liftM (^.cvValue) deathmatchCVar

    if deathmatchValue /= 0
      then
        GameUtil.freeEdict selfRef

      else do
        gameImport <- use $ gameBaseGlobals.gbGameImport

        let soundIndex = gameImport^.giSoundIndex
            modelIndex = gameImport^.giModelIndex
            linkEntity = gameImport^.giLinkEntity

        soundIndex (Just "berserk/berpain2.wav") >>= (mBerserkGlobals.mBerserkSoundPain .=)
        soundIndex (Just "berserk/berdeth2.wav") >>= (mBerserkGlobals.mBerserkSoundDie .=)
        soundIndex (Just "berserk/beridle1.wav") >>= (mBerserkGlobals.mBerserkSoundIdle .=)
        soundIndex (Just "berserk/attack.wav") >>= (mBerserkGlobals.mBerserkSoundPunch .=)
        soundIndex (Just "berserk/bersrch1.wav") >>= (mBerserkGlobals.mBerserkSoundSearch .=)
        soundIndex (Just "berserk/sight.wav") >>= (mBerserkGlobals.mBerserkSoundSight .=)

        modelIdx <- modelIndex (Just "models/monsters/berserk/tris.md2")

        modifyRef selfRef (\v -> v & eEntityState.esModelIndex .~ modelIdx
                                      & eMins .~ V3 (-16) (-16) (-24)
                                      & eMaxs .~ V3 16 16 32
                                      & eMoveType .~ Constants.moveTypeStep
                                      & eSolid .~ Constants.solidBbox
                                      & eHealth .~ 240
                                      & eGibHealth .~ (-60)
                                      & eMass .~ 250
                                      & ePain .~ Just berserkPain
                                      & eDie .~ Just berserkDie
                                      & eMonsterInfo.miStand .~ Just berserkStand
                                      & eMonsterInfo.miWalk .~ Just berserkWalk
                                      & eMonsterInfo.miRun .~ Just berserkRun
                                      & eMonsterInfo.miDodge .~ Nothing
                                      & eMonsterInfo.miAttack .~ Nothing
                                      & eMonsterInfo.miMelee .~ Just berserkMelee
                                      & eMonsterInfo.miSight .~ Just berserkSight
                                      & eMonsterInfo.miSearch .~ Just berserkSearch
                                      & eMonsterInfo.miCurrentMove .~ Just berserkMoveStand
                                      & eMonsterInfo.miScale .~ modelScale)

        linkEntity selfRef

        void $ think GameAI.walkMonsterStart selfRef
spMonsterBerserk selfRef = do
    deathmatchValue <- liftM (^.cvValue) deathmatchCVar

    if deathmatchValue /= 0
      then
        GameUtil.freeEdict selfRef

      else do
        gameImport <- use $ gameBaseGlobals.gbGameImport

        let soundIndex = gameImport^.giSoundIndex
            modelIndex = gameImport^.giModelIndex
            linkEntity = gameImport^.giLinkEntity

        soundIndex (Just "berserk/berpain2.wav") >>= (mBerserkGlobals.mBerserkSoundPain .=)
        soundIndex (Just "berserk/berdeth2.wav") >>= (mBerserkGlobals.mBerserkSoundDie .=)
        soundIndex (Just "berserk/beridle1.wav") >>= (mBerserkGlobals.mBerserkSoundIdle .=)
        soundIndex (Just "berserk/attack.wav") >>= (mBerserkGlobals.mBerserkSoundPunch .=)
        soundIndex (Just "berserk/bersrch1.wav") >>= (mBerserkGlobals.mBerserkSoundSearch .=)
        soundIndex (Just "berserk/sight.wav") >>= (mBerserkGlobals.mBerserkSoundSight .=)

        modelIdx <- modelIndex (Just "models/monsters/berserk/tris.md2")

        modifyRef selfRef (\v -> v & eEntityState.esModelIndex .~ modelIdx
                                      & eMins .~ V3 (-16) (-16) (-24)
                                      & eMaxs .~ V3 16 16 32
                                      & eMoveType .~ Constants.moveTypeStep
                                      & eSolid .~ Constants.solidBbox
                                      & eHealth .~ 240
                                      & eGibHealth .~ (-60)
                                      & eMass .~ 250
                                      & ePain .~ Just berserkPain
                                      & eDie .~ Just berserkDie
                                      & eMonsterInfo.miStand .~ Just berserkStand
                                      & eMonsterInfo.miWalk .~ Just berserkWalk
                                      & eMonsterInfo.miRun .~ Just berserkRun
                                      & eMonsterInfo.miDodge .~ Nothing
                                      & eMonsterInfo.miAttack .~ Nothing
                                      & eMonsterInfo.miMelee .~ Just berserkMelee
                                      & eMonsterInfo.miSight .~ Just berserkSight
                                      & eMonsterInfo.miSearch .~ Just berserkSearch
                                      & eMonsterInfo.miCurrentMove .~ Just berserkMoveStand
                                      & eMonsterInfo.miScale .~ modelScale)

        linkEntity selfRef

        void $ think GameAI.walkMonsterStart selfRef