Created
February 17, 2023 00:52
-
-
Save gesslar/27dc91641df69c4625c8a4a76126fe18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /cmds/race/_units.c | |
// Short description of this file and its purpose. | |
// | |
// Created: 2013/08/31: Gesslar | |
// Last Change: 2013/08/31: Gesslar | |
// | |
// 2013/08/31: Gesslar - Created | |
inherit STD_CMD ; | |
int execute(object caller, object room, string arg) { | |
int val; | |
float ret; | |
string from ; | |
if(!arg || sscanf(arg, "%d %s", val, from) != 2) { | |
return caller->force_me("help units") ; | |
} | |
from = lower_case(from); | |
if( from == "c" ) { | |
ret = 0.0 + val * 9.0 / 5.0 + 32.0; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Celsius", ret, "Fahrenheit")); | |
return 1; | |
} else if( from == "f" ) { | |
ret = 0.0 + (val - 32.0) * 5.0 / 9.0; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Fahrenheit", ret, "Celsius")); | |
return 1; | |
} else if( from == "mi" ) { | |
ret = 0.0 + (val / 0.62137) ; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Miles", ret, "Kilometers")); | |
return 1; | |
} else if( from == "km" ) { | |
ret = 0.0 + (val * 0.62137) ; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Kilometers", ret, "Miles")); | |
return 1; | |
} else if( from == "l" ) { | |
ret = 0.0 + (val * 0.26417) ; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Liters", ret, "Gallons")); | |
return 1; | |
} else if( from == "gal" ) { | |
ret = 0.0 + (val / 0.26417) ; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Gallons", ret, "Liters")); | |
return 1; | |
} else if( from == "cm" ) { | |
ret = 0.0 + (val * 0.39370) ; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Centimeters", ret, "Inches")); | |
return 1; | |
} else if( from == "in" ) { | |
ret = 0.0 + (val / 0.39370) ; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Inches", ret, "Centimeters")); | |
return 1; | |
} else if( from == "kg" ) { | |
ret = 0.0 + (val * 2.2046) ; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Kilograms", ret, "Pounds")); | |
return 1; | |
} else if( from == "lbs" ) { | |
ret = 0.0 + (val / 2.2046) ; | |
caller->tell(sprintf("%d %s is %.1f %s\n", val, "Pounds", ret, "Kilograms")); | |
return 1; | |
} else { | |
return caller->force_me("help units") ; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment