MEGS - This is the economy gamescript running on Midgard, a public OpenTTD server. It's a heavily changed version of https://openttd-polska.pl/Thread-Inne-Projekt-skrypt-New-World-Disorder

config.nut 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. class Config
  5. {
  6. static TransportCargo =
  7. {
  8. PASS = 1.0
  9. MAIL = 0.5
  10. };
  11. static BuildCargoMultipier =
  12. { /* autofilled */ };
  13. static IndustryMultipier =
  14. { /* autofilled */ };
  15. static TradeCargoMultipier =
  16. { /* autofilled */ };
  17. static StationDistance = 20.0;
  18. static IndustryDistance = 60.0;
  19. static NonNearestMultipier = 0.5;
  20. static UpdateInterval = 31;
  21. static function Init ()
  22. {
  23. local cargoValues = GSCargoList();
  24. cargoValues.Valuate(GSCargo.GetCargoIncome, 20, 30);
  25. local max = 0;
  26. for (local cargoId = cargoValues.Begin(); !cargoValues.IsEnd(); cargoId = cargoValues.Next()) {
  27. if (max < cargoValues.GetValue(cargoId))
  28. max = cargoValues.GetValue(cargoId);
  29. }
  30. cargoValues.Valuate(function(cargoId, max) {
  31. return ((GSCargo.GetCargoIncome(cargoId, 20, 30)/(max).tofloat())*100).tointeger();
  32. }, max);
  33. local list = GSCargoList();
  34. for (local v = list.Begin(); !list.IsEnd(); v = list.Next())
  35. {
  36. local cargoLabel = GSCargo.GetCargoLabel(v);
  37. if (cargoLabel in Config.TransportCargo)
  38. {
  39. Config.TransportCargo[v] <- Config.TransportCargo[cargoLabel];
  40. delete Config.TransportCargo[cargoLabel];
  41. //GSLog.Info("Transport " + cargoLabel + " ratio: " + Config.TransportCargo[v]);
  42. }
  43. else
  44. {
  45. Config.TradeCargoMultipier[v] <- cargoValues.GetValue(v)/50.0;
  46. //GSLog.Info("Trade " + cargoLabel + " ratio: " + Config.TradeCargoMultipier[v]);
  47. }
  48. }
  49. local list = GSIndustryTypeList();
  50. local prodIndustry = GSList();
  51. local procIndustry = GSList();
  52. for (local industryId = list.Begin(); !list.IsEnd(); industryId = list.Next()) {
  53. if (GSIndustryType.IsRawIndustry(industryId)) {
  54. prodIndustry.AddItem(industryId, 0);
  55. } else {
  56. local onlyPass = true;
  57. local accepting = GSIndustryType.GetAcceptedCargo(GSIndustry.GetIndustryType(industryId));
  58. if (accepting != null) {
  59. foreach (c,_ in accepting) {
  60. if (!GSCargo.HasCargoClass(c, GSCargo.CC_PASSENGERS))
  61. onlyPass = false;
  62. }
  63. }
  64. if (onlyPass)
  65. prodIndustry.AddItem(industryId, 0);
  66. else
  67. procIndustry.AddItem(industryId, 0);
  68. }
  69. }
  70. for (local industryId = prodIndustry.Begin(); !prodIndustry.IsEnd(); industryId = prodIndustry.Next())
  71. {
  72. local industryCargoList = GSIndustryType.GetProducedCargo(industryId);
  73. for (local cargoId = industryCargoList.Begin(); !industryCargoList.IsEnd(); cargoId = industryCargoList.Next()) {
  74. local cargoLabel = GSCargo.GetCargoLabel(cargoId);
  75. if (cargoId in Config.BuildCargoMultipier)
  76. continue;
  77. if (!GSCargo.HasCargoClass(cargoId, GSCargo.CC_PASSENGERS)) {
  78. local cargoPaymentRatio = cargoValues.GetValue(cargoId)/50.0;
  79. //GSLog.Info("Raw " + cargoLabel + " ratio: " + cargoPaymentRatio);
  80. Config.BuildCargoMultipier[cargoId] <- cargoPaymentRatio;
  81. }
  82. }
  83. }
  84. for (local industryId = procIndustry.Begin(); !procIndustry.IsEnd(); industryId = procIndustry.Next())
  85. {
  86. local industryCargoList = GSIndustryType.GetProducedCargo(industryId);
  87. for (local cargoId = industryCargoList.Begin(); !industryCargoList.IsEnd(); cargoId = industryCargoList.Next()) {
  88. local cargoLabel = GSCargo.GetCargoLabel(cargoId);
  89. if (cargoId in Config.IndustryMultipier)
  90. continue;
  91. if (!GSCargo.HasCargoClass(cargoId, GSCargo.CC_PASSENGERS)) {
  92. local cargoPaymentRatio = cargoValues.GetValue(cargoId)/50.0;
  93. //GSLog.Info("Processed " + cargoLabel + " ratio: " + cargoPaymentRatio);
  94. Config.IndustryMultipier[cargoId] <- cargoPaymentRatio;
  95. }
  96. }
  97. }
  98. }
  99. }
  100. Config.Init ();