There are two bugs:
- It checks that the car, specifically the “center” of the car, is in sunlight instead of the individual solar panels.
- The method it uses to check whether a tile is inside or outside factors in whether there’s a vehicle roof in the same tile.
Pretty sure the fix is the following: (compiles, but I can’t test it at the moment) (This also scales charge rate with light level instead of it being only on in full sunlight.)
index c5c912e..e9a97cf 100644
--- a/vehicle.cpp
+++ b/vehicle.cpp
@@ -923,9 +923,16 @@ int vehicle::total_power (bool fueled)
int vehicle::solar_power ()
{
int pwr = 0;
- for (int p = 0; p < parts.size(); p++)
- if (part_flag(p, vpf_solar_panel) && parts[p].hp > 0)
- pwr += part_power(p);
+ for (int p = 0; p < parts.size(); p++) {
+ if (part_flag(p, vpf_solar_panel) && parts[p].hp > 0) {
+ int part_x = global_x() + parts[p].precalc_dx[0];
+ int part_y = global_y() + parts[p].precalc_dy[0];
+ // Can't use g->in_sunlight() because it factors in vehicle roofs.
+ if( !g->m.has_flag_ter_or_furn( indoors, part_x, part_y ) ) {
+ pwr += (part_power(p) * g->natural_light_level()) / DAYLIGHT_LEVEL;
+ }
+ }
+ }
return pwr;
}
@@ -1770,14 +1777,7 @@ void vehicle::gain_moves (int mp)
thrust (cruise_velocity > velocity? 1 : -1);
}
- if (g->is_in_sunlight(global_x(), global_y())) {
- refill (AT_BATT, solar_power());
- }
-
- // If the vehicle is moving, trickle-charge storage batteries.
- if (velocity && one_in(10)) {
- refill (AT_BATT, abs(velocity) / 100);
- }
+ refill (AT_BATT, solar_power());
// check for smoking parts
for (int ep = 0; ep < external_parts.size(); ep++)