MooingCat

MooingCat's Road Efficiency Script

Feb 5th, 2021 (edited)
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var total_sides = [0,0];
  2. var buildings = [0,0]
  3. var road_tiles = [0,0];
  4. var excluded_types = ["hub_main","hub_part","friends_tavern","outpost_ship","off_grid"]
  5. for (var i in MainParser.CityMapData){
  6.     if(excluded_types.indexOf(MainParser.CityMapData[i].type) > -1){continue}
  7.     if(MainParser.CityMapData[i].type == "street"){
  8.         var r = 1;
  9.         if(MainParser.CityMapData[i].connected == 2){r = 2;}
  10.         road_tiles[r-1] = road_tiles[r-1] + Math.pow(r,2);
  11.         continue;
  12.     }
  13.     var entity = MainParser.CityEntities[MainParser.CityMapData[i].cityentity_id]
  14.     if(!entity.requirements.hasOwnProperty("street_connection_level") || !MainParser.CityMapData[i].hasOwnProperty("connected")){continue}
  15.     var b = 0;
  16.     if(entity.requirements.street_connection_level == 2){b = 1;}
  17.     total_sides[b] = total_sides[b] + Math.min(entity.length,entity.width)*entity.requirements.street_connection_level;
  18.     buildings[b] += 1
  19. }
  20. console.log("Score = 100% * (0.5 * buildings * average_shortest_side / road_tiles)");
  21. // Explanation: https://old.reddit.com/r/forgeofempires/comments/kr1it0/road_efficiency_a_metric_for_an_efficient_city/gi8h0ut/
  22. console.log("Without unconnected buildings (that require roads) \n" +
  23. "1x1 Road -\t" +
  24. "Score: " + Math.round((1000*0.5*total_sides[0]/road_tiles[0]))/10 + " %  \t | Road tiles: " + road_tiles[0] + "    \t | Buildings: " + buildings[0] + "    \t | Avg. Side: " + Math.round(total_sides[0]/buildings[0]*100)/100 + "\n" +
  25. "2x2 Road -\t" +
  26. "Score: " + Math.round((1000*0.5*total_sides[1]/road_tiles[1]))/10 + " %  \t | Road tiles: " + road_tiles[1] + "    \t | Buildings: " + buildings[1] + "     \t | Avg. Side: " + Math.round((total_sides[1]/buildings[1]*100)/100)/2 + "\n" +
  27. "Combined -\t" +
  28. "Score: " + Math.round((1000*0.5*(total_sides[0]+total_sides[1])/(road_tiles[0]+road_tiles[1])))/10 + " %  \t | Road tiles: " + (road_tiles[0]+road_tiles[1]) + "    \t | Buildings: " + (buildings[0]+buildings[1]) + "    \t | Avg. Side: " + Math.round((total_sides[0]+total_sides[1]/2)/(buildings[0]+buildings[1])*100)/100);
  29.  
  30. total_sides = [0,0];
  31. buildings = [0,0]
  32. road_tiles = [0,0];
  33. excluded_types = ["hub_main","hub_part","friends_tavern","outpost_ship","off_grid"]
  34. for (var i in MainParser.CityMapData){
  35.     if(excluded_types.indexOf(MainParser.CityMapData[i].type) > -1){continue}
  36.     if(MainParser.CityMapData[i].type == "street"){
  37.         var r = 1;
  38.         if(MainParser.CityMapData[i].connected == 2){r = 2;}
  39.         road_tiles[r-1] = road_tiles[r-1] + Math.pow(r,2);
  40.         continue;
  41.     }
  42.     var entity = MainParser.CityEntities[MainParser.CityMapData[i].cityentity_id]
  43.     if(!entity.requirements.hasOwnProperty("street_connection_level")){continue}
  44.     var b = 0;
  45.     if(entity.requirements.street_connection_level == 2){b = 1;}
  46.     total_sides[b] = total_sides[b] + Math.min(entity.length,entity.width)*entity.requirements.street_connection_level;
  47.     buildings[b] += 1
  48. }
  49. console.log("With unconnected buildings (that require roads) \n" +
  50. "1x1 Road -\t" +
  51. "Score: " + Math.round((1000*0.5*total_sides[0]/road_tiles[0]))/10 + " %  \t | Road tiles: " + road_tiles[0] + "    \t | Buildings: " + buildings[0] + "    \t | Avg. Side: " + Math.round(total_sides[0]/buildings[0]*100)/100 + "\n" +
  52. "2x2 Road -\t" +
  53. "Score: " + Math.round((1000*0.5*total_sides[1]/road_tiles[1]))/10 + " %  \t | Road tiles: " + road_tiles[1] + "    \t | Buildings: " + buildings[1] + "     \t | Avg. Side: " + Math.round((total_sides[1]/buildings[1]*100)/100)/2 + "\n" +
  54. "Combined -\t" +
  55. "Score: " + Math.round((1000*0.5*(total_sides[0]+total_sides[1])/(road_tiles[0]+road_tiles[1])))/10 + " %  \t | Road tiles: " + (road_tiles[0]+road_tiles[1]) + "    \t | Buildings: " + (buildings[0]+buildings[1]) + "    \t | Avg. Side: " + Math.round((total_sides[0]+total_sides[1]/2)/(buildings[0]+buildings[1])*100)/100);
  56.  
  57. var total = (CityMap.UnlockedAreas.length-1)*16+256;
  58. var roads = road_tiles[0] + road_tiles[1];
  59. var cle = Math.round(100*(total-roads)/roads)/100;
  60. console.log("CLE: " + cle + "\t\t (total tiles - road tiles) / road tiles");
Add Comment
Please, Sign In to add comment