News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

edit credit per MW of powerline

Started by poppo, January 17, 2026, 05:23:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

poppo

today, the credit per electric(MW) is fixed as 2 in leitung2.h.
I want to edit it for my paksets.

I suggest that credit per MW can be set and editted in settings.

prissi

This is a good idea. I would take a patch for it.

poppo

diff --git a/src/simutrans/dataobj/settings.cc b/src/simutrans/dataobj/settings.cc
index bcc0a3294..67e110fe2 100644
--- a/src/simutrans/dataobj/settings.cc
+++ b/src/simutrans/dataobj/settings.cc
@@ -746,6 +746,13 @@ void settings_t::rdwr(loadsave_t *file)
  file->rdwr_long(way_count_avoid_crossings);
  file->rdwr_long(way_count_maximum);
  }
+
+ if (file->is_version_atleast(124,4)) {
+ file->rdwr_long(credit_per_MWs);
+ }
+ else {
+ credit_per_MWs = 2;
+ }
  }
 
  // sometimes broken savegames could have no legal direction for take off ...
@@ -1307,6 +1314,8 @@ void settings_t::parse_simuconf( tabfile_t& simuconf, sint16& disp_width, sint16
 
  crossconnect_factories         = contents.get_int("crossconnect_factories", crossconnect_factories ) != 0;
 
+ credit_per_MWs = contents.get_int_clamped( "credit_per_MWs", credit_per_MWs, 1, 512);
+
  env_t::just_in_time = contents.get_int_clamped("just_in_time", env_t::just_in_time, 0, 2);
  just_in_time = env_t::just_in_time;
 
diff --git a/src/simutrans/dataobj/settings.h b/src/simutrans/dataobj/settings.h
index a15b485f4..d3a12fa57 100644
--- a/src/simutrans/dataobj/settings.h
+++ b/src/simutrans/dataobj/settings.h
@@ -63,6 +63,8 @@ private:
  sint32 factory_count       =  12;
  sint32 electric_promille   = 330;
 
+ uint32 credit_per_MWs;
+
  sint32 city_count         =   16;
  sint32 mean_citizen_count = 1600;
 
@@ -418,6 +420,8 @@ public:
 
  sint32 get_electric_promille() const {return electric_promille;}
 
+ sint32 get_credit_per_MWs() const {return credit_per_MWs;}
+
  void set_tourist_attractions( sint32 n ) { tourist_attractions = n; }
  sint32 get_tourist_attractions() const {return tourist_attractions;}
 
diff --git a/src/simutrans/gui/settings_stats.cc b/src/simutrans/gui/settings_stats.cc
index 40b1425d0..bb113b843 100644
--- a/src/simutrans/gui/settings_stats.cc
+++ b/src/simutrans/gui/settings_stats.cc
@@ -306,6 +306,7 @@ void settings_economy_stats_t::init(settings_t const* const sets)
  INIT_NUM( "electric_promille", sets->get_electric_promille(), 0, 1000, gui_numberinput_t::AUTOLINEAR, false );
  INIT_BOOL( "allow_underground_transformers", sets->get_allow_underground_transformers() );
  INIT_NUM( "way_height_clearance", sets->get_way_height_clearance(), 1, 2, gui_numberinput_t::AUTOLINEAR, true );
+ INIT_NUM( "credit_per_MWs", sets->get_credit_per_MWs(), 1, 512, gui_numberinput_t::AUTOLINEAR, false);
  SEPERATOR
 
  INIT_NUM( "passenger_factor",  sets->get_passenger_factor(), 0, 16, gui_numberinput_t::AUTOLINEAR, false );
@@ -398,6 +399,7 @@ void settings_economy_stats_t::read(settings_t* const sets)
  READ_NUM_VALUE( sets->electric_promille );
  READ_BOOL_VALUE( sets->allow_underground_transformers );
  READ_NUM_VALUE( sets->way_height_clearance );
+ READ_NUM_VALUE( sets->credit_per_MWs );
 
  READ_NUM_VALUE( sets->passenger_factor );
  READ_NUM_VALUE( sets->minimum_city_distance );
diff --git a/src/simutrans/obj/leitung2.cc b/src/simutrans/obj/leitung2.cc
index c84e9b36c..b2d528667 100644
--- a/src/simutrans/obj/leitung2.cc
+++ b/src/simutrans/obj/leitung2.cc
@@ -668,7 +668,7 @@ senke_t::~senke_t()
 void senke_t::pay_revenue()
 {
  // megajoules (megawatt seconds) per cent
- const uint64 mjpc = (1 << POWER_TO_MW) / CREDIT_PER_MWS; // should be tied to game setting
+ const uint64 mjpc = (1 << POWER_TO_MW) / world()->get_settings().get_credit_per_MWs(); // should be tied to game setting
 
  // calculate payment in cent
  const sint64 payment = (sint64)(energy_acc / mjpc);
diff --git a/src/simutrans/obj/leitung2.h b/src/simutrans/obj/leitung2.h
index e1a17e75c..a4c4e1a5d 100644
--- a/src/simutrans/obj/leitung2.h
+++ b/src/simutrans/obj/leitung2.h
@@ -16,8 +16,6 @@
 // bitshift for converting internal power values to MW for display
 extern const uint32 POWER_TO_MW;
 
-#define CREDIT_PER_MWS 2
-
 class powernet_t;
 class player_t;
 class fabrik_t;
I made a patch.
But I want to discuss about how much the upper limit of credit per MW.
In addition, in calculating energy_acc, we should consider about "MW per credit" cannot be as an integer (a remainder occurs in division).

prissi

Oh, I somewhat overlooked this. I think there is no need for a sensible maximum, one can change many internal parameter to ridicilous values without being hindered by hard limits in the program.

Also, if the unit is kw per credit, one could just shift by 10 and get much more accuracy ...

Implemented in r11888, parameter is kw_per_credit and old was 512. So it leves enough roome for higher and lower incodem, I think

poppo

I understand kw_per_credit is better to use in current codes.
But I think credit_per_kw is easier for players to understand.

TurfIt

Payment in the code is for energy, not power. kW is a unit of power, not energy...

prissi

Since Simutrans does not support floats, it would be millicredits per kwh. Not sure if this is easier to understand.

Indeed, the unit is kW/time (in arbitary game units). You suggest naming it cost_kwh_per_credit?