~ubuntu-branches/ubuntu/wily/hedgewars/wily

« back to all changes in this revision

Viewing changes to gameServer/HandlerUtils.hs

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-09-23 10:16:55 UTC
  • mfrom: (1.2.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110923101655-3977th2gc5n0a3pv
Tags: 0.9.16-1
* New upstream version.
 + Downloadable content! Simply click to install any content.
   New voices, hats, maps, themes, translations, music, scripts...
   Hedgewars is now more customisable than ever before! As time goes
   by we will be soliciting community content to feature on this page,
   so remember to check it from time to time. If you decide you want
   to go back to standard Hedgewars, just remove the Data directory
   from your Hedgewars config directory.
 + 3-D rendering! Diorama-like rendering of the game in a variety
   of 3D modes. Let us know which ones work best for you, we didn't
   really have the equipment to test them all.
 + Resizable game window.
 + New utilities! The Time Box will remove one of your hedgehogs
   from the game for a while, protecting from attack until it returns,
   somewhere else on the map. Land spray will allow you to build bridges,
   seal up holes, or just make life unpleasant for your enemies.
 + New single player: Bamboo Thicket, That Sinking Feeling, Newton and
   the Tree and multi-player: The Specialists, Space Invaders,
   Racer - scripts! And a ton more script hooks for scripters
 + New twists on old weapons. Drill strike, seduction and fire have
   been adjusted. Defective mines have been added, rope can attach to
   hogs/crates/barrels again, grenades now have variable bounce (use
   precise key + 1-5). Portal gun is now more usable in flight and
   all game actions are a lot faster.
 + New theme - Golf, dozens of new community hats and a new
   localised Default voice, Ukranian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module HandlerUtils where
 
2
 
 
3
import Control.Monad.Reader
 
4
import qualified Data.ByteString.Char8 as B
 
5
import Data.List
 
6
 
 
7
import RoomsAndClients
 
8
import CoreTypes
 
9
import Actions
 
10
 
 
11
thisClient :: Reader (ClientIndex, IRnC) ClientInfo
 
12
thisClient = do
 
13
    (ci, rnc) <- ask
 
14
    return $ rnc `client` ci
 
15
 
 
16
thisRoom :: Reader (ClientIndex, IRnC) RoomInfo
 
17
thisRoom = do
 
18
    (ci, rnc) <- ask
 
19
    let ri = clientRoom rnc ci
 
20
    return $ rnc `room` ri
 
21
 
 
22
clientNick :: Reader (ClientIndex, IRnC) B.ByteString
 
23
clientNick = liftM nick thisClient
 
24
 
 
25
roomOthersChans :: Reader (ClientIndex, IRnC) [ClientChan]
 
26
roomOthersChans = do
 
27
    (ci, rnc) <- ask
 
28
    let ri = clientRoom rnc ci
 
29
    return $ map (sendChan . client rnc) $ filter (/= ci) (roomClients rnc ri)
 
30
 
 
31
roomSameClanChans :: Reader (ClientIndex, IRnC) [ClientChan]
 
32
roomSameClanChans = do
 
33
    (ci, rnc) <- ask
 
34
    let ri = clientRoom rnc ci
 
35
    let otherRoomClients = map (client rnc) . filter (/= ci) $ roomClients rnc ri
 
36
    let cl = rnc `client` ci
 
37
    let sameClanClients = Prelude.filter (\c -> clientClan c == clientClan cl) otherRoomClients
 
38
    return $ map sendChan sameClanClients
 
39
 
 
40
roomClientsChans :: Reader (ClientIndex, IRnC) [ClientChan]
 
41
roomClientsChans = do
 
42
    (ci, rnc) <- ask
 
43
    let ri = clientRoom rnc ci
 
44
    return $ map (sendChan . client rnc) (roomClients rnc ri)
 
45
 
 
46
thisClientChans :: Reader (ClientIndex, IRnC) [ClientChan]
 
47
thisClientChans = do
 
48
    (ci, rnc) <- ask
 
49
    return [sendChan (rnc `client` ci)]
 
50
 
 
51
answerClient :: [B.ByteString] -> Reader (ClientIndex, IRnC) [Action]
 
52
answerClient msg = liftM ((: []) . flip AnswerClients msg) thisClientChans
 
53
 
 
54
allRoomInfos :: Reader (a, IRnC) [RoomInfo]
 
55
allRoomInfos = liftM ((\irnc -> map (room irnc) $ allRooms irnc) . snd) ask
 
56
 
 
57
clientByNick :: B.ByteString -> Reader (ClientIndex, IRnC) (Maybe ClientIndex)
 
58
clientByNick n = do
 
59
    (_, rnc) <- ask
 
60
    let allClientIDs = allClients rnc
 
61
    return $ find (\clId -> n == nick (client rnc clId)) allClientIDs
 
62