AI authors can just read the NoCarGoal readme and use SCP themself, or use this library that offers a simple API to focus on the cargoes where the NoCarGoal transport goal has not yet been reached.
Minimal SCPLib version: 45
Usage
1. Import SCPLib and SCPClient_NoCarGoal: (please refer to bananas for information on what is the currently last library versions)
Code: Select all
import("Library.SCPLib", "SCPLib", 45);
import("Library.SCPClient_NoCarGoal", "SCPClient_NoCarGoal", 1);
Code: Select all
g_no_car_goal <- null;
4. Add to your Init procedure: (where SHORT_NAME is your 4 letter short name and SELF_VERSION is your script version)
Code: Select all
if(AIController.GetSetting("scp_enabled")) {
this.scp = SCPLib(SHORT_NAME, SELF_VERSION);
this.scp.SCPLogging_Info(Log.IsLevelAccepted(Log.LVL_DEBUG)); // Change this if you don't use SuperLib log system
this.scp.SCPLogging_Error(true);
} else {
this.scp = null;
}
// Always create g_no_car_goal which will just act as if no NoCarGoal
// gs has been found if this.scp is null.
g_no_car_goal = SCPClient_NoCarGoal(this.scp);
Code: Select all
// Read incoming SCP messages (up to 5 per loop)
if(this.scp != null) {
this.scp.SCPLogging_Info(Log.IsLevelAccepted(Log.LVL_DEBUG));
for(local j = 0; j < 5 && this.scp.Check(); j++){}
}
Code: Select all
AddSetting({name = "scp_enabled",
description = "Enable AI-GS communication - with support for NoCarGoal (SCP library)",
easy_value = 1,
medium_value = 1,
hard_value = 1,
custom_value = 1,
flags = CONFIG_BOOLEAN});
Second note, not all goal cargoes will be primary cargoes. So you may need to either employ the idea that any player that want to beat you must build up that infrastructure and accept that you will usually not win gold, or consider also to build cargo connections that eventually will give industry output that can be used to fulfill a goal.
8. As bananas dependency, you must select both SCPLib and SCPClient_NoCarGoal. Note that SCPClient_NoCarGoal do not depend or import SCPLib. This is because if you want to use several SCPClient libraries in the same AI it would be a hell if they depended too closely on different SCPLib versions. If the AI depend+import SCPLib, then it is enough that all SCP clients work with that SCPLib version.
In the steps I have included how to add SCPLib into your AI. If you already use SCPLib you should pass your already existing SCPLib instance to the SCPClient_NoCarGoal constructor.
Edit: made it more clear that the variable names used are examples.