Skip to content

Commit 33bbbb7

Browse files
LeifLeif
Leif
authored and
Leif
committed
also for version 29: Improve error message when no transport mode is available
1 parent d730bda commit 33bbbb7

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

main.nut

+40-7
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ function GetAvailableTransportModes(min_vehicles_left = 1)
128128
return tm_list;
129129
}
130130

131+
function GetSupportedVehicleTypeList()
132+
{
133+
return [AIVehicle.VT_AIR, AIVehicle.VT_ROAD];
134+
}
135+
131136
function GetVehiclesWithoutOrders()
132137
{
133138
local empty_orders = AIVehicleList();
@@ -203,14 +208,37 @@ function GetCargoFromStation(station_id)
203208
function AnyVehicleTypeBuildable()
204209
{
205210
local vt_available = false;
206-
foreach(vt in [AIVehicle.VT_ROAD, AIVehicle.VT_AIR])
211+
local vt_list = GetSupportedVehicleTypeList();
212+
foreach(vt in vt_list)
207213
{
208-
vt_available = vt_available || Vehicle.GetVehicleLimit(vt);
214+
vt_available = vt_available || Vehicle.GetVehicleLimit(vt) > 0;
209215
}
210216

211217
return vt_available;
212218
}
213219

220+
// Call this function if AnyVehicleTypeBuildable returns false
221+
function DisplayEnableVehicleTypesTips()
222+
{
223+
local vt_list = GetSupportedVehicleTypeList();
224+
foreach(vt in vt_list)
225+
{
226+
local label = TransportModeToString( VehicleTypeToTransportMode(vt) );
227+
label = label.toupper();
228+
229+
local s = Vehicle.GetVehicleTypeDisabledBySettingString(vt);
230+
if(s != null)
231+
Log.Info(label + " is disabled by: " + s);
232+
else
233+
{
234+
if(Vehicle.GetVehiclesLeft(vt) == 0)
235+
Log.Info(label + " is enabled, but have zero vehicles left");
236+
else
237+
Log.Info(label + " is enabled");
238+
}
239+
}
240+
}
241+
214242
// if avoid_small_airports is true, the result will only contain small airports
215243
// if there are no large ones.
216244
function GetAirportTypeList_AllowedAndBuildable(avoid_small_airports = false)
@@ -525,6 +553,8 @@ function CluelessPlus::Start()
525553
Log.Error("All transport modes that are supported by this AI are disabled for AIs (or have vehicle limit = 0).", Log.LVL_INFO);
526554
Log.Info("Enable road or air transport mode in advanced settings if you want that this AI should build something", Log.LVL_INFO);
527555
Log.Info("", Log.LVL_INFO);
556+
DisplayEnableVehicleTypesTips();
557+
Log.Info("", Log.LVL_INFO);
528558
}
529559

530560
state_build = false;
@@ -735,7 +765,7 @@ function CluelessPlus::Start()
735765

736766
// wait a year for next yearly manage
737767
last_yearly_manage = AIDate.GetCurrentDate();
738-
Log.Info("Yearly manage - done", Log.LVL_INFO);
768+
Log.Info("Yearly manage - done", Log.LVL_SUB_DECISIONS);
739769
}
740770

741771
TimerStop("all");
@@ -1119,10 +1149,13 @@ function CluelessPlus::GetNewPairMoneyLimit()
11191149
{
11201150
local limits = this.GetNewPairMoneyLimitPerTransportMode();
11211151
local min_limit = null;
1122-
foreach(item in limits)
1152+
if(limits != null)
11231153
{
1124-
if(min_limit == null || item.limit < min_limit)
1125-
min_limit = item.limit;
1154+
foreach(item in limits)
1155+
{
1156+
if(min_limit == null || item.limit < min_limit)
1157+
min_limit = item.limit;
1158+
}
11261159
}
11271160

11281161
if(min_limit == null) min_limit = 95000;
@@ -1137,7 +1170,7 @@ function CluelessPlus::GetNewPairMoneyLimitPerTransportMode()
11371170

11381171
// Make sure there are at least one transport mode
11391172
if(tm_list.len() == 0)
1140-
return 95000;
1173+
return null;
11411174

11421175
local tm_money_limits = [];
11431176
foreach(tm in tm_list)

transport_mode_stats.nut

+17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ function TransportModeToVehicleType(tm)
2828
return null;
2929
}
3030

31+
function VehicleTypeToTransportMode(tm)
32+
{
33+
switch(tm)
34+
{
35+
case AIVehicle.VT_ROAD:
36+
return TM_ROAD;
37+
case AIVehicle.VT_AIR:
38+
return TM_AIR;
39+
case AIVehicle.VT_RAIL:
40+
return TM_RAIL;
41+
case AIVehicle.VT_WATER:
42+
return TM_WATER;
43+
}
44+
45+
return null;
46+
}
47+
3148
function TransportModeToString(tm)
3249
{
3350
switch(tm)

0 commit comments

Comments
 (0)