outline and randomness. Afterfix now tackles if necessary
[fp1415-soccerfun.git] / src / Game / matchControl.icl
index e0505c0..f52e843 100644 (file)
@@ -22,6 +22,16 @@ instance toString  Seconds where toString  (Seconds s)                               = s +++> " sec."
 doSoccerFun :: !*World -> *World\r
 doSoccerFun world                                                      = SoccerFunGUI2D world\r
 \r
+simulationGranularity :: Seconds\r
+simulationGranularity = s 0.05\r
+\r
+// the original simulation expected to run at 0.1s; this function is used to adjust it to different rates\r
+rateAdjust :: (Real -> Real)\r
+rateAdjust = case simulationGranularity of\r
+                                       Seconds 0.1  -> id\r
+                                       Seconds 0.05 -> sqrt\r
+                                       Seconds x        -> \y -> y^(10.0*x)\r
+\r
 setMatchStart :: !Team !Team !FootballField !Referee !PlayingTime !RandomSeed -> Match\r
 setMatchStart fstTeam sndTeam field referee time rs\r
        = { team1                                                               = validateTeam fstTeam\r
@@ -31,7 +41,7 @@ setMatchStart fstTeam sndTeam field referee time rs
          , theReferee                                                  = referee\r
          , playingHalf                                                 = FirstHalf\r
          , playingTime                                                 = time\r
-         , unittime                                                    = s 0.05\r
+         , unittime                                                    = simulationGranularity\r
          , score                                                               = (0,0)\r
          , nextRandomP                                                 = nextRandomP\r
          , seed                                                                = rs\r
@@ -266,7 +276,7 @@ where
                                angleDifficulty                         = angleHowFarFromPi   (speed.direction-new_nose)\r
                                angleDifference                         = angleHowFarFromAngle speed.direction new_nose\r
                                new_stamina                                     = alter_stamina ball fb angleDifficulty angleDifference\r
-                               new_vel                                         = scale (1.4 * fb.health * new_stamina) (setbetween speed.velocity zero (maxVelocity (skillsAsList fb) angleDifficulty angleDifference))\r
+                               new_vel                                         = scale (fb.health * new_stamina) (setbetween speed.velocity zero (maxVelocity (skillsAsList fb) angleDifficulty angleDifference))\r
                                new_speed                                       = {speed & velocity=new_vel}\r
                                new_position`                           = move_point (scale (dt * (toReal new_vel)) (toRVector new_speed.direction)) fb.pos\r
                                new_position                            = point_to_rectangle ({px=scale -0.5 flength, py=scale -0.5 fwidth},{px=scale 0.5 flength,py=scale 0.5 fwidth}) new_position` \r
@@ -404,7 +414,7 @@ where
        where\r
                old_height                                                      = ballPos.pz\r
                in_the_air                                                      = old_height > zero\r
-               resistance                                                      = if in_the_air air_resistance surface_resistance\r
+               resistance                                                      = rateAdjust if in_the_air air_resistance surface_resistance\r
                dt                                                                      = toReal unittime\r
                surface_movement                                        = scale (dt * (toReal v)) (toRVector d)\r
                new_speed2D                                                     = let new_v = scale resistance v in {direction = d, velocity = if (new_v <= ms 0.05) zero new_v}\r
@@ -470,18 +480,18 @@ alter_stamina :: !FootballState !Footballer !Angle !Angle -> Stamina
 alter_stamina ballState fb angleDifficulty angleDifference\r
 | velocity <= rfv                                                                                      // increase stamina\r
        | stamina < MinimumFatigue                              = MinimumFatigue\r
-       | otherwise                                                             = stamina^0.8   \r
-| otherwise                                                                    = fatigue * factor\r
+       | otherwise                                                             = stamina^(rateAdjust 0.8)\r
+| otherwise                                                                    = fatigue * (rateAdjust factor)\r
 where\r
        velocity                                                                = fb.speed.velocity\r
        length                                                                  = fb.length\r
        stamina                                                                 = fb.stamina\r
        rfv                                                                             = restore_stamina_velocity (ballIsGainedBy fb.playerID ballState) (skillsAsList fb) angleDifficulty angleDifference\r
        diff                                                                    = velocity - rfv\r
-       fv                                                                              = if (diff >= ms 6.0) (stamina^(stamina^(1.6 + 0.02 * toReal length)))\r
-                                                                                        (if (diff >= ms 4.0) (stamina^(         1.5 + 0.01 * toReal length))\r
-                                                                                        (if (diff >= ms 2.0) (stamina^(         1.4 - 0.01 * toReal length))\r
-                                                                                                                         (stamina^(         1.3 - 0.02 * toReal length))))\r
+       fv                                                                              = if (diff >= ms 6.0) (stamina^rateAdjust (stamina^(1.6 + 0.02 * toReal length)))  // problematic\r
+                                                                                        (if (diff >= ms 4.0) (stamina^rateAdjust (         1.5 + 0.01 * toReal length))\r
+                                                                                        (if (diff >= ms 2.0) (stamina^rateAdjust (         1.4 - 0.01 * toReal length))\r
+                                                                                                             (stamina^rateAdjust (         1.3 - 0.02 * toReal length))))\r
        factor                                                                  = one - (toReal angleDifficulty)/(4.0*pi)\r
        fatigue                                                                 = if (stamina > MaximumFatigue) MaximumFatigue fv\r
 \r