Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculateCost(d:Number, type:int):int {
- var count:int = 0;
- var cost:Number = 0;
- while(count < 4 && d > 0){
- if(d >= 100 && count < 3) cost += 100*getTypeCost(type, count);
- else if(d > 0) cost += Math.ceil(d)*getTypeCost(type, count);
- d -= 100;
- count++;
- }
- return Math.round(cost);
- }
- function getTypeCost(type:int, count:int):Number {
- switch (type){
- case 1: return (count == 0?0.932:(count==1?0.853:(count==2?0.785:0.739)));
- case 2: return (count == 0?0.488:(count==1?0.420:(count==2?0.375:0.336)));
- case 3: return (count == 0?0.215:(count==1?0.180:(count==2?0.160:0.145)));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment