Server: Replace hardcoded hog-related numbers with consts
authorWuzzy <Wuzzy2@mail.ru>
Tue, 17 Jul 2018 22:42:49 +0200
changeset 13504 f747c385b5ba
parent 13503 c5d7376fa58a
child 13505 69f0f437c75a
Server: Replace hardcoded hog-related numbers with consts
gameServer/Consts.hs
gameServer/HWProtoInRoomState.hs
gameServer/Votes.hs
--- a/gameServer/Consts.hs	Tue Jul 17 22:00:15 2018 +0200
+++ b/gameServer/Consts.hs	Tue Jul 17 22:42:49 2018 +0200
@@ -23,3 +23,12 @@
 
 serverVersion :: B.ByteString
 serverVersion = "3"
+
+cHogsPerTeam :: Int
+cHogsPerTeam = 8
+
+cMaxTeams :: Int
+cMaxTeams = 8
+
+cMaxHHs :: Int
+cMaxHHs = 48
--- a/gameServer/HWProtoInRoomState.hs	Tue Jul 17 22:00:15 2018 +0200
+++ b/gameServer/HWProtoInRoomState.hs	Tue Jul 17 22:42:49 2018 +0200
@@ -27,6 +27,7 @@
 import Control.Monad.Reader
 --------------------------------------
 import CoreTypes
+import Consts
 import Utils
 import HandlerUtils
 import RoomsAndClients
@@ -144,7 +145,7 @@
                 AnswerClients roomChans ["HH_NUM", tName, showB $ hhnum newTeam]
                 ]
         where
-        canAddNumber rt = (48::Int) - (sum $ map hhnum rt)
+        canAddNumber rt = (cMaxHHs) - (sum $ map hhnum rt)
         findTeam = find (\t -> tName == teamname t) . teams
         dif = readInt_ difStr
         hhsList [] = []
@@ -153,7 +154,7 @@
         newTeamHHNum rt p = min p (canAddNumber rt)
         maxTeams r
             | roomProto r < 38 = 6
-            | otherwise = 8
+            | otherwise = cMaxTeams
 
 
 handleCmd_inRoom ["REMOVE_TEAM", tName] = do
@@ -196,7 +197,7 @@
             [ProtocolError $ loc "You're not the room master!"]
         else if isNothing maybeTeam then
             []
-        else if hhNumber < 1 || hhNumber > 8 || hhNumber > canAddNumber r + hhnum team then
+        else if hhNumber < 1 || hhNumber > cHogsPerTeam || hhNumber > canAddNumber r + hhnum team then
             [AnswerClients clChan ["HH_NUM", teamName, showB $ hhnum team]]
         else
             [ModifyRoom $ modifyTeam team{hhnum = hhNumber},
@@ -204,7 +205,7 @@
     where
         hhNumber = readInt_ numberStr
         findTeam = find (\t -> teamName == teamname t) . teams
-        canAddNumber = (-) 48 . sum . map hhnum . teams
+        canAddNumber = (-) cMaxHHs . sum . map hhnum . teams
 
 
 
@@ -393,7 +394,7 @@
 handleCmd_inRoom ["MAXTEAMS", n] = roomAdminOnly $ do
     cl <- thisClient
     let m = readInt_ n
-    if m < 2 || m > 8 then
+    if m < 2 || m > cMaxTeams then
         return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/maxteams: specify number from 2 to 8"]]
     else
         return [ModifyRoom (\r -> r{teamsNumberLimit = m})]
@@ -476,7 +477,7 @@
     cl <- thisClient
     let h = readInt_ hhs
 
-    if h > 0 && h <= 8 then
+    if h > 0 && h <= cHogsPerTeam then
         startVote $ VoteHedgehogsPerTeam h
         else
         return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]]
--- a/gameServer/Votes.hs	Tue Jul 17 22:00:15 2018 +0200
+++ b/gameServer/Votes.hs	Tue Jul 17 22:42:49 2018 +0200
@@ -28,6 +28,7 @@
 import Data.Maybe
 import Control.Applicative
 -------------------
+import Consts
 import Utils
 import CoreTypes
 import HandlerUtils
@@ -118,7 +119,7 @@
         let answers = concatMap (\t -> 
                 [ModifyRoom $ modifyTeam t{hhnum = h}
                 , AnswerClients chans ["HH_NUM", teamname t, showB h]]
-                ) $ if length curteams * h > 48 then [] else curteams
+                ) $ if length curteams * h > cMaxHHs then [] else curteams
             ;
             curteams =
                 if isJust $ gameInfo rm then