pluginnutritiondumper.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. class PluginNutritionDumper extends PluginBase
  2. {
  3. /*
  4. ref TStringArray m_AllPaths = new TStringArray;
  5. ref TStringArray m_AllLines = new TStringArray;
  6. ref map<string, int> m_ParamPool = new map<string, int>;
  7. string config_path;
  8. string child_name;
  9. int scope;
  10. string path;
  11. PlayerBase m_Player;
  12. override void OnInit()
  13. {
  14. m_AllPaths.Insert("CfgVehicles");
  15. m_AllPaths.Insert("cfgLiquidDefinitions");
  16. m_Player = PlayerBase.Cast(GetGame().GetPlayer());
  17. }
  18. void CheckInit()
  19. {
  20. m_AllLines.Clear();
  21. string line = "Classname(stage),energy,water,toxicity,fullnessIndex,nutritionalIndex";
  22. m_AllLines.Insert(line);
  23. for(int i = 0; i < m_AllPaths.Count(); i++)
  24. {
  25. config_path = m_AllPaths.Get(i);
  26. int children_count = GetGame().ConfigGetChildrenCount(config_path);
  27. for(int x = 0; x < children_count; x++)
  28. {
  29. GetGame().ConfigGetChildName(config_path, x, child_name);
  30. path = config_path + " " + child_name;
  31. scope = GetGame().ConfigGetInt( config_path + " " + child_name + " scope" );
  32. bool should_check = 1;
  33. if( config_path == "CfgVehicles" && scope == 0)
  34. {
  35. should_check = 0;
  36. }
  37. if ( should_check )
  38. {
  39. bool has_nutrition = GetGame().ConfigIsExisting(path + " Nutrition");
  40. bool has_stages = GetGame().ConfigIsExisting(path + " Food");
  41. if(has_nutrition || has_stages)
  42. {
  43. EntityAI item = PlayerBase.Cast(GetGame().GetPlayer()).SpawnEntityOnGroundOnCursorDir(child_name,1);
  44. Edible_Base edible = Edible_Base.Cast(item);
  45. if(edible)
  46. {
  47. //Print("spawning " + child_name);
  48. line = "";
  49. NutritionalProfile profile;
  50. if(!has_stages)
  51. {
  52. profile = edible.GetNutritionalProfile();
  53. line = BuildLine(child_name, profile);
  54. m_AllLines.Insert(line);
  55. //Print(line);
  56. }
  57. else
  58. {
  59. for(int z = FoodStageType.RAW; z < FoodStageType.COUNT; z++)
  60. {
  61. if( z != FoodStageType.RAW )
  62. edible.ChangeFoodStage(z);
  63. profile = edible.GetNutritionalProfile();
  64. string itemname = child_name + "(stage " + z.ToString()+")";
  65. line = BuildLine(itemname, profile);
  66. m_AllLines.Insert(line);
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. SaveToFile("nutritional_values.csv");
  75. }
  76. protected void SaveToFile(string filename)
  77. {
  78. FileHandle file = OpenFile(filename, FileMode.WRITE);
  79. if( file!=0 )
  80. {
  81. for(int i = 0; i < m_AllLines.Count(); i++)
  82. {
  83. FPrintln(file,m_AllLines.Get(i));
  84. Print(m_AllLines.Get(i));
  85. }
  86. }
  87. }
  88. string BuildLine(string item_name, NutritionalProfile profile)
  89. {
  90. string line = item_name+",";
  91. line = line + profile.GetEnergy()+",";
  92. line = line + profile.GetWaterContent()+",";
  93. line = line + profile.GetToxicity()+",";
  94. line = line + profile.GetFullnessIndex()+",";
  95. line = line + profile.GetNutritionalIndex();
  96. return line;
  97. }
  98. */
  99. }