AIChallenge - ilikegoodfood/CommunityLib GitHub Wiki
The AIChallenge
class is at the core of the universal Agent AI. It contains the type of challenge that the agent is able to perform, alongside custom profile, valid, validFor, and Utility functions.
public AIChallenge(Type challengeType, double profile, List<ChallengeTags> tags = null, bool safeMove = false)
The only parameters that are mandatory fo the AIChallenge constructor is the challenge type, and the base profile.
-
Type challengeType
- The challenge type you provide must be the exact challenge type, including ritual types. It cannot be a parent type for a group of challenge classes. When the AI runs, it will get all instances of challenges of this type anywhere on the map, and check their validity using the AIChallenge's prfoile and validity functions, explained below. -
double profile
- This is the base profile that the challenge has. A challenge is visible if the distance, in steps, is less than or equal to the profile divided by ten. If the Agent AI that you are assigning this AIChallenge to does not care about the challenge's visibility, simply set the profile to 0.
The optional parameters are list of ChallengeTags, and the safeMove boolean.
-
List<ChallengeTags> tags = null
- The tags list is a list of ChallengeTags, which are defined as an Enum in theAIChallenge
class. Each ChallengeTag has a pre-made piece of logic attached to it for the challenge's validity and or utility. By using tags, you can avoid having to create valid, validFor and utility delegates for commonly used situations. You can check the complete list of ChallengeTags and the logic that is attached them in theAIChallenge
class. -
bool safeMove = false
- The safeMove boolean allows you to instruct the challenge that it should only be done if the agent can get to it without being intercepted by a hostile army. The turnTickAI can also be set to care about safeMove. If it is instructed to do so, it will ignore the safeMove parameter on the AIChallenges assigned to it.
In additon to these parameters, the AIChallenge class also depends on four fields to store delegates. These are as follows:
-
List<Func<Challenge, UA, Location, double, double>> delegates_Profile
- Is called if the AgentAi respects challenge visibility, and returns the profile of the challenge. A challenge is visible if the distance, in steps, is less than or equal to the profile divided by ten. -
List<Func<Challenge, Location, bool>> delegates_Valid
- Is called to check if the challenge is valid. -
List<Func<Challenge, UA, Location, bool>> delegates_ValidFor
- Is called to check if the challenge is valid for the agent checking. -
List<Func<Challenge, UA, Location, List<ReasonMsg>, double>> delegates_Utility
- Is called for valid challenges to determined the utility of the challenge. The Agent AI will always perform the challenge with the highest utility, so make sure that the utility you set is in range with the other challenges assigned to that agent type, and variable.
All of the delegates in each field are called sequentially, alongside any logic in the AgentAI
class and the ChallengeTags, except for the valid and validFor delegates, which will only be called until one returns false, at which point no futher delegates will be called.
If you need to change the outcome of one of these two delegates to true, you will need to find and remove the offending delegate from the delegates field.
To assign a delegate to an AIChallenge, simply create a function where the return type is the last type listed in the Func defintion, and the other types are parameters, and add it, by name, to the appropriate delegate list. See the UAENOverrideAI
class for examples.