korstudio

Train transport rate

May 8th, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculateCost(d:Number, type:int):int {
  2.     var count:int = 0;
  3.     var cost:Number = 0;
  4.     while(count < 4 && d > 0){
  5.         if(d >= 100 && count < 3) cost += 100*getTypeCost(type, count);
  6.         else if(d > 0) cost += Math.ceil(d)*getTypeCost(type, count);
  7.         d -= 100;
  8.         count++;
  9.     }
  10.     return Math.round(cost);
  11. }
  12. function getTypeCost(type:int, count:int):Number {
  13.     switch (type){
  14.         case 1: return (count == 0?0.932:(count==1?0.853:(count==2?0.785:0.739)));
  15.         case 2: return (count == 0?0.488:(count==1?0.420:(count==2?0.375:0.336)));
  16.         case 3: return (count == 0?0.215:(count==1?0.180:(count==2?0.160:0.145)));
  17.     }
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment