Stellarcore.net

Stellarcore.net

Here is a Rust version of the script, it is always interesting to work in a new language. There are probably better ways to do this but I followed my old patterns.

fn level_th(number: i32) -> String {
   //Take an interger in but return a String
   let mut number_th = number.to_string();
   if number_th == "11" || number_th == "12" || number_th == "13" {
      number_th.push_str("th");
   } else if number_th.ends_with("1") {
      number_th.push_str("st");
   } else if number_th.ends_with("2") {
      number_th.push_str("nd");
   } else if number_th.ends_with("3") {
      number_th.push_str("rd");
   } else {
      number_th.push_str("th");
   } 
   return number_th;
}

fn main() {
   let max_lvl: i32 = 40;
   //any way to clear screen?
   //Headers
   println!("Char \t \tClass Skill\tCC Skill\t \tStat\t");
   println!("Level\tXP\tMax Ranks\tMax Ranks\tFeats\tIncreases\t");

   //Main loop
   let mut xp: i32  = 0;
   let mut feats: i32 = 0; 
   let mut stats: i32 = 0;

   for level in  1..(max_lvl + 1) {
      xp = xp + (level - 1) * 1000;
      let maxranks: i32 = level + 3;
      let maxcc: f32 = maxranks as f32 / 2.0;

      let feat_check: i32 = level % 3;
      let mut feats_out = "--".to_string();
      if feat_check == 0 || level == 1 {
         feats = feats + 1;
         feats_out = level_th(feats);
      }

      let stat_check = level % 4;
      let mut stats_out = "--".to_string();
      if stat_check == 0 {
         stats = stats + 1;
         stats_out = level_th(stats);
      }

      let level_out = level_th(level);

      println!(" {}\t{}\t\t{}\t\t{}\t{}\t{}", level_out, xp, maxranks, maxcc, feats_out, stats_out);
 
   }

}
//vi: shiftwidth=3 tabstop=3 et